SetCheckState(-1, bHasAllChecked);
}
- ATL::CSimpleArray<PAPPLICATION_INFO> GetCheckedItems()
+ ATL::CSimpleArray<CAvailableApplicationInfo*> GetCheckedItems()
{
- ATL::CSimpleArray<PAPPLICATION_INFO> list;
+ ATL::CSimpleArray<CAvailableApplicationInfo*> list;
for (INT i = 0; i >= 0; i = GetNextItem(i, LVNI_ALL))
{
if (GetCheckState(i) != FALSE)
{
- PAPPLICATION_INFO pAppInfo = (PAPPLICATION_INFO) GetItemData(i);
+ CAvailableApplicationInfo* pAppInfo = (CAvailableApplicationInfo*) GetItemData(i);
list.Add(pAppInfo);
}
}
return list;
}
- PAPPLICATION_INFO GetSelectedData()
+ CAvailableApplicationInfo* GetSelectedData()
{
INT item = GetSelectionMark();
- return (PAPPLICATION_INFO) GetItemData(item);
+ return (CAvailableApplicationInfo*) GetItemData(item);
}
};
{
if (IS_INSTALLED_ENUM(SelectedEnumType))
ShowInstalledAppInfo(ItemIndex);
- if (isAvailableEnum(SelectedEnumType))
+ if (IsAvailableEnum(SelectedEnumType))
CAvailableAppView::ShowAvailableAppInfo(ItemIndex);
}
/* Check if the item is checked */
{
if (IS_INSTALLED_ENUM(SelectedEnumType))
ShowInstalledAppInfo(-1);
- if (isAvailableEnum(SelectedEnumType))
+ if (IsAvailableEnum(SelectedEnumType))
CAvailableAppView::ShowAvailableAppInfo(-1);
}
}
break;
case ID_INSTALL:
- if (nSelectedApps > 0)
+ if (IsAvailableEnum(SelectedEnumType))
{
- CDownloadManager::DownloadListOfApplications(m_ListView->GetCheckedItems());
- UpdateApplicationsList(-1);
- }
- else if (CDownloadManager::DownloadApplication(m_ListView->GetSelectedData()))
- {
- UpdateApplicationsList(-1);
- }
+ if (nSelectedApps > 0)
+ {
+ CDownloadManager::DownloadListOfApplications(m_ListView->GetCheckedItems());
+ UpdateApplicationsList(-1);
+ }
+ else if (CDownloadManager::DownloadApplication(m_ListView->GetSelectedData()))
+ {
+ UpdateApplicationsList(-1);
+ }
+ }
break;
case ID_UNINSTALL:
return TRUE;
}
- static BOOL CALLBACK s_EnumAvailableAppProc(PAPPLICATION_INFO Info, LPCWSTR szFolderPath)
+ static BOOL CALLBACK s_EnumAvailableAppProc(CAvailableApplicationInfo* Info, LPCWSTR szFolderPath)
{
INT Index;
HICON hIcon = NULL;
EnumInstalledApplications(EnumType, TRUE, s_EnumInstalledAppProc);
EnumInstalledApplications(EnumType, FALSE, s_EnumInstalledAppProc);
}
- else if (isAvailableEnum(EnumType))
+ else if (IsAvailableEnum(EnumType))
{
/* Enum available applications */
m_AvailableApps.EnumAvailableApplications(EnumType, s_EnumAvailableAppProc);
return szString;
}
+
+struct DownloadInfo
+{
+ DownloadInfo() {}
+ DownloadInfo(const CAvailableApplicationInfo& AppInfo)
+ :szUrl(AppInfo.szUrlDownload), szName(AppInfo.szName), szSHA1(AppInfo.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
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);
}
}
}
}
-struct DownloadParam
-{
- DownloadParam() : Dialog(NULL), AppInfo(), szCaption(NULL) {}
- DownloadParam(HWND dlg, const ATL::CSimpleArray<PAPPLICATION_INFO> &info, LPCWSTR caption)
- : Dialog(dlg), AppInfo(info), szCaption(caption)
- {
- }
-
- HWND Dialog;
- ATL::CSimpleArray<PAPPLICATION_INFO> AppInfo;
- LPCWSTR szCaption;
-};
-
// CDownloadManager
-ATL::CSimpleArray<PAPPLICATION_INFO> CDownloadManager::AppsToInstallList;
+ATL::CSimpleArray<DownloadInfo> CDownloadManager::AppsToInstallList;
CDowloadingAppsListView CDownloadManager::DownloadsListView;
INT CDownloadManager::iCurrentApp;
+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)
{
static WCHAR szCaption[MAX_PATH];
}
CloseHandle(Thread);
+ AppsToInstallList.RemoveAll();
return TRUE;
}
size_t urlLength, filenameLength;
const INT iAppId = iCurrentApp;
- const ATL::CSimpleArray<PAPPLICATION_INFO> InfoArray = static_cast<DownloadParam*>(param)->AppInfo;
+ const ATL::CSimpleArray<DownloadInfo> &InfoArray = static_cast<DownloadParam*>(param)->AppInfo;
LPCWSTR szCaption = static_cast<DownloadParam*>(param)->szCaption;
ATL::CStringW szNewCaption;
- delete param;
+
if (InfoArray.GetSize() <= 0)
{
MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_DOWNLOAD);
for (INT iAppId = 0; iAppId < InfoArray.GetSize(); ++iAppId)
{
- PAPPLICATION_INFO pCurrentInfo = AppsToInstallList[iAppId];
- if (!pCurrentInfo)
- {
- MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_DOWNLOAD);
- continue;
- }
+ const DownloadInfo &CurrentInfo = InfoArray[iAppId];
// build the path for the download
- p = wcsrchr(pCurrentInfo->szUrlDownload.GetString(), L'/');
- q = wcsrchr(pCurrentInfo->szUrlDownload.GetString(), L'?');
+ p = wcsrchr(CurrentInfo.szUrl.GetString(), L'/');
+ q = wcsrchr(CurrentInfo.szUrl.GetString(), L'?');
// do we have a final slash separator?
if (!p)
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)
+ if (CurrentInfo.szUrl == APPLICATION_DATABASE_URL)
{
bCab = TRUE;
if (!GetStorageDirectory(Path))
Path += L"\\";
Path += (LPWSTR) (p + 1);
- if (!bCab && pCurrentInfo->szSHA1[0] && GetFileAttributesW(Path.GetString()) != INVALID_FILE_ATTRIBUTES)
+ if (!bCab && CurrentInfo.szSHA1[0] && GetFileAttributesW(Path.GetString()) != INVALID_FILE_ATTRIBUTES)
{
// only open it in case of total correctness
- if (VerifyInteg(pCurrentInfo->szSHA1, Path))
+ if (VerifyInteg(CurrentInfo.szSHA1.GetString(), Path))
goto run;
}
// Change caption to show the currently downloaded app
if (!bCab)
{
- szNewCaption.Format(szCaption, pCurrentInfo->szName.GetString());
+ szNewCaption.Format(szCaption, CurrentInfo.szName.GetString());
}
else
{
SetWindowTextW(hDlg, szNewCaption.GetString());
// Add the download URL
- SetDlgItemTextW(hDlg, IDC_DOWNLOAD_STATUS, pCurrentInfo->szUrlDownload.GetString());
+ SetDlgItemTextW(hDlg, IDC_DOWNLOAD_STATUS, CurrentInfo.szUrl.GetString());
DownloadsListView.SetDownloadStatus(iAppId, DOWNLOAD_STATUS::DLDownloading);
if (!hOpen)
goto end;
- hFile = InternetOpenUrlW(hOpen, pCurrentInfo->szUrlDownload.GetString(), NULL, 0, INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_KEEP_CONNECTION, 0);
+ hFile = InternetOpenUrlW(hOpen, CurrentInfo.szUrl.GetString(), NULL, 0, INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_KEEP_CONNECTION, 0);
if (!hFile)
{
memset(&urlComponents, 0, sizeof(urlComponents));
urlComponents.dwStructSize = sizeof(urlComponents);
- urlLength = pCurrentInfo->szUrlDownload.GetLength();
+ 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 (!InternetCrackUrlW(pCurrentInfo->szUrlDownload, urlLength + 1, ICU_DECODE | ICU_ESCAPE, &urlComponents))
+ if (!InternetCrackUrlW(CurrentInfo.szUrl, urlLength + 1, ICU_DECODE | ICU_ESCAPE, &urlComponents))
goto end;
if (urlComponents.nScheme == INTERNET_SCHEME_HTTP || urlComponents.nScheme == INTERNET_SCHEME_HTTPS)
#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) &&
+ (wcscmp(CurrentInfo.szUrl, APPLICATION_DATABASE_URL) == 0) &&
(!CertIsValid(hOpen, urlComponents.lpszHostName)))
{
MessageBox_LoadString(hMainWnd, IDS_CERT_DOES_NOT_MATCH);
}
dwCurrentBytesRead += dwBytesRead;
- dl->OnProgress(dwCurrentBytesRead, dwContentLen, 0, pCurrentInfo->szUrlDownload.GetString());
+ dl->OnProgress(dwCurrentBytesRead, dwContentLen, 0, CurrentInfo.szUrl.GetString());
} while (dwBytesRead && !bCancelled);
CloseHandle(hOut);
/* 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)
+ if (!bCab && CurrentInfo.szSHA1[0] != 0)
{
ATL::CStringW szMsgText;
SendMessageW(GetDlgItem(hDlg, 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 (!VerifyInteg(CurrentInfo.szSHA1.GetString(), Path.GetString()))
{
if (!szMsgText.LoadStringW(IDS_INTEG_CHECK_FAIL))
goto end;
DownloadsListView.SetDownloadStatus(iAppId, DOWNLOAD_STATUS::DLFinished);
}
+ delete param;
SendMessageW(hDlg, WM_CLOSE, 0, 0);
return 0;
}
-BOOL CDownloadManager::DownloadListOfApplications(const ATL::CSimpleArray<PAPPLICATION_INFO>& AppsList, BOOL bIsModal)
+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(bIsModal);
return TRUE;
}
-BOOL CDownloadManager::DownloadApplication(PAPPLICATION_INFO pAppInfo, BOOL bIsModal)
+BOOL CDownloadManager::DownloadApplication(CAvailableApplicationInfo* pAppInfo, BOOL bIsModal)
{
if (!pAppInfo)
- {
return FALSE;
- }
-
- AppsToInstallList.RemoveAll();
- AppsToInstallList.Add(pAppInfo);
- LaunchDownloadDialog(bIsModal);
+ Download(*pAppInfo, bIsModal);
return TRUE;
}
VOID CDownloadManager::DownloadApplicationsDB(LPCWSTR lpUrl)
{
- static APPLICATION_INFO IntInfo;
- IntInfo.szUrlDownload = lpUrl;
- IntInfo.szName.LoadStringW(IDS_DL_DIALOG_DB_DISP);
- DownloadApplication(&IntInfo, TRUE);
+ static DownloadInfo DatabaseDLInfo;
+ DatabaseDLInfo.szUrl = lpUrl;
+ DatabaseDLInfo.szName.LoadStringW(IDS_DL_DIALOG_DB_DISP);
+ Download(DatabaseDLInfo, TRUE);
}
//TODO: Reuse the dialog