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 "..\version.h"
22 #include "MessageBox.h"
23 #include ".\checkforupdatesdlg.h"
29 IMPLEMENT_DYNAMIC(CCheckForUpdatesDlg
, CStandAloneDialog
)
30 CCheckForUpdatesDlg::CCheckForUpdatesDlg(CWnd
* pParent
/*=NULL*/)
31 : CStandAloneDialog(CCheckForUpdatesDlg::IDD
, pParent
)
35 m_sUpdateDownloadLink
= _T("http://tortoisesvn.tigris.org");
38 CCheckForUpdatesDlg::~CCheckForUpdatesDlg()
42 void CCheckForUpdatesDlg::DoDataExchange(CDataExchange
* pDX
)
44 CStandAloneDialog::DoDataExchange(pDX
);
45 DDX_Control(pDX
, IDC_LINK
, m_link
);
49 BEGIN_MESSAGE_MAP(CCheckForUpdatesDlg
, CStandAloneDialog
)
50 ON_STN_CLICKED(IDC_CHECKRESULT
, OnStnClickedCheckresult
)
52 ON_WM_WINDOWPOSCHANGING()
56 BOOL
CCheckForUpdatesDlg::OnInitDialog()
58 CStandAloneDialog::OnInitDialog();
61 temp
.Format(IDS_CHECKNEWER_YOURVERSION
, TSVN_VERMAJOR
, TSVN_VERMINOR
, TSVN_VERMICRO
, TSVN_VERBUILD
);
62 SetDlgItemText(IDC_YOURVERSION
, temp
);
64 DialogEnableWindow(IDOK
, FALSE
);
66 if (AfxBeginThread(CheckThreadEntry
, this)==NULL
)
68 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
71 SetTimer(100, 1000, NULL
);
75 void CCheckForUpdatesDlg::OnOK()
79 CStandAloneDialog::OnOK();
82 void CCheckForUpdatesDlg::OnCancel()
86 CStandAloneDialog::OnCancel();
89 UINT
CCheckForUpdatesDlg::CheckThreadEntry(LPVOID pVoid
)
91 return ((CCheckForUpdatesDlg
*)pVoid
)->CheckThread();
94 UINT
CCheckForUpdatesDlg::CheckThread()
96 m_bThreadRunning
= TRUE
;
99 CString tempfile
= CTempFiles::Instance().GetTempFilePath(true).GetWinPathString();
101 CRegString checkurluser
= CRegString(_T("Software\\TortoiseGit\\UpdateCheckURL"), _T(""));
102 CRegString checkurlmachine
= CRegString(_T("Software\\TortoiseGit\\UpdateCheckURL"), _T(""), FALSE
, HKEY_LOCAL_MACHINE
);
103 CString sCheckURL
= checkurluser
;
104 if (sCheckURL
.IsEmpty())
106 sCheckURL
= checkurlmachine
;
107 if (sCheckURL
.IsEmpty())
108 sCheckURL
= _T("http://tortoisesvn.tigris.org/version.txt");
110 HRESULT res
= URLDownloadToFile(NULL
, sCheckURL
, tempfile
, 0, NULL
);
115 CStdioFile
file(tempfile
, CFile::modeRead
| CFile::shareDenyWrite
);
117 if (file
.ReadString(ver
))
119 CString vertemp
= ver
;
120 int major
= _ttoi(vertemp
);
121 vertemp
= vertemp
.Mid(vertemp
.Find('.')+1);
122 int minor
= _ttoi(vertemp
);
123 vertemp
= vertemp
.Mid(vertemp
.Find('.')+1);
124 int micro
= _ttoi(vertemp
);
125 vertemp
= vertemp
.Mid(vertemp
.Find('.')+1);
126 int build
= _ttoi(vertemp
);
128 if (major
> TSVN_VERMAJOR
)
130 else if ((minor
> TSVN_VERMINOR
)&&(major
== TSVN_VERMAJOR
))
132 else if ((micro
> TSVN_VERMICRO
)&&(minor
== TSVN_VERMINOR
)&&(major
== TSVN_VERMAJOR
))
134 else if ((build
> TSVN_VERBUILD
)&&(micro
== TSVN_VERMICRO
)&&(minor
== TSVN_VERMINOR
)&&(major
== TSVN_VERMAJOR
))
139 temp
.Format(IDS_CHECKNEWER_CURRENTVERSION
, (LPCTSTR
)ver
);
140 SetDlgItemText(IDC_CURRENTVERSION
, temp
);
141 temp
.Format(_T("%d.%d.%d.%d"), TSVN_VERMAJOR
, TSVN_VERMINOR
, TSVN_VERMICRO
, TSVN_VERBUILD
);
146 temp
.LoadString(IDS_CHECKNEWER_NETERROR
);
147 SetDlgItemText(IDC_CHECKRESULT
, temp
);
151 if(file
.ReadString(temp
) && !temp
.IsEmpty())
152 { // Read the next line, it could contain a message for the user
154 if(file
.ReadString(tempLink
) && !tempLink
.IsEmpty())
155 { // Read another line to find out the download link-URL, if any
156 m_sUpdateDownloadLink
= tempLink
;
162 temp
.LoadString(IDS_CHECKNEWER_NEWERVERSIONAVAILABLE
);
164 SetDlgItemText(IDC_CHECKRESULT
, temp
);
169 temp
.LoadString(IDS_CHECKNEWER_YOURUPTODATE
);
170 SetDlgItemText(IDC_CHECKRESULT
, temp
);
174 catch (CException
* e
)
177 temp
.LoadString(IDS_CHECKNEWER_NETERROR
);
178 SetDlgItemText(IDC_CHECKRESULT
, temp
);
183 temp
.LoadString(IDS_CHECKNEWER_NETERROR
);
184 SetDlgItemText(IDC_CHECKRESULT
, temp
);
186 if (!m_sUpdateDownloadLink
.IsEmpty())
188 m_link
.ShowWindow(SW_SHOW
);
189 m_link
.SetURL(m_sUpdateDownloadLink
);
192 DeleteFile(tempfile
);
193 m_bThreadRunning
= FALSE
;
194 DialogEnableWindow(IDOK
, TRUE
);
198 void CCheckForUpdatesDlg::OnStnClickedCheckresult()
200 // user clicked on the label, start the browser with our web page
201 HINSTANCE result
= ShellExecute(NULL
, _T("opennew"), m_sUpdateDownloadLink
, NULL
,NULL
, SW_SHOWNORMAL
);
202 if ((UINT
)result
<= HINSTANCE_ERROR
)
204 result
= ShellExecute(NULL
, _T("open"), m_sUpdateDownloadLink
, NULL
,NULL
, SW_SHOWNORMAL
);
208 void CCheckForUpdatesDlg::OnTimer(UINT_PTR nIDEvent
)
212 if (m_bThreadRunning
== FALSE
)
217 ShowWindow(SW_SHOWNORMAL
);
225 CStandAloneDialog::OnTimer(nIDEvent
);
228 void CCheckForUpdatesDlg::OnWindowPosChanging(WINDOWPOS
* lpwndpos
)
230 CStandAloneDialog::OnWindowPosChanging(lpwndpos
);
231 if (m_bVisible
== FALSE
)
232 lpwndpos
->flags
&= ~SWP_SHOWWINDOW
;
235 BOOL
CCheckForUpdatesDlg::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
237 if ((!m_sUpdateDownloadLink
.IsEmpty())&&(pWnd
)&&(pWnd
== GetDlgItem(IDC_CHECKRESULT
)))
239 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_HAND
));
244 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_ARROW
));
246 return CStandAloneDialogTmpl
<CDialog
>::OnSetCursor(pWnd
, nHitTest
, message
);