[RAPPS] Rework application handling

Previously, there would be function duplication between installed and available applications.
Now this is handled with polymorphism, which allows to re-use a lot of code.
Additionally, toolbar buttons are properly disabled now.
The mutex used to guard rapps' single instance is renamed,
so that the 'new' and old rapps can be run at the same time for testing.

CORE-18459
This commit is contained in:
Mark Jansen 2023-02-20 19:30:02 +01:00
parent 0cd80c17f6
commit 33c2903e6d
No known key found for this signature in database
GPG key ID: B39240EE84BEAE8B
30 changed files with 3758 additions and 4076 deletions

View file

@ -5,13 +5,13 @@ include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/conutils)
include_directories(include)
list(APPEND SOURCE
applicationdb.cpp
applicationinfo.cpp
appview.cpp
asyncinet.cpp
available.cpp
cabinet.cpp
configparser.cpp
gui.cpp
installed.cpp
integrity.cpp
loaddlg.cpp
misc.cpp
@ -19,15 +19,15 @@ list(APPEND SOURCE
settingsdlg.cpp
unattended.cpp
winmain.cpp
include/applicationdb.h
include/applicationinfo.h
include/appview.h
include/asyncinet.h
include/available.h
include/configparser.h
include/crichedit.h
include/defines.h
include/dialogs.h
include/gui.h
include/installed.h
include/misc.h
include/rapps.h
include/resource.h

View file

@ -0,0 +1,291 @@
/*
* PROJECT: ReactOS Applications Manager
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Classes for working with available applications
* COPYRIGHT: Copyright 2017 Alexander Shaposhnikov (sanchaez@reactos.org)
* Copyright 2020 He Yang (1160386205@qq.com)
* Copyright 2021-2023 Mark Jansen <mark.jansen@reactos.org>
*/
#include "rapps.h"
#include "applicationdb.h"
#include "configparser.h"
#include "settings.h"
static HKEY g_RootKeyEnum[3] = {HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_LOCAL_MACHINE};
static REGSAM g_RegSamEnum[3] = {KEY_WOW64_32KEY, KEY_WOW64_32KEY, KEY_WOW64_64KEY};
#define UNINSTALL_SUBKEY L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall"
static VOID
ClearList(CAtlList<CApplicationInfo *> &list)
{
POSITION InfoListPosition = list.GetHeadPosition();
while (InfoListPosition)
{
CApplicationInfo *Info = list.GetNext(InfoListPosition);
delete Info;
}
list.RemoveAll();
}
CApplicationDB::CApplicationDB(const CStringW &path) : m_BasePath(path)
{
m_BasePath.Canonicalize();
}
CApplicationInfo *
CApplicationDB::FindByPackageName(const CStringW &name)
{
POSITION CurrentListPosition = m_Available.GetHeadPosition();
while (CurrentListPosition)
{
CApplicationInfo *Info = m_Available.GetNext(CurrentListPosition);
if (Info->szIdentifier == name)
{
return Info;
}
}
return NULL;
}
void
CApplicationDB::GetApps(CAtlList<CApplicationInfo *> &List, AppsCategories Type) const
{
const BOOL UseInstalled = IsInstalledEnum(Type);
const CAtlList<CApplicationInfo *> &list = UseInstalled ? m_Installed : m_Available;
const BOOL IncludeAll = UseInstalled ? (Type == ENUM_ALL_INSTALLED) : (Type == ENUM_ALL_AVAILABLE);
POSITION CurrentListPosition = list.GetHeadPosition();
while (CurrentListPosition)
{
CApplicationInfo *Info = list.GetNext(CurrentListPosition);
if (IncludeAll || Type == Info->iCategory)
{
List.AddTail(Info);
}
}
}
BOOL
CApplicationDB::EnumerateFiles()
{
ClearList(m_Available);
CPathW AppsPath = m_BasePath;
AppsPath += L"rapps";
CPathW WildcardPath = AppsPath;
WildcardPath += L"*.txt";
WIN32_FIND_DATAW FindFileData;
HANDLE hFind = FindFirstFileW(WildcardPath, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
{
return FALSE;
}
do
{
CStringW szPkgName = FindFileData.cFileName;
PathRemoveExtensionW(szPkgName.GetBuffer(MAX_PATH));
szPkgName.ReleaseBuffer();
CApplicationInfo *Info = FindByPackageName(szPkgName);
ATLASSERT(Info == NULL);
if (!Info)
{
CConfigParser *Parser = new CConfigParser(FindFileData.cFileName);
int Cat;
if (!Parser->GetInt(L"Category", Cat))
Cat = ENUM_INVALID;
Info = new CAvailableApplicationInfo(Parser, szPkgName, static_cast<AppsCategories>(Cat), AppsPath);
if (Info->Valid())
{
m_Available.AddTail(Info);
}
else
{
delete Info;
}
}
} while (FindNextFileW(hFind, &FindFileData));
FindClose(hFind);
return TRUE;
}
VOID
CApplicationDB::UpdateAvailable()
{
if (!CreateDirectoryW(m_BasePath, NULL) && GetLastError() != ERROR_ALREADY_EXISTS)
return;
if (EnumerateFiles())
return;
DownloadApplicationsDB(
SettingsInfo.bUseSource ? SettingsInfo.szSourceURL : APPLICATION_DATABASE_URL, !SettingsInfo.bUseSource);
CPathW AppsPath = m_BasePath;
AppsPath += L"rapps";
if (!ExtractFilesFromCab(APPLICATION_DATABASE_NAME, m_BasePath, AppsPath))
return;
CPathW CabFile = m_BasePath;
CabFile += APPLICATION_DATABASE_NAME;
DeleteFileW(CabFile);
EnumerateFiles();
}
VOID
CApplicationDB::UpdateInstalled()
{
// Remove all old entries
ClearList(m_Installed);
int LoopKeys = 2;
if (IsSystem64Bit())
{
// loop for all 3 combination.
// note that HKEY_CURRENT_USER\Software don't have a redirect
// https://docs.microsoft.com/en-us/windows/win32/winprog64/shared-registry-keys#redirected-shared-and-reflected-keys-under-wow64
LoopKeys = 3;
}
for (int keyIndex = 0; keyIndex < LoopKeys; keyIndex++)
{
LONG ItemIndex = 0;
WCHAR szKeyName[MAX_PATH];
CRegKey hKey;
if (hKey.Open(g_RootKeyEnum[keyIndex], UNINSTALL_SUBKEY, KEY_READ | g_RegSamEnum[keyIndex]) != ERROR_SUCCESS)
{
continue;
}
while (1)
{
DWORD dwSize = _countof(szKeyName);
if (hKey.EnumKey(ItemIndex, szKeyName, &dwSize) != ERROR_SUCCESS)
{
break;
}
ItemIndex++;
CRegKey hSubKey;
if (hSubKey.Open(hKey, szKeyName, KEY_READ) == ERROR_SUCCESS)
{
DWORD dwValue = 0;
dwSize = sizeof(DWORD);
if (RegQueryValueExW(hSubKey, L"SystemComponent", NULL, NULL, (LPBYTE)&dwValue, &dwSize) ==
ERROR_SUCCESS &&
dwValue == 1)
{
// Ignore system components
continue;
}
BOOL bIsUpdate =
(RegQueryValueExW(hSubKey, L"ParentKeyName", NULL, NULL, NULL, &dwSize) == ERROR_SUCCESS);
CInstalledApplicationInfo *Info = new CInstalledApplicationInfo(
hSubKey.Detach(), szKeyName, bIsUpdate ? ENUM_UPDATES : ENUM_INSTALLED_APPLICATIONS, keyIndex);
if (Info->Valid())
{
m_Installed.AddTail(Info);
}
else
{
delete Info;
}
}
}
}
}
static void
DeleteWithWildcard(const CPathW &Dir, const CStringW &Filter)
{
HANDLE hFind = INVALID_HANDLE_VALUE;
WIN32_FIND_DATAW FindFileData;
CPathW DirWithFilter = Dir;
DirWithFilter += Filter;
hFind = FindFirstFileW(DirWithFilter, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
return;
do
{
CPathW szTmp = Dir;
szTmp += FindFileData.cFileName;
if (!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
DeleteFileW(szTmp);
}
} while (FindNextFileW(hFind, &FindFileData) != 0);
FindClose(hFind);
}
VOID
CApplicationDB::RemoveCached()
{
// Delete icons
CPathW AppsPath = m_BasePath;
AppsPath += L"rapps";
CPathW IconPath = AppsPath;
IconPath += L"icons";
DeleteWithWildcard(IconPath, L"*.ico");
// Delete leftover screenshots
CPathW ScrnshotFolder = AppsPath;
ScrnshotFolder += L"screenshots";
DeleteWithWildcard(ScrnshotFolder, L"*.tmp");
// Delete data base files (*.txt)
DeleteWithWildcard(AppsPath, L"*.txt");
RemoveDirectoryW(IconPath);
RemoveDirectoryW(ScrnshotFolder);
RemoveDirectoryW(AppsPath);
RemoveDirectoryW(m_BasePath);
}
BOOL
CApplicationDB::RemoveInstalledAppFromRegistry(const CApplicationInfo *Info)
{
// Validate that this is actually an installed app / update
ATLASSERT(Info->iCategory == ENUM_INSTALLED_APPLICATIONS || Info->iCategory == ENUM_UPDATES);
if (Info->iCategory != ENUM_INSTALLED_APPLICATIONS && Info->iCategory != ENUM_UPDATES)
return FALSE;
// Grab the index in the registry keys
const CInstalledApplicationInfo *InstalledInfo = static_cast<const CInstalledApplicationInfo *>(Info);
ATLASSERT(InstalledInfo->iKeyIndex >= 0 && InstalledInfo->iKeyIndex < (int)_countof(g_RootKeyEnum));
if (InstalledInfo->iKeyIndex < 0 && InstalledInfo->iKeyIndex >= (int)_countof(g_RootKeyEnum))
return FALSE;
int keyIndex = InstalledInfo->iKeyIndex;
// Grab the registry key name
CStringW Name = InstalledInfo->szIdentifier;
// Recursively delete this key
CRegKey Uninstall;
if (Uninstall.Open(g_RootKeyEnum[keyIndex], UNINSTALL_SUBKEY, KEY_READ | KEY_WRITE | g_RegSamEnum[keyIndex]) !=
ERROR_SUCCESS)
return FALSE;
return Uninstall.RecurseDeleteKey(Name) == ERROR_SUCCESS;
}

View file

@ -0,0 +1,630 @@
/*
* PROJECT: ReactOS Applications Manager
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Classes for working with available applications
* COPYRIGHT: Copyright 2017 Alexander Shaposhnikov (sanchaez@reactos.org)
* Copyright 2020 He Yang (1160386205@qq.com)
* Copyright 2021-2023 Mark Jansen <mark.jansen@reactos.org>
*/
#include "rapps.h"
#include "appview.h"
CApplicationInfo::CApplicationInfo(const CStringW &Identifier, AppsCategories Category)
: szIdentifier(Identifier), iCategory(Category)
{
}
CApplicationInfo::~CApplicationInfo()
{
}
CAvailableApplicationInfo::CAvailableApplicationInfo(
CConfigParser *Parser,
const CStringW &PkgName,
AppsCategories Category,
const CPathW &BasePath)
: CApplicationInfo(PkgName, Category), m_Parser(Parser), m_ScrnshotRetrieved(false), m_LanguagesLoaded(false)
{
m_Parser->GetString(L"Name", szDisplayName);
m_Parser->GetString(L"Version", szDisplayVersion);
m_Parser->GetString(L"URLDownload", m_szUrlDownload);
m_Parser->GetString(L"Description", szComments);
CPathW IconPath = BasePath;
IconPath += L"icons";
CStringW IconName;
if (m_Parser->GetString(L"Icon", IconName))
{
IconPath += IconName;
}
else
{
// inifile.ico
IconPath += (szIdentifier + L".ico");
}
if (PathFileExistsW(IconPath))
{
szDisplayIcon = (LPCWSTR)IconPath;
}
INT iSizeBytes;
if (m_Parser->GetInt(L"SizeBytes", iSizeBytes))
{
StrFormatByteSizeW(iSizeBytes, m_szSize.GetBuffer(MAX_PATH), MAX_PATH);
m_szSize.ReleaseBuffer();
}
m_Parser->GetString(L"URLSite", m_szUrlSite);
}
CAvailableApplicationInfo::~CAvailableApplicationInfo()
{
delete m_Parser;
}
VOID
CAvailableApplicationInfo::ShowAppInfo(CAppRichEdit *RichEdit)
{
RichEdit->SetText(szDisplayName, CFE_BOLD);
InsertVersionInfo(RichEdit);
RichEdit->LoadAndInsertText(IDS_AINFO_LICENSE, LicenseString(), 0);
InsertLanguageInfo(RichEdit);
RichEdit->LoadAndInsertText(IDS_AINFO_SIZE, m_szSize, 0);
RichEdit->LoadAndInsertText(IDS_AINFO_URLSITE, m_szUrlSite, CFE_LINK);
RichEdit->LoadAndInsertText(IDS_AINFO_DESCRIPTION, szComments, 0);
RichEdit->LoadAndInsertText(IDS_AINFO_URLDOWNLOAD, m_szUrlDownload, CFE_LINK);
RichEdit->LoadAndInsertText(IDS_AINFO_PACKAGE_NAME, szIdentifier, 0);
}
int
CompareVersion(const CStringW &left, const CStringW &right)
{
int nLeft = 0, nRight = 0;
while (true)
{
CStringW leftPart = left.Tokenize(L".", nLeft);
CStringW rightPart = right.Tokenize(L".", nRight);
if (leftPart.IsEmpty() && rightPart.IsEmpty())
return 0;
if (leftPart.IsEmpty())
return -1;
if (rightPart.IsEmpty())
return 1;
int leftVal, rightVal;
if (!StrToIntExW(leftPart, STIF_DEFAULT, &leftVal))
leftVal = 0;
if (!StrToIntExW(rightPart, STIF_DEFAULT, &rightVal))
rightVal = 0;
if (leftVal > rightVal)
return 1;
if (rightVal < leftVal)
return -1;
}
}
VOID
CAvailableApplicationInfo::InsertVersionInfo(CAppRichEdit *RichEdit)
{
CStringW szRegName;
m_Parser->GetString(L"RegName", szRegName);
BOOL bIsInstalled = ::GetInstalledVersion(NULL, szRegName) || ::GetInstalledVersion(NULL, szDisplayName);
if (bIsInstalled)
{
CStringW szInstalledVersion;
CStringW szNameVersion = szDisplayName + L" " + szDisplayVersion;
BOOL bHasInstalledVersion = ::GetInstalledVersion(&szInstalledVersion, szRegName) ||
::GetInstalledVersion(&szInstalledVersion, szDisplayName) ||
::GetInstalledVersion(&szInstalledVersion, szNameVersion);
if (bHasInstalledVersion)
{
BOOL bHasUpdate = CompareVersion(szInstalledVersion, szDisplayVersion) < 0;
if (bHasUpdate)
RichEdit->LoadAndInsertText(IDS_STATUS_UPDATE_AVAILABLE, CFE_ITALIC);
else
RichEdit->LoadAndInsertText(IDS_STATUS_INSTALLED, CFE_ITALIC);
RichEdit->LoadAndInsertText(IDS_AINFO_VERSION, szInstalledVersion, 0);
}
else
{
RichEdit->LoadAndInsertText(IDS_STATUS_INSTALLED, CFE_ITALIC);
}
}
else
{
RichEdit->LoadAndInsertText(IDS_STATUS_NOTINSTALLED, CFE_ITALIC);
}
RichEdit->LoadAndInsertText(IDS_AINFO_AVAILABLEVERSION, szDisplayVersion, 0);
}
CStringW
CAvailableApplicationInfo::LicenseString()
{
INT IntBuffer;
m_Parser->GetInt(L"LicenseType", IntBuffer);
CStringW szLicenseString;
m_Parser->GetString(L"License", szLicenseString);
LicenseType licenseType;
if (IsLicenseType(IntBuffer))
{
licenseType = static_cast<LicenseType>(IntBuffer);
}
else
{
licenseType = LICENSE_NONE;
}
CStringW szLicense;
switch (licenseType)
{
case LICENSE_OPENSOURCE:
szLicense.LoadStringW(IDS_LICENSE_OPENSOURCE);
break;
case LICENSE_FREEWARE:
szLicense.LoadStringW(IDS_LICENSE_FREEWARE);
break;
case LICENSE_TRIAL:
szLicense.LoadStringW(IDS_LICENSE_TRIAL);
break;
default:
return szLicenseString;
}
return szLicense + L" (" + szLicenseString + L")";
}
VOID
CAvailableApplicationInfo::InsertLanguageInfo(CAppRichEdit *RichEdit)
{
if (!m_LanguagesLoaded)
{
RetrieveLanguages();
}
if (m_LanguageLCIDs.GetSize() == 0)
{
return;
}
const INT nTranslations = m_LanguageLCIDs.GetSize();
CStringW szLangInfo;
CStringW szLoadedTextAvailability;
CStringW szLoadedAInfoText;
szLoadedAInfoText.LoadStringW(IDS_AINFO_LANGUAGES);
const LCID lcEnglish = MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), SORT_DEFAULT);
if (m_LanguageLCIDs.Find(GetUserDefaultLCID()) >= 0)
{
szLoadedTextAvailability.LoadStringW(IDS_LANGUAGE_AVAILABLE_TRANSLATION);
if (nTranslations > 1)
{
CStringW buf;
buf.LoadStringW(IDS_LANGUAGE_MORE_PLACEHOLDER);
szLangInfo.Format(buf, nTranslations - 1);
}
else
{
szLangInfo.LoadStringW(IDS_LANGUAGE_SINGLE);
szLangInfo = L" (" + szLangInfo + L")";
}
}
else if (m_LanguageLCIDs.Find(lcEnglish) >= 0)
{
szLoadedTextAvailability.LoadStringW(IDS_LANGUAGE_ENGLISH_TRANSLATION);
if (nTranslations > 1)
{
CStringW buf;
buf.LoadStringW(IDS_LANGUAGE_AVAILABLE_PLACEHOLDER);
szLangInfo.Format(buf, nTranslations - 1);
}
else
{
szLangInfo.LoadStringW(IDS_LANGUAGE_SINGLE);
szLangInfo = L" (" + szLangInfo + L")";
}
}
else
{
szLoadedTextAvailability.LoadStringW(IDS_LANGUAGE_NO_TRANSLATION);
}
RichEdit->InsertText(szLoadedAInfoText, CFE_BOLD);
RichEdit->InsertText(szLoadedTextAvailability, NULL);
RichEdit->InsertText(szLangInfo, CFE_ITALIC);
}
VOID
CAvailableApplicationInfo::RetrieveLanguages()
{
m_LanguagesLoaded = true;
CStringW szBuffer;
if (!m_Parser->GetString(L"Languages", szBuffer))
{
return;
}
// Parse parameter string
int iIndex = 0;
while (true)
{
CStringW szLocale = szBuffer.Tokenize(L"|", iIndex);
if (szLocale.IsEmpty())
break;
szLocale = L"0x" + szLocale;
INT iLCID;
if (StrToIntExW(szLocale, STIF_SUPPORT_HEX, &iLCID))
{
m_LanguageLCIDs.Add(static_cast<LCID>(iLCID));
}
}
}
BOOL
CAvailableApplicationInfo::Valid() const
{
return !szDisplayName.IsEmpty() && !m_szUrlDownload.IsEmpty();
}
BOOL
CAvailableApplicationInfo::CanModify()
{
return FALSE;
}
BOOL
CAvailableApplicationInfo::RetrieveIcon(CStringW &Path) const
{
Path = szDisplayIcon;
return !Path.IsEmpty();
}
#define MAX_SCRNSHOT_NUM 16
BOOL
CAvailableApplicationInfo::RetrieveScreenshot(CStringW &Path)
{
if (!m_ScrnshotRetrieved)
{
static_assert(MAX_SCRNSHOT_NUM < 10000, "MAX_SCRNSHOT_NUM is too big");
for (int i = 0; i < MAX_SCRNSHOT_NUM; i++)
{
CStringW ScrnshotField;
ScrnshotField.Format(L"Screenshot%d", i + 1);
CStringW ScrnshotLocation;
if (!m_Parser->GetString(ScrnshotField, ScrnshotLocation))
{
// We stop at the first screenshot not found,
// so screenshots _have_ to be consecutive
break;
}
if (PathIsURLW(ScrnshotLocation.GetString()))
{
m_szScrnshotLocation.Add(ScrnshotLocation);
}
}
m_ScrnshotRetrieved = true;
}
if (m_szScrnshotLocation.GetSize() > 0)
{
Path = m_szScrnshotLocation[0];
}
return !Path.IsEmpty();
}
VOID
CAvailableApplicationInfo::GetDownloadInfo(CStringW &Url, CStringW &Sha1, ULONG &SizeInBytes) const
{
Url = m_szUrlDownload;
m_Parser->GetString(L"SHA1", Sha1);
INT iSizeBytes;
if (m_Parser->GetInt(L"SizeBytes", iSizeBytes))
{
SizeInBytes = (ULONG)iSizeBytes;
}
else
{
SizeInBytes = 0;
}
}
VOID
CAvailableApplicationInfo::GetDisplayInfo(CStringW &License, CStringW &Size, CStringW &UrlSite, CStringW &UrlDownload)
{
License = LicenseString();
Size = m_szSize;
UrlSite = m_szUrlSite;
UrlDownload = m_szUrlDownload;
}
BOOL
CAvailableApplicationInfo::UninstallApplication(BOOL bModify)
{
ATLASSERT(FALSE && "Should not be called");
return FALSE;
}
CInstalledApplicationInfo::CInstalledApplicationInfo(
HKEY Key,
const CStringW &KeyName,
AppsCategories Category,
int KeyIndex)
: CApplicationInfo(KeyName, Category), m_hKey(Key), iKeyIndex(KeyIndex)
{
if (GetApplicationRegString(L"DisplayName", szDisplayName))
{
GetApplicationRegString(L"DisplayIcon", szDisplayIcon);
GetApplicationRegString(L"DisplayVersion", szDisplayVersion);
GetApplicationRegString(L"Comments", szComments);
}
}
CInstalledApplicationInfo::~CInstalledApplicationInfo()
{
}
VOID
CInstalledApplicationInfo::AddApplicationRegString(
CAppRichEdit *RichEdit,
UINT StringID,
const CStringW &String,
DWORD TextFlags)
{
CStringW Tmp;
if (GetApplicationRegString(String, Tmp))
{
RichEdit->InsertTextWithString(StringID, Tmp, TextFlags);
}
}
VOID
CInstalledApplicationInfo::ShowAppInfo(CAppRichEdit *RichEdit)
{
RichEdit->SetText(szDisplayName, CFE_BOLD);
RichEdit->InsertText(L"\n", 0);
RichEdit->InsertTextWithString(IDS_INFO_VERSION, szDisplayVersion, 0);
AddApplicationRegString(RichEdit, IDS_INFO_PUBLISHER, L"Publisher", 0);
AddApplicationRegString(RichEdit, IDS_INFO_REGOWNER, L"RegOwner", 0);
AddApplicationRegString(RichEdit, IDS_INFO_PRODUCTID, L"ProductID", 0);
AddApplicationRegString(RichEdit, IDS_INFO_HELPLINK, L"HelpLink", CFM_LINK);
AddApplicationRegString(RichEdit, IDS_INFO_HELPPHONE, L"HelpTelephone", 0);
AddApplicationRegString(RichEdit, IDS_INFO_README, L"Readme", 0);
AddApplicationRegString(RichEdit, IDS_INFO_CONTACT, L"Contact", 0);
AddApplicationRegString(RichEdit, IDS_INFO_UPDATEINFO, L"URLUpdateInfo", CFM_LINK);
AddApplicationRegString(RichEdit, IDS_INFO_INFOABOUT, L"URLInfoAbout", CFM_LINK);
RichEdit->InsertTextWithString(IDS_INFO_COMMENTS, szComments, 0);
if (m_szInstallDate.IsEmpty())
{
RetrieveInstallDate();
}
RichEdit->InsertTextWithString(IDS_INFO_INSTALLDATE, m_szInstallDate, 0);
AddApplicationRegString(RichEdit, IDS_INFO_INSTLOCATION, L"InstallLocation", 0);
AddApplicationRegString(RichEdit, IDS_INFO_INSTALLSRC, L"InstallSource", 0);
if (m_szUninstallString.IsEmpty())
{
RetrieveUninstallStrings();
}
RichEdit->InsertTextWithString(IDS_INFO_UNINSTALLSTR, m_szUninstallString, 0);
RichEdit->InsertTextWithString(IDS_INFO_MODIFYPATH, m_szModifyString, 0);
}
VOID
CInstalledApplicationInfo::RetrieveInstallDate()
{
DWORD dwInstallTimeStamp;
SYSTEMTIME InstallLocalTime;
if (GetApplicationRegString(L"InstallDate", m_szInstallDate))
{
ZeroMemory(&InstallLocalTime, sizeof(InstallLocalTime));
// Check if we have 8 characters to parse the datetime.
// Maybe other formats exist as well?
m_szInstallDate = m_szInstallDate.Trim();
if (m_szInstallDate.GetLength() == 8)
{
InstallLocalTime.wYear = wcstol(m_szInstallDate.Left(4).GetString(), NULL, 10);
InstallLocalTime.wMonth = wcstol(m_szInstallDate.Mid(4, 2).GetString(), NULL, 10);
InstallLocalTime.wDay = wcstol(m_szInstallDate.Mid(6, 2).GetString(), NULL, 10);
}
}
// It might be a DWORD (Unix timestamp). try again.
else if (GetApplicationRegDword(L"InstallDate", &dwInstallTimeStamp))
{
FILETIME InstallFileTime;
SYSTEMTIME InstallSystemTime;
UnixTimeToFileTime(dwInstallTimeStamp, &InstallFileTime);
FileTimeToSystemTime(&InstallFileTime, &InstallSystemTime);
// convert to localtime
SystemTimeToTzSpecificLocalTime(NULL, &InstallSystemTime, &InstallLocalTime);
}
// convert to readable date string
int cchTimeStrLen = GetDateFormatW(LOCALE_USER_DEFAULT, 0, &InstallLocalTime, NULL, 0, 0);
GetDateFormatW(
LOCALE_USER_DEFAULT, // use default locale for current user
0, &InstallLocalTime, NULL, m_szInstallDate.GetBuffer(cchTimeStrLen), cchTimeStrLen);
m_szInstallDate.ReleaseBuffer();
}
VOID
CInstalledApplicationInfo::RetrieveUninstallStrings()
{
DWORD dwWindowsInstaller = 0;
if (GetApplicationRegDword(L"WindowsInstaller", &dwWindowsInstaller) && dwWindowsInstaller)
{
// MSI has the same info in Uninstall / modify, so manually build it
m_szUninstallString.Format(L"msiexec /x%s", szIdentifier.GetString());
}
else
{
GetApplicationRegString(L"UninstallString", m_szUninstallString);
}
DWORD dwNoModify = 0;
if (!GetApplicationRegDword(L"NoModify", &dwNoModify))
{
CStringW Tmp;
if (GetApplicationRegString(L"NoModify", Tmp))
{
dwNoModify = Tmp.GetLength() > 0 ? (Tmp[0] == '1') : 0;
}
else
{
dwNoModify = 0;
}
}
if (!dwNoModify)
{
if (dwWindowsInstaller)
{
m_szModifyString.Format(L"msiexec /i%s", szIdentifier.GetString());
}
else
{
GetApplicationRegString(L"ModifyPath", m_szModifyString);
}
}
}
BOOL
CInstalledApplicationInfo::Valid() const
{
return !szDisplayName.IsEmpty();
}
BOOL
CInstalledApplicationInfo::CanModify()
{
if (m_szUninstallString.IsEmpty())
{
RetrieveUninstallStrings();
}
return !m_szModifyString.IsEmpty();
}
BOOL
CInstalledApplicationInfo::RetrieveIcon(CStringW &Path) const
{
Path = szDisplayIcon;
return !Path.IsEmpty();
}
BOOL
CInstalledApplicationInfo::RetrieveScreenshot(CStringW & /*Path*/)
{
return FALSE;
}
VOID
CInstalledApplicationInfo::GetDownloadInfo(CStringW &Url, CStringW &Sha1, ULONG &SizeInBytes) const
{
ATLASSERT(FALSE && "Should not be called");
}
VOID
CInstalledApplicationInfo::GetDisplayInfo(CStringW &License, CStringW &Size, CStringW &UrlSite, CStringW &UrlDownload)
{
ATLASSERT(FALSE && "Should not be called");
}
BOOL
CInstalledApplicationInfo::UninstallApplication(BOOL bModify)
{
if (m_szUninstallString.IsEmpty())
{
RetrieveUninstallStrings();
}
BOOL bSuccess = StartProcess(bModify ? m_szModifyString : m_szUninstallString, TRUE);
if (bSuccess && !bModify)
WriteLogMessage(EVENTLOG_SUCCESS, MSG_SUCCESS_REMOVE, szDisplayName);
return bSuccess;
}
BOOL
CInstalledApplicationInfo::GetApplicationRegString(LPCWSTR lpKeyName, CStringW &String)
{
ULONG nChars = 0;
// Get the size
if (m_hKey.QueryStringValue(lpKeyName, NULL, &nChars) != ERROR_SUCCESS)
{
String.Empty();
return FALSE;
}
LPWSTR Buffer = String.GetBuffer(nChars);
LONG lResult = m_hKey.QueryStringValue(lpKeyName, Buffer, &nChars);
if (nChars > 0 && Buffer[nChars - 1] == UNICODE_NULL)
nChars--;
String.ReleaseBuffer(nChars);
if (lResult != ERROR_SUCCESS)
{
String.Empty();
return FALSE;
}
if (String.Find('%') >= 0)
{
CStringW Tmp;
DWORD dwLen = ExpandEnvironmentStringsW(String, NULL, 0);
if (dwLen > 0)
{
BOOL bSuccess = ExpandEnvironmentStringsW(String, Tmp.GetBuffer(dwLen), dwLen) == dwLen;
Tmp.ReleaseBuffer(dwLen - 1);
if (bSuccess)
{
String = Tmp;
}
else
{
String.Empty();
return FALSE;
}
}
}
return TRUE;
}
BOOL
CInstalledApplicationInfo::GetApplicationRegDword(LPCWSTR lpKeyName, DWORD *lpValue)
{
DWORD dwSize = sizeof(DWORD), dwType;
if (RegQueryValueExW(m_hKey, lpKeyName, NULL, &dwType, (LPBYTE)lpValue, &dwSize) != ERROR_SUCCESS ||
dwType != REG_DWORD)
{
return FALSE;
}
return TRUE;
}

File diff suppressed because it is too large Load diff

View file

@ -1,612 +0,0 @@
/*
* PROJECT: ReactOS Applications Manager
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Classes for working with available applications
* COPYRIGHT: Copyright 2009 Dmitry Chapyshev (dmitry@reactos.org)
* Copyright 2015 Ismael Ferreras Morezuelas (swyterzone+ros@gmail.com)
* Copyright 2017 Alexander Shaposhnikov (sanchaez@reactos.org)
* Copyright 2020 He Yang (1160386205@qq.com)
*/
#include "rapps.h"
#include "available.h"
#include "misc.h"
#include "dialogs.h"
// CAvailableApplicationInfo
CAvailableApplicationInfo::CAvailableApplicationInfo(const ATL::CStringW& sFileNameParam, AvailableStrings& AvlbStrings)
: m_LicenseType(LICENSE_NONE), m_SizeBytes(0), m_sFileName(sFileNameParam),
m_IsInstalled(FALSE), m_HasLanguageInfo(FALSE), m_HasInstalledVersion(FALSE)
{
RetrieveGeneralInfo(AvlbStrings);
}
VOID CAvailableApplicationInfo::RefreshAppInfo(AvailableStrings& AvlbStrings)
{
if (m_szUrlDownload.IsEmpty())
{
RetrieveGeneralInfo(AvlbStrings);
}
}
// Lazily load general info from the file
VOID CAvailableApplicationInfo::RetrieveGeneralInfo(AvailableStrings& AvlbStrings)
{
m_Parser = new CConfigParser(m_sFileName);
// TODO: I temporarily use the file name (without suffix) as package name.
// It should be better to put this in a field of ini file.
// Consider writing a converter to do this and write a github action for
// rapps-db to ensure package_name is unique.
m_szPkgName = m_sFileName;
PathRemoveExtensionW(m_szPkgName.GetBuffer(MAX_PATH));
m_szPkgName.ReleaseBuffer();
m_Parser->GetInt(L"Category", m_Category);
if (!GetString(L"Name", m_szName)
|| !GetString(L"URLDownload", m_szUrlDownload))
{
delete m_Parser;
return;
}
GetString(L"RegName", m_szRegName);
GetString(L"Version", m_szVersion);
GetString(L"License", m_szLicense);
GetString(L"Description", m_szDesc);
GetString(L"URLSite", m_szUrlSite);
GetString(L"SHA1", m_szSHA1);
static_assert(MAX_SCRNSHOT_NUM < 10000, "MAX_SCRNSHOT_NUM is too big");
for (int i = 0; i < MAX_SCRNSHOT_NUM; i++)
{
CStringW ScrnshotField;
ScrnshotField.Format(L"Screenshot%d", i + 1);
CStringW ScrnshotLocation;
if (!GetString(ScrnshotField, ScrnshotLocation))
{
// We stop at the first screenshot not found,
// so screenshots _have_ to be consecutive
break;
}
if (PathIsURLW(ScrnshotLocation.GetString()))
{
m_szScrnshotLocation.Add(ScrnshotLocation);
}
else
{
// TODO: Does the filename contain anything stuff like ":" "<" ">" ?
// these stuff may lead to security issues
ATL::CStringW ScrnshotName = AvlbStrings.szAppsPath;
PathAppendW(ScrnshotName.GetBuffer(MAX_PATH), L"screenshots");
BOOL bSuccess = PathAppendNoDirEscapeW(ScrnshotName.GetBuffer(), ScrnshotLocation.GetString());
ScrnshotName.ReleaseBuffer();
if (bSuccess)
{
m_szScrnshotLocation.Add(ScrnshotName);
}
}
}
ATL::CStringW IconPath = AvlbStrings.szAppsPath;
PathAppendW(IconPath.GetBuffer(MAX_PATH), L"icons");
// TODO: are we going to support specify an URL for an icon ?
ATL::CStringW IconLocation;
if (GetString(L"Icon", IconLocation))
{
BOOL bSuccess = PathAppendNoDirEscapeW(IconPath.GetBuffer(), IconLocation.GetString());
IconPath.ReleaseBuffer();
if (!bSuccess)
{
IconPath.Empty();
}
}
else
{
// inifile.ico
PathAppendW(IconPath.GetBuffer(), m_szPkgName);
IconPath.ReleaseBuffer();
IconPath += L".ico";
}
if (!IconPath.IsEmpty())
{
if (PathFileExistsW(IconPath))
{
m_szIconLocation = IconPath;
}
}
RetrieveSize();
RetrieveLicenseType();
RetrieveLanguages();
RetrieveInstalledStatus();
if (m_IsInstalled)
{
RetrieveInstalledVersion();
}
delete m_Parser;
}
VOID CAvailableApplicationInfo::RetrieveInstalledStatus()
{
m_IsInstalled = ::GetInstalledVersion(NULL, m_szRegName)
|| ::GetInstalledVersion(NULL, m_szName);
}
VOID CAvailableApplicationInfo::RetrieveInstalledVersion()
{
ATL::CStringW szNameVersion;
szNameVersion = m_szName + L" " + m_szVersion;
m_HasInstalledVersion = ::GetInstalledVersion(&m_szInstalledVersion, m_szRegName)
|| ::GetInstalledVersion(&m_szInstalledVersion, m_szName)
|| ::GetInstalledVersion(&m_szInstalledVersion, szNameVersion);
}
VOID CAvailableApplicationInfo::RetrieveLanguages()
{
const WCHAR cDelimiter = L'|';
ATL::CStringW szBuffer;
// TODO: Get multiline parameter
if (!m_Parser->GetString(L"Languages", szBuffer))
{
m_HasLanguageInfo = FALSE;
return;
}
// Parse parameter string
ATL::CStringW m_szLocale;
INT iLCID;
for (INT i = 0; szBuffer[i] != UNICODE_NULL; ++i)
{
if (szBuffer[i] != cDelimiter && szBuffer[i] != L'\n')
{
m_szLocale += szBuffer[i];
}
else
{
if (StrToIntExW(m_szLocale.GetString(), STIF_DEFAULT, &iLCID))
{
m_LanguageLCIDs.Add(static_cast<LCID>(iLCID));
m_szLocale.Empty();
}
}
}
// For the text after delimiter
if (!m_szLocale.IsEmpty())
{
if (StrToIntExW(m_szLocale.GetString(), STIF_DEFAULT, &iLCID))
{
m_LanguageLCIDs.Add(static_cast<LCID>(iLCID));
}
}
m_HasLanguageInfo = TRUE;
}
VOID CAvailableApplicationInfo::RetrieveLicenseType()
{
INT IntBuffer;
m_Parser->GetInt(L"LicenseType", IntBuffer);
if (IsLicenseType(IntBuffer))
{
m_LicenseType = static_cast<LicenseType>(IntBuffer);
}
else
{
m_LicenseType = LICENSE_NONE;
}
}
VOID CAvailableApplicationInfo::RetrieveSize()
{
INT iSizeBytes;
if (!m_Parser->GetInt(L"SizeBytes", iSizeBytes))
return;
m_SizeBytes = iSizeBytes;
StrFormatByteSizeW(iSizeBytes, m_szSize.GetBuffer(MAX_PATH), MAX_PATH);
m_szSize.ReleaseBuffer();
}
BOOL CAvailableApplicationInfo::FindInLanguages(LCID what) const
{
if (!m_HasLanguageInfo)
{
return FALSE;
}
//Find locale code in the list
const INT nLanguagesSize = m_LanguageLCIDs.GetSize();
for (INT i = 0; i < nLanguagesSize; ++i)
{
if (m_LanguageLCIDs[i] == what)
{
return TRUE;
}
}
return FALSE;
}
BOOL CAvailableApplicationInfo::HasLanguageInfo() const
{
return m_HasLanguageInfo;
}
BOOL CAvailableApplicationInfo::HasNativeLanguage() const
{
return FindInLanguages(GetUserDefaultLCID());
}
BOOL CAvailableApplicationInfo::HasEnglishLanguage() const
{
return FindInLanguages(MAKELCID(MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), SORT_DEFAULT));
}
BOOL CAvailableApplicationInfo::IsInstalled() const
{
return m_IsInstalled;
}
BOOL CAvailableApplicationInfo::HasInstalledVersion() const
{
return m_HasInstalledVersion;
}
BOOL CAvailableApplicationInfo::HasUpdate() const
{
return (m_szInstalledVersion.Compare(m_szVersion) < 0) ? TRUE : FALSE;
}
BOOL CAvailableApplicationInfo::RetrieveScrnshot(UINT Index,ATL::CStringW& ScrnshotLocation) const
{
if (Index >= (UINT)m_szScrnshotLocation.GetSize())
{
return FALSE;
}
ScrnshotLocation = m_szScrnshotLocation[Index];
return TRUE;
}
BOOL CAvailableApplicationInfo::RetrieveIcon(ATL::CStringW& IconLocation) const
{
if (m_szIconLocation.IsEmpty())
{
return FALSE;
}
IconLocation = m_szIconLocation;
return TRUE;
}
VOID CAvailableApplicationInfo::SetLastWriteTime(FILETIME* ftTime)
{
RtlCopyMemory(&m_ftCacheStamp, ftTime, sizeof(FILETIME));
}
inline BOOL CAvailableApplicationInfo::GetString(LPCWSTR lpKeyName, ATL::CStringW& ReturnedString)
{
if (!m_Parser->GetString(lpKeyName, ReturnedString))
{
ReturnedString.Empty();
return FALSE;
}
return TRUE;
}
// CAvailableApplicationInfo
// AvailableStrings
AvailableStrings::AvailableStrings()
{
//FIXME: maybe provide a fallback?
if (GetStorageDirectory(szPath))
{
szAppsPath = szPath;
PathAppendW(szAppsPath.GetBuffer(MAX_PATH), L"rapps");
szAppsPath.ReleaseBuffer();
szCabName = APPLICATION_DATABASE_NAME;
szCabDir = szPath;
szCabPath = szCabDir;
PathAppendW(szCabPath.GetBuffer(MAX_PATH), szCabName);
szCabPath.ReleaseBuffer();
szSearchPath = szAppsPath;
PathAppendW(szSearchPath.GetBuffer(MAX_PATH), L"*.txt");
szSearchPath.ReleaseBuffer();
}
}
// AvailableStrings
// CAvailableApps
AvailableStrings CAvailableApps::m_Strings;
CAvailableApps::CAvailableApps()
{
}
VOID CAvailableApps::FreeCachedEntries()
{
POSITION InfoListPosition = m_InfoList.GetHeadPosition();
/* loop and deallocate all the cached app infos in the list */
while (InfoListPosition)
{
CAvailableApplicationInfo* Info = m_InfoList.GetNext(InfoListPosition);
delete Info;
}
m_InfoList.RemoveAll();
}
static void DeleteWithWildcard(const CStringW& DirWithFilter)
{
HANDLE hFind = INVALID_HANDLE_VALUE;
WIN32_FIND_DATAW FindFileData;
hFind = FindFirstFileW(DirWithFilter, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
return;
CStringW Dir = DirWithFilter;
PathRemoveFileSpecW(Dir.GetBuffer(MAX_PATH));
Dir.ReleaseBuffer();
do
{
ATL::CStringW szTmp = Dir + L"\\";
szTmp += FindFileData.cFileName;
if (!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
DeleteFileW(szTmp);
}
} while (FindNextFileW(hFind, &FindFileData) != 0);
FindClose(hFind);
}
VOID CAvailableApps::DeleteCurrentAppsDB()
{
// Delete icons
ATL::CStringW IconPath = m_Strings.szAppsPath;
PathAppendW(IconPath.GetBuffer(MAX_PATH), L"icons");
IconPath.ReleaseBuffer();
DeleteWithWildcard(IconPath + L"\\*.ico");
// Delete leftover screenshots
ATL::CStringW ScrnshotFolder = m_Strings.szAppsPath;
PathAppendW(ScrnshotFolder.GetBuffer(MAX_PATH), L"screenshots");
ScrnshotFolder.ReleaseBuffer();
DeleteWithWildcard(IconPath + L"\\*.tmp");
// Delete data base files (*.txt)
DeleteWithWildcard(m_Strings.szSearchPath);
RemoveDirectoryW(IconPath);
RemoveDirectoryW(ScrnshotFolder);
RemoveDirectoryW(m_Strings.szAppsPath);
RemoveDirectoryW(m_Strings.szPath);
}
BOOL CAvailableApps::UpdateAppsDB()
{
HANDLE hFind = INVALID_HANDLE_VALUE;
WIN32_FIND_DATAW FindFileData;
if (!CreateDirectoryW(m_Strings.szPath, NULL) && GetLastError() != ERROR_ALREADY_EXISTS)
{
return FALSE;
}
// If there are some files in the db folder, we're good
hFind = FindFirstFileW(m_Strings.szSearchPath, &FindFileData);
if (hFind != INVALID_HANDLE_VALUE)
{
FindClose(hFind);
return TRUE;
}
DownloadApplicationsDB(SettingsInfo.bUseSource ? SettingsInfo.szSourceURL : APPLICATION_DATABASE_URL,
!SettingsInfo.bUseSource);
if (!ExtractFilesFromCab(m_Strings.szCabName,
m_Strings.szCabDir,
m_Strings.szAppsPath))
{
return FALSE;
}
DeleteFileW(m_Strings.szCabPath);
return TRUE;
}
BOOL CAvailableApps::ForceUpdateAppsDB()
{
DeleteCurrentAppsDB();
return UpdateAppsDB();
}
BOOL CAvailableApps::Enum(INT EnumType, AVAILENUMPROC lpEnumProc, PVOID param)
{
if (EnumType == ENUM_CAT_SELECTED)
{
CAvailableApplicationInfo *EnumAvlbInfo = NULL;
// enum all object in m_SelectedList and invoke callback
for(POSITION CurrentPosition = m_SelectedList.GetHeadPosition();
CurrentPosition && (EnumAvlbInfo = m_SelectedList.GetAt(CurrentPosition));
m_SelectedList.GetNext(CurrentPosition))
{
EnumAvlbInfo->RefreshAppInfo(m_Strings);
if (lpEnumProc)
lpEnumProc(EnumAvlbInfo, TRUE, param);
}
return TRUE;
}
else
{
HANDLE hFind = INVALID_HANDLE_VALUE;
WIN32_FIND_DATAW FindFileData;
hFind = FindFirstFileW(m_Strings.szSearchPath.GetString(), &FindFileData);
if (hFind == INVALID_HANDLE_VALUE)
{
//no db yet
return FALSE;
}
do
{
// loop for all the cached entries
POSITION CurrentListPosition = m_InfoList.GetHeadPosition();
CAvailableApplicationInfo *Info = NULL;
while (CurrentListPosition != NULL)
{
POSITION LastListPosition = CurrentListPosition;
Info = m_InfoList.GetNext(CurrentListPosition);
// do we already have this entry in cache?
if (Info->m_sFileName == FindFileData.cFileName)
{
// is it current enough, or the file has been modified since our last time here?
if (CompareFileTime(&FindFileData.ftLastWriteTime, &Info->m_ftCacheStamp) == 1)
{
// recreate our cache, this is the slow path
m_InfoList.RemoveAt(LastListPosition);
// also remove this in selected list (if exist)
RemoveSelected(Info);
delete Info;
Info = NULL;
break;
}
else
{
// speedy path, compare directly, we already have the data
goto skip_if_cached;
}
}
}
// create a new entry
Info = new CAvailableApplicationInfo(FindFileData.cFileName, m_Strings);
// set a timestamp for the next time
Info->SetLastWriteTime(&FindFileData.ftLastWriteTime);
/* Check if we have the download URL */
if (Info->m_szUrlDownload.IsEmpty())
{
/* Can't use it, delete it */
delete Info;
continue;
}
m_InfoList.AddTail(Info);
skip_if_cached:
if (EnumType == Info->m_Category
|| EnumType == ENUM_ALL_AVAILABLE)
{
Info->RefreshAppInfo(m_Strings);
if (lpEnumProc)
{
if (m_SelectedList.Find(Info))
{
lpEnumProc(Info, TRUE, param);
}
else
{
lpEnumProc(Info, FALSE, param);
}
}
}
} while (FindNextFileW(hFind, &FindFileData));
FindClose(hFind);
return TRUE;
}
}
BOOL CAvailableApps::AddSelected(CAvailableApplicationInfo *AvlbInfo)
{
return m_SelectedList.AddTail(AvlbInfo) != 0;
}
BOOL CAvailableApps::RemoveSelected(CAvailableApplicationInfo *AvlbInfo)
{
POSITION Position = m_SelectedList.Find(AvlbInfo);
if (Position)
{
m_SelectedList.RemoveAt(Position);
return TRUE;
}
return FALSE;
}
VOID CAvailableApps::RemoveAllSelected()
{
m_SelectedList.RemoveAll();
return;
}
int CAvailableApps::GetSelectedCount()
{
return m_SelectedList.GetCount();
}
CAvailableApplicationInfo* CAvailableApps::FindAppByPkgName(const ATL::CStringW& szPkgName) const
{
if (m_InfoList.IsEmpty())
{
return NULL;
}
// linear search
POSITION CurrentListPosition = m_InfoList.GetHeadPosition();
CAvailableApplicationInfo* info;
while (CurrentListPosition != NULL)
{
info = m_InfoList.GetNext(CurrentListPosition);
if (info->m_szPkgName.CompareNoCase(szPkgName) == 0)
{
return info;
}
}
return NULL;
}
ATL::CSimpleArray<CAvailableApplicationInfo> CAvailableApps::FindAppsByPkgNameList(const ATL::CSimpleArray<ATL::CStringW> &PkgNameList) const
{
ATL::CSimpleArray<CAvailableApplicationInfo> result;
for (INT i = 0; i < PkgNameList.GetSize(); ++i)
{
CAvailableApplicationInfo* Info = FindAppByPkgName(PkgNameList[i]);
if (Info)
{
result.Add(*Info);
}
}
return result;
}
// CAvailableApps

View file

@ -22,58 +22,32 @@
/* String conversion helper functions */
// converts CStringW to CStringA using a given codepage
inline BOOL WideToMultiByte(const CStringW& szSource,
CStringA& szDest,
UINT Codepage)
inline BOOL
WideToMultiByte(const CStringW &szSource, CStringA &szDest, UINT Codepage)
{
// determine the needed size
INT sz = WideCharToMultiByte(Codepage,
0,
szSource,
-1,
NULL,
NULL,
NULL,
NULL);
INT sz = WideCharToMultiByte(Codepage, 0, szSource, -1, NULL, NULL, NULL, NULL);
if (!sz)
return FALSE;
// do the actual conversion
sz = WideCharToMultiByte(Codepage,
0,
szSource,
-1,
szDest.GetBuffer(sz),
sz,
NULL,
NULL);
sz = WideCharToMultiByte(Codepage, 0, szSource, -1, szDest.GetBuffer(sz), sz, NULL, NULL);
szDest.ReleaseBuffer();
return sz != 0;
}
// converts CStringA to CStringW using a given codepage
inline BOOL MultiByteToWide(const CStringA& szSource,
CStringW& szDest,
UINT Codepage)
inline BOOL
MultiByteToWide(const CStringA &szSource, CStringW &szDest, UINT Codepage)
{
// determine the needed size
INT sz = MultiByteToWideChar(Codepage,
0,
szSource,
-1,
NULL,
NULL);
INT sz = MultiByteToWideChar(Codepage, 0, szSource, -1, NULL, NULL);
if (!sz)
return FALSE;
// do the actual conversion
sz = MultiByteToWideChar(CP_UTF8,
0,
szSource,
-1,
szDest.GetBuffer(sz),
sz);
sz = MultiByteToWideChar(CP_UTF8, 0, szSource, -1, szDest.GetBuffer(sz), sz);
szDest.ReleaseBuffer();
return sz != 0;
@ -96,7 +70,7 @@ FNOPEN(fnFileOpen)
HANDLE hFile = NULL;
DWORD dwDesiredAccess = 0;
DWORD dwCreationDisposition = 0;
ATL::CStringW szFileName;
CStringW szFileName;
UNREFERENCED_PARAMETER(pmode);
@ -124,24 +98,19 @@ FNOPEN(fnFileOpen)
MultiByteToWide(pszFile, szFileName, CP_UTF8);
hFile = CreateFileW(szFileName,
dwDesiredAccess,
FILE_SHARE_READ,
NULL,
dwCreationDisposition,
FILE_ATTRIBUTE_NORMAL,
NULL);
hFile = CreateFileW(
szFileName, dwDesiredAccess, FILE_SHARE_READ, NULL, dwCreationDisposition, FILE_ATTRIBUTE_NORMAL, NULL);
return (INT_PTR) hFile;
return (INT_PTR)hFile;
}
FNREAD(fnFileRead)
{
DWORD dwBytesRead = 0;
if (ReadFile((HANDLE) hf, pv, cb, &dwBytesRead, NULL) == FALSE)
if (ReadFile((HANDLE)hf, pv, cb, &dwBytesRead, NULL) == FALSE)
{
dwBytesRead = (DWORD) -1L;
dwBytesRead = (DWORD)-1L;
}
return dwBytesRead;
@ -151,9 +120,9 @@ FNWRITE(fnFileWrite)
{
DWORD dwBytesWritten = 0;
if (WriteFile((HANDLE) hf, pv, cb, &dwBytesWritten, NULL) == FALSE)
if (WriteFile((HANDLE)hf, pv, cb, &dwBytesWritten, NULL) == FALSE)
{
dwBytesWritten = (DWORD) -1;
dwBytesWritten = (DWORD)-1;
}
return dwBytesWritten;
@ -161,12 +130,12 @@ FNWRITE(fnFileWrite)
FNCLOSE(fnFileClose)
{
return (CloseHandle((HANDLE) hf) != FALSE) ? 0 : -1;
return (CloseHandle((HANDLE)hf) != FALSE) ? 0 : -1;
}
FNSEEK(fnFileSeek)
{
return SetFilePointer((HANDLE) hf, dist, NULL, seektype);
return SetFilePointer((HANDLE)hf, dist, NULL, seektype);
}
/* FDICopy callbacks */
@ -182,7 +151,7 @@ FNFDINOTIFY(fnNotify)
CStringW szExtractDir, szCabFileName;
// Append the destination directory to the file name.
MultiByteToWide((LPCSTR) pfdin->pv, szExtractDir, CP_UTF8);
MultiByteToWide((LPCSTR)pfdin->pv, szExtractDir, CP_UTF8);
MultiByteToWide(pfdin->psz1, szCabFileName, CP_ACP);
if (szCabFileName.Find('\\') >= 0)
@ -203,7 +172,8 @@ FNFDINOTIFY(fnNotify)
DWORD dwErr = GetLastError();
if (dwErr != ERROR_ALREADY_EXISTS)
{
DPRINT1("ERROR: Unable to create directory %S (err %lu)\n", szNewDirName.GetString(), dwErr);
DPRINT1(
"ERROR: Unable to create directory %S (err %lu)\n", szNewDirName.GetString(), dwErr);
}
}
}
@ -215,9 +185,7 @@ FNFDINOTIFY(fnNotify)
WideToMultiByte(szNewFileName, szFilePathUTF8, CP_UTF8);
// Open the file
iResult = fnFileOpen((LPSTR) szFilePathUTF8.GetString(),
_O_WRONLY | _O_CREAT,
0);
iResult = fnFileOpen((LPSTR)szFilePathUTF8.GetString(), _O_WRONLY | _O_CREAT, 0);
}
break;
@ -254,33 +222,18 @@ FNFDINOTIFY(fnNotify)
/* cabinet.dll FDI function pointers */
typedef HFDI(*fnFDICreate)(PFNALLOC,
PFNFREE,
PFNOPEN,
PFNREAD,
PFNWRITE,
PFNCLOSE,
PFNSEEK,
int,
PERF);
typedef HFDI (*fnFDICreate)(PFNALLOC, PFNFREE, PFNOPEN, PFNREAD, PFNWRITE, PFNCLOSE, PFNSEEK, int, PERF);
typedef BOOL(*fnFDICopy)(HFDI,
LPSTR,
LPSTR,
INT,
PFNFDINOTIFY,
PFNFDIDECRYPT,
void FAR *pvUser);
typedef BOOL (*fnFDICopy)(HFDI, LPSTR, LPSTR, INT, PFNFDINOTIFY, PFNFDIDECRYPT, void FAR *pvUser);
typedef BOOL(*fnFDIDestroy)(HFDI);
typedef BOOL (*fnFDIDestroy)(HFDI);
/*
* Extraction function
* TODO: require only a full path to the cab as an argument
*/
BOOL ExtractFilesFromCab(const ATL::CStringW& szCabName,
const ATL::CStringW& szCabDir,
const ATL::CStringW& szOutputDir)
BOOL
ExtractFilesFromCab(const CStringW &szCabName, const CStringW &szCabDir, const CStringW &szOutputDir)
{
HINSTANCE hCabinetDll;
HFDI ExtractHandler;
@ -299,9 +252,9 @@ BOOL ExtractFilesFromCab(const ATL::CStringW& szCabName,
return FALSE;
}
pfnFDICreate = (fnFDICreate) GetProcAddress(hCabinetDll, "FDICreate");
pfnFDICopy = (fnFDICopy) GetProcAddress(hCabinetDll, "FDICopy");
pfnFDIDestroy = (fnFDIDestroy) GetProcAddress(hCabinetDll, "FDIDestroy");
pfnFDICreate = (fnFDICreate)GetProcAddress(hCabinetDll, "FDICreate");
pfnFDICopy = (fnFDICopy)GetProcAddress(hCabinetDll, "FDICopy");
pfnFDIDestroy = (fnFDIDestroy)GetProcAddress(hCabinetDll, "FDIDestroy");
if (!pfnFDICreate || !pfnFDICopy || !pfnFDIDestroy)
{
@ -310,14 +263,8 @@ BOOL ExtractFilesFromCab(const ATL::CStringW& szCabName,
}
// Create FDI context
ExtractHandler = pfnFDICreate(fnMemAlloc,
fnMemFree,
fnFileOpen,
fnFileRead,
fnFileWrite,
fnFileClose,
fnFileSeek,
cpuUNKNOWN,
ExtractHandler = pfnFDICreate(
fnMemAlloc, fnMemFree, fnFileOpen, fnFileRead, fnFileWrite, fnFileClose, fnFileSeek, cpuUNKNOWN,
&ExtractErrors);
if (!ExtractHandler)
@ -343,13 +290,9 @@ BOOL ExtractFilesFromCab(const ATL::CStringW& szCabName,
// Add a slash to cab name as required by the api
szCabNameUTF8 = "\\" + szCabNameUTF8;
bResult = pfnFDICopy(ExtractHandler,
(LPSTR) szCabNameUTF8.GetString(),
(LPSTR) szCabDirUTF8.GetString(),
0,
fnNotify,
NULL,
(void FAR *) szOutputDirUTF8.GetString());
bResult = pfnFDICopy(
ExtractHandler, (LPSTR)szCabNameUTF8.GetString(), (LPSTR)szCabDirUTF8.GetString(), 0, fnNotify, NULL,
(void FAR *)szOutputDirUTF8.GetString());
}
pfnFDIDestroy(ExtractHandler);

View file

@ -24,12 +24,11 @@ struct CSectionNames
};
static CSectionNames g_Names;
static
ATL::CStringW GetINIFullPath(const ATL::CStringW& FileName)
static CStringW
GetINIFullPath(const CStringW &FileName)
{
ATL::CStringW szDir;
ATL::CStringW szBuffer;
CStringW szDir;
CStringW szBuffer;
GetStorageDirectory(szDir);
szBuffer.Format(L"%ls\\rapps\\%ls", szDir.GetString(), FileName.GetString());
@ -37,13 +36,13 @@ ATL::CStringW GetINIFullPath(const ATL::CStringW& FileName)
return szBuffer;
}
CConfigParser::CConfigParser(const ATL::CStringW& FileName)
: szConfigPath(GetINIFullPath(FileName))
CConfigParser::CConfigParser(const CStringW &FileName) : szConfigPath(GetINIFullPath(FileName))
{
CacheINI();
}
void CConfigParser::ReadSection(ATL::CStringW& Buffer, const ATL::CStringW& Section, BOOL isArch)
void
CConfigParser::ReadSection(CStringW &Buffer, const CStringW &Section, BOOL isArch)
{
DWORD len = 512;
DWORD result;
@ -84,7 +83,7 @@ void CConfigParser::ReadSection(ATL::CStringW& Buffer, const ATL::CStringW& Sect
continue;
}
CString value = tmp.Mid(idx+1);
CString value = tmp.Mid(idx + 1);
m_Keys.Add(key, value);
}
else
@ -99,7 +98,8 @@ void CConfigParser::ReadSection(ATL::CStringW& Buffer, const ATL::CStringW& Sect
}
}
VOID CConfigParser::CacheINI()
VOID
CConfigParser::CacheINI()
{
// Cache section names
if (g_Names.ArchSpecific.Locale.IsEmpty())
@ -135,7 +135,6 @@ VOID CConfigParser::CacheINI()
}
ReadSection(Buffer, g_Names.ArchSpecific.Section, TRUE);
ReadSection(Buffer, g_Names.ArchNeutral.Locale, FALSE);
if (!g_Names.ArchNeutral.LocaleNeutral.IsEmpty())
{
@ -144,7 +143,8 @@ VOID CConfigParser::CacheINI()
ReadSection(Buffer, g_Names.ArchNeutral.Section, FALSE);
}
BOOL CConfigParser::GetString(const ATL::CStringW& KeyName, ATL::CStringW& ResultString)
BOOL
CConfigParser::GetString(const CStringW &KeyName, CStringW &ResultString)
{
int nIndex = m_Keys.FindKey(KeyName);
if (nIndex >= 0)
@ -157,9 +157,10 @@ BOOL CConfigParser::GetString(const ATL::CStringW& KeyName, ATL::CStringW& Resul
return FALSE;
}
BOOL CConfigParser::GetInt(const ATL::CStringW& KeyName, INT& iResult)
BOOL
CConfigParser::GetInt(const CStringW &KeyName, INT &iResult)
{
ATL::CStringW Buffer;
CStringW Buffer;
iResult = 0;

View file

@ -32,35 +32,29 @@
#define SEARCH_TIMER_ID 'SR'
#define TREEVIEW_ICON_SIZE 24
// **** CSideTreeView ****
CSideTreeView::CSideTreeView() :
CUiWindow(),
hImageTreeView(ImageList_Create(TREEVIEW_ICON_SIZE, TREEVIEW_ICON_SIZE,
GetSystemColorDepth() | ILC_MASK,
0, 1))
CSideTreeView::CSideTreeView()
: CUiWindow(),
hImageTreeView(ImageList_Create(TREEVIEW_ICON_SIZE, TREEVIEW_ICON_SIZE, GetSystemColorDepth() | ILC_MASK, 0, 1))
{
}
HTREEITEM CSideTreeView::AddItem(HTREEITEM hParent, ATL::CStringW &Text, INT Image, INT SelectedImage, LPARAM lParam)
HTREEITEM
CSideTreeView::AddItem(HTREEITEM hParent, CStringW &Text, INT Image, INT SelectedImage, LPARAM lParam)
{
return CUiWindow<CTreeView>::AddItem(hParent, const_cast<LPWSTR>(Text.GetString()), Image, SelectedImage, lParam);
}
HTREEITEM CSideTreeView::AddCategory(HTREEITEM hRootItem, UINT TextIndex, UINT IconIndex)
HTREEITEM
CSideTreeView::AddCategory(HTREEITEM hRootItem, UINT TextIndex, UINT IconIndex)
{
ATL::CStringW szText;
CStringW szText;
INT Index = 0;
HICON hIcon;
hIcon = (HICON)LoadImageW(hInst,
MAKEINTRESOURCE(IconIndex),
IMAGE_ICON,
TREEVIEW_ICON_SIZE,
TREEVIEW_ICON_SIZE,
LR_CREATEDIBSECTION);
hIcon = (HICON)LoadImageW(
hInst, MAKEINTRESOURCE(IconIndex), IMAGE_ICON, TREEVIEW_ICON_SIZE, TREEVIEW_ICON_SIZE, LR_CREATEDIBSECTION);
if (hIcon)
{
Index = ImageList_AddIcon(hImageTreeView, hIcon);
@ -71,12 +65,14 @@ HTREEITEM CSideTreeView::AddCategory(HTREEITEM hRootItem, UINT TextIndex, UINT I
return AddItem(hRootItem, szText, Index, Index, TextIndex);
}
HIMAGELIST CSideTreeView::SetImageList()
HIMAGELIST
CSideTreeView::SetImageList()
{
return CUiWindow<CTreeView>::SetImageList(hImageTreeView, TVSIL_NORMAL);
}
VOID CSideTreeView::DestroyImageList()
VOID
CSideTreeView::DestroyImageList()
{
if (hImageTreeView)
ImageList_Destroy(hImageTreeView);
@ -88,13 +84,9 @@ CSideTreeView::~CSideTreeView()
}
// **** CSideTreeView ****
// **** CMainWindow ****
CMainWindow::CMainWindow() :
m_ClientPanel(NULL),
SelectedEnumType(ENUM_ALL_INSTALLED)
CMainWindow::CMainWindow(CApplicationDB *db) : m_ClientPanel(NULL), m_Db(db), SelectedEnumType(ENUM_ALL_INSTALLED)
{
}
@ -103,7 +95,8 @@ CMainWindow::~CMainWindow()
LayoutCleanup();
}
VOID CMainWindow::InitCategoriesList()
VOID
CMainWindow::InitCategoriesList()
{
HTREEITEM hRootItemInstalled, hRootItemAvailable;
@ -137,7 +130,8 @@ VOID CMainWindow::InitCategoriesList()
m_TreeView->SelectItem(hRootItemAvailable);
}
BOOL CMainWindow::CreateStatusBar()
BOOL
CMainWindow::CreateStatusBar()
{
m_StatusBar = new CUiWindow<CStatusBar>();
m_StatusBar->m_VerticalAlignment = UiAlign_RightBtm;
@ -147,7 +141,8 @@ BOOL CMainWindow::CreateStatusBar()
return m_StatusBar->Create(m_hWnd, (HMENU)IDC_STATUSBAR) != NULL;
}
BOOL CMainWindow::CreateTreeView()
BOOL
CMainWindow::CreateTreeView()
{
m_TreeView = new CSideTreeView();
m_TreeView->m_VerticalAlignment = UiAlign_Stretch;
@ -157,7 +152,8 @@ BOOL CMainWindow::CreateTreeView()
return m_TreeView->Create(m_hWnd) != NULL;
}
BOOL CMainWindow::CreateApplicationView()
BOOL
CMainWindow::CreateApplicationView()
{
m_ApplicationView = new CApplicationView(this); // pass this to ApplicationView for callback purpose
m_ApplicationView->m_VerticalAlignment = UiAlign_Stretch;
@ -167,7 +163,8 @@ BOOL CMainWindow::CreateApplicationView()
return m_ApplicationView->Create(m_hWnd) != NULL;
}
BOOL CMainWindow::CreateVSplitter()
BOOL
CMainWindow::CreateVSplitter()
{
m_VSplitter = new CUiSplitPanel();
m_VSplitter->m_VerticalAlignment = UiAlign_Stretch;
@ -184,7 +181,8 @@ BOOL CMainWindow::CreateVSplitter()
return m_VSplitter->Create(m_hWnd) != NULL;
}
BOOL CMainWindow::CreateLayout()
BOOL
CMainWindow::CreateLayout()
{
BOOL b = TRUE;
bUpdating = TRUE;
@ -217,7 +215,8 @@ BOOL CMainWindow::CreateLayout()
return b;
}
VOID CMainWindow::LayoutCleanup()
VOID
CMainWindow::LayoutCleanup()
{
delete m_TreeView;
delete m_ApplicationView;
@ -226,12 +225,12 @@ VOID CMainWindow::LayoutCleanup()
return;
}
BOOL CMainWindow::InitControls()
BOOL
CMainWindow::InitControls()
{
if (CreateLayout())
{
InitCategoriesList();
UpdateStatusBarText();
return TRUE;
@ -240,7 +239,8 @@ BOOL CMainWindow::InitControls()
return FALSE;
}
VOID CMainWindow::OnSize(HWND hwnd, WPARAM wParam, LPARAM lParam)
VOID
CMainWindow::OnSize(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
if (wParam == SIZE_MINIMIZED)
return;
@ -248,8 +248,7 @@ VOID CMainWindow::OnSize(HWND hwnd, WPARAM wParam, LPARAM lParam)
/* Size status bar */
m_StatusBar->SendMessage(WM_SIZE, 0, 0);
RECT r = { 0, 0, LOWORD(lParam), HIWORD(lParam) };
RECT r = {0, 0, LOWORD(lParam), HIWORD(lParam)};
HDWP hdwp = NULL;
INT count = m_ClientPanel->CountSizableChildren();
@ -264,51 +263,44 @@ VOID CMainWindow::OnSize(HWND hwnd, WPARAM wParam, LPARAM lParam)
}
}
BOOL CMainWindow::RemoveSelectedAppFromRegistry()
BOOL
CMainWindow::RemoveSelectedAppFromRegistry()
{
if (!IsInstalledEnum(SelectedEnumType))
return FALSE;
ATL::CStringW szMsgText, szMsgTitle;
CStringW szMsgText, szMsgTitle;
if (!szMsgText.LoadStringW(IDS_APP_REG_REMOVE) ||
!szMsgTitle.LoadStringW(IDS_INFORMATION))
if (!szMsgText.LoadStringW(IDS_APP_REG_REMOVE) || !szMsgTitle.LoadStringW(IDS_INFORMATION))
return FALSE;
if (MessageBoxW(szMsgText, szMsgTitle, MB_YESNO | MB_ICONQUESTION) == IDYES)
{
CInstalledApplicationInfo *InstalledApp = (CInstalledApplicationInfo *)m_ApplicationView->GetFocusedItemData();
CApplicationInfo *InstalledApp = (CApplicationInfo *)m_ApplicationView->GetFocusedItemData();
if (!InstalledApp)
return FALSE;
LSTATUS Result = InstalledApp->RemoveFromRegistry();
if (Result != ERROR_SUCCESS)
{
// TODO: popup a messagebox telling user it fails somehow
return FALSE;
}
// as it's already removed form registry, this will also remove it from the list
UpdateApplicationsList(-1);
return TRUE;
return m_Db->RemoveInstalledAppFromRegistry(InstalledApp);
}
return FALSE;
}
BOOL CMainWindow::UninstallSelectedApp(BOOL bModify)
BOOL
CMainWindow::UninstallSelectedApp(BOOL bModify)
{
if (!IsInstalledEnum(SelectedEnumType))
return FALSE;
CInstalledApplicationInfo *InstalledApp = (CInstalledApplicationInfo *)m_ApplicationView->GetFocusedItemData();
CApplicationInfo *InstalledApp = (CApplicationInfo *)m_ApplicationView->GetFocusedItemData();
if (!InstalledApp)
return FALSE;
return InstalledApp->UninstallApplication(bModify);
}
BOOL CMainWindow::ProcessWindowMessage(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT &theResult, DWORD dwMapId)
BOOL
CMainWindow::ProcessWindowMessage(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT &theResult, DWORD dwMapId)
{
theResult = 0;
switch (Msg)
@ -324,8 +316,6 @@ BOOL CMainWindow::ProcessWindowMessage(HWND hwnd, UINT Msg, WPARAM wParam, LPARA
SaveSettings(hwnd, &SettingsInfo);
FreeLogs();
m_AvailableApps.FreeCachedEntries();
m_InstalledApps.FreeCachedEntries();
delete m_ClientPanel;
@ -434,27 +424,8 @@ BOOL CMainWindow::ProcessWindowMessage(HWND hwnd, UINT Msg, WPARAM wParam, LPARA
break;
}
}
HMENU mainMenu = ::GetMenu(hwnd);
/* Disable/enable items based on treeview selection */
if (IsSelectedNodeInstalled())
{
EnableMenuItem(mainMenu, ID_REGREMOVE, MF_ENABLED);
EnableMenuItem(mainMenu, ID_INSTALL, MF_GRAYED);
EnableMenuItem(mainMenu, ID_UNINSTALL, MF_ENABLED);
EnableMenuItem(mainMenu, ID_MODIFY, MF_ENABLED);
}
else
{
EnableMenuItem(mainMenu, ID_REGREMOVE, MF_GRAYED);
EnableMenuItem(mainMenu, ID_INSTALL, MF_ENABLED);
EnableMenuItem(mainMenu, ID_UNINSTALL, MF_GRAYED);
EnableMenuItem(mainMenu, ID_MODIFY, MF_GRAYED);
}
}
break;
}
}
break;
@ -489,7 +460,7 @@ BOOL CMainWindow::ProcessWindowMessage(HWND hwnd, UINT Msg, WPARAM wParam, LPARA
{
::KillTimer(hwnd, SEARCH_TIMER_ID);
UpdateApplicationsList(-1);
UpdateApplicationsList(SelectedEnumType);
}
break;
}
@ -497,29 +468,11 @@ BOOL CMainWindow::ProcessWindowMessage(HWND hwnd, UINT Msg, WPARAM wParam, LPARA
return FALSE;
}
BOOL CMainWindow::IsSelectedNodeInstalled()
VOID
CMainWindow::ShowAboutDlg()
{
HTREEITEM hSelectedItem = m_TreeView->GetSelection();
TV_ITEM tItem;
tItem.mask = TVIF_PARAM | TVIF_HANDLE;
tItem.hItem = hSelectedItem;
m_TreeView->GetItem(&tItem);
switch (tItem.lParam)
{
case IDS_INSTALLED:
case IDS_APPLICATIONS:
case IDS_UPDATES:
return TRUE;
default:
return FALSE;
}
}
VOID CMainWindow::ShowAboutDlg()
{
ATL::CStringW szApp;
ATL::CStringW szAuthors;
CStringW szApp;
CStringW szAuthors;
HICON hIcon;
szApp.LoadStringW(IDS_APPTITLE);
@ -529,8 +482,10 @@ VOID CMainWindow::ShowAboutDlg()
DestroyIcon(hIcon);
}
VOID CMainWindow::OnCommand(WPARAM wParam, LPARAM lParam)
VOID
CMainWindow::OnCommand(WPARAM wParam, LPARAM lParam)
{
const BOOL bReload = TRUE;
WORD wCommand = LOWORD(wParam);
if (!lParam)
@ -552,34 +507,20 @@ VOID CMainWindow::OnCommand(WPARAM wParam, LPARAM lParam)
case ID_INSTALL:
if (IsAvailableEnum(SelectedEnumType))
{
ATL::CSimpleArray<CAvailableApplicationInfo> AppsList;
// enum all selected apps
m_AvailableApps.Enum(ENUM_CAT_SELECTED, s_EnumSelectedAppForDownloadProc, (PVOID)&AppsList);
if (AppsList.GetSize())
if (!m_Selected.IsEmpty())
{
if (DownloadListOfApplications(AppsList, FALSE))
if (DownloadListOfApplications(m_Selected, FALSE))
{
m_AvailableApps.RemoveAllSelected();
UpdateApplicationsList(-1);
m_Selected.RemoveAll();
UpdateApplicationsList(SelectedEnumType);
}
}
else
{
// use the currently focused item in application-view
CAvailableApplicationInfo *FocusedApps = (CAvailableApplicationInfo *)m_ApplicationView->GetFocusedItemData();
if (FocusedApps)
CApplicationInfo *App = (CApplicationInfo *)m_ApplicationView->GetFocusedItemData();
if (App)
{
if (DownloadApplication(FocusedApps))
{
UpdateApplicationsList(-1);
}
}
else
{
// TODO: in this case, Install button in toolbar (and all other places) should be disabled
// or at least popup a messagebox telling user to select/check some app first
InstallApplication(App);
}
}
}
@ -587,25 +528,26 @@ VOID CMainWindow::OnCommand(WPARAM wParam, LPARAM lParam)
case ID_UNINSTALL:
if (UninstallSelectedApp(FALSE))
UpdateApplicationsList(-1);
UpdateApplicationsList(SelectedEnumType, bReload);
break;
case ID_MODIFY:
if (UninstallSelectedApp(TRUE))
UpdateApplicationsList(-1);
UpdateApplicationsList(SelectedEnumType, bReload);
break;
case ID_REGREMOVE:
RemoveSelectedAppFromRegistry();
if (RemoveSelectedAppFromRegistry())
UpdateApplicationsList(SelectedEnumType, bReload);
break;
case ID_REFRESH:
UpdateApplicationsList(-1);
UpdateApplicationsList(SelectedEnumType);
break;
case ID_RESETDB:
CAvailableApps::ForceUpdateAppsDB();
UpdateApplicationsList(-1);
m_Db->RemoveCached();
UpdateApplicationsList(SelectedEnumType, bReload);
break;
case ID_HELP:
@ -623,85 +565,81 @@ VOID CMainWindow::OnCommand(WPARAM wParam, LPARAM lParam)
}
}
BOOL CALLBACK CMainWindow::EnumInstalledAppProc(CInstalledApplicationInfo *Info)
{
if (!SearchPatternMatch(Info->szDisplayName.GetString(), szSearchPattern))
{
return TRUE;
}
return m_ApplicationView->AddInstalledApplication(Info, Info); // currently, the callback param is Info itself
}
BOOL CALLBACK CMainWindow::EnumAvailableAppProc(CAvailableApplicationInfo *Info, BOOL bInitialCheckState)
{
if (!SearchPatternMatch(Info->m_szName.GetString(), szSearchPattern) &&
!SearchPatternMatch(Info->m_szDesc.GetString(), szSearchPattern))
{
return TRUE;
}
return m_ApplicationView->AddAvailableApplication(Info, bInitialCheckState, Info); // currently, the callback param is Info itself
}
BOOL CALLBACK CMainWindow::s_EnumInstalledAppProc(CInstalledApplicationInfo *Info, PVOID param)
{
CMainWindow *pThis = (CMainWindow *)param;
return pThis->EnumInstalledAppProc(Info);
}
BOOL CALLBACK CMainWindow::s_EnumAvailableAppProc(CAvailableApplicationInfo *Info, BOOL bInitialCheckState, PVOID param)
{
CMainWindow *pThis = (CMainWindow *)param;
return pThis->EnumAvailableAppProc(Info, bInitialCheckState);
}
BOOL CALLBACK CMainWindow::s_EnumSelectedAppForDownloadProc(CAvailableApplicationInfo *Info, BOOL bInitialCheckState, PVOID param)
{
ATL::CSimpleArray<CAvailableApplicationInfo> *pAppList = (ATL::CSimpleArray<CAvailableApplicationInfo> *)param;
pAppList->Add(*Info);
return TRUE;
}
VOID CMainWindow::UpdateStatusBarText()
VOID
CMainWindow::UpdateStatusBarText()
{
if (m_StatusBar)
{
ATL::CStringW szBuffer;
CStringW szBuffer;
szBuffer.Format(IDS_APPS_COUNT, m_ApplicationView->GetItemCount(), m_AvailableApps.GetSelectedCount());
szBuffer.Format(IDS_APPS_COUNT, m_ApplicationView->GetItemCount(), m_Selected.GetCount());
m_StatusBar->SetText(szBuffer);
}
}
VOID CMainWindow::UpdateApplicationsList(INT EnumType)
VOID
CMainWindow::AddApplicationsToView(CAtlList<CApplicationInfo *> &List)
{
POSITION CurrentListPosition = List.GetHeadPosition();
while (CurrentListPosition)
{
CApplicationInfo *Info = List.GetNext(CurrentListPosition);
if (szSearchPattern.IsEmpty() || SearchPatternMatch(Info->szDisplayName, szSearchPattern) ||
SearchPatternMatch(Info->szComments, szSearchPattern))
{
BOOL bSelected = m_Selected.Find(Info) != NULL;
m_ApplicationView->AddApplication(Info, bSelected);
}
}
}
VOID
CMainWindow::UpdateApplicationsList(AppsCategories EnumType, BOOL bReload)
{
bUpdating = TRUE;
if (EnumType == -1)
{
// keep the old enum type
EnumType = SelectedEnumType;
}
else
{
if (SelectedEnumType != EnumType)
SelectedEnumType = EnumType;
}
if (bReload)
m_Selected.RemoveAll();
m_ApplicationView->SetRedraw(FALSE);
if (IsInstalledEnum(EnumType))
{
if (bReload)
m_Db->UpdateInstalled();
// set the display type of application-view. this will remove all the item in application-view too.
m_ApplicationView->SetDisplayAppType(AppViewTypeInstalledApps);
// enum installed softwares
m_InstalledApps.Enum(EnumType, s_EnumInstalledAppProc, this);
CAtlList<CApplicationInfo *> List;
m_Db->GetApps(List, EnumType);
AddApplicationsToView(List);
}
else if (IsAvailableEnum(EnumType))
{
if (bReload)
m_Db->UpdateAvailable();
// set the display type of application-view. this will remove all the item in application-view too.
m_ApplicationView->SetDisplayAppType(AppViewTypeAvailableApps);
// enum available softwares
m_AvailableApps.Enum(EnumType, s_EnumAvailableAppProc, this);
if (EnumType == ENUM_CAT_SELECTED)
{
AddApplicationsToView(m_Selected);
}
else
{
CAtlList<CApplicationInfo *> List;
m_Db->GetApps(List, EnumType);
AddApplicationsToView(List);
}
}
else
{
ATLASSERT(0 && "This should be unreachable!");
}
m_ApplicationView->SetRedraw(TRUE);
m_ApplicationView->RedrawWindow(0, 0, RDW_INVALIDATE | RDW_ALLCHILDREN); // force the child window to repaint
@ -717,111 +655,87 @@ VOID CMainWindow::UpdateApplicationsList(INT EnumType)
bUpdating = FALSE;
}
ATL::CWndClassInfo &CMainWindow::GetWndClassInfo()
ATL::CWndClassInfo &
CMainWindow::GetWndClassInfo()
{
DWORD csStyle = CS_VREDRAW | CS_HREDRAW;
static ATL::CWndClassInfo wc =
{
{
sizeof(WNDCLASSEX),
csStyle,
StartWindowProc,
0,
0,
static ATL::CWndClassInfo wc = {
{sizeof(WNDCLASSEX), csStyle, StartWindowProc, 0, 0, NULL,
LoadIconW(_AtlBaseModule.GetModuleInstance(), MAKEINTRESOURCEW(IDI_MAIN)), LoadCursorW(NULL, IDC_ARROW),
(HBRUSH)(COLOR_BTNFACE + 1), MAKEINTRESOURCEW(IDR_MAINMENU), szWindowClass, NULL},
NULL,
LoadIconW(_AtlBaseModule.GetModuleInstance(), MAKEINTRESOURCEW(IDI_MAIN)),
LoadCursorW(NULL, IDC_ARROW),
(HBRUSH)(COLOR_BTNFACE + 1),
MAKEINTRESOURCEW(IDR_MAINMENU),
szWindowClass,
NULL
},
NULL, NULL, IDC_ARROW, TRUE, 0, _T("")
};
NULL,
IDC_ARROW,
TRUE,
0,
_T("")};
return wc;
}
HWND CMainWindow::Create()
HWND
CMainWindow::Create()
{
ATL::CStringW szWindowName;
CStringW szWindowName;
szWindowName.LoadStringW(IDS_APPTITLE);
RECT r = {
(SettingsInfo.bSaveWndPos ? SettingsInfo.Left : CW_USEDEFAULT),
(SettingsInfo.bSaveWndPos ? SettingsInfo.Top : CW_USEDEFAULT),
(SettingsInfo.bSaveWndPos ? SettingsInfo.Width : 680),
(SettingsInfo.bSaveWndPos ? SettingsInfo.Height : 450)
};
(SettingsInfo.bSaveWndPos ? SettingsInfo.Width : 680), (SettingsInfo.bSaveWndPos ? SettingsInfo.Height : 450)};
r.right += r.left;
r.bottom += r.top;
return CWindowImpl::Create(NULL, r, szWindowName.GetString(), WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
return CWindowImpl::Create(
NULL, r, szWindowName.GetString(), WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE);
}
// this function is called when a item of application-view is checked/unchecked
// CallbackParam is the param passed to application-view when adding the item (the one getting focus now).
BOOL CMainWindow::ItemCheckStateChanged(BOOL bChecked, LPVOID CallbackParam)
VOID
CMainWindow::ItemCheckStateChanged(BOOL bChecked, LPVOID CallbackParam)
{
if (!bUpdating)
{
if (bUpdating)
return;
CApplicationInfo *Info = (CApplicationInfo *)CallbackParam;
if (bChecked)
{
if (!m_AvailableApps.AddSelected((CAvailableApplicationInfo *)CallbackParam))
{
return FALSE;
}
m_Selected.AddTail(Info);
}
else
{
if (!m_AvailableApps.RemoveSelected((CAvailableApplicationInfo *)CallbackParam))
POSITION Pos = m_Selected.Find(Info);
ATLASSERT(Pos != NULL);
if (Pos != NULL)
{
return FALSE;
m_Selected.RemoveAt(Pos);
}
}
UpdateStatusBarText();
return TRUE;
}
else
{
return TRUE;
}
}
// this function is called when one or more application(s) should be installed install
// this function is called when one or more application(s) should be installed
// if Info is not zero, this app should be installed. otherwise those checked apps should be installed
BOOL CMainWindow::InstallApplication(CAvailableApplicationInfo *Info)
BOOL
CMainWindow::InstallApplication(CApplicationInfo *Info)
{
if (Info)
{
if (DownloadApplication(Info))
{
UpdateApplicationsList(-1);
UpdateApplicationsList(SelectedEnumType);
return TRUE;
}
}
else
{
ATL::CSimpleArray<CAvailableApplicationInfo> AppsList;
// enum all selected apps
m_AvailableApps.Enum(ENUM_CAT_SELECTED, s_EnumSelectedAppForDownloadProc, (PVOID)&AppsList);
if (AppsList.GetSize())
{
if (DownloadListOfApplications(AppsList, FALSE))
{
m_AvailableApps.RemoveAllSelected();
UpdateApplicationsList(-1);
return TRUE;
}
}
}
return FALSE;
}
BOOL CMainWindow::SearchTextChanged(ATL::CStringW &SearchText)
BOOL
CMainWindow::SearchTextChanged(CStringW &SearchText)
{
if (szSearchPattern == SearchText)
{
@ -830,21 +744,21 @@ BOOL CMainWindow::SearchTextChanged(ATL::CStringW &SearchText)
szSearchPattern = SearchText;
DWORD dwDelay;
DWORD dwDelay = 0;
SystemParametersInfoW(SPI_GETMENUSHOWDELAY, 0, &dwDelay, 0);
SetTimer(SEARCH_TIMER_ID, dwDelay);
return TRUE;
}
void CMainWindow::HandleTabOrder(int direction)
void
CMainWindow::HandleTabOrder(int direction)
{
ATL::CSimpleArray<HWND> TabOrderHwndList;
m_TreeView->AppendTabOrderWindow(direction, TabOrderHwndList);
m_ApplicationView->AppendTabOrderWindow(direction, TabOrderHwndList);
if (TabOrderHwndList.GetSize() == 0)
{
// in case the list is empty
@ -860,7 +774,8 @@ void CMainWindow::HandleTabOrder(int direction)
else
{
FocusIndex += direction;
FocusIndex += TabOrderHwndList.GetSize(); // FocusIndex might be negative. we don't want to mod a negative number
FocusIndex +=
TabOrderHwndList.GetSize(); // FocusIndex might be negative. we don't want to mod a negative number
FocusIndex %= TabOrderHwndList.GetSize();
}
@ -869,14 +784,13 @@ void CMainWindow::HandleTabOrder(int direction)
}
// **** CMainWindow ****
VOID MainWindowLoop(INT nShowCmd)
VOID
MainWindowLoop(CApplicationDB *db, INT nShowCmd)
{
HACCEL KeyBrd;
MSG Msg;
CMainWindow* wnd = new CMainWindow();
CMainWindow *wnd = new CMainWindow(db);
if (!wnd)
return;
@ -896,8 +810,7 @@ VOID MainWindowLoop(INT nShowCmd)
{
if (!TranslateAcceleratorW(hMainWnd, KeyBrd, &Msg))
{
if (Msg.message == WM_CHAR &&
Msg.wParam == VK_TAB)
if (Msg.message == WM_CHAR && Msg.wParam == VK_TAB)
{
// Move backwards if shift is held down
int direction = (GetKeyState(VK_SHIFT) & 0x8000) ? -1 : 1;

View file

@ -0,0 +1,35 @@
#pragma once
#include <atlcoll.h>
#include <atlpath.h>
#include "applicationinfo.h"
class CApplicationDB
{
private:
CPathW m_BasePath;
CAtlList<CApplicationInfo *> m_Available;
CAtlList<CApplicationInfo *> m_Installed;
BOOL
EnumerateFiles();
public:
CApplicationDB(const CStringW &path);
VOID
GetApps(CAtlList<CApplicationInfo *> &List, AppsCategories Type) const;
CApplicationInfo *
FindByPackageName(const CStringW &name);
VOID
UpdateAvailable();
VOID
UpdateInstalled();
VOID
RemoveCached();
BOOL
RemoveInstalledAppFromRegistry(const CApplicationInfo *Info);
};

View file

@ -0,0 +1,186 @@
#pragma once
#include <atlstr.h>
#include <atlpath.h>
#include <atlsimpcoll.h>
enum LicenseType
{
LICENSE_NONE,
LICENSE_OPENSOURCE,
LICENSE_FREEWARE,
LICENSE_TRIAL,
LICENSE_MIN = LICENSE_NONE,
LICENSE_MAX = LICENSE_TRIAL
};
inline BOOL
IsLicenseType(INT x)
{
return (x >= LICENSE_MIN && x <= LICENSE_MAX);
}
enum AppsCategories
{
ENUM_ALL_AVAILABLE,
ENUM_CAT_AUDIO,
ENUM_CAT_VIDEO,
ENUM_CAT_GRAPHICS,
ENUM_CAT_GAMES,
ENUM_CAT_INTERNET,
ENUM_CAT_OFFICE,
ENUM_CAT_DEVEL,
ENUM_CAT_EDU,
ENUM_CAT_ENGINEER,
ENUM_CAT_FINANCE,
ENUM_CAT_SCIENCE,
ENUM_CAT_TOOLS,
ENUM_CAT_DRIVERS,
ENUM_CAT_LIBS,
ENUM_CAT_THEMES,
ENUM_CAT_OTHER,
ENUM_CAT_SELECTED,
ENUM_ALL_INSTALLED = 30,
ENUM_INSTALLED_APPLICATIONS,
ENUM_UPDATES,
ENUM_INVALID,
ENUM_INSTALLED_MIN = ENUM_ALL_INSTALLED,
ENUM_INSTALLED_MAX = ENUM_UPDATES,
ENUM_AVAILABLE_MIN = ENUM_ALL_AVAILABLE,
ENUM_AVAILABLE_MAX = ENUM_CAT_SELECTED,
};
inline BOOL
IsAvailableEnum(INT x)
{
return (x >= ENUM_AVAILABLE_MIN && x <= ENUM_AVAILABLE_MAX);
}
inline BOOL
IsInstalledEnum(INT x)
{
return (x >= ENUM_INSTALLED_MIN && x <= ENUM_INSTALLED_MAX);
}
class CAppRichEdit;
class CApplicationInfo
{
public:
CApplicationInfo(const CStringW &Identifier, AppsCategories Category);
virtual ~CApplicationInfo();
const CStringW szIdentifier; // PkgName or KeyName
const AppsCategories iCategory;
CStringW szDisplayIcon;
CStringW szDisplayName;
CStringW szDisplayVersion;
CStringW szComments;
virtual BOOL
Valid() const = 0;
virtual BOOL
CanModify() = 0;
virtual BOOL
RetrieveIcon(CStringW &Path) const = 0;
virtual BOOL
RetrieveScreenshot(CStringW &Path) = 0;
virtual VOID
ShowAppInfo(CAppRichEdit *RichEdit) = 0;
virtual VOID
GetDownloadInfo(CStringW &Url, CStringW &Sha1, ULONG &SizeInBytes) const = 0;
virtual VOID
GetDisplayInfo(CStringW &License, CStringW &Size, CStringW &UrlSite, CStringW &UrlDownload) = 0;
virtual BOOL
UninstallApplication(BOOL bModify) = 0;
};
class CAvailableApplicationInfo : public CApplicationInfo
{
class CConfigParser *m_Parser;
CSimpleArray<CStringW> m_szScrnshotLocation;
bool m_ScrnshotRetrieved;
CStringW m_szUrlDownload;
CStringW m_szSize;
CStringW m_szUrlSite;
CSimpleArray<LCID> m_LanguageLCIDs;
bool m_LanguagesLoaded;
VOID
InsertVersionInfo(CAppRichEdit *RichEdit);
VOID
InsertLanguageInfo(CAppRichEdit *RichEdit);
VOID
RetrieveLanguages();
CStringW
LicenseString();
public:
CAvailableApplicationInfo(
CConfigParser *Parser,
const CStringW &PkgName,
AppsCategories Category,
const CPathW &BasePath);
~CAvailableApplicationInfo();
virtual BOOL
Valid() const override;
virtual BOOL
CanModify() override;
virtual BOOL
RetrieveIcon(CStringW &Path) const override;
virtual BOOL
RetrieveScreenshot(CStringW &Path) override;
virtual VOID
ShowAppInfo(CAppRichEdit *RichEdit) override;
virtual VOID
GetDownloadInfo(CStringW &Url, CStringW &Sha1, ULONG &SizeInBytes) const override;
virtual VOID
GetDisplayInfo(CStringW &License, CStringW &Size, CStringW &UrlSite, CStringW &UrlDownload) override;
virtual BOOL
UninstallApplication(BOOL bModify) override;
};
class CInstalledApplicationInfo : public CApplicationInfo
{
CRegKey m_hKey;
CStringW m_szInstallDate;
CStringW m_szUninstallString;
CStringW m_szModifyString;
BOOL
GetApplicationRegString(LPCWSTR lpKeyName, CStringW &String);
BOOL
GetApplicationRegDword(LPCWSTR lpKeyName, DWORD *lpValue);
VOID
AddApplicationRegString(CAppRichEdit *RichEdit, UINT StringID, const CStringW &String, DWORD TextFlags);
VOID
RetrieveInstallDate();
VOID
RetrieveUninstallStrings();
public:
const int iKeyIndex;
CInstalledApplicationInfo(HKEY Key, const CStringW &KeyName, AppsCategories Category, int KeyIndex);
~CInstalledApplicationInfo();
virtual BOOL
Valid() const override;
virtual BOOL
CanModify() override;
virtual BOOL
RetrieveIcon(CStringW &Path) const override;
virtual BOOL
RetrieveScreenshot(CStringW &Path) override;
virtual VOID
ShowAppInfo(CAppRichEdit *RichEdit) override;
virtual VOID
GetDownloadInfo(CStringW &Url, CStringW &Sha1, ULONG &SizeInBytes) const override;
virtual VOID
GetDisplayInfo(CStringW &License, CStringW &Size, CStringW &UrlSite, CStringW &UrlDownload) override;
virtual BOOL
UninstallApplication(BOOL bModify) override;
};

View file

@ -18,7 +18,6 @@
#include <gdiplus.h>
#include <math.h>
using namespace Gdiplus;
#define LISTVIEW_ICON_SIZE 32
@ -38,7 +37,8 @@ using namespace Gdiplus;
#define TOOLBAR_PADDING 6
// user-defined window message
#define WM_RAPPS_DOWNLOAD_COMPLETE (WM_USER + 1) // notify download complete. wParam is error code, and lParam is a pointer to ScrnshotDownloadParam
#define WM_RAPPS_DOWNLOAD_COMPLETE \
(WM_USER + 1) // notify download complete. wParam is error code, and lParam is a pointer to ScrnshotDownloadParam
#define WM_RAPPS_RESIZE_CHILDREN (WM_USER + 2) // ask parent window to resize children.
enum SCRNSHOT_STATUS
@ -54,14 +54,13 @@ enum SCRNSHOT_STATUS
#define LOADING_ANIMATION_PERIOD 3 // Animation cycling period (in seconds)
#define LOADING_ANIMATION_FPS 18 // Animation Frame Per Second
#define PI 3.1415927
// retrieve the value using a mask
#define STATEIMAGETOINDEX(x) (((x) & LVIS_STATEIMAGEMASK) >> 12)
#define STATEIMAGETOINDEX(x) (((x)&LVIS_STATEIMAGEMASK) >> 12)
// for listview with extend style LVS_EX_CHECKBOXES, State image 1 is the unchecked box, and state image 2 is the checked box.
// see this: https://docs.microsoft.com/en-us/windows/win32/controls/extended-list-view-styles
// for listview with extend style LVS_EX_CHECKBOXES, State image 1 is the unchecked box, and state image 2 is the
// checked box. see this: https://docs.microsoft.com/en-us/windows/win32/controls/extended-list-view-styles
#define STATEIMAGE_UNCHECKED 1
#define STATEIMAGE_CHECKED 2
@ -69,7 +68,6 @@ class CMainWindow;
enum APPLICATION_VIEW_TYPE
{
AppViewTypeEmpty,
AppViewTypeAvailableApps,
AppViewTypeInstalledApps
};
@ -79,129 +77,116 @@ typedef struct __ScrnshotDownloadParam
LONGLONG ID;
HANDLE hFile;
HWND hwndNotify;
ATL::CStringW DownloadFileName;
CStringW DownloadFileName;
} ScrnshotDownloadParam;
class CAppRichEdit :
public CUiWindow<CRichEdit>
class CAppRichEdit : public CUiWindow<CRichEdit>
{
private:
VOID LoadAndInsertText(UINT uStringID,
const ATL::CStringW &szText,
DWORD StringFlags,
DWORD TextFlags);
VOID LoadAndInsertText(UINT uStringID,
DWORD StringFlags);
VOID InsertVersionInfo(CAvailableApplicationInfo *Info);
VOID InsertLicenseInfo(CAvailableApplicationInfo *Info);
VOID InsertLanguageInfo(CAvailableApplicationInfo *Info);
public:
BOOL ShowAvailableAppInfo(CAvailableApplicationInfo *Info);
inline VOID InsertTextWithString(UINT StringID, DWORD StringFlags, const ATL::CStringW &Text, DWORD TextFlags);
BOOL ShowInstalledAppInfo(CInstalledApplicationInfo *Info);
VOID SetWelcomeText();
public:
VOID
LoadAndInsertText(UINT uStringID, const CStringW &szText, DWORD TextFlags);
VOID
LoadAndInsertText(UINT uStringID, DWORD StringFlags);
VOID
InsertTextWithString(UINT StringID, const CStringW &Text, DWORD TextFlags);
VOID
SetWelcomeText();
};
int ScrnshotDownloadCallback(
pASYNCINET AsyncInet,
ASYNC_EVENT Event,
WPARAM wParam,
LPARAM lParam,
VOID *Extension
);
int
ScrnshotDownloadCallback(pASYNCINET AsyncInet, ASYNC_EVENT Event, WPARAM wParam, LPARAM lParam, VOID *Extension);
class CAppScrnshotPreview :
public CWindowImpl<CAppScrnshotPreview>
class CAppScrnshotPreview : public CWindowImpl<CAppScrnshotPreview>
{
private:
private:
CStringW m_BasePath;
SCRNSHOT_STATUS ScrnshotPrevStauts = SCRNSHOT_PREV_EMPTY;
Image *pImage = NULL;
Gdiplus::Image *pImage = NULL;
HICON hBrokenImgIcon = NULL;
BOOL bLoadingTimerOn = FALSE;
int LoadingAnimationFrame = 0;
int BrokenImgSize = BROKENIMG_ICON_SIZE;
pASYNCINET AsyncInet = NULL;
LONGLONG ContentID = 0; // used to determine whether image has been switched when download complete. Increase by 1 each time the content of this window changed
ATL::CStringW TempImagePath; // currently displayed temp file
LONGLONG ContentID = 0; // used to determine whether image has been switched when download complete. Increase by 1
// each time the content of this window changed
CStringW TempImagePath; // currently displayed temp file
BOOL ProcessWindowMessage(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT &theResult, DWORD dwMapId);
BOOL
ProcessWindowMessage(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT &theResult, DWORD dwMapId);
VOID DisplayLoading();
VOID
DisplayLoading();
VOID
DisplayFailed();
BOOL
DisplayFile(LPCWSTR lpszFileName);
VOID
SetStatus(SCRNSHOT_STATUS Status);
VOID DisplayFailed();
VOID
PaintOnDC(HDC hdc, int width, int height, BOOL bDrawBkgnd);
float
GetLoadingDotWidth(int width, int height);
float
GetFrameDotShift(int Frame, int width, int height);
BOOL DisplayFile(LPCWSTR lpszFileName);
public:
static ATL::CWndClassInfo &
GetWndClassInfo();
VOID SetStatus(SCRNSHOT_STATUS Status);
VOID PaintOnDC(HDC hdc, int width, int height, BOOL bDrawBkgnd);
float GetLoadingDotWidth(int width, int height);
float GetFrameDotShift(int Frame, int width, int height);
public:
static ATL::CWndClassInfo &GetWndClassInfo();
HWND Create(HWND hParent);
VOID PreviousDisplayCleanup();
VOID DisplayEmpty();
BOOL DisplayImage(LPCWSTR lpszLocation);
HWND
Create(HWND hParent);
VOID
PreviousDisplayCleanup();
VOID
DisplayEmpty();
BOOL
DisplayImage(LPCWSTR lpszLocation);
// calculate requested window width by given height
int GetRequestedWidth(int Height);
int
GetRequestedWidth(int Height);
CAppScrnshotPreview(const CStringW &BasePath);
~CAppScrnshotPreview();
};
class CAppInfoDisplay :
public CUiWindow<CWindowImpl<CAppInfoDisplay>>
class CAppInfoDisplay : public CUiWindow<CWindowImpl<CAppInfoDisplay>>
{
LPWSTR pLink = NULL;
private:
BOOL ProcessWindowMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT &theResult, DWORD dwMapId);
private:
BOOL
ProcessWindowMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT &theResult, DWORD dwMapId);
VOID
OnLink(ENLINK *Link);
VOID ResizeChildren();
VOID ResizeChildren(int Width, int Height);
VOID OnLink(ENLINK *Link);
public:
VOID
ResizeChildren();
VOID
ResizeChildren(int Width, int Height);
public:
CAppRichEdit *RichEdit = NULL;
CAppScrnshotPreview *ScrnshotPrev = NULL;
static ATL::CWndClassInfo &GetWndClassInfo();
static ATL::CWndClassInfo &
GetWndClassInfo();
HWND Create(HWND hwndParent);
HWND
Create(HWND hwndParent);
BOOL ShowAvailableAppInfo(CAvailableApplicationInfo *Info);
BOOL ShowInstalledAppInfo(CInstalledApplicationInfo *Info);
VOID SetWelcomeText();
VOID OnCommand(WPARAM wParam, LPARAM lParam);
VOID
ShowAppInfo(CApplicationInfo *Info);
VOID
SetWelcomeText();
VOID
OnCommand(WPARAM wParam, LPARAM lParam);
~CAppInfoDisplay();
};
class CAppsListView :
public CUiWindow<CWindowImpl<CAppsListView, CListView>>
class CAppsListView : public CUiWindow<CWindowImpl<CAppsListView, CListView>>
{
struct SortContext
{
@ -218,7 +203,7 @@ class CAppsListView :
INT nLastHeaderID = -1;
APPLICATION_VIEW_TYPE ApplicationViewType = AppViewTypeEmpty;
APPLICATION_VIEW_TYPE ApplicationViewType = AppViewTypeAvailableApps;
HIMAGELIST m_hImageListView = NULL;
CStringW m_Watermark;
@ -227,56 +212,65 @@ class CAppsListView :
MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground)
END_MSG_MAP()
LRESULT
OnEraseBackground(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
LRESULT OnEraseBackground(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
public:
public:
CAppsListView();
~CAppsListView();
VOID SetWatermark(const CStringW& Text);
VOID SetCheckboxesVisible(BOOL bIsVisible);
VOID
SetWatermark(const CStringW &Text);
VOID
SetCheckboxesVisible(BOOL bIsVisible);
VOID ColumnClick(LPNMLISTVIEW pnmv);
VOID
ColumnClick(LPNMLISTVIEW pnmv);
BOOL AddColumn(INT Index, ATL::CStringW &Text, INT Width, INT Format);
BOOL
AddColumn(INT Index, CStringW &Text, INT Width, INT Format);
void
DeleteColumn(INT Index);
int AddColumn(INT Index, LPWSTR lpText, INT Width, INT Format);
INT
AddItem(INT ItemIndex, INT IconIndex, LPCWSTR lpText, LPARAM lParam);
void DeleteColumn(INT Index);
HIMAGELIST
GetImageList(int iImageList);
INT AddItem(INT ItemIndex, INT IconIndex, LPCWSTR lpText, LPARAM lParam);
static INT CALLBACK
s_CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
HIMAGELIST GetImageList(int iImageList);
INT
CompareFunc(LPARAM lParam1, LPARAM lParam2, INT iSubItem);
static INT CALLBACK s_CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);
HWND
Create(HWND hwndParent);
INT CompareFunc(LPARAM lParam1, LPARAM lParam2, INT iSubItem);
BOOL
GetCheckState(INT item);
VOID
SetCheckState(INT item, BOOL fCheck);
VOID
CheckAll();
HWND Create(HWND hwndParent);
PVOID
GetFocusedItemData();
BOOL GetCheckState(INT item);
BOOL
SetDisplayAppType(APPLICATION_VIEW_TYPE AppType);
BOOL
SetViewMode(DWORD ViewMode);
VOID SetCheckState(INT item, BOOL fCheck);
VOID CheckAll();
PVOID GetFocusedItemData();
BOOL SetDisplayAppType(APPLICATION_VIEW_TYPE AppType);
BOOL SetViewMode(DWORD ViewMode);
BOOL AddInstalledApplication(CInstalledApplicationInfo *InstAppInfo, LPVOID CallbackParam);
BOOL AddAvailableApplication(CAvailableApplicationInfo *AvlbAppInfo, BOOL InitCheckState, LPVOID CallbackParam);
BOOL
AddApplication(CApplicationInfo *AppInfo, BOOL InitialCheckState);
// this function is called when parent window receiving an notification about checkstate changing
VOID ItemCheckStateNotify(int iItem, BOOL bCheck);
VOID
ItemCheckStateNotify(int iItem, BOOL bCheck);
};
class CMainToolbar :
public CUiWindow< CToolbar<> >
class CMainToolbar : public CUiWindow<CToolbar<>>
{
const INT m_iToolbarHeight;
DWORD m_dButtonsWidthMax;
@ -288,66 +282,73 @@ class CMainToolbar :
WCHAR szRefreshBtn[MAX_STR_LEN];
WCHAR szUpdateDbBtn[MAX_STR_LEN];
VOID AddImageToImageList(HIMAGELIST hImageList, UINT ImageIndex);
VOID
AddImageToImageList(HIMAGELIST hImageList, UINT ImageIndex);
HIMAGELIST InitImageList();
public:
HIMAGELIST
InitImageList();
public:
CMainToolbar();
VOID OnGetDispInfo(LPTOOLTIPTEXT lpttt);
VOID
OnGetDispInfo(LPTOOLTIPTEXT lpttt);
HWND Create(HWND hwndParent);
HWND
Create(HWND hwndParent);
VOID HideButtonCaption();
VOID
HideButtonCaption();
VOID
ShowButtonCaption();
VOID ShowButtonCaption();
DWORD GetMaxButtonsWidth() const;
DWORD
GetMaxButtonsWidth() const;
};
class CSearchBar :
public CWindow
class CSearchBar : public CWindow
{
public:
public:
const INT m_Width;
const INT m_Height;
CSearchBar();
VOID SetText(LPCWSTR lpszText);
HWND Create(HWND hwndParent);
VOID
SetText(LPCWSTR lpszText);
HWND
Create(HWND hwndParent);
};
class CComboBox :
public CWindow
class CComboBox : public CWindow
{
// ID refers to different types of view
enum
{ m_AppDisplayTypeDetails, m_AppDisplayTypeList, m_AppDisplayTypeTile };
{
m_AppDisplayTypeDetails,
m_AppDisplayTypeList,
m_AppDisplayTypeTile
};
// string ID for different. this should correspond with the enum above.
const UINT m_TypeStringID[3] =
{ IDS_APP_DISPLAY_DETAILS, IDS_APP_DISPLAY_LIST, IDS_APP_DISPLAY_TILE };
const UINT m_TypeStringID[3] = {IDS_APP_DISPLAY_DETAILS, IDS_APP_DISPLAY_LIST, IDS_APP_DISPLAY_TILE};
const int m_DefaultSelectType = m_AppDisplayTypeDetails;
public:
public:
int m_Width;
int m_Height;
CComboBox();
HWND Create(HWND hwndParent);
HWND
Create(HWND hwndParent);
};
class CApplicationView :
public CUiWindow<CWindowImpl<CApplicationView>>
class CApplicationView : public CUiWindow<CWindowImpl<CApplicationView>>
{
private:
private:
CUiPanel *m_Panel = NULL;
CMainToolbar *m_Toolbar = NULL;
CUiWindow<CComboBox> *m_ComboBox = NULL;
@ -356,47 +357,66 @@ private:
CAppInfoDisplay *m_AppsInfo = NULL;
CUiSplitPanel *m_HSplitter = NULL;
CMainWindow *m_MainWindow = NULL;
APPLICATION_VIEW_TYPE ApplicationViewType = AppViewTypeEmpty;
APPLICATION_VIEW_TYPE ApplicationViewType = AppViewTypeAvailableApps;
BOOL ProcessWindowMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT &theResult, DWORD dwMapId);
BOOL
ProcessWindowMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT &theResult, DWORD dwMapId);
BOOL CreateToolbar();
BOOL CreateSearchBar();
BOOL CreateComboBox();
BOOL CreateHSplitter();
BOOL CreateListView();
BOOL CreateAppInfoDisplay();
BOOL
CreateToolbar();
BOOL
CreateSearchBar();
BOOL
CreateComboBox();
BOOL
CreateHSplitter();
BOOL
CreateListView();
BOOL
CreateAppInfoDisplay();
VOID OnSize(HWND hwnd, WPARAM wParam, LPARAM lParam);
VOID OnCommand(WPARAM wParam, LPARAM lParam);
public:
VOID
OnSize(HWND hwnd, WPARAM wParam, LPARAM lParam);
VOID
OnCommand(WPARAM wParam, LPARAM lParam);
public:
CApplicationView(CMainWindow *MainWindow);
~CApplicationView();
static ATL::CWndClassInfo &GetWndClassInfo();
static ATL::CWndClassInfo &
GetWndClassInfo();
HWND Create(HWND hwndParent);
void SetRedraw(BOOL bRedraw);
void SetFocusOnSearchBar();
BOOL SetDisplayAppType(APPLICATION_VIEW_TYPE AppType);
HWND
Create(HWND hwndParent);
void
SetRedraw(BOOL bRedraw);
void
SetFocusOnSearchBar();
BOOL
SetDisplayAppType(APPLICATION_VIEW_TYPE AppType);
BOOL AddInstalledApplication(CInstalledApplicationInfo *InstAppInfo, LPVOID param);
BOOL AddAvailableApplication(CAvailableApplicationInfo *AvlbAppInfo, BOOL InitCheckState, LPVOID param);
VOID SetWatermark(const CStringW& Text);
BOOL
AddApplication(CApplicationInfo *InstAppInfo, BOOL InitialCheckState);
VOID
SetWatermark(const CStringW &Text);
void CheckAll();
PVOID GetFocusedItemData();
int GetItemCount();
VOID AppendTabOrderWindow(int Direction, ATL::CSimpleArray<HWND> &TabOrderList);
void
CheckAll();
PVOID
GetFocusedItemData();
int
GetItemCount();
VOID
AppendTabOrderWindow(int Direction, ATL::CSimpleArray<HWND> &TabOrderList);
// this function is called when a item of listview get focus.
// CallbackParam is the param passed to listview when adding the item (the one getting focus now).
BOOL ItemGetFocus(LPVOID CallbackParam);
VOID
ItemGetFocus(LPVOID CallbackParam);
// this function is called when a item of listview is checked/unchecked
// CallbackParam is the param passed to listview when adding the item (the one getting focus now).
BOOL ItemCheckStateChanged(BOOL bChecked, LPVOID CallbackParam);
VOID
ItemCheckStateChanged(BOOL bChecked, LPVOID CallbackParam);
};

View file

@ -1,132 +0,0 @@
#pragma once
#include <windef.h>
#include <atlstr.h>
#include <atlsimpcoll.h>
#include <atlcoll.h>
#include "misc.h"
#include "configparser.h"
#define MAX_SCRNSHOT_NUM 16
enum LicenseType
{
LICENSE_NONE,
LICENSE_OPENSOURCE,
LICENSE_FREEWARE,
LICENSE_TRIAL,
LICENSE_MIN = LICENSE_NONE,
LICENSE_MAX = LICENSE_TRIAL
};
inline BOOL IsLicenseType(INT x)
{
return (x >= LICENSE_MIN && x <= LICENSE_MAX);
}
struct AvailableStrings
{
ATL::CStringW szPath;
ATL::CStringW szCabPath;
ATL::CStringW szAppsPath;
ATL::CStringW szSearchPath;
ATL::CStringW szCabName;
ATL::CStringW szCabDir;
AvailableStrings();
};
class CAvailableApplicationInfo
{
public:
INT m_Category;
//BOOL m_IsSelected;
LicenseType m_LicenseType;
ATL::CStringW m_szName; // software's display name.
ATL::CStringW m_szRegName;
ATL::CStringW m_szVersion;
ATL::CStringW m_szLicense;
ATL::CStringW m_szDesc;
ATL::CStringW m_szSize;
ATL::CStringW m_szUrlSite;
ATL::CStringW m_szUrlDownload;
ATL::CSimpleArray<LCID> m_LanguageLCIDs;
ATL::CSimpleArray<ATL::CStringW> m_szScrnshotLocation;
ATL::CStringW m_szIconLocation;
ATL::CStringW m_szPkgName; // software's package name.
ULONG m_SizeBytes;
// Caching mechanism related entries
ATL::CStringW m_sFileName;
FILETIME m_ftCacheStamp;
// Optional integrity checks (SHA-1 digests are 160 bit = 40 characters in hex string form)
ATL::CStringW m_szSHA1;
ATL::CStringW m_szInstalledVersion;
// Create an object from file
CAvailableApplicationInfo(const ATL::CStringW& sFileNameParam, AvailableStrings& m_Strings);
// Load all info from the file
VOID RefreshAppInfo(AvailableStrings& m_Strings);
BOOL HasLanguageInfo() const;
BOOL HasNativeLanguage() const;
BOOL HasEnglishLanguage() const;
BOOL IsInstalled() const;
BOOL HasInstalledVersion() const;
BOOL HasUpdate() const;
BOOL RetrieveScrnshot(UINT Index, ATL::CStringW& ScrnshotLocation) const;
BOOL RetrieveIcon(ATL::CStringW& IconLocation) const;
// Set a timestamp
VOID SetLastWriteTime(FILETIME* ftTime);
private:
BOOL m_IsInstalled;
BOOL m_HasLanguageInfo;
BOOL m_HasInstalledVersion;
CConfigParser* m_Parser;
inline BOOL GetString(LPCWSTR lpKeyName, ATL::CStringW& ReturnedString);
// Lazily load general info from the file
VOID RetrieveGeneralInfo(AvailableStrings& m_Strings);
VOID RetrieveInstalledStatus();
VOID RetrieveInstalledVersion();
VOID RetrieveLanguages();
VOID RetrieveLicenseType();
VOID RetrieveSize();
inline BOOL FindInLanguages(LCID what) const;
};
typedef BOOL(CALLBACK *AVAILENUMPROC)(CAvailableApplicationInfo *Info, BOOL bInitialCheckState, PVOID param);
class CAvailableApps
{
ATL::CAtlList<CAvailableApplicationInfo*> m_InfoList;
ATL::CAtlList< CAvailableApplicationInfo*> m_SelectedList;
public:
static AvailableStrings m_Strings;
CAvailableApps();
static BOOL UpdateAppsDB();
static BOOL ForceUpdateAppsDB();
static VOID DeleteCurrentAppsDB();
VOID FreeCachedEntries();
BOOL Enum(INT EnumType, AVAILENUMPROC lpEnumProc, PVOID param);
BOOL AddSelected(CAvailableApplicationInfo *AvlbInfo);
BOOL RemoveSelected(CAvailableApplicationInfo *AvlbInfo);
VOID RemoveAllSelected();
int GetSelectedCount();
CAvailableApplicationInfo* FindAppByPkgName(const ATL::CStringW& szPkgName) const;
ATL::CSimpleArray<CAvailableApplicationInfo> FindAppsByPkgNameList(const ATL::CSimpleArray<ATL::CStringW> &arrAppsNames) const;
//ATL::CSimpleArray<CAvailableApplicationInfo> GetSelected() const;
};

View file

@ -5,16 +5,19 @@
class CConfigParser
{
const ATL::CStringW szConfigPath;
const CStringW szConfigPath;
CSimpleMap<CStringW, CStringW> m_Keys;
void CacheINI();
void ReadSection(ATL::CStringW& Buffer, const ATL::CStringW& Section, BOOL isArch);
void
CacheINI();
void
ReadSection(CStringW &Buffer, const CStringW &Section, BOOL isArch);
public:
CConfigParser(const ATL::CStringW& FileName);
public:
CConfigParser(const CStringW &FileName);
BOOL GetString(const ATL::CStringW& KeyName, ATL::CStringW& ResultString);
BOOL GetInt(const ATL::CStringW& KeyName, INT& iResult);
BOOL
GetString(const CStringW &KeyName, CStringW &ResultString);
BOOL
GetInt(const CStringW &KeyName, INT &iResult);
};

View file

@ -1,12 +1,12 @@
#pragma once
#include <ui/rosctrls.h>
class CRichEdit :
public CWindow
class CRichEdit : public CWindow
{
HMODULE m_LoadedLibrary;
VOID GenericInsertText(LPCWSTR lpszText, SIZE_T InsertedTextLen, DWORD dwEffects)
VOID
GenericInsertText(LPCWSTR lpszText, SIZE_T InsertedTextLen, DWORD dwEffects)
{
SETTEXTEX SetText;
SIZE_T Len = GetTextLen();
@ -17,7 +17,7 @@ class CRichEdit :
SetText.flags = ST_SELECTION;
SetText.codepage = 1200;
SendMessageW(EM_SETTEXTEX, (WPARAM) &SetText, (LPARAM) lpszText);
SendMessageW(EM_SETTEXTEX, (WPARAM)&SetText, (LPARAM)lpszText);
if ((dwEffects == CFM_LINK) && !PathIsURLW(lpszText))
{
@ -31,10 +31,13 @@ class CRichEdit :
}
}
public:
CRichEdit() : CWindow(), m_LoadedLibrary(NULL) {}
public:
CRichEdit() : CWindow(), m_LoadedLibrary(NULL)
{
}
VOID SetRangeFormatting(SIZE_T Start, SIZE_T End, DWORD dwEffects)
VOID
SetRangeFormatting(SIZE_T Start, SIZE_T End, DWORD dwEffects)
{
CHARFORMAT2W CharFormat;
@ -46,19 +49,20 @@ public:
CharFormat.dwMask = dwEffects;
CharFormat.dwEffects = dwEffects;
SendMessageW(EM_SETCHARFORMAT, SCF_WORD | SCF_SELECTION, (LPARAM) &CharFormat);
SendMessageW(EM_SETCHARFORMAT, SCF_WORD | SCF_SELECTION, (LPARAM)&CharFormat);
SendMessageW(EM_SETSEL, End, End + 1);
}
LONG GetTextLen()
LONG
GetTextLen()
{
GETTEXTLENGTHEX TxtLenStruct;
TxtLenStruct.flags = GTL_NUMCHARS;
TxtLenStruct.codepage = 1200;
return (LONG) SendMessageW(EM_GETTEXTLENGTHEX, (WPARAM) &TxtLenStruct, 0);
return (LONG)SendMessageW(EM_GETTEXTLENGTHEX, (WPARAM)&TxtLenStruct, 0);
}
/*
@ -69,48 +73,46 @@ public:
* - CFM_UNDERLINE
* - CFM_LINK
*/
VOID InsertText(LPCWSTR lpszText, DWORD dwEffects)
VOID
InsertText(LPCWSTR lpszText, DWORD dwEffects)
{
GenericInsertText(lpszText, wcslen(lpszText), dwEffects);
}
VOID InsertText(const ATL::CStringW& szText, DWORD dwEffects)
VOID
InsertText(const CStringW &szText, DWORD dwEffects)
{
GenericInsertText(szText.GetString(), szText.GetLength(), dwEffects);
}
/*
* Clear old text and add new
*/
VOID SetText(LPCWSTR lpszText, DWORD dwEffects)
VOID
SetText(LPCWSTR lpszText, DWORD dwEffects)
{
SetWindowTextW(L"");
InsertText(lpszText, dwEffects);
}
VOID SetText(const ATL::CStringW& szText, DWORD dwEffects)
VOID
SetText(const CStringW &szText, DWORD dwEffects)
{
SetText(szText.GetString(), dwEffects);
}
HWND Create(HWND hwndParent)
HWND
Create(HWND hwndParent)
{
m_LoadedLibrary = LoadLibraryW(L"riched20.dll");
m_hWnd = CreateWindowExW(0,
L"RichEdit20W",
NULL,
WS_CHILD | WS_VISIBLE | ES_MULTILINE |
ES_LEFT | ES_READONLY,
205, 28, 465, 100,
hwndParent,
NULL,
_AtlBaseModule.GetModuleInstance(),
NULL);
m_hWnd = CreateWindowExW(
0, L"RichEdit20W", NULL, WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_LEFT | ES_READONLY, 205, 28, 465, 100,
hwndParent, NULL, _AtlBaseModule.GetModuleInstance(), NULL);
if (m_hWnd)
{
SendMessageW(EM_SETBKGNDCOLOR, 0, GetSysColor(COLOR_BTNFACE));
SendMessageW(WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0);
SendMessageW(WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0);
SendMessageW(EM_SETEVENTMASK, 0, ENM_LINK | ENM_MOUSEEVENTS);
SendMessageW(EM_SHOWSCROLLBAR, SB_VERT, TRUE);
}
@ -118,7 +120,8 @@ public:
return m_hWnd;
}
virtual VOID OnLink(ENLINK *Link)
virtual VOID
OnLink(ENLINK *Link)
{
}
@ -129,5 +132,4 @@ public:
FreeLibrary(m_LoadedLibrary);
}
}
};

View file

@ -32,42 +32,3 @@
#define APPLICATION_DATABASE_URL L"https://rapps.reactos.org/rappmgr2.cab"
#define APPLICATION_DATABASE_NAME L"rappmgr2.cab"
#define MAX_STR_LEN 256
enum AppsCategories
{
ENUM_ALL_AVAILABLE,
ENUM_CAT_AUDIO,
ENUM_CAT_VIDEO,
ENUM_CAT_GRAPHICS,
ENUM_CAT_GAMES,
ENUM_CAT_INTERNET,
ENUM_CAT_OFFICE,
ENUM_CAT_DEVEL,
ENUM_CAT_EDU,
ENUM_CAT_ENGINEER,
ENUM_CAT_FINANCE,
ENUM_CAT_SCIENCE,
ENUM_CAT_TOOLS,
ENUM_CAT_DRIVERS,
ENUM_CAT_LIBS,
ENUM_CAT_THEMES,
ENUM_CAT_OTHER,
ENUM_CAT_SELECTED,
ENUM_ALL_INSTALLED,
ENUM_INSTALLED_APPLICATIONS = 31,
ENUM_UPDATES = 32,
ENUM_INSTALLED_MIN = ENUM_ALL_INSTALLED,
ENUM_INSTALLED_MAX = ENUM_UPDATES,
ENUM_AVAILABLE_MIN = ENUM_ALL_AVAILABLE,
ENUM_AVAILABLE_MAX = ENUM_CAT_SELECTED,
};
inline BOOL IsAvailableEnum(INT x)
{
return (x >= ENUM_AVAILABLE_MIN && x <= ENUM_AVAILABLE_MAX);
}
inline BOOL IsInstalledEnum(INT x)
{
return (x >= ENUM_INSTALLED_MIN && x <= ENUM_INSTALLED_MAX);
}

View file

@ -1,17 +1,22 @@
#pragma once
#include "available.h"
#include "applicationinfo.h"
#include <windef.h>
#include <atlsimpcoll.h>
// Settings dialog (settingsdlg.cpp)
VOID CreateSettingsDlg(HWND hwnd);
VOID
CreateSettingsDlg(HWND hwnd);
//Main window
VOID MainWindowLoop(INT nShowCmd);
// Main window
VOID
MainWindowLoop(class CApplicationDB *db, INT nShowCmd);
// Download dialogs
VOID DownloadApplicationsDB(LPCWSTR lpUrl, BOOL IsOfficial);
BOOL DownloadApplication(CAvailableApplicationInfo* pAppInfo);
BOOL DownloadListOfApplications(const ATL::CSimpleArray<CAvailableApplicationInfo>& AppsList, BOOL bIsModal);
VOID
DownloadApplicationsDB(LPCWSTR lpUrl, BOOL IsOfficial);
BOOL
DownloadApplication(CApplicationInfo *pAppInfo);
BOOL
DownloadListOfApplications(const CAtlList<CApplicationInfo *> &AppsList, BOOL bIsModal);

View file

@ -22,29 +22,29 @@
#define SEARCH_TIMER_ID 'SR'
#define TREEVIEW_ICON_SIZE 24
class CSideTreeView :
public CUiWindow<CTreeView>
class CSideTreeView : public CUiWindow<CTreeView>
{
HIMAGELIST hImageTreeView;
public:
public:
CSideTreeView();
HTREEITEM AddItem(HTREEITEM hParent, ATL::CStringW &Text, INT Image, INT SelectedImage, LPARAM lParam);
HTREEITEM
AddItem(HTREEITEM hParent, CStringW &Text, INT Image, INT SelectedImage, LPARAM lParam);
HTREEITEM AddCategory(HTREEITEM hRootItem, UINT TextIndex, UINT IconIndex);
HTREEITEM
AddCategory(HTREEITEM hRootItem, UINT TextIndex, UINT IconIndex);
HIMAGELIST SetImageList();
HIMAGELIST
SetImageList();
VOID DestroyImageList();
VOID
DestroyImageList();
~CSideTreeView();
};
class CMainWindow :
public CWindowImpl<CMainWindow, CWindow, CFrameWinTraits>
class CMainWindow : public CWindowImpl<CMainWindow, CWindow, CFrameWinTraits>
{
CUiPanel *m_ClientPanel = NULL;
CUiSplitPanel *m_VSplitter = NULL;
@ -54,75 +54,81 @@ class CMainWindow :
CApplicationView *m_ApplicationView = NULL;
CAvailableApps m_AvailableApps;
CInstalledApps m_InstalledApps;
CApplicationDB *m_Db;
CAtlList<CApplicationInfo *> m_Selected;
BOOL bUpdating = FALSE;
ATL::CStringW szSearchPattern;
INT SelectedEnumType;
CStringW szSearchPattern;
AppsCategories SelectedEnumType;
public:
CMainWindow();
public:
CMainWindow(CApplicationDB *db);
~CMainWindow();
private:
VOID InitCategoriesList();
private:
VOID
InitCategoriesList();
BOOL CreateStatusBar();
BOOL CreateTreeView();
BOOL CreateApplicationView();
BOOL CreateVSplitter();
BOOL CreateLayout();
BOOL
CreateStatusBar();
BOOL
CreateTreeView();
BOOL
CreateApplicationView();
BOOL
CreateVSplitter();
BOOL
CreateLayout();
VOID
LayoutCleanup();
BOOL
InitControls();
VOID LayoutCleanup();
VOID
OnSize(HWND hwnd, WPARAM wParam, LPARAM lParam);
BOOL InitControls();
BOOL
RemoveSelectedAppFromRegistry();
BOOL
UninstallSelectedApp(BOOL bModify);
VOID OnSize(HWND hwnd, WPARAM wParam, LPARAM lParam);
BOOL
ProcessWindowMessage(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT &theResult, DWORD dwMapId);
VOID
ShowAboutDlg();
VOID
OnCommand(WPARAM wParam, LPARAM lParam);
VOID
UpdateStatusBarText();
BOOL RemoveSelectedAppFromRegistry();
VOID
UpdateApplicationsList(AppsCategories EnumType, BOOL bReload = FALSE);
VOID
AddApplicationsToView(CAtlList<CApplicationInfo *> &List);
BOOL UninstallSelectedApp(BOOL bModify);
public:
static ATL::CWndClassInfo &
GetWndClassInfo();
BOOL ProcessWindowMessage(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT &theResult, DWORD dwMapId);
BOOL IsSelectedNodeInstalled();
VOID ShowAboutDlg();
VOID OnCommand(WPARAM wParam, LPARAM lParam);
BOOL CALLBACK EnumInstalledAppProc(CInstalledApplicationInfo *Info);
BOOL CALLBACK EnumAvailableAppProc(CAvailableApplicationInfo *Info, BOOL bInitialCheckState);
static BOOL CALLBACK s_EnumInstalledAppProc(CInstalledApplicationInfo *Info, PVOID param);
static BOOL CALLBACK s_EnumAvailableAppProc(CAvailableApplicationInfo *Info, BOOL bInitialCheckState, PVOID param);
static BOOL CALLBACK s_EnumSelectedAppForDownloadProc(CAvailableApplicationInfo *Info, BOOL bInitialCheckState, PVOID param);
VOID UpdateStatusBarText();
VOID UpdateApplicationsList(INT EnumType);
public:
static ATL::CWndClassInfo &GetWndClassInfo();
HWND Create();
HWND
Create();
// this function is called when a item of application-view is checked/unchecked
// CallbackParam is the param passed to application-view when adding the item (the one getting focus now).
BOOL ItemCheckStateChanged(BOOL bChecked, LPVOID CallbackParam);
VOID
ItemCheckStateChanged(BOOL bChecked, LPVOID CallbackParam);
// this function is called when application-view is asked to install an application
// if Info is not zero, this app should be installed. otherwise those checked apps should be installed
BOOL InstallApplication(CAvailableApplicationInfo *Info);
BOOL
InstallApplication(CApplicationInfo *Info);
// this function is called when search text is changed
BOOL SearchTextChanged(ATL::CStringW &SearchText);
BOOL
SearchTextChanged(CStringW &SearchText);
void HandleTabOrder(int direction);
void
HandleTabOrder(int direction);
};
VOID MainWindowLoop(INT nShowCmd);

View file

@ -1,63 +0,0 @@
#pragma once
#include <windef.h>
#include <atlstr.h>
class CInstalledApplicationInfo
{
private:
BOOL m_IsUserKey;
REGSAM m_WowKey;
HKEY m_hSubKey;
CStringW m_szKeyName;
public:
CInstalledApplicationInfo(BOOL bIsUserKey, REGSAM RegWowKey, HKEY hKey, const CStringW& szKeyName);
~CInstalledApplicationInfo();
VOID EnsureDetailsLoaded();
BOOL GetApplicationRegString(LPCWSTR lpKeyName, ATL::CStringW& String);
BOOL GetApplicationRegDword(LPCWSTR lpKeyName, DWORD *lpValue);
BOOL RetrieveIcon(ATL::CStringW& IconLocation);
BOOL UninstallApplication(BOOL bModify);
LSTATUS RemoveFromRegistry();
// These fields are always loaded
BOOL bIsUpdate;
CStringW szDisplayIcon;
CStringW szDisplayName;
CStringW szDisplayVersion;
CStringW szComments;
// These details are loaded on demand
CStringW szPublisher;
CStringW szRegOwner;
CStringW szProductID;
CStringW szHelpLink;
CStringW szHelpTelephone;
CStringW szReadme;
CStringW szContact;
CStringW szURLUpdateInfo;
CStringW szURLInfoAbout;
CStringW szInstallDate;
CStringW szInstallLocation;
CStringW szInstallSource;
CStringW szUninstallString;
CStringW szModifyPath;
};
typedef BOOL(CALLBACK *APPENUMPROC)(CInstalledApplicationInfo * Info, PVOID param);
class CInstalledApps
{
ATL::CAtlList<CInstalledApplicationInfo *> m_InfoList;
public:
BOOL Enum(INT EnumType, APPENUMPROC lpEnumProc, PVOID param);
VOID FreeCachedEntries();
};

View file

@ -17,32 +17,39 @@
#define CurrentArchitecture L"ppc"
#endif
VOID CopyTextToClipboard(LPCWSTR lpszText);
VOID ShowPopupMenuEx(HWND hwnd, HWND hwndOwner, UINT MenuID, UINT DefaultItem);
BOOL StartProcess(const ATL::CStringW &Path, BOOL Wait);
BOOL GetStorageDirectory(ATL::CStringW &lpDirectory);
VOID
CopyTextToClipboard(LPCWSTR lpszText);
VOID
ShowPopupMenuEx(HWND hwnd, HWND hwndOwner, UINT MenuID, UINT DefaultItem);
BOOL
StartProcess(const CStringW &Path, BOOL Wait);
BOOL
GetStorageDirectory(CStringW &lpDirectory);
VOID InitLogs();
VOID FreeLogs();
BOOL WriteLogMessage(WORD wType, DWORD dwEventID, LPCWSTR lpMsg);
BOOL GetInstalledVersion(ATL::CStringW *pszVersion, const ATL::CStringW &szRegName);
VOID
InitLogs();
VOID
FreeLogs();
BOOL
WriteLogMessage(WORD wType, DWORD dwEventID, LPCWSTR lpMsg);
BOOL
GetInstalledVersion(CStringW *pszVersion, const CStringW &szRegName);
BOOL ExtractFilesFromCab(const ATL::CStringW& szCabName,
const ATL::CStringW& szCabDir,
const ATL::CStringW& szOutputDir);
BOOL
ExtractFilesFromCab(const CStringW &szCabName, const CStringW &szCabDir, const CStringW &szOutputDir);
BOOL PathAppendNoDirEscapeW(LPWSTR pszPath, LPCWSTR pszMore);
BOOL
IsSystem64Bit();
BOOL IsSystem64Bit();
INT
GetSystemColorDepth();
INT GetSystemColorDepth();
void
UnixTimeToFileTime(DWORD dwUnixTime, LPFILETIME pFileTime);
void UnixTimeToFileTime(DWORD dwUnixTime, LPFILETIME pFileTime);
BOOL
SearchPatternMatch(LPCWSTR szHaystack, LPCWSTR szNeedle);
BOOL SearchPatternMatch(LPCWSTR szHaystack, LPCWSTR szNeedle);
template<class T>
class CLocalPtr : public CHeapPtr<T, CLocalAllocator>
template <class T> class CLocalPtr : public CHeapPtr<T, CLocalAllocator>
{
};

View file

@ -2,14 +2,14 @@
#define _RAPPS_H
#if DBG && !defined(_DEBUG)
#define _DEBUG // CORE-17505
#define _DEBUG // CORE-17505
#endif
#include "defines.h"
#include "dialogs.h"
#include "installed.h"
#include "available.h"
#include "applicationinfo.h"
#include "applicationdb.h"
#include "misc.h"
#include "configparser.h"

View file

@ -84,7 +84,6 @@
#define ID_RESETDB 561
#define ID_CHECK_ALL 562
#define ID_SEARCH 563
#define ID_TOOLBAR_INSTALL 564
/* Strings */
#define IDS_APPTITLE 100

View file

@ -9,13 +9,12 @@
#include <atlwin.h>
template<class T, INT GrowthRate = 10>
class CPointerArray
template <class T, INT GrowthRate = 10> class CPointerArray
{
protected:
protected:
HDPA m_hDpa;
public:
public:
CPointerArray()
{
m_hDpa = DPA_Create(GrowthRate);
@ -26,26 +25,30 @@ public:
DPA_DestroyCallback(m_hDpa, s_OnRemoveItem, this);
}
private:
static INT CALLBACK s_OnRemoveItem(PVOID ptr, PVOID context)
private:
static INT CALLBACK
s_OnRemoveItem(PVOID ptr, PVOID context)
{
CPointerArray * self = (CPointerArray*) context;
return (INT) self->OnRemoveItem(reinterpret_cast<T*>(ptr));
CPointerArray *self = (CPointerArray *)context;
return (INT)self->OnRemoveItem(reinterpret_cast<T *>(ptr));
}
static INT CALLBACK s_OnCompareItems(PVOID p1, PVOID p2, LPARAM lParam)
static INT CALLBACK
s_OnCompareItems(PVOID p1, PVOID p2, LPARAM lParam)
{
CPointerArray * self = (CPointerArray*) lParam;
return self->OnCompareItems(reinterpret_cast<T*>(p1), reinterpret_cast<T*>(p2));
CPointerArray *self = (CPointerArray *)lParam;
return self->OnCompareItems(reinterpret_cast<T *>(p1), reinterpret_cast<T *>(p2));
}
public:
virtual BOOL OnRemoveItem(T * ptr)
public:
virtual BOOL
OnRemoveItem(T *ptr)
{
return TRUE;
}
virtual INT OnCompareItems(T * p1, T * p2)
virtual INT
OnCompareItems(T *p1, T *p2)
{
INT_PTR t = (reinterpret_cast<INT_PTR>(p2) - reinterpret_cast<INT_PTR>(p1));
if (t > 0)
@ -55,38 +58,45 @@ public:
return 0;
}
public:
INT GetCount() const
public:
INT
GetCount() const
{
return DPA_GetPtrCount(m_hDpa);
}
T* Get(INT i) const
T *
Get(INT i) const
{
return (T*) DPA_GetPtr(m_hDpa, i);
return (T *)DPA_GetPtr(m_hDpa, i);
}
BOOL Set(INT i, T* ptr)
BOOL
Set(INT i, T *ptr)
{
return DPA_SetPtr(m_hDpa, i, ptr);
}
INT Insert(INT at, T* ptr)
INT
Insert(INT at, T *ptr)
{
return DPA_InsertPtr(m_hDpa, at, ptr);
}
INT Append(T* ptr)
INT
Append(T *ptr)
{
return DPA_InsertPtr(m_hDpa, DA_LAST, ptr);
}
INT IndexOf(T* ptr) const
INT
IndexOf(T *ptr) const
{
return DPA_GetPtrIndex(m_hDpa, ptr);
}
BOOL Remove(T* ptr)
BOOL
Remove(T *ptr)
{
INT i = IndexOf(ptr);
if (i < 0)
@ -94,38 +104,41 @@ public:
return RemoveAt(i);
}
BOOL RemoveAt(INT i)
BOOL
RemoveAt(INT i)
{
PVOID ptr = DPA_DeletePtr(m_hDpa, i);
if (ptr != NULL)
{
OnRemoveItem(reinterpret_cast<T*>(ptr));
OnRemoveItem(reinterpret_cast<T *>(ptr));
return TRUE;
}
return FALSE;
}
BOOL Clear()
BOOL
Clear()
{
DPA_EnumCallback(s_OnRemoveItem, this);
return DPA_DeleteAllPtrs(m_hDpa);
}
BOOL Sort()
BOOL
Sort()
{
return DPA_Sort(m_hDpa, s_OnCompareItems, (LPARAM)this);
}
INT Search(T* item, INT iStart, UINT uFlags)
INT
Search(T *item, INT iStart, UINT uFlags)
{
return DPA_Search(m_hDpa, item, 0, s_OnCompareItems, (LPARAM)this, 0);
}
};
class CUiRect
: public RECT
class CUiRect : public RECT
{
public:
public:
CUiRect()
{
left = right = top = bottom = 0;
@ -140,28 +153,25 @@ public:
}
};
class CUiMargin
: public CUiRect
class CUiMargin : public CUiRect
{
public:
public:
CUiMargin()
{
}
CUiMargin(INT all)
: CUiRect(all, all, all, all)
CUiMargin(INT all) : CUiRect(all, all, all, all)
{
}
CUiMargin(INT horz, INT vert)
: CUiRect(horz, vert, horz, vert)
CUiMargin(INT horz, INT vert) : CUiRect(horz, vert, horz, vert)
{
}
};
class CUiMeasure
{
public:
public:
enum MeasureType
{
Type_FitContent = 0,
@ -170,11 +180,11 @@ public:
Type_FitParent = 3
};
private:
private:
MeasureType m_Type;
INT m_Value;
public:
public:
CUiMeasure()
{
m_Type = Type_FitContent;
@ -187,7 +197,8 @@ public:
m_Value = value;
}
INT ComputeMeasure(INT parent, INT content)
INT
ComputeMeasure(INT parent, INT content)
{
switch (m_Type)
{
@ -204,23 +215,27 @@ public:
return 0;
}
public:
static CUiMeasure FitContent()
public:
static CUiMeasure
FitContent()
{
return CUiMeasure(Type_FitContent, 0);
}
static CUiMeasure FitParent()
static CUiMeasure
FitParent()
{
return CUiMeasure(Type_FitParent, 0);
}
static CUiMeasure Fixed(INT pixels)
static CUiMeasure
Fixed(INT pixels)
{
return CUiMeasure(Type_Fixed, pixels);
}
static CUiMeasure Percent(INT percent)
static CUiMeasure
Percent(INT percent)
{
return CUiMeasure(Type_Percent, percent);
}
@ -236,20 +251,21 @@ enum CUiAlignment
class CUiBox
{
public:
public:
CUiMargin m_Margin;
CUiAlignment m_HorizontalAlignment;
CUiAlignment m_VerticalAlignment;
protected:
protected:
CUiBox()
{
m_HorizontalAlignment = UiAlign_LeftTop;
m_VerticalAlignment = UiAlign_LeftTop;
}
virtual VOID ComputeRect(RECT parentRect, RECT currentRect, RECT* newRect)
virtual VOID
ComputeRect(RECT parentRect, RECT currentRect, RECT *newRect)
{
parentRect.left += m_Margin.left;
parentRect.right -= m_Margin.right;
@ -302,27 +318,29 @@ protected:
*newRect = currentRect;
}
public:
virtual VOID ComputeMinimalSize(SIZE* size)
public:
virtual VOID
ComputeMinimalSize(SIZE *size)
{
// Override in subclass
size->cx = max(size->cx, 0);
size->cy = min(size->cy, 0);
};
virtual VOID ComputeContentBounds(RECT* rect)
{
virtual VOID
ComputeContentBounds(RECT *rect){
// Override in subclass
};
virtual DWORD_PTR CountSizableChildren()
virtual DWORD_PTR
CountSizableChildren()
{
// Override in subclass
return 0;
};
virtual HDWP OnParentSize(RECT parentRect, HDWP hDwp)
virtual HDWP
OnParentSize(RECT parentRect, HDWP hDwp)
{
// Override in subclass
return NULL;
@ -331,19 +349,25 @@ public:
class CUiPrimitive
{
protected:
CUiPrimitive * m_Parent;
protected:
CUiPrimitive *m_Parent;
public:
virtual ~CUiPrimitive() {}
public:
virtual ~CUiPrimitive()
{
}
virtual CUiBox * AsBox() { return NULL; }
virtual CUiBox *
AsBox()
{
return NULL;
}
};
class CUiCollection :
public CPointerArray < CUiPrimitive >
class CUiCollection : public CPointerArray<CUiPrimitive>
{
virtual BOOL OnRemoveItem(CUiPrimitive * ptr)
virtual BOOL
OnRemoveItem(CUiPrimitive *ptr)
{
delete ptr;
return TRUE;
@ -352,19 +376,20 @@ class CUiCollection :
class CUiContainer
{
protected:
protected:
CUiCollection m_Children;
public:
CUiCollection& Children() { return m_Children; }
public:
CUiCollection &
Children()
{
return m_Children;
}
};
class CUiPanel :
public CUiPrimitive,
public CUiBox,
public CUiContainer
class CUiPanel : public CUiPrimitive, public CUiBox, public CUiContainer
{
public:
public:
CUiMeasure m_Width;
CUiMeasure m_Height;
@ -378,13 +403,18 @@ public:
{
}
virtual CUiBox * AsBox() { return this; }
virtual CUiBox *
AsBox()
{
return this;
}
virtual VOID ComputeMinimalSize(SIZE* size)
virtual VOID
ComputeMinimalSize(SIZE *size)
{
for (INT i = 0; i < m_Children.GetCount(); i++)
{
CUiBox * box = m_Children.Get(i)->AsBox();
CUiBox *box = m_Children.Get(i)->AsBox();
if (box)
{
box->ComputeMinimalSize(size);
@ -392,11 +422,12 @@ public:
}
};
virtual VOID ComputeContentBounds(RECT* rect)
virtual VOID
ComputeContentBounds(RECT *rect)
{
for (INT i = 0; i < m_Children.GetCount(); i++)
{
CUiBox * box = m_Children.Get(i)->AsBox();
CUiBox *box = m_Children.Get(i)->AsBox();
if (box)
{
box->ComputeContentBounds(rect);
@ -404,12 +435,13 @@ public:
}
};
virtual DWORD_PTR CountSizableChildren()
virtual DWORD_PTR
CountSizableChildren()
{
INT count = 0;
for (INT i = 0; i < m_Children.GetCount(); i++)
{
CUiBox * box = m_Children.Get(i)->AsBox();
CUiBox *box = m_Children.Get(i)->AsBox();
if (box)
{
count += box->CountSizableChildren();
@ -418,7 +450,8 @@ public:
return count;
}
virtual HDWP OnParentSize(RECT parentRect, HDWP hDwp)
virtual HDWP
OnParentSize(RECT parentRect, HDWP hDwp)
{
RECT rect = {0};
@ -435,7 +468,7 @@ public:
for (INT i = 0; i < m_Children.GetCount(); i++)
{
CUiBox * box = m_Children.Get(i)->AsBox();
CUiBox *box = m_Children.Get(i)->AsBox();
if (box)
{
hDwp = box->OnParentSize(rect, hDwp);
@ -446,24 +479,30 @@ public:
}
};
template<class T = CWindow>
class CUiWindow :
public CUiPrimitive,
public CUiBox,
public T
template <class T = CWindow> class CUiWindow : public CUiPrimitive, public CUiBox, public T
{
public:
virtual CUiBox * AsBox() { return this; }
public:
virtual CUiBox *
AsBox()
{
return this;
}
HWND GetWindow() { return T::m_hWnd; }
HWND
GetWindow()
{
return T::m_hWnd;
}
virtual VOID ComputeMinimalSize(SIZE* size)
virtual VOID
ComputeMinimalSize(SIZE *size)
{
// TODO: Maybe use WM_GETMINMAXINFO?
return CUiBox::ComputeMinimalSize(size);
};
virtual VOID ComputeContentBounds(RECT* rect)
virtual VOID
ComputeContentBounds(RECT *rect)
{
RECT r;
::GetWindowRect(T::m_hWnd, &r);
@ -473,12 +512,14 @@ public:
rect->bottom = max(rect->bottom, r.bottom);
};
virtual DWORD_PTR CountSizableChildren()
virtual DWORD_PTR
CountSizableChildren()
{
return 1;
};
virtual HDWP OnParentSize(RECT parentRect, HDWP hDwp)
virtual HDWP
OnParentSize(RECT parentRect, HDWP hDwp)
{
RECT rect;
@ -488,16 +529,21 @@ public:
if (hDwp)
{
return ::DeferWindowPos(hDwp, T::m_hWnd, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOACTIVATE | SWP_NOZORDER);
return ::DeferWindowPos(
hDwp, T::m_hWnd, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
SWP_NOACTIVATE | SWP_NOZORDER);
}
else
{
T::SetWindowPos(NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOACTIVATE | SWP_NOZORDER | SWP_DEFERERASE);
T::SetWindowPos(
NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top,
SWP_NOACTIVATE | SWP_NOZORDER | SWP_DEFERERASE);
return NULL;
}
};
virtual VOID AppendTabOrderWindow(int Direction, ATL::CSimpleArray<HWND> & TabOrderList)
virtual VOID
AppendTabOrderWindow(int Direction, ATL::CSimpleArray<HWND> &TabOrderList)
{
TabOrderList.Add(T::m_hWnd);
return;
@ -511,7 +557,8 @@ public:
}
}
VOID GetWindowTextW(ATL::CStringW& szText)
VOID
GetWindowTextW(CStringW &szText)
{
INT length = CWindow::GetWindowTextLengthW() + 1;
CWindow::GetWindowTextW(szText.GetBuffer(length), length);
@ -519,15 +566,11 @@ public:
}
};
class CUiSplitPanel :
public CUiPrimitive,
public CUiBox,
public CWindowImpl<CUiSplitPanel>
class CUiSplitPanel : public CUiPrimitive, public CUiBox, public CWindowImpl<CUiSplitPanel>
{
static const INT THICKNESS = 4;
protected:
protected:
HCURSOR m_hCursor;
CUiPanel m_First;
@ -537,7 +580,7 @@ protected:
BOOL m_HasOldRect;
public:
public:
INT m_Pos;
BOOL m_Horizontal;
BOOL m_DynamicFirst;
@ -549,25 +592,41 @@ public:
CUiSplitPanel()
{
m_hCursor = NULL;
m_Width = CUiMeasure::FitParent();
m_Height = CUiMeasure::FitParent();
m_Pos = 100;
m_Horizontal = FALSE;
m_MinFirst = 100;
m_MinSecond = 100;
m_DynamicFirst = FALSE;
m_HasOldRect = FALSE;
memset(&m_LastRect, 0, sizeof(m_LastRect));
}
virtual ~CUiSplitPanel()
{
}
virtual CUiBox * AsBox() { return this; }
virtual CUiBox *
AsBox()
{
return this;
}
CUiCollection& First() { return m_First.Children(); }
CUiCollection& Second() { return m_Second.Children(); }
CUiCollection &
First()
{
return m_First.Children();
}
CUiCollection &
Second()
{
return m_Second.Children();
}
virtual VOID ComputeMinimalSize(SIZE* size)
virtual VOID
ComputeMinimalSize(SIZE *size)
{
if (m_Horizontal)
size->cx = max(size->cx, THICKNESS);
@ -577,7 +636,8 @@ public:
m_Second.ComputeMinimalSize(size);
};
virtual VOID ComputeContentBounds(RECT* rect)
virtual VOID
ComputeContentBounds(RECT *rect)
{
RECT r;
@ -592,7 +652,8 @@ public:
rect->bottom = max(rect->bottom, r.bottom);
};
virtual DWORD_PTR CountSizableChildren()
virtual DWORD_PTR
CountSizableChildren()
{
INT count = 1;
count += m_First.CountSizableChildren();
@ -600,7 +661,8 @@ public:
return count;
};
virtual HDWP OnParentSize(RECT parentRect, HDWP hDwp)
virtual HDWP
OnParentSize(RECT parentRect, HDWP hDwp)
{
RECT rect = {0};
@ -691,25 +753,22 @@ public:
if (hDwp)
{
return DeferWindowPos(hDwp, NULL,
splitter.left, splitter.top,
splitter.right - splitter.left,
splitter.bottom - splitter.top,
return DeferWindowPos(
hDwp, NULL, splitter.left, splitter.top, splitter.right - splitter.left, splitter.bottom - splitter.top,
SWP_NOACTIVATE | SWP_NOZORDER);
}
else
{
SetWindowPos(NULL,
splitter.left, splitter.top,
splitter.right - splitter.left,
splitter.bottom - splitter.top,
SetWindowPos(
NULL, splitter.left, splitter.top, splitter.right - splitter.left, splitter.bottom - splitter.top,
SWP_NOACTIVATE | SWP_NOZORDER);
return NULL;
}
};
private:
BOOL ProcessWindowMessage(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT& theResult, DWORD dwMapId)
private:
BOOL
ProcessWindowMessage(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT &theResult, DWORD dwMapId)
{
theResult = 0;
switch (Msg)
@ -751,13 +810,15 @@ private:
return TRUE;
}
public:
INT GetPos()
public:
INT
GetPos()
{
return m_Pos;
}
VOID SetPos(INT NewPos)
VOID
SetPos(INT NewPos)
{
RECT rcParent;
@ -792,15 +853,18 @@ public:
HDWP hdwp = NULL;
hdwp = BeginDeferWindowPos(count);
if (hdwp) hdwp = OnParentSize(m_LastRect, hdwp);
if (hdwp) EndDeferWindowPos(hdwp);
if (hdwp)
hdwp = OnParentSize(m_LastRect, hdwp);
if (hdwp)
EndDeferWindowPos(hdwp);
}
public:
public:
DECLARE_WND_CLASS_EX(_T("SplitterWindowClass"), CS_HREDRAW | CS_VREDRAW, COLOR_BTNFACE)
/* Create splitter bar */
HWND Create(HWND hwndParent)
HWND
Create(HWND hwndParent)
{
if (m_Horizontal)
m_hCursor = LoadCursor(0, IDC_SIZENS);

View file

@ -1,371 +0,0 @@
/*
* PROJECT: ReactOS Applications Manager
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Classes for working with installed applications
* COPYRIGHT: Copyright 2009 Dmitry Chapyshev <dmitry@reactos.org>
* Copyright 2017 Alexander Shaposhnikov <sanchaez@reactos.org>
* Copyright 2020 He Yang <1160386205@qq.com>
* Copyright 2021 Mark Jansen <mark.jansen@reactos.org>
*/
#include "rapps.h"
#include "installed.h"
#include "misc.h"
CInstalledApplicationInfo::CInstalledApplicationInfo(BOOL bIsUserKey, REGSAM RegWowKey, HKEY hKey, const CStringW& szKeyName)
: m_IsUserKey(bIsUserKey)
, m_WowKey(RegWowKey)
, m_hSubKey(hKey)
, m_szKeyName(szKeyName)
{
DWORD dwSize = 0;
bIsUpdate = (RegQueryValueExW(m_hSubKey, L"ParentKeyName", NULL, NULL, NULL, &dwSize) == ERROR_SUCCESS);
}
CInstalledApplicationInfo::~CInstalledApplicationInfo()
{
if (m_hSubKey)
{
CloseHandle(m_hSubKey);
m_hSubKey = NULL;
}
}
void CInstalledApplicationInfo::EnsureDetailsLoaded()
{
// Key not closed, so we have not loaded details yet
if (m_hSubKey)
{
GetApplicationRegString(L"Publisher", szPublisher);
GetApplicationRegString(L"RegOwner", szRegOwner);
GetApplicationRegString(L"ProductID", szProductID);
GetApplicationRegString(L"HelpLink", szHelpLink);
GetApplicationRegString(L"HelpTelephone", szHelpTelephone);
GetApplicationRegString(L"Readme", szReadme);
GetApplicationRegString(L"Contact", szContact);
GetApplicationRegString(L"URLUpdateInfo", szURLUpdateInfo);
GetApplicationRegString(L"URLInfoAbout", szURLInfoAbout);
DWORD dwInstallTimeStamp;
SYSTEMTIME InstallLocalTime;
if (GetApplicationRegString(L"InstallDate", szInstallDate))
{
ZeroMemory(&InstallLocalTime, sizeof(InstallLocalTime));
// Check if we have 8 characters to parse the datetime.
// Maybe other formats exist as well?
szInstallDate = szInstallDate.Trim();
if (szInstallDate.GetLength() == 8)
{
InstallLocalTime.wYear = wcstol(szInstallDate.Left(4).GetString(), NULL, 10);
InstallLocalTime.wMonth = wcstol(szInstallDate.Mid(4, 2).GetString(), NULL, 10);
InstallLocalTime.wDay = wcstol(szInstallDate.Mid(6, 2).GetString(), NULL, 10);
}
}
// It might be a DWORD (Unix timestamp). try again.
else if (GetApplicationRegDword(L"InstallDate", &dwInstallTimeStamp))
{
FILETIME InstallFileTime;
SYSTEMTIME InstallSystemTime;
UnixTimeToFileTime(dwInstallTimeStamp, &InstallFileTime);
FileTimeToSystemTime(&InstallFileTime, &InstallSystemTime);
// convert to localtime
SystemTimeToTzSpecificLocalTime(NULL, &InstallSystemTime, &InstallLocalTime);
}
// convert to readable date string
int cchTimeStrLen = GetDateFormatW(LOCALE_USER_DEFAULT, 0, &InstallLocalTime, NULL, 0, 0);
GetDateFormatW(
LOCALE_USER_DEFAULT, // use default locale for current user
0, &InstallLocalTime, NULL, szInstallDate.GetBuffer(cchTimeStrLen), cchTimeStrLen);
szInstallDate.ReleaseBuffer();
GetApplicationRegString(L"InstallLocation", szInstallLocation);
GetApplicationRegString(L"InstallSource", szInstallSource);
DWORD dwWindowsInstaller = 0;
if (GetApplicationRegDword(L"WindowsInstaller", &dwWindowsInstaller) && dwWindowsInstaller)
{
// MSI has the same info in Uninstall / modify, so manually build it
szUninstallString.Format(L"msiexec /x%s", m_szKeyName.GetString());
}
else
{
GetApplicationRegString(L"UninstallString", szUninstallString);
}
DWORD dwNoModify = 0;
if (!GetApplicationRegDword(L"NoModify", &dwNoModify))
{
CStringW Tmp;
if (GetApplicationRegString(L"NoModify", Tmp))
{
dwNoModify = Tmp.GetLength() > 0 ? (Tmp[0] == '1') : 0;
}
else
{
dwNoModify = 0;
}
}
if (!dwNoModify)
{
if (dwWindowsInstaller)
{
szModifyPath.Format(L"msiexec /i%s", m_szKeyName.GetString());
}
else
{
GetApplicationRegString(L"ModifyPath", szModifyPath);
}
}
CloseHandle(m_hSubKey);
m_hSubKey = NULL;
}
}
BOOL CInstalledApplicationInfo::GetApplicationRegString(LPCWSTR lpKeyName, ATL::CStringW& String)
{
DWORD dwAllocated = 0, dwSize, dwType;
// retrieve the size of value first.
if (RegQueryValueExW(m_hSubKey, lpKeyName, NULL, &dwType, NULL, &dwAllocated) != ERROR_SUCCESS)
{
String.Empty();
return FALSE;
}
if (dwType != REG_SZ && dwType != REG_EXPAND_SZ)
{
String.Empty();
return FALSE;
}
// query the value
dwSize = dwAllocated;
LSTATUS Result =
RegQueryValueExW(m_hSubKey, lpKeyName, NULL, NULL, (LPBYTE)String.GetBuffer(dwAllocated / sizeof(WCHAR)), &dwSize);
dwSize = min(dwAllocated, dwSize);
// CString takes care of zero-terminating it
String.ReleaseBuffer();
if (Result != ERROR_SUCCESS)
{
String.Empty();
return FALSE;
}
if (dwType == REG_EXPAND_SZ)
{
CStringW Tmp;
DWORD dwLen = ExpandEnvironmentStringsW(String, NULL, 0);
if (dwLen > 0)
{
BOOL bSuccess = ExpandEnvironmentStringsW(String, Tmp.GetBuffer(dwLen), dwLen) == dwLen;
Tmp.ReleaseBuffer();
if (bSuccess)
{
String = Tmp;
}
else
{
String.Empty();
return FALSE;
}
}
}
return TRUE;
}
BOOL CInstalledApplicationInfo::GetApplicationRegDword(LPCWSTR lpKeyName, DWORD *lpValue)
{
DWORD dwSize = sizeof(DWORD), dwType;
if (RegQueryValueExW(m_hSubKey,
lpKeyName,
NULL,
&dwType,
(LPBYTE)lpValue,
&dwSize) != ERROR_SUCCESS || dwType != REG_DWORD)
{
return FALSE;
}
return TRUE;
}
BOOL CInstalledApplicationInfo::RetrieveIcon(ATL::CStringW& IconLocation)
{
if (szDisplayIcon.IsEmpty())
{
return FALSE;
}
IconLocation = szDisplayIcon;
return TRUE;
}
BOOL CInstalledApplicationInfo::UninstallApplication(BOOL bModify)
{
if (!bModify)
WriteLogMessage(EVENTLOG_SUCCESS, MSG_SUCCESS_REMOVE, szDisplayName);
return StartProcess(bModify ? szModifyPath : szUninstallString, TRUE);
}
typedef LSTATUS (WINAPI *RegDeleteKeyExWProc)(HKEY, LPCWSTR, REGSAM, DWORD);
LSTATUS CInstalledApplicationInfo::RemoveFromRegistry()
{
ATL::CStringW szFullName = L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + m_szKeyName;
HMODULE hMod = GetModuleHandleW(L"advapi32.dll");
RegDeleteKeyExWProc pRegDeleteKeyExW;
// TODO: if there are subkeys inside, simply RegDeleteKeyExW
// (or RegDeleteKeyW on Server 2003 SP0 and earlier) will fail
// we don't have RegDeleteTree for ReactOS now. (It's a WinVista API)
// write a function to delete all subkeys recursively to solve this
// or consider letting ReactOS having this API
/* Load RegDeleteKeyExW from advapi32.dll if available */
if (hMod)
{
pRegDeleteKeyExW = (RegDeleteKeyExWProc)GetProcAddress(hMod, "RegDeleteKeyExW");
if (pRegDeleteKeyExW)
{
/* Return it */
return pRegDeleteKeyExW(m_IsUserKey ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, szFullName, m_WowKey, 0);
}
}
/* Otherwise, return non-Ex function */
return RegDeleteKeyW(m_IsUserKey ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, szFullName);
}
BOOL CInstalledApps::Enum(INT EnumType, APPENUMPROC lpEnumProc, PVOID param)
{
FreeCachedEntries();
HKEY RootKeyEnum[3] = { HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_LOCAL_MACHINE };
REGSAM RegSamEnum[3] = { KEY_WOW64_32KEY, KEY_WOW64_32KEY, KEY_WOW64_64KEY };
int LoopTime;
// test if the OS is 64 bit.
if (IsSystem64Bit())
{
// loop for all 3 combination.
// note that HKEY_CURRENT_USER\Software don't have a redirect
// https://docs.microsoft.com/en-us/windows/win32/winprog64/shared-registry-keys#redirected-shared-and-reflected-keys-under-wow64
LoopTime = 3;
}
else
{
// loop for 2 combination for KEY_WOW64_32KEY only
LoopTime = 2;
}
// loop for all combination
for (int i = 0; i < LoopTime; i++)
{
DWORD dwSize = MAX_PATH;
HKEY hKey, hSubKey;
LONG ItemIndex = 0;
ATL::CStringW szKeyName;
if (RegOpenKeyExW(RootKeyEnum[i],
L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
NULL,
KEY_READ | RegSamEnum[i],
&hKey) != ERROR_SUCCESS)
{
return FALSE;
}
while (1)
{
dwSize = MAX_PATH;
if (RegEnumKeyExW(hKey, ItemIndex, szKeyName.GetBuffer(MAX_PATH), &dwSize, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
{
break;
}
ItemIndex++;
szKeyName.ReleaseBuffer();
if (RegOpenKeyW(hKey, szKeyName, &hSubKey) == ERROR_SUCCESS)
{
DWORD dwValue = 0;
BOOL bIsSystemComponent = FALSE;
dwSize = sizeof(DWORD);
if (RegQueryValueExW(hSubKey, L"SystemComponent", NULL, NULL, (LPBYTE)&dwValue, &dwSize) == ERROR_SUCCESS)
{
bIsSystemComponent = (dwValue == 0x1);
}
// Ignore system components
if (bIsSystemComponent)
{
RegCloseKey(hSubKey);
continue;
}
BOOL bSuccess = FALSE;
CInstalledApplicationInfo *Info = new CInstalledApplicationInfo(RootKeyEnum[i] == HKEY_CURRENT_USER, RegSamEnum[i], hSubKey, szKeyName);
// items without display name are ignored
if (Info->GetApplicationRegString(L"DisplayName", Info->szDisplayName))
{
Info->GetApplicationRegString(L"DisplayIcon", Info->szDisplayIcon);
Info->GetApplicationRegString(L"DisplayVersion", Info->szDisplayVersion);
Info->GetApplicationRegString(L"Comments", Info->szComments);
bSuccess = TRUE;
}
if (bSuccess)
{
// add to InfoList.
m_InfoList.AddTail(Info);
// invoke callback
if (lpEnumProc)
{
if ((EnumType == ENUM_ALL_INSTALLED) || /* All components */
((EnumType == ENUM_INSTALLED_APPLICATIONS) && (!Info->bIsUpdate)) || /* Applications only */
((EnumType == ENUM_UPDATES) && (Info->bIsUpdate))) /* Updates only */
{
lpEnumProc(Info, param);
}
}
}
else
{
// destory object
delete Info;
}
}
}
szKeyName.ReleaseBuffer();
RegCloseKey(hKey);
}
return TRUE;
}
VOID CInstalledApps::FreeCachedEntries()
{
POSITION InfoListPosition = m_InfoList.GetHeadPosition();
/* loop and deallocate all the cached app infos in the list */
while (InfoListPosition)
{
CInstalledApplicationInfo *Info = m_InfoList.GetNext(InfoListPosition);
delete Info;
}
m_InfoList.RemoveAll();
}

View file

@ -3,14 +3,15 @@
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Various integrity check mechanisms
* COPYRIGHT: Copyright Ismael Ferreras Morezuelas (swyterzone+ros@gmail.com)
* Copyright Mark Jansen
* Copyright 2016 Mark Jansen <mark.jansen@reactos.org>
*/
#include "rapps.h"
#include <sha1.h>
BOOL VerifyInteg(LPCWSTR lpSHA1Hash, LPCWSTR lpFileName)
BOOL
VerifyInteg(LPCWSTR lpSHA1Hash, LPCWSTR lpFileName)
{
BOOL ret = FALSE;
@ -48,7 +49,7 @@ BOOL VerifyInteg(LPCWSTR lpSHA1Hash, LPCWSTR lpFileName)
WCHAR buf[(sizeof(sha) * 2) + 1];
for (UINT i = 0; i < sizeof(sha); i++)
swprintf(buf + 2 * i, L"%02x", ((unsigned char *) sha)[i]);
swprintf(buf + 2 * i, L"%02x", ((unsigned char *)sha)[i]);
/* does the resulting SHA1 match with the provided one? */
if (!_wcsicmp(buf, lpSHA1Hash))
ret = TRUE;

View file

@ -10,7 +10,7 @@
* Copyright 2017 Alexander Shaposhnikov (sanchaez@reactos.org)
*/
/*
/*
* Based on Wine dlls/shdocvw/shdocvw_main.c
*
* This library is free software; you can redistribute it and/or
@ -55,7 +55,6 @@
#define CERT_SUBJECT_INFO "rapps.reactos.org"
#endif
enum DownloadType
{
DLTYPE_APPLICATION,
@ -73,35 +72,37 @@ enum DownloadStatus
DLSTATUS_FINISHED = IDS_STATUS_FINISHED
};
ATL::CStringW LoadStatusString(DownloadStatus StatusParam)
CStringW
LoadStatusString(DownloadStatus StatusParam)
{
ATL::CStringW szString;
CStringW szString;
szString.LoadStringW(StatusParam);
return szString;
}
struct DownloadInfo
{
DownloadInfo() {}
DownloadInfo(const CAvailableApplicationInfo& AppInfo)
: DLType(DLTYPE_APPLICATION)
, szUrl(AppInfo.m_szUrlDownload)
, szName(AppInfo.m_szName)
, szSHA1(AppInfo.m_szSHA1)
, SizeInBytes(AppInfo.m_SizeBytes)
DownloadInfo()
{
}
DownloadInfo(const CApplicationInfo &AppInfo) : DLType(DLTYPE_APPLICATION)
{
AppInfo.GetDownloadInfo(szUrl, szSHA1, SizeInBytes);
szName = AppInfo.szDisplayName;
}
DownloadType DLType;
ATL::CStringW szUrl;
ATL::CStringW szName;
ATL::CStringW szSHA1;
CStringW szUrl;
CStringW szName;
CStringW szSHA1;
ULONG SizeInBytes;
};
struct DownloadParam
{
DownloadParam() : Dialog(NULL), AppInfo(), szCaption(NULL) {}
DownloadParam() : Dialog(NULL), AppInfo(), szCaption(NULL)
{
}
DownloadParam(HWND dlg, const ATL::CSimpleArray<DownloadInfo> &info, LPCWSTR caption)
: Dialog(dlg), AppInfo(info), szCaption(caption)
{
@ -112,18 +113,17 @@ struct DownloadParam
LPCWSTR szCaption;
};
class CDownloaderProgress
: public CWindowImpl<CDownloaderProgress, CWindow, CControlWinTraits>
class CDownloaderProgress : public CWindowImpl<CDownloaderProgress, CWindow, CControlWinTraits>
{
ATL::CStringW m_szProgressText;
CStringW m_szProgressText;
public:
public:
CDownloaderProgress()
{
}
VOID SetMarquee(BOOL Enable)
VOID
SetMarquee(BOOL Enable)
{
if (Enable)
ModifyStyle(0, PBS_MARQUEE, 0);
@ -133,7 +133,8 @@ public:
SendMessage(PBM_SETMARQUEE, Enable, 0);
}
VOID SetProgress(ULONG ulProgress, ULONG ulProgressMax)
VOID
SetProgress(ULONG ulProgress, ULONG ulProgressMax)
{
WCHAR szProgress[100];
@ -141,31 +142,30 @@ public:
StrFormatByteSizeW(ulProgress, szProgress, _countof(szProgress));
/* use our subclassed progress bar text subroutine */
ATL::CStringW ProgressText;
CStringW ProgressText;
if (ulProgressMax)
{
/* total size is known */
WCHAR szProgressMax[100];
UINT uiPercentage = ((ULONGLONG) ulProgress * 100) / ulProgressMax;
UINT uiPercentage = ((ULONGLONG)ulProgress * 100) / ulProgressMax;
/* send the current progress to the progress bar */
if (!IsWindow()) return;
if (!IsWindow())
return;
SendMessage(PBM_SETPOS, uiPercentage, 0);
/* format total download size */
StrFormatByteSizeW(ulProgressMax, szProgressMax, _countof(szProgressMax));
/* generate the text on progress bar */
ProgressText.Format(L"%u%% \x2014 %ls / %ls",
uiPercentage,
szProgress,
szProgressMax);
ProgressText.Format(L"%u%% \x2014 %ls / %ls", uiPercentage, szProgress, szProgressMax);
}
else
{
/* send the current progress to the progress bar */
if (!IsWindow()) return;
if (!IsWindow())
return;
SendMessage(PBM_SETPOS, 0, 0);
/* total size is not known, display only current size */
@ -173,16 +173,19 @@ public:
}
/* and finally display it */
if (!IsWindow()) return;
if (!IsWindow())
return;
SetWindowText(ProgressText.GetString());
}
LRESULT OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
LRESULT
OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
{
return TRUE;
}
LRESULT OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
LRESULT
OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
{
PAINTSTRUCT ps;
HDC hDC = BeginPaint(&ps), hdcMem;
@ -204,16 +207,14 @@ public:
hOld = SelectObject(hdcMem, hbmMem);
/* call the original draw code and redirect it to our memory buffer */
DefWindowProc(uMsg, (WPARAM) hdcMem, lParam);
DefWindowProc(uMsg, (WPARAM)hdcMem, lParam);
/* draw our nifty progress text over it */
SelectFont(hdcMem, GetStockFont(DEFAULT_GUI_FONT));
DrawShadowText(hdcMem, m_szProgressText.GetString(), m_szProgressText.GetLength(),
&myRect,
DT_CENTER | DT_VCENTER | DT_NOPREFIX | DT_SINGLELINE,
GetSysColor(COLOR_CAPTIONTEXT),
GetSysColor(COLOR_3DDKSHADOW),
1, 1);
DrawShadowText(
hdcMem, m_szProgressText.GetString(), m_szProgressText.GetLength(), &myRect,
DT_CENTER | DT_VCENTER | DT_NOPREFIX | DT_SINGLELINE, GetSysColor(COLOR_CAPTIONTEXT),
GetSysColor(COLOR_3DDKSHADOW), 1, 1);
/* transfer the off-screen DC to the screen */
BitBlt(hDC, 0, 0, win_width, win_height, hdcMem, 0, 0, SRCCOPY);
@ -227,7 +228,8 @@ public:
return 0;
}
LRESULT OnSetText(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
LRESULT
OnSetText(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
{
PCWSTR pszText = (PCWSTR)lParam;
if (pszText)
@ -256,15 +258,15 @@ public:
END_MSG_MAP()
};
class CDowloadingAppsListView
: public CListView
class CDowloadingAppsListView : public CListView
{
public:
HWND Create(HWND hwndParent)
public:
HWND
Create(HWND hwndParent)
{
RECT r = {10, 150, 320, 350};
const DWORD style = WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_SINGLESEL
| LVS_SHOWSELALWAYS | LVS_NOSORTHEADER | LVS_NOCOLUMNHEADER;
const DWORD style = WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_NOSORTHEADER |
LVS_NOCOLUMNHEADER;
HWND hwnd = CListView::Create(hwndParent, r, NULL, style, WS_EX_CLIENTEDGE);
@ -274,7 +276,8 @@ public:
return hwnd;
}
VOID LoadList(ATL::CSimpleArray<DownloadInfo> arrInfo)
VOID
LoadList(ATL::CSimpleArray<DownloadInfo> arrInfo)
{
for (INT i = 0; i < arrInfo.GetSize(); ++i)
{
@ -282,13 +285,15 @@ public:
}
}
VOID SetDownloadStatus(INT ItemIndex, DownloadStatus Status)
VOID
SetDownloadStatus(INT ItemIndex, DownloadStatus Status)
{
ATL::CStringW szBuffer = LoadStatusString(Status);
CStringW szBuffer = LoadStatusString(Status);
SetItemText(ItemIndex, 1, szBuffer.GetString());
}
BOOL AddItem(INT ItemIndex, LPWSTR lpText)
BOOL
AddItem(INT ItemIndex, LPWSTR lpText)
{
LVITEMW Item;
@ -301,15 +306,16 @@ public:
return InsertItem(&Item);
}
VOID AddRow(INT RowIndex, LPCWSTR szAppName, const DownloadStatus Status)
VOID
AddRow(INT RowIndex, LPCWSTR szAppName, const DownloadStatus Status)
{
ATL::CStringW szStatus = LoadStatusString(Status);
AddItem(RowIndex,
const_cast<LPWSTR>(szAppName));
CStringW szStatus = LoadStatusString(Status);
AddItem(RowIndex, const_cast<LPWSTR>(szAppName));
SetDownloadStatus(RowIndex, Status);
}
BOOL AddColumn(INT Index, INT Width, INT Format)
BOOL
AddColumn(INT Index, INT Width, INT Format)
{
LVCOLUMNW Column;
ZeroMemory(&Column, sizeof(Column));
@ -324,7 +330,8 @@ public:
};
#ifdef USE_CERT_PINNING
static BOOL CertGetSubjectAndIssuer(HINTERNET hFile, CLocalPtr<char>& subjectInfo, CLocalPtr<char>& issuerInfo)
static BOOL
CertGetSubjectAndIssuer(HINTERNET hFile, CLocalPtr<char> &subjectInfo, CLocalPtr<char> &issuerInfo)
{
DWORD certInfoLength;
INTERNET_CERTIFICATE_INFOA certInfo;
@ -343,10 +350,7 @@ static BOOL CertGetSubjectAndIssuer(HINTERNET hFile, CLocalPtr<char>& subjectInf
/* Despite what the header indicates, the implementation of INTERNET_CERTIFICATE_INFO is not Unicode-aware. */
certInfoLength = sizeof(certInfo);
if (!InternetQueryOptionA(hFile,
INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT,
&certInfo,
&certInfoLength))
if (!InternetQueryOptionA(hFile, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, &certInfo, &certInfoLength))
{
return FALSE;
}
@ -365,9 +369,10 @@ static BOOL CertGetSubjectAndIssuer(HINTERNET hFile, CLocalPtr<char>& subjectInf
}
#endif
inline VOID MessageBox_LoadString(HWND hMainWnd, INT StringID)
inline VOID
MessageBox_LoadString(HWND hMainWnd, INT StringID)
{
ATL::CStringW szMsgText;
CStringW szMsgText;
if (szMsgText.LoadStringW(StringID))
{
MessageBoxW(hMainWnd, szMsgText.GetString(), NULL, MB_OK | MB_ICONERROR);
@ -382,16 +387,21 @@ class CDownloadManager
static CDownloaderProgress ProgressBar;
static BOOL bCancelled;
static BOOL bModal;
static VOID UpdateProgress(HWND hDlg, ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText);
public:
static VOID Add(DownloadInfo info);
static VOID Download(const DownloadInfo& DLInfo, BOOL bIsModal = FALSE);
static INT_PTR CALLBACK DownloadDlgProc(HWND Dlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
static unsigned int WINAPI ThreadFunc(LPVOID Context);
static VOID
UpdateProgress(HWND hDlg, ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText);
public:
static VOID
Add(DownloadInfo info);
static VOID
Download(const DownloadInfo &DLInfo, BOOL bIsModal = FALSE);
static INT_PTR CALLBACK
DownloadDlgProc(HWND Dlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
static unsigned int WINAPI
ThreadFunc(LPVOID Context);
static VOID LaunchDownloadDialog(BOOL);
};
// CDownloadManager
ATL::CSimpleArray<DownloadInfo> CDownloadManager::AppsDownloadList;
CDowloadingAppsListView CDownloadManager::DownloadsListView;
@ -399,19 +409,22 @@ CDownloaderProgress CDownloadManager::ProgressBar;
BOOL CDownloadManager::bCancelled = FALSE;
BOOL CDownloadManager::bModal = FALSE;
VOID CDownloadManager::Add(DownloadInfo info)
VOID
CDownloadManager::Add(DownloadInfo info)
{
AppsDownloadList.Add(info);
}
VOID CDownloadManager::Download(const DownloadInfo &DLInfo, BOOL bIsModal)
VOID
CDownloadManager::Download(const DownloadInfo &DLInfo, BOOL bIsModal)
{
AppsDownloadList.RemoveAll();
AppsDownloadList.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];
@ -420,7 +433,7 @@ INT_PTR CALLBACK CDownloadManager::DownloadDlgProc(HWND Dlg, UINT uMsg, WPARAM w
case WM_INITDIALOG:
{
HICON hIconSm, hIconBg;
ATL::CStringW szTempCaption;
CStringW szTempCaption;
bCancelled = FALSE;
@ -474,7 +487,7 @@ INT_PTR CALLBACK CDownloadManager::DownloadDlgProc(HWND Dlg, UINT uMsg, WPARAM w
// Start download process
DownloadParam *param = new DownloadParam(Dlg, AppsDownloadList, szCaption);
unsigned int ThreadId;
HANDLE Thread = (HANDLE)_beginthreadex(NULL, 0, ThreadFunc, (void *) param, 0, &ThreadId);
HANDLE Thread = (HANDLE)_beginthreadex(NULL, 0, ThreadFunc, (void *)param, 0, &ThreadId);
if (!Thread)
{
return FALSE;
@ -513,7 +526,8 @@ INT_PTR CALLBACK CDownloadManager::DownloadDlgProc(HWND Dlg, UINT uMsg, WPARAM w
BOOL UrlHasBeenCopied;
VOID CDownloadManager::UpdateProgress(
VOID
CDownloadManager::UpdateProgress(
HWND hDlg,
ULONG ulProgress,
ULONG ulProgressMax,
@ -522,15 +536,17 @@ VOID CDownloadManager::UpdateProgress(
{
HWND Item;
if (!IsWindow(hDlg)) return;
if (!IsWindow(hDlg))
return;
ProgressBar.SetProgress(ulProgress, ulProgressMax);
if (!IsWindow(hDlg)) return;
if (!IsWindow(hDlg))
return;
Item = GetDlgItem(hDlg, IDC_DOWNLOAD_STATUS);
if (Item && szStatusText && wcslen(szStatusText) > 0 && UrlHasBeenCopied == FALSE)
{
SIZE_T len = wcslen(szStatusText) + 1;
ATL::CStringW buf;
CStringW buf;
DWORD dummyLen;
/* beautify our url for display purposes */
@ -551,21 +567,16 @@ VOID CDownloadManager::UpdateProgress(
}
}
BOOL ShowLastError(
HWND hWndOwner,
BOOL bInetError,
DWORD dwLastError)
BOOL
ShowLastError(HWND hWndOwner, BOOL bInetError, DWORD dwLastError)
{
CLocalPtr<WCHAR> lpMsg;
if (!FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_IGNORE_INSERTS |
if (!FormatMessageW(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS |
(bInetError ? FORMAT_MESSAGE_FROM_HMODULE : FORMAT_MESSAGE_FROM_SYSTEM),
(bInetError ? GetModuleHandleW(L"wininet.dll") : NULL),
dwLastError,
LANG_USER_DEFAULT,
(LPWSTR)&lpMsg,
0, NULL))
(bInetError ? GetModuleHandleW(L"wininet.dll") : NULL), dwLastError, LANG_USER_DEFAULT, (LPWSTR)&lpMsg, 0,
NULL))
{
DPRINT1("FormatMessageW unexpected failure (err %d)\n", GetLastError());
return FALSE;
@ -575,12 +586,13 @@ BOOL ShowLastError(
return TRUE;
}
unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
unsigned int WINAPI
CDownloadManager::ThreadFunc(LPVOID param)
{
ATL::CStringW Path;
CPathW Path;
PWSTR p, q;
HWND hDlg = static_cast<DownloadParam*>(param)->Dialog;
HWND hDlg = static_cast<DownloadParam *>(param)->Dialog;
HWND Item;
INT iAppId;
@ -599,11 +611,12 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
URL_COMPONENTSW urlComponents;
size_t urlLength, filenameLength;
const ATL::CSimpleArray<DownloadInfo> &InfoArray = static_cast<DownloadParam*>(param)->AppInfo;
LPCWSTR szCaption = static_cast<DownloadParam*>(param)->szCaption;
ATL::CStringW szNewCaption;
const ATL::CSimpleArray<DownloadInfo> &InfoArray = static_cast<DownloadParam *>(param)->AppInfo;
LPCWSTR szCaption = static_cast<DownloadParam *>(param)->szCaption;
CStringW szNewCaption;
const DWORD dwUrlConnectFlags = INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_KEEP_CONNECTION;
const DWORD dwUrlConnectFlags =
INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_KEEP_CONNECTION;
if (InfoArray.GetSize() <= 0)
{
@ -614,7 +627,8 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
for (iAppId = 0; iAppId < InfoArray.GetSize(); ++iAppId)
{
// Reset progress bar
if (!IsWindow(hDlg)) break;
if (!IsWindow(hDlg))
break;
Item = GetDlgItem(hDlg, IDC_DOWNLOAD_PROGRESS);
if (Item)
{
@ -638,7 +652,7 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
}
// Change caption to show the currently downloaded app
switch(InfoArray[iAppId].DLType)
switch (InfoArray[iAppId].DLType)
{
case DLTYPE_APPLICATION:
szNewCaption.Format(szCaption, InfoArray[iAppId].szName.GetString());
@ -651,7 +665,8 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
break;
}
if (!IsWindow(hDlg)) goto end;
if (!IsWindow(hDlg))
goto end;
SetWindowTextW(hDlg, szNewCaption.GetString());
// build the path for the download
@ -674,31 +689,28 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
filenameLength -= wcslen(q - 1) * sizeof(WCHAR);
// is the path valid? can we access it?
if (GetFileAttributesW(Path.GetString()) == INVALID_FILE_ATTRIBUTES)
if (GetFileAttributesW(Path) == INVALID_FILE_ATTRIBUTES)
{
if (!CreateDirectoryW(Path.GetString(), NULL))
if (!CreateDirectoryW(Path, NULL))
{
ShowLastError(hMainWnd, FALSE, GetLastError());
goto end;
}
}
// append a \ to the provided file system path, and the filename portion from the URL after that
PathAddBackslashW(Path.GetBuffer(MAX_PATH));
switch (InfoArray[iAppId].DLType)
{
case DLTYPE_DBUPDATE:
case DLTYPE_DBUPDATE_UNOFFICIAL:
PathAppendW(Path.GetBuffer(), APPLICATION_DATABASE_NAME);
Path += APPLICATION_DATABASE_NAME;
break;
case DLTYPE_APPLICATION:
PathAppendW(Path.GetBuffer(), (LPWSTR)(p + 1)); // use the filename retrieved from URL
Path += (LPWSTR)(p + 1); // use the filename retrieved from URL
break;
}
Path.ReleaseBuffer();
if ((InfoArray[iAppId].DLType == DLTYPE_APPLICATION) && InfoArray[iAppId].szSHA1[0] && GetFileAttributesW(Path.GetString()) != INVALID_FILE_ATTRIBUTES)
if ((InfoArray[iAppId].DLType == DLTYPE_APPLICATION) && InfoArray[iAppId].szSHA1[0] &&
GetFileAttributesW(Path) != INVALID_FILE_ATTRIBUTES)
{
// only open it in case of total correctness
if (VerifyInteg(InfoArray[iAppId].szSHA1.GetString(), Path))
@ -706,7 +718,8 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
}
// Add the download URL
if (!IsWindow(hDlg)) goto end;
if (!IsWindow(hDlg))
goto end;
SetDlgItemTextW(hDlg, IDC_DOWNLOAD_STATUS, InfoArray[iAppId].szUrl.GetString());
DownloadsListView.SetDownloadStatus(iAppId, DLSTATUS_DOWNLOADING);
@ -726,7 +739,8 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
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);
hOpen = InternetOpenW(
lpszAgent, INTERNET_OPEN_TYPE_PROXY, SettingsInfo.szProxyServer, SettingsInfo.szNoProxyFor, 0);
break;
}
@ -743,7 +757,7 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
urlLength = InfoArray[iAppId].szUrl.GetLength();
urlComponents.dwSchemeLength = urlLength + 1;
urlComponents.lpszScheme = (LPWSTR) malloc(urlComponents.dwSchemeLength * sizeof(WCHAR));
urlComponents.lpszScheme = (LPWSTR)malloc(urlComponents.dwSchemeLength * sizeof(WCHAR));
if (!InternetCrackUrlW(InfoArray[iAppId].szUrl, urlLength + 1, ICU_DECODE | ICU_ESCAPE, &urlComponents))
{
@ -753,12 +767,9 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
dwContentLen = 0;
if (urlComponents.nScheme == INTERNET_SCHEME_HTTP ||
urlComponents.nScheme == INTERNET_SCHEME_HTTPS)
if (urlComponents.nScheme == INTERNET_SCHEME_HTTP || urlComponents.nScheme == INTERNET_SCHEME_HTTPS)
{
hFile = InternetOpenUrlW(hOpen, InfoArray[iAppId].szUrl.GetString(), NULL, 0,
dwUrlConnectFlags,
0);
hFile = InternetOpenUrlW(hOpen, InfoArray[iAppId].szUrl.GetString(), NULL, 0, dwUrlConnectFlags, 0);
if (!hFile)
{
if (!ShowLastError(hMainWnd, TRUE, GetLastError()))
@ -783,14 +794,14 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
}
// query content length
HttpQueryInfoW(hFile, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &dwContentLen, &dwStatusLen, NULL);
HttpQueryInfoW(
hFile, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &dwContentLen, &dwStatusLen, NULL);
}
else if (urlComponents.nScheme == INTERNET_SCHEME_FTP)
{
// force passive mode on FTP
hFile = InternetOpenUrlW(hOpen, InfoArray[iAppId].szUrl, NULL, 0,
dwUrlConnectFlags | INTERNET_FLAG_PASSIVE,
0);
hFile =
InternetOpenUrlW(hOpen, InfoArray[iAppId].szUrl, NULL, 0, dwUrlConnectFlags | INTERNET_FLAG_PASSIVE, 0);
if (!hFile)
{
if (!ShowLastError(hMainWnd, TRUE, GetLastError()))
@ -847,8 +858,7 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
#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) &&
(InfoArray[iAppId].DLType == DLTYPE_DBUPDATE))
if ((urlComponents.nScheme == INTERNET_SCHEME_HTTPS) && (InfoArray[iAppId].DLType == DLTYPE_DBUPDATE))
{
CLocalPtr<char> subjectName, issuerName;
CStringA szMsgText;
@ -861,10 +871,9 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
else
{
if (strcmp(subjectName, CERT_SUBJECT_INFO) ||
(strcmp(issuerName, CERT_ISSUER_INFO_OLD) &&
strcmp(issuerName, CERT_ISSUER_INFO_NEW)))
(strcmp(issuerName, CERT_ISSUER_INFO_OLD) && strcmp(issuerName, CERT_ISSUER_INFO_NEW)))
{
szMsgText.Format(IDS_MISMATCH_CERT_INFO, (char*)subjectName, (const char*)issuerName);
szMsgText.Format(IDS_MISMATCH_CERT_INFO, (char *)subjectName, (const char *)issuerName);
bAskQuestion = true;
}
}
@ -879,7 +888,7 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
}
#endif
hOut = CreateFileW(Path.GetString(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, NULL);
hOut = CreateFileW(Path, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, NULL);
if (hOut == INVALID_HANDLE_VALUE)
{
@ -903,7 +912,8 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
}
dwCurrentBytesRead += dwBytesRead;
if (!IsWindow(hDlg)) goto end;
if (!IsWindow(hDlg))
goto end;
UpdateProgress(hDlg, dwCurrentBytesRead, dwContentLen, 0, InfoArray[iAppId].szUrl.GetString());
} while (dwBytesRead && !bCancelled);
@ -922,7 +932,8 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
ProgressBar.SetMarquee(FALSE);
dwContentLen = dwCurrentBytesRead;
if (!IsWindow(hDlg)) goto end;
if (!IsWindow(hDlg))
goto end;
UpdateProgress(hDlg, dwCurrentBytesRead, dwContentLen, 0, InfoArray[iAppId].szUrl.GetString());
}
@ -930,7 +941,7 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
verify its integrity by using the native advapi32.A_SHA1 functions */
if ((InfoArray[iAppId].DLType == DLTYPE_APPLICATION) && InfoArray[iAppId].szSHA1[0] != 0)
{
ATL::CStringW szMsgText;
CStringW szMsgText;
// change a few strings in the download dialog to reflect the verification process
if (!szMsgText.LoadStringW(IDS_INTEG_CHECK_TITLE))
@ -939,12 +950,13 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
goto end;
}
if (!IsWindow(hDlg)) goto end;
if (!IsWindow(hDlg))
goto end;
SetWindowTextW(hDlg, szMsgText.GetString());
::SetDlgItemText(hDlg, IDC_DOWNLOAD_STATUS, Path.GetString());
::SetDlgItemTextW(hDlg, IDC_DOWNLOAD_STATUS, Path);
// this may take a while, depending on the file size
if (!VerifyInteg(InfoArray[iAppId].szSHA1.GetString(), Path.GetString()))
if (!VerifyInteg(InfoArray[iAppId].szSHA1.GetString(), Path))
{
if (!szMsgText.LoadStringW(IDS_INTEG_CHECK_FAIL))
{
@ -952,13 +964,14 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param)
goto end;
}
if (!IsWindow(hDlg)) goto end;
if (!IsWindow(hDlg))
goto end;
MessageBoxW(hDlg, szMsgText.GetString(), NULL, MB_OK | MB_ICONERROR);
goto end;
}
}
run:
run:
DownloadsListView.SetDownloadStatus(iAppId, DLSTATUS_WAITING_INSTALL);
// run it
@ -968,7 +981,7 @@ run:
shExInfo.cbSize = sizeof(shExInfo);
shExInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
shExInfo.lpVerb = L"open";
shExInfo.lpFile = Path.GetString();
shExInfo.lpFile = Path;
shExInfo.lpParameters = L"";
shExInfo.nShow = SW_SHOW;
@ -977,15 +990,16 @@ run:
if (ShellExecuteExW(&shExInfo))
{
//reflect installation progress in the titlebar
//TODO: make a separate string with a placeholder to include app name?
ATL::CStringW szMsgText = LoadStatusString(DLSTATUS_INSTALLING);
if (!IsWindow(hDlg)) goto end;
// reflect installation progress in the titlebar
// TODO: make a separate string with a placeholder to include app name?
CStringW szMsgText = LoadStatusString(DLSTATUS_INSTALLING);
if (!IsWindow(hDlg))
goto end;
SetWindowTextW(hDlg, szMsgText.GetString());
DownloadsListView.SetDownloadStatus(iAppId, DLSTATUS_INSTALLING);
//TODO: issue an install operation separately so that the apps could be downloaded in the background
// TODO: issue an install operation separately so that the apps could be downloaded in the background
WaitForSingleObject(shExInfo.hProcess, INFINITE);
CloseHandle(shExInfo.hProcess);
}
@ -995,7 +1009,7 @@ run:
}
}
end:
end:
if (hOut != INVALID_HANDLE_VALUE)
CloseHandle(hOut);
@ -1006,50 +1020,48 @@ end:
if (bTempfile)
{
if (bCancelled || (SettingsInfo.bDelInstaller && (InfoArray[iAppId].DLType == DLTYPE_APPLICATION)))
DeleteFileW(Path.GetString());
DeleteFileW(Path);
}
if (!IsWindow(hDlg)) return 0;
if (!IsWindow(hDlg))
return 0;
DownloadsListView.SetDownloadStatus(iAppId, DLSTATUS_FINISHED);
}
delete static_cast<DownloadParam*>(param);
if (!IsWindow(hDlg)) return 0;
delete static_cast<DownloadParam *>(param);
if (!IsWindow(hDlg))
return 0;
SendMessageW(hDlg, WM_CLOSE, 0, 0);
return 0;
}
//TODO: Reuse the dialog
VOID CDownloadManager::LaunchDownloadDialog(BOOL bIsModal)
// TODO: Reuse the dialog
VOID
CDownloadManager::LaunchDownloadDialog(BOOL bIsModal)
{
CDownloadManager::bModal = bIsModal;
if (bIsModal)
{
DialogBoxW(hInst,
MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG),
hMainWnd,
DownloadDlgProc);
DialogBoxW(hInst, MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG), hMainWnd, DownloadDlgProc);
}
else
{
CreateDialogW(hInst,
MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG),
hMainWnd,
DownloadDlgProc);
CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG), hMainWnd, DownloadDlgProc);
}
}
// CDownloadManager
BOOL DownloadListOfApplications(const ATL::CSimpleArray<CAvailableApplicationInfo>& AppsList, BOOL bIsModal)
BOOL
DownloadListOfApplications(const CAtlList<CApplicationInfo *> &AppsList, BOOL bIsModal)
{
if (AppsList.GetSize() == 0)
if (AppsList.IsEmpty())
return FALSE;
// Initialize shared variables
for (INT i = 0; i < AppsList.GetSize(); ++i)
POSITION CurrentListPosition = AppsList.GetHeadPosition();
while (CurrentListPosition)
{
CDownloadManager::Add(AppsList[i]); // implicit conversion to DownloadInfo
const CApplicationInfo *Info = AppsList.GetNext(CurrentListPosition);
CDownloadManager::Add(DownloadInfo(*Info));
}
// Create a dialog and issue a download process
@ -1058,7 +1070,8 @@ BOOL DownloadListOfApplications(const ATL::CSimpleArray<CAvailableApplicationInf
return TRUE;
}
BOOL DownloadApplication(CAvailableApplicationInfo* pAppInfo)
BOOL
DownloadApplication(CApplicationInfo *pAppInfo)
{
if (!pAppInfo)
return FALSE;
@ -1067,7 +1080,8 @@ BOOL DownloadApplication(CAvailableApplicationInfo* pAppInfo)
return TRUE;
}
VOID DownloadApplicationsDB(LPCWSTR lpUrl, BOOL IsOfficial)
VOID
DownloadApplicationsDB(LPCWSTR lpUrl, BOOL IsOfficial)
{
static DownloadInfo DatabaseDLInfo;
DatabaseDLInfo.szUrl = lpUrl;
@ -1075,4 +1089,3 @@ VOID DownloadApplicationsDB(LPCWSTR lpUrl, BOOL IsOfficial)
DatabaseDLInfo.DLType = IsOfficial ? DLTYPE_DBUPDATE : DLTYPE_DBUPDATE_UNOFFICIAL;
CDownloadManager::Download(DatabaseDLInfo, TRUE);
}

View file

@ -15,7 +15,8 @@ static HANDLE hLog = NULL;
static BOOL bIsSys64ResultCached = FALSE;
static BOOL bIsSys64Result = FALSE;
VOID CopyTextToClipboard(LPCWSTR lpszText)
VOID
CopyTextToClipboard(LPCWSTR lpszText)
{
if (!OpenClipboard(NULL))
{
@ -31,7 +32,7 @@ VOID CopyTextToClipboard(LPCWSTR lpszText)
cchBuffer = wcslen(lpszText) + 1;
ClipBuffer = GlobalAlloc(GMEM_DDESHARE, cchBuffer * sizeof(WCHAR));
Buffer = (PWCHAR) GlobalLock(ClipBuffer);
Buffer = (PWCHAR)GlobalLock(ClipBuffer);
hr = StringCchCopyW(Buffer, cchBuffer, lpszText);
GlobalUnlock(ClipBuffer);
@ -41,7 +42,8 @@ VOID CopyTextToClipboard(LPCWSTR lpszText)
CloseClipboard();
}
VOID ShowPopupMenuEx(HWND hwnd, HWND hwndOwner, UINT MenuID, UINT DefaultItem)
VOID
ShowPopupMenuEx(HWND hwnd, HWND hwndOwner, UINT MenuID, UINT DefaultItem)
{
HMENU hMenu = NULL;
HMENU hPopupMenu;
@ -80,7 +82,8 @@ VOID ShowPopupMenuEx(HWND hwnd, HWND hwndOwner, UINT MenuID, UINT DefaultItem)
}
}
BOOL StartProcess(const ATL::CStringW& Path, BOOL Wait)
BOOL
StartProcess(const CStringW &Path, BOOL Wait)
{
PROCESS_INFORMATION pi;
STARTUPINFOW si;
@ -138,7 +141,8 @@ BOOL StartProcess(const ATL::CStringW& Path, BOOL Wait)
return TRUE;
}
BOOL GetStorageDirectory(ATL::CStringW& Directory)
BOOL
GetStorageDirectory(CStringW &Directory)
{
static CStringW CachedDirectory;
static BOOL CachedDirectoryInitialized = FALSE;
@ -172,7 +176,8 @@ BOOL GetStorageDirectory(ATL::CStringW& Directory)
return !Directory.IsEmpty();
}
VOID InitLogs()
VOID
InitLogs()
{
if (!SettingsInfo.bLogEnabled)
{
@ -184,9 +189,10 @@ VOID InitLogs()
DWORD dwDisp, dwData;
ATL::CRegKey key;
if (key.Create(HKEY_LOCAL_MACHINE,
L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\ReactOS Application Manager",
REG_NONE, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &dwDisp) != ERROR_SUCCESS)
if (key.Create(
HKEY_LOCAL_MACHINE,
L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\ReactOS Application Manager", REG_NONE,
REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &dwDisp) != ERROR_SUCCESS)
{
return;
}
@ -196,26 +202,20 @@ VOID InitLogs()
return;
}
dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE |
EVENTLOG_INFORMATION_TYPE;
dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
if ((key.SetStringValue(L"EventMessageFile",
szPath,
REG_EXPAND_SZ) == ERROR_SUCCESS)
&& (key.SetStringValue(L"CategoryMessageFile",
szPath,
REG_EXPAND_SZ) == ERROR_SUCCESS)
&& (key.SetDWORDValue(L"TypesSupported",
dwData) == ERROR_SUCCESS)
&& (key.SetDWORDValue(L"CategoryCount",
dwCategoryNum) == ERROR_SUCCESS))
if ((key.SetStringValue(L"EventMessageFile", szPath, REG_EXPAND_SZ) == ERROR_SUCCESS) &&
(key.SetStringValue(L"CategoryMessageFile", szPath, REG_EXPAND_SZ) == ERROR_SUCCESS) &&
(key.SetDWORDValue(L"TypesSupported", dwData) == ERROR_SUCCESS) &&
(key.SetDWORDValue(L"CategoryCount", dwCategoryNum) == ERROR_SUCCESS))
{
hLog = RegisterEventSourceW(NULL, L"ReactOS Application Manager");
}
}
VOID FreeLogs()
VOID
FreeLogs()
{
if (hLog)
{
@ -223,15 +223,15 @@ VOID FreeLogs()
}
}
BOOL WriteLogMessage(WORD wType, DWORD dwEventID, LPCWSTR lpMsg)
BOOL
WriteLogMessage(WORD wType, DWORD dwEventID, LPCWSTR lpMsg)
{
if (!SettingsInfo.bLogEnabled)
{
return TRUE;
}
if (!ReportEventW(hLog, wType, 0, dwEventID,
NULL, 1, 0, &lpMsg, NULL))
if (!ReportEventW(hLog, wType, 0, dwEventID, NULL, 1, 0, &lpMsg, NULL))
{
return FALSE;
}
@ -239,19 +239,16 @@ BOOL WriteLogMessage(WORD wType, DWORD dwEventID, LPCWSTR lpMsg)
return TRUE;
}
BOOL GetInstalledVersion_WowUser(ATL::CStringW* szVersionResult,
const ATL::CStringW& szRegName,
BOOL IsUserKey,
REGSAM keyWow)
BOOL
GetInstalledVersion_WowUser(CStringW *szVersionResult, const CStringW &szRegName, BOOL IsUserKey, REGSAM keyWow)
{
BOOL bHasSucceded = FALSE;
ATL::CRegKey key;
ATL::CStringW szVersion;
ATL::CStringW szPath = ATL::CStringW(L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\") + szRegName;
CStringW szVersion;
CStringW szPath = CStringW(L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\") + szRegName;
if (key.Open(IsUserKey ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE,
szPath.GetString(),
keyWow | KEY_READ) != ERROR_SUCCESS)
if (key.Open(IsUserKey ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, szPath.GetString(), keyWow | KEY_READ) !=
ERROR_SUCCESS)
{
return FALSE;
}
@ -260,9 +257,7 @@ BOOL GetInstalledVersion_WowUser(ATL::CStringW* szVersionResult,
{
ULONG dwSize = MAX_PATH * sizeof(WCHAR);
if (key.QueryStringValue(L"DisplayVersion",
szVersion.GetBuffer(MAX_PATH),
&dwSize) == ERROR_SUCCESS)
if (key.QueryStringValue(L"DisplayVersion", szVersion.GetBuffer(MAX_PATH), &dwSize) == ERROR_SUCCESS)
{
szVersion.ReleaseBuffer();
*szVersionResult = szVersion;
@ -276,67 +271,23 @@ BOOL GetInstalledVersion_WowUser(ATL::CStringW* szVersionResult,
else
{
bHasSucceded = TRUE;
szVersion.ReleaseBuffer();
}
return bHasSucceded;
}
BOOL GetInstalledVersion(ATL::CStringW *pszVersion, const ATL::CStringW &szRegName)
BOOL
GetInstalledVersion(CStringW *pszVersion, const CStringW &szRegName)
{
return (!szRegName.IsEmpty()
&& (GetInstalledVersion_WowUser(pszVersion, szRegName, TRUE, KEY_WOW64_32KEY)
|| GetInstalledVersion_WowUser(pszVersion, szRegName, FALSE, KEY_WOW64_32KEY)
|| GetInstalledVersion_WowUser(pszVersion, szRegName, TRUE, KEY_WOW64_64KEY)
|| GetInstalledVersion_WowUser(pszVersion, szRegName, FALSE, KEY_WOW64_64KEY)));
return (
!szRegName.IsEmpty() && (GetInstalledVersion_WowUser(pszVersion, szRegName, TRUE, KEY_WOW64_32KEY) ||
GetInstalledVersion_WowUser(pszVersion, szRegName, FALSE, KEY_WOW64_32KEY) ||
GetInstalledVersion_WowUser(pszVersion, szRegName, TRUE, KEY_WOW64_64KEY) ||
GetInstalledVersion_WowUser(pszVersion, szRegName, FALSE, KEY_WOW64_64KEY)));
}
BOOL PathAppendNoDirEscapeW(LPWSTR pszPath, LPCWSTR pszMore)
{
WCHAR pszPathBuffer[MAX_PATH]; // buffer to store result
WCHAR pszPathCopy[MAX_PATH];
if (!PathCanonicalizeW(pszPathCopy, pszPath))
{
return FALSE;
}
PathRemoveBackslashW(pszPathCopy);
if (StringCchCopyW(pszPathBuffer, _countof(pszPathBuffer), pszPathCopy) != S_OK)
{
return FALSE;
}
if (!PathAppendW(pszPathBuffer, pszMore))
{
return FALSE;
}
size_t PathLen;
if (StringCchLengthW(pszPathCopy, _countof(pszPathCopy), &PathLen) != S_OK)
{
return FALSE;
}
int CommonPrefixLen = PathCommonPrefixW(pszPathCopy, pszPathBuffer, NULL);
if ((unsigned int)CommonPrefixLen != PathLen)
{
// pszPathBuffer should be a file/folder under pszPath.
// but now common prefix len is smaller than length of pszPathCopy
// hacking use ".." ?
return FALSE;
}
if (StringCchCopyW(pszPath, MAX_PATH, pszPathBuffer) != S_OK)
{
return FALSE;
}
return TRUE;
}
BOOL IsSystem64Bit()
BOOL
IsSystem64Bit()
{
if (bIsSys64ResultCached)
{
@ -345,12 +296,14 @@ BOOL IsSystem64Bit()
}
SYSTEM_INFO si;
typedef void (WINAPI *LPFN_PGNSI)(LPSYSTEM_INFO);
LPFN_PGNSI pGetNativeSystemInfo = (LPFN_PGNSI)GetProcAddress(GetModuleHandle(L"kernel32.dll"), "GetNativeSystemInfo");
typedef void(WINAPI * LPFN_PGNSI)(LPSYSTEM_INFO);
LPFN_PGNSI pGetNativeSystemInfo =
(LPFN_PGNSI)GetProcAddress(GetModuleHandle(L"kernel32.dll"), "GetNativeSystemInfo");
if (pGetNativeSystemInfo)
{
pGetNativeSystemInfo(&si);
if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 || si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)
if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 ||
si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64)
{
bIsSys64Result = TRUE;
}
@ -364,7 +317,8 @@ BOOL IsSystem64Bit()
return bIsSys64Result;
}
INT GetSystemColorDepth()
INT
GetSystemColorDepth()
{
DEVMODEW pDevMode;
INT ColorDepth;
@ -380,18 +334,31 @@ INT GetSystemColorDepth()
switch (pDevMode.dmBitsPerPel)
{
case 32: ColorDepth = ILC_COLOR32; break;
case 24: ColorDepth = ILC_COLOR24; break;
case 16: ColorDepth = ILC_COLOR16; break;
case 8: ColorDepth = ILC_COLOR8; break;
case 4: ColorDepth = ILC_COLOR4; break;
default: ColorDepth = ILC_COLOR; break;
case 32:
ColorDepth = ILC_COLOR32;
break;
case 24:
ColorDepth = ILC_COLOR24;
break;
case 16:
ColorDepth = ILC_COLOR16;
break;
case 8:
ColorDepth = ILC_COLOR8;
break;
case 4:
ColorDepth = ILC_COLOR4;
break;
default:
ColorDepth = ILC_COLOR;
break;
}
return ColorDepth;
}
void UnixTimeToFileTime(DWORD dwUnixTime, LPFILETIME pFileTime)
void
UnixTimeToFileTime(DWORD dwUnixTime, LPFILETIME pFileTime)
{
// Note that LONGLONG is a 64-bit value
LONGLONG ll;
@ -401,7 +368,8 @@ void UnixTimeToFileTime(DWORD dwUnixTime, LPFILETIME pFileTime)
pFileTime->dwHighDateTime = ll >> 32;
}
BOOL SearchPatternMatch(LPCWSTR szHaystack, LPCWSTR szNeedle)
BOOL
SearchPatternMatch(LPCWSTR szHaystack, LPCWSTR szNeedle)
{
if (!*szNeedle)
return TRUE;

View file

@ -11,25 +11,31 @@
class SettingsField
{
public:
virtual ~SettingsField() { ; }
virtual BOOL Save(CRegKey &key) = 0;
virtual BOOL Load(CRegKey &key) = 0;
public:
virtual ~SettingsField()
{
;
}
virtual BOOL
Save(CRegKey &key) = 0;
virtual BOOL
Load(CRegKey &key) = 0;
};
class SettingsFieldBool : public SettingsField
{
public:
SettingsFieldBool(BOOL *pValue, LPCWSTR szRegName)
: m_pValueStore(pValue), m_RegName(szRegName)
public:
SettingsFieldBool(BOOL *pValue, LPCWSTR szRegName) : m_pValueStore(pValue), m_RegName(szRegName)
{
}
virtual BOOL Save(CRegKey &key) override
virtual BOOL
Save(CRegKey &key) override
{
return key.SetDWORDValue(m_RegName, (DWORD)(*m_pValueStore)) == ERROR_SUCCESS;
}
virtual BOOL Load(CRegKey &key) override
virtual BOOL
Load(CRegKey &key) override
{
DWORD dwField;
LONG lResult = key.QueryDWORDValue(m_RegName, dwField);
@ -41,24 +47,25 @@ public:
return TRUE;
}
private:
private:
BOOL *m_pValueStore; // where to read/store the value
LPCWSTR m_RegName; // key name in registery
};
class SettingsFieldInt : public SettingsField
{
public:
SettingsFieldInt(INT *pValue, LPCWSTR szRegName)
: m_pValueStore(pValue), m_RegName(szRegName)
public:
SettingsFieldInt(INT *pValue, LPCWSTR szRegName) : m_pValueStore(pValue), m_RegName(szRegName)
{
}
virtual BOOL Save(CRegKey &key) override
virtual BOOL
Save(CRegKey &key) override
{
return key.SetDWORDValue(m_RegName, (DWORD)(*m_pValueStore)) == ERROR_SUCCESS;
}
virtual BOOL Load(CRegKey &key) override
virtual BOOL
Load(CRegKey &key) override
{
DWORD dwField;
LONG lResult = key.QueryDWORDValue(m_RegName, dwField);
@ -70,38 +77,40 @@ public:
return TRUE;
}
private:
private:
INT *m_pValueStore; // where to read/store the value
LPCWSTR m_RegName; // key name in registery
};
class SettingsFieldString : public SettingsField
{
public:
public:
SettingsFieldString(WCHAR *pString, ULONG cchLen, LPCWSTR szRegName)
: m_pStringStore(pString), m_StringLen(cchLen), m_RegName(szRegName)
{
}
virtual BOOL Save(CRegKey &key) override
virtual BOOL
Save(CRegKey &key) override
{
return key.SetStringValue(m_RegName, m_pStringStore) == ERROR_SUCCESS;
}
virtual BOOL Load(CRegKey &key) override
virtual BOOL
Load(CRegKey &key) override
{
ULONG nChar = m_StringLen - 1; // make sure the terminating L'\0'
LONG lResult = key.QueryStringValue(m_RegName, m_pStringStore, &nChar);
return lResult == ERROR_SUCCESS;
}
private:
private:
WCHAR *m_pStringStore; // where to read/store the value
ULONG m_StringLen; // string length, in chars
LPCWSTR m_RegName; // key name in registery
};
void AddInfoFields(ATL::CAtlList<SettingsField *> &infoFields, SETTINGS_INFO &settings)
void
AddInfoFields(ATL::CAtlList<SettingsField *> &infoFields, SETTINGS_INFO &settings)
{
infoFields.AddTail(new SettingsFieldBool(&(settings.bSaveWndPos), L"bSaveWndPos"));
infoFields.AddTail(new SettingsFieldBool(&(settings.bUpdateAtStart), L"bUpdateAtStart"));
@ -122,7 +131,8 @@ void AddInfoFields(ATL::CAtlList<SettingsField *> &infoFields, SETTINGS_INFO &se
return;
}
BOOL SaveAllSettings(CRegKey &key, SETTINGS_INFO &settings)
BOOL
SaveAllSettings(CRegKey &key, SETTINGS_INFO &settings)
{
BOOL bAllSuccess = TRUE;
ATL::CAtlList<SettingsField *> infoFields;
@ -143,7 +153,8 @@ BOOL SaveAllSettings(CRegKey &key, SETTINGS_INFO &settings)
return bAllSuccess;
}
BOOL LoadAllSettings(CRegKey &key, SETTINGS_INFO &settings)
BOOL
LoadAllSettings(CRegKey &key, SETTINGS_INFO &settings)
{
BOOL bAllSuccess = TRUE;
ATL::CAtlList<SettingsField *> infoFields;
@ -164,9 +175,10 @@ BOOL LoadAllSettings(CRegKey &key, SETTINGS_INFO &settings)
return bAllSuccess;
}
VOID FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
VOID
FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
{
ATL::CStringW szDownloadDir;
CStringW szDownloadDir;
ZeroMemory(pSettingsInfo, sizeof(SETTINGS_INFO));
pSettingsInfo->bSaveWndPos = TRUE;
@ -190,9 +202,8 @@ VOID FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
PathAppendW(szDownloadDir.GetBuffer(MAX_PATH), L"\\RAPPS Downloads");
szDownloadDir.ReleaseBuffer();
ATL::CStringW::CopyChars(pSettingsInfo->szDownloadDir,
_countof(pSettingsInfo->szDownloadDir),
szDownloadDir.GetString(),
CStringW::CopyChars(
pSettingsInfo->szDownloadDir, _countof(pSettingsInfo->szDownloadDir), szDownloadDir.GetString(),
szDownloadDir.GetLength() + 1);
pSettingsInfo->bDelInstaller = FALSE;
@ -203,7 +214,8 @@ VOID FillDefaultSettings(PSETTINGS_INFO pSettingsInfo)
pSettingsInfo->Height = 450;
}
BOOL LoadSettings(PSETTINGS_INFO pSettingsInfo)
BOOL
LoadSettings(PSETTINGS_INFO pSettingsInfo)
{
ATL::CRegKey RegKey;
if (RegKey.Open(HKEY_CURRENT_USER, L"Software\\ReactOS\\rapps", KEY_READ) != ERROR_SUCCESS)
@ -214,7 +226,8 @@ BOOL LoadSettings(PSETTINGS_INFO pSettingsInfo)
return LoadAllSettings(RegKey, *pSettingsInfo);
}
BOOL SaveSettings(HWND hwnd, PSETTINGS_INFO pSettingsInfo)
BOOL
SaveSettings(HWND hwnd, PSETTINGS_INFO pSettingsInfo)
{
WINDOWPLACEMENT wp;
ATL::CRegKey RegKey;
@ -228,13 +241,13 @@ BOOL SaveSettings(HWND hwnd, PSETTINGS_INFO pSettingsInfo)
pSettingsInfo->Top = wp.rcNormalPosition.top;
pSettingsInfo->Width = wp.rcNormalPosition.right - wp.rcNormalPosition.left;
pSettingsInfo->Height = wp.rcNormalPosition.bottom - wp.rcNormalPosition.top;
pSettingsInfo->Maximized = (wp.showCmd == SW_MAXIMIZE
|| (wp.showCmd == SW_SHOWMINIMIZED
&& (wp.flags & WPF_RESTORETOMAXIMIZED)));
pSettingsInfo->Maximized =
(wp.showCmd == SW_MAXIMIZE || (wp.showCmd == SW_SHOWMINIMIZED && (wp.flags & WPF_RESTORETOMAXIMIZED)));
}
if (RegKey.Create(HKEY_CURRENT_USER, L"Software\\ReactOS\\rapps", NULL,
REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, NULL) != ERROR_SUCCESS)
if (RegKey.Create(
HKEY_CURRENT_USER, L"Software\\ReactOS\\rapps", NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, NULL) !=
ERROR_SUCCESS)
{
return FALSE;
}

View file

@ -9,23 +9,25 @@
SETTINGS_INFO NewSettingsInfo;
BOOL ChooseFolder(HWND hwnd)
BOOL
ChooseFolder(HWND hwnd)
{
BOOL bRet = FALSE;
BROWSEINFOW bi;
ATL::CStringW szChooseFolderText;
CStringW szChooseFolderText;
szChooseFolderText.LoadStringW(IDS_CHOOSE_FOLDER_TEXT);
ZeroMemory(&bi, sizeof(bi));
bi.hwndOwner = hwnd;
bi.pidlRoot = NULL;
bi.lpszTitle = szChooseFolderText.GetString();
bi.ulFlags = BIF_USENEWUI | BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | /* BIF_BROWSEFILEJUNCTIONS | */ BIF_VALIDATE;
bi.lpszTitle = szChooseFolderText;
bi.ulFlags =
BIF_USENEWUI | BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | /* BIF_BROWSEFILEJUNCTIONS | */ BIF_VALIDATE;
if (SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)))
{
ATL::CStringW szBuf;
CStringW szBuf;
LPITEMIDLIST lpItemList = SHBrowseForFolderW(&bi);
if (lpItemList && SHGetPathFromIDListW(lpItemList, szBuf.GetBuffer(MAX_PATH)))
@ -33,7 +35,7 @@ BOOL ChooseFolder(HWND hwnd)
szBuf.ReleaseBuffer();
if (!szBuf.IsEmpty())
{
SetDlgItemTextW(hwnd, IDC_DOWNLOAD_DIR_EDIT, szBuf.GetString());
SetDlgItemTextW(hwnd, IDC_DOWNLOAD_DIR_EDIT, szBuf);
bRet = TRUE;
}
}
@ -49,19 +51,20 @@ BOOL ChooseFolder(HWND hwnd)
return bRet;
}
BOOL IsUrlValid(const WCHAR * Url)
BOOL
IsUrlValid(const WCHAR *Url)
{
URL_COMPONENTSW UrlComponmentInfo = { 0 };
URL_COMPONENTSW UrlComponmentInfo = {0};
UrlComponmentInfo.dwStructSize = sizeof(UrlComponmentInfo);
UrlComponmentInfo.dwSchemeLength = 1;
BOOL bSuccess = InternetCrackUrlW(Url, wcslen(Url), 0, &UrlComponmentInfo);
if(!bSuccess)
if (!bSuccess)
{
return FALSE;
}
switch(UrlComponmentInfo.nScheme)
switch (UrlComponmentInfo.nScheme)
{
case INTERNET_SCHEME_HTTP:
case INTERNET_SCHEME_HTTPS:
@ -77,20 +80,21 @@ BOOL IsUrlValid(const WCHAR * Url)
namespace
{
inline BOOL IsCheckedDlgItem(HWND hDlg, INT nIDDlgItem)
{
inline BOOL
IsCheckedDlgItem(HWND hDlg, INT nIDDlgItem)
{
return (SendDlgItemMessageW(hDlg, nIDDlgItem, BM_GETCHECK, 0, 0) == BST_CHECKED) ? TRUE : FALSE;
}
}
VOID InitSettingsControls(HWND hDlg, PSETTINGS_INFO Info)
{
VOID
InitSettingsControls(HWND hDlg, PSETTINGS_INFO Info)
{
SendDlgItemMessageW(hDlg, IDC_SAVE_WINDOW_POS, BM_SETCHECK, Info->bSaveWndPos, 0);
SendDlgItemMessageW(hDlg, IDC_UPDATE_AVLIST, BM_SETCHECK, Info->bUpdateAtStart, 0);
SendDlgItemMessageW(hDlg, IDC_LOG_ENABLED, BM_SETCHECK, Info->bLogEnabled, 0);
SendDlgItemMessageW(hDlg, IDC_DEL_AFTER_INSTALL, BM_SETCHECK, Info->bDelInstaller, 0);
SetWindowTextW(GetDlgItem(hDlg, IDC_DOWNLOAD_DIR_EDIT),
Info->szDownloadDir);
SetWindowTextW(GetDlgItem(hDlg, IDC_DOWNLOAD_DIR_EDIT), Info->szDownloadDir);
CheckRadioButton(hDlg, IDC_PROXY_DEFAULT, IDC_USE_PROXY, IDC_PROXY_DEFAULT + Info->Proxy);
@ -112,10 +116,11 @@ namespace
SetWindowTextW(GetDlgItem(hDlg, IDC_SOURCE_URL), Info->szSourceURL);
SetWindowTextW(GetDlgItem(hDlg, IDC_PROXY_SERVER), Info->szProxyServer);
SetWindowTextW(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), Info->szNoProxyFor);
}
}
INT_PTR CALLBACK SettingsDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
INT_PTR CALLBACK
SettingsDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch (Msg)
{
case WM_INITDIALOG:
@ -184,53 +189,47 @@ namespace
case IDOK:
{
ATL::CStringW szDir;
ATL::CStringW szSource;
ATL::CStringW szProxy;
ATL::CStringW szNoProxy;
CStringW szDir;
CStringW szSource;
CStringW szProxy;
CStringW szNoProxy;
DWORD dwAttr;
GetWindowTextW(GetDlgItem(hDlg, IDC_DOWNLOAD_DIR_EDIT),
szDir.GetBuffer(MAX_PATH), MAX_PATH);
GetWindowTextW(GetDlgItem(hDlg, IDC_DOWNLOAD_DIR_EDIT), szDir.GetBuffer(MAX_PATH), MAX_PATH);
szDir.ReleaseBuffer();
GetWindowTextW(GetDlgItem(hDlg, IDC_SOURCE_URL),
szSource.GetBuffer(INTERNET_MAX_URL_LENGTH), INTERNET_MAX_URL_LENGTH);
GetWindowTextW(
GetDlgItem(hDlg, IDC_SOURCE_URL), szSource.GetBuffer(INTERNET_MAX_URL_LENGTH),
INTERNET_MAX_URL_LENGTH);
szSource.ReleaseBuffer();
GetWindowTextW(GetDlgItem(hDlg, IDC_PROXY_SERVER),
szProxy.GetBuffer(MAX_PATH), MAX_PATH);
GetWindowTextW(GetDlgItem(hDlg, IDC_PROXY_SERVER), szProxy.GetBuffer(MAX_PATH), MAX_PATH);
szProxy.ReleaseBuffer();
ATL::CStringW::CopyChars(NewSettingsInfo.szProxyServer,
_countof(NewSettingsInfo.szProxyServer),
szProxy.GetString(),
CStringW::CopyChars(
NewSettingsInfo.szProxyServer, _countof(NewSettingsInfo.szProxyServer), szProxy,
szProxy.GetLength() + 1);
GetWindowTextW(GetDlgItem(hDlg, IDC_NO_PROXY_FOR),
szNoProxy.GetBuffer(MAX_PATH), MAX_PATH);
GetWindowTextW(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), szNoProxy.GetBuffer(MAX_PATH), MAX_PATH);
szNoProxy.ReleaseBuffer();
ATL::CStringW::CopyChars(NewSettingsInfo.szNoProxyFor,
_countof(NewSettingsInfo.szNoProxyFor),
szNoProxy.GetString(),
CStringW::CopyChars(
NewSettingsInfo.szNoProxyFor, _countof(NewSettingsInfo.szNoProxyFor), szNoProxy,
szNoProxy.GetLength() + 1);
dwAttr = GetFileAttributesW(szDir.GetString());
if (dwAttr != INVALID_FILE_ATTRIBUTES &&
(dwAttr & FILE_ATTRIBUTE_DIRECTORY))
dwAttr = GetFileAttributesW(szDir);
if (dwAttr != INVALID_FILE_ATTRIBUTES && (dwAttr & FILE_ATTRIBUTE_DIRECTORY))
{
ATL::CStringW::CopyChars(NewSettingsInfo.szDownloadDir,
_countof(NewSettingsInfo.szDownloadDir),
szDir.GetString(),
CStringW::CopyChars(
NewSettingsInfo.szDownloadDir, _countof(NewSettingsInfo.szDownloadDir), szDir,
szDir.GetLength() + 1);
}
else
{
ATL::CStringW szMsgText;
CStringW szMsgText;
szMsgText.LoadStringW(IDS_CHOOSE_FOLDER_ERROR);
if (MessageBoxW(hDlg, szMsgText.GetString(), NULL, MB_YESNO) == IDYES)
if (MessageBoxW(hDlg, szMsgText, NULL, MB_YESNO) == IDYES)
{
if (CreateDirectoryW(szDir.GetString(), NULL))
if (CreateDirectoryW(szDir, NULL))
{
EndDialog(hDlg, LOWORD(wParam));
}
@ -242,21 +241,19 @@ namespace
}
}
if(NewSettingsInfo.bUseSource && !IsUrlValid(szSource.GetString()))
if (NewSettingsInfo.bUseSource && !IsUrlValid(szSource))
{
ATL::CStringW szMsgText;
CStringW szMsgText;
szMsgText.LoadStringW(IDS_URL_INVALID);
MessageBoxW(hDlg, szMsgText.GetString(), NULL, 0);
MessageBoxW(hDlg, szMsgText, NULL, 0);
SetFocus(GetDlgItem(hDlg, IDC_SOURCE_URL));
break;
}
else
{
ATL::CStringW::CopyChars(NewSettingsInfo.szSourceURL,
_countof(NewSettingsInfo.szSourceURL),
szSource.GetString(),
CStringW::CopyChars(
NewSettingsInfo.szSourceURL, _countof(NewSettingsInfo.szSourceURL), szSource,
szSource.GetLength() + 1);
}
@ -275,13 +272,11 @@ namespace
}
return FALSE;
}
}
} // namespace
VOID CreateSettingsDlg(HWND hwnd)
VOID
CreateSettingsDlg(HWND hwnd)
{
DialogBoxW(hInst,
MAKEINTRESOURCEW(IDD_SETTINGS_DIALOG),
hwnd,
SettingsDlgProc);
DialogBoxW(hInst, MAKEINTRESOURCEW(IDD_SETTINGS_DIALOG), hwnd, SettingsDlgProc);
}

View file

@ -12,9 +12,10 @@
#include <setupapi.h>
#include <conutils.h>
BOOL MatchCmdOption(LPWSTR argvOption, LPCWSTR szOptToMacth)
static BOOL
MatchCmdOption(LPWSTR argvOption, LPCWSTR szOptToMacth)
{
WCHAR FirstCharList[] = { L'-', L'/' };
WCHAR FirstCharList[] = {L'-', L'/'};
for (UINT i = 0; i < _countof(FirstCharList); i++)
{
@ -26,7 +27,8 @@ BOOL MatchCmdOption(LPWSTR argvOption, LPCWSTR szOptToMacth)
return FALSE;
}
void InitRappsConsole()
static void
InitRappsConsole()
{
// First, try to attach to our parent's console
if (!AttachConsole(ATTACH_PARENT_PROCESS))
@ -41,40 +43,32 @@ void InitRappsConsole()
ConInitStdStreams(); // Initialize the Console Standard Streams
}
BOOL HandleInstallCommand(LPWSTR szCommand, int argcLeft, LPWSTR * argvLeft)
static BOOL
HandleInstallCommand(CApplicationDB *db, LPWSTR szCommand, int argcLeft, LPWSTR *argvLeft)
{
if (argcLeft == 0)
if (argcLeft < 1)
{
InitRappsConsole();
ConResMsgPrintf(StdOut, NULL, IDS_CMD_NEED_PACKAGE_NAME, szCommand);
return FALSE;
}
ATL::CSimpleArray<ATL::CStringW> PkgNameList;
CAtlList<CApplicationInfo *> Applications;
for (int i = 0; i < argcLeft; i++)
{
PkgNameList.Add(argvLeft[i]);
LPCWSTR PackageName = argvLeft[i];
CApplicationInfo *AppInfo = db->FindByPackageName(PackageName);
if (AppInfo)
{
Applications.AddTail(AppInfo);
}
}
CAvailableApps apps;
apps.UpdateAppsDB();
apps.Enum(ENUM_ALL_AVAILABLE, NULL, NULL);
ATL::CSimpleArray<CAvailableApplicationInfo> arrAppInfo = apps.FindAppsByPkgNameList(PkgNameList);
if (arrAppInfo.GetSize() > 0)
{
DownloadListOfApplications(arrAppInfo, TRUE);
return TRUE;
}
else
{
return FALSE;
}
return DownloadListOfApplications(Applications, TRUE);
}
BOOL HandleSetupCommand(LPWSTR szCommand, int argcLeft, LPWSTR * argvLeft)
static BOOL
HandleSetupCommand(CApplicationDB *db, LPWSTR szCommand, int argcLeft, LPWSTR *argvLeft)
{
if (argcLeft != 1)
{
@ -83,7 +77,7 @@ BOOL HandleSetupCommand(LPWSTR szCommand, int argcLeft, LPWSTR * argvLeft)
return FALSE;
}
ATL::CSimpleArray<ATL::CStringW> PkgNameList;
CAtlList<CApplicationInfo *> Applications;
HINF InfHandle = SetupOpenInfFileW(argvLeft[0], NULL, INF_STYLE_WIN4, NULL);
if (InfHandle == INVALID_HANDLE_VALUE)
{
@ -98,42 +92,21 @@ BOOL HandleSetupCommand(LPWSTR szCommand, int argcLeft, LPWSTR * argvLeft)
{
if (SetupGetStringFieldW(&Context, 1, szPkgName, _countof(szPkgName), NULL))
{
PkgNameList.Add(szPkgName);
CApplicationInfo *AppInfo = db->FindByPackageName(szPkgName);
if (AppInfo)
{
Applications.AddTail(AppInfo);
}
}
} while (SetupFindNextLine(&Context, &Context));
}
SetupCloseInfFile(InfHandle);
CAvailableApps apps;
apps.UpdateAppsDB();
apps.Enum(ENUM_ALL_AVAILABLE, NULL, NULL);
ATL::CSimpleArray<CAvailableApplicationInfo> arrAppInfo = apps.FindAppsByPkgNameList(PkgNameList);
if (arrAppInfo.GetSize() > 0)
{
DownloadListOfApplications(arrAppInfo, TRUE);
return TRUE;
}
else
{
return FALSE;
}
return DownloadListOfApplications(Applications, TRUE);
}
BOOL CALLBACK CmdFindAppEnum(CAvailableApplicationInfo *Info, BOOL bInitialCheckState, PVOID param)
{
LPCWSTR lpszSearch = (LPCWSTR)param;
if (!SearchPatternMatch(Info->m_szName, lpszSearch) &&
!SearchPatternMatch(Info->m_szDesc, lpszSearch))
{
return TRUE;
}
ConPrintf(StdOut, L"%s (%s)\n", Info->m_szName.GetString(), Info->m_szPkgName.GetString());
return TRUE;
}
BOOL HandleFindCommand(LPWSTR szCommand, int argcLeft, LPWSTR *argvLeft)
static BOOL
HandleFindCommand(CApplicationDB *db, LPWSTR szCommand, int argcLeft, LPWSTR *argvLeft)
{
if (argcLeft < 1)
{
@ -141,20 +114,33 @@ BOOL HandleFindCommand(LPWSTR szCommand, int argcLeft, LPWSTR *argvLeft)
return FALSE;
}
CAvailableApps apps;
apps.UpdateAppsDB();
CAtlList<CApplicationInfo *> List;
db->GetApps(List, ENUM_ALL_AVAILABLE);
for (int i = 0; i < argcLeft; i++)
{
ConResMsgPrintf(StdOut, NULL, IDS_CMD_FIND_RESULT_FOR, argvLeft[i]);
apps.Enum(ENUM_ALL_AVAILABLE, CmdFindAppEnum, argvLeft[i]);
LPCWSTR lpszSearch = argvLeft[i];
ConResMsgPrintf(StdOut, NULL, IDS_CMD_FIND_RESULT_FOR, lpszSearch);
POSITION CurrentListPosition = List.GetHeadPosition();
while (CurrentListPosition)
{
CApplicationInfo *Info = List.GetNext(CurrentListPosition);
if (SearchPatternMatch(Info->szDisplayName, lpszSearch) || SearchPatternMatch(Info->szComments, lpszSearch))
{
ConPrintf(StdOut, L"%s (%s)\n", Info->szDisplayName.GetString(), Info->szIdentifier.GetString());
}
}
ConPrintf(StdOut, L"\n");
}
return TRUE;
}
BOOL HandleInfoCommand(LPWSTR szCommand, int argcLeft, LPWSTR *argvLeft)
static BOOL
HandleInfoCommand(CApplicationDB *db, LPWSTR szCommand, int argcLeft, LPWSTR *argvLeft)
{
if (argcLeft < 1)
{
@ -162,70 +148,67 @@ BOOL HandleInfoCommand(LPWSTR szCommand, int argcLeft, LPWSTR *argvLeft)
return FALSE;
}
CAvailableApps apps;
apps.UpdateAppsDB();
apps.Enum(ENUM_ALL_AVAILABLE, NULL, NULL);
for (int i = 0; i < argcLeft; i++)
{
CAvailableApplicationInfo *AppInfo = apps.FindAppByPkgName(argvLeft[i]);
LPCWSTR PackageName = argvLeft[i];
CApplicationInfo *AppInfo = db->FindByPackageName(PackageName);
if (!AppInfo)
{
ConResMsgPrintf(StdOut, NULL, IDS_CMD_PACKAGE_NOT_FOUND, argvLeft[i]);
ConResMsgPrintf(StdOut, NULL, IDS_CMD_PACKAGE_NOT_FOUND, PackageName);
}
else
{
ConResMsgPrintf(StdOut, NULL, IDS_CMD_PACKAGE_INFO, argvLeft[i]);
// TODO: code about extracting information from CAvailableApplicationInfo (in appview.cpp, class CAppRichEdit)
// is in a mess. It should be refactored, and should not placed in class CAppRichEdit.
// and the code here should reused that code after refactor.
ConResMsgPrintf(StdOut, NULL, IDS_CMD_PACKAGE_INFO, PackageName);
ConPuts(StdOut, AppInfo->m_szName);
ConPuts(StdOut, AppInfo->szDisplayName);
if (AppInfo->m_szVersion)
if (!AppInfo->szDisplayVersion.IsEmpty())
{
ConResPrintf(StdOut, IDS_AINFO_VERSION);
ConPuts(StdOut, AppInfo->m_szVersion);
ConPuts(StdOut, AppInfo->szDisplayVersion);
}
if (AppInfo->m_szLicense)
CStringW License, Size, UrlSite, UrlDownload;
AppInfo->GetDisplayInfo(License, Size, UrlSite, UrlDownload);
if (!License.IsEmpty())
{
ConResPrintf(StdOut, IDS_AINFO_LICENSE);
ConPuts(StdOut, AppInfo->m_szLicense);
ConPuts(StdOut, License);
}
if (AppInfo->m_szSize)
if (!Size.IsEmpty())
{
ConResPrintf(StdOut, IDS_AINFO_SIZE);
ConPuts(StdOut, AppInfo->m_szSize);
ConPuts(StdOut, Size);
}
if (AppInfo->m_szUrlSite)
if (!UrlSite.IsEmpty())
{
ConResPrintf(StdOut, IDS_AINFO_URLSITE);
ConPuts(StdOut, AppInfo->m_szUrlSite);
ConPuts(StdOut, UrlSite);
}
if (AppInfo->m_szDesc)
if (AppInfo->szComments)
{
ConResPrintf(StdOut, IDS_AINFO_DESCRIPTION);
ConPuts(StdOut, AppInfo->m_szDesc);
ConPuts(StdOut, AppInfo->szComments);
}
if (AppInfo->m_szUrlDownload)
if (!UrlDownload.IsEmpty())
{
ConResPrintf(StdOut, IDS_AINFO_URLDOWNLOAD);
ConPuts(StdOut, AppInfo->m_szUrlDownload);
ConPuts(StdOut, UrlDownload);
}
ConPrintf(StdOut, L"\n");
ConPuts(StdOut, L"\n");
}
ConPrintf(StdOut, L"\n");
ConPuts(StdOut, L"\n");
}
return TRUE;
}
VOID PrintHelpCommand()
static VOID
PrintHelpCommand()
{
ConPrintf(StdOut, L"\n");
ConResPuts(StdOut, IDS_APPTITLE);
@ -235,7 +218,8 @@ VOID PrintHelpCommand()
ConPrintf(StdOut, L"%ls\n", UsageString);
}
BOOL ParseCmdAndExecute(LPWSTR lpCmdLine, BOOL bIsFirstLaunch, int nCmdShow)
BOOL
ParseCmdAndExecute(LPWSTR lpCmdLine, BOOL bIsFirstLaunch, int nCmdShow)
{
INT argc;
LPWSTR *argv = CommandLineToArgvW(lpCmdLine, &argc);
@ -245,6 +229,17 @@ BOOL ParseCmdAndExecute(LPWSTR lpCmdLine, BOOL bIsFirstLaunch, int nCmdShow)
return FALSE;
}
CStringW Directory;
GetStorageDirectory(Directory);
CApplicationDB db(Directory);
if (SettingsInfo.bUpdateAtStart || bIsFirstLaunch)
{
db.RemoveCached();
}
db.UpdateAvailable();
db.UpdateInstalled();
if (argc == 1) // RAPPS is launched without options
{
// Check for if rapps MainWindow is already launched in another process
@ -262,10 +257,7 @@ BOOL ParseCmdAndExecute(LPWSTR lpCmdLine, BOOL bIsFirstLaunch, int nCmdShow)
return FALSE;
}
if (SettingsInfo.bUpdateAtStart || bIsFirstLaunch)
CAvailableApps::ForceUpdateAppsDB();
MainWindowLoop(nCmdShow);
MainWindowLoop(&db, nCmdShow);
if (hMutex)
CloseHandle(hMutex);
@ -275,22 +267,22 @@ BOOL ParseCmdAndExecute(LPWSTR lpCmdLine, BOOL bIsFirstLaunch, int nCmdShow)
if (MatchCmdOption(argv[1], CMD_KEY_INSTALL))
{
return HandleInstallCommand(argv[1], argc - 2, argv + 2);
return HandleInstallCommand(&db, argv[1], argc - 2, argv + 2);
}
else if (MatchCmdOption(argv[1], CMD_KEY_SETUP))
{
return HandleSetupCommand(argv[1], argc - 2, argv + 2);
return HandleSetupCommand(&db, argv[1], argc - 2, argv + 2);
}
InitRappsConsole();
if (MatchCmdOption(argv[1], CMD_KEY_FIND))
{
return HandleFindCommand(argv[1], argc - 2, argv + 2);
return HandleFindCommand(&db, argv[1], argc - 2, argv + 2);
}
else if (MatchCmdOption(argv[1], CMD_KEY_INFO))
{
return HandleInfoCommand(argv[1], argc - 2, argv + 2);
return HandleInfoCommand(&db, argv[1], argc - 2, argv + 2);
}
else if (MatchCmdOption(argv[1], CMD_KEY_HELP) || MatchCmdOption(argv[1], CMD_KEY_HELP_ALT))
{

View file

@ -13,7 +13,7 @@
#include <gdiplus.h>
#include <conutils.h>
LPCWSTR szWindowClass = L"ROSAPPMGR";
LPCWSTR szWindowClass = L"ROSAPPMGR2";
HWND hMainWnd;
HINSTANCE hInst;
@ -25,8 +25,8 @@ END_OBJECT_MAP()
CComModule gModule;
CAtlWinModule gWinModule;
INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nShowCmd)
INT WINAPI
wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nShowCmd)
{
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;