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