Update diff del rename ignore document.
[TortoiseGit.git] / src / TortoiseProc / CheckForUpdatesDlg.cpp
blob79bbefa579db72c9bb760b0e3b90cac479688e36
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.
19 #include "stdafx.h"
20 #include "TortoiseProc.h"
21 #include "..\version.h"
22 #include "MessageBox.h"
23 #include ".\checkforupdatesdlg.h"
24 #include "Registry.h"
25 #include "AppUtils.h"
26 #include "TempFile.h"
29 IMPLEMENT_DYNAMIC(CCheckForUpdatesDlg, CStandAloneDialog)
30 CCheckForUpdatesDlg::CCheckForUpdatesDlg(CWnd* pParent /*=NULL*/)
31 : CStandAloneDialog(CCheckForUpdatesDlg::IDD, pParent)
32 , m_bShowInfo(FALSE)
33 , m_bVisible(FALSE)
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)
51 ON_WM_TIMER()
52 ON_WM_WINDOWPOSCHANGING()
53 ON_WM_SETCURSOR()
54 END_MESSAGE_MAP()
56 BOOL CCheckForUpdatesDlg::OnInitDialog()
58 CStandAloneDialog::OnInitDialog();
60 CString temp;
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);
72 return TRUE;
75 void CCheckForUpdatesDlg::OnOK()
77 if (m_bThreadRunning)
78 return;
79 CStandAloneDialog::OnOK();
82 void CCheckForUpdatesDlg::OnCancel()
84 if (m_bThreadRunning)
85 return;
86 CStandAloneDialog::OnCancel();
89 UINT CCheckForUpdatesDlg::CheckThreadEntry(LPVOID pVoid)
91 return ((CCheckForUpdatesDlg*)pVoid)->CheckThread();
94 UINT CCheckForUpdatesDlg::CheckThread()
96 m_bThreadRunning = TRUE;
98 CString temp;
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);
111 if (res == S_OK)
115 CStdioFile file(tempfile, CFile::modeRead | CFile::shareDenyWrite);
116 CString ver;
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);
127 BOOL bNewer = FALSE;
128 if (major > TSVN_VERMAJOR)
129 bNewer = TRUE;
130 else if ((minor > TSVN_VERMINOR)&&(major == TSVN_VERMAJOR))
131 bNewer = TRUE;
132 else if ((micro > TSVN_VERMICRO)&&(minor == TSVN_VERMINOR)&&(major == TSVN_VERMAJOR))
133 bNewer = TRUE;
134 else if ((build > TSVN_VERBUILD)&&(micro == TSVN_VERMICRO)&&(minor == TSVN_VERMINOR)&&(major == TSVN_VERMAJOR))
135 bNewer = TRUE;
137 if (_ttoi(ver)!=0)
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);
144 if (_ttoi(ver)==0)
146 temp.LoadString(IDS_CHECKNEWER_NETERROR);
147 SetDlgItemText(IDC_CHECKRESULT, temp);
149 else if (bNewer)
151 if(file.ReadString(temp) && !temp.IsEmpty())
152 { // Read the next line, it could contain a message for the user
153 CString tempLink;
154 if(file.ReadString(tempLink) && !tempLink.IsEmpty())
155 { // Read another line to find out the download link-URL, if any
156 m_sUpdateDownloadLink = tempLink;
160 else
162 temp.LoadString(IDS_CHECKNEWER_NEWERVERSIONAVAILABLE);
164 SetDlgItemText(IDC_CHECKRESULT, temp);
165 m_bShowInfo = TRUE;
167 else
169 temp.LoadString(IDS_CHECKNEWER_YOURUPTODATE);
170 SetDlgItemText(IDC_CHECKRESULT, temp);
174 catch (CException * e)
176 e->Delete();
177 temp.LoadString(IDS_CHECKNEWER_NETERROR);
178 SetDlgItemText(IDC_CHECKRESULT, temp);
181 else
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);
195 return 0;
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)
210 if (nIDEvent == 100)
212 if (m_bThreadRunning == FALSE)
214 if (m_bShowInfo)
216 m_bVisible = TRUE;
217 ShowWindow(SW_SHOWNORMAL);
219 else
221 EndDialog(0);
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));
240 SetCursor(hCur);
241 return TRUE;
244 HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW));
245 SetCursor(hCur);
246 return CStandAloneDialogTmpl<CDialog>::OnSetCursor(pWnd, nHitTest, message);