- Fixed crash when trying to double-click in the "Installed" category
- Replaced APPLICATION_INFO with CAvailableApplicationInfo
- Added DownloadInfo struct as a replacement of APPLICATION_INFO in CDownloadManager
- Minor fixes

svn path=/branches/GSoC_2017/rapps/; revision=75684
This commit is contained in:
Alexander Shaposhnikov 2017-08-26 22:43:05 +00:00
parent b6ba25a4da
commit 15a86cdf6a
8 changed files with 118 additions and 95 deletions

View file

@ -22,6 +22,7 @@ CAvailableApplicationInfo::CAvailableApplicationInfo(const ATL::CStringW& sFileN
: m_Parser(sFileNameParam) : m_Parser(sFileNameParam)
{ {
LicenseType = LICENSE_TYPE::None; LicenseType = LICENSE_TYPE::None;
sFileName = sFileNameParam; sFileName = sFileNameParam;
RetrieveGeneralInfo(); RetrieveGeneralInfo();
@ -73,8 +74,10 @@ VOID CAvailableApplicationInfo::RetrieveInstalledStatus()
VOID CAvailableApplicationInfo::RetrieveInstalledVersion() VOID CAvailableApplicationInfo::RetrieveInstalledVersion()
{ {
ATL::CStringW szNameVersion = szName + L" " + szVersion;
m_HasInstalledVersion = ::GetInstalledVersion(&szInstalledVersion, szRegName) m_HasInstalledVersion = ::GetInstalledVersion(&szInstalledVersion, szRegName)
|| ::GetInstalledVersion(&szInstalledVersion, szName); || ::GetInstalledVersion(&szInstalledVersion, szName)
|| ::GetInstalledVersion(&szInstalledVersion, szNameVersion);
} }
VOID CAvailableApplicationInfo::RetrieveLanguages() VOID CAvailableApplicationInfo::RetrieveLanguages()
@ -377,7 +380,7 @@ skip_if_cached:
Info->RefreshAppInfo(); Info->RefreshAppInfo();
if (lpEnumProc) if (lpEnumProc)
lpEnumProc(static_cast<PAPPLICATION_INFO>(Info), m_szAppsPath.GetString()); lpEnumProc(static_cast<CAvailableApplicationInfo*>(Info), m_szAppsPath.GetString());
} while (FindNextFileW(hFind, &FindFileData) != 0); } while (FindNextFileW(hFind, &FindFileData) != 0);
@ -385,7 +388,7 @@ skip_if_cached:
return TRUE; return TRUE;
} }
const PAPPLICATION_INFO CAvailableApps::FindInfo(const ATL::CStringW& szAppName) CAvailableApplicationInfo* CAvailableApps::FindInfo(const ATL::CStringW& szAppName)
{ {
if (m_InfoList.IsEmpty()) if (m_InfoList.IsEmpty())
{ {
@ -394,7 +397,7 @@ const PAPPLICATION_INFO CAvailableApps::FindInfo(const ATL::CStringW& szAppName)
// linear search // linear search
POSITION CurrentListPosition = m_InfoList.GetHeadPosition(); POSITION CurrentListPosition = m_InfoList.GetHeadPosition();
PAPPLICATION_INFO info; CAvailableApplicationInfo* info;
while (CurrentListPosition != NULL) while (CurrentListPosition != NULL)
{ {
info = m_InfoList.GetNext(CurrentListPosition); info = m_InfoList.GetNext(CurrentListPosition);
@ -406,12 +409,12 @@ const PAPPLICATION_INFO CAvailableApps::FindInfo(const ATL::CStringW& szAppName)
return NULL; return NULL;
} }
ATL::CSimpleArray<PAPPLICATION_INFO> CAvailableApps::FindInfoList(const ATL::CSimpleArray<ATL::CStringW> &arrAppsNames) ATL::CSimpleArray<CAvailableApplicationInfo*> CAvailableApps::FindInfoList(const ATL::CSimpleArray<ATL::CStringW> &arrAppsNames)
{ {
ATL::CSimpleArray<PAPPLICATION_INFO> result; ATL::CSimpleArray<CAvailableApplicationInfo*> result;
for (INT i = 0; i < arrAppsNames.GetSize(); ++i) for (INT i = 0; i < arrAppsNames.GetSize(); ++i)
{ {
PAPPLICATION_INFO Info = FindInfo(arrAppsNames[i]); CAvailableApplicationInfo* Info = FindInfo(arrAppsNames[i]);
if (Info) if (Info)
{ {
result.Add(Info); result.Add(Info);

View file

@ -504,24 +504,24 @@ public:
SetCheckState(-1, bHasAllChecked); 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)) for (INT i = 0; i >= 0; i = GetNextItem(i, LVNI_ALL))
{ {
if (GetCheckState(i) != FALSE) if (GetCheckState(i) != FALSE)
{ {
PAPPLICATION_INFO pAppInfo = (PAPPLICATION_INFO) GetItemData(i); CAvailableApplicationInfo* pAppInfo = (CAvailableApplicationInfo*) GetItemData(i);
list.Add(pAppInfo); list.Add(pAppInfo);
} }
} }
return list; return list;
} }
PAPPLICATION_INFO GetSelectedData() CAvailableApplicationInfo* GetSelectedData()
{ {
INT item = GetSelectionMark(); INT item = GetSelectionMark();
return (PAPPLICATION_INFO) GetItemData(item); return (CAvailableApplicationInfo*) GetItemData(item);
} }
}; };
@ -1062,7 +1062,7 @@ private:
{ {
if (IS_INSTALLED_ENUM(SelectedEnumType)) if (IS_INSTALLED_ENUM(SelectedEnumType))
ShowInstalledAppInfo(ItemIndex); ShowInstalledAppInfo(ItemIndex);
if (isAvailableEnum(SelectedEnumType)) if (IsAvailableEnum(SelectedEnumType))
CAvailableAppView::ShowAvailableAppInfo(ItemIndex); CAvailableAppView::ShowAvailableAppInfo(ItemIndex);
} }
/* Check if the item is checked */ /* Check if the item is checked */
@ -1100,7 +1100,7 @@ private:
{ {
if (IS_INSTALLED_ENUM(SelectedEnumType)) if (IS_INSTALLED_ENUM(SelectedEnumType))
ShowInstalledAppInfo(-1); ShowInstalledAppInfo(-1);
if (isAvailableEnum(SelectedEnumType)) if (IsAvailableEnum(SelectedEnumType))
CAvailableAppView::ShowAvailableAppInfo(-1); CAvailableAppView::ShowAvailableAppInfo(-1);
} }
} }
@ -1310,16 +1310,19 @@ private:
break; break;
case ID_INSTALL: case ID_INSTALL:
if (nSelectedApps > 0) if (IsAvailableEnum(SelectedEnumType))
{ {
CDownloadManager::DownloadListOfApplications(m_ListView->GetCheckedItems()); if (nSelectedApps > 0)
UpdateApplicationsList(-1); {
} CDownloadManager::DownloadListOfApplications(m_ListView->GetCheckedItems());
else if (CDownloadManager::DownloadApplication(m_ListView->GetSelectedData())) UpdateApplicationsList(-1);
{ }
UpdateApplicationsList(-1); else if (CDownloadManager::DownloadApplication(m_ListView->GetSelectedData()))
} {
UpdateApplicationsList(-1);
}
}
break; break;
case ID_UNINSTALL: case ID_UNINSTALL:
@ -1416,7 +1419,7 @@ private:
return TRUE; return TRUE;
} }
static BOOL CALLBACK s_EnumAvailableAppProc(PAPPLICATION_INFO Info, LPCWSTR szFolderPath) static BOOL CALLBACK s_EnumAvailableAppProc(CAvailableApplicationInfo* Info, LPCWSTR szFolderPath)
{ {
INT Index; INT Index;
HICON hIcon = NULL; HICON hIcon = NULL;
@ -1506,7 +1509,7 @@ private:
EnumInstalledApplications(EnumType, TRUE, s_EnumInstalledAppProc); EnumInstalledApplications(EnumType, TRUE, s_EnumInstalledAppProc);
EnumInstalledApplications(EnumType, FALSE, s_EnumInstalledAppProc); EnumInstalledApplications(EnumType, FALSE, s_EnumInstalledAppProc);
} }
else if (isAvailableEnum(EnumType)) else if (IsAvailableEnum(EnumType))
{ {
/* Enum available applications */ /* Enum available applications */
m_AvailableApps.EnumAvailableApplications(EnumType, s_EnumAvailableAppProc); m_AvailableApps.EnumAvailableApplications(EnumType, s_EnumAvailableAppProc);

View file

@ -29,7 +29,7 @@ enum AvailableCategories
ENUM_AVAILABLE_MAX = ENUM_CAT_OTHER ENUM_AVAILABLE_MAX = ENUM_CAT_OTHER
}; };
inline BOOL isAvailableEnum(INT x) inline BOOL IsAvailableEnum(INT x)
{ {
return (x >= ENUM_AVAILABLE_MIN && x <= ENUM_AVAILABLE_MAX); return (x >= ENUM_AVAILABLE_MIN && x <= ENUM_AVAILABLE_MAX);
} }
@ -44,7 +44,7 @@ typedef enum LICENSE_TYPE
Min = None Min = None
} *PLICENSE_TYPE; } *PLICENSE_TYPE;
typedef struct APPLICATION_INFO struct CAvailableApplicationInfo
{ {
INT Category; INT Category;
LICENSE_TYPE LicenseType; LICENSE_TYPE LicenseType;
@ -65,14 +65,8 @@ typedef struct APPLICATION_INFO
// Optional integrity checks (SHA-1 digests are 160 bit = 40 characters in hex string form) // Optional integrity checks (SHA-1 digests are 160 bit = 40 characters in hex string form)
ATL::CStringW szSHA1; ATL::CStringW szSHA1;
} *PAPPLICATION_INFO;
typedef BOOL(CALLBACK *AVAILENUMPROC)(PAPPLICATION_INFO Info, LPCWSTR szFolderPath);
struct CAvailableApplicationInfo : public APPLICATION_INFO
{
ATL::CStringW szInstalledVersion; ATL::CStringW szInstalledVersion;
CAvailableApplicationInfo(const ATL::CStringW& sFileNameParam); CAvailableApplicationInfo(const ATL::CStringW& sFileNameParam);
// Load all info from the file // Load all info from the file
@ -104,6 +98,8 @@ private:
inline BOOL FindInLanguages(LCID what) const; inline BOOL FindInLanguages(LCID what) const;
}; };
typedef BOOL(CALLBACK *AVAILENUMPROC)(CAvailableApplicationInfo *Info, LPCWSTR szFolderPath);
class CAvailableApps class CAvailableApps
{ {
ATL::CAtlList<CAvailableApplicationInfo*> m_InfoList; ATL::CAtlList<CAvailableApplicationInfo*> m_InfoList;
@ -123,8 +119,8 @@ public:
VOID FreeCachedEntries(); VOID FreeCachedEntries();
static VOID DeleteCurrentAppsDB(); static VOID DeleteCurrentAppsDB();
BOOL EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnumProc); BOOL EnumAvailableApplications(INT EnumType, AVAILENUMPROC lpEnumProc);
const PAPPLICATION_INFO FindInfo(const ATL::CStringW& szAppName); CAvailableApplicationInfo* FindInfo(const ATL::CStringW& szAppName);
ATL::CSimpleArray<PAPPLICATION_INFO> FindInfoList(const ATL::CSimpleArray<ATL::CStringW> &arrAppsNames); ATL::CSimpleArray<CAvailableApplicationInfo*> FindInfoList(const ATL::CSimpleArray<ATL::CStringW> &arrAppsNames);
const ATL::CStringW& GetFolderPath(); const ATL::CStringW& GetFolderPath();
const ATL::CStringW& GetAppPath(); const ATL::CStringW& GetAppPath();
const ATL::CStringW& GetCabPath(); const ATL::CStringW& GetCabPath();

View file

@ -7,13 +7,15 @@
// Download dialog (loaddlg.cpp) // Download dialog (loaddlg.cpp)
class CDowloadingAppsListView; class CDowloadingAppsListView;
struct DownloadInfo;
class CDownloadManager class CDownloadManager
{ {
static ATL::CSimpleArray<PAPPLICATION_INFO> AppsToInstallList; static ATL::CSimpleArray<DownloadInfo> AppsToInstallList;
static CDowloadingAppsListView DownloadsListView; static CDowloadingAppsListView DownloadsListView;
static INT iCurrentApp; static INT iCurrentApp;
static VOID Download(const DownloadInfo& DLInfo, BOOL bIsModal = FALSE);
public: public:
static INT_PTR CALLBACK DownloadDlgProc(HWND Dlg, UINT uMsg, WPARAM wParam, LPARAM lParam); static INT_PTR CALLBACK DownloadDlgProc(HWND Dlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK DownloadProgressProc(HWND hWnd, static LRESULT CALLBACK DownloadProgressProc(HWND hWnd,
@ -24,8 +26,8 @@ public:
DWORD_PTR dwRefData); DWORD_PTR dwRefData);
static DWORD WINAPI ThreadFunc(LPVOID Context); static DWORD WINAPI ThreadFunc(LPVOID Context);
static BOOL DownloadListOfApplications(const ATL::CSimpleArray<PAPPLICATION_INFO>& AppsList, BOOL bIsModal = FALSE); static BOOL DownloadListOfApplications(const ATL::CSimpleArray<CAvailableApplicationInfo*>& AppsList, BOOL bIsModal = FALSE);
static BOOL DownloadApplication(PAPPLICATION_INFO pAppInfo, BOOL modal = FALSE); static BOOL DownloadApplication(CAvailableApplicationInfo* pAppInfo, BOOL bIsModal = FALSE);
static VOID DownloadApplicationsDB(LPCWSTR lpUrl); static VOID DownloadApplicationsDB(LPCWSTR lpUrl);
static VOID LaunchDownloadDialog(BOOL); static VOID LaunchDownloadDialog(BOOL);
}; };

View file

@ -38,7 +38,7 @@ public:
static const ATL::CStringW& GetLocale(); static const ATL::CStringW& GetLocale();
static INT CConfigParser::GetLocaleSize(); static INT CConfigParser::GetLocaleSize();
CConfigParser(const ATL::CStringW& FileName); CConfigParser(const ATL::CStringW& FileName = "");
UINT GetString(const ATL::CStringW& KeyName, ATL::CStringW& ResultString); UINT GetString(const ATL::CStringW& KeyName, ATL::CStringW& ResultString);
UINT GetInt(const ATL::CStringW& KeyName); UINT GetInt(const ATL::CStringW& KeyName);

View file

@ -10,7 +10,7 @@
#include "dialogs.h" #include "dialogs.h"
#include "available.h" #include "available.h"
static PAPPLICATION_INFO AppInfo; static CAvailableApplicationInfo* AppInfo;
static static
INT_PTR CALLBACK INT_PTR CALLBACK
@ -42,10 +42,10 @@ InstallDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
BOOL BOOL
InstallApplication(INT Index) InstallApplication(INT Index)
{ {
if (!isAvailableEnum(SelectedEnumType)) if (!IsAvailableEnum(SelectedEnumType))
return FALSE; return FALSE;
AppInfo = (PAPPLICATION_INFO) ListViewGetlParam(Index); AppInfo = (CAvailableApplicationInfo*) ListViewGetlParam(Index);
if (!AppInfo) return FALSE; if (!AppInfo) return FALSE;
DialogBoxW(hInst, DialogBoxW(hInst,

View file

@ -67,6 +67,34 @@ ATL::CStringW LoadStatusString(DOWNLOAD_STATUS StatusParam)
return szString; 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 : class CDownloadDialog :
public CComObjectRootEx<CComMultiThreadModelNoCS>, public CComObjectRootEx<CComMultiThreadModelNoCS>,
public IBindStatusCallback public IBindStatusCallback
@ -227,12 +255,11 @@ public:
return hwnd; return hwnd;
} }
VOID LoadList(ATL::CSimpleArray<PAPPLICATION_INFO> arrInfo) VOID LoadList(ATL::CSimpleArray<DownloadInfo> arrInfo)
{ {
for (INT i = 0; i < arrInfo.GetSize(); ++i) for (INT i = 0; i < arrInfo.GetSize(); ++i)
{ {
PAPPLICATION_INFO AppInfo = arrInfo[i]; AddRow(i, arrInfo[i].szName.GetString(), DOWNLOAD_STATUS::DLWaiting);
AddRow(i, AppInfo->szName.GetString(), DOWNLOAD_STATUS::DLWaiting);
} }
} }
@ -346,24 +373,18 @@ inline VOID MessageBox_LoadString(HWND hMainWnd, INT StringID)
} }
} }
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 // CDownloadManager
ATL::CSimpleArray<PAPPLICATION_INFO> CDownloadManager::AppsToInstallList; ATL::CSimpleArray<DownloadInfo> CDownloadManager::AppsToInstallList;
CDowloadingAppsListView CDownloadManager::DownloadsListView; CDowloadingAppsListView CDownloadManager::DownloadsListView;
INT CDownloadManager::iCurrentApp; 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) INT_PTR CALLBACK CDownloadManager::DownloadDlgProc(HWND Dlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
static WCHAR szCaption[MAX_PATH]; static WCHAR szCaption[MAX_PATH];
@ -419,6 +440,7 @@ INT_PTR CALLBACK CDownloadManager::DownloadDlgProc(HWND Dlg, UINT uMsg, WPARAM w
} }
CloseHandle(Thread); CloseHandle(Thread);
AppsToInstallList.RemoveAll();
return TRUE; return TRUE;
} }
@ -546,11 +568,11 @@ DWORD WINAPI CDownloadManager::ThreadFunc(LPVOID param)
size_t urlLength, filenameLength; size_t urlLength, filenameLength;
const INT iAppId = iCurrentApp; 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; LPCWSTR szCaption = static_cast<DownloadParam*>(param)->szCaption;
ATL::CStringW szNewCaption; ATL::CStringW szNewCaption;
delete param;
if (InfoArray.GetSize() <= 0) if (InfoArray.GetSize() <= 0)
{ {
MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_DOWNLOAD); MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_DOWNLOAD);
@ -559,16 +581,11 @@ DWORD WINAPI CDownloadManager::ThreadFunc(LPVOID param)
for (INT iAppId = 0; iAppId < InfoArray.GetSize(); ++iAppId) for (INT iAppId = 0; iAppId < InfoArray.GetSize(); ++iAppId)
{ {
PAPPLICATION_INFO pCurrentInfo = AppsToInstallList[iAppId]; const DownloadInfo &CurrentInfo = InfoArray[iAppId];
if (!pCurrentInfo)
{
MessageBox_LoadString(hMainWnd, IDS_UNABLE_TO_DOWNLOAD);
continue;
}
// build the path for the download // build the path for the download
p = wcsrchr(pCurrentInfo->szUrlDownload.GetString(), L'/'); p = wcsrchr(CurrentInfo.szUrl.GetString(), L'/');
q = wcsrchr(pCurrentInfo->szUrlDownload.GetString(), L'?'); q = wcsrchr(CurrentInfo.szUrl.GetString(), L'?');
// do we have a final slash separator? // do we have a final slash separator?
if (!p) if (!p)
@ -583,7 +600,7 @@ DWORD WINAPI CDownloadManager::ThreadFunc(LPVOID param)
filenameLength -= wcslen(q - 1) * sizeof(WCHAR); filenameLength -= wcslen(q - 1) * sizeof(WCHAR);
// is this URL an update package for RAPPS? if so store it in a different place // 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; bCab = TRUE;
if (!GetStorageDirectory(Path)) if (!GetStorageDirectory(Path))
@ -605,10 +622,10 @@ DWORD WINAPI CDownloadManager::ThreadFunc(LPVOID param)
Path += L"\\"; Path += L"\\";
Path += (LPWSTR) (p + 1); 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 // only open it in case of total correctness
if (VerifyInteg(pCurrentInfo->szSHA1, Path)) if (VerifyInteg(CurrentInfo.szSHA1.GetString(), Path))
goto run; goto run;
} }
@ -622,7 +639,7 @@ DWORD WINAPI CDownloadManager::ThreadFunc(LPVOID param)
// Change caption to show the currently downloaded app // Change caption to show the currently downloaded app
if (!bCab) if (!bCab)
{ {
szNewCaption.Format(szCaption, pCurrentInfo->szName.GetString()); szNewCaption.Format(szCaption, CurrentInfo.szName.GetString());
} }
else else
{ {
@ -632,7 +649,7 @@ DWORD WINAPI CDownloadManager::ThreadFunc(LPVOID param)
SetWindowTextW(hDlg, szNewCaption.GetString()); SetWindowTextW(hDlg, szNewCaption.GetString());
// Add the download URL // 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); DownloadsListView.SetDownloadStatus(iAppId, DOWNLOAD_STATUS::DLDownloading);
@ -663,7 +680,7 @@ DWORD WINAPI CDownloadManager::ThreadFunc(LPVOID param)
if (!hOpen) if (!hOpen)
goto end; 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) if (!hFile)
{ {
@ -685,13 +702,13 @@ DWORD WINAPI CDownloadManager::ThreadFunc(LPVOID param)
memset(&urlComponents, 0, sizeof(urlComponents)); memset(&urlComponents, 0, sizeof(urlComponents));
urlComponents.dwStructSize = sizeof(urlComponents); urlComponents.dwStructSize = sizeof(urlComponents);
urlLength = pCurrentInfo->szUrlDownload.GetLength(); urlLength = CurrentInfo.szUrl.GetLength();
urlComponents.dwSchemeLength = urlLength + 1; urlComponents.dwSchemeLength = urlLength + 1;
urlComponents.lpszScheme = (LPWSTR) malloc(urlComponents.dwSchemeLength * sizeof(WCHAR)); urlComponents.lpszScheme = (LPWSTR) malloc(urlComponents.dwSchemeLength * sizeof(WCHAR));
urlComponents.dwHostNameLength = urlLength + 1; urlComponents.dwHostNameLength = urlLength + 1;
urlComponents.lpszHostName = (LPWSTR) malloc(urlComponents.dwHostNameLength * sizeof(WCHAR)); 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; goto end;
if (urlComponents.nScheme == INTERNET_SCHEME_HTTP || urlComponents.nScheme == INTERNET_SCHEME_HTTPS) if (urlComponents.nScheme == INTERNET_SCHEME_HTTP || urlComponents.nScheme == INTERNET_SCHEME_HTTPS)
@ -703,7 +720,7 @@ DWORD WINAPI CDownloadManager::ThreadFunc(LPVOID param)
#ifdef USE_CERT_PINNING #ifdef USE_CERT_PINNING
// are we using HTTPS to download the RAPPS update package? check if the certificate is original // are we using HTTPS to download the RAPPS update package? check if the certificate is original
if ((urlComponents.nScheme == INTERNET_SCHEME_HTTPS) && if ((urlComponents.nScheme == INTERNET_SCHEME_HTTPS) &&
(wcscmp(pCurrentInfo->szUrlDownload, APPLICATION_DATABASE_URL) == 0) && (wcscmp(CurrentInfo.szUrl, APPLICATION_DATABASE_URL) == 0) &&
(!CertIsValid(hOpen, urlComponents.lpszHostName))) (!CertIsValid(hOpen, urlComponents.lpszHostName)))
{ {
MessageBox_LoadString(hMainWnd, IDS_CERT_DOES_NOT_MATCH); MessageBox_LoadString(hMainWnd, IDS_CERT_DOES_NOT_MATCH);
@ -735,7 +752,7 @@ DWORD WINAPI CDownloadManager::ThreadFunc(LPVOID param)
} }
dwCurrentBytesRead += dwBytesRead; dwCurrentBytesRead += dwBytesRead;
dl->OnProgress(dwCurrentBytesRead, dwContentLen, 0, pCurrentInfo->szUrlDownload.GetString()); dl->OnProgress(dwCurrentBytesRead, dwContentLen, 0, CurrentInfo.szUrl.GetString());
} while (dwBytesRead && !bCancelled); } while (dwBytesRead && !bCancelled);
CloseHandle(hOut); CloseHandle(hOut);
@ -746,7 +763,7 @@ DWORD WINAPI CDownloadManager::ThreadFunc(LPVOID param)
/* if this thing isn't a RAPPS update and it has a SHA-1 checksum /* 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 */ 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; ATL::CStringW szMsgText;
@ -758,7 +775,7 @@ DWORD WINAPI CDownloadManager::ThreadFunc(LPVOID param)
SendMessageW(GetDlgItem(hDlg, IDC_DOWNLOAD_STATUS), WM_SETTEXT, 0, (LPARAM) Path.GetString()); SendMessageW(GetDlgItem(hDlg, IDC_DOWNLOAD_STATUS), WM_SETTEXT, 0, (LPARAM) Path.GetString());
// this may take a while, depending on the file size // 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)) if (!szMsgText.LoadStringW(IDS_INTEG_CHECK_FAIL))
goto end; goto end;
@ -811,11 +828,12 @@ end:
DownloadsListView.SetDownloadStatus(iAppId, DOWNLOAD_STATUS::DLFinished); DownloadsListView.SetDownloadStatus(iAppId, DOWNLOAD_STATUS::DLFinished);
} }
delete param;
SendMessageW(hDlg, WM_CLOSE, 0, 0); SendMessageW(hDlg, WM_CLOSE, 0, 0);
return 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) if (AppsList.GetSize() == 0)
{ {
@ -823,7 +841,13 @@ BOOL CDownloadManager::DownloadListOfApplications(const ATL::CSimpleArray<PAPPLI
} }
// Initialize shared variables // 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 // Create a dialog and issue a download process
LaunchDownloadDialog(bIsModal); LaunchDownloadDialog(bIsModal);
@ -831,26 +855,21 @@ BOOL CDownloadManager::DownloadListOfApplications(const ATL::CSimpleArray<PAPPLI
return TRUE; return TRUE;
} }
BOOL CDownloadManager::DownloadApplication(PAPPLICATION_INFO pAppInfo, BOOL bIsModal) BOOL CDownloadManager::DownloadApplication(CAvailableApplicationInfo* pAppInfo, BOOL bIsModal)
{ {
if (!pAppInfo) if (!pAppInfo)
{
return FALSE; return FALSE;
}
AppsToInstallList.RemoveAll();
AppsToInstallList.Add(pAppInfo);
LaunchDownloadDialog(bIsModal);
Download(*pAppInfo, bIsModal);
return TRUE; return TRUE;
} }
VOID CDownloadManager::DownloadApplicationsDB(LPCWSTR lpUrl) VOID CDownloadManager::DownloadApplicationsDB(LPCWSTR lpUrl)
{ {
static APPLICATION_INFO IntInfo; static DownloadInfo DatabaseDLInfo;
IntInfo.szUrlDownload = lpUrl; DatabaseDLInfo.szUrl = lpUrl;
IntInfo.szName.LoadStringW(IDS_DL_DIALOG_DB_DISP); DatabaseDLInfo.szName.LoadStringW(IDS_DL_DIALOG_DB_DISP);
DownloadApplication(&IntInfo, TRUE); Download(DatabaseDLInfo, TRUE);
} }
//TODO: Reuse the dialog //TODO: Reuse the dialog

View file

@ -58,7 +58,7 @@ BOOL CmdParser(LPWSTR lpCmdLine)
CAvailableApps apps; CAvailableApps apps;
CAvailableApps::UpdateAppsDB(); CAvailableApps::UpdateAppsDB();
apps.EnumAvailableApplications(ENUM_ALL_AVAILABLE, NULL); apps.EnumAvailableApplications(ENUM_ALL_AVAILABLE, NULL);
ATL::CSimpleArray<PAPPLICATION_INFO> arrAppInfo = apps.FindInfoList(arrNames); ATL::CSimpleArray<CAvailableApplicationInfo*> arrAppInfo = apps.FindInfoList(arrNames);
if (arrAppInfo.GetSize() > 0) if (arrAppInfo.GetSize() > 0)
{ {
CDownloadManager::DownloadListOfApplications(arrAppInfo, TRUE); CDownloadManager::DownloadListOfApplications(arrAppInfo, TRUE);