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
);
74 DownloadInfo(const CAvailableApplicationInfo
& AppInfo
)
75 :szUrl(AppInfo
.m_szUrlDownload
), m_szName(AppInfo
.m_szName
), szSHA1(AppInfo
.m_szSHA1
)
80 ATL::CStringW m_szName
;
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
);
149 if (Item
&& ulProgressMax
)
151 WCHAR szProgress
[100];
152 WCHAR szProgressMax
[100];
153 UINT uiPercentage
= ((ULONGLONG
) ulProgress
* 100) / ulProgressMax
;
155 /* send the current progress to the progress bar */
156 SendMessageW(Item
, PBM_SETPOS
, uiPercentage
, 0);
158 /* format the bits and bytes into pretty and accessible units... */
159 StrFormatByteSizeW(ulProgress
, szProgress
, _countof(szProgress
));
160 StrFormatByteSizeW(ulProgressMax
, szProgressMax
, _countof(szProgressMax
));
162 /* ...and post all of it to our subclassed progress bar text subroutine */
163 ATL::CStringW m_ProgressText
;
164 m_ProgressText
.Format(L
"%u%% \x2014 %ls / %ls",
168 SendMessageW(Item
, WM_SETTEXT
, 0, (LPARAM
) m_ProgressText
.GetString());
171 Item
= GetDlgItem(m_hDialog
, IDC_DOWNLOAD_STATUS
);
172 if (Item
&& szStatusText
&& wcslen(szStatusText
) > 0 && m_UrlHasBeenCopied
== FALSE
)
174 DWORD len
= wcslen(szStatusText
) + 1;
177 /* beautify our url for display purposes */
178 if (!InternetCanonicalizeUrlW(szStatusText
, buf
.GetBuffer(len
), &len
, ICU_DECODE
| ICU_NO_ENCODE
))
180 /* just use the original */
189 /* paste it into our dialog and don't do it again in this instance */
190 SendMessageW(Item
, WM_SETTEXT
, 0, (LPARAM
) buf
.GetString());
191 m_UrlHasBeenCopied
= TRUE
;
194 SetLastError(ERROR_SUCCESS
);
195 r
= GetWindowLongPtrW(m_hDialog
, GWLP_USERDATA
);
196 if (r
|| GetLastError() != ERROR_SUCCESS
)
198 *m_pbCancelled
= TRUE
;
205 virtual HRESULT STDMETHODCALLTYPE
OnStopBinding(
212 virtual HRESULT STDMETHODCALLTYPE
GetBindInfo(
219 virtual HRESULT STDMETHODCALLTYPE
OnDataAvailable(
222 FORMATETC
*pformatetc
,
228 virtual HRESULT STDMETHODCALLTYPE
OnObjectAvailable(
235 BEGIN_COM_MAP(CDownloadDialog
)
236 COM_INTERFACE_ENTRY_IID(IID_IBindStatusCallback
, IBindStatusCallback
)
240 class CDowloadingAppsListView
241 : public CUiWindow
<CListView
>
244 HWND
Create(HWND hwndParent
)
246 RECT r
= {10, 150, 320, 350};
247 const DWORD style
= WS_CHILD
| WS_VISIBLE
| LVS_REPORT
| LVS_SINGLESEL
248 | LVS_SHOWSELALWAYS
| LVS_NOSORTHEADER
| LVS_NOCOLUMNHEADER
;
250 HWND hwnd
= CListView::Create(hwndParent
, r
, NULL
, style
, WS_EX_CLIENTEDGE
);
252 AddColumn(0, 150, LVCFMT_LEFT
);
253 AddColumn(1, 120, LVCFMT_LEFT
);
258 VOID
LoadList(ATL::CSimpleArray
<DownloadInfo
> arrInfo
)
260 for (INT i
= 0; i
< arrInfo
.GetSize(); ++i
)
262 AddRow(i
, arrInfo
[i
].m_szName
.GetString(), DOWNLOAD_STATUS::DLWaiting
);
266 VOID
SetDownloadStatus(INT ItemIndex
, DOWNLOAD_STATUS Status
)
268 HWND hListView
= GetWindow();
269 ATL::CStringW szBuffer
= LoadStatusString(Status
);
270 ListView_SetItemText(hListView
, ItemIndex
, 1, const_cast<LPWSTR
>(szBuffer
.GetString()));
273 BOOL
AddItem(INT ItemIndex
, LPWSTR lpText
)
277 ZeroMemory(&Item
, sizeof(Item
));
279 Item
.mask
= LVIF_TEXT
| LVIF_STATE
;
280 Item
.pszText
= lpText
;
281 Item
.iItem
= ItemIndex
;
283 return InsertItem(&Item
);
286 VOID
AddRow(INT RowIndex
, LPCWSTR szAppName
, const DOWNLOAD_STATUS Status
)
288 ATL::CStringW szStatus
= LoadStatusString(Status
);
290 const_cast<LPWSTR
>(szAppName
));
291 SetDownloadStatus(RowIndex
, Status
);
294 BOOL
AddColumn(INT Index
, INT Width
, INT Format
)
297 ZeroMemory(&Column
, sizeof(Column
));
299 Column
.mask
= LVCF_FMT
| LVCF_WIDTH
| LVCF_SUBITEM
;
300 Column
.iSubItem
= Index
;
304 return (InsertColumn(Index
, &Column
) == -1) ? FALSE
: TRUE
;
309 HRESULT WINAPI
CDownloadDialog_Constructor(HWND Dlg
, BOOL
*pbCancelled
, REFIID riid
, LPVOID
*ppv
)
311 return ShellObjectCreatorInit
<CDownloadDialog
>(Dlg
, pbCancelled
, riid
, ppv
);
314 #ifdef USE_CERT_PINNING
315 static BOOL
CertIsValid(HINTERNET hInternet
, LPWSTR lpszHostName
)
319 DWORD certInfoLength
;
321 INTERNET_CERTIFICATE_INFOW certInfo
;
323 hConnect
= InternetConnectW(hInternet
, lpszHostName
, INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0);
326 hRequest
= HttpOpenRequestW(hConnect
, L
"HEAD", NULL
, NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
327 if (hRequest
!= NULL
)
329 Ret
= HttpSendRequestW(hRequest
, L
"", 0, NULL
, 0);
332 certInfoLength
= sizeof(certInfo
);
333 Ret
= InternetQueryOptionW(hRequest
,
334 INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
339 if (certInfo
.lpszEncryptionAlgName
)
340 LocalFree(certInfo
.lpszEncryptionAlgName
);
341 if (certInfo
.lpszIssuerInfo
)
343 if (strcmp((LPSTR
) certInfo
.lpszIssuerInfo
, CERT_ISSUER_INFO
) != 0)
345 LocalFree(certInfo
.lpszIssuerInfo
);
347 if (certInfo
.lpszProtocolName
)
348 LocalFree(certInfo
.lpszProtocolName
);
349 if (certInfo
.lpszSignatureAlgName
)
350 LocalFree(certInfo
.lpszSignatureAlgName
);
351 if (certInfo
.lpszSubjectInfo
)
353 if (strcmp((LPSTR
) certInfo
.lpszSubjectInfo
, CERT_SUBJECT_INFO
) != 0)
355 LocalFree(certInfo
.lpszSubjectInfo
);
359 InternetCloseHandle(hRequest
);
361 InternetCloseHandle(hConnect
);
367 inline VOID
MessageBox_LoadString(HWND hMainWnd
, INT StringID
)
369 ATL::CString szMsgText
;
370 if (szMsgText
.LoadStringW(StringID
))
372 MessageBoxW(hMainWnd
, szMsgText
.GetString(), NULL
, MB_OK
| MB_ICONERROR
);
377 ATL::CSimpleArray
<DownloadInfo
> CDownloadManager::AppsToInstallList
;
378 CDowloadingAppsListView
CDownloadManager::DownloadsListView
;
379 INT
CDownloadManager::iCurrentApp
;
381 VOID
CDownloadManager::Download(const DownloadInfo
&DLInfo
, BOOL bIsModal
)
383 AppsToInstallList
.RemoveAll();
384 AppsToInstallList
.Add(DLInfo
);
385 LaunchDownloadDialog(bIsModal
);
388 INT_PTR CALLBACK
CDownloadManager::DownloadDlgProc(HWND Dlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
390 static WCHAR szCaption
[MAX_PATH
];
396 HICON hIconSm
, hIconBg
;
398 hIconBg
= (HICON
) GetClassLongW(hMainWnd
, GCLP_HICON
);
399 hIconSm
= (HICON
) GetClassLongW(hMainWnd
, GCLP_HICONSM
);
401 if (hIconBg
&& hIconSm
)
403 SendMessageW(Dlg
, WM_SETICON
, ICON_BIG
, (LPARAM
) hIconBg
);
404 SendMessageW(Dlg
, WM_SETICON
, ICON_SMALL
, (LPARAM
) hIconSm
);
407 SetWindowLongW(Dlg
, GWLP_USERDATA
, 0);
408 HWND Item
= GetDlgItem(Dlg
, IDC_DOWNLOAD_PROGRESS
);
411 // initialize the default values for our nifty progress bar
412 // and subclass it so that it learns to print a status text
413 SendMessageW(Item
, PBM_SETRANGE
, 0, MAKELPARAM(0, 100));
414 SendMessageW(Item
, PBM_SETPOS
, 0, 0);
416 SetWindowSubclass(Item
, DownloadProgressProc
, 0, 0);
420 HWND hListView
= DownloadsListView
.Create(Dlg
);
425 DownloadsListView
.LoadList(AppsToInstallList
);
427 ShowWindow(Dlg
, SW_SHOW
);
429 // Get a dlg string for later use
430 GetWindowTextW(Dlg
, szCaption
, MAX_PATH
);
432 // Start download process
433 DownloadParam
*param
= new DownloadParam(Dlg
, AppsToInstallList
, szCaption
);
435 HANDLE Thread
= CreateThread(NULL
, 0, ThreadFunc
, (LPVOID
) param
, 0, &ThreadId
);
443 AppsToInstallList
.RemoveAll();
448 if (wParam
== IDCANCEL
)
450 SetWindowLongW(Dlg
, GWLP_USERDATA
, 1);
451 PostMessageW(Dlg
, WM_CLOSE
, 0, 0);
457 //DestroyWindow(Dlg);
465 LRESULT CALLBACK
CDownloadManager::DownloadProgressProc(HWND hWnd
,
469 UINT_PTR uIdSubclass
,
472 static ATL::CStringW szProgressText
;
480 szProgressText
= (PCWSTR
) lParam
;
489 HDC hDC
= BeginPaint(hWnd
, &ps
), hdcMem
;
493 UINT win_width
, win_height
;
495 GetClientRect(hWnd
, &myRect
);
497 /* grab the progress bar rect size */
498 win_width
= myRect
.right
- myRect
.left
;
499 win_height
= myRect
.bottom
- myRect
.top
;
501 /* create an off-screen DC for double-buffering */
502 hdcMem
= CreateCompatibleDC(hDC
);
503 hbmMem
= CreateCompatibleBitmap(hDC
, win_width
, win_height
);
505 hOld
= SelectObject(hdcMem
, hbmMem
);
507 /* call the original draw code and redirect it to our memory buffer */
508 DefSubclassProc(hWnd
, uMsg
, (WPARAM
) hdcMem
, lParam
);
510 /* draw our nifty progress text over it */
511 SelectFont(hdcMem
, GetStockFont(DEFAULT_GUI_FONT
));
512 DrawShadowText(hdcMem
, szProgressText
.GetString(), szProgressText
.GetLength(),
514 DT_CENTER
| DT_VCENTER
| DT_NOPREFIX
| DT_SINGLELINE
,
515 GetSysColor(COLOR_CAPTIONTEXT
),
516 GetSysColor(COLOR_3DSHADOW
),
519 /* transfer the off-screen DC to the screen */
520 BitBlt(hDC
, 0, 0, win_width
, win_height
, hdcMem
, 0, 0, SRCCOPY
);
522 /* free the off-screen DC */
523 SelectObject(hdcMem
, hOld
);
524 DeleteObject(hbmMem
);
531 /* Raymond Chen says that we should safely unsubclass all the things!
532 (http://blogs.msdn.com/b/oldnewthing/archive/2003/11/11/55653.aspx) */
536 szProgressText
.Empty();
537 RemoveWindowSubclass(hWnd
, DownloadProgressProc
, uIdSubclass
);
541 return DefSubclassProc(hWnd
, uMsg
, wParam
, lParam
);
545 DWORD WINAPI
CDownloadManager::ThreadFunc(LPVOID param
)
547 CComPtr
<IBindStatusCallback
> dl
;
551 HWND hDlg
= static_cast<DownloadParam
*>(param
)->Dialog
;
553 ULONG dwContentLen
, dwBytesWritten
, dwBytesRead
, dwStatus
;
554 ULONG dwCurrentBytesRead
= 0;
555 ULONG dwStatusLen
= sizeof(dwStatus
);
557 BOOL bCancelled
= FALSE
;
558 BOOL bTempfile
= FALSE
;
561 HINTERNET hOpen
= NULL
;
562 HINTERNET hFile
= NULL
;
563 HANDLE hOut
= INVALID_HANDLE_VALUE
;
565 unsigned char lpBuffer
[4096];
566 LPCWSTR lpszAgent
= L
"RApps/1.0";
567 URL_COMPONENTS urlComponents
;
568 size_t urlLength
, filenameLength
;
570 const INT iAppId
= iCurrentApp
;
571 const ATL::CSimpleArray
<DownloadInfo
> &InfoArray
= static_cast<DownloadParam
*>(param
)->AppInfo
;
572 LPCWSTR szCaption
= static_cast<DownloadParam
*>(param
)->szCaption
;
573 ATL::CStringW szNewCaption
;
576 if (InfoArray
.GetSize() <= 0)
578 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_DOWNLOAD
);
582 for (INT iAppId
= 0; iAppId
< InfoArray
.GetSize(); ++iAppId
)
584 const DownloadInfo
&CurrentInfo
= InfoArray
[iAppId
];
586 // build the path for the download
587 p
= wcsrchr(CurrentInfo
.szUrl
.GetString(), L
'/');
588 q
= wcsrchr(CurrentInfo
.szUrl
.GetString(), L
'?');
590 // do we have a final slash separator?
594 // prepare the tentative length of the filename, maybe we've to remove part of it later on
595 filenameLength
= wcslen(p
) * sizeof(WCHAR
);
597 /* do we have query arguments in the target URL after the filename? account for them
598 (e.g. https://example.org/myfile.exe?no_adware_plz) */
599 if (q
&& q
> p
&& (q
- p
) > 0)
600 filenameLength
-= wcslen(q
- 1) * sizeof(WCHAR
);
602 // is this URL an update package for RAPPS? if so store it in a different place
603 if (CurrentInfo
.szUrl
== APPLICATION_DATABASE_URL
)
606 if (!GetStorageDirectory(Path
))
611 Path
= SettingsInfo
.szDownloadDir
;
614 // is the path valid? can we access it?
615 if (GetFileAttributesW(Path
.GetString()) == INVALID_FILE_ATTRIBUTES
)
617 if (!CreateDirectoryW(Path
.GetString(), NULL
))
621 // append a \ to the provided file system path, and the filename portion from the URL after that
623 Path
+= (LPWSTR
) (p
+ 1);
625 if (!bCab
&& CurrentInfo
.szSHA1
[0] && GetFileAttributesW(Path
.GetString()) != INVALID_FILE_ATTRIBUTES
)
627 // only open it in case of total correctness
628 if (VerifyInteg(CurrentInfo
.szSHA1
.GetString(), Path
))
632 // Reset progress bar
633 HWND Item
= GetDlgItem(hDlg
, IDC_DOWNLOAD_PROGRESS
);
636 SendMessageW(Item
, PBM_SETPOS
, 0, 0);
639 // Change caption to show the currently downloaded app
642 szNewCaption
.Format(szCaption
, CurrentInfo
.m_szName
.GetString());
646 szNewCaption
.LoadStringW(IDS_DL_DIALOG_DB_DOWNLOAD_DISP
);
649 SetWindowTextW(hDlg
, szNewCaption
.GetString());
651 // Add the download URL
652 SetDlgItemTextW(hDlg
, IDC_DOWNLOAD_STATUS
, CurrentInfo
.szUrl
.GetString());
654 DownloadsListView
.SetDownloadStatus(iAppId
, DOWNLOAD_STATUS::DLDownloading
);
658 CDownloadDialog_Constructor(hDlg
, &bCancelled
, IID_PPV_ARG(IBindStatusCallback
, &dl
));
663 /* FIXME: this should just be using the system-wide proxy settings */
664 switch (SettingsInfo
.Proxy
)
667 hOpen
= InternetOpenW(lpszAgent
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
669 case 1: // direct (no proxy)
670 hOpen
= InternetOpenW(lpszAgent
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
673 hOpen
= InternetOpenW(lpszAgent
, INTERNET_OPEN_TYPE_PROXY
, SettingsInfo
.szProxyServer
, SettingsInfo
.szNoProxyFor
, 0);
675 default: // preconfig
676 hOpen
= InternetOpenW(lpszAgent
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
683 hFile
= InternetOpenUrlW(hOpen
, CurrentInfo
.szUrl
.GetString(), NULL
, 0, INTERNET_FLAG_PRAGMA_NOCACHE
| INTERNET_FLAG_KEEP_CONNECTION
, 0);
687 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_DOWNLOAD2
);
691 if (!HttpQueryInfoW(hFile
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &dwStatus
, &dwStatusLen
, NULL
))
694 if (dwStatus
!= HTTP_STATUS_OK
)
696 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_DOWNLOAD
);
700 dwStatusLen
= sizeof(dwStatus
);
702 memset(&urlComponents
, 0, sizeof(urlComponents
));
703 urlComponents
.dwStructSize
= sizeof(urlComponents
);
705 urlLength
= CurrentInfo
.szUrl
.GetLength();
706 urlComponents
.dwSchemeLength
= urlLength
+ 1;
707 urlComponents
.lpszScheme
= (LPWSTR
) malloc(urlComponents
.dwSchemeLength
* sizeof(WCHAR
));
708 urlComponents
.dwHostNameLength
= urlLength
+ 1;
709 urlComponents
.lpszHostName
= (LPWSTR
) malloc(urlComponents
.dwHostNameLength
* sizeof(WCHAR
));
711 if (!InternetCrackUrlW(CurrentInfo
.szUrl
, urlLength
+ 1, ICU_DECODE
| ICU_ESCAPE
, &urlComponents
))
714 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
|| urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
)
715 HttpQueryInfoW(hFile
, HTTP_QUERY_CONTENT_LENGTH
| HTTP_QUERY_FLAG_NUMBER
, &dwContentLen
, &dwStatus
, 0);
717 if (urlComponents
.nScheme
== INTERNET_SCHEME_FTP
)
718 dwContentLen
= FtpGetFileSize(hFile
, &dwStatus
);
720 #ifdef USE_CERT_PINNING
721 // are we using HTTPS to download the RAPPS update package? check if the certificate is original
722 if ((urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) &&
723 (wcscmp(CurrentInfo
.szUrl
, APPLICATION_DATABASE_URL
) == 0) &&
724 (!CertIsValid(hOpen
, urlComponents
.lpszHostName
)))
726 MessageBox_LoadString(hMainWnd
, IDS_CERT_DOES_NOT_MATCH
);
731 free(urlComponents
.lpszScheme
);
732 free(urlComponents
.lpszHostName
);
734 hOut
= CreateFileW(Path
.GetString(), GENERIC_WRITE
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, CREATE_ALWAYS
, 0, NULL
);
736 if (hOut
== INVALID_HANDLE_VALUE
)
739 dwCurrentBytesRead
= 0;
742 if (!InternetReadFile(hFile
, lpBuffer
, _countof(lpBuffer
), &dwBytesRead
))
744 MessageBox_LoadString(hMainWnd
, IDS_INTERRUPTED_DOWNLOAD
);
748 if (!WriteFile(hOut
, &lpBuffer
[0], dwBytesRead
, &dwBytesWritten
, NULL
))
750 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_WRITE
);
754 dwCurrentBytesRead
+= dwBytesRead
;
755 dl
->OnProgress(dwCurrentBytesRead
, dwContentLen
, 0, CurrentInfo
.szUrl
.GetString());
756 } while (dwBytesRead
&& !bCancelled
);
759 hOut
= INVALID_HANDLE_VALUE
;
764 /* if this thing isn't a RAPPS update and it has a SHA-1 checksum
765 verify its integrity by using the native advapi32.A_SHA1 functions */
766 if (!bCab
&& CurrentInfo
.szSHA1
[0] != 0)
768 ATL::CStringW szMsgText
;
770 // change a few strings in the download dialog to reflect the verification process
771 if (!szMsgText
.LoadStringW(IDS_INTEG_CHECK_TITLE
))
774 SetWindowTextW(hDlg
, szMsgText
.GetString());
775 SendMessageW(GetDlgItem(hDlg
, IDC_DOWNLOAD_STATUS
), WM_SETTEXT
, 0, (LPARAM
) Path
.GetString());
777 // this may take a while, depending on the file size
778 if (!VerifyInteg(CurrentInfo
.szSHA1
.GetString(), Path
.GetString()))
780 if (!szMsgText
.LoadStringW(IDS_INTEG_CHECK_FAIL
))
783 MessageBoxW(hDlg
, szMsgText
.GetString(), NULL
, MB_OK
| MB_ICONERROR
);
789 DownloadsListView
.SetDownloadStatus(iAppId
, DOWNLOAD_STATUS::DLWaitingToInstall
);
794 SHELLEXECUTEINFOW shExInfo
= {0};
795 shExInfo
.cbSize
= sizeof(shExInfo
);
796 shExInfo
.fMask
= SEE_MASK_NOCLOSEPROCESS
;
797 shExInfo
.lpVerb
= L
"open";
798 shExInfo
.lpFile
= Path
.GetString();
799 shExInfo
.lpParameters
= L
"";
800 shExInfo
.nShow
= SW_SHOW
;
802 if (ShellExecuteExW(&shExInfo
))
804 DownloadsListView
.SetDownloadStatus(iAppId
, DOWNLOAD_STATUS::DLInstalling
);
805 //TODO: issue an install operation separately so that the apps could be downloaded in the background
806 WaitForSingleObject(shExInfo
.hProcess
, INFINITE
);
807 CloseHandle(shExInfo
.hProcess
);
811 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_INSTALL
);
816 if (hOut
!= INVALID_HANDLE_VALUE
)
819 InternetCloseHandle(hFile
);
820 InternetCloseHandle(hOpen
);
824 if (bCancelled
|| (SettingsInfo
.bDelInstaller
&& !bCab
))
825 DeleteFileW(Path
.GetString());
828 DownloadsListView
.SetDownloadStatus(iAppId
, DOWNLOAD_STATUS::DLFinished
);
832 SendMessageW(hDlg
, WM_CLOSE
, 0, 0);
836 BOOL
CDownloadManager::DownloadListOfApplications(const ATL::CSimpleArray
<CAvailableApplicationInfo
*>& AppsList
, BOOL bIsModal
)
838 if (AppsList
.GetSize() == 0)
843 // Initialize shared variables
844 for (INT i
= 0; i
< AppsList
.GetSize(); ++i
)
848 AppsToInstallList
.Add(*(AppsList
[i
]));
852 // Create a dialog and issue a download process
853 LaunchDownloadDialog(bIsModal
);
858 BOOL
CDownloadManager::DownloadApplication(CAvailableApplicationInfo
* pAppInfo
, BOOL bIsModal
)
863 Download(*pAppInfo
, bIsModal
);
867 VOID
CDownloadManager::DownloadApplicationsDB(LPCWSTR lpUrl
)
869 static DownloadInfo DatabaseDLInfo
;
870 DatabaseDLInfo
.szUrl
= lpUrl
;
871 DatabaseDLInfo
.m_szName
.LoadStringW(IDS_DL_DIALOG_DB_DISP
);
872 Download(DatabaseDLInfo
, TRUE
);
875 //TODO: Reuse the dialog
876 VOID
CDownloadManager::LaunchDownloadDialog(BOOL bIsModal
)
881 MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG
),
888 MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG
),