1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2003-2008 - TortoiseSVN
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
20 #include "TortoiseProc.h"
\r
21 #include "CommonResource.h"
\r
22 #include "..\version.h"
\r
23 #include "MessageBox.h"
\r
24 #include ".\checkforupdatesdlg.h"
\r
25 #include "Registry.h"
\r
26 #include "AppUtils.h"
\r
27 #include "TempFile.h"
\r
30 IMPLEMENT_DYNAMIC(CCheckForUpdatesDlg, CStandAloneDialog)
\r
31 CCheckForUpdatesDlg::CCheckForUpdatesDlg(CWnd* pParent /*=NULL*/)
\r
32 : CStandAloneDialog(CCheckForUpdatesDlg::IDD, pParent)
\r
33 , m_bShowInfo(FALSE)
\r
36 m_sUpdateDownloadLink = _T("http://code.google.com/p/tortoisegit/downloads");
\r
37 m_sUpdateChangeLogLink = _T("http://code.google.com/p/tortoisegit/wiki/ReleaseNotes");
\r
40 CCheckForUpdatesDlg::~CCheckForUpdatesDlg()
\r
44 void CCheckForUpdatesDlg::DoDataExchange(CDataExchange* pDX)
\r
46 CStandAloneDialog::DoDataExchange(pDX);
\r
47 DDX_Control(pDX, IDC_LINK, m_link);
\r
48 DDX_Control(pDX, IDC_LINK_CHANGE_LOG, m_ChangeLogLink);
\r
52 BEGIN_MESSAGE_MAP(CCheckForUpdatesDlg, CStandAloneDialog)
\r
53 ON_STN_CLICKED(IDC_CHECKRESULT, OnStnClickedCheckresult)
\r
55 ON_WM_WINDOWPOSCHANGING()
\r
59 BOOL CCheckForUpdatesDlg::OnInitDialog()
\r
61 CStandAloneDialog::OnInitDialog();
\r
64 temp.Format(IDS_CHECKNEWER_YOURVERSION, TSVN_VERMAJOR, TSVN_VERMINOR, TSVN_VERMICRO, TSVN_VERBUILD);
\r
65 SetDlgItemText(IDC_YOURVERSION, temp);
\r
67 DialogEnableWindow(IDOK, FALSE);
\r
69 if (AfxBeginThread(CheckThreadEntry, this)==NULL)
\r
71 CMessageBox::Show(NULL, IDS_ERR_THREADSTARTFAILED, IDS_APPNAME, MB_OK | MB_ICONERROR);
\r
74 SetTimer(100, 1000, NULL);
\r
78 void CCheckForUpdatesDlg::OnOK()
\r
80 if (m_bThreadRunning)
\r
82 CStandAloneDialog::OnOK();
\r
85 void CCheckForUpdatesDlg::OnCancel()
\r
87 if (m_bThreadRunning)
\r
89 CStandAloneDialog::OnCancel();
\r
92 UINT CCheckForUpdatesDlg::CheckThreadEntry(LPVOID pVoid)
\r
94 return ((CCheckForUpdatesDlg*)pVoid)->CheckThread();
\r
97 UINT CCheckForUpdatesDlg::CheckThread()
\r
99 m_bThreadRunning = TRUE;
\r
102 CString tempfile = CTempFiles::Instance().GetTempFilePath(true).GetWinPathString();
\r
104 CRegString checkurluser = CRegString(_T("Software\\TortoiseGit\\UpdateCheckURL"), _T(""));
\r
105 CRegString checkurlmachine = CRegString(_T("Software\\TortoiseGit\\UpdateCheckURL"), _T(""), FALSE, HKEY_LOCAL_MACHINE);
\r
106 CString sCheckURL = checkurluser;
\r
107 if (sCheckURL.IsEmpty())
\r
109 sCheckURL = checkurlmachine;
\r
110 if (sCheckURL.IsEmpty())
\r
111 sCheckURL = _T("http://code.google.com/p/tortoisegit/downloads/list");
\r
113 CoInitialize(NULL);
\r
114 HRESULT res = URLDownloadToFile(NULL, sCheckURL, tempfile, 0, NULL);
\r
119 CStdioFile file(tempfile, CFile::modeRead | CFile::shareDenyWrite);
\r
121 int major,minor,micro,build;
\r
122 major=minor=micro=build=0;
\r
123 unsigned __int64 version=0;
\r
125 if(file.GetLength()>100)
\r
127 while(file.ReadString(ver))
\r
130 while( (start=ver.Find(_T("TortoiseGit-"))) > 0 )
\r
132 ver = ver.Mid(start+CString(_T("TortoiseGit-")).GetLength());
\r
134 x1=_ttoi(ver)&0xFFFF;
\r
135 ver = ver.Mid(ver.Find('.')+1);
\r
136 x2=_ttoi(ver)&0xFFFF;
\r
137 ver = ver.Mid(ver.Find('.')+1);
\r
138 x3=_ttoi(ver)&0xFFFF;
\r
139 ver = ver.Mid(ver.Find('.')+1);
\r
140 x4=_ttoi(ver)&0xFFFF;
\r
142 unsigned __int64 newversion;
\r
143 newversion = (x1<<48) + (x2<<32) + (x3<<16)+x4;
\r
144 if(newversion>version)
\r
150 version = newversion;
\r
155 }else if (file.ReadString(ver))
\r
157 CString vertemp = ver;
\r
158 major = _ttoi(vertemp);
\r
159 vertemp = vertemp.Mid(vertemp.Find('.')+1);
\r
160 minor = _ttoi(vertemp);
\r
161 vertemp = vertemp.Mid(vertemp.Find('.')+1);
\r
162 micro = _ttoi(vertemp);
\r
163 vertemp = vertemp.Mid(vertemp.Find('.')+1);
\r
164 build = _ttoi(vertemp);
\r
165 version = (major<<48) + (minor<<32) + (micro<<16)+build;
\r
169 BOOL bNewer = FALSE;
\r
170 if (major > TSVN_VERMAJOR)
\r
172 else if ((minor > TSVN_VERMINOR)&&(major == TSVN_VERMAJOR))
\r
174 else if ((micro > TSVN_VERMICRO)&&(minor == TSVN_VERMINOR)&&(major == TSVN_VERMAJOR))
\r
176 else if ((build > TSVN_VERBUILD)&&(micro == TSVN_VERMICRO)&&(minor == TSVN_VERMINOR)&&(major == TSVN_VERMAJOR))
\r
181 ver.Format(_T("%d.%d.%d.%d"),major,minor,micro,build);
\r
182 temp.Format(IDS_CHECKNEWER_CURRENTVERSION, (LPCTSTR)ver);
\r
183 SetDlgItemText(IDC_CURRENTVERSION, temp);
\r
184 temp.Format(_T("%d.%d.%d.%d"), TSVN_VERMAJOR, TSVN_VERMINOR, TSVN_VERMICRO, TSVN_VERBUILD);
\r
189 temp.LoadString(IDS_CHECKNEWER_NETERROR);
\r
190 SetDlgItemText(IDC_CHECKRESULT, temp);
\r
194 if(file.ReadString(temp) && !temp.IsEmpty())
\r
195 { // Read the next line, it could contain a message for the user
\r
197 if(file.ReadString(tempLink) && !tempLink.IsEmpty())
\r
198 { // Read another line to find out the download link-URL, if any
\r
199 m_sUpdateDownloadLink = tempLink;
\r
205 temp.LoadString(IDS_CHECKNEWER_NEWERVERSIONAVAILABLE);
\r
207 SetDlgItemText(IDC_CHECKRESULT, temp);
\r
208 m_bShowInfo = TRUE;
\r
212 temp.LoadString(IDS_CHECKNEWER_YOURUPTODATE);
\r
213 SetDlgItemText(IDC_CHECKRESULT, temp);
\r
217 catch (CException * e)
\r
220 temp.LoadString(IDS_CHECKNEWER_NETERROR);
\r
221 SetDlgItemText(IDC_CHECKRESULT, temp);
\r
226 // Try to cache web page;
\r
228 temp.LoadString(IDS_CHECKNEWER_NETERROR);
\r
229 SetDlgItemText(IDC_CHECKRESULT, temp);
\r
231 if (!m_sUpdateDownloadLink.IsEmpty())
\r
233 m_link.ShowWindow(SW_SHOW);
\r
234 m_link.SetURL(m_sUpdateDownloadLink);
\r
236 if (!m_sUpdateDownloadLink.IsEmpty())
\r
238 m_ChangeLogLink.ShowWindow(SW_SHOW);
\r
239 m_ChangeLogLink.SetURL(m_sUpdateChangeLogLink);
\r
242 DeleteFile(tempfile);
\r
243 m_bThreadRunning = FALSE;
\r
244 DialogEnableWindow(IDOK, TRUE);
\r
248 void CCheckForUpdatesDlg::OnStnClickedCheckresult()
\r
250 // user clicked on the label, start the browser with our web page
\r
251 HINSTANCE result = ShellExecute(NULL, _T("opennew"), m_sUpdateDownloadLink, NULL,NULL, SW_SHOWNORMAL);
\r
252 if ((UINT)result <= HINSTANCE_ERROR)
\r
254 result = ShellExecute(NULL, _T("open"), m_sUpdateDownloadLink, NULL,NULL, SW_SHOWNORMAL);
\r
258 void CCheckForUpdatesDlg::OnTimer(UINT_PTR nIDEvent)
\r
260 if (nIDEvent == 100)
\r
262 if (m_bThreadRunning == FALSE)
\r
267 ShowWindow(SW_SHOWNORMAL);
\r
275 CStandAloneDialog::OnTimer(nIDEvent);
\r
278 void CCheckForUpdatesDlg::OnWindowPosChanging(WINDOWPOS* lpwndpos)
\r
280 CStandAloneDialog::OnWindowPosChanging(lpwndpos);
\r
281 if (m_bVisible == FALSE)
\r
282 lpwndpos->flags &= ~SWP_SHOWWINDOW;
\r
285 BOOL CCheckForUpdatesDlg::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
\r
287 if ((!m_sUpdateDownloadLink.IsEmpty())&&(pWnd)&&(pWnd == GetDlgItem(IDC_CHECKRESULT)))
\r
289 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_HAND));
\r
294 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
\r
296 return CStandAloneDialogTmpl<CDialog>::OnSetCursor(pWnd, nHitTest, message);
\r