2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * FILE: base/applications/rapps/loaddlg.cpp
5 * PURPOSE: Displaying a download dialog
6 * COPYRIGHT: Copyright 2001 John R. Sheets (for CodeWeavers)
7 * Copyright 2004 Mike McCormack (for CodeWeavers)
8 * Copyright 2005 Ge van Geldorp (gvg@reactos.org)
9 * Copyright 2009 Dmitry Chapyshev (dmitry@reactos.org)
10 * Copyright 2015 Ismael Ferreras Morezuelas (swyterzone+ros@gmail.com)
11 * Copyright 2017 Alexander Shaposhnikov (sanchaez@reactos.org)
15 * Based on Wine dlls/shdocvw/shdocvw_main.c
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License as published by the Free Software Foundation; either
20 * version 2.1 of the License, or (at your option) any later version.
22 * This library is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25 * Lesser General Public License for more details.
27 * You should have received a copy of the GNU Lesser General Public
28 * License along with this library; if not, write to the Free Software
29 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
33 #include <shlobj_undoc.h>
34 #include <shlguid_undoc.h>
40 #include <shellutils.h>
49 #ifdef USE_CERT_PINNING
50 #define CERT_ISSUER_INFO "US\r\nLet's Encrypt\r\nLet's Encrypt Authority X3"
51 #define CERT_SUBJECT_INFO "rapps.reactos.org"
56 DLSTATUS_WAITING
= IDS_STATUS_WAITING
,
57 DLSTATUS_DOWNLOADING
= IDS_STATUS_DOWNLOADING
,
58 DLSTATUS_WAITING_INSTALL
= IDS_STATUS_DOWNLOADED
,
59 DLSTATUS_INSTALLING
= IDS_STATUS_INSTALLING
,
60 DLSTATUS_INSTALLED
= IDS_STATUS_INSTALLED
,
61 DLSTATUS_FINISHED
= IDS_STATUS_FINISHED
64 ATL::CStringW
LoadStatusString(DownloadStatus StatusParam
)
66 ATL::CStringW szString
;
67 szString
.LoadStringW(StatusParam
);
74 DownloadInfo(const CAvailableApplicationInfo
& AppInfo
)
75 :szUrl(AppInfo
.m_szUrlDownload
), szName(AppInfo
.m_szName
), szSHA1(AppInfo
.m_szSHA1
)
86 DownloadParam() : Dialog(NULL
), AppInfo(), szCaption(NULL
) {}
87 DownloadParam(HWND dlg
, const ATL::CSimpleArray
<DownloadInfo
> &info
, LPCWSTR caption
)
88 : Dialog(dlg
), AppInfo(info
), szCaption(caption
)
93 ATL::CSimpleArray
<DownloadInfo
> AppInfo
;
98 class CDownloadDialog
:
99 public CComObjectRootEx
<CComMultiThreadModelNoCS
>,
100 public IBindStatusCallback
104 BOOL m_UrlHasBeenCopied
;
109 //DestroyWindow(m_hDialog);
112 HRESULT
Initialize(HWND Dlg
, BOOL
*pbCancelled
)
115 m_pbCancelled
= pbCancelled
;
116 m_UrlHasBeenCopied
= FALSE
;
120 virtual HRESULT STDMETHODCALLTYPE
OnStartBinding(
127 virtual HRESULT STDMETHODCALLTYPE
GetPriority(
133 virtual HRESULT STDMETHODCALLTYPE
OnLowResource(
139 virtual HRESULT STDMETHODCALLTYPE
OnProgress(
143 LPCWSTR szStatusText
)
148 Item
= GetDlgItem(m_hDialog
, IDC_DOWNLOAD_PROGRESS
);
151 WCHAR szProgress
[100];
153 /* format the bits and bytes into pretty and accessible units... */
154 StrFormatByteSizeW(ulProgress
, szProgress
, _countof(szProgress
));
156 /* use our subclassed progress bar text subroutine */
157 ATL::CStringW m_ProgressText
;
161 /* total size is known */
162 WCHAR szProgressMax
[100];
163 UINT uiPercentage
= ((ULONGLONG
) ulProgress
* 100) / ulProgressMax
;
165 /* send the current progress to the progress bar */
166 SendMessageW(Item
, PBM_SETPOS
, uiPercentage
, 0);
168 /* format total download size */
169 StrFormatByteSizeW(ulProgressMax
, szProgressMax
, _countof(szProgressMax
));
171 /* generate the text on progress bar */
172 m_ProgressText
.Format(L
"%u%% \x2014 %ls / %ls",
179 /* send the current progress to the progress bar */
180 SendMessageW(Item
, PBM_SETPOS
, 0, 0);
182 /* total size is not known, display only current size */
183 m_ProgressText
.Format(L
"%ls...",
186 /* and finally display it */
187 SendMessageW(Item
, WM_SETTEXT
, 0, (LPARAM
) m_ProgressText
.GetString());
190 Item
= GetDlgItem(m_hDialog
, IDC_DOWNLOAD_STATUS
);
191 if (Item
&& szStatusText
&& wcslen(szStatusText
) > 0 && m_UrlHasBeenCopied
== FALSE
)
193 DWORD len
= wcslen(szStatusText
) + 1;
196 /* beautify our url for display purposes */
197 if (!InternetCanonicalizeUrlW(szStatusText
, buf
.GetBuffer(len
), &len
, ICU_DECODE
| ICU_NO_ENCODE
))
199 /* just use the original */
208 /* paste it into our dialog and don't do it again in this instance */
209 SendMessageW(Item
, WM_SETTEXT
, 0, (LPARAM
) buf
.GetString());
210 m_UrlHasBeenCopied
= TRUE
;
213 SetLastError(ERROR_SUCCESS
);
214 r
= GetWindowLongPtrW(m_hDialog
, GWLP_USERDATA
);
215 if (r
|| GetLastError() != ERROR_SUCCESS
)
217 *m_pbCancelled
= TRUE
;
224 virtual HRESULT STDMETHODCALLTYPE
OnStopBinding(
231 virtual HRESULT STDMETHODCALLTYPE
GetBindInfo(
238 virtual HRESULT STDMETHODCALLTYPE
OnDataAvailable(
241 FORMATETC
*pformatetc
,
247 virtual HRESULT STDMETHODCALLTYPE
OnObjectAvailable(
254 BEGIN_COM_MAP(CDownloadDialog
)
255 COM_INTERFACE_ENTRY_IID(IID_IBindStatusCallback
, IBindStatusCallback
)
259 class CDowloadingAppsListView
260 : public CUiWindow
<CListView
>
263 HWND
Create(HWND hwndParent
)
265 RECT r
= {10, 150, 320, 350};
266 const DWORD style
= WS_CHILD
| WS_VISIBLE
| LVS_REPORT
| LVS_SINGLESEL
267 | LVS_SHOWSELALWAYS
| LVS_NOSORTHEADER
| LVS_NOCOLUMNHEADER
;
269 HWND hwnd
= CListView::Create(hwndParent
, r
, NULL
, style
, WS_EX_CLIENTEDGE
);
271 AddColumn(0, 150, LVCFMT_LEFT
);
272 AddColumn(1, 120, LVCFMT_LEFT
);
277 VOID
LoadList(ATL::CSimpleArray
<DownloadInfo
> arrInfo
)
279 for (INT i
= 0; i
< arrInfo
.GetSize(); ++i
)
281 AddRow(i
, arrInfo
[i
].szName
.GetString(), DLSTATUS_WAITING
);
285 VOID
SetDownloadStatus(INT ItemIndex
, DownloadStatus Status
)
287 HWND hListView
= GetWindow();
288 ATL::CStringW szBuffer
= LoadStatusString(Status
);
289 ListView_SetItemText(hListView
, ItemIndex
, 1, const_cast<LPWSTR
>(szBuffer
.GetString()));
292 BOOL
AddItem(INT ItemIndex
, LPWSTR lpText
)
296 ZeroMemory(&Item
, sizeof(Item
));
298 Item
.mask
= LVIF_TEXT
| LVIF_STATE
;
299 Item
.pszText
= lpText
;
300 Item
.iItem
= ItemIndex
;
302 return InsertItem(&Item
);
305 VOID
AddRow(INT RowIndex
, LPCWSTR szAppName
, const DownloadStatus Status
)
307 ATL::CStringW szStatus
= LoadStatusString(Status
);
309 const_cast<LPWSTR
>(szAppName
));
310 SetDownloadStatus(RowIndex
, Status
);
313 BOOL
AddColumn(INT Index
, INT Width
, INT Format
)
316 ZeroMemory(&Column
, sizeof(Column
));
318 Column
.mask
= LVCF_FMT
| LVCF_WIDTH
| LVCF_SUBITEM
;
319 Column
.iSubItem
= Index
;
323 return (InsertColumn(Index
, &Column
) == -1) ? FALSE
: TRUE
;
328 HRESULT WINAPI
CDownloadDialog_Constructor(HWND Dlg
, BOOL
*pbCancelled
, REFIID riid
, LPVOID
*ppv
)
330 return ShellObjectCreatorInit
<CDownloadDialog
>(Dlg
, pbCancelled
, riid
, ppv
);
333 #ifdef USE_CERT_PINNING
334 typedef CHeapPtr
<char, CLocalAllocator
> CLocalPtr
;
336 static BOOL
CertGetSubjectAndIssuer(HINTERNET hFile
, CLocalPtr
& subjectInfo
, CLocalPtr
& issuerInfo
)
338 DWORD certInfoLength
;
339 INTERNET_CERTIFICATE_INFOA certInfo
;
342 size
= sizeof(flags
);
343 if (!InternetQueryOptionA(hFile
, INTERNET_OPTION_SECURITY_FLAGS
, &flags
, &size
))
348 if (!flags
& SECURITY_FLAG_SECURE
)
353 /* Despite what the header indicates, the implementation of INTERNET_CERTIFICATE_INFO is not Unicode-aware. */
354 certInfoLength
= sizeof(certInfo
);
355 if (!InternetQueryOptionA(hFile
,
356 INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
363 subjectInfo
.Attach(certInfo
.lpszSubjectInfo
);
364 issuerInfo
.Attach(certInfo
.lpszIssuerInfo
);
366 if (certInfo
.lpszProtocolName
)
367 LocalFree(certInfo
.lpszProtocolName
);
368 if (certInfo
.lpszSignatureAlgName
)
369 LocalFree(certInfo
.lpszSignatureAlgName
);
370 if (certInfo
.lpszEncryptionAlgName
)
371 LocalFree(certInfo
.lpszEncryptionAlgName
);
373 return certInfo
.lpszSubjectInfo
&& certInfo
.lpszIssuerInfo
;
377 inline VOID
MessageBox_LoadString(HWND hMainWnd
, INT StringID
)
379 ATL::CStringW szMsgText
;
380 if (szMsgText
.LoadStringW(StringID
))
382 MessageBoxW(hMainWnd
, szMsgText
.GetString(), NULL
, MB_OK
| MB_ICONERROR
);
387 ATL::CSimpleArray
<DownloadInfo
> CDownloadManager::AppsToInstallList
;
388 CDowloadingAppsListView
CDownloadManager::DownloadsListView
;
390 VOID
CDownloadManager::Download(const DownloadInfo
&DLInfo
, BOOL bIsModal
)
392 AppsToInstallList
.RemoveAll();
393 AppsToInstallList
.Add(DLInfo
);
394 LaunchDownloadDialog(bIsModal
);
397 INT_PTR CALLBACK
CDownloadManager::DownloadDlgProc(HWND Dlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
399 static WCHAR szCaption
[MAX_PATH
];
405 HICON hIconSm
, hIconBg
;
406 ATL::CStringW szTempCaption
;
408 hIconBg
= (HICON
) GetClassLongW(hMainWnd
, GCLP_HICON
);
409 hIconSm
= (HICON
) GetClassLongW(hMainWnd
, GCLP_HICONSM
);
411 if (hIconBg
&& hIconSm
)
413 SendMessageW(Dlg
, WM_SETICON
, ICON_BIG
, (LPARAM
) hIconBg
);
414 SendMessageW(Dlg
, WM_SETICON
, ICON_SMALL
, (LPARAM
) hIconSm
);
417 SetWindowLongW(Dlg
, GWLP_USERDATA
, 0);
418 HWND Item
= GetDlgItem(Dlg
, IDC_DOWNLOAD_PROGRESS
);
421 // initialize the default values for our nifty progress bar
422 // and subclass it so that it learns to print a status text
423 SendMessageW(Item
, PBM_SETRANGE
, 0, MAKELPARAM(0, 100));
424 SendMessageW(Item
, PBM_SETPOS
, 0, 0);
426 SetWindowSubclass(Item
, DownloadProgressProc
, 0, 0);
430 HWND hListView
= DownloadsListView
.Create(Dlg
);
435 DownloadsListView
.LoadList(AppsToInstallList
);
437 // Get a dlg string for later use
438 GetWindowTextW(Dlg
, szCaption
, _countof(szCaption
));
440 // Hide a placeholder from displaying
441 szTempCaption
= szCaption
;
442 szTempCaption
.Replace(L
"%ls", L
"");
443 SetWindowText(Dlg
, szTempCaption
.GetString());
445 ShowWindow(Dlg
, SW_SHOW
);
447 // Start download process
448 DownloadParam
*param
= new DownloadParam(Dlg
, AppsToInstallList
, szCaption
);
450 HANDLE Thread
= CreateThread(NULL
, 0, ThreadFunc
, (LPVOID
) param
, 0, &ThreadId
);
458 AppsToInstallList
.RemoveAll();
463 if (wParam
== IDCANCEL
)
465 SetWindowLongW(Dlg
, GWLP_USERDATA
, 1);
466 PostMessageW(Dlg
, WM_CLOSE
, 0, 0);
472 //DestroyWindow(Dlg);
480 LRESULT CALLBACK
CDownloadManager::DownloadProgressProc(HWND hWnd
,
484 UINT_PTR uIdSubclass
,
487 static ATL::CStringW szProgressText
;
495 szProgressText
= (PCWSTR
) lParam
;
504 HDC hDC
= BeginPaint(hWnd
, &ps
), hdcMem
;
508 UINT win_width
, win_height
;
510 GetClientRect(hWnd
, &myRect
);
512 /* grab the progress bar rect size */
513 win_width
= myRect
.right
- myRect
.left
;
514 win_height
= myRect
.bottom
- myRect
.top
;
516 /* create an off-screen DC for double-buffering */
517 hdcMem
= CreateCompatibleDC(hDC
);
518 hbmMem
= CreateCompatibleBitmap(hDC
, win_width
, win_height
);
520 hOld
= SelectObject(hdcMem
, hbmMem
);
522 /* call the original draw code and redirect it to our memory buffer */
523 DefSubclassProc(hWnd
, uMsg
, (WPARAM
) hdcMem
, lParam
);
525 /* draw our nifty progress text over it */
526 SelectFont(hdcMem
, GetStockFont(DEFAULT_GUI_FONT
));
527 DrawShadowText(hdcMem
, szProgressText
.GetString(), szProgressText
.GetLength(),
529 DT_CENTER
| DT_VCENTER
| DT_NOPREFIX
| DT_SINGLELINE
,
530 GetSysColor(COLOR_CAPTIONTEXT
),
531 GetSysColor(COLOR_3DSHADOW
),
534 /* transfer the off-screen DC to the screen */
535 BitBlt(hDC
, 0, 0, win_width
, win_height
, hdcMem
, 0, 0, SRCCOPY
);
537 /* free the off-screen DC */
538 SelectObject(hdcMem
, hOld
);
539 DeleteObject(hbmMem
);
546 /* Raymond Chen says that we should safely unsubclass all the things!
547 (http://blogs.msdn.com/b/oldnewthing/archive/2003/11/11/55653.aspx) */
551 szProgressText
.Empty();
552 RemoveWindowSubclass(hWnd
, DownloadProgressProc
, uIdSubclass
);
556 return DefSubclassProc(hWnd
, uMsg
, wParam
, lParam
);
560 VOID
CDownloadManager::SetProgressMarquee(HWND Item
, BOOL Enable
)
565 DWORD style
= GetWindowLongPtr(Item
, GWL_STYLE
);
569 if (!SetWindowLongPtr(Item
, GWL_STYLE
, (Enable
? style
| PBS_MARQUEE
: style
& ~PBS_MARQUEE
)))
572 SendMessageW(Item
, PBM_SETMARQUEE
, Enable
, 0);
575 DWORD WINAPI
CDownloadManager::ThreadFunc(LPVOID param
)
577 CComPtr
<IBindStatusCallback
> dl
;
581 HWND hDlg
= static_cast<DownloadParam
*>(param
)->Dialog
;
585 ULONG dwContentLen
, dwBytesWritten
, dwBytesRead
, dwStatus
;
586 ULONG dwCurrentBytesRead
= 0;
587 ULONG dwStatusLen
= sizeof(dwStatus
);
589 BOOL bCancelled
= FALSE
;
590 BOOL bTempfile
= FALSE
;
593 HINTERNET hOpen
= NULL
;
594 HINTERNET hFile
= NULL
;
595 HANDLE hOut
= INVALID_HANDLE_VALUE
;
597 unsigned char lpBuffer
[4096];
598 LPCWSTR lpszAgent
= L
"RApps/1.0";
599 URL_COMPONENTS urlComponents
;
600 size_t urlLength
, filenameLength
;
602 const ATL::CSimpleArray
<DownloadInfo
> &InfoArray
= static_cast<DownloadParam
*>(param
)->AppInfo
;
603 LPCWSTR szCaption
= static_cast<DownloadParam
*>(param
)->szCaption
;
604 ATL::CStringW szNewCaption
;
606 if (InfoArray
.GetSize() <= 0)
608 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_DOWNLOAD
);
612 for (iAppId
= 0; iAppId
< InfoArray
.GetSize(); ++iAppId
)
614 // Reset progress bar
615 Item
= GetDlgItem(hDlg
, IDC_DOWNLOAD_PROGRESS
);
618 SetProgressMarquee(Item
, FALSE
);
619 SendMessageW(Item
, WM_SETTEXT
, 0, (LPARAM
) L
"");
620 SendMessageW(Item
, PBM_SETPOS
, 0, 0);
623 // is this URL an update package for RAPPS? if so store it in a different place
624 if (InfoArray
[iAppId
].szUrl
== APPLICATION_DATABASE_URL
)
627 if (!GetStorageDirectory(Path
))
633 Path
= SettingsInfo
.szDownloadDir
;
636 // Change caption to show the currently downloaded app
639 szNewCaption
.Format(szCaption
, InfoArray
[iAppId
].szName
.GetString());
643 szNewCaption
.LoadStringW(IDS_DL_DIALOG_DB_DOWNLOAD_DISP
);
646 SetWindowTextW(hDlg
, szNewCaption
.GetString());
648 // build the path for the download
649 p
= wcsrchr(InfoArray
[iAppId
].szUrl
.GetString(), L
'/');
650 q
= wcsrchr(InfoArray
[iAppId
].szUrl
.GetString(), L
'?');
652 // do we have a final slash separator?
656 // prepare the tentative length of the filename, maybe we've to remove part of it later on
657 filenameLength
= wcslen(p
) * sizeof(WCHAR
);
659 /* do we have query arguments in the target URL after the filename? account for them
660 (e.g. https://example.org/myfile.exe?no_adware_plz) */
661 if (q
&& q
> p
&& (q
- p
) > 0)
662 filenameLength
-= wcslen(q
- 1) * sizeof(WCHAR
);
664 // is the path valid? can we access it?
665 if (GetFileAttributesW(Path
.GetString()) == INVALID_FILE_ATTRIBUTES
)
667 if (!CreateDirectoryW(Path
.GetString(), NULL
))
671 // append a \ to the provided file system path, and the filename portion from the URL after that
673 Path
+= (LPWSTR
) (p
+ 1);
675 if (!bCab
&& InfoArray
[iAppId
].szSHA1
[0] && GetFileAttributesW(Path
.GetString()) != INVALID_FILE_ATTRIBUTES
)
677 // only open it in case of total correctness
678 if (VerifyInteg(InfoArray
[iAppId
].szSHA1
.GetString(), Path
))
682 // Add the download URL
683 SetDlgItemTextW(hDlg
, IDC_DOWNLOAD_STATUS
, InfoArray
[iAppId
].szUrl
.GetString());
685 DownloadsListView
.SetDownloadStatus(iAppId
, DLSTATUS_DOWNLOADING
);
689 CDownloadDialog_Constructor(hDlg
, &bCancelled
, IID_PPV_ARG(IBindStatusCallback
, &dl
));
694 /* FIXME: this should just be using the system-wide proxy settings */
695 switch (SettingsInfo
.Proxy
)
699 hOpen
= InternetOpenW(lpszAgent
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
701 case 1: // direct (no proxy)
702 hOpen
= InternetOpenW(lpszAgent
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
705 hOpen
= InternetOpenW(lpszAgent
, INTERNET_OPEN_TYPE_PROXY
, SettingsInfo
.szProxyServer
, SettingsInfo
.szNoProxyFor
, 0);
712 hFile
= InternetOpenUrlW(hOpen
, InfoArray
[iAppId
].szUrl
.GetString(), NULL
, 0,
713 INTERNET_FLAG_DONT_CACHE
| INTERNET_FLAG_PRAGMA_NOCACHE
| INTERNET_FLAG_KEEP_CONNECTION
,
718 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_DOWNLOAD2
);
722 dwStatusLen
= sizeof(dwStatus
);
724 memset(&urlComponents
, 0, sizeof(urlComponents
));
725 urlComponents
.dwStructSize
= sizeof(urlComponents
);
727 urlLength
= InfoArray
[iAppId
].szUrl
.GetLength();
728 urlComponents
.dwSchemeLength
= urlLength
+ 1;
729 urlComponents
.lpszScheme
= (LPWSTR
) malloc(urlComponents
.dwSchemeLength
* sizeof(WCHAR
));
730 urlComponents
.dwHostNameLength
= urlLength
+ 1;
731 urlComponents
.lpszHostName
= (LPWSTR
) malloc(urlComponents
.dwHostNameLength
* sizeof(WCHAR
));
733 if (!InternetCrackUrlW(InfoArray
[iAppId
].szUrl
, urlLength
+ 1, ICU_DECODE
| ICU_ESCAPE
, &urlComponents
))
738 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
|| urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
)
741 if (!HttpQueryInfoW(hFile
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &dwStatus
, &dwStatusLen
, NULL
))
744 if (dwStatus
!= HTTP_STATUS_OK
)
746 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_DOWNLOAD
);
750 // query content length
751 HttpQueryInfoW(hFile
, HTTP_QUERY_CONTENT_LENGTH
| HTTP_QUERY_FLAG_NUMBER
, &dwContentLen
, &dwStatusLen
, NULL
);
754 if (urlComponents
.nScheme
== INTERNET_SCHEME_FTP
)
756 dwContentLen
= FtpGetFileSize(hFile
, &dwStatus
);
761 // content-length is not known, enable marquee mode
762 SetProgressMarquee(Item
, TRUE
);
765 free(urlComponents
.lpszScheme
);
766 free(urlComponents
.lpszHostName
);
768 #ifdef USE_CERT_PINNING
769 // are we using HTTPS to download the RAPPS update package? check if the certificate is original
770 if ((urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) &&
771 (wcscmp(InfoArray
[iAppId
].szUrl
, APPLICATION_DATABASE_URL
) == 0))
773 CLocalPtr subjectName
, issuerName
;
775 bool bAskQuestion
= false;
776 if (!CertGetSubjectAndIssuer(hFile
, subjectName
, issuerName
))
778 szMsgText
.LoadStringW(IDS_UNABLE_TO_QUERY_CERT
);
783 if (strcmp(subjectName
, CERT_SUBJECT_INFO
) ||
784 strcmp(issuerName
, CERT_ISSUER_INFO
))
786 szMsgText
.Format(IDS_MISMATCH_CERT_INFO
, (char*)subjectName
, (const char*)issuerName
);
793 if (MessageBoxW(hMainWnd
, szMsgText
.GetString(), NULL
, MB_YESNO
| MB_ICONERROR
) != IDYES
)
801 hOut
= CreateFileW(Path
.GetString(), GENERIC_WRITE
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, CREATE_ALWAYS
, 0, NULL
);
803 if (hOut
== INVALID_HANDLE_VALUE
)
806 dwCurrentBytesRead
= 0;
809 if (!InternetReadFile(hFile
, lpBuffer
, _countof(lpBuffer
), &dwBytesRead
))
811 MessageBox_LoadString(hMainWnd
, IDS_INTERRUPTED_DOWNLOAD
);
815 if (!WriteFile(hOut
, &lpBuffer
[0], dwBytesRead
, &dwBytesWritten
, NULL
))
817 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_WRITE
);
821 dwCurrentBytesRead
+= dwBytesRead
;
822 dl
->OnProgress(dwCurrentBytesRead
, dwContentLen
, 0, InfoArray
[iAppId
].szUrl
.GetString());
823 } while (dwBytesRead
&& !bCancelled
);
826 hOut
= INVALID_HANDLE_VALUE
;
833 // set progress bar to 100%
834 SetProgressMarquee(Item
, FALSE
);
836 dwContentLen
= dwCurrentBytesRead
;
837 dl
->OnProgress(dwCurrentBytesRead
, dwContentLen
, 0, InfoArray
[iAppId
].szUrl
.GetString());
840 /* if this thing isn't a RAPPS update and it has a SHA-1 checksum
841 verify its integrity by using the native advapi32.A_SHA1 functions */
842 if (!bCab
&& InfoArray
[iAppId
].szSHA1
[0] != 0)
844 ATL::CStringW szMsgText
;
846 // change a few strings in the download dialog to reflect the verification process
847 if (!szMsgText
.LoadStringW(IDS_INTEG_CHECK_TITLE
))
850 SetWindowTextW(hDlg
, szMsgText
.GetString());
851 SendMessageW(GetDlgItem(hDlg
, IDC_DOWNLOAD_STATUS
), WM_SETTEXT
, 0, (LPARAM
) Path
.GetString());
853 // this may take a while, depending on the file size
854 if (!VerifyInteg(InfoArray
[iAppId
].szSHA1
.GetString(), Path
.GetString()))
856 if (!szMsgText
.LoadStringW(IDS_INTEG_CHECK_FAIL
))
859 MessageBoxW(hDlg
, szMsgText
.GetString(), NULL
, MB_OK
| MB_ICONERROR
);
865 DownloadsListView
.SetDownloadStatus(iAppId
, DLSTATUS_WAITING_INSTALL
);
870 SHELLEXECUTEINFOW shExInfo
= {0};
871 shExInfo
.cbSize
= sizeof(shExInfo
);
872 shExInfo
.fMask
= SEE_MASK_NOCLOSEPROCESS
;
873 shExInfo
.lpVerb
= L
"open";
874 shExInfo
.lpFile
= Path
.GetString();
875 shExInfo
.lpParameters
= L
"";
876 shExInfo
.nShow
= SW_SHOW
;
878 if (ShellExecuteExW(&shExInfo
))
880 //reflect installation progress in the titlebar
881 //TODO: make a separate string with a placeholder to include app name?
882 ATL::CStringW szMsgText
= LoadStatusString(DLSTATUS_INSTALLING
);
883 SetWindowTextW(hDlg
, szMsgText
.GetString());
885 DownloadsListView
.SetDownloadStatus(iAppId
, DLSTATUS_INSTALLING
);
887 //TODO: issue an install operation separately so that the apps could be downloaded in the background
888 WaitForSingleObject(shExInfo
.hProcess
, INFINITE
);
889 CloseHandle(shExInfo
.hProcess
);
893 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_INSTALL
);
898 if (hOut
!= INVALID_HANDLE_VALUE
)
901 InternetCloseHandle(hFile
);
902 InternetCloseHandle(hOpen
);
906 if (bCancelled
|| (SettingsInfo
.bDelInstaller
&& !bCab
))
907 DeleteFileW(Path
.GetString());
910 DownloadsListView
.SetDownloadStatus(iAppId
, DLSTATUS_FINISHED
);
913 delete static_cast<DownloadParam
*>(param
);
914 SendMessageW(hDlg
, WM_CLOSE
, 0, 0);
918 BOOL
CDownloadManager::DownloadListOfApplications(const ATL::CSimpleArray
<CAvailableApplicationInfo
>& AppsList
, BOOL bIsModal
)
920 if (AppsList
.GetSize() == 0)
923 // Initialize shared variables
924 for (INT i
= 0; i
< AppsList
.GetSize(); ++i
)
926 AppsToInstallList
.Add(AppsList
[i
]); // implicit conversion to DownloadInfo
929 // Create a dialog and issue a download process
930 LaunchDownloadDialog(bIsModal
);
935 BOOL
CDownloadManager::DownloadApplication(CAvailableApplicationInfo
* pAppInfo
, BOOL bIsModal
)
940 Download(*pAppInfo
, bIsModal
);
944 VOID
CDownloadManager::DownloadApplicationsDB(LPCWSTR lpUrl
)
946 static DownloadInfo DatabaseDLInfo
;
947 DatabaseDLInfo
.szUrl
= lpUrl
;
948 DatabaseDLInfo
.szName
.LoadStringW(IDS_DL_DIALOG_DB_DISP
);
949 Download(DatabaseDLInfo
, TRUE
);
952 //TODO: Reuse the dialog
953 VOID
CDownloadManager::LaunchDownloadDialog(BOOL bIsModal
)
958 MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG
),
965 MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG
),