1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2011 - TortoiseGit
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "TortoiseProc.h"
22 #include "LoglistCommonResource.h"
23 #include "..\version.h"
24 #include "MessageBox.h"
25 #include ".\checkforupdatesdlg.h"
31 IMPLEMENT_DYNAMIC(CCheckForUpdatesDlg
, CStandAloneDialog
)
32 CCheckForUpdatesDlg::CCheckForUpdatesDlg(CWnd
* pParent
/*=NULL*/)
33 : CStandAloneDialog(CCheckForUpdatesDlg::IDD
, pParent
)
37 m_sUpdateDownloadLink
= _T("http://code.google.com/p/tortoisegit/downloads");
38 m_sUpdateChangeLogLink
= _T("http://code.google.com/p/tortoisegit/wiki/ReleaseNotes");
41 CCheckForUpdatesDlg::~CCheckForUpdatesDlg()
45 void CCheckForUpdatesDlg::DoDataExchange(CDataExchange
* pDX
)
47 CStandAloneDialog::DoDataExchange(pDX
);
48 DDX_Control(pDX
, IDC_LINK
, m_link
);
49 DDX_Control(pDX
, IDC_LINK_CHANGE_LOG
, m_ChangeLogLink
);
53 BEGIN_MESSAGE_MAP(CCheckForUpdatesDlg
, CStandAloneDialog
)
54 ON_STN_CLICKED(IDC_CHECKRESULT
, OnStnClickedCheckresult
)
56 ON_WM_WINDOWPOSCHANGING()
60 BOOL
CCheckForUpdatesDlg::OnInitDialog()
62 CStandAloneDialog::OnInitDialog();
63 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
66 temp
.Format(IDS_CHECKNEWER_YOURVERSION
, TGIT_VERMAJOR
, TGIT_VERMINOR
, TGIT_VERMICRO
, TGIT_VERBUILD
);
67 SetDlgItemText(IDC_YOURVERSION
, temp
);
69 DialogEnableWindow(IDOK
, FALSE
);
71 if (AfxBeginThread(CheckThreadEntry
, this)==NULL
)
73 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
76 SetTimer(100, 1000, NULL
);
80 void CCheckForUpdatesDlg::OnOK()
84 CStandAloneDialog::OnOK();
87 void CCheckForUpdatesDlg::OnCancel()
91 CStandAloneDialog::OnCancel();
94 UINT
CCheckForUpdatesDlg::CheckThreadEntry(LPVOID pVoid
)
96 return ((CCheckForUpdatesDlg
*)pVoid
)->CheckThread();
99 UINT
CCheckForUpdatesDlg::CheckThread()
101 m_bThreadRunning
= TRUE
;
104 CString tempfile
= CTempFiles::Instance().GetTempFilePath(true).GetWinPathString();
106 CRegString checkurluser
= CRegString(_T("Software\\TortoiseGit\\UpdateCheckURL"), _T(""));
107 CRegString checkurlmachine
= CRegString(_T("Software\\TortoiseGit\\UpdateCheckURL"), _T(""), FALSE
, HKEY_LOCAL_MACHINE
);
108 CString sCheckURL
= checkurluser
;
109 if (sCheckURL
.IsEmpty())
111 sCheckURL
= checkurlmachine
;
112 if (sCheckURL
.IsEmpty())
113 sCheckURL
= _T("http://code.google.com/p/tortoisegit/downloads/list?q=label%3AFeatured");
116 HRESULT res
= URLDownloadToFile(NULL
, sCheckURL
, tempfile
, 0, NULL
);
121 CStdioFile
file(tempfile
, CFile::modeRead
| CFile::shareDenyWrite
);
123 unsigned int major
,minor
,micro
,build
;
124 major
=minor
=micro
=build
=0;
125 unsigned __int64 version
=0;
127 if(file
.GetLength()>100)
129 while(file
.ReadString(ver
))
131 ver
.Trim().MakeLower();
133 while( (start
=ver
.Find(_T("tortoisegit-"))) > 0 )
135 ver
= ver
.Mid(start
+CString(_T("tortoisegit-")).GetLength());
136 unsigned int x1
,x2
,x3
,x4
;
137 x1
=_ttoi(ver
)&0xFFFF;
138 ver
= ver
.Mid(ver
.Find('.')+1);
139 x2
=_ttoi(ver
)&0xFFFF;
140 ver
= ver
.Mid(ver
.Find('.')+1);
141 x3
=_ttoi(ver
)&0xFFFF;
142 ver
= ver
.Mid(ver
.Find('.')+1);
143 x4
=_ttoi(ver
)&0xFFFF;
145 unsigned __int64 newversion
;
154 if(newversion
>version
)
160 version
= newversion
;
166 else if (file
.ReadString(ver
))
168 CString vertemp
= ver
;
169 major
= _ttoi(vertemp
);
170 vertemp
= vertemp
.Mid(vertemp
.Find('.')+1);
171 minor
= _ttoi(vertemp
);
172 vertemp
= vertemp
.Mid(vertemp
.Find('.')+1);
173 micro
= _ttoi(vertemp
);
174 vertemp
= vertemp
.Mid(vertemp
.Find('.')+1);
175 build
= _ttoi(vertemp
);
187 if (major
> TGIT_VERMAJOR
)
189 else if ((minor
> TGIT_VERMINOR
)&&(major
== TGIT_VERMAJOR
))
191 else if ((micro
> TGIT_VERMICRO
)&&(minor
== TGIT_VERMINOR
)&&(major
== TGIT_VERMAJOR
))
193 else if ((build
> TGIT_VERBUILD
)&&(micro
== TGIT_VERMICRO
)&&(minor
== TGIT_VERMINOR
)&&(major
== TGIT_VERMAJOR
))
198 ver
.Format(_T("%d.%d.%d.%d"),major
,minor
,micro
,build
);
199 temp
.Format(IDS_CHECKNEWER_CURRENTVERSION
, (LPCTSTR
)ver
);
200 SetDlgItemText(IDC_CURRENTVERSION
, temp
);
201 temp
.Format(_T("%d.%d.%d.%d"), TGIT_VERMAJOR
, TGIT_VERMINOR
, TGIT_VERMICRO
, TGIT_VERBUILD
);
206 temp
.LoadString(IDS_CHECKNEWER_NETERROR
);
207 SetDlgItemText(IDC_CHECKRESULT
, temp
);
211 if(file
.ReadString(temp
) && !temp
.IsEmpty())
212 { // Read the next line, it could contain a message for the user
214 if(file
.ReadString(tempLink
) && !tempLink
.IsEmpty())
215 { // Read another line to find out the download link-URL, if any
216 m_sUpdateDownloadLink
= tempLink
;
222 temp
.LoadString(IDS_CHECKNEWER_NEWERVERSIONAVAILABLE
);
224 SetDlgItemText(IDC_CHECKRESULT
, temp
);
229 temp
.LoadString(IDS_CHECKNEWER_YOURUPTODATE
);
230 SetDlgItemText(IDC_CHECKRESULT
, temp
);
234 catch (CException
* e
)
237 temp
.LoadString(IDS_CHECKNEWER_NETERROR
);
238 SetDlgItemText(IDC_CHECKRESULT
, temp
);
243 // Try to cache web page;
245 temp
.LoadString(IDS_CHECKNEWER_NETERROR
);
246 SetDlgItemText(IDC_CHECKRESULT
, temp
);
248 if (!m_sUpdateDownloadLink
.IsEmpty())
250 m_link
.ShowWindow(SW_SHOW
);
251 m_link
.SetURL(m_sUpdateDownloadLink
);
253 if (!m_sUpdateDownloadLink
.IsEmpty())
255 m_ChangeLogLink
.ShowWindow(SW_SHOW
);
256 m_ChangeLogLink
.SetURL(m_sUpdateChangeLogLink
);
259 DeleteFile(tempfile
);
260 m_bThreadRunning
= FALSE
;
261 DialogEnableWindow(IDOK
, TRUE
);
265 void CCheckForUpdatesDlg::OnStnClickedCheckresult()
267 // user clicked on the label, start the browser with our web page
268 HINSTANCE result
= ShellExecute(NULL
, _T("opennew"), m_sUpdateDownloadLink
, NULL
,NULL
, SW_SHOWNORMAL
);
269 if ((UINT
)result
<= HINSTANCE_ERROR
)
271 result
= ShellExecute(NULL
, _T("open"), m_sUpdateDownloadLink
, NULL
,NULL
, SW_SHOWNORMAL
);
275 void CCheckForUpdatesDlg::OnTimer(UINT_PTR nIDEvent
)
279 if (m_bThreadRunning
== FALSE
)
284 ShowWindow(SW_SHOWNORMAL
);
292 CStandAloneDialog::OnTimer(nIDEvent
);
295 void CCheckForUpdatesDlg::OnWindowPosChanging(WINDOWPOS
* lpwndpos
)
297 CStandAloneDialog::OnWindowPosChanging(lpwndpos
);
298 if (m_bVisible
== FALSE
)
299 lpwndpos
->flags
&= ~SWP_SHOWWINDOW
;
302 BOOL
CCheckForUpdatesDlg::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
304 if ((!m_sUpdateDownloadLink
.IsEmpty())&&(pWnd
)&&(pWnd
== GetDlgItem(IDC_CHECKRESULT
)))
306 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_HAND
));
311 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_ARROW
));
313 return CStandAloneDialogTmpl
<CDialog
>::OnSetCursor(pWnd
, nHitTest
, message
);