1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2008 - TortoiseSVN
4 // Copyright (C) 2008-2012 - 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 #include "SmartHandle.h"
33 #include "PathUtils.h"
34 #include "DirFileEnum.h"
35 #include "ProjectProperties.h"
36 #include "UniCodeUtils.h"
38 // Link with Wintrust.lib
39 #pragma comment (lib, "wintrust")
41 #define WM_USER_DISPLAYSTATUS (WM_USER + 1)
42 #define WM_USER_ENDDOWNLOAD (WM_USER + 2)
43 #define WM_USER_FILLCHANGELOG (WM_USER + 3)
45 IMPLEMENT_DYNAMIC(CCheckForUpdatesDlg
, CStandAloneDialog
)
46 CCheckForUpdatesDlg::CCheckForUpdatesDlg(CWnd
* pParent
/*=NULL*/)
47 : CStandAloneDialog(CCheckForUpdatesDlg::IDD
, pParent
)
51 , m_pDownloadThread(NULL
)
53 m_sUpdateDownloadLink
= _T("http://code.google.com/p/tortoisegit/wiki/Download?tm=2");
56 CCheckForUpdatesDlg::~CCheckForUpdatesDlg()
60 void CCheckForUpdatesDlg::DoDataExchange(CDataExchange
* pDX
)
62 CStandAloneDialog::DoDataExchange(pDX
);
63 DDX_Control(pDX
, IDC_LINK
, m_link
);
64 DDX_Control(pDX
, IDC_PROGRESSBAR
, m_progress
);
65 DDX_Control(pDX
, IDC_LIST_DOWNLOADS
, m_ctrlFiles
);
66 DDX_Control(pDX
, IDC_BUTTON_UPDATE
, m_ctrlUpdate
);
67 DDX_Control(pDX
, IDC_LOGMESSAGE
, m_cLogMessage
);
70 BEGIN_MESSAGE_MAP(CCheckForUpdatesDlg
, CStandAloneDialog
)
71 ON_STN_CLICKED(IDC_CHECKRESULT
, OnStnClickedCheckresult
)
73 ON_WM_WINDOWPOSCHANGING()
75 ON_BN_CLICKED(IDC_BUTTON_UPDATE
, OnBnClickedButtonUpdate
)
76 ON_MESSAGE(WM_USER_DISPLAYSTATUS
, OnDisplayStatus
)
77 ON_MESSAGE(WM_USER_ENDDOWNLOAD
, OnEndDownload
)
78 ON_MESSAGE(WM_USER_FILLCHANGELOG
, OnFillChangelog
)
81 BOOL
CCheckForUpdatesDlg::OnInitDialog()
83 CStandAloneDialog::OnInitDialog();
84 CAppUtils::MarkWindowAsUnpinnable(m_hWnd
);
87 temp
.Format(IDS_CHECKNEWER_YOURVERSION
, TGIT_VERMAJOR
, TGIT_VERMINOR
, TGIT_VERMICRO
, TGIT_VERBUILD
);
88 SetDlgItemText(IDC_YOURVERSION
, temp
);
90 DialogEnableWindow(IDOK
, FALSE
);
92 // hide download controls
93 m_ctrlFiles
.ShowWindow(SW_HIDE
);
94 GetDlgItem(IDC_GROUP_DOWNLOADS
)->ShowWindow(SW_HIDE
);
95 RECT rectWindow
, rectGroupDownloads
, rectOKButton
;
96 GetWindowRect(&rectWindow
);
97 GetDlgItem(IDC_GROUP_DOWNLOADS
)->GetWindowRect(&rectGroupDownloads
);
98 GetDlgItem(IDOK
)->GetWindowRect(&rectOKButton
);
99 LONG bottomDistance
= rectWindow
.bottom
- rectOKButton
.bottom
;
100 OffsetRect(&rectOKButton
, 0, rectGroupDownloads
.top
- rectOKButton
.top
);
101 rectWindow
.bottom
= rectOKButton
.bottom
+ bottomDistance
;
102 MoveWindow(&rectWindow
);
103 ::MapWindowPoints(NULL
, GetSafeHwnd(), (LPPOINT
)&rectOKButton
, 2);
104 GetDlgItem(IDOK
)->MoveWindow(&rectOKButton
);
106 temp
.LoadString(IDS_STATUSLIST_COLFILE
);
107 m_ctrlFiles
.InsertColumn(0, temp
, 0, -1);
108 m_ctrlFiles
.InsertColumn(1, temp
, 0, -1);
109 m_ctrlFiles
.SetExtendedStyle(LVS_EX_DOUBLEBUFFER
| LVS_EX_CHECKBOXES
);
110 m_ctrlFiles
.SetColumnWidth(0, 350);
111 m_ctrlFiles
.SetColumnWidth(1, 200);
113 ProjectProperties pp
;
114 pp
.SetCheckRe(_T("[Ii]ssues?:?(\\s*(,|and)?\\s*#?\\d+)+"));
115 pp
.SetBugIDRe(_T("(\\d+)"));
116 pp
.lProjectLanguage
= -1;
117 pp
.sUrl
= _T("http://code.google.com/p/tortoisegit/issues/detail?id=%BUGID%");
118 m_cLogMessage
.Init(pp
);
119 m_cLogMessage
.SetFont((CString
)CRegString(_T("Software\\TortoiseGit\\LogFontName"), _T("Courier New")), (DWORD
)CRegDWORD(_T("Software\\TortoiseGit\\LogFontSize"), 8));
120 m_cLogMessage
.Call(SCI_SETREADONLY
, TRUE
);
122 if (AfxBeginThread(CheckThreadEntry
, this)==NULL
)
124 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
127 SetTimer(100, 1000, NULL
);
131 void CCheckForUpdatesDlg::OnOK()
133 if (m_bThreadRunning
|| m_pDownloadThread
!= NULL
)
134 return; // Don't exit while downloading
136 CStandAloneDialog::OnOK();
139 void CCheckForUpdatesDlg::OnCancel()
141 if (m_bThreadRunning
|| m_pDownloadThread
!= NULL
)
142 return; // Don't exit while downloading
143 CStandAloneDialog::OnCancel();
146 UINT
CCheckForUpdatesDlg::CheckThreadEntry(LPVOID pVoid
)
148 return ((CCheckForUpdatesDlg
*)pVoid
)->CheckThread();
151 UINT
CCheckForUpdatesDlg::CheckThread()
153 m_bThreadRunning
= TRUE
;
156 CString tempfile
= CTempFiles::Instance().GetTempFilePath(true).GetWinPathString();
158 CRegString checkurluser
= CRegString(_T("Software\\TortoiseGit\\UpdateCheckURL"), _T(""));
159 CRegString checkurlmachine
= CRegString(_T("Software\\TortoiseGit\\UpdateCheckURL"), _T(""), FALSE
, HKEY_LOCAL_MACHINE
);
160 CString sCheckURL
= checkurluser
;
161 if (sCheckURL
.IsEmpty())
163 sCheckURL
= checkurlmachine
;
164 if (sCheckURL
.IsEmpty())
166 bool checkPreview
= false;
170 CRegStdDWORD
regCheckPreview(L
"Software\\TortoiseGit\\VersionCheckPreview", FALSE
);
171 if (DWORD(regCheckPreview
))
175 sCheckURL
= _T("http://version.tortoisegit.googlecode.com/git/version-preview.txt");
177 sCheckURL
= _T("http://version.tortoisegit.googlecode.com/git/version.txt");
181 HRESULT res
= URLDownloadToFile(NULL
, sCheckURL
, tempfile
, 0, NULL
);
186 CStdioFile
file(tempfile
, CFile::modeRead
| CFile::shareDenyWrite
);
188 unsigned int major
,minor
,micro
,build
;
189 major
=minor
=micro
=build
=0;
190 unsigned __int64 version
=0;
192 if (file
.ReadString(ver
))
194 CString vertemp
= ver
;
195 // another versionstring for the filename can be provided after a semicolon
196 // this is needed for preview releases
197 int differentFilenamePos
= vertemp
.Find(_T(";"));
198 if (differentFilenamePos
> 0)
200 vertemp
= vertemp
.Left(differentFilenamePos
);
201 ver
= ver
.Mid(differentFilenamePos
+ 1);
204 major
= _ttoi(vertemp
);
205 vertemp
= vertemp
.Mid(vertemp
.Find('.')+1);
206 minor
= _ttoi(vertemp
);
207 vertemp
= vertemp
.Mid(vertemp
.Find('.')+1);
208 micro
= _ttoi(vertemp
);
209 vertemp
= vertemp
.Mid(vertemp
.Find('.')+1);
210 build
= _ttoi(vertemp
);
224 if (major
> TGIT_VERMAJOR
)
226 else if ((minor
> TGIT_VERMINOR
)&&(major
== TGIT_VERMAJOR
))
228 else if ((micro
> TGIT_VERMICRO
)&&(minor
== TGIT_VERMINOR
)&&(major
== TGIT_VERMAJOR
))
230 else if ((build
> TGIT_VERBUILD
)&&(micro
== TGIT_VERMICRO
)&&(minor
== TGIT_VERMINOR
)&&(major
== TGIT_VERMAJOR
))
236 version
.Format(_T("%d.%d.%d.%d"),major
,minor
,micro
,build
);
238 version
+= _T(" (") + ver
+ _T(")");
239 temp
.Format(IDS_CHECKNEWER_CURRENTVERSION
, (LPCTSTR
)version
);
240 SetDlgItemText(IDC_CURRENTVERSION
, temp
);
245 temp
.LoadString(IDS_CHECKNEWER_NETERROR
);
246 SetDlgItemText(IDC_CHECKRESULT
, temp
);
250 if(file
.ReadString(temp
) && !temp
.IsEmpty())
251 { // Read the next line, it could contain a message for the user
253 if(file
.ReadString(tempLink
) && !tempLink
.IsEmpty())
254 { // Read another line to find out the download link-URL, if any
255 m_sUpdateDownloadLink
= tempLink
;
260 temp
.LoadString(IDS_CHECKNEWER_NEWERVERSIONAVAILABLE
);
262 file
.ReadString(tempLink
);
264 SetDlgItemText(IDC_CHECKRESULT
, temp
);
268 FillDownloads(file
, ver
);
270 // Show download controls
271 RECT rectWindow
, rectProgress
, rectGroupDownloads
, rectOKButton
;
272 GetWindowRect(&rectWindow
);
273 m_progress
.GetWindowRect(&rectProgress
);
274 GetDlgItem(IDC_GROUP_DOWNLOADS
)->GetWindowRect(&rectGroupDownloads
);
275 GetDlgItem(IDOK
)->GetWindowRect(&rectOKButton
);
276 LONG bottomDistance
= rectWindow
.bottom
- rectOKButton
.bottom
;
277 OffsetRect(&rectOKButton
, 0, (rectGroupDownloads
.bottom
+ (rectGroupDownloads
.bottom
- rectProgress
.bottom
)) - rectOKButton
.top
);
278 rectWindow
.bottom
= rectOKButton
.bottom
+ bottomDistance
;
279 MoveWindow(&rectWindow
);
280 ::MapWindowPoints(NULL
, GetSafeHwnd(), (LPPOINT
)&rectOKButton
, 2);
281 GetDlgItem(IDOK
)->MoveWindow(&rectOKButton
);
282 m_ctrlFiles
.ShowWindow(SW_SHOW
);
283 GetDlgItem(IDC_GROUP_DOWNLOADS
)->ShowWindow(SW_SHOW
);
288 temp
.LoadString(IDS_CHECKNEWER_YOURUPTODATE
);
289 SetDlgItemText(IDC_CHECKRESULT
, temp
);
290 file
.ReadString(temp
);
291 file
.ReadString(temp
);
296 catch (CException
* e
)
299 temp
.LoadString(IDS_CHECKNEWER_NETERROR
);
300 SetDlgItemText(IDC_CHECKRESULT
, temp
);
305 // Try to cache web page;
307 temp
.LoadString(IDS_CHECKNEWER_NETERROR
);
308 SetDlgItemText(IDC_CHECKRESULT
, temp
);
310 if (!m_sUpdateDownloadLink
.IsEmpty())
312 m_link
.ShowWindow(SW_SHOW
);
313 m_link
.SetURL(m_sUpdateDownloadLink
);
316 DeleteFile(tempfile
);
317 m_bThreadRunning
= FALSE
;
318 DialogEnableWindow(IDOK
, TRUE
);
322 void CCheckForUpdatesDlg::FillDownloads(CStdioFile
&file
, CString version
)
325 const CString x86x64
= _T("64");
327 const CString x86x64
= _T("32");
330 if (!file
.ReadString(m_sFilesURL
) || m_sFilesURL
.IsEmpty())
331 m_sFilesURL
= _T("http://tortoisegit.googlecode.com/files/");
333 m_ctrlFiles
.InsertItem(0, _T("TortoiseGit"));
335 filename
.Format(_T("TortoiseGit-%s-%sbit.msi"), version
, x86x64
);
336 m_ctrlFiles
.SetItemData(0, (DWORD_PTR
)(new CUpdateListCtrl::Entry(filename
, CUpdateListCtrl::STATUS_NONE
)));
337 m_ctrlFiles
.SetCheck(0 , TRUE
);
339 std::vector
<DWORD
> m_installedLangs
;
341 // set up the language selecting combobox
342 CString path
= CPathUtils::GetAppParentDirectory();
343 path
= path
+ _T("Languages\\");
344 CSimpleFileFind
finder(path
, _T("*.dll"));
345 while (finder
.FindNextFileNoDirectories())
347 CString file
= finder
.GetFilePath();
348 CString filename
= finder
.GetFileName();
349 if (filename
.Left(12).CompareNoCase(_T("TortoiseProc")) == 0)
351 CString sVer
= _T(STRPRODUCTVER
);
352 sVer
= sVer
.Left(sVer
.ReverseFind('.'));
353 CString sFileVer
= CPathUtils::GetVersionFromFile(file
);
354 sFileVer
= sFileVer
.Left(sFileVer
.ReverseFind('.'));
355 CString sLoc
= filename
.Mid(12);
356 sLoc
= sLoc
.Left(sLoc
.GetLength() - 4); // cut off ".dll"
357 if ((sLoc
.Left(2) == L
"32") && (sLoc
.GetLength() > 5))
359 DWORD loc
= _tstoi(filename
.Mid(12));
360 m_installedLangs
.push_back(loc
);
366 while (file
.ReadString(langs
) && !langs
.IsEmpty())
368 CString sLang
= _T("TortoiseGit Language Pack ") + langs
.Mid(5);
370 DWORD loc
= _tstoi(langs
.Mid(0, 4));
372 GetLocaleInfo(loc
, LOCALE_SNATIVELANGNAME
, buf
, _countof(buf
));
374 GetLocaleInfo(loc
, LOCALE_SNATIVECTRYNAME
, buf
, _countof(buf
));
382 int pos
= m_ctrlFiles
.InsertItem(m_ctrlFiles
.GetItemCount(), sLang
);
383 m_ctrlFiles
.SetItemText(pos
, 1, sLang2
);
386 filename
.Format(_T("TortoiseGit-LanguagePack-%s-%sbit-%s.msi"), version
, x86x64
, langs
.Mid(5));
387 m_ctrlFiles
.SetItemData(pos
, (DWORD_PTR
)(new CUpdateListCtrl::Entry(filename
, CUpdateListCtrl::STATUS_NONE
)));
389 if (std::find(m_installedLangs
.begin(), m_installedLangs
.end(), loc
) != m_installedLangs
.end())
390 m_ctrlFiles
.SetCheck(pos
, TRUE
);
392 DialogEnableWindow(IDC_BUTTON_UPDATE
, TRUE
);
395 void CCheckForUpdatesDlg::FillChangelog(CStdioFile
&file
)
397 CString sChangelogURL
;
398 if (!file
.ReadString(sChangelogURL
) || sChangelogURL
.IsEmpty())
399 sChangelogURL
= _T("http://tortoisegit.googlecode.com/git/src/Changelog.txt");
401 CString tempchangelogfile
= CTempFiles::Instance().GetTempFilePath(true).GetWinPathString();
402 HRESULT res
= URLDownloadToFile(NULL
, sChangelogURL
, tempchangelogfile
, 0, NULL
);
406 CStdioFile
file(tempchangelogfile
, CFile::modeRead
|CFile::typeText
);
409 while (file
.ReadString(str
))
414 if (str
.GetLength() > 2 && str
.GetAt(0) == 0xEF && str
.GetAt(1) == 0xBB)
416 if (str
.GetAt(2) == 0xBF)
426 str
= CUnicodeUtils::GetUnicode(CStringA(str
), CP_UTF8
);
427 temp
+= str
+ _T("\n");
429 ::SendMessage(m_hWnd
, WM_USER_FILLCHANGELOG
, 0, reinterpret_cast<LPARAM
>(temp
.GetBuffer()));
432 ::SendMessage(m_hWnd
, WM_USER_FILLCHANGELOG
, 0, reinterpret_cast<LPARAM
>(_T("Could not load changelog.")));
435 void CCheckForUpdatesDlg::OnStnClickedCheckresult()
437 // user clicked on the label, start the browser with our web page
438 HINSTANCE result
= ShellExecute(NULL
, _T("opennew"), m_sUpdateDownloadLink
, NULL
,NULL
, SW_SHOWNORMAL
);
439 if ((UINT
)result
<= HINSTANCE_ERROR
)
441 result
= ShellExecute(NULL
, _T("open"), m_sUpdateDownloadLink
, NULL
,NULL
, SW_SHOWNORMAL
);
445 void CCheckForUpdatesDlg::OnTimer(UINT_PTR nIDEvent
)
449 if (m_bThreadRunning
== FALSE
)
454 ShowWindow(SW_SHOWNORMAL
);
462 CStandAloneDialog::OnTimer(nIDEvent
);
465 void CCheckForUpdatesDlg::OnWindowPosChanging(WINDOWPOS
* lpwndpos
)
467 CStandAloneDialog::OnWindowPosChanging(lpwndpos
);
468 if (m_bVisible
== FALSE
)
469 lpwndpos
->flags
&= ~SWP_SHOWWINDOW
;
472 BOOL
CCheckForUpdatesDlg::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
474 if ((!m_sUpdateDownloadLink
.IsEmpty())&&(pWnd
)&&(pWnd
== GetDlgItem(IDC_CHECKRESULT
)))
476 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_HAND
));
481 HCURSOR hCur
= LoadCursor(NULL
, MAKEINTRESOURCE(IDC_ARROW
));
483 return CStandAloneDialogTmpl
<CDialog
>::OnSetCursor(pWnd
, nHitTest
, message
);
486 void CCheckForUpdatesDlg::OnBnClickedButtonUpdate()
489 m_ctrlUpdate
.GetWindowText(title
);
490 if (m_pDownloadThread
== NULL
&& title
== CString(MAKEINTRESOURCE(IDS_PROC_DOWNLOAD
)))
492 bool isOneSelected
= false;
493 for (int i
= 0; i
< (int)m_ctrlFiles
.GetItemCount(); i
++)
495 if (m_ctrlFiles
.GetCheck(i
))
497 isOneSelected
= true;
504 m_eventStop
.ResetEvent();
506 m_pDownloadThread
= ::AfxBeginThread(DownloadThreadEntry
, this, THREAD_PRIORITY_NORMAL
, 0, CREATE_SUSPENDED
);
507 if (m_pDownloadThread
!= NULL
)
509 m_pDownloadThread
->m_bAutoDelete
= FALSE
;
510 m_pDownloadThread
->ResumeThread();
512 GetDlgItem(IDC_BUTTON_UPDATE
)->SetWindowText(CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
)));
516 CMessageBox::Show(NULL
, IDS_ERR_THREADSTARTFAILED
, IDS_APPNAME
, MB_OK
| MB_ICONERROR
);
519 else if (title
== CString(MAKEINTRESOURCE(IDS_ABORTBUTTON
)))
522 m_eventStop
.SetEvent();
526 CString folder
= GetDownloadsDirectory();
527 if (m_ctrlUpdate
.GetCurrentEntry() == 0)
529 for (int i
= 0; i
< (int)m_ctrlFiles
.GetItemCount(); i
++)
531 CUpdateListCtrl::Entry
*data
= (CUpdateListCtrl::Entry
*)m_ctrlFiles
.GetItemData(i
);
532 if (m_ctrlFiles
.GetCheck(i
) == TRUE
)
533 ShellExecute(NULL
, _T("open"), folder
+ data
->m_filename
, NULL
, NULL
, SW_SHOWNORMAL
);
535 CStandAloneDialog::OnOK();
537 else if (m_ctrlUpdate
.GetCurrentEntry() == 1)
539 ShellExecute(NULL
, _T("open"), folder
, NULL
, NULL
, SW_SHOWNORMAL
);
542 m_ctrlUpdate
.SetCurrentEntry(0);
546 UINT
CCheckForUpdatesDlg::DownloadThreadEntry(LPVOID pVoid
)
548 return ((CCheckForUpdatesDlg
*)pVoid
)->DownloadThread();
551 bool CCheckForUpdatesDlg::Download(CString filename
)
553 CString destFilename
= GetDownloadsDirectory() + filename
;
554 if (PathFileExists(destFilename
))
556 if (VerifySignature(destFilename
))
559 DeleteFile(destFilename
);
562 CBSCallbackImpl
bsc(this->GetSafeHwnd(), m_eventStop
);
564 CString url
= m_sFilesURL
+ filename
;
566 m_progress
.SetRange32(0, 1);
567 m_progress
.SetPos(0);
568 m_progress
.ShowWindow(SW_SHOW
);
570 CString tempfile
= CTempFiles::Instance().GetTempFilePath(true).GetWinPathString();
571 HRESULT res
= URLDownloadToFile(NULL
, url
, tempfile
, 0, &bsc
);
574 if (VerifySignature(tempfile
))
576 if (PathFileExists(destFilename
))
577 DeleteFile(destFilename
);
578 MoveFile(tempfile
, destFilename
);
585 UINT
CCheckForUpdatesDlg::DownloadThread()
587 m_ctrlFiles
.SetExtendedStyle(m_ctrlFiles
.GetExtendedStyle() & ~LVS_EX_CHECKBOXES
);
590 for (int i
= 0; i
< (int)m_ctrlFiles
.GetItemCount(); i
++)
592 m_ctrlFiles
.EnsureVisible(i
, FALSE
);
594 m_ctrlFiles
.GetItemRect(i
, &rect
, LVIR_BOUNDS
);
595 CUpdateListCtrl::Entry
*data
= (CUpdateListCtrl::Entry
*)m_ctrlFiles
.GetItemData(i
);
596 if (m_ctrlFiles
.GetCheck(i
) == TRUE
)
598 data
->m_status
= CUpdateListCtrl::STATUS_DOWNLOADING
;
599 m_ctrlFiles
.InvalidateRect(rect
);
600 if (Download(data
->m_filename
))
601 data
->m_status
= CUpdateListCtrl::STATUS_SUCCESS
;
604 data
->m_status
= CUpdateListCtrl::STATUS_FAIL
;
609 data
->m_status
= CUpdateListCtrl::STATUS_IGNORE
;
610 m_ctrlFiles
.InvalidateRect(rect
);
613 ::PostMessage(GetSafeHwnd(), WM_USER_ENDDOWNLOAD
, 0, 0);
618 LRESULT
CCheckForUpdatesDlg::OnEndDownload(WPARAM
, LPARAM
)
620 ASSERT(m_pDownloadThread
!= NULL
);
622 // wait until the thread terminates
624 if (::GetExitCodeThread(m_pDownloadThread
->m_hThread
, &dwExitCode
) && dwExitCode
== STILL_ACTIVE
)
625 ::WaitForSingleObject(m_pDownloadThread
->m_hThread
, INFINITE
);
627 // make sure we always have the correct exit code
628 ::GetExitCodeThread(m_pDownloadThread
->m_hThread
, &dwExitCode
);
630 delete m_pDownloadThread
;
631 m_pDownloadThread
= NULL
;
633 m_progress
.ShowWindow(SW_HIDE
);
635 if (dwExitCode
== TRUE
)
637 m_ctrlUpdate
.AddEntry(CString(MAKEINTRESOURCE(IDS_PROC_INSTALL
)));
638 m_ctrlUpdate
.AddEntry(CString(MAKEINTRESOURCE(IDS_CHECKUPDATE_DESTFOLDER
)));
639 m_ctrlUpdate
.Invalidate();
643 m_ctrlUpdate
.SetWindowText(CString(MAKEINTRESOURCE(IDS_PROC_DOWNLOAD
)));
644 CMessageBox::Show(NULL
, IDS_ERR_FAILEDUPDATEDOWNLOAD
, IDS_APPNAME
, MB_ICONERROR
);
650 LRESULT
CCheckForUpdatesDlg::OnFillChangelog(WPARAM
, LPARAM lParam
)
652 ASSERT(lParam
!= NULL
);
654 TCHAR
* changelog
= reinterpret_cast<TCHAR
*>(lParam
);
655 m_cLogMessage
.Call(SCI_SETREADONLY
, FALSE
);
656 m_cLogMessage
.SetText(changelog
);
657 m_cLogMessage
.Call(SCI_SETREADONLY
, TRUE
);
658 m_cLogMessage
.Call(SCI_GOTOPOS
, 0);
663 CString
CCheckForUpdatesDlg::GetDownloadsDirectory()
667 if (SysInfo::Instance().IsVistaOrLater())
669 CAutoLibrary hShell
= ::LoadLibrary(_T("shell32.dll"));
672 typedef HRESULT STDAPICALLTYPE
SHGetKnownFolderPathFN(__in REFKNOWNFOLDERID rfid
, __in DWORD dwFlags
, __in_opt HANDLE hToken
, __deref_out PWSTR
*ppszPath
);
673 SHGetKnownFolderPathFN
*pfnSHGetKnownFolderPath
= (SHGetKnownFolderPathFN
*)GetProcAddress(hShell
, "SHGetKnownFolderPath");
674 if (pfnSHGetKnownFolderPath
)
676 wchar_t * wcharPtr
= 0;
677 HRESULT hr
= pfnSHGetKnownFolderPath(FOLDERID_Downloads
, KF_FLAG_CREATE
, NULL
, &wcharPtr
);
681 CoTaskMemFree(static_cast<void*>(wcharPtr
));
682 return folder
.TrimRight(_T("\\")) + _T("\\");
688 TCHAR szPath
[MAX_PATH
];
689 if (SUCCEEDED(SHGetFolderPath(NULL
, CSIDL_PERSONAL
| CSIDL_FLAG_CREATE
, NULL
, SHGFP_TYPE_CURRENT
, szPath
)))
691 CString downloads
= folder
.TrimRight(_T("\\")) + _T("\\Downloads\\");
692 if ((PathFileExists(downloads
) && PathIsDirectory(downloads
)) || (!PathFileExists(downloads
) && CreateDirectory(downloads
, NULL
)))
698 LRESULT
CCheckForUpdatesDlg::OnDisplayStatus(WPARAM
, LPARAM lParam
)
700 const DOWNLOADSTATUS
*const pDownloadStatus
= reinterpret_cast<DOWNLOADSTATUS
*>(lParam
);
701 if (pDownloadStatus
!= NULL
)
703 ASSERT(::AfxIsValidAddress(pDownloadStatus
, sizeof(DOWNLOADSTATUS
)));
705 m_progress
.SetRange32(0, pDownloadStatus
->ulProgressMax
);
706 m_progress
.SetPos(pDownloadStatus
->ulProgress
);
712 CBSCallbackImpl::CBSCallbackImpl(HWND hWnd
, HANDLE hEventStop
)
715 m_hEventStop
= hEventStop
;
720 STDMETHODIMP
CBSCallbackImpl::QueryInterface(REFIID riid
, void **ppvObject
)
725 if (::IsEqualIID(riid
, __uuidof(IUnknown
)))
728 // IBindStatusCallback
729 else if (::IsEqualIID(riid
, __uuidof(IBindStatusCallback
)))
730 *ppvObject
= static_cast<IBindStatusCallback
*>(this);
734 (*reinterpret_cast<LPUNKNOWN
*>(ppvObject
))->AddRef();
738 return E_NOINTERFACE
;
741 STDMETHODIMP_(ULONG
) CBSCallbackImpl::AddRef()
743 return ++m_ulObjRefCount
;
746 STDMETHODIMP_(ULONG
) CBSCallbackImpl::Release()
748 return --m_ulObjRefCount
;
751 // IBindStatusCallback
752 STDMETHODIMP
CBSCallbackImpl::OnStartBinding(DWORD
, IBinding
*)
757 STDMETHODIMP
CBSCallbackImpl::GetPriority(LONG
*)
761 STDMETHODIMP
CBSCallbackImpl::OnLowResource(DWORD
)
766 STDMETHODIMP
CBSCallbackImpl::OnProgress(ULONG ulProgress
, ULONG ulProgressMax
, ULONG ulStatusCode
, LPCWSTR
/* szStatusText */)
768 TRACE(_T("IBindStatusCallback::OnProgress\n"));
769 TRACE(_T("ulProgress: %lu, ulProgressMax: %lu\n"), ulProgress
, ulProgressMax
);
770 UNREFERENCED_PARAMETER(ulStatusCode
);
771 TRACE(_T("ulStatusCode: %lu "), ulStatusCode
);
775 // inform the dialog box to display current status,
776 // don't use PostMessage
777 CCheckForUpdatesDlg::DOWNLOADSTATUS downloadStatus
= { ulProgress
, ulProgressMax
};
778 ::SendMessage(m_hWnd
, WM_USER_DISPLAYSTATUS
, 0, reinterpret_cast<LPARAM
>(&downloadStatus
));
781 if (m_hEventStop
!= NULL
&& ::WaitForSingleObject(m_hEventStop
, 0) == WAIT_OBJECT_0
)
783 return E_ABORT
; // canceled by the user
789 STDMETHODIMP
CBSCallbackImpl::OnStopBinding(HRESULT
, LPCWSTR
)
794 STDMETHODIMP
CBSCallbackImpl::GetBindInfo(DWORD
*, BINDINFO
*)
799 STDMETHODIMP
CBSCallbackImpl::OnDataAvailable(DWORD
, DWORD
, FORMATETC
*, STGMEDIUM
*)
804 STDMETHODIMP
CBSCallbackImpl::OnObjectAvailable(REFIID
, IUnknown
*)
809 BOOL
CCheckForUpdatesDlg::VerifySignature(CString fileName
)
811 WINTRUST_FILE_INFO fileInfo
;
812 memset(&fileInfo
, 0, sizeof(fileInfo
));
813 fileInfo
.cbStruct
= sizeof(WINTRUST_FILE_INFO
);
814 fileInfo
.pcwszFilePath
= fileName
;
817 memset(&data
, 0, sizeof(data
));
818 data
.cbStruct
= sizeof(data
);
820 data
.dwUIChoice
= WTD_UI_NONE
;
821 data
.fdwRevocationChecks
= WTD_REVOKE_NONE
;
822 data
.dwUnionChoice
= WTD_CHOICE_FILE
;
823 data
.pFile
= &fileInfo
;
825 GUID policyGUID
= WINTRUST_ACTION_GENERIC_VERIFY_V2
;
827 return (WinVerifyTrust(NULL
, &policyGUID
, &data
) == ERROR_SUCCESS
);