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 "BE\r\nGlobalSign nv-sa\r\nGlobalSign Domain Validation CA - SHA256 - G2"
51 #define CERT_SUBJECT_INFO "Domain Control Validated\r\n*.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
);
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
].szName
.GetString(), DLSTATUS_WAITING
);
266 VOID
SetDownloadStatus(INT ItemIndex
, DownloadStatus 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 DownloadStatus 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
;
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
;
554 ULONG dwContentLen
, dwBytesWritten
, dwBytesRead
, dwStatus
;
555 ULONG dwCurrentBytesRead
= 0;
556 ULONG dwStatusLen
= sizeof(dwStatus
);
558 BOOL bCancelled
= FALSE
;
559 BOOL bTempfile
= FALSE
;
562 HINTERNET hOpen
= NULL
;
563 HINTERNET hFile
= NULL
;
564 HANDLE hOut
= INVALID_HANDLE_VALUE
;
566 unsigned char lpBuffer
[4096];
567 LPCWSTR lpszAgent
= L
"RApps/1.0";
568 URL_COMPONENTS urlComponents
;
569 size_t urlLength
, filenameLength
;
571 const ATL::CSimpleArray
<DownloadInfo
> &InfoArray
= static_cast<DownloadParam
*>(param
)->AppInfo
;
572 LPCWSTR szCaption
= static_cast<DownloadParam
*>(param
)->szCaption
;
573 ATL::CStringW szNewCaption
;
575 if (InfoArray
.GetSize() <= 0)
577 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_DOWNLOAD
);
581 for (iAppId
= 0; iAppId
< InfoArray
.GetSize(); ++iAppId
)
583 // build the path for the download
584 p
= wcsrchr(InfoArray
[iAppId
].szUrl
.GetString(), L
'/');
585 q
= wcsrchr(InfoArray
[iAppId
].szUrl
.GetString(), L
'?');
587 // do we have a final slash separator?
591 // prepare the tentative length of the filename, maybe we've to remove part of it later on
592 filenameLength
= wcslen(p
) * sizeof(WCHAR
);
594 /* do we have query arguments in the target URL after the filename? account for them
595 (e.g. https://example.org/myfile.exe?no_adware_plz) */
596 if (q
&& q
> p
&& (q
- p
) > 0)
597 filenameLength
-= wcslen(q
- 1) * sizeof(WCHAR
);
599 // is this URL an update package for RAPPS? if so store it in a different place
600 if (InfoArray
[iAppId
].szUrl
== APPLICATION_DATABASE_URL
)
603 if (!GetStorageDirectory(Path
))
608 Path
= SettingsInfo
.szDownloadDir
;
611 // is the path valid? can we access it?
612 if (GetFileAttributesW(Path
.GetString()) == INVALID_FILE_ATTRIBUTES
)
614 if (!CreateDirectoryW(Path
.GetString(), NULL
))
618 // append a \ to the provided file system path, and the filename portion from the URL after that
620 Path
+= (LPWSTR
) (p
+ 1);
622 if (!bCab
&& InfoArray
[iAppId
].szSHA1
[0] && GetFileAttributesW(Path
.GetString()) != INVALID_FILE_ATTRIBUTES
)
624 // only open it in case of total correctness
625 if (VerifyInteg(InfoArray
[iAppId
].szSHA1
.GetString(), Path
))
629 // Reset progress bar
630 Item
= GetDlgItem(hDlg
, IDC_DOWNLOAD_PROGRESS
);
633 SendMessageW(Item
, PBM_SETPOS
, 0, 0);
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 // Add the download URL
649 SetDlgItemTextW(hDlg
, IDC_DOWNLOAD_STATUS
, InfoArray
[iAppId
].szUrl
.GetString());
651 DownloadsListView
.SetDownloadStatus(iAppId
, DLSTATUS_DOWNLOADING
);
655 CDownloadDialog_Constructor(hDlg
, &bCancelled
, IID_PPV_ARG(IBindStatusCallback
, &dl
));
660 /* FIXME: this should just be using the system-wide proxy settings */
661 switch (SettingsInfo
.Proxy
)
664 hOpen
= InternetOpenW(lpszAgent
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
666 case 1: // direct (no proxy)
667 hOpen
= InternetOpenW(lpszAgent
, INTERNET_OPEN_TYPE_DIRECT
, NULL
, NULL
, 0);
670 hOpen
= InternetOpenW(lpszAgent
, INTERNET_OPEN_TYPE_PROXY
, SettingsInfo
.szProxyServer
, SettingsInfo
.szNoProxyFor
, 0);
672 default: // preconfig
673 hOpen
= InternetOpenW(lpszAgent
, INTERNET_OPEN_TYPE_PRECONFIG
, NULL
, NULL
, 0);
680 hFile
= InternetOpenUrlW(hOpen
, InfoArray
[iAppId
].szUrl
.GetString(), NULL
, 0, INTERNET_FLAG_PRAGMA_NOCACHE
| INTERNET_FLAG_KEEP_CONNECTION
, 0);
684 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_DOWNLOAD2
);
688 if (!HttpQueryInfoW(hFile
, HTTP_QUERY_STATUS_CODE
| HTTP_QUERY_FLAG_NUMBER
, &dwStatus
, &dwStatusLen
, NULL
))
691 if (dwStatus
!= HTTP_STATUS_OK
)
693 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_DOWNLOAD
);
697 dwStatusLen
= sizeof(dwStatus
);
699 memset(&urlComponents
, 0, sizeof(urlComponents
));
700 urlComponents
.dwStructSize
= sizeof(urlComponents
);
702 urlLength
= InfoArray
[iAppId
].szUrl
.GetLength();
703 urlComponents
.dwSchemeLength
= urlLength
+ 1;
704 urlComponents
.lpszScheme
= (LPWSTR
) malloc(urlComponents
.dwSchemeLength
* sizeof(WCHAR
));
705 urlComponents
.dwHostNameLength
= urlLength
+ 1;
706 urlComponents
.lpszHostName
= (LPWSTR
) malloc(urlComponents
.dwHostNameLength
* sizeof(WCHAR
));
708 if (!InternetCrackUrlW(InfoArray
[iAppId
].szUrl
, urlLength
+ 1, ICU_DECODE
| ICU_ESCAPE
, &urlComponents
))
711 if (urlComponents
.nScheme
== INTERNET_SCHEME_HTTP
|| urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
)
712 HttpQueryInfoW(hFile
, HTTP_QUERY_CONTENT_LENGTH
| HTTP_QUERY_FLAG_NUMBER
, &dwContentLen
, &dwStatus
, 0);
714 if (urlComponents
.nScheme
== INTERNET_SCHEME_FTP
)
715 dwContentLen
= FtpGetFileSize(hFile
, &dwStatus
);
717 #ifdef USE_CERT_PINNING
718 // are we using HTTPS to download the RAPPS update package? check if the certificate is original
719 if ((urlComponents
.nScheme
== INTERNET_SCHEME_HTTPS
) &&
720 (wcscmp(InfoArray
[iAppId
].szUrl
, APPLICATION_DATABASE_URL
) == 0) &&
721 (!CertIsValid(hOpen
, urlComponents
.lpszHostName
)))
723 MessageBox_LoadString(hMainWnd
, IDS_CERT_DOES_NOT_MATCH
);
728 free(urlComponents
.lpszScheme
);
729 free(urlComponents
.lpszHostName
);
731 hOut
= CreateFileW(Path
.GetString(), GENERIC_WRITE
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
, CREATE_ALWAYS
, 0, NULL
);
733 if (hOut
== INVALID_HANDLE_VALUE
)
736 dwCurrentBytesRead
= 0;
739 if (!InternetReadFile(hFile
, lpBuffer
, _countof(lpBuffer
), &dwBytesRead
))
741 MessageBox_LoadString(hMainWnd
, IDS_INTERRUPTED_DOWNLOAD
);
745 if (!WriteFile(hOut
, &lpBuffer
[0], dwBytesRead
, &dwBytesWritten
, NULL
))
747 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_WRITE
);
751 dwCurrentBytesRead
+= dwBytesRead
;
752 dl
->OnProgress(dwCurrentBytesRead
, dwContentLen
, 0, InfoArray
[iAppId
].szUrl
.GetString());
753 } while (dwBytesRead
&& !bCancelled
);
756 hOut
= INVALID_HANDLE_VALUE
;
761 /* if this thing isn't a RAPPS update and it has a SHA-1 checksum
762 verify its integrity by using the native advapi32.A_SHA1 functions */
763 if (!bCab
&& InfoArray
[iAppId
].szSHA1
[0] != 0)
765 ATL::CStringW szMsgText
;
767 // change a few strings in the download dialog to reflect the verification process
768 if (!szMsgText
.LoadStringW(IDS_INTEG_CHECK_TITLE
))
771 SetWindowTextW(hDlg
, szMsgText
.GetString());
772 SendMessageW(GetDlgItem(hDlg
, IDC_DOWNLOAD_STATUS
), WM_SETTEXT
, 0, (LPARAM
) Path
.GetString());
774 // this may take a while, depending on the file size
775 if (!VerifyInteg(InfoArray
[iAppId
].szSHA1
.GetString(), Path
.GetString()))
777 if (!szMsgText
.LoadStringW(IDS_INTEG_CHECK_FAIL
))
780 MessageBoxW(hDlg
, szMsgText
.GetString(), NULL
, MB_OK
| MB_ICONERROR
);
786 DownloadsListView
.SetDownloadStatus(iAppId
, DLSTATUS_WAITING_INSTALL
);
791 SHELLEXECUTEINFOW shExInfo
= {0};
792 shExInfo
.cbSize
= sizeof(shExInfo
);
793 shExInfo
.fMask
= SEE_MASK_NOCLOSEPROCESS
;
794 shExInfo
.lpVerb
= L
"open";
795 shExInfo
.lpFile
= Path
.GetString();
796 shExInfo
.lpParameters
= L
"";
797 shExInfo
.nShow
= SW_SHOW
;
799 if (ShellExecuteExW(&shExInfo
))
801 DownloadsListView
.SetDownloadStatus(iAppId
, DLSTATUS_INSTALLING
);
802 //TODO: issue an install operation separately so that the apps could be downloaded in the background
803 WaitForSingleObject(shExInfo
.hProcess
, INFINITE
);
804 CloseHandle(shExInfo
.hProcess
);
808 MessageBox_LoadString(hMainWnd
, IDS_UNABLE_TO_INSTALL
);
813 if (hOut
!= INVALID_HANDLE_VALUE
)
816 InternetCloseHandle(hFile
);
817 InternetCloseHandle(hOpen
);
821 if (bCancelled
|| (SettingsInfo
.bDelInstaller
&& !bCab
))
822 DeleteFileW(Path
.GetString());
825 DownloadsListView
.SetDownloadStatus(iAppId
, DLSTATUS_FINISHED
);
828 delete static_cast<DownloadParam
*>(param
);
829 SendMessageW(hDlg
, WM_CLOSE
, 0, 0);
833 BOOL
CDownloadManager::DownloadListOfApplications(const ATL::CSimpleArray
<CAvailableApplicationInfo
*>& AppsList
, BOOL bIsModal
)
835 if (AppsList
.GetSize() == 0)
840 // Initialize shared variables
841 for (INT i
= 0; i
< AppsList
.GetSize(); ++i
)
845 AppsToInstallList
.Add(*(AppsList
[i
]));
849 // Create a dialog and issue a download process
850 LaunchDownloadDialog(bIsModal
);
855 BOOL
CDownloadManager::DownloadApplication(CAvailableApplicationInfo
* pAppInfo
, BOOL bIsModal
)
860 Download(*pAppInfo
, bIsModal
);
864 VOID
CDownloadManager::DownloadApplicationsDB(LPCWSTR lpUrl
)
866 static DownloadInfo DatabaseDLInfo
;
867 DatabaseDLInfo
.szUrl
= lpUrl
;
868 DatabaseDLInfo
.szName
.LoadStringW(IDS_DL_DIALOG_DB_DISP
);
869 Download(DatabaseDLInfo
, TRUE
);
872 //TODO: Reuse the dialog
873 VOID
CDownloadManager::LaunchDownloadDialog(BOOL bIsModal
)
878 MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG
),
885 MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG
),