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