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
);
73 DownloadInfo(const CAvailableApplicationInfo
& AppInfo
)
74 :szUrl(AppInfo
.m_szUrlDownload
), szName(AppInfo
.m_szName
), szSHA1(AppInfo
.m_szSHA1
)
85 DownloadParam() : Dialog(NULL
), AppInfo(), szCaption(NULL
) {}
86 DownloadParam(HWND dlg
, const ATL::CSimpleArray
<DownloadInfo
> &info
, LPCWSTR caption
)
87 : Dialog(dlg
), AppInfo(info
), szCaption(caption
)
92 ATL::CSimpleArray
<DownloadInfo
> AppInfo
;
97 class CDownloadDialog
:
98 public CComObjectRootEx
<CComMultiThreadModelNoCS
>,
99 public IBindStatusCallback
103 BOOL m_UrlHasBeenCopied
;
108 //DestroyWindow(m_hDialog);
111 HRESULT
Initialize(HWND Dlg
, BOOL
*pbCancelled
)
114 m_pbCancelled
= pbCancelled
;
115 m_UrlHasBeenCopied
= FALSE
;
119 virtual HRESULT STDMETHODCALLTYPE
OnStartBinding(
126 virtual HRESULT STDMETHODCALLTYPE
GetPriority(
132 virtual HRESULT STDMETHODCALLTYPE
OnLowResource(
138 virtual HRESULT STDMETHODCALLTYPE
OnProgress(
142 LPCWSTR szStatusText
)
147 Item
= GetDlgItem(m_hDialog
, IDC_DOWNLOAD_PROGRESS
);
148 if (Item
&& ulProgressMax
)
150 WCHAR szProgress
[100];
151 WCHAR szProgressMax
[100];
152 UINT uiPercentage
= ((ULONGLONG
) ulProgress
* 100) / ulProgressMax
;
154 /* send the current progress to the progress bar */
155 SendMessageW(Item
, PBM_SETPOS
, uiPercentage
, 0);
157 /* format the bits and bytes into pretty and accessible units... */
158 StrFormatByteSizeW(ulProgress
, szProgress
, _countof(szProgress
));
159 StrFormatByteSizeW(ulProgressMax
, szProgressMax
, _countof(szProgressMax
));
161 /* ...and post all of it to our subclassed progress bar text subroutine */
162 ATL::CStringW m_ProgressText
;
163 m_ProgressText
.Format(L
"%u%% \x2014 %ls / %ls",
167 SendMessageW(Item
, WM_SETTEXT
, 0, (LPARAM
) m_ProgressText
.GetString());
170 Item
= GetDlgItem(m_hDialog
, IDC_DOWNLOAD_STATUS
);
171 if (Item
&& szStatusText
&& wcslen(szStatusText
) > 0 && m_UrlHasBeenCopied
== FALSE
)
173 DWORD len
= wcslen(szStatusText
) + 1;
176 /* beautify our url for display purposes */
177 if (!InternetCanonicalizeUrlW(szStatusText
, buf
.GetBuffer(len
), &len
, ICU_DECODE
| ICU_NO_ENCODE
))
179 /* just use the original */
188 /* paste it into our dialog and don't do it again in this instance */
189 SendMessageW(Item
, WM_SETTEXT
, 0, (LPARAM
) buf
.GetString());
190 m_UrlHasBeenCopied
= TRUE
;
193 SetLastError(ERROR_SUCCESS
);
194 r
= GetWindowLongPtrW(m_hDialog
, GWLP_USERDATA
);
195 if (r
|| GetLastError() != ERROR_SUCCESS
)
197 *m_pbCancelled
= TRUE
;
204 virtual HRESULT STDMETHODCALLTYPE
OnStopBinding(
211 virtual HRESULT STDMETHODCALLTYPE
GetBindInfo(
218 virtual HRESULT STDMETHODCALLTYPE
OnDataAvailable(
221 FORMATETC
*pformatetc
,
227 virtual HRESULT STDMETHODCALLTYPE
OnObjectAvailable(
234 BEGIN_COM_MAP(CDownloadDialog
)
235 COM_INTERFACE_ENTRY_IID(IID_IBindStatusCallback
, IBindStatusCallback
)
239 class CDowloadingAppsListView
240 : public CUiWindow
<CListView
>
243 HWND
Create(HWND hwndParent
)
245 RECT r
= {10, 150, 320, 350};
246 const DWORD style
= WS_CHILD
| WS_VISIBLE
| LVS_REPORT
| LVS_SINGLESEL
247 | LVS_SHOWSELALWAYS
| LVS_NOSORTHEADER
| LVS_NOCOLUMNHEADER
;
249 HWND hwnd
= CListView::Create(hwndParent
, r
, NULL
, style
, WS_EX_CLIENTEDGE
);
251 AddColumn(0, 150, LVCFMT_LEFT
);
252 AddColumn(1, 120, LVCFMT_LEFT
);
257 VOID
LoadList(ATL::CSimpleArray
<DownloadInfo
> arrInfo
)
259 for (INT i
= 0; i
< arrInfo
.GetSize(); ++i
)
261 AddRow(i
, arrInfo
[i
].szName
.GetString(), DOWNLOAD_STATUS::DLWaiting
);
265 VOID
SetDownloadStatus(INT ItemIndex
, DOWNLOAD_STATUS Status
)
267 HWND hListView
= GetWindow();
268 ATL::CStringW szBuffer
= LoadStatusString(Status
);
269 ListView_SetItemText(hListView
, ItemIndex
, 1, const_cast<LPWSTR
>(szBuffer
.GetString()));
272 BOOL
AddItem(INT ItemIndex
, LPWSTR lpText
)
276 ZeroMemory(&Item
, sizeof(Item
));
278 Item
.mask
= LVIF_TEXT
| LVIF_STATE
;
279 Item
.pszText
= lpText
;
280 Item
.iItem
= ItemIndex
;
282 return InsertItem(&Item
);
285 VOID
AddRow(INT RowIndex
, LPCWSTR szAppName
, const DOWNLOAD_STATUS Status
)
287 ATL::CStringW szStatus
= LoadStatusString(Status
);
289 const_cast<LPWSTR
>(szAppName
));
290 SetDownloadStatus(RowIndex
, Status
);
293 BOOL
AddColumn(INT Index
, INT Width
, INT Format
)
296 ZeroMemory(&Column
, sizeof(Column
));
298 Column
.mask
= LVCF_FMT
| LVCF_WIDTH
| LVCF_SUBITEM
;
299 Column
.iSubItem
= Index
;
303 return (InsertColumn(Index
, &Column
) == -1) ? FALSE
: TRUE
;
308 HRESULT WINAPI
CDownloadDialog_Constructor(HWND Dlg
, BOOL
*pbCancelled
, REFIID riid
, LPVOID
*ppv
)
310 return ShellObjectCreatorInit
<CDownloadDialog
>(Dlg
, pbCancelled
, riid
, ppv
);
313 #ifdef USE_CERT_PINNING
314 static BOOL
CertIsValid(HINTERNET hInternet
, LPWSTR lpszHostName
)
318 DWORD certInfoLength
;
320 INTERNET_CERTIFICATE_INFOW certInfo
;
322 hConnect
= InternetConnectW(hInternet
, lpszHostName
, INTERNET_DEFAULT_HTTPS_PORT
, NULL
, NULL
, INTERNET_SERVICE_HTTP
, INTERNET_FLAG_SECURE
, 0);
325 hRequest
= HttpOpenRequestW(hConnect
, L
"HEAD", NULL
, NULL
, NULL
, NULL
, INTERNET_FLAG_SECURE
, 0);
326 if (hRequest
!= NULL
)
328 Ret
= HttpSendRequestW(hRequest
, L
"", 0, NULL
, 0);
331 certInfoLength
= sizeof(certInfo
);
332 Ret
= InternetQueryOptionW(hRequest
,
333 INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT
,
338 if (certInfo
.lpszEncryptionAlgName
)
339 LocalFree(certInfo
.lpszEncryptionAlgName
);
340 if (certInfo
.lpszIssuerInfo
)
342 if (strcmp((LPSTR
) certInfo
.lpszIssuerInfo
, CERT_ISSUER_INFO
) != 0)
344 LocalFree(certInfo
.lpszIssuerInfo
);
346 if (certInfo
.lpszProtocolName
)
347 LocalFree(certInfo
.lpszProtocolName
);
348 if (certInfo
.lpszSignatureAlgName
)
349 LocalFree(certInfo
.lpszSignatureAlgName
);
350 if (certInfo
.lpszSubjectInfo
)
352 if (strcmp((LPSTR
) certInfo
.lpszSubjectInfo
, CERT_SUBJECT_INFO
) != 0)
354 LocalFree(certInfo
.lpszSubjectInfo
);
358 InternetCloseHandle(hRequest
);
360 InternetCloseHandle(hConnect
);
366 inline VOID
MessageBox_LoadString(HWND hMainWnd
, INT StringID
)
368 ATL::CString szMsgText
;
369 if (szMsgText
.LoadStringW(StringID
))
371 MessageBoxW(hMainWnd
, szMsgText
.GetString(), NULL
, MB_OK
| MB_ICONERROR
);
376 ATL::CSimpleArray
<DownloadInfo
> CDownloadManager::AppsToInstallList
;
377 CDowloadingAppsListView
CDownloadManager::DownloadsListView
;
378 INT
CDownloadManager::iCurrentApp
;
380 VOID
CDownloadManager::Download(const DownloadInfo
&DLInfo
, BOOL bIsModal
)
382 AppsToInstallList
.RemoveAll();
383 AppsToInstallList
.Add(DLInfo
);
384 LaunchDownloadDialog(bIsModal
);
387 INT_PTR CALLBACK
CDownloadManager::DownloadDlgProc(HWND Dlg
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
389 static WCHAR szCaption
[MAX_PATH
];
395 HICON hIconSm
, hIconBg
;
397 hIconBg
= (HICON
) GetClassLongW(hMainWnd
, GCLP_HICON
);
398 hIconSm
= (HICON
) GetClassLongW(hMainWnd
, GCLP_HICONSM
);
400 if (hIconBg
&& hIconSm
)
402 SendMessageW(Dlg
, WM_SETICON
, ICON_BIG
, (LPARAM
) hIconBg
);
403 SendMessageW(Dlg
, WM_SETICON
, ICON_SMALL
, (LPARAM
) hIconSm
);
406 SetWindowLongW(Dlg
, GWLP_USERDATA
, 0);
407 HWND Item
= GetDlgItem(Dlg
, IDC_DOWNLOAD_PROGRESS
);
410 // initialize the default values for our nifty progress bar
411 // and subclass it so that it learns to print a status text
412 SendMessageW(Item
, PBM_SETRANGE
, 0, MAKELPARAM(0, 100));
413 SendMessageW(Item
, PBM_SETPOS
, 0, 0);
415 SetWindowSubclass(Item
, DownloadProgressProc
, 0, 0);
419 HWND hListView
= DownloadsListView
.Create(Dlg
);
424 DownloadsListView
.LoadList(AppsToInstallList
);
426 ShowWindow(Dlg
, SW_SHOW
);
428 // Get a dlg string for later use
429 GetWindowTextW(Dlg
, szCaption
, MAX_PATH
);
431 // Start download process
432 DownloadParam
*param
= new DownloadParam(Dlg
, AppsToInstallList
, szCaption
);
434 HANDLE Thread
= CreateThread(NULL
, 0, ThreadFunc
, (LPVOID
) param
, 0, &ThreadId
);
442 AppsToInstallList
.RemoveAll();
447 if (wParam
== IDCANCEL
)
449 SetWindowLongW(Dlg
, GWLP_USERDATA
, 1);
450 PostMessageW(Dlg
, WM_CLOSE
, 0, 0);
456 //DestroyWindow(Dlg);
464 LRESULT CALLBACK
CDownloadManager::DownloadProgressProc(HWND hWnd
,
468 UINT_PTR uIdSubclass
,
471 static ATL::CStringW szProgressText
;
479 szProgressText
= (PCWSTR
) lParam
;
488 HDC hDC
= BeginPaint(hWnd
, &ps
), hdcMem
;
492 UINT win_width
, win_height
;
494 GetClientRect(hWnd
, &myRect
);
496 /* grab the progress bar rect size */
497 win_width
= myRect
.right
- myRect
.left
;
498 win_height
= myRect
.bottom
- myRect
.top
;
500 /* create an off-screen DC for double-buffering */
501 hdcMem
= CreateCompatibleDC(hDC
);
502 hbmMem
= CreateCompatibleBitmap(hDC
, win_width
, win_height
);
504 hOld
= SelectObject(hdcMem
, hbmMem
);
506 /* call the original draw code and redirect it to our memory buffer */
507 DefSubclassProc(hWnd
, uMsg
, (WPARAM
) hdcMem
, lParam
);
509 /* draw our nifty progress text over it */
510 SelectFont(hdcMem
, GetStockFont(DEFAULT_GUI_FONT
));
511 DrawShadowText(hdcMem
, szProgressText
.GetString(), szProgressText
.GetLength(),
513 DT_CENTER
| DT_VCENTER
| DT_NOPREFIX
| DT_SINGLELINE
,
514 GetSysColor(COLOR_CAPTIONTEXT
),
515 GetSysColor(COLOR_3DSHADOW
),
518 /* transfer the off-screen DC to the screen */
519 BitBlt(hDC
, 0, 0, win_width
, win_height
, hdcMem
, 0, 0, SRCCOPY
);
521 /* free the off-screen DC */
522 SelectObject(hdcMem
, hOld
);
523 DeleteObject(hbmMem
);
530 /* Raymond Chen says that we should safely unsubclass all the things!
531 (http://blogs.msdn.com/b/oldnewthing/archive/2003/11/11/55653.aspx) */
535 szProgressText
.Empty();
536 RemoveWindowSubclass(hWnd
, DownloadProgressProc
, uIdSubclass
);
540 return DefSubclassProc(hWnd
, uMsg
, wParam
, lParam
);
544 DWORD WINAPI
CDownloadManager::ThreadFunc(LPVOID param
)
546 CComPtr
<IBindStatusCallback
> dl
;
550 HWND hDlg
= static_cast<DownloadParam
*>(param
)->Dialog
;
552 ULONG dwContentLen
, dwBytesWritten
, dwBytesRead
, dwStatus
;
553 ULONG dwCurrentBytesRead
= 0;
554 ULONG dwStatusLen
= sizeof(dwStatus
);
556 BOOL bCancelled
= FALSE
;
557 BOOL bTempfile
= FALSE
;
560 HINTERNET hOpen
= NULL
;
561 HINTERNET hFile
= NULL
;
562 HANDLE hOut
= INVALID_HANDLE_VALUE
;
564 unsigned char lpBuffer
[4096];
565 LPCWSTR lpszAgent
= L
"RApps/1.0";
566 URL_COMPONENTS urlComponents
;
567 size_t urlLength
, filenameLength
;
569 const INT iAppId
= iCurrentApp
;
570 const ATL::CSimpleArray
<DownloadInfo
> &InfoArray
= static_cast<DownloadParam
*>(param
)->AppInfo
;
571 LPCWSTR szCaption
= static_cast<DownloadParam
*>(param
)->szCaption
;
572 ATL::CStringW szNewCaption
;
575 if (InfoArray
.GetSize() <= 0)
577 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_DOWNLOAD
);
581 for (INT iAppId
= 0; iAppId
< InfoArray
.GetSize(); ++iAppId
)
583 const DownloadInfo
&CurrentInfo
= InfoArray
[iAppId
];
585 // build the path for the download
586 p
= wcsrchr(CurrentInfo
.szUrl
.GetString(), L
'/');
587 q
= wcsrchr(CurrentInfo
.szUrl
.GetString(), L
'?');
589 // do we have a final slash separator?
593 // prepare the tentative length of the filename, maybe we've to remove part of it later on
594 filenameLength
= wcslen(p
) * sizeof(WCHAR
);
596 /* do we have query arguments in the target URL after the filename? account for them
597 (e.g. https://example.org/myfile.exe?no_adware_plz) */
598 if (q
&& q
> p
&& (q
- p
) > 0)
599 filenameLength
-= wcslen(q
- 1) * sizeof(WCHAR
);
601 // is this URL an update package for RAPPS? if so store it in a different place
602 if (CurrentInfo
.szUrl
== APPLICATION_DATABASE_URL
)
605 if (!GetStorageDirectory(Path
))
610 Path
= SettingsInfo
.szDownloadDir
;
613 // is the path valid? can we access it?
614 if (GetFileAttributesW(Path
.GetString()) == INVALID_FILE_ATTRIBUTES
)
616 if (!CreateDirectoryW(Path
.GetString(), NULL
))
620 // append a \ to the provided file system path, and the filename portion from the URL after that
622 Path
+= (LPWSTR
) (p
+ 1);
624 if (!bCab
&& CurrentInfo
.szSHA1
[0] && GetFileAttributesW(Path
.GetString()) != INVALID_FILE_ATTRIBUTES
)
626 // only open it in case of total correctness
627 if (VerifyInteg(CurrentInfo
.szSHA1
.GetString(), Path
))
631 // Reset progress bar
632 HWND Item
= GetDlgItem(hDlg
, IDC_DOWNLOAD_PROGRESS
);
635 SendMessageW(Item
, PBM_SETPOS
, 0, 0);
638 // Change caption to show the currently downloaded app
641 szNewCaption
.Format(szCaption
, CurrentInfo
.szName
.GetString());
645 szNewCaption
.LoadStringW(IDS_DL_DIALOG_DB_DOWNLOAD_DISP
);
648 SetWindowTextW(hDlg
, szNewCaption
.GetString());
650 // Add the download URL
651 SetDlgItemTextW(hDlg
, IDC_DOWNLOAD_STATUS
, CurrentInfo
.szUrl
.GetString());
653 DownloadsListView
.SetDownloadStatus(iAppId
, DOWNLOAD_STATUS::DLDownloading
);
657 CDownloadDialog_Constructor(hDlg
, &bCancelled
, IID_PPV_ARG(IBindStatusCallback
, &dl
));
662 /* FIXME: this should just be using the system-wide proxy settings */
663 switch (SettingsInfo
.Proxy
)
666 hOpen
= InternetOpenW(lpszAgent
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
668 case 1: // direct (no proxy)
669 hOpen
= InternetOpenW(lpszAgent
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
672 hOpen
= InternetOpenW(lpszAgent
, INTERNET_OPEN_TYPE_PROXY
, SettingsInfo
.szProxyServer
, SettingsInfo
.szNoProxyFor
, 0);
674 default: // preconfig
675 hOpen
= InternetOpenW(lpszAgent
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
682 hFile
= InternetOpenUrlW(hOpen
, CurrentInfo
.szUrl
.GetString(), NULL
, 0, INTERNET_FLAG_PRAGMA_NOCACHE
| INTERNET_FLAG_KEEP_CONNECTION
, 0);
686 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_DOWNLOAD2
);
690 if (!HttpQueryInfoW(hFile
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &dwStatus
, &dwStatusLen
, NULL
))
693 if (dwStatus
!= HTTP_STATUS_OK
)
695 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_DOWNLOAD
);
699 dwStatusLen
= sizeof(dwStatus
);
701 memset(&urlComponents
, 0, sizeof(urlComponents
));
702 urlComponents
.dwStructSize
= sizeof(urlComponents
);
704 urlLength
= CurrentInfo
.szUrl
.GetLength();
705 urlComponents
.dwSchemeLength
= urlLength
+ 1;
706 urlComponents
.lpszScheme
= (LPWSTR
) malloc(urlComponents
.dwSchemeLength
* sizeof(WCHAR
));
707 urlComponents
.dwHostNameLength
= urlLength
+ 1;
708 urlComponents
.lpszHostName
= (LPWSTR
) malloc(urlComponents
.dwHostNameLength
* sizeof(WCHAR
));
710 if (!InternetCrackUrlW(CurrentInfo
.szUrl
, urlLength
+ 1, ICU_DECODE
| ICU_ESCAPE
, &urlComponents
))
713 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
|| urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
)
714 HttpQueryInfoW(hFile
, HTTP_QUERY_CONTENT_LENGTH
| HTTP_QUERY_FLAG_NUMBER
, &dwContentLen
, &dwStatus
, 0);
716 if (urlComponents
.nScheme
== INTERNET_SCHEME_FTP
)
717 dwContentLen
= FtpGetFileSize(hFile
, &dwStatus
);
719 #ifdef USE_CERT_PINNING
720 // are we using HTTPS to download the RAPPS update package? check if the certificate is original
721 if ((urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) &&
722 (wcscmp(CurrentInfo
.szUrl
, APPLICATION_DATABASE_URL
) == 0) &&
723 (!CertIsValid(hOpen
, urlComponents
.lpszHostName
)))
725 MessageBox_LoadString(hMainWnd
, IDS_CERT_DOES_NOT_MATCH
);
730 free(urlComponents
.lpszScheme
);
731 free(urlComponents
.lpszHostName
);
733 hOut
= CreateFileW(Path
.GetString(), GENERIC_WRITE
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, CREATE_ALWAYS
, 0, NULL
);
735 if (hOut
== INVALID_HANDLE_VALUE
)
738 dwCurrentBytesRead
= 0;
741 if (!InternetReadFile(hFile
, lpBuffer
, _countof(lpBuffer
), &dwBytesRead
))
743 MessageBox_LoadString(hMainWnd
, IDS_INTERRUPTED_DOWNLOAD
);
747 if (!WriteFile(hOut
, &lpBuffer
[0], dwBytesRead
, &dwBytesWritten
, NULL
))
749 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_WRITE
);
753 dwCurrentBytesRead
+= dwBytesRead
;
754 dl
->OnProgress(dwCurrentBytesRead
, dwContentLen
, 0, CurrentInfo
.szUrl
.GetString());
755 } while (dwBytesRead
&& !bCancelled
);
758 hOut
= INVALID_HANDLE_VALUE
;
763 /* if this thing isn't a RAPPS update and it has a SHA-1 checksum
764 verify its integrity by using the native advapi32.A_SHA1 functions */
765 if (!bCab
&& CurrentInfo
.szSHA1
[0] != 0)
767 ATL::CStringW szMsgText
;
769 // change a few strings in the download dialog to reflect the verification process
770 if (!szMsgText
.LoadStringW(IDS_INTEG_CHECK_TITLE
))
773 SetWindowTextW(hDlg
, szMsgText
.GetString());
774 SendMessageW(GetDlgItem(hDlg
, IDC_DOWNLOAD_STATUS
), WM_SETTEXT
, 0, (LPARAM
) Path
.GetString());
776 // this may take a while, depending on the file size
777 if (!VerifyInteg(CurrentInfo
.szSHA1
.GetString(), Path
.GetString()))
779 if (!szMsgText
.LoadStringW(IDS_INTEG_CHECK_FAIL
))
782 MessageBoxW(hDlg
, szMsgText
.GetString(), NULL
, MB_OK
| MB_ICONERROR
);
788 DownloadsListView
.SetDownloadStatus(iAppId
, DOWNLOAD_STATUS::DLWaitingToInstall
);
793 SHELLEXECUTEINFOW shExInfo
= {0};
794 shExInfo
.cbSize
= sizeof(shExInfo
);
795 shExInfo
.fMask
= SEE_MASK_NOCLOSEPROCESS
;
796 shExInfo
.lpVerb
= L
"open";
797 shExInfo
.lpFile
= Path
.GetString();
798 shExInfo
.lpParameters
= L
"";
799 shExInfo
.nShow
= SW_SHOW
;
801 if (ShellExecuteExW(&shExInfo
))
803 DownloadsListView
.SetDownloadStatus(iAppId
, DOWNLOAD_STATUS::DLInstalling
);
804 //TODO: issue an install operation separately so that the apps could be downloaded in the background
805 WaitForSingleObject(shExInfo
.hProcess
, INFINITE
);
806 CloseHandle(shExInfo
.hProcess
);
810 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_INSTALL
);
815 if (hOut
!= INVALID_HANDLE_VALUE
)
818 InternetCloseHandle(hFile
);
819 InternetCloseHandle(hOpen
);
823 if (bCancelled
|| (SettingsInfo
.bDelInstaller
&& !bCab
))
824 DeleteFileW(Path
.GetString());
827 DownloadsListView
.SetDownloadStatus(iAppId
, DOWNLOAD_STATUS::DLFinished
);
831 SendMessageW(hDlg
, WM_CLOSE
, 0, 0);
835 BOOL
CDownloadManager::DownloadListOfApplications(const ATL::CSimpleArray
<CAvailableApplicationInfo
*>& AppsList
, BOOL bIsModal
)
837 if (AppsList
.GetSize() == 0)
842 // Initialize shared variables
843 for (INT i
= 0; i
< AppsList
.GetSize(); ++i
)
847 AppsToInstallList
.Add(*(AppsList
[i
]));
851 // Create a dialog and issue a download process
852 LaunchDownloadDialog(bIsModal
);
857 BOOL
CDownloadManager::DownloadApplication(CAvailableApplicationInfo
* pAppInfo
, BOOL bIsModal
)
862 Download(*pAppInfo
, bIsModal
);
866 VOID
CDownloadManager::DownloadApplicationsDB(LPCWSTR lpUrl
)
868 static DownloadInfo DatabaseDLInfo
;
869 DatabaseDLInfo
.szUrl
= lpUrl
;
870 DatabaseDLInfo
.szName
.LoadStringW(IDS_DL_DIALOG_DB_DISP
);
871 Download(DatabaseDLInfo
, TRUE
);
874 //TODO: Reuse the dialog
875 VOID
CDownloadManager::LaunchDownloadDialog(BOOL bIsModal
)
880 MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG
),
887 MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG
),