-/* PROJECT: ReactOS Applications Manager
- * LICENSE: GPL - See COPYING in the top level directory
+/*
+ * PROJECT: ReactOS Applications Manager
+ * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
* FILE: base/applications/rapps/loaddlg.cpp
* PURPOSE: Displaying a download dialog
* COPYRIGHT: Copyright 2001 John R. Sheets (for CodeWeavers)
* Copyright 2005 Ge van Geldorp (gvg@reactos.org)
* Copyright 2009 Dmitry Chapyshev (dmitry@reactos.org)
* Copyright 2015 Ismael Ferreras Morezuelas (swyterzone+ros@gmail.com)
- * Copyright 2017 Alexander Shaposhnikov (chaez.san@gmail.com)
+ * Copyright 2017 Alexander Shaposhnikov (sanchaez@reactos.org)
*/
/*
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-
-#include "rapps.h"
+#include "defines.h"
#include <shlobj_undoc.h>
#include <shlguid_undoc.h>
#include <windowsx.h>
#include "rosui.h"
+#include "dialogs.h"
+#include "misc.h"
+
+#ifdef USE_CERT_PINNING
+#define CERT_ISSUER_INFO "BE\r\nGlobalSign nv-sa\r\nGlobalSign Domain Validation CA - SHA256 - G2"
+#define CERT_SUBJECT_INFO "Domain Control Validated\r\n*.reactos.org"
+#endif
typedef enum
{
return szString;
}
+struct DownloadInfo
+{
+ DownloadInfo() {}
+ DownloadInfo(const CAvailableApplicationInfo& AppInfo)
+ :szUrl(AppInfo.m_szUrlDownload), szName(AppInfo.m_szName), szSHA1(AppInfo.m_szSHA1)
+ {
+ }
+
+ ATL::CStringW szUrl;
+ ATL::CStringW szName;
+ ATL::CStringW szSHA1;
+};
+
+struct DownloadParam
+{
+ DownloadParam() : Dialog(NULL), AppInfo(), szCaption(NULL) {}
+ DownloadParam(HWND dlg, const ATL::CSimpleArray<DownloadInfo> &info, LPCWSTR caption)
+ : Dialog(dlg), AppInfo(info), szCaption(caption)
+ {
+ }
+
+ HWND Dialog;
+ ATL::CSimpleArray<DownloadInfo> AppInfo;
+ LPCWSTR szCaption;
+};
+
+
class CDownloadDialog :
public CComObjectRootEx<CComMultiThreadModelNoCS>,
public IBindStatusCallback
m_UrlHasBeenCopied = TRUE;
}
- SetLastError(0);
+ SetLastError(ERROR_SUCCESS);
r = GetWindowLongPtrW(m_hDialog, GWLP_USERDATA);
- if (0 != r || 0 != GetLastError())
+ if (r || GetLastError() != ERROR_SUCCESS)
{
*m_pbCancelled = TRUE;
return E_ABORT;
return hwnd;
}
- VOID LoadList(ATL::CSimpleArray<PAPPLICATION_INFO> arrInfo)
+ VOID LoadList(ATL::CSimpleArray<DownloadInfo> arrInfo)
{
for (INT i = 0; i < arrInfo.GetSize(); ++i)
{
- PAPPLICATION_INFO AppInfo = arrInfo[i];
- AddRow(i, AppInfo->szName.GetString(), DOWNLOAD_STATUS::DLWaiting);
+ AddRow(i, arrInfo[i].szName.GetString(), DOWNLOAD_STATUS::DLWaiting);
}
}
}
#endif
-inline VOID
-MessageBox_LoadString(HWND hMainWnd, INT StringID)
+inline VOID MessageBox_LoadString(HWND hMainWnd, INT StringID)
{
ATL::CString szMsgText;
- if (szMsgText.LoadStringW(hInst, StringID))
+ if (szMsgText.LoadStringW(StringID))
{
MessageBoxW(hMainWnd, szMsgText.GetString(), NULL, MB_OK | MB_ICONERROR);
}
}
// CDownloadManager
-PAPPLICATION_INFO CDownloadManager::AppInfo;
-ATL::CSimpleArray<PAPPLICATION_INFO> CDownloadManager::AppsToInstallList;
+ATL::CSimpleArray<DownloadInfo> CDownloadManager::AppsToInstallList;
CDowloadingAppsListView CDownloadManager::DownloadsListView;
INT CDownloadManager::iCurrentApp;
-#define DL_START_NEW WM_APP + 1
+VOID CDownloadManager::Download(const DownloadInfo &DLInfo, BOOL bIsModal)
+{
+ AppsToInstallList.RemoveAll();
+ AppsToInstallList.Add(DLInfo);
+ LaunchDownloadDialog(bIsModal);
+}
INT_PTR CALLBACK CDownloadManager::DownloadDlgProc(HWND Dlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
- HANDLE Thread;
- DWORD ThreadId;
- HWND Item;
static WCHAR szCaption[MAX_PATH];
switch (uMsg)
}
SetWindowLongW(Dlg, GWLP_USERDATA, 0);
- Item = GetDlgItem(Dlg, IDC_DOWNLOAD_PROGRESS);
+ HWND Item = GetDlgItem(Dlg, IDC_DOWNLOAD_PROGRESS);
if (Item)
{
// initialize the default values for our nifty progress bar
SetWindowSubclass(Item, DownloadProgressProc, 0, 0);
}
- // Get a dlg string for later use
- GetWindowTextW(Dlg, szCaption, MAX_PATH);
// Add a ListView
HWND hListView = DownloadsListView.Create(Dlg);
return FALSE;
}
DownloadsListView.LoadList(AppsToInstallList);
- iCurrentApp = -1;
ShowWindow(Dlg, SW_SHOW);
- //Start new download
- SendMessageW(Dlg, DL_START_NEW, 0, 0);
+ // Get a dlg string for later use
+ GetWindowTextW(Dlg, szCaption, MAX_PATH);
+
+ // Start download process
+ DownloadParam *param = new DownloadParam(Dlg, AppsToInstallList, szCaption);
+ DWORD ThreadId;
+ HANDLE Thread = CreateThread(NULL, 0, ThreadFunc, (LPVOID) param, 0, &ThreadId);
+ if (!Thread)
+ {
+ return FALSE;
+ }
+
+ CloseHandle(Thread);
+ AppsToInstallList.RemoveAll();
return TRUE;
}
+
case WM_COMMAND:
if (wParam == IDCANCEL)
{
}
return FALSE;
- case DL_START_NEW:
-
- ++iCurrentApp;
- // If some downloads left we issue it
- if (iCurrentApp < AppsToInstallList.GetSize())
- {
- AppInfo = AppsToInstallList[iCurrentApp];
- if (!AppInfo)
- {
- return FALSE;
- }
-
- ATL::CStringW szNewCaption;
-
- // Reset progress bar
- Item = GetDlgItem(Dlg, IDC_DOWNLOAD_PROGRESS);
- if (Item)
- {
- SendMessageW(Item, PBM_SETPOS, 0, 0);
- }
-
- // Change caption to show the currently downloaded app
- szNewCaption.Format(szCaption, AppInfo->szName.GetString());
- SetWindowTextW(Dlg, szNewCaption.GetString());
-
- // Add a neat placeholder until the download URL is retrieved
- SetDlgItemTextW(Dlg, IDC_DOWNLOAD_STATUS, L"\x2022 \x2022 \x2022");
- Thread = CreateThread(NULL, 0, ThreadFunc, Dlg, 0, &ThreadId);
-
- if (!Thread)
- {
- return FALSE;
- }
-
- CloseHandle(Thread);
- return TRUE;
- }
- // No downloads left, closing (fallthrough)
-
case WM_CLOSE:
EndDialog(Dlg, 0);
- DestroyWindow(Dlg);
+ //DestroyWindow(Dlg);
return TRUE;
default:
}
}
-LRESULT CALLBACK CDownloadManager::DownloadProgressProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, UINT_PTR uIdSubclass, DWORD_PTR dwRefData)
+LRESULT CALLBACK CDownloadManager::DownloadProgressProc(HWND hWnd,
+ UINT uMsg,
+ WPARAM wParam,
+ LPARAM lParam,
+ UINT_PTR uIdSubclass,
+ DWORD_PTR dwRefData)
{
static ATL::CStringW szProgressText;
}
}
-DWORD WINAPI CDownloadManager::ThreadFunc(LPVOID Context)
+DWORD WINAPI CDownloadManager::ThreadFunc(LPVOID param)
{
CComPtr<IBindStatusCallback> dl;
ATL::CStringW Path;
PWSTR p, q;
- HWND Dlg = (HWND) Context;
+
+ HWND hDlg = static_cast<DownloadParam*>(param)->Dialog;
ULONG dwContentLen, dwBytesWritten, dwBytesRead, dwStatus;
ULONG dwCurrentBytesRead = 0;
size_t urlLength, filenameLength;
const INT iAppId = iCurrentApp;
- const PAPPLICATION_INFO pCurrentInfo = AppInfo;
- if (!AppInfo)
+ const ATL::CSimpleArray<DownloadInfo> &InfoArray = static_cast<DownloadParam*>(param)->AppInfo;
+ LPCWSTR szCaption = static_cast<DownloadParam*>(param)->szCaption;
+ ATL::CStringW szNewCaption;
+
+
+ if (InfoArray.GetSize() <= 0)
{
MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_DOWNLOAD);
goto end;
}
- DownloadsListView.SetDownloadStatus(iAppId, DOWNLOAD_STATUS::DLDownloading);
+ for (INT iAppId = 0; iAppId < InfoArray.GetSize(); ++iAppId)
+ {
+ const DownloadInfo &CurrentInfo = InfoArray[iAppId];
- // build the path for the download
- p = wcsrchr(pCurrentInfo->szUrlDownload.GetString(), L'/');
- q = wcsrchr(pCurrentInfo->szUrlDownload.GetString(), L'?');
+ // build the path for the download
+ p = wcsrchr(CurrentInfo.szUrl.GetString(), L'/');
+ q = wcsrchr(CurrentInfo.szUrl.GetString(), L'?');
- // do we have a final slash separator?
- if (!p)
- goto end;
+ // do we have a final slash separator?
+ if (!p)
+ goto end;
- // prepare the tentative length of the filename, maybe we've to remove part of it later on
- filenameLength = wcslen(p) * sizeof(WCHAR);
+ // prepare the tentative length of the filename, maybe we've to remove part of it later on
+ filenameLength = wcslen(p) * sizeof(WCHAR);
- /* do we have query arguments in the target URL after the filename? account for them
- (e.g. https://example.org/myfile.exe?no_adware_plz) */
- if (q && q > p && (q - p) > 0)
- filenameLength -= wcslen(q - 1) * sizeof(WCHAR);
+ /* do we have query arguments in the target URL after the filename? account for them
+ (e.g. https://example.org/myfile.exe?no_adware_plz) */
+ if (q && q > p && (q - p) > 0)
+ filenameLength -= wcslen(q - 1) * sizeof(WCHAR);
- // is this URL an update package for RAPPS? if so store it in a different place
- if (pCurrentInfo->szUrlDownload == APPLICATION_DATABASE_URL)
- {
- bCab = TRUE;
- if (!GetStorageDirectory(Path))
- goto end;
- }
- else
- {
- Path = SettingsInfo.szDownloadDir;
- }
+ // is this URL an update package for RAPPS? if so store it in a different place
+ if (CurrentInfo.szUrl == APPLICATION_DATABASE_URL)
+ {
+ bCab = TRUE;
+ if (!GetStorageDirectory(Path))
+ goto end;
+ }
+ else
+ {
+ Path = SettingsInfo.szDownloadDir;
+ }
- // is the path valid? can we access it?
- if (GetFileAttributesW(Path.GetString()) == INVALID_FILE_ATTRIBUTES)
- {
- if (!CreateDirectoryW(Path.GetString(), NULL))
- goto end;
- }
+ // is the path valid? can we access it?
+ if (GetFileAttributesW(Path.GetString()) == INVALID_FILE_ATTRIBUTES)
+ {
+ if (!CreateDirectoryW(Path.GetString(), NULL))
+ goto end;
+ }
- // append a \ to the provided file system path, and the filename portion from the URL after that
- Path += L"\\";
- Path += (LPWSTR) (p + 1);
+ // append a \ to the provided file system path, and the filename portion from the URL after that
+ Path += L"\\";
+ Path += (LPWSTR) (p + 1);
- if (!bCab && pCurrentInfo->szSHA1[0] && GetFileAttributesW(Path.GetString()) != INVALID_FILE_ATTRIBUTES)
- {
- // only open it in case of total correctness
- if (VerifyInteg(pCurrentInfo->szSHA1, Path))
- goto run;
- }
+ if (!bCab && CurrentInfo.szSHA1[0] && GetFileAttributesW(Path.GetString()) != INVALID_FILE_ATTRIBUTES)
+ {
+ // only open it in case of total correctness
+ if (VerifyInteg(CurrentInfo.szSHA1.GetString(), Path))
+ goto run;
+ }
- // download it
- bTempfile = TRUE;
- CDownloadDialog_Constructor(Dlg, &bCancelled, IID_PPV_ARG(IBindStatusCallback, &dl));
+ // Reset progress bar
+ HWND Item = GetDlgItem(hDlg, IDC_DOWNLOAD_PROGRESS);
+ if (Item)
+ {
+ SendMessageW(Item, PBM_SETPOS, 0, 0);
+ }
- if (dl == NULL)
- goto end;
+ // Change caption to show the currently downloaded app
+ if (!bCab)
+ {
+ szNewCaption.Format(szCaption, CurrentInfo.szName.GetString());
+ }
+ else
+ {
+ szNewCaption.LoadStringW(IDS_DL_DIALOG_DB_DOWNLOAD_DISP);
+ }
- /* FIXME: this should just be using the system-wide proxy settings */
- switch (SettingsInfo.Proxy)
- {
- case 0: // preconfig
- hOpen = InternetOpenW(lpszAgent, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
- break;
- case 1: // direct (no proxy)
- hOpen = InternetOpenW(lpszAgent, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
- break;
- case 2: // use proxy
- hOpen = InternetOpenW(lpszAgent, INTERNET_OPEN_TYPE_PROXY, SettingsInfo.szProxyServer, SettingsInfo.szNoProxyFor, 0);
- break;
- default: // preconfig
- hOpen = InternetOpenW(lpszAgent, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
- break;
- }
+ SetWindowTextW(hDlg, szNewCaption.GetString());
- if (!hOpen)
- goto end;
+ // Add the download URL
+ SetDlgItemTextW(hDlg, IDC_DOWNLOAD_STATUS, CurrentInfo.szUrl.GetString());
- hFile = InternetOpenUrlW(hOpen, pCurrentInfo->szUrlDownload, NULL, 0, INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_KEEP_CONNECTION, 0);
- if (!hFile)
- {
- MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_DOWNLOAD2);
- goto end;
- }
+ DownloadsListView.SetDownloadStatus(iAppId, DOWNLOAD_STATUS::DLDownloading);
- if (!HttpQueryInfoW(hFile, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &dwStatus, &dwStatusLen, NULL))
- goto end;
+ // download it
+ bTempfile = TRUE;
+ CDownloadDialog_Constructor(hDlg, &bCancelled, IID_PPV_ARG(IBindStatusCallback, &dl));
- if (dwStatus != HTTP_STATUS_OK)
- {
- MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_DOWNLOAD);
- goto end;
- }
+ if (dl == NULL)
+ goto end;
- dwStatusLen = sizeof(dwStatus);
+ /* FIXME: this should just be using the system-wide proxy settings */
+ switch (SettingsInfo.Proxy)
+ {
+ case 0: // preconfig
+ hOpen = InternetOpenW(lpszAgent, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
+ break;
+ case 1: // direct (no proxy)
+ hOpen = InternetOpenW(lpszAgent, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);
+ break;
+ case 2: // use proxy
+ hOpen = InternetOpenW(lpszAgent, INTERNET_OPEN_TYPE_PROXY, SettingsInfo.szProxyServer, SettingsInfo.szNoProxyFor, 0);
+ break;
+ default: // preconfig
+ hOpen = InternetOpenW(lpszAgent, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
+ break;
+ }
- memset(&urlComponents, 0, sizeof(urlComponents));
- urlComponents.dwStructSize = sizeof(urlComponents);
+ if (!hOpen)
+ goto end;
- urlLength = pCurrentInfo->szUrlDownload.GetLength();
- urlComponents.dwSchemeLength = urlLength + 1;
- urlComponents.lpszScheme = (LPWSTR) malloc(urlComponents.dwSchemeLength * sizeof(WCHAR));
- urlComponents.dwHostNameLength = urlLength + 1;
- urlComponents.lpszHostName = (LPWSTR) malloc(urlComponents.dwHostNameLength * sizeof(WCHAR));
+ hFile = InternetOpenUrlW(hOpen, CurrentInfo.szUrl.GetString(), NULL, 0, INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_KEEP_CONNECTION, 0);
- if (!InternetCrackUrlW(pCurrentInfo->szUrlDownload, urlLength + 1, ICU_DECODE | ICU_ESCAPE, &urlComponents))
- goto end;
+ if (!hFile)
+ {
+ MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_DOWNLOAD2);
+ goto end;
+ }
- if (urlComponents.nScheme == INTERNET_SCHEME_HTTP || urlComponents.nScheme == INTERNET_SCHEME_HTTPS)
- HttpQueryInfoW(hFile, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &dwContentLen, &dwStatus, 0);
+ if (!HttpQueryInfoW(hFile, HTTP_QUERY_STATUS_CODE | HTTP_QUERY_FLAG_NUMBER, &dwStatus, &dwStatusLen, NULL))
+ goto end;
- if (urlComponents.nScheme == INTERNET_SCHEME_FTP)
- dwContentLen = FtpGetFileSize(hFile, &dwStatus);
+ if (dwStatus != HTTP_STATUS_OK)
+ {
+ MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_DOWNLOAD);
+ goto end;
+ }
-#ifdef USE_CERT_PINNING
- // are we using HTTPS to download the RAPPS update package? check if the certificate is original
- if ((urlComponents.nScheme == INTERNET_SCHEME_HTTPS) &&
- (wcscmp(pCurrentInfo->szUrlDownload, APPLICATION_DATABASE_URL) == 0) &&
- (!CertIsValid(hOpen, urlComponents.lpszHostName)))
- {
- MessageBox_LoadString(hMainWnd, IDS_CERT_DOES_NOT_MATCH);
- goto end;
- }
-#endif
+ dwStatusLen = sizeof(dwStatus);
- free(urlComponents.lpszScheme);
- free(urlComponents.lpszHostName);
+ memset(&urlComponents, 0, sizeof(urlComponents));
+ urlComponents.dwStructSize = sizeof(urlComponents);
- hOut = CreateFileW(Path.GetString(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, NULL);
+ urlLength = CurrentInfo.szUrl.GetLength();
+ urlComponents.dwSchemeLength = urlLength + 1;
+ urlComponents.lpszScheme = (LPWSTR) malloc(urlComponents.dwSchemeLength * sizeof(WCHAR));
+ urlComponents.dwHostNameLength = urlLength + 1;
+ urlComponents.lpszHostName = (LPWSTR) malloc(urlComponents.dwHostNameLength * sizeof(WCHAR));
- if (hOut == INVALID_HANDLE_VALUE)
- goto end;
+ if (!InternetCrackUrlW(CurrentInfo.szUrl, urlLength + 1, ICU_DECODE | ICU_ESCAPE, &urlComponents))
+ goto end;
- do
- {
- if (!InternetReadFile(hFile, lpBuffer, _countof(lpBuffer), &dwBytesRead))
+ if (urlComponents.nScheme == INTERNET_SCHEME_HTTP || urlComponents.nScheme == INTERNET_SCHEME_HTTPS)
+ HttpQueryInfoW(hFile, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &dwContentLen, &dwStatus, 0);
+
+ if (urlComponents.nScheme == INTERNET_SCHEME_FTP)
+ dwContentLen = FtpGetFileSize(hFile, &dwStatus);
+
+#ifdef USE_CERT_PINNING
+ // are we using HTTPS to download the RAPPS update package? check if the certificate is original
+ if ((urlComponents.nScheme == INTERNET_SCHEME_HTTPS) &&
+ (wcscmp(CurrentInfo.szUrl, APPLICATION_DATABASE_URL) == 0) &&
+ (!CertIsValid(hOpen, urlComponents.lpszHostName)))
{
- MessageBox_LoadString(hMainWnd, IDS_INTERRUPTED_DOWNLOAD);
+ MessageBox_LoadString(hMainWnd, IDS_CERT_DOES_NOT_MATCH);
goto end;
}
+#endif
- if (!WriteFile(hOut, &lpBuffer[0], dwBytesRead, &dwBytesWritten, NULL))
- {
- MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_WRITE);
+ free(urlComponents.lpszScheme);
+ free(urlComponents.lpszHostName);
+
+ hOut = CreateFileW(Path.GetString(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, NULL);
+
+ if (hOut == INVALID_HANDLE_VALUE)
goto end;
- }
- dwCurrentBytesRead += dwBytesRead;
- dl->OnProgress(dwCurrentBytesRead, dwContentLen, 0, pCurrentInfo->szUrlDownload);
- } while (dwBytesRead && !bCancelled);
+ dwCurrentBytesRead = 0;
+ do
+ {
+ if (!InternetReadFile(hFile, lpBuffer, _countof(lpBuffer), &dwBytesRead))
+ {
+ MessageBox_LoadString(hMainWnd, IDS_INTERRUPTED_DOWNLOAD);
+ goto end;
+ }
- CloseHandle(hOut);
- hOut = INVALID_HANDLE_VALUE;
+ if (!WriteFile(hOut, &lpBuffer[0], dwBytesRead, &dwBytesWritten, NULL))
+ {
+ MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_WRITE);
+ goto end;
+ }
- if (bCancelled)
- goto end;
+ dwCurrentBytesRead += dwBytesRead;
+ dl->OnProgress(dwCurrentBytesRead, dwContentLen, 0, CurrentInfo.szUrl.GetString());
+ } while (dwBytesRead && !bCancelled);
- /* if this thing isn't a RAPPS update and it has a SHA-1 checksum
- verify its integrity by using the native advapi32.A_SHA1 functions */
- if (!bCab && pCurrentInfo->szSHA1[0] != 0)
- {
- ATL::CStringW szMsgText;
+ CloseHandle(hOut);
+ hOut = INVALID_HANDLE_VALUE;
- // change a few strings in the download dialog to reflect the verification process
- if (!szMsgText.LoadStringW(hInst, IDS_INTEG_CHECK_TITLE))
+ if (bCancelled)
goto end;
- SetWindowTextW(Dlg, szMsgText.GetString());
- SendMessageW(GetDlgItem(Dlg, IDC_DOWNLOAD_STATUS), WM_SETTEXT, 0, (LPARAM) Path.GetString());
-
- // this may take a while, depending on the file size
- if (!VerifyInteg(pCurrentInfo->szSHA1, Path.GetString()))
+ /* if this thing isn't a RAPPS update and it has a SHA-1 checksum
+ verify its integrity by using the native advapi32.A_SHA1 functions */
+ if (!bCab && CurrentInfo.szSHA1[0] != 0)
{
- if (!szMsgText.LoadStringW(hInst, IDS_INTEG_CHECK_FAIL))
+ ATL::CStringW szMsgText;
+
+ // change a few strings in the download dialog to reflect the verification process
+ if (!szMsgText.LoadStringW(IDS_INTEG_CHECK_TITLE))
goto end;
- MessageBoxW(Dlg, szMsgText.GetString(), NULL, MB_OK | MB_ICONERROR);
- goto end;
- }
- }
+ SetWindowTextW(hDlg, szMsgText.GetString());
+ SendMessageW(GetDlgItem(hDlg, IDC_DOWNLOAD_STATUS), WM_SETTEXT, 0, (LPARAM) Path.GetString());
+ // this may take a while, depending on the file size
+ if (!VerifyInteg(CurrentInfo.szSHA1.GetString(), Path.GetString()))
+ {
+ if (!szMsgText.LoadStringW(IDS_INTEG_CHECK_FAIL))
+ goto end;
-run:
- DownloadsListView.SetDownloadStatus(iAppId, DOWNLOAD_STATUS::DLWaitingToInstall);
+ MessageBoxW(hDlg, szMsgText.GetString(), NULL, MB_OK | MB_ICONERROR);
+ goto end;
+ }
+ }
- // run it
- if (!bCab)
- {
- SHELLEXECUTEINFOW shExInfo = {0};
- shExInfo.cbSize = sizeof(shExInfo);
- shExInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
- shExInfo.lpVerb = L"open";
- shExInfo.lpFile = Path.GetString();
- shExInfo.lpParameters = L"";
- shExInfo.nShow = SW_SHOW;
+run:
+ DownloadsListView.SetDownloadStatus(iAppId, DOWNLOAD_STATUS::DLWaitingToInstall);
- if (ShellExecuteExW(&shExInfo))
- {
- DownloadsListView.SetDownloadStatus(iAppId, DOWNLOAD_STATUS::DLInstalling);
- //TODO: issue an install operation separately so that the apps could be downloaded in the background
- WaitForSingleObject(shExInfo.hProcess, INFINITE);
- CloseHandle(shExInfo.hProcess);
- }
- else
+ // run it
+ if (!bCab)
{
- MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_INSTALL);
+ SHELLEXECUTEINFOW shExInfo = {0};
+ shExInfo.cbSize = sizeof(shExInfo);
+ shExInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
+ shExInfo.lpVerb = L"open";
+ shExInfo.lpFile = Path.GetString();
+ shExInfo.lpParameters = L"";
+ shExInfo.nShow = SW_SHOW;
+
+ if (ShellExecuteExW(&shExInfo))
+ {
+ DownloadsListView.SetDownloadStatus(iAppId, DOWNLOAD_STATUS::DLInstalling);
+ //TODO: issue an install operation separately so that the apps could be downloaded in the background
+ WaitForSingleObject(shExInfo.hProcess, INFINITE);
+ CloseHandle(shExInfo.hProcess);
+ }
+ else
+ {
+ MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_INSTALL);
+ }
}
- }
end:
- if (hOut != INVALID_HANDLE_VALUE)
- CloseHandle(hOut);
+ if (hOut != INVALID_HANDLE_VALUE)
+ CloseHandle(hOut);
- InternetCloseHandle(hFile);
- InternetCloseHandle(hOpen);
+ InternetCloseHandle(hFile);
+ InternetCloseHandle(hOpen);
- if (bTempfile)
- {
- if (bCancelled || (SettingsInfo.bDelInstaller && !bCab))
- DeleteFileW(Path.GetString());
+ if (bTempfile)
+ {
+ if (bCancelled || (SettingsInfo.bDelInstaller && !bCab))
+ DeleteFileW(Path.GetString());
+ }
+
+ DownloadsListView.SetDownloadStatus(iAppId, DOWNLOAD_STATUS::DLFinished);
}
- DownloadsListView.SetDownloadStatus(iAppId, DOWNLOAD_STATUS::DLFinished);
- SendMessageW(Dlg, DL_START_NEW, 0, 0);
+
+ delete param;
+ SendMessageW(hDlg, WM_CLOSE, 0, 0);
return 0;
}
-BOOL CDownloadManager::DownloadListOfApplications(const ATL::CSimpleArray<PAPPLICATION_INFO>& AppsList)
+BOOL CDownloadManager::DownloadListOfApplications(const ATL::CSimpleArray<CAvailableApplicationInfo*>& AppsList, BOOL bIsModal)
{
if (AppsList.GetSize() == 0)
{
}
// Initialize shared variables
- AppsToInstallList = AppsList;
+ for (INT i = 0; i < AppsList.GetSize(); ++i)
+ {
+ if (AppsList[i])
+ {
+ AppsToInstallList.Add(*(AppsList[i]));
+ }
+ }
// Create a dialog and issue a download process
- LaunchDownloadDialog();
+ LaunchDownloadDialog(bIsModal);
return TRUE;
}
-BOOL CDownloadManager::DownloadApplication(PAPPLICATION_INFO pAppInfo)
+BOOL CDownloadManager::DownloadApplication(CAvailableApplicationInfo* pAppInfo, BOOL bIsModal)
{
if (!pAppInfo)
- {
return FALSE;
- }
-
- AppsToInstallList.RemoveAll();
- AppsToInstallList.Add(pAppInfo);
- LaunchDownloadDialog();
+ Download(*pAppInfo, bIsModal);
return TRUE;
}
VOID CDownloadManager::DownloadApplicationsDB(LPCWSTR lpUrl)
{
- APPLICATION_INFO IntInfo;
- IntInfo.szUrlDownload = lpUrl;
-
- DownloadApplication(&IntInfo);
+ static DownloadInfo DatabaseDLInfo;
+ DatabaseDLInfo.szUrl = lpUrl;
+ DatabaseDLInfo.szName.LoadStringW(IDS_DL_DIALOG_DB_DISP);
+ Download(DatabaseDLInfo, TRUE);
}
//TODO: Reuse the dialog
-VOID CDownloadManager::LaunchDownloadDialog()
+VOID CDownloadManager::LaunchDownloadDialog(BOOL bIsModal)
{
- CreateDialogW(hInst,
- MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG),
- hMainWnd,
- DownloadDlgProc);
+ if (bIsModal)
+ {
+ DialogBoxW(hInst,
+ MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG),
+ hMainWnd,
+ DownloadDlgProc);
+ }
+ else
+ {
+ CreateDialogW(hInst,
+ MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG),
+ hMainWnd,
+ DownloadDlgProc);
+ }
}
-// CDownloadManager
\ No newline at end of file
+// CDownloadManager