1 /* PROJECT: ReactOS Applications Manager
2 * LICENSE: GPL - See COPYING in the top level directory
3 * FILE: base/applications/rapps/loaddlg.cpp
4 * PURPOSE: Displaying a download dialog
5 * COPYRIGHT: Copyright 2001 John R. Sheets (for CodeWeavers)
6 * Copyright 2004 Mike McCormack (for CodeWeavers)
7 * Copyright 2005 Ge van Geldorp (gvg@reactos.org)
8 * Copyright 2009 Dmitry Chapyshev (dmitry@reactos.org)
9 * Copyright 2015 Ismael Ferreras Morezuelas (swyterzone+ros@gmail.com)
10 * Copyright 2017 Alexander Shaposhnikov (chaez.san@gmail.com)
14 * Based on Wine dlls/shdocvw/shdocvw_main.c
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License as published by the Free Software Foundation; either
19 * version 2.1 of the License, or (at your option) any later version.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
32 #include <shlobj_undoc.h>
33 #include <shlguid_undoc.h>
39 #include <shellutils.h>
48 #ifdef USE_CERT_PINNING
49 #define CERT_ISSUER_INFO "BE\r\nGlobalSign nv-sa\r\nGlobalSign Domain Validation CA - SHA256 - G2"
50 #define CERT_SUBJECT_INFO "Domain Control Validated\r\n*.reactos.org"
55 DLWaiting
= IDS_STATUS_WAITING
,
56 DLDownloading
= IDS_STATUS_DOWNLOADING
,
57 DLWaitingToInstall
= IDS_STATUS_DOWNLOADED
,
58 DLInstalling
= IDS_STATUS_INSTALLING
,
59 DLInstalled
= IDS_STATUS_INSTALLED
,
60 DLFinished
= IDS_STATUS_FINISHED
63 ATL::CStringW
LoadStatusString(DOWNLOAD_STATUS StatusParam
)
65 ATL::CStringW szString
;
66 szString
.LoadStringW(StatusParam
);
70 class CDownloadDialog
:
71 public CComObjectRootEx
<CComMultiThreadModelNoCS
>,
72 public IBindStatusCallback
76 BOOL m_UrlHasBeenCopied
;
81 //DestroyWindow(m_hDialog);
84 HRESULT
Initialize(HWND Dlg
, BOOL
*pbCancelled
)
87 m_pbCancelled
= pbCancelled
;
88 m_UrlHasBeenCopied
= FALSE
;
92 virtual HRESULT STDMETHODCALLTYPE
OnStartBinding(
99 virtual HRESULT STDMETHODCALLTYPE
GetPriority(
105 virtual HRESULT STDMETHODCALLTYPE
OnLowResource(
111 virtual HRESULT STDMETHODCALLTYPE
OnProgress(
115 LPCWSTR szStatusText
)
120 Item
= GetDlgItem(m_hDialog
, IDC_DOWNLOAD_PROGRESS
);
121 if (Item
&& ulProgressMax
)
123 WCHAR szProgress
[100];
124 WCHAR szProgressMax
[100];
125 UINT uiPercentage
= ((ULONGLONG
) ulProgress
* 100) / ulProgressMax
;
127 /* send the current progress to the progress bar */
128 SendMessageW(Item
, PBM_SETPOS
, uiPercentage
, 0);
130 /* format the bits and bytes into pretty and accessible units... */
131 StrFormatByteSizeW(ulProgress
, szProgress
, _countof(szProgress
));
132 StrFormatByteSizeW(ulProgressMax
, szProgressMax
, _countof(szProgressMax
));
134 /* ...and post all of it to our subclassed progress bar text subroutine */
135 ATL::CStringW m_ProgressText
;
136 m_ProgressText
.Format(L
"%u%% \x2014 %ls / %ls",
140 SendMessageW(Item
, WM_SETTEXT
, 0, (LPARAM
) m_ProgressText
.GetString());
143 Item
= GetDlgItem(m_hDialog
, IDC_DOWNLOAD_STATUS
);
144 if (Item
&& szStatusText
&& wcslen(szStatusText
) > 0 && m_UrlHasBeenCopied
== FALSE
)
146 DWORD len
= wcslen(szStatusText
) + 1;
149 /* beautify our url for display purposes */
150 if (!InternetCanonicalizeUrlW(szStatusText
, buf
.GetBuffer(len
), &len
, ICU_DECODE
| ICU_NO_ENCODE
))
152 /* just use the original */
161 /* paste it into our dialog and don't do it again in this instance */
162 SendMessageW(Item
, WM_SETTEXT
, 0, (LPARAM
) buf
.GetString());
163 m_UrlHasBeenCopied
= TRUE
;
166 SetLastError(ERROR_SUCCESS
);
167 r
= GetWindowLongPtrW(m_hDialog
, GWLP_USERDATA
);
168 if (r
|| GetLastError() != ERROR_SUCCESS
)
170 *m_pbCancelled
= TRUE
;
177 virtual HRESULT STDMETHODCALLTYPE
OnStopBinding(
184 virtual HRESULT STDMETHODCALLTYPE
GetBindInfo(
191 virtual HRESULT STDMETHODCALLTYPE
OnDataAvailable(
194 FORMATETC
*pformatetc
,
200 virtual HRESULT STDMETHODCALLTYPE
OnObjectAvailable(
207 BEGIN_COM_MAP(CDownloadDialog
)
208 COM_INTERFACE_ENTRY_IID(IID_IBindStatusCallback
, IBindStatusCallback
)
212 class CDowloadingAppsListView
213 : public CUiWindow
<CListView
>
216 HWND
Create(HWND hwndParent
)
218 RECT r
= {10, 150, 320, 350};
219 const DWORD style
= WS_CHILD
| WS_VISIBLE
| LVS_REPORT
| LVS_SINGLESEL
220 | LVS_SHOWSELALWAYS
| LVS_NOSORTHEADER
| LVS_NOCOLUMNHEADER
;
222 HWND hwnd
= CListView::Create(hwndParent
, r
, NULL
, style
, WS_EX_CLIENTEDGE
);
224 AddColumn(0, 150, LVCFMT_LEFT
);
225 AddColumn(1, 120, LVCFMT_LEFT
);
230 VOID
LoadList(ATL::CSimpleArray
<PAPPLICATION_INFO
> arrInfo
)
232 for (INT i
= 0; i
< arrInfo
.GetSize(); ++i
)
234 PAPPLICATION_INFO AppInfo
= arrInfo
[i
];
235 AddRow(i
, AppInfo
->szName
.GetString(), DOWNLOAD_STATUS::DLWaiting
);
239 VOID
SetDownloadStatus(INT ItemIndex
, DOWNLOAD_STATUS Status
)
241 HWND hListView
= GetWindow();
242 ATL::CStringW szBuffer
= LoadStatusString(Status
);
243 ListView_SetItemText(hListView
, ItemIndex
, 1, const_cast<LPWSTR
>(szBuffer
.GetString()));
246 BOOL
AddItem(INT ItemIndex
, LPWSTR lpText
)
250 ZeroMemory(&Item
, sizeof(Item
));
252 Item
.mask
= LVIF_TEXT
| LVIF_STATE
;
253 Item
.pszText
= lpText
;
254 Item
.iItem
= ItemIndex
;
256 return InsertItem(&Item
);
259 VOID
AddRow(INT RowIndex
, LPCWSTR szAppName
, const DOWNLOAD_STATUS Status
)
261 ATL::CStringW szStatus
= LoadStatusString(Status
);
263 const_cast<LPWSTR
>(szAppName
));
264 SetDownloadStatus(RowIndex
, Status
);
267 BOOL
AddColumn(INT Index
, INT Width
, INT Format
)
270 ZeroMemory(&Column
, sizeof(Column
));
272 Column
.mask
= LVCF_FMT
| LVCF_WIDTH
| LVCF_SUBITEM
;
273 Column
.iSubItem
= Index
;
277 return (InsertColumn(Index
, &Column
) == -1) ? FALSE
: TRUE
;
282 HRESULT WINAPI
CDownloadDialog_Constructor(HWND Dlg
, BOOL
*pbCancelled
, REFIID riid
, LPVOID
*ppv
)
284 return ShellObjectCreatorInit
<CDownloadDialog
>(Dlg
, pbCancelled
, riid
, ppv
);
287 #ifdef USE_CERT_PINNING
288 static BOOL
CertIsValid(HINTERNET hInternet
, LPWSTR lpszHostName
)
292 DWORD certInfoLength
;
294 INTERNET_CERTIFICATE_INFOW certInfo
;
296 hConnect
= InternetConnectW(hInternet
, lpszHostName
, INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0);
299 hRequest
= HttpOpenRequestW(hConnect
, L
"HEAD", NULL
, NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
300 if (hRequest
!= NULL
)
302 Ret
= HttpSendRequestW(hRequest
, L
"", 0, NULL
, 0);
305 certInfoLength
= sizeof(certInfo
);
306 Ret
= InternetQueryOptionW(hRequest
,
307 INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
312 if (certInfo
.lpszEncryptionAlgName
)
313 LocalFree(certInfo
.lpszEncryptionAlgName
);
314 if (certInfo
.lpszIssuerInfo
)
316 if (strcmp((LPSTR
) certInfo
.lpszIssuerInfo
, CERT_ISSUER_INFO
) != 0)
318 LocalFree(certInfo
.lpszIssuerInfo
);
320 if (certInfo
.lpszProtocolName
)
321 LocalFree(certInfo
.lpszProtocolName
);
322 if (certInfo
.lpszSignatureAlgName
)
323 LocalFree(certInfo
.lpszSignatureAlgName
);
324 if (certInfo
.lpszSubjectInfo
)
326 if (strcmp((LPSTR
) certInfo
.lpszSubjectInfo
, CERT_SUBJECT_INFO
) != 0)
328 LocalFree(certInfo
.lpszSubjectInfo
);
332 InternetCloseHandle(hRequest
);
334 InternetCloseHandle(hConnect
);
340 inline VOID
MessageBox_LoadString(HWND hMainWnd
, INT StringID
)
342 ATL::CString szMsgText
;
343 if (szMsgText
.LoadStringW(StringID
))
345 MessageBoxW(hMainWnd
, szMsgText
.GetString(), NULL
, MB_OK
| MB_ICONERROR
);
351 DownloadParam() : Dialog(NULL
), AppInfo(), szCaption(NULL
) {}
352 DownloadParam(HWND dlg
, const ATL::CSimpleArray
<PAPPLICATION_INFO
> &info
, LPCWSTR caption
)
353 : Dialog(dlg
), AppInfo(info
), szCaption(caption
)
358 ATL::CSimpleArray
<PAPPLICATION_INFO
> AppInfo
;
363 ATL::CSimpleArray
<PAPPLICATION_INFO
> CDownloadManager::AppsToInstallList
;
364 CDowloadingAppsListView
CDownloadManager::DownloadsListView
;
365 INT
CDownloadManager::iCurrentApp
;
367 INT_PTR CALLBACK
CDownloadManager::DownloadDlgProc(HWND Dlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
369 static WCHAR szCaption
[MAX_PATH
];
375 HICON hIconSm
, hIconBg
;
377 hIconBg
= (HICON
) GetClassLongW(hMainWnd
, GCLP_HICON
);
378 hIconSm
= (HICON
) GetClassLongW(hMainWnd
, GCLP_HICONSM
);
380 if (hIconBg
&& hIconSm
)
382 SendMessageW(Dlg
, WM_SETICON
, ICON_BIG
, (LPARAM
) hIconBg
);
383 SendMessageW(Dlg
, WM_SETICON
, ICON_SMALL
, (LPARAM
) hIconSm
);
386 SetWindowLongW(Dlg
, GWLP_USERDATA
, 0);
387 HWND Item
= GetDlgItem(Dlg
, IDC_DOWNLOAD_PROGRESS
);
390 // initialize the default values for our nifty progress bar
391 // and subclass it so that it learns to print a status text
392 SendMessageW(Item
, PBM_SETRANGE
, 0, MAKELPARAM(0, 100));
393 SendMessageW(Item
, PBM_SETPOS
, 0, 0);
395 SetWindowSubclass(Item
, DownloadProgressProc
, 0, 0);
399 HWND hListView
= DownloadsListView
.Create(Dlg
);
404 DownloadsListView
.LoadList(AppsToInstallList
);
406 ShowWindow(Dlg
, SW_SHOW
);
408 // Get a dlg string for later use
409 GetWindowTextW(Dlg
, szCaption
, MAX_PATH
);
411 // Start download process
412 DownloadParam
*param
= new DownloadParam(Dlg
, AppsToInstallList
, szCaption
);
414 HANDLE Thread
= CreateThread(NULL
, 0, ThreadFunc
, (LPVOID
) param
, 0, &ThreadId
);
426 if (wParam
== IDCANCEL
)
428 SetWindowLongW(Dlg
, GWLP_USERDATA
, 1);
429 PostMessageW(Dlg
, WM_CLOSE
, 0, 0);
435 //DestroyWindow(Dlg);
443 LRESULT CALLBACK
CDownloadManager::DownloadProgressProc(HWND hWnd
,
447 UINT_PTR uIdSubclass
,
450 static ATL::CStringW szProgressText
;
458 szProgressText
= (PCWSTR
) lParam
;
467 HDC hDC
= BeginPaint(hWnd
, &ps
), hdcMem
;
471 UINT win_width
, win_height
;
473 GetClientRect(hWnd
, &myRect
);
475 /* grab the progress bar rect size */
476 win_width
= myRect
.right
- myRect
.left
;
477 win_height
= myRect
.bottom
- myRect
.top
;
479 /* create an off-screen DC for double-buffering */
480 hdcMem
= CreateCompatibleDC(hDC
);
481 hbmMem
= CreateCompatibleBitmap(hDC
, win_width
, win_height
);
483 hOld
= SelectObject(hdcMem
, hbmMem
);
485 /* call the original draw code and redirect it to our memory buffer */
486 DefSubclassProc(hWnd
, uMsg
, (WPARAM
) hdcMem
, lParam
);
488 /* draw our nifty progress text over it */
489 SelectFont(hdcMem
, GetStockFont(DEFAULT_GUI_FONT
));
490 DrawShadowText(hdcMem
, szProgressText
.GetString(), szProgressText
.GetLength(),
492 DT_CENTER
| DT_VCENTER
| DT_NOPREFIX
| DT_SINGLELINE
,
493 GetSysColor(COLOR_CAPTIONTEXT
),
494 GetSysColor(COLOR_3DSHADOW
),
497 /* transfer the off-screen DC to the screen */
498 BitBlt(hDC
, 0, 0, win_width
, win_height
, hdcMem
, 0, 0, SRCCOPY
);
500 /* free the off-screen DC */
501 SelectObject(hdcMem
, hOld
);
502 DeleteObject(hbmMem
);
509 /* Raymond Chen says that we should safely unsubclass all the things!
510 (http://blogs.msdn.com/b/oldnewthing/archive/2003/11/11/55653.aspx) */
514 szProgressText
.Empty();
515 RemoveWindowSubclass(hWnd
, DownloadProgressProc
, uIdSubclass
);
519 return DefSubclassProc(hWnd
, uMsg
, wParam
, lParam
);
523 DWORD WINAPI
CDownloadManager::ThreadFunc(LPVOID param
)
525 CComPtr
<IBindStatusCallback
> dl
;
529 HWND hDlg
= static_cast<DownloadParam
*>(param
)->Dialog
;
531 ULONG dwContentLen
, dwBytesWritten
, dwBytesRead
, dwStatus
;
532 ULONG dwCurrentBytesRead
= 0;
533 ULONG dwStatusLen
= sizeof(dwStatus
);
535 BOOL bCancelled
= FALSE
;
536 BOOL bTempfile
= FALSE
;
539 HINTERNET hOpen
= NULL
;
540 HINTERNET hFile
= NULL
;
541 HANDLE hOut
= INVALID_HANDLE_VALUE
;
543 unsigned char lpBuffer
[4096];
544 LPCWSTR lpszAgent
= L
"RApps/1.0";
545 URL_COMPONENTS urlComponents
;
546 size_t urlLength
, filenameLength
;
548 const INT iAppId
= iCurrentApp
;
549 const ATL::CSimpleArray
<PAPPLICATION_INFO
> InfoArray
= static_cast<DownloadParam
*>(param
)->AppInfo
;
550 LPCWSTR szCaption
= static_cast<DownloadParam
*>(param
)->szCaption
;
551 ATL::CStringW szNewCaption
;
554 if (InfoArray
.GetSize() <= 0)
556 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_DOWNLOAD
);
560 for (INT iAppId
= 0; iAppId
< InfoArray
.GetSize(); ++iAppId
)
562 PAPPLICATION_INFO pCurrentInfo
= AppsToInstallList
[iAppId
];
565 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_DOWNLOAD
);
569 // build the path for the download
570 p
= wcsrchr(pCurrentInfo
->szUrlDownload
.GetString(), L
'/');
571 q
= wcsrchr(pCurrentInfo
->szUrlDownload
.GetString(), L
'?');
573 // do we have a final slash separator?
577 // prepare the tentative length of the filename, maybe we've to remove part of it later on
578 filenameLength
= wcslen(p
) * sizeof(WCHAR
);
580 /* do we have query arguments in the target URL after the filename? account for them
581 (e.g. https://example.org/myfile.exe?no_adware_plz) */
582 if (q
&& q
> p
&& (q
- p
) > 0)
583 filenameLength
-= wcslen(q
- 1) * sizeof(WCHAR
);
585 // is this URL an update package for RAPPS? if so store it in a different place
586 if (pCurrentInfo
->szUrlDownload
== APPLICATION_DATABASE_URL
)
589 if (!GetStorageDirectory(Path
))
594 Path
= SettingsInfo
.szDownloadDir
;
597 // is the path valid? can we access it?
598 if (GetFileAttributesW(Path
.GetString()) == INVALID_FILE_ATTRIBUTES
)
600 if (!CreateDirectoryW(Path
.GetString(), NULL
))
604 // append a \ to the provided file system path, and the filename portion from the URL after that
606 Path
+= (LPWSTR
) (p
+ 1);
608 if (!bCab
&& pCurrentInfo
->szSHA1
[0] && GetFileAttributesW(Path
.GetString()) != INVALID_FILE_ATTRIBUTES
)
610 // only open it in case of total correctness
611 if (VerifyInteg(pCurrentInfo
->szSHA1
, Path
))
615 // Reset progress bar
616 HWND Item
= GetDlgItem(hDlg
, IDC_DOWNLOAD_PROGRESS
);
619 SendMessageW(Item
, PBM_SETPOS
, 0, 0);
622 // Change caption to show the currently downloaded app
625 szNewCaption
.Format(szCaption
, pCurrentInfo
->szName
.GetString());
629 szNewCaption
.LoadStringW(IDS_DL_DIALOG_DB_DOWNLOAD_DISP
);
632 SetWindowTextW(hDlg
, szNewCaption
.GetString());
634 // Add the download URL
635 SetDlgItemTextW(hDlg
, IDC_DOWNLOAD_STATUS
, pCurrentInfo
->szUrlDownload
.GetString());
637 DownloadsListView
.SetDownloadStatus(iAppId
, DOWNLOAD_STATUS::DLDownloading
);
641 CDownloadDialog_Constructor(hDlg
, &bCancelled
, IID_PPV_ARG(IBindStatusCallback
, &dl
));
646 /* FIXME: this should just be using the system-wide proxy settings */
647 switch (SettingsInfo
.Proxy
)
650 hOpen
= InternetOpenW(lpszAgent
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
652 case 1: // direct (no proxy)
653 hOpen
= InternetOpenW(lpszAgent
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
656 hOpen
= InternetOpenW(lpszAgent
, INTERNET_OPEN_TYPE_PROXY
, SettingsInfo
.szProxyServer
, SettingsInfo
.szNoProxyFor
, 0);
658 default: // preconfig
659 hOpen
= InternetOpenW(lpszAgent
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
666 hFile
= InternetOpenUrlW(hOpen
, pCurrentInfo
->szUrlDownload
.GetString(), NULL
, 0, INTERNET_FLAG_PRAGMA_NOCACHE
| INTERNET_FLAG_KEEP_CONNECTION
, 0);
670 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_DOWNLOAD2
);
674 if (!HttpQueryInfoW(hFile
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &dwStatus
, &dwStatusLen
, NULL
))
677 if (dwStatus
!= HTTP_STATUS_OK
)
679 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_DOWNLOAD
);
683 dwStatusLen
= sizeof(dwStatus
);
685 memset(&urlComponents
, 0, sizeof(urlComponents
));
686 urlComponents
.dwStructSize
= sizeof(urlComponents
);
688 urlLength
= pCurrentInfo
->szUrlDownload
.GetLength();
689 urlComponents
.dwSchemeLength
= urlLength
+ 1;
690 urlComponents
.lpszScheme
= (LPWSTR
) malloc(urlComponents
.dwSchemeLength
* sizeof(WCHAR
));
691 urlComponents
.dwHostNameLength
= urlLength
+ 1;
692 urlComponents
.lpszHostName
= (LPWSTR
) malloc(urlComponents
.dwHostNameLength
* sizeof(WCHAR
));
694 if (!InternetCrackUrlW(pCurrentInfo
->szUrlDownload
, urlLength
+ 1, ICU_DECODE
| ICU_ESCAPE
, &urlComponents
))
697 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
|| urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
)
698 HttpQueryInfoW(hFile
, HTTP_QUERY_CONTENT_LENGTH
| HTTP_QUERY_FLAG_NUMBER
, &dwContentLen
, &dwStatus
, 0);
700 if (urlComponents
.nScheme
== INTERNET_SCHEME_FTP
)
701 dwContentLen
= FtpGetFileSize(hFile
, &dwStatus
);
703 #ifdef USE_CERT_PINNING
704 // are we using HTTPS to download the RAPPS update package? check if the certificate is original
705 if ((urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) &&
706 (wcscmp(pCurrentInfo
->szUrlDownload
, APPLICATION_DATABASE_URL
) == 0) &&
707 (!CertIsValid(hOpen
, urlComponents
.lpszHostName
)))
709 MessageBox_LoadString(hMainWnd
, IDS_CERT_DOES_NOT_MATCH
);
714 free(urlComponents
.lpszScheme
);
715 free(urlComponents
.lpszHostName
);
717 hOut
= CreateFileW(Path
.GetString(), GENERIC_WRITE
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, CREATE_ALWAYS
, 0, NULL
);
719 if (hOut
== INVALID_HANDLE_VALUE
)
722 dwCurrentBytesRead
= 0;
725 if (!InternetReadFile(hFile
, lpBuffer
, _countof(lpBuffer
), &dwBytesRead
))
727 MessageBox_LoadString(hMainWnd
, IDS_INTERRUPTED_DOWNLOAD
);
731 if (!WriteFile(hOut
, &lpBuffer
[0], dwBytesRead
, &dwBytesWritten
, NULL
))
733 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_WRITE
);
737 dwCurrentBytesRead
+= dwBytesRead
;
738 dl
->OnProgress(dwCurrentBytesRead
, dwContentLen
, 0, pCurrentInfo
->szUrlDownload
.GetString());
739 } while (dwBytesRead
&& !bCancelled
);
742 hOut
= INVALID_HANDLE_VALUE
;
747 /* if this thing isn't a RAPPS update and it has a SHA-1 checksum
748 verify its integrity by using the native advapi32.A_SHA1 functions */
749 if (!bCab
&& pCurrentInfo
->szSHA1
[0] != 0)
751 ATL::CStringW szMsgText
;
753 // change a few strings in the download dialog to reflect the verification process
754 if (!szMsgText
.LoadStringW(IDS_INTEG_CHECK_TITLE
))
757 SetWindowTextW(hDlg
, szMsgText
.GetString());
758 SendMessageW(GetDlgItem(hDlg
, IDC_DOWNLOAD_STATUS
), WM_SETTEXT
, 0, (LPARAM
) Path
.GetString());
760 // this may take a while, depending on the file size
761 if (!VerifyInteg(pCurrentInfo
->szSHA1
, Path
.GetString()))
763 if (!szMsgText
.LoadStringW(IDS_INTEG_CHECK_FAIL
))
766 MessageBoxW(hDlg
, szMsgText
.GetString(), NULL
, MB_OK
| MB_ICONERROR
);
772 DownloadsListView
.SetDownloadStatus(iAppId
, DOWNLOAD_STATUS::DLWaitingToInstall
);
777 SHELLEXECUTEINFOW shExInfo
= {0};
778 shExInfo
.cbSize
= sizeof(shExInfo
);
779 shExInfo
.fMask
= SEE_MASK_NOCLOSEPROCESS
;
780 shExInfo
.lpVerb
= L
"open";
781 shExInfo
.lpFile
= Path
.GetString();
782 shExInfo
.lpParameters
= L
"";
783 shExInfo
.nShow
= SW_SHOW
;
785 if (ShellExecuteExW(&shExInfo
))
787 DownloadsListView
.SetDownloadStatus(iAppId
, DOWNLOAD_STATUS::DLInstalling
);
788 //TODO: issue an install operation separately so that the apps could be downloaded in the background
789 WaitForSingleObject(shExInfo
.hProcess
, INFINITE
);
790 CloseHandle(shExInfo
.hProcess
);
794 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_INSTALL
);
799 if (hOut
!= INVALID_HANDLE_VALUE
)
802 InternetCloseHandle(hFile
);
803 InternetCloseHandle(hOpen
);
807 if (bCancelled
|| (SettingsInfo
.bDelInstaller
&& !bCab
))
808 DeleteFileW(Path
.GetString());
811 DownloadsListView
.SetDownloadStatus(iAppId
, DOWNLOAD_STATUS::DLFinished
);
814 SendMessageW(hDlg
, WM_CLOSE
, 0, 0);
818 BOOL
CDownloadManager::DownloadListOfApplications(const ATL::CSimpleArray
<PAPPLICATION_INFO
>& AppsList
, BOOL bIsModal
)
820 if (AppsList
.GetSize() == 0)
825 // Initialize shared variables
826 AppsToInstallList
= AppsList
;
828 // Create a dialog and issue a download process
829 LaunchDownloadDialog(bIsModal
);
834 BOOL
CDownloadManager::DownloadApplication(PAPPLICATION_INFO pAppInfo
, BOOL bIsModal
)
841 AppsToInstallList
.RemoveAll();
842 AppsToInstallList
.Add(pAppInfo
);
843 LaunchDownloadDialog(bIsModal
);
848 VOID
CDownloadManager::DownloadApplicationsDB(LPCWSTR lpUrl
)
850 static APPLICATION_INFO IntInfo
;
851 IntInfo
.szUrlDownload
= lpUrl
;
852 IntInfo
.szName
.LoadStringW(IDS_DL_DIALOG_DB_DISP
);
853 DownloadApplication(&IntInfo
, TRUE
);
856 //TODO: Reuse the dialog
857 VOID
CDownloadManager::LaunchDownloadDialog(BOOL bIsModal
)
862 MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG
),
869 MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG
),