https://git.reactos.org/?p=reactos.git;a=commitdiff;h=33c2903e6d4fda32215f5…
commit 33c2903e6d4fda32215f553c2189c13d52ed31de
Author: Mark Jansen <mark.jansen(a)reactos.org>
AuthorDate: Mon Feb 20 19:30:02 2023 +0100
Commit: Mark Jansen <mark.jansen(a)reactos.org>
CommitDate: Mon Feb 20 19:30:02 2023 +0100
[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
---
base/applications/rapps/CMakeLists.txt | 8 +-
base/applications/rapps/applicationdb.cpp | 291 ++++
base/applications/rapps/applicationinfo.cpp | 630 +++++++
base/applications/rapps/appview.cpp | 1842 +++++++++------------
base/applications/rapps/available.cpp | 612 -------
base/applications/rapps/cabinet.cpp | 229 +--
base/applications/rapps/configparser.cpp | 29 +-
base/applications/rapps/gui.cpp | 731 ++++----
base/applications/rapps/include/applicationdb.h | 35 +
base/applications/rapps/include/applicationinfo.h | 186 +++
base/applications/rapps/include/appview.h | 412 ++---
base/applications/rapps/include/available.h | 132 --
base/applications/rapps/include/configparser.h | 19 +-
base/applications/rapps/include/crichedit.h | 76 +-
base/applications/rapps/include/defines.h | 41 +-
base/applications/rapps/include/dialogs.h | 19 +-
base/applications/rapps/include/gui.h | 138 +-
base/applications/rapps/include/installed.h | 63 -
base/applications/rapps/include/misc.h | 61 +-
base/applications/rapps/include/rapps.h | 6 +-
base/applications/rapps/include/resource.h | 1 -
base/applications/rapps/include/rosui.h | 450 ++---
base/applications/rapps/installed.cpp | 371 -----
base/applications/rapps/integrity.cpp | 7 +-
base/applications/rapps/loaddlg.cpp | 595 +++----
base/applications/rapps/misc.cpp | 172 +-
base/applications/rapps/settings.cpp | 99 +-
base/applications/rapps/settingsdlg.cpp | 333 ++--
base/applications/rapps/unattended.cpp | 182 +-
base/applications/rapps/winmain.cpp | 6 +-
30 files changed, 3729 insertions(+), 4047 deletions(-)
diff --git a/base/applications/rapps/CMakeLists.txt
b/base/applications/rapps/CMakeLists.txt
index 8a260cfb2e3..0e22cea8134 100644
--- a/base/applications/rapps/CMakeLists.txt
+++ b/base/applications/rapps/CMakeLists.txt
@@ -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
diff --git a/base/applications/rapps/applicationdb.cpp
b/base/applications/rapps/applicationdb.cpp
new file mode 100644
index 00000000000..f1044c57ba8
--- /dev/null
+++ b/base/applications/rapps/applicationdb.cpp
@@ -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(a)reactos.org)
+ * Copyright 2020 He Yang (1160386205(a)qq.com)
+ * Copyright 2021-2023 Mark Jansen <mark.jansen(a)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-ke…
+ 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;
+}
diff --git a/base/applications/rapps/applicationinfo.cpp
b/base/applications/rapps/applicationinfo.cpp
new file mode 100644
index 00000000000..942668e05de
--- /dev/null
+++ b/base/applications/rapps/applicationinfo.cpp
@@ -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(a)reactos.org)
+ * Copyright 2020 He Yang (1160386205(a)qq.com)
+ * Copyright 2021-2023 Mark Jansen <mark.jansen(a)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;
+}
diff --git a/base/applications/rapps/appview.cpp b/base/applications/rapps/appview.cpp
index 11e442d28e3..5c1c548b6a6 100644
--- a/base/applications/rapps/appview.cpp
+++ b/base/applications/rapps/appview.cpp
@@ -2,7 +2,8 @@
* PROJECT: ReactOS Applications Manager
* LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Application view class and other classes used by it
- * COPYRIGHT: Copyright 2020 He Yang (1160386205(a)qq.com)
+ * COPYRIGHT: Copyright 2020 He Yang (1160386205(a)qq.com)
+ * Copyright 2022,2023 Mark Jansen <mark.jansen(a)reactos.org>
*/
#include "rapps.h"
@@ -10,39 +11,34 @@
#include "gui.h"
#include <windowsx.h>
+using namespace Gdiplus;
- // **** CMainToolbar ****
+// **** CMainToolbar ****
-VOID CMainToolbar::AddImageToImageList(HIMAGELIST hImageList, UINT ImageIndex)
+VOID
+CMainToolbar::AddImageToImageList(HIMAGELIST hImageList, UINT ImageIndex)
{
HICON hImage;
- if (!(hImage = (HICON)LoadImageW(hInst,
- MAKEINTRESOURCE(ImageIndex),
- IMAGE_ICON,
- m_iToolbarHeight,
- m_iToolbarHeight,
- 0)))
+ if (!(hImage =
+ (HICON)LoadImageW(hInst, MAKEINTRESOURCE(ImageIndex), IMAGE_ICON,
m_iToolbarHeight, m_iToolbarHeight, 0)))
{
- /* TODO: Error message */
+ return;
}
ImageList_AddIcon(hImageList, hImage);
DeleteObject(hImage);
}
-HIMAGELIST CMainToolbar::InitImageList()
+HIMAGELIST
+CMainToolbar::InitImageList()
{
HIMAGELIST hImageList;
/* Create the toolbar icon image list */
- hImageList = ImageList_Create(m_iToolbarHeight,//GetSystemMetrics(SM_CXSMICON),
- m_iToolbarHeight,//GetSystemMetrics(SM_CYSMICON),
- ILC_MASK | GetSystemColorDepth(),
- 1, 1);
+ hImageList = ImageList_Create(m_iToolbarHeight, m_iToolbarHeight, ILC_MASK |
GetSystemColorDepth(), 1, 1);
if (!hImageList)
{
- /* TODO: Error message */
return NULL;
}
@@ -58,9 +54,7 @@ HIMAGELIST CMainToolbar::InitImageList()
return hImageList;
}
-CMainToolbar::CMainToolbar()
- : m_iToolbarHeight(24)
- , m_dButtonsWidthMax(0)
+CMainToolbar::CMainToolbar() : m_iToolbarHeight(24), m_dButtonsWidthMax(0)
{
memset(szInstallBtn, 0, sizeof(szInstallBtn));
memset(szUninstallBtn, 0, sizeof(szUninstallBtn));
@@ -70,55 +64,56 @@ CMainToolbar::CMainToolbar()
memset(szUpdateDbBtn, 0, sizeof(szUpdateDbBtn));
}
-VOID CMainToolbar::OnGetDispInfo(LPTOOLTIPTEXT lpttt)
+VOID
+CMainToolbar::OnGetDispInfo(LPTOOLTIPTEXT lpttt)
{
UINT idButton = (UINT)lpttt->hdr.idFrom;
switch (idButton)
{
- case ID_EXIT:
- lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_EXIT);
- break;
+ case ID_EXIT:
+ lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_EXIT);
+ break;
- case ID_INSTALL:
- lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_INSTALL);
- break;
+ case ID_INSTALL:
+ lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_INSTALL);
+ break;
- case ID_UNINSTALL:
- lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_UNINSTALL);
- break;
+ case ID_UNINSTALL:
+ lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_UNINSTALL);
+ break;
- case ID_MODIFY:
- lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_MODIFY);
- break;
+ case ID_MODIFY:
+ lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_MODIFY);
+ break;
- case ID_SETTINGS:
- lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_SETTINGS);
- break;
+ case ID_SETTINGS:
+ lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_SETTINGS);
+ break;
- case ID_REFRESH:
- lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_REFRESH);
- break;
+ case ID_REFRESH:
+ lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_REFRESH);
+ break;
- case ID_RESETDB:
- lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_UPDATE_DB);
- break;
+ case ID_RESETDB:
+ lpttt->lpszText = MAKEINTRESOURCEW(IDS_TOOLTIP_UPDATE_DB);
+ break;
}
}
-HWND CMainToolbar::Create(HWND hwndParent)
+HWND
+CMainToolbar::Create(HWND hwndParent)
{
/* Create buttons */
- TBBUTTON Buttons[] =
- { /* iBitmap, idCommand, fsState, fsStyle, bReserved[2], dwData, iString */
- { 0, ID_TOOLBAR_INSTALL, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, { 0 },
0, (INT_PTR)szInstallBtn },
- { 1, ID_UNINSTALL, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, { 0 }, 0,
(INT_PTR)szUninstallBtn },
- { 2, ID_MODIFY, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, { 0 }, 0,
(INT_PTR)szModifyBtn },
- { 3, ID_CHECK_ALL, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, { 0 }, 0,
(INT_PTR)szSelectAll },
- { -1, 0, TBSTATE_ENABLED, BTNS_SEP, { 0 }, 0, 0
},
- { 4, ID_REFRESH, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, { 0 }, 0,
(INT_PTR)szRefreshBtn },
- { 5, ID_RESETDB, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, { 0 }, 0,
(INT_PTR)szUpdateDbBtn }
- };
+ TBBUTTON Buttons[] = {
+ /* iBitmap, idCommand, fsState, fsStyle, bReserved[2], dwData, iString */
+ {0, ID_INSTALL, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, {0}, 0,
(INT_PTR)szInstallBtn},
+ {1, ID_UNINSTALL, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, {0}, 0,
(INT_PTR)szUninstallBtn},
+ {2, ID_MODIFY, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, {0}, 0,
(INT_PTR)szModifyBtn},
+ {3, ID_CHECK_ALL, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, {0}, 0,
(INT_PTR)szSelectAll},
+ {-1, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0},
+ {4, ID_REFRESH, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, {0}, 0,
(INT_PTR)szRefreshBtn},
+ {5, ID_RESETDB, TBSTATE_ENABLED, BTNS_BUTTON | BTNS_AUTOSIZE, {0}, 0,
(INT_PTR)szUpdateDbBtn}};
LoadStringW(hInst, IDS_INSTALL, szInstallBtn, _countof(szInstallBtn));
LoadStringW(hInst, IDS_UNINSTALL, szUninstallBtn, _countof(szUninstallBtn));
@@ -127,15 +122,12 @@ HWND CMainToolbar::Create(HWND hwndParent)
LoadStringW(hInst, IDS_TOOLTIP_REFRESH, szRefreshBtn, _countof(szRefreshBtn));
LoadStringW(hInst, IDS_TOOLTIP_UPDATE_DB, szUpdateDbBtn, _countof(szUpdateDbBtn));
- m_hWnd = CreateWindowExW(0, TOOLBARCLASSNAMEW, NULL,
- WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | TBSTYLE_LIST,
- 0, 0, 0, 0,
- hwndParent,
- 0, hInst, NULL);
+ m_hWnd = CreateWindowExW(
+ 0, TOOLBARCLASSNAMEW, NULL, WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT |
TBSTYLE_TOOLTIPS | TBSTYLE_LIST, 0, 0, 0, 0,
+ hwndParent, 0, hInst, NULL);
if (!m_hWnd)
{
- /* TODO: Show error message */
return FALSE;
}
@@ -145,14 +137,11 @@ HWND CMainToolbar::Create(HWND hwndParent)
/* Set image list */
HIMAGELIST hImageList = InitImageList();
- if (!hImageList)
+ if (hImageList)
{
- /* TODO: Show error message */
- return FALSE;
+ ImageList_Destroy(SetImageList(hImageList));
}
- ImageList_Destroy(SetImageList(hImageList));
-
AddButtons(_countof(Buttons), Buttons);
/* Remember ideal width to use as a max width of buttons */
@@ -163,44 +152,46 @@ HWND CMainToolbar::Create(HWND hwndParent)
return m_hWnd;
}
-VOID CMainToolbar::HideButtonCaption()
+VOID
+CMainToolbar::HideButtonCaption()
{
DWORD dCurrentExStyle = (DWORD)SendMessageW(TB_GETEXTENDEDSTYLE, 0, 0);
SendMessageW(TB_SETEXTENDEDSTYLE, 0, dCurrentExStyle | TBSTYLE_EX_MIXEDBUTTONS);
}
-VOID CMainToolbar::ShowButtonCaption()
+VOID
+CMainToolbar::ShowButtonCaption()
{
DWORD dCurrentExStyle = (DWORD)SendMessageW(TB_GETEXTENDEDSTYLE, 0, 0);
SendMessageW(TB_SETEXTENDEDSTYLE, 0, dCurrentExStyle &
~TBSTYLE_EX_MIXEDBUTTONS);
}
-DWORD CMainToolbar::GetMaxButtonsWidth() const
+DWORD
+CMainToolbar::GetMaxButtonsWidth() const
{
return m_dButtonsWidthMax;
}
// **** CMainToolbar ****
-
// **** CSearchBar ****
CSearchBar::CSearchBar() : m_Width(180), m_Height(22)
{
}
-VOID CSearchBar::SetText(LPCWSTR lpszText)
+VOID
+CSearchBar::SetText(LPCWSTR lpszText)
{
SendMessageW(SB_SETTEXT, SBT_NOBORDERS, (LPARAM)lpszText);
}
-HWND CSearchBar::Create(HWND hwndParent)
+HWND
+CSearchBar::Create(HWND hwndParent)
{
- ATL::CStringW szBuf;
- m_hWnd = CreateWindowExW(WS_EX_CLIENTEDGE, L"Edit", NULL,
- WS_CHILD | WS_VISIBLE | ES_LEFT | ES_AUTOHSCROLL,
- 0, 0, m_Width, m_Height,
- hwndParent, (HMENU)NULL,
- hInst, 0);
+ CStringW szBuf;
+ m_hWnd = CreateWindowExW(
+ WS_EX_CLIENTEDGE, L"Edit", NULL, WS_CHILD | WS_VISIBLE | ES_LEFT |
ES_AUTOHSCROLL, 0, 0, m_Width, m_Height,
+ hwndParent, (HMENU)NULL, hInst, 0);
SendMessageW(WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0);
szBuf.LoadStringW(IDS_SEARCH_TEXT);
@@ -209,25 +200,24 @@ HWND CSearchBar::Create(HWND hwndParent)
}
// **** CSearchBar ****
-
// **** CComboBox ****
CComboBox::CComboBox() : m_Width(80), m_Height(22)
{
}
-HWND CComboBox::Create(HWND hwndParent)
+HWND
+CComboBox::Create(HWND hwndParent)
{
- m_hWnd = CreateWindowW(WC_COMBOBOX, L"",
- CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD | WS_OVERLAPPED | WS_VISIBLE,
- 0, 0, m_Width, m_Height, hwndParent, NULL, 0,
- NULL);
+ m_hWnd = CreateWindowW(
+ WC_COMBOBOX, L"", CBS_DROPDOWNLIST | CBS_HASSTRINGS | WS_CHILD |
WS_OVERLAPPED | WS_VISIBLE, 0, 0, m_Width,
+ m_Height, hwndParent, NULL, 0, NULL);
SendMessageW(WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0);
for (int i = 0; i < (int)_countof(m_TypeStringID); i++)
{
- ATL::CStringW szBuf;
+ CStringW szBuf;
szBuf.LoadStringW(m_TypeStringID[i]);
SendMessageW(CB_ADDSTRING, 0, (LPARAM)(LPCWSTR)szBuf);
}
@@ -238,26 +228,24 @@ HWND CComboBox::Create(HWND hwndParent)
}
// **** CComboBox ****
-
// **** CAppRichEdit ****
-VOID CAppRichEdit::LoadAndInsertText(UINT uStringID,
- const ATL::CStringW &szText,
- DWORD StringFlags,
- DWORD TextFlags)
+VOID
+CAppRichEdit::LoadAndInsertText(UINT uStringID, const CStringW &szText, DWORD
TextFlags)
{
- ATL::CStringW szLoadedText;
+ CStringW szLoadedText;
if (!szText.IsEmpty() && szLoadedText.LoadStringW(uStringID))
{
+ const DWORD StringFlags = CFE_BOLD;
InsertText(szLoadedText, StringFlags);
InsertText(szText, TextFlags);
}
}
-VOID CAppRichEdit::LoadAndInsertText(UINT uStringID,
- DWORD StringFlags)
+VOID
+CAppRichEdit::LoadAndInsertText(UINT uStringID, DWORD StringFlags)
{
- ATL::CStringW szLoadedText;
+ CStringW szLoadedText;
if (szLoadedText.LoadStringW(uStringID))
{
InsertText(L"\n", 0);
@@ -266,167 +254,19 @@ VOID CAppRichEdit::LoadAndInsertText(UINT uStringID,
}
}
-VOID CAppRichEdit::InsertVersionInfo(CAvailableApplicationInfo *Info)
-{
- if (Info->IsInstalled())
- {
- if (Info->HasInstalledVersion())
- {
- if (Info->HasUpdate())
- LoadAndInsertText(IDS_STATUS_UPDATE_AVAILABLE, CFE_ITALIC);
- else
- LoadAndInsertText(IDS_STATUS_INSTALLED, CFE_ITALIC);
-
- LoadAndInsertText(IDS_AINFO_VERSION, Info->m_szInstalledVersion, CFE_BOLD,
0);
- }
- else
- {
- LoadAndInsertText(IDS_STATUS_INSTALLED, CFE_ITALIC);
- }
- }
- else
- {
- LoadAndInsertText(IDS_STATUS_NOTINSTALLED, CFE_ITALIC);
- }
-
- LoadAndInsertText(IDS_AINFO_AVAILABLEVERSION, Info->m_szVersion, CFE_BOLD, 0);
-}
-
-VOID CAppRichEdit::InsertLicenseInfo(CAvailableApplicationInfo *Info)
-{
- ATL::CStringW szLicense;
- switch (Info->m_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:
- LoadAndInsertText(IDS_AINFO_LICENSE, Info->m_szLicense, CFE_BOLD, 0);
- return;
- }
-
- szLicense += L" (" + Info->m_szLicense + L")";
- LoadAndInsertText(IDS_AINFO_LICENSE, szLicense, CFE_BOLD, 0);
-}
-
-VOID CAppRichEdit::InsertLanguageInfo(CAvailableApplicationInfo *Info)
-{
- if (!Info->HasLanguageInfo())
- {
- return;
- }
-
- const INT nTranslations = Info->m_LanguageLCIDs.GetSize();
- ATL::CStringW szLangInfo;
- ATL::CStringW szLoadedTextAvailability;
- ATL::CStringW szLoadedAInfoText;
-
- szLoadedAInfoText.LoadStringW(IDS_AINFO_LANGUAGES);
-
- if (Info->HasNativeLanguage())
- {
- szLoadedTextAvailability.LoadStringW(IDS_LANGUAGE_AVAILABLE_TRANSLATION);
- if (nTranslations > 1)
- {
- ATL::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 (Info->HasEnglishLanguage())
- {
- szLoadedTextAvailability.LoadStringW(IDS_LANGUAGE_ENGLISH_TRANSLATION);
- if (nTranslations > 1)
- {
- ATL::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);
- }
-
- InsertText(szLoadedAInfoText, CFE_BOLD);
- InsertText(szLoadedTextAvailability, NULL);
- InsertText(szLangInfo, CFE_ITALIC);
-}
-
-BOOL CAppRichEdit::ShowAvailableAppInfo(CAvailableApplicationInfo *Info)
-{
- if (!Info) return FALSE;
-
- SetText(Info->m_szName, CFE_BOLD);
- InsertVersionInfo(Info);
- InsertLicenseInfo(Info);
- InsertLanguageInfo(Info);
-
- LoadAndInsertText(IDS_AINFO_SIZE, Info->m_szSize, CFE_BOLD, 0);
- LoadAndInsertText(IDS_AINFO_URLSITE, Info->m_szUrlSite, CFE_BOLD, CFE_LINK);
- LoadAndInsertText(IDS_AINFO_DESCRIPTION, Info->m_szDesc, CFE_BOLD, 0);
- LoadAndInsertText(IDS_AINFO_URLDOWNLOAD, Info->m_szUrlDownload, CFE_BOLD,
CFE_LINK);
- LoadAndInsertText(IDS_AINFO_PACKAGE_NAME, Info->m_szPkgName, CFE_BOLD, 0);
-
- return TRUE;
-}
-
-inline VOID CAppRichEdit::InsertTextWithString(UINT StringID, DWORD StringFlags, const
ATL::CStringW &Text, DWORD TextFlags)
+VOID
+CAppRichEdit::InsertTextWithString(UINT StringID, const CStringW &Text, DWORD
TextFlags)
{
if (!Text.IsEmpty())
{
- LoadAndInsertText(StringID, Text, StringFlags, TextFlags);
+ LoadAndInsertText(StringID, Text, TextFlags);
}
}
-BOOL CAppRichEdit::ShowInstalledAppInfo(CInstalledApplicationInfo *Info)
-{
- if (!Info) return FALSE;
-
- SetText(Info->szDisplayName, CFE_BOLD);
- InsertText(L"\n", 0);
-
- Info->EnsureDetailsLoaded();
-
- InsertTextWithString(IDS_INFO_VERSION, CFE_BOLD, Info->szDisplayVersion, 0);
- InsertTextWithString(IDS_INFO_PUBLISHER, CFE_BOLD, Info->szPublisher, 0);
- InsertTextWithString(IDS_INFO_REGOWNER, CFE_BOLD, Info->szRegOwner, 0);
- InsertTextWithString(IDS_INFO_PRODUCTID, CFE_BOLD, Info->szProductID, 0);
- InsertTextWithString(IDS_INFO_HELPLINK, CFE_BOLD, Info->szHelpLink, CFM_LINK);
- InsertTextWithString(IDS_INFO_HELPPHONE, CFE_BOLD, Info->szHelpTelephone, 0);
- InsertTextWithString(IDS_INFO_README, CFE_BOLD, Info->szReadme, 0);
- InsertTextWithString(IDS_INFO_CONTACT, CFE_BOLD, Info->szContact, 0);
- InsertTextWithString(IDS_INFO_UPDATEINFO, CFE_BOLD, Info->szURLUpdateInfo,
CFM_LINK);
- InsertTextWithString(IDS_INFO_INFOABOUT, CFE_BOLD, Info->szURLInfoAbout,
CFM_LINK);
- InsertTextWithString(IDS_INFO_COMMENTS, CFE_BOLD, Info->szComments, 0);
- InsertTextWithString(IDS_INFO_INSTALLDATE, CFE_BOLD, Info->szInstallDate, 0);
- InsertTextWithString(IDS_INFO_INSTLOCATION, CFE_BOLD, Info->szInstallLocation,
0);
- InsertTextWithString(IDS_INFO_INSTALLSRC, CFE_BOLD, Info->szInstallSource, 0);
- InsertTextWithString(IDS_INFO_UNINSTALLSTR, CFE_BOLD, Info->szUninstallString,
0);
- InsertTextWithString(IDS_INFO_MODIFYPATH, CFE_BOLD, Info->szModifyPath, 0);
-
- return TRUE;
-}
-
-VOID CAppRichEdit::SetWelcomeText()
+VOID
+CAppRichEdit::SetWelcomeText()
{
- ATL::CStringW szText;
+ CStringW szText;
szText.LoadStringW(IDS_WELCOME_TITLE);
SetText(szText, CFE_BOLD);
@@ -439,167 +279,169 @@ VOID CAppRichEdit::SetWelcomeText()
}
// **** CAppRichEdit ****
-
-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)
{
ScrnshotDownloadParam *DownloadParam = (ScrnshotDownloadParam *)Extension;
switch (Event)
{
- case ASYNCINET_DATA:
- DWORD BytesWritten;
- WriteFile(DownloadParam->hFile, (LPCVOID)wParam, (DWORD)lParam,
&BytesWritten, NULL);
- break;
- case ASYNCINET_COMPLETE:
- CloseHandle(DownloadParam->hFile);
- SendMessage(DownloadParam->hwndNotify, WM_RAPPS_DOWNLOAD_COMPLETE,
(WPARAM)ERROR_SUCCESS, (LPARAM)DownloadParam);
- break;
- case ASYNCINET_CANCELLED:
- CloseHandle(DownloadParam->hFile);
- SendMessage(DownloadParam->hwndNotify, WM_RAPPS_DOWNLOAD_COMPLETE,
(WPARAM)ERROR_CANCELLED, (LPARAM)DownloadParam);
- break;
- case ASYNCINET_ERROR:
- CloseHandle(DownloadParam->hFile);
- SendMessage(DownloadParam->hwndNotify, WM_RAPPS_DOWNLOAD_COMPLETE, wParam,
(LPARAM)DownloadParam);
- break;
- default:
- ATLASSERT(FALSE);
- break;
+ case ASYNCINET_DATA:
+ DWORD BytesWritten;
+ WriteFile(DownloadParam->hFile, (LPCVOID)wParam, (DWORD)lParam,
&BytesWritten, NULL);
+ break;
+ case ASYNCINET_COMPLETE:
+ CloseHandle(DownloadParam->hFile);
+ SendMessage(
+ DownloadParam->hwndNotify, WM_RAPPS_DOWNLOAD_COMPLETE,
(WPARAM)ERROR_SUCCESS, (LPARAM)DownloadParam);
+ break;
+ case ASYNCINET_CANCELLED:
+ CloseHandle(DownloadParam->hFile);
+ SendMessage(
+ DownloadParam->hwndNotify, WM_RAPPS_DOWNLOAD_COMPLETE,
(WPARAM)ERROR_CANCELLED, (LPARAM)DownloadParam);
+ break;
+ case ASYNCINET_ERROR:
+ CloseHandle(DownloadParam->hFile);
+ SendMessage(DownloadParam->hwndNotify, WM_RAPPS_DOWNLOAD_COMPLETE, wParam,
(LPARAM)DownloadParam);
+ break;
+ default:
+ ATLASSERT(FALSE);
+ break;
}
return 0;
}
-
// **** CAppScrnshotPreview ****
-BOOL CAppScrnshotPreview::ProcessWindowMessage(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM
lParam, LRESULT &theResult, DWORD dwMapId)
+CAppScrnshotPreview::CAppScrnshotPreview(const CStringW &BasePath) :
m_BasePath(BasePath)
+{
+}
+
+BOOL
+CAppScrnshotPreview::ProcessWindowMessage(
+ HWND hwnd,
+ UINT Msg,
+ WPARAM wParam,
+ LPARAM lParam,
+ LRESULT &theResult,
+ DWORD dwMapId)
{
theResult = 0;
switch (Msg)
{
- case WM_CREATE:
- hBrokenImgIcon = (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_BROKEN_IMAGE),
IMAGE_ICON, BrokenImgSize, BrokenImgSize, 0);
- break;
- case WM_SIZE:
- {
- if (BrokenImgSize != min(min(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)),
BROKENIMG_ICON_SIZE))
+ case WM_CREATE:
+ hBrokenImgIcon =
+ (HICON)LoadImage(hInst, MAKEINTRESOURCE(IDI_BROKEN_IMAGE), IMAGE_ICON,
BrokenImgSize, BrokenImgSize, 0);
+ break;
+ case WM_SIZE:
{
- BrokenImgSize = min(min(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)),
BROKENIMG_ICON_SIZE);
-
- if (hBrokenImgIcon)
+ if (BrokenImgSize != min(min(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)),
BROKENIMG_ICON_SIZE))
{
- DeleteObject(hBrokenImgIcon);
- hBrokenImgIcon = (HICON)LoadImage(hInst,
MAKEINTRESOURCE(IDI_BROKEN_IMAGE), IMAGE_ICON, BrokenImgSize, BrokenImgSize, 0);
+ BrokenImgSize = min(min(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)),
BROKENIMG_ICON_SIZE);
+
+ if (hBrokenImgIcon)
+ {
+ DeleteObject(hBrokenImgIcon);
+ hBrokenImgIcon = (HICON)LoadImage(
+ hInst, MAKEINTRESOURCE(IDI_BROKEN_IMAGE), IMAGE_ICON,
BrokenImgSize, BrokenImgSize, 0);
+ }
}
+ break;
}
- break;
- }
- case WM_RAPPS_DOWNLOAD_COMPLETE:
- {
- ScrnshotDownloadParam *DownloadParam = (ScrnshotDownloadParam *)lParam;
- AsyncInetRelease(AsyncInet);
- AsyncInet = NULL;
- switch (wParam)
+ case WM_RAPPS_DOWNLOAD_COMPLETE:
{
- case ERROR_SUCCESS:
- if (ContentID == DownloadParam->ID)
- {
- DisplayFile(DownloadParam->DownloadFileName);
- // send a message to trigger resizing
- ::SendMessageW(::GetParent(m_hWnd), WM_RAPPS_RESIZE_CHILDREN, 0, 0);
- InvalidateRect(0, 0);
- TempImagePath = DownloadParam->DownloadFileName; // record tmp file
path in order to delete it when cleanup
- }
- else
+ ScrnshotDownloadParam *DownloadParam = (ScrnshotDownloadParam *)lParam;
+ AsyncInetRelease(AsyncInet);
+ AsyncInet = NULL;
+ switch (wParam)
{
- // the picture downloaded is already outdated. delete it.
- DeleteFileW(DownloadParam->DownloadFileName);
+ case ERROR_SUCCESS:
+ if (ContentID == DownloadParam->ID)
+ {
+ DisplayFile(DownloadParam->DownloadFileName);
+ // send a message to trigger resizing
+ ::SendMessageW(::GetParent(m_hWnd), WM_RAPPS_RESIZE_CHILDREN, 0,
0);
+ InvalidateRect(0, 0);
+ TempImagePath =
+ DownloadParam->DownloadFileName; // record tmp file path
in order to delete it when cleanup
+ }
+ else
+ {
+ // the picture downloaded is already outdated. delete it.
+ DeleteFileW(DownloadParam->DownloadFileName);
+ }
+ break;
+ case ERROR_CANCELLED:
+ DeleteFileW(DownloadParam->DownloadFileName);
+ break;
+ default:
+ DisplayFailed();
+ // send a message to trigger resizing
+ ::SendMessageW(::GetParent(m_hWnd), WM_RAPPS_RESIZE_CHILDREN, 0, 0);
+ InvalidateRect(0, 0);
+ DeleteFileW(DownloadParam->DownloadFileName);
+ break;
}
- break;
- case ERROR_CANCELLED:
- DeleteFileW(DownloadParam->DownloadFileName);
- break;
- default:
- DisplayFailed();
- // send a message to trigger resizing
- ::SendMessageW(::GetParent(m_hWnd), WM_RAPPS_RESIZE_CHILDREN, 0, 0);
- InvalidateRect(0, 0);
- DeleteFileW(DownloadParam->DownloadFileName);
+ delete DownloadParam;
break;
}
- delete DownloadParam;
- break;
- }
- case WM_PAINT:
- {
- PAINTSTRUCT ps;
- HDC hdc = BeginPaint(&ps);
- CRect rect;
- GetClientRect(&rect);
+ case WM_PAINT:
+ {
+ PAINTSTRUCT ps;
+ HDC hdc = BeginPaint(&ps);
+ CRect rect;
+ GetClientRect(&rect);
- PaintOnDC(hdc,
- rect.Width(),
- rect.Height(),
- ps.fErase);
+ PaintOnDC(hdc, rect.Width(), rect.Height(), ps.fErase);
- EndPaint(&ps);
- break;
- }
- case WM_PRINTCLIENT:
- {
- if (lParam & PRF_CHECKVISIBLE)
- {
- if (!IsWindowVisible()) break;
+ EndPaint(&ps);
+ break;
}
- CRect rect;
- GetClientRect(&rect);
-
- PaintOnDC((HDC)wParam,
- rect.Width(),
- rect.Height(),
- lParam & PRF_ERASEBKGND);
- break;
- }
- case WM_ERASEBKGND:
- {
- return TRUE; // do not erase to avoid blinking
- }
- case WM_TIMER:
- {
- switch (wParam)
+ case WM_PRINTCLIENT:
{
- case TIMER_LOADING_ANIMATION:
- LoadingAnimationFrame++;
- LoadingAnimationFrame %= (LOADING_ANIMATION_PERIOD * LOADING_ANIMATION_FPS);
- HDC hdc = GetDC();
+ if (lParam & PRF_CHECKVISIBLE)
+ {
+ if (!IsWindowVisible())
+ break;
+ }
CRect rect;
GetClientRect(&rect);
- PaintOnDC(hdc,
- rect.Width(),
- rect.Height(),
- TRUE);
- ReleaseDC(hdc);
+ PaintOnDC((HDC)wParam, rect.Width(), rect.Height(), lParam &
PRF_ERASEBKGND);
+ break;
+ }
+ case WM_ERASEBKGND:
+ {
+ return TRUE; // do not erase to avoid blinking
+ }
+ case WM_TIMER:
+ {
+ switch (wParam)
+ {
+ case TIMER_LOADING_ANIMATION:
+ LoadingAnimationFrame++;
+ LoadingAnimationFrame %= (LOADING_ANIMATION_PERIOD *
LOADING_ANIMATION_FPS);
+ HDC hdc = GetDC();
+ CRect rect;
+ GetClientRect(&rect);
+
+ PaintOnDC(hdc, rect.Width(), rect.Height(), TRUE);
+ ReleaseDC(hdc);
+ }
+ break;
+ }
+ case WM_DESTROY:
+ {
+ PreviousDisplayCleanup();
+ DeleteObject(hBrokenImgIcon);
+ hBrokenImgIcon = NULL;
+ break;
}
- break;
- }
- case WM_DESTROY:
- {
- PreviousDisplayCleanup();
- DeleteObject(hBrokenImgIcon);
- hBrokenImgIcon = NULL;
- break;
- }
}
return FALSE;
}
-VOID CAppScrnshotPreview::DisplayLoading()
+VOID
+CAppScrnshotPreview::DisplayLoading()
{
SetStatus(SCRNSHOT_PREV_LOADING);
if (bLoadingTimerOn)
@@ -611,14 +453,16 @@ VOID CAppScrnshotPreview::DisplayLoading()
SetTimer(TIMER_LOADING_ANIMATION, 1000 / LOADING_ANIMATION_FPS, 0);
}
-VOID CAppScrnshotPreview::DisplayFailed()
+VOID
+CAppScrnshotPreview::DisplayFailed()
{
InterlockedIncrement64(&ContentID);
SetStatus(SCRNSHOT_PREV_FAILED);
PreviousDisplayCleanup();
}
-BOOL CAppScrnshotPreview::DisplayFile(LPCWSTR lpszFileName)
+BOOL
+CAppScrnshotPreview::DisplayFile(LPCWSTR lpszFileName)
{
PreviousDisplayCleanup();
SetStatus(SCRNSHOT_PREV_IMAGE);
@@ -631,12 +475,14 @@ BOOL CAppScrnshotPreview::DisplayFile(LPCWSTR lpszFileName)
return TRUE;
}
-VOID CAppScrnshotPreview::SetStatus(SCRNSHOT_STATUS Status)
+VOID
+CAppScrnshotPreview::SetStatus(SCRNSHOT_STATUS Status)
{
ScrnshotPrevStauts = Status;
}
-VOID CAppScrnshotPreview::PaintOnDC(HDC hdc, int width, int height, BOOL bDrawBkgnd)
+VOID
+CAppScrnshotPreview::PaintOnDC(HDC hdc, int width, int height, BOOL bDrawBkgnd)
{
// use an off screen dc to avoid blinking
HDC hdcMem = CreateCompatibleDC(hdc);
@@ -652,72 +498,65 @@ VOID CAppScrnshotPreview::PaintOnDC(HDC hdc, int width, int height,
BOOL bDrawBk
switch (ScrnshotPrevStauts)
{
- case SCRNSHOT_PREV_EMPTY:
- {
-
- }
- break;
-
- case SCRNSHOT_PREV_LOADING:
- {
- Graphics graphics(hdcMem);
- Color color(255, 0, 0);
- SolidBrush dotBrush(Color(255, 100, 100, 100));
-
- graphics.SetSmoothingMode(SmoothingMode::SmoothingModeAntiAlias);
-
- // Paint three dot
- float DotWidth = GetLoadingDotWidth(width, height);
- graphics.FillEllipse((Brush *)(&dotBrush),
- (REAL)width / 2.0 - min(width, height) * 2.0 / 16.0 - DotWidth / 2.0,
- (REAL)height / 2.0 - GetFrameDotShift(LoadingAnimationFrame +
LOADING_ANIMATION_FPS / 4, width, height) - DotWidth / 2.0,
- DotWidth,
- DotWidth);
-
- graphics.FillEllipse((Brush *)(&dotBrush),
- (REAL)width / 2.0 - DotWidth / 2.0,
- (REAL)height / 2.0 - GetFrameDotShift(LoadingAnimationFrame, width, height) -
DotWidth / 2.0,
- DotWidth,
- DotWidth);
-
- graphics.FillEllipse((Brush *)(&dotBrush),
- (REAL)width / 2.0 + min(width, height) * 2.0 / 16.0 - DotWidth / 2.0,
- (REAL)height / 2.0 - GetFrameDotShift(LoadingAnimationFrame -
LOADING_ANIMATION_FPS / 4, width, height) - DotWidth / 2.0,
- DotWidth,
- DotWidth);
- }
- break;
+ case SCRNSHOT_PREV_EMPTY:
+ {
+ }
+ break;
- case SCRNSHOT_PREV_IMAGE:
- {
- if (pImage)
+ case SCRNSHOT_PREV_LOADING:
{
- // always draw entire image inside the window.
Graphics graphics(hdcMem);
- float ZoomRatio = min(((float)width / (float)pImage->GetWidth()),
((float)height / (float)pImage->GetHeight()));
- float ZoomedImgWidth = ZoomRatio * (float)pImage->GetWidth();
- float ZoomedImgHeight = ZoomRatio * (float)pImage->GetHeight();
+ Color color(255, 0, 0);
+ SolidBrush dotBrush(Color(255, 100, 100, 100));
+
+ graphics.SetSmoothingMode(SmoothingMode::SmoothingModeAntiAlias);
+
+ // Paint three dot
+ float DotWidth = GetLoadingDotWidth(width, height);
+ graphics.FillEllipse(
+ (Brush *)(&dotBrush), (REAL)width / 2.0 - min(width, height) * 2.0 /
16.0 - DotWidth / 2.0,
+ (REAL)height / 2.0 -
+ GetFrameDotShift(LoadingAnimationFrame + LOADING_ANIMATION_FPS / 4,
width, height) - DotWidth / 2.0,
+ DotWidth, DotWidth);
+
+ graphics.FillEllipse(
+ (Brush *)(&dotBrush), (REAL)width / 2.0 - DotWidth / 2.0,
+ (REAL)height / 2.0 - GetFrameDotShift(LoadingAnimationFrame, width,
height) - DotWidth / 2.0, DotWidth,
+ DotWidth);
+
+ graphics.FillEllipse(
+ (Brush *)(&dotBrush), (REAL)width / 2.0 + min(width, height) * 2.0 /
16.0 - DotWidth / 2.0,
+ (REAL)height / 2.0 -
+ GetFrameDotShift(LoadingAnimationFrame - LOADING_ANIMATION_FPS / 4,
width, height) - DotWidth / 2.0,
+ DotWidth, DotWidth);
+ }
+ break;
- graphics.DrawImage(pImage,
- ((float)width - ZoomedImgWidth) / 2.0, ((float)height - ZoomedImgHeight)
/ 2.0,
- ZoomedImgWidth, ZoomedImgHeight);
+ case SCRNSHOT_PREV_IMAGE:
+ {
+ if (pImage)
+ {
+ // always draw entire image inside the window.
+ Graphics graphics(hdcMem);
+ float ZoomRatio =
+ min(((float)width / (float)pImage->GetWidth()), ((float)height /
(float)pImage->GetHeight()));
+ float ZoomedImgWidth = ZoomRatio * (float)pImage->GetWidth();
+ float ZoomedImgHeight = ZoomRatio * (float)pImage->GetHeight();
+
+ graphics.DrawImage(
+ pImage, ((float)width - ZoomedImgWidth) / 2.0, ((float)height -
ZoomedImgHeight) / 2.0,
+ ZoomedImgWidth, ZoomedImgHeight);
+ }
}
- }
- break;
+ break;
- case SCRNSHOT_PREV_FAILED:
- {
- DrawIconEx(hdcMem,
- (width - BrokenImgSize) / 2,
- (height - BrokenImgSize) / 2,
- hBrokenImgIcon,
- BrokenImgSize,
- BrokenImgSize,
- NULL,
- NULL,
- DI_NORMAL | DI_COMPAT);
- }
- break;
+ case SCRNSHOT_PREV_FAILED:
+ {
+ DrawIconEx(
+ hdcMem, (width - BrokenImgSize) / 2, (height - BrokenImgSize) / 2,
hBrokenImgIcon, BrokenImgSize,
+ BrokenImgSize, NULL, NULL, DI_NORMAL | DI_COMPAT);
+ }
+ break;
}
// copy the content form off-screen dc to hdc
@@ -726,51 +565,46 @@ VOID CAppScrnshotPreview::PaintOnDC(HDC hdc, int width, int height,
BOOL bDrawBk
DeleteObject(hBitmap);
}
-float CAppScrnshotPreview::GetLoadingDotWidth(int width, int height)
+float
+CAppScrnshotPreview::GetLoadingDotWidth(int width, int height)
{
return min(width, height) / 20.0;
}
-float CAppScrnshotPreview::GetFrameDotShift(int Frame, int width, int height)
+float
+CAppScrnshotPreview::GetFrameDotShift(int Frame, int width, int height)
{
- return min(width, height) *
- (1.0 / 16.0) *
- (2.0 / (2.0 - sqrt(3.0))) *
- (max(sin((float)Frame * 2 * PI / (LOADING_ANIMATION_PERIOD *
LOADING_ANIMATION_FPS)), sqrt(3.0) / 2.0) - sqrt(3.0) / 2.0);
+ return min(width, height) * (1.0 / 16.0) * (2.0 / (2.0 - sqrt(3.0))) *
+ (max(sin((float)Frame * 2 * PI / (LOADING_ANIMATION_PERIOD *
LOADING_ANIMATION_FPS)), sqrt(3.0) / 2.0) -
+ sqrt(3.0) / 2.0);
}
-ATL::CWndClassInfo &CAppScrnshotPreview::GetWndClassInfo()
+ATL::CWndClassInfo &
+CAppScrnshotPreview::GetWndClassInfo()
{
DWORD csStyle = CS_VREDRAW | CS_HREDRAW;
- static ATL::CWndClassInfo wc =
- {
- {
- sizeof(WNDCLASSEX),
- csStyle,
- StartWindowProc,
- 0,
- 0,
- NULL,
- 0,
- LoadCursorW(NULL, IDC_ARROW),
- (HBRUSH)(COLOR_BTNFACE + 1),
- 0,
- L"RAppsScrnshotPreview",
- NULL
- },
- NULL, NULL, IDC_ARROW, TRUE, 0, _T("")
- };
+ static ATL::CWndClassInfo wc = {
+ {sizeof(WNDCLASSEX), csStyle, StartWindowProc, 0, 0, NULL, 0, LoadCursorW(NULL,
IDC_ARROW),
+ (HBRUSH)(COLOR_BTNFACE + 1), 0, L"RAppsScrnshotPreview", NULL},
+ NULL,
+ NULL,
+ IDC_ARROW,
+ TRUE,
+ 0,
+ _T("")};
return wc;
}
-HWND CAppScrnshotPreview::Create(HWND hParent)
+HWND
+CAppScrnshotPreview::Create(HWND hParent)
{
- RECT r = { 0,0,0,0 };
+ RECT r = {0, 0, 0, 0};
return CWindowImpl::Create(hParent, r, L"", WS_CHILD | WS_VISIBLE);
}
-VOID CAppScrnshotPreview::PreviousDisplayCleanup()
+VOID
+CAppScrnshotPreview::PreviousDisplayCleanup()
{
if (bLoadingTimerOn)
{
@@ -794,14 +628,16 @@ VOID CAppScrnshotPreview::PreviousDisplayCleanup()
}
}
-VOID CAppScrnshotPreview::DisplayEmpty()
+VOID
+CAppScrnshotPreview::DisplayEmpty()
{
InterlockedIncrement64(&ContentID);
SetStatus(SCRNSHOT_PREV_EMPTY);
PreviousDisplayCleanup();
}
-BOOL CAppScrnshotPreview::DisplayImage(LPCWSTR lpszLocation)
+BOOL
+CAppScrnshotPreview::DisplayImage(LPCWSTR lpszLocation)
{
LONGLONG ID = InterlockedIncrement64(&ContentID);
PreviousDisplayCleanup();
@@ -811,12 +647,13 @@ BOOL CAppScrnshotPreview::DisplayImage(LPCWSTR lpszLocation)
DisplayLoading();
ScrnshotDownloadParam *DownloadParam = new ScrnshotDownloadParam;
- if (!DownloadParam) return FALSE;
+ if (!DownloadParam)
+ return FALSE;
DownloadParam->hwndNotify = m_hWnd;
DownloadParam->ID = ID;
// generate a filename
- ATL::CStringW ScrnshotFolder = CAvailableApps::m_Strings.szAppsPath;
+ CStringW ScrnshotFolder = m_BasePath;
PathAppendW(ScrnshotFolder.GetBuffer(MAX_PATH), L"screenshots");
ScrnshotFolder.ReleaseBuffer();
@@ -825,8 +662,8 @@ BOOL CAppScrnshotPreview::DisplayImage(LPCWSTR lpszLocation)
CreateDirectoryW(ScrnshotFolder.GetString(), NULL);
}
- if (!GetTempFileNameW(ScrnshotFolder.GetString(), L"img",
- 0, DownloadParam->DownloadFileName.GetBuffer(MAX_PATH)))
+ if (!GetTempFileNameW(
+ ScrnshotFolder.GetString(), L"img", 0,
DownloadParam->DownloadFileName.GetBuffer(MAX_PATH)))
{
DownloadParam->DownloadFileName.ReleaseBuffer();
delete DownloadParam;
@@ -835,8 +672,9 @@ BOOL CAppScrnshotPreview::DisplayImage(LPCWSTR lpszLocation)
}
DownloadParam->DownloadFileName.ReleaseBuffer();
- DownloadParam->hFile =
CreateFileW(DownloadParam->DownloadFileName.GetString(),
- GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+ DownloadParam->hFile = CreateFileW(
+ DownloadParam->DownloadFileName.GetString(), GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,
+ NULL);
if (DownloadParam->hFile == INVALID_HANDLE_VALUE)
{
delete DownloadParam;
@@ -844,7 +682,8 @@ BOOL CAppScrnshotPreview::DisplayImage(LPCWSTR lpszLocation)
return FALSE;
}
- AsyncInet = AsyncInetDownload(0, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0,
lpszLocation, TRUE, ScrnshotDownloadCallback, DownloadParam);
+ AsyncInet = AsyncInetDownload(
+ 0, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, lpszLocation, TRUE,
ScrnshotDownloadCallback, DownloadParam);
if (!AsyncInet)
{
CloseHandle(DownloadParam->hFile);
@@ -861,27 +700,30 @@ BOOL CAppScrnshotPreview::DisplayImage(LPCWSTR lpszLocation)
}
}
-int CAppScrnshotPreview::GetRequestedWidth(int Height) // calculate requested window
width by given height
+int
+CAppScrnshotPreview::GetRequestedWidth(int Height) // calculate requested window width by
given height
{
switch (ScrnshotPrevStauts)
{
- case SCRNSHOT_PREV_EMPTY:
- return 0;
- case SCRNSHOT_PREV_LOADING:
- return 200;
- case SCRNSHOT_PREV_IMAGE:
- if (pImage)
- {
- // return the width needed to display image inside the window.
- // and always keep window w/h ratio inside [ 1/SCRNSHOT_MAX_ASPECT_RAT,
SCRNSHOT_MAX_ASPECT_RAT ]
- return (int)floor((float)Height *
- max(min((float)pImage->GetWidth() / (float)pImage->GetHeight(),
(float)SCRNSHOT_MAX_ASPECT_RAT), 1.0 / (float)SCRNSHOT_MAX_ASPECT_RAT));
- }
- return 0;
- case SCRNSHOT_PREV_FAILED:
- return 200;
- default:
- return 0;
+ case SCRNSHOT_PREV_EMPTY:
+ return 0;
+ case SCRNSHOT_PREV_LOADING:
+ return 200;
+ case SCRNSHOT_PREV_IMAGE:
+ if (pImage)
+ {
+ // return the width needed to display image inside the window.
+ // and always keep window w/h ratio inside [ 1/SCRNSHOT_MAX_ASPECT_RAT,
SCRNSHOT_MAX_ASPECT_RAT ]
+ return (int)floor(
+ (float)Height *
+ max(min((float)pImage->GetWidth() / (float)pImage->GetHeight(),
(float)SCRNSHOT_MAX_ASPECT_RAT),
+ 1.0 / (float)SCRNSHOT_MAX_ASPECT_RAT));
+ }
+ return 0;
+ case SCRNSHOT_PREV_FAILED:
+ return 200;
+ default:
+ return 0;
}
}
@@ -891,65 +733,75 @@ CAppScrnshotPreview::~CAppScrnshotPreview()
}
// **** CAppScrnshotPreview ****
-
// **** CAppInfoDisplay ****
-BOOL CAppInfoDisplay::ProcessWindowMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM
lParam, LRESULT &theResult, DWORD dwMapId)
+BOOL
+CAppInfoDisplay::ProcessWindowMessage(
+ HWND hwnd,
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam,
+ LRESULT &theResult,
+ DWORD dwMapId)
{
theResult = 0;
switch (message)
{
- case WM_CREATE:
- {
- RichEdit = new CAppRichEdit();
- RichEdit->Create(hwnd);
+ case WM_CREATE:
+ {
+ RichEdit = new CAppRichEdit();
+ RichEdit->Create(hwnd);
- ScrnshotPrev = new CAppScrnshotPreview();
- ScrnshotPrev->Create(hwnd);
- break;
- }
- case WM_SIZE:
- {
- ResizeChildren(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
- break;
- }
- case WM_RAPPS_RESIZE_CHILDREN:
- {
- ResizeChildren();
- break;
- }
- case WM_COMMAND:
- {
- OnCommand(wParam, lParam);
- break;
- }
- case WM_NOTIFY:
- {
- NMHDR *NotifyHeader = (NMHDR *)lParam;
- if (NotifyHeader->hwndFrom == RichEdit->m_hWnd)
+ CStringW Directory;
+ ::GetStorageDirectory(Directory);
+ ScrnshotPrev = new CAppScrnshotPreview(Directory);
+ ScrnshotPrev->Create(hwnd);
+ break;
+ }
+ case WM_SIZE:
+ {
+ ResizeChildren(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
+ break;
+ }
+ case WM_RAPPS_RESIZE_CHILDREN:
+ {
+ ResizeChildren();
+ break;
+ }
+ case WM_COMMAND:
{
- switch (NotifyHeader->code)
+ OnCommand(wParam, lParam);
+ break;
+ }
+ case WM_NOTIFY:
+ {
+ NMHDR *NotifyHeader = (NMHDR *)lParam;
+ if (NotifyHeader->hwndFrom == RichEdit->m_hWnd)
{
- case EN_LINK:
- OnLink((ENLINK *)lParam);
- break;
+ switch (NotifyHeader->code)
+ {
+ case EN_LINK:
+ OnLink((ENLINK *)lParam);
+ break;
+ }
}
+ break;
}
- break;
- }
}
return FALSE;
}
-VOID CAppInfoDisplay::ResizeChildren()
+VOID
+CAppInfoDisplay::ResizeChildren()
{
CRect rect;
GetWindowRect(&rect);
ResizeChildren(rect.Width(), rect.Height());
}
-VOID CAppInfoDisplay::ResizeChildren(int Width, int Height)
+VOID
+CAppInfoDisplay::ResizeChildren(int Width, int Height)
{
int ScrnshotWidth = ScrnshotPrev->GetRequestedWidth(Height);
@@ -961,16 +813,14 @@ VOID CAppInfoDisplay::ResizeChildren(int Width, int Height)
if (hDwp)
{
- hDwp = ::DeferWindowPos(hDwp, ScrnshotPrev->m_hWnd, NULL,
- 0, 0, ScrnshotWidth, Height, 0);
+ hDwp = ::DeferWindowPos(hDwp, ScrnshotPrev->m_hWnd, NULL, 0, 0, ScrnshotWidth,
Height, 0);
if (hDwp)
{
// hide the padding if scrnshot window width == 0
int RicheditPosX = ScrnshotWidth ? (ScrnshotWidth + INFO_DISPLAY_PADDING) :
0;
- hDwp = ::DeferWindowPos(hDwp, RichEdit->m_hWnd, NULL,
- RicheditPosX, 0, Width - RicheditPosX, Height, 0);
+ hDwp = ::DeferWindowPos(hDwp, RichEdit->m_hWnd, NULL, RicheditPosX, 0,
Width - RicheditPosX, Height, 0);
if (hDwp)
{
@@ -991,7 +841,6 @@ VOID CAppInfoDisplay::ResizeChildren(int Width, int Height)
dwError = GetLastError();
}
-
#if DBG
ATLASSERT(dwError == ERROR_SUCCESS);
#endif
@@ -1000,68 +849,75 @@ VOID CAppInfoDisplay::ResizeChildren(int Width, int Height)
UpdateWindow();
}
-VOID CAppInfoDisplay::OnLink(ENLINK *Link)
+VOID
+CAppInfoDisplay::OnLink(ENLINK *Link)
{
switch (Link->msg)
{
- case WM_LBUTTONUP:
- case WM_RBUTTONUP:
- {
- if (pLink) HeapFree(GetProcessHeap(), 0, pLink);
-
- pLink = (LPWSTR)HeapAlloc(GetProcessHeap(), 0,
- (max(Link->chrg.cpMin, Link->chrg.cpMax) -
- min(Link->chrg.cpMin, Link->chrg.cpMax) + 1) * sizeof(WCHAR));
- if (!pLink)
+ case WM_LBUTTONUP:
+ case WM_RBUTTONUP:
{
- /* TODO: Error message */
- return;
- }
+ if (pLink)
+ HeapFree(GetProcessHeap(), 0, pLink);
+
+ pLink = (LPWSTR)HeapAlloc(
+ GetProcessHeap(), 0,
+ (max(Link->chrg.cpMin, Link->chrg.cpMax) - min(Link->chrg.cpMin,
Link->chrg.cpMax) + 1) *
+ sizeof(WCHAR));
+ if (!pLink)
+ {
+ /* TODO: Error message */
+ return;
+ }
- RichEdit->SendMessageW(EM_SETSEL, Link->chrg.cpMin, Link->chrg.cpMax);
- RichEdit->SendMessageW(EM_GETSELTEXT, 0, (LPARAM)pLink);
+ RichEdit->SendMessageW(EM_SETSEL, Link->chrg.cpMin,
Link->chrg.cpMax);
+ RichEdit->SendMessageW(EM_GETSELTEXT, 0, (LPARAM)pLink);
- ShowPopupMenuEx(m_hWnd, m_hWnd, IDR_LINKMENU, -1);
- }
- break;
+ ShowPopupMenuEx(m_hWnd, m_hWnd, IDR_LINKMENU, -1);
+ }
+ break;
}
}
-ATL::CWndClassInfo &CAppInfoDisplay::GetWndClassInfo()
+ATL::CWndClassInfo &
+CAppInfoDisplay::GetWndClassInfo()
{
DWORD csStyle = CS_VREDRAW | CS_HREDRAW;
- static ATL::CWndClassInfo wc =
- {
- {
- sizeof(WNDCLASSEX),
- csStyle,
- StartWindowProc,
- 0,
- 0,
- NULL,
- NULL,
- NULL,
- (HBRUSH)(COLOR_BTNFACE + 1),
- NULL,
- L"RAppsAppInfo",
- NULL
- },
- NULL, NULL, IDC_ARROW, TRUE, 0, _T("")
- };
+ static ATL::CWndClassInfo wc = {/*.m_wc=*/
+ {/*cbSize=*/sizeof(WNDCLASSEX),
+ /*style=*/csStyle,
+ /*lpfnWndProc=*/StartWindowProc,
+ /*cbClsExtra=*/0,
+ /*cbWndExtra=*/0,
+ /*hInstance=*/NULL,
+ /*hIcon=*/NULL,
+ /*hCursor*/ NULL,
+ /*hbrBackground=*/(HBRUSH)(COLOR_BTNFACE + 1),
+ /*lpszMenuName=*/NULL,
+ /*lpszClassName=*/L"RAppsAppInfo",
+ /*hIconSm=*/NULL},
+ /*m_lpszOrigName=*/NULL,
+ /*pWndProc=*/NULL,
+ /*m_lpszCursorID=*/IDC_ARROW,
+ /*m_bSystemCursor*/ TRUE,
+ /*m_atom=*/0,
+ /*m_szAutoName=*/_T("")};
return wc;
}
-HWND CAppInfoDisplay::Create(HWND hwndParent)
+HWND
+CAppInfoDisplay::Create(HWND hwndParent)
{
- RECT r = { 0,0,0,0 };
+ RECT r = {0, 0, 0, 0};
return CWindowImpl::Create(hwndParent, r, L"", WS_CHILD | WS_VISIBLE |
WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
}
-BOOL CAppInfoDisplay::ShowAvailableAppInfo(CAvailableApplicationInfo *Info)
+VOID
+CAppInfoDisplay::ShowAppInfo(CApplicationInfo *Info)
{
- ATL::CStringW ScrnshotLocation;
- if (Info->RetrieveScrnshot(0, ScrnshotLocation))
+ CStringW ScrnshotLocation;
+ if (Info->RetrieveScreenshot(ScrnshotLocation))
{
ScrnshotPrev->DisplayImage(ScrnshotLocation);
}
@@ -1070,42 +926,36 @@ BOOL
CAppInfoDisplay::ShowAvailableAppInfo(CAvailableApplicationInfo *Info)
ScrnshotPrev->DisplayEmpty();
}
ResizeChildren();
- return RichEdit->ShowAvailableAppInfo(Info);
+ Info->ShowAppInfo(RichEdit);
}
-BOOL CAppInfoDisplay::ShowInstalledAppInfo(CInstalledApplicationInfo *Info)
-{
- ScrnshotPrev->DisplayEmpty();
- ResizeChildren();
- return RichEdit->ShowInstalledAppInfo(Info);
-}
-
-VOID CAppInfoDisplay::SetWelcomeText()
+VOID
+CAppInfoDisplay::SetWelcomeText()
{
ScrnshotPrev->DisplayEmpty();
ResizeChildren();
RichEdit->SetWelcomeText();
}
-VOID CAppInfoDisplay::OnCommand(WPARAM wParam, LPARAM lParam)
+VOID
+CAppInfoDisplay::OnCommand(WPARAM wParam, LPARAM lParam)
{
WORD wCommand = LOWORD(wParam);
switch (wCommand)
{
- case ID_OPEN_LINK:
-
- ShellExecuteW(m_hWnd, L"open", pLink, NULL, NULL, SW_SHOWNOACTIVATE);
- HeapFree(GetProcessHeap(), 0, pLink);
- pLink = NULL;
- break;
+ case ID_OPEN_LINK:
- case ID_COPY_LINK:
- CopyTextToClipboard(pLink);
- HeapFree(GetProcessHeap(), 0, pLink);
- pLink = NULL;
- break;
+ ShellExecuteW(m_hWnd, L"open", pLink, NULL, NULL,
SW_SHOWNOACTIVATE);
+ HeapFree(GetProcessHeap(), 0, pLink);
+ pLink = NULL;
+ break;
+ case ID_COPY_LINK:
+ CopyTextToClipboard(pLink);
+ HeapFree(GetProcessHeap(), 0, pLink);
+ pLink = NULL;
+ break;
}
}
@@ -1116,7 +966,6 @@ CAppInfoDisplay::~CAppInfoDisplay()
}
// **** CAppInfoDisplay ****
-
// **** CAppsListView ****
CAppsListView::CAppsListView()
@@ -1149,13 +998,14 @@ CAppsListView::OnEraseBackground(UINT uMsg, WPARAM wParam, LPARAM
lParam, BOOL &
return lRes;
}
-VOID CAppsListView::SetWatermark(const CStringW& Text)
+VOID
+CAppsListView::SetWatermark(const CStringW &Text)
{
m_Watermark = Text;
}
-
-VOID CAppsListView::SetCheckboxesVisible(BOOL bIsVisible)
+VOID
+CAppsListView::SetCheckboxesVisible(BOOL bIsVisible)
{
if (bIsVisible)
{
@@ -1169,7 +1019,8 @@ VOID CAppsListView::SetCheckboxesVisible(BOOL bIsVisible)
bHasCheckboxes = bIsVisible;
}
-VOID CAppsListView::ColumnClick(LPNMLISTVIEW pnmv)
+VOID
+CAppsListView::ColumnClick(LPNMLISTVIEW pnmv)
{
HWND hHeader;
HDITEMW hColumn;
@@ -1200,7 +1051,7 @@ VOID CAppsListView::ColumnClick(LPNMLISTVIEW pnmv)
Header_SetItem(hHeader, nHeaderID, &hColumn);
/* Sort the list, using the current values of nHeaderID and bIsAscending */
- SortContext ctx = { this, nHeaderID };
+ SortContext ctx = {this, nHeaderID};
SortItems(s_CompareFunc, &ctx);
/* Save new values */
@@ -1208,12 +1059,8 @@ VOID CAppsListView::ColumnClick(LPNMLISTVIEW pnmv)
bIsAscending = !bIsAscending;
}
-BOOL CAppsListView::AddColumn(INT Index, ATL::CStringW &Text, INT Width, INT Format)
-{
- return AddColumn(Index, const_cast<LPWSTR>(Text.GetString()), Width, Format);
-}
-
-int CAppsListView::AddColumn(INT Index, LPWSTR lpText, INT Width, INT Format)
+BOOL
+CAppsListView::AddColumn(INT Index, CStringW &Text, INT Width, INT Format)
{
LVCOLUMNW Column;
@@ -1221,20 +1068,22 @@ int CAppsListView::AddColumn(INT Index, LPWSTR lpText, INT Width,
INT Format)
Column.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
Column.iSubItem = Index;
- Column.pszText = lpText;
+ Column.pszText = const_cast<LPWSTR>(Text.GetString());
Column.cx = Width;
Column.fmt = Format;
return SendMessage(LVM_INSERTCOLUMN, Index, (LPARAM)(&Column));
}
-void CAppsListView::DeleteColumn(INT Index)
+void
+CAppsListView::DeleteColumn(INT Index)
{
SendMessage(LVM_DELETECOLUMN, Index, 0);
return;
}
-INT CAppsListView::AddItem(INT ItemIndex, INT IconIndex, LPCWSTR lpText, LPARAM lParam)
+INT
+CAppsListView::AddItem(INT ItemIndex, INT IconIndex, LPCWSTR lpText, LPARAM lParam)
{
LVITEMW Item;
@@ -1254,20 +1103,23 @@ INT CAppsListView::AddItem(INT ItemIndex, INT IconIndex, LPCWSTR
lpText, LPARAM
return InsertItem(&Item);
}
-HIMAGELIST CAppsListView::GetImageList(int iImageList)
+HIMAGELIST
+CAppsListView::GetImageList(int iImageList)
{
return (HIMAGELIST)SendMessage(LVM_GETIMAGELIST, iImageList, 0);
}
-INT CALLBACK CAppsListView::s_CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM
lParamSort)
+INT CALLBACK
+CAppsListView::s_CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
SortContext *ctx = ((SortContext *)lParamSort);
return ctx->lvw->CompareFunc(lParam1, lParam2, ctx->iSubItem);
}
-INT CAppsListView::CompareFunc(LPARAM lParam1, LPARAM lParam2, INT iSubItem)
+INT
+CAppsListView::CompareFunc(LPARAM lParam1, LPARAM lParam2, INT iSubItem)
{
- ATL::CStringW Item1, Item2;
+ CStringW Item1, Item2;
LVFINDINFOW IndexInfo;
INT Index;
@@ -1286,10 +1138,12 @@ INT CAppsListView::CompareFunc(LPARAM lParam1, LPARAM lParam2, INT
iSubItem)
return bIsAscending ? Item1.Compare(Item2) : Item2.Compare(Item1);
}
-HWND CAppsListView::Create(HWND hwndParent)
+HWND
+CAppsListView::Create(HWND hwndParent)
{
- RECT r = { 205, 28, 465, 250 };
- DWORD style = WS_CHILD | WS_VISIBLE | LVS_SORTASCENDING | LVS_REPORT | LVS_SINGLESEL
| LVS_SHOWSELALWAYS | LVS_AUTOARRANGE | LVS_SHAREIMAGELISTS;
+ RECT r = {205, 28, 465, 250};
+ DWORD style = WS_CHILD | WS_VISIBLE | LVS_SORTASCENDING | LVS_REPORT | LVS_SINGLESEL
| LVS_SHOWSELALWAYS |
+ LVS_AUTOARRANGE | LVS_SHAREIMAGELISTS;
HWND hwnd = CListView::Create(hwndParent, r, NULL, style, WS_EX_CLIENTEDGE);
@@ -1298,12 +1152,8 @@ HWND CAppsListView::Create(HWND hwndParent)
SetCheckboxesVisible(FALSE);
}
- m_hImageListView = ImageList_Create(LISTVIEW_ICON_SIZE,
- LISTVIEW_ICON_SIZE,
- GetSystemColorDepth() | ILC_MASK,
- 0, 1);
+ m_hImageListView = ImageList_Create(LISTVIEW_ICON_SIZE, LISTVIEW_ICON_SIZE,
GetSystemColorDepth() | ILC_MASK, 0, 1);
- // currently, this two Imagelist is the same one.
SetImageList(m_hImageListView, LVSIL_SMALL);
SetImageList(m_hImageListView, LVSIL_NORMAL);
@@ -1316,12 +1166,14 @@ HWND CAppsListView::Create(HWND hwndParent)
return hwnd;
}
-BOOL CAppsListView::GetCheckState(INT item)
+BOOL
+CAppsListView::GetCheckState(INT item)
{
return (BOOL)(GetItemState(item, LVIS_STATEIMAGEMASK) >> 12) - 1;
}
-VOID CAppsListView::SetCheckState(INT item, BOOL fCheck)
+VOID
+CAppsListView::SetCheckState(INT item, BOOL fCheck)
{
if (bHasCheckboxes)
{
@@ -1329,7 +1181,8 @@ VOID CAppsListView::SetCheckState(INT item, BOOL fCheck)
}
}
-VOID CAppsListView::CheckAll()
+VOID
+CAppsListView::CheckAll()
{
if (bHasCheckboxes)
{
@@ -1346,7 +1199,8 @@ VOID CAppsListView::CheckAll()
}
}
-PVOID CAppsListView::GetFocusedItemData()
+PVOID
+CAppsListView::GetFocusedItemData()
{
INT item = GetSelectionMark();
if (item == -1)
@@ -1356,9 +1210,11 @@ PVOID CAppsListView::GetFocusedItemData()
return (PVOID)GetItemData(item);
}
-BOOL CAppsListView::SetDisplayAppType(APPLICATION_VIEW_TYPE AppType)
+BOOL
+CAppsListView::SetDisplayAppType(APPLICATION_VIEW_TYPE AppType)
{
- if (!DeleteAllItems()) return FALSE;
+ if (!DeleteAllItems())
+ return FALSE;
ApplicationViewType = AppType;
bIsAscending = TRUE;
@@ -1375,139 +1231,130 @@ BOOL CAppsListView::SetDisplayAppType(APPLICATION_VIEW_TYPE
AppType)
ImageList_RemoveAll(m_hImageListView);
// add new columns
- ATL::CStringW szText;
+ CStringW szText;
switch (AppType)
{
- case AppViewTypeInstalledApps:
+ case AppViewTypeInstalledApps:
- /* Add columns to ListView */
- szText.LoadStringW(IDS_APP_NAME);
- AddColumn(ColumnCount++, szText, 250, LVCFMT_LEFT);
+ /* Add columns to ListView */
+ szText.LoadStringW(IDS_APP_NAME);
+ AddColumn(ColumnCount++, szText, 250, LVCFMT_LEFT);
- szText.LoadStringW(IDS_APP_INST_VERSION);
- AddColumn(ColumnCount++, szText, 90, LVCFMT_RIGHT);
+ szText.LoadStringW(IDS_APP_INST_VERSION);
+ AddColumn(ColumnCount++, szText, 90, LVCFMT_RIGHT);
- szText.LoadStringW(IDS_APP_DESCRIPTION);
- AddColumn(ColumnCount++, szText, 300, LVCFMT_LEFT);
+ szText.LoadStringW(IDS_APP_DESCRIPTION);
+ AddColumn(ColumnCount++, szText, 300, LVCFMT_LEFT);
- // disable checkboxes
- SetCheckboxesVisible(FALSE);
- break;
+ // disable checkboxes
+ SetCheckboxesVisible(FALSE);
+ break;
- case AppViewTypeAvailableApps:
+ case AppViewTypeAvailableApps:
- /* Add columns to ListView */
- szText.LoadStringW(IDS_APP_NAME);
- AddColumn(ColumnCount++, szText, 250, LVCFMT_LEFT);
+ /* Add columns to ListView */
+ szText.LoadStringW(IDS_APP_NAME);
+ AddColumn(ColumnCount++, szText, 250, LVCFMT_LEFT);
- szText.LoadStringW(IDS_APP_INST_VERSION);
- AddColumn(ColumnCount++, szText, 90, LVCFMT_RIGHT);
+ szText.LoadStringW(IDS_APP_INST_VERSION);
+ AddColumn(ColumnCount++, szText, 90, LVCFMT_RIGHT);
- szText.LoadStringW(IDS_APP_DESCRIPTION);
- AddColumn(ColumnCount++, szText, 300, LVCFMT_LEFT);
+ szText.LoadStringW(IDS_APP_DESCRIPTION);
+ AddColumn(ColumnCount++, szText, 300, LVCFMT_LEFT);
- // enable checkboxes
- SetCheckboxesVisible(TRUE);
- break;
+ // enable checkboxes
+ SetCheckboxesVisible(TRUE);
+ break;
- case AppViewTypeEmpty:
- default:
- break;
+ default:
+ break;
}
-
return TRUE;
}
-BOOL CAppsListView::SetViewMode(DWORD ViewMode)
+BOOL
+CAppsListView::SetViewMode(DWORD ViewMode)
{
return SendMessage(LVM_SETVIEW, (WPARAM)ViewMode, 0) == 1;
}
-BOOL CAppsListView::AddInstalledApplication(CInstalledApplicationInfo *InstAppInfo,
LPVOID CallbackParam)
+BOOL
+CAppsListView::AddApplication(CApplicationInfo *AppInfo, BOOL InitialCheckState)
{
- if (ApplicationViewType != AppViewTypeInstalledApps)
- {
- return FALSE;
- }
-
- /* Load icon from registry */
- HICON hIcon = NULL;
- ATL::CStringW szIconPath;
- if (InstAppInfo->RetrieveIcon(szIconPath))
+ if (ApplicationViewType == AppViewTypeInstalledApps)
{
- PathParseIconLocationW((LPWSTR)szIconPath.GetString());
-
- /* Load only the 1st icon from the application executable,
- * because all apps provide the executables which have the main icon
- * as 1st in the index , so we don't need other icons here */
- hIcon = ExtractIconW(hInst,
- szIconPath.GetString(),
- 0);
- }
+ /* Load icon from registry */
+ HICON hIcon = NULL;
+ CStringW szIconPath;
+ if (AppInfo->RetrieveIcon(szIconPath))
+ {
+ PathParseIconLocationW((LPWSTR)szIconPath.GetString());
- if (!hIcon)
- {
- /* Load the default icon */
- hIcon = LoadIconW(hInst, MAKEINTRESOURCEW(IDI_MAIN));
- }
+ /* Load only the 1st icon from the application executable,
+ * because all apps provide the executables which have the main icon
+ * as 1st in the index , so we don't need other icons here */
+ hIcon = ExtractIconW(hInst, szIconPath.GetString(), 0);
+ }
- int IconIndex = ImageList_AddIcon(m_hImageListView, hIcon);
- DestroyIcon(hIcon);
+ if (!hIcon)
+ {
+ /* Load default icon */
+ hIcon = LoadIconW(hInst, MAKEINTRESOURCEW(IDI_MAIN));
+ }
- int Index = AddItem(ItemCount, IconIndex, InstAppInfo->szDisplayName,
(LPARAM)CallbackParam);
- SetItemText(Index, 1, InstAppInfo->szDisplayVersion.IsEmpty() ? L"---" :
InstAppInfo->szDisplayVersion);
- SetItemText(Index, 2, InstAppInfo->szComments.IsEmpty() ? L"---" :
InstAppInfo->szComments);
+ int IconIndex = ImageList_AddIcon(m_hImageListView, hIcon);
+ DestroyIcon(hIcon);
- ItemCount++;
- return TRUE;
-}
+ int Index = AddItem(ItemCount, IconIndex, AppInfo->szDisplayName,
(LPARAM)AppInfo);
+ SetItemText(Index, 1, AppInfo->szDisplayVersion.IsEmpty() ? L"---" :
AppInfo->szDisplayVersion);
+ SetItemText(Index, 2, AppInfo->szComments.IsEmpty() ? L"---" :
AppInfo->szComments);
-BOOL CAppsListView::AddAvailableApplication(CAvailableApplicationInfo *AvlbAppInfo, BOOL
InitCheckState, LPVOID CallbackParam)
-{
- if (ApplicationViewType != AppViewTypeAvailableApps)
- {
- return FALSE;
+ ItemCount++;
+ return TRUE;
}
-
- /* Load icon from file */
- HICON hIcon = NULL;
- ATL::CStringW szIconPath;
- if (AvlbAppInfo->RetrieveIcon(szIconPath))
+ else if (ApplicationViewType == AppViewTypeAvailableApps)
{
- hIcon = (HICON)LoadImageW(NULL,
- szIconPath.GetString(),
- IMAGE_ICON,
- LISTVIEW_ICON_SIZE,
- LISTVIEW_ICON_SIZE,
- LR_LOADFROMFILE);
- }
+ /* Load icon from file */
+ HICON hIcon = NULL;
+ CStringW szIconPath;
+ if (AppInfo->RetrieveIcon(szIconPath))
+ {
+ hIcon = (HICON)LoadImageW(
+ NULL, szIconPath, IMAGE_ICON, LISTVIEW_ICON_SIZE, LISTVIEW_ICON_SIZE,
LR_LOADFROMFILE);
+ }
- if (!hIcon || GetLastError() != ERROR_SUCCESS)
- {
- /* Load the default icon */
- hIcon = LoadIconW(hInst, MAKEINTRESOURCEW(IDI_MAIN));
- }
+ if (!hIcon)
+ {
+ /* Load default icon */
+ hIcon = LoadIconW(hInst, MAKEINTRESOURCEW(IDI_MAIN));
+ }
- int IconIndex = ImageList_AddIcon(m_hImageListView, hIcon);
- DestroyIcon(hIcon);
+ int IconIndex = ImageList_AddIcon(m_hImageListView, hIcon);
+ DestroyIcon(hIcon);
- int Index = AddItem(ItemCount, IconIndex, AvlbAppInfo->m_szName,
(LPARAM)CallbackParam);
+ int Index = AddItem(ItemCount, IconIndex, AppInfo->szDisplayName,
(LPARAM)AppInfo);
- if (InitCheckState)
- {
- SetCheckState(Index, TRUE);
- }
+ if (InitialCheckState)
+ {
+ SetCheckState(Index, TRUE);
+ }
- SetItemText(Index, 1, AvlbAppInfo->m_szVersion);
- SetItemText(Index, 2, AvlbAppInfo->m_szDesc);
+ SetItemText(Index, 1, AppInfo->szDisplayVersion);
+ SetItemText(Index, 2, AppInfo->szComments);
- ItemCount++;
- return TRUE;
+ ItemCount++;
+ return TRUE;
+ }
+ else
+ {
+ return FALSE;
+ }
}
// this function is called when parent window receiving an notification about checkstate
changing
-VOID CAppsListView::ItemCheckStateNotify(int iItem, BOOL bCheck)
+VOID
+CAppsListView::ItemCheckStateNotify(int iItem, BOOL bCheck)
{
if (bCheck)
{
@@ -1520,162 +1367,168 @@ VOID CAppsListView::ItemCheckStateNotify(int iItem, BOOL
bCheck)
}
// **** CAppsListView ****
-
// **** CApplicationView ****
-BOOL CApplicationView::ProcessWindowMessage(HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam, LRESULT &theResult, DWORD dwMapId)
+BOOL
+CApplicationView::ProcessWindowMessage(
+ HWND hwnd,
+ UINT message,
+ WPARAM wParam,
+ LPARAM lParam,
+ LRESULT &theResult,
+ DWORD dwMapId)
{
theResult = 0;
switch (message)
{
- case WM_CREATE:
- {
- BOOL bSuccess = TRUE;
- m_Panel = new CUiPanel();
- m_Panel->m_VerticalAlignment = UiAlign_Stretch;
- m_Panel->m_HorizontalAlignment = UiAlign_Stretch;
+ case WM_CREATE:
+ {
+ BOOL bSuccess = TRUE;
+ m_Panel = new CUiPanel();
+ m_Panel->m_VerticalAlignment = UiAlign_Stretch;
+ m_Panel->m_HorizontalAlignment = UiAlign_Stretch;
- bSuccess &= CreateToolbar();
- bSuccess &= CreateSearchBar();
- bSuccess &= CreateComboBox();
- bSuccess &= CreateHSplitter();
- bSuccess &= CreateListView();
- bSuccess &= CreateAppInfoDisplay();
+ bSuccess &= CreateToolbar();
+ bSuccess &= CreateSearchBar();
+ bSuccess &= CreateComboBox();
+ bSuccess &= CreateHSplitter();
+ bSuccess &= CreateListView();
+ bSuccess &= CreateAppInfoDisplay();
- m_Toolbar->AutoSize();
+ m_Toolbar->AutoSize();
- RECT rTop;
+ RECT rTop;
- ::GetWindowRect(m_Toolbar->m_hWnd, &rTop);
- m_HSplitter->m_Margin.top = rTop.bottom - rTop.top;
- if (!bSuccess)
- {
- return -1; // creation failure
+ ::GetWindowRect(m_Toolbar->m_hWnd, &rTop);
+ m_HSplitter->m_Margin.top = rTop.bottom - rTop.top;
+ if (!bSuccess)
+ {
+ return -1; // creation failure
+ }
}
- }
- break;
+ break;
- case WM_NOTIFY:
- {
- LPNMHDR pNotifyHeader = (LPNMHDR)lParam;
- if (pNotifyHeader->hwndFrom == m_ListView->GetWindow())
+ case WM_NOTIFY:
{
- switch (pNotifyHeader->code)
+ LPNMHDR pNotifyHeader = (LPNMHDR)lParam;
+ if (pNotifyHeader->hwndFrom == m_ListView->GetWindow())
{
- case LVN_ITEMCHANGED:
- {
- LPNMLISTVIEW pnic = (LPNMLISTVIEW)lParam;
-
- /* Check if this is a valid item
- * (technically, it can be also an unselect) */
- INT ItemIndex = pnic->iItem;
- if (ItemIndex == -1 ||
- ItemIndex >= ListView_GetItemCount(pnic->hdr.hwndFrom))
+ switch (pNotifyHeader->code)
{
+ case LVN_ITEMCHANGED:
+ {
+ LPNMLISTVIEW pnic = (LPNMLISTVIEW)lParam;
+
+ /* Check if this is a valid item
+ * (technically, it can be also an unselect) */
+ INT ItemIndex = pnic->iItem;
+ if (ItemIndex == -1 || ItemIndex >=
ListView_GetItemCount(pnic->hdr.hwndFrom))
+ {
+ break;
+ }
+
+ /* Check if the focus has been moved to another item */
+ if ((pnic->uChanged & LVIF_STATE) &&
(pnic->uNewState & LVIS_FOCUSED) &&
+ !(pnic->uOldState & LVIS_FOCUSED))
+ {
+ ItemGetFocus((LPVOID)pnic->lParam);
+ }
+
+ /* Check if the item is checked/unchecked */
+ if (pnic->uChanged & LVIF_STATE)
+ {
+ int iOldState = STATEIMAGETOINDEX(pnic->uOldState);
+ int iNewState = STATEIMAGETOINDEX(pnic->uNewState);
+
+ if (iOldState == STATEIMAGE_UNCHECKED && iNewState ==
STATEIMAGE_CHECKED)
+ {
+ // this item is just checked
+ m_ListView->ItemCheckStateNotify(pnic->iItem,
TRUE);
+ ItemCheckStateChanged(TRUE, (LPVOID)pnic->lParam);
+ }
+ else if (iOldState == STATEIMAGE_CHECKED && iNewState
== STATEIMAGE_UNCHECKED)
+ {
+ // this item is just unchecked
+ m_ListView->ItemCheckStateNotify(pnic->iItem,
FALSE);
+ ItemCheckStateChanged(FALSE, (LPVOID)pnic->lParam);
+ }
+ }
+ }
break;
- }
- /* Check if the focus has been moved to another item */
- if ((pnic->uChanged & LVIF_STATE) &&
- (pnic->uNewState & LVIS_FOCUSED) &&
- !(pnic->uOldState & LVIS_FOCUSED))
- {
- ItemGetFocus((LPVOID)pnic->lParam);
- }
-
- /* Check if the item is checked/unchecked */
- if (pnic->uChanged & LVIF_STATE)
- {
- int iOldState = STATEIMAGETOINDEX(pnic->uOldState);
- int iNewState = STATEIMAGETOINDEX(pnic->uNewState);
-
- if (iOldState == STATEIMAGE_UNCHECKED && iNewState ==
STATEIMAGE_CHECKED)
+ case LVN_COLUMNCLICK:
{
- // this item is just checked
- m_ListView->ItemCheckStateNotify(pnic->iItem, TRUE);
- ItemCheckStateChanged(TRUE, (LPVOID)pnic->lParam);
+ LPNMLISTVIEW pnmv = (LPNMLISTVIEW)lParam;
+
+ m_ListView->ColumnClick(pnmv);
}
- else if (iOldState == STATEIMAGE_CHECKED && iNewState ==
STATEIMAGE_UNCHECKED)
+ break;
+
+ case NM_DBLCLK:
{
- // this item is just unchecked
- m_ListView->ItemCheckStateNotify(pnic->iItem, FALSE);
- ItemCheckStateChanged(FALSE, (LPVOID)pnic->lParam);
+ LPNMITEMACTIVATE Item = (LPNMITEMACTIVATE)lParam;
+ if (Item->iItem != -1)
+ {
+ /* this won't do anything if the program is already
installed */
+
+ if (ApplicationViewType == AppViewTypeAvailableApps)
+ {
+ m_MainWindow->InstallApplication(
+ (CApplicationInfo
*)m_ListView->GetItemData(Item->iItem));
+ }
+ }
}
- }
- }
- break;
-
- case LVN_COLUMNCLICK:
- {
- LPNMLISTVIEW pnmv = (LPNMLISTVIEW)lParam;
-
- m_ListView->ColumnClick(pnmv);
- }
- break;
-
- case NM_DBLCLK:
- {
- LPNMITEMACTIVATE Item = (LPNMITEMACTIVATE)lParam;
- if (Item->iItem != -1)
- {
- /* this won't do anything if the program is already installed */
+ break;
- if (ApplicationViewType == AppViewTypeAvailableApps)
+ case NM_RCLICK:
{
- m_MainWindow->InstallApplication((CAvailableApplicationInfo
*)m_ListView->GetItemData(Item->iItem));
+ if (((LPNMLISTVIEW)lParam)->iItem != -1)
+ {
+ ShowPopupMenuEx(m_hWnd, m_hWnd, 0, ID_INSTALL);
+ }
}
+ break;
}
}
- break;
-
- case NM_RCLICK:
+ else if (pNotifyHeader->hwndFrom == m_Toolbar->GetWindow())
{
- if (((LPNMLISTVIEW)lParam)->iItem != -1)
+ switch (pNotifyHeader->code)
{
- ShowPopupMenuEx(m_hWnd, m_hWnd, 0, ID_INSTALL);
+ case TTN_GETDISPINFO:
+ m_Toolbar->OnGetDispInfo((LPTOOLTIPTEXT)lParam);
+ break;
}
}
- break;
- }
}
- else if (pNotifyHeader->hwndFrom == m_Toolbar->GetWindow())
+ break;
+
+ case WM_SYSCOLORCHANGE:
{
- switch (pNotifyHeader->code)
- {
- case TTN_GETDISPINFO:
- m_Toolbar->OnGetDispInfo((LPTOOLTIPTEXT)lParam);
- break;
- }
+ /* Forward WM_SYSCOLORCHANGE to common controls */
+ m_ListView->SendMessageW(WM_SYSCOLORCHANGE, wParam, lParam);
+ m_ListView->SendMessageW(EM_SETBKGNDCOLOR, 0,
GetSysColor(COLOR_BTNFACE));
+ m_Toolbar->SendMessageW(WM_SYSCOLORCHANGE, wParam, lParam);
+ m_ComboBox->SendMessageW(WM_SYSCOLORCHANGE, wParam, lParam);
}
- }
- break;
+ break;
- case WM_SYSCOLORCHANGE:
- {
- /* Forward WM_SYSCOLORCHANGE to common controls */
- m_ListView->SendMessageW(WM_SYSCOLORCHANGE, wParam, lParam);
- m_ListView->SendMessageW(EM_SETBKGNDCOLOR, 0, GetSysColor(COLOR_BTNFACE));
- m_Toolbar->SendMessageW(WM_SYSCOLORCHANGE, wParam, lParam);
- m_ComboBox->SendMessageW(WM_SYSCOLORCHANGE, wParam, lParam);
- }
- break;
+ case WM_SIZE:
+ {
+ OnSize(hwnd, wParam, lParam);
+ break;
+ }
- case WM_SIZE:
- {
- OnSize(hwnd, wParam, lParam);
+ case WM_COMMAND:
+ {
+ OnCommand(wParam, lParam);
+ }
break;
}
-
- case WM_COMMAND:
- {
- OnCommand(wParam, lParam);
- }
- break;
- }
return FALSE;
}
-BOOL CApplicationView::CreateToolbar()
+BOOL
+CApplicationView::CreateToolbar()
{
m_Toolbar = new CMainToolbar();
m_Toolbar->m_VerticalAlignment = UiAlign_LeftTop;
@@ -1685,7 +1538,8 @@ BOOL CApplicationView::CreateToolbar()
return m_Toolbar->Create(m_hWnd) != NULL;
}
-BOOL CApplicationView::CreateSearchBar()
+BOOL
+CApplicationView::CreateSearchBar()
{
m_SearchBar = new CUiWindow<CSearchBar>();
m_SearchBar->m_VerticalAlignment = UiAlign_LeftTop;
@@ -1696,7 +1550,8 @@ BOOL CApplicationView::CreateSearchBar()
return m_SearchBar->Create(m_Toolbar->m_hWnd) != NULL;
}
-BOOL CApplicationView::CreateComboBox()
+BOOL
+CApplicationView::CreateComboBox()
{
m_ComboBox = new CUiWindow<CComboBox>();
m_ComboBox->m_VerticalAlignment = UiAlign_LeftTop;
@@ -1706,14 +1561,15 @@ BOOL CApplicationView::CreateComboBox()
return m_ComboBox->Create(m_Toolbar->m_hWnd) != NULL;
}
-BOOL CApplicationView::CreateHSplitter()
+BOOL
+CApplicationView::CreateHSplitter()
{
m_HSplitter = new CUiSplitPanel();
m_HSplitter->m_VerticalAlignment = UiAlign_Stretch;
m_HSplitter->m_HorizontalAlignment = UiAlign_Stretch;
m_HSplitter->m_DynamicFirst = TRUE;
m_HSplitter->m_Horizontal = TRUE;
- m_HSplitter->m_Pos = INT_MAX; //set INT_MAX to use lowest possible position
(m_MinSecond)
+ m_HSplitter->m_Pos = INT_MAX; // set INT_MAX to use lowest possible position
(m_MinSecond)
m_HSplitter->m_MinFirst = 10;
m_HSplitter->m_MinSecond = 140;
m_Panel->Children().Append(m_HSplitter);
@@ -1721,7 +1577,8 @@ BOOL CApplicationView::CreateHSplitter()
return m_HSplitter->Create(m_hWnd) != NULL;
}
-BOOL CApplicationView::CreateListView()
+BOOL
+CApplicationView::CreateListView()
{
m_ListView = new CAppsListView();
m_ListView->m_VerticalAlignment = UiAlign_Stretch;
@@ -1731,7 +1588,8 @@ BOOL CApplicationView::CreateListView()
return m_ListView->Create(m_hWnd) != NULL;
}
-BOOL CApplicationView::CreateAppInfoDisplay()
+BOOL
+CApplicationView::CreateAppInfoDisplay()
{
m_AppsInfo = new CAppInfoDisplay();
m_AppsInfo->m_VerticalAlignment = UiAlign_Stretch;
@@ -1741,18 +1599,21 @@ BOOL CApplicationView::CreateAppInfoDisplay()
return m_AppsInfo->Create(m_hWnd) != NULL;
}
-void CApplicationView::SetRedraw(BOOL bRedraw)
+void
+CApplicationView::SetRedraw(BOOL bRedraw)
{
CWindow::SetRedraw(bRedraw);
m_ListView->SetRedraw(bRedraw);
}
-void CApplicationView::SetFocusOnSearchBar()
+void
+CApplicationView::SetFocusOnSearchBar()
{
m_SearchBar->SetFocus();
}
-VOID CApplicationView::OnSize(HWND hwnd, WPARAM wParam, LPARAM lParam)
+VOID
+CApplicationView::OnSize(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
if (wParam == SIZE_MINIMIZED)
return;
@@ -1771,10 +1632,9 @@ VOID CApplicationView::OnSize(HWND hwnd, WPARAM wParam, LPARAM
lParam)
else if (dSearchbarMargin < dToolbarTreshold)
{
m_Toolbar->HideButtonCaption();
-
}
- RECT r = { 0, 0, LOWORD(lParam), HIWORD(lParam) };
+ RECT r = {0, 0, LOWORD(lParam), HIWORD(lParam)};
HDWP hdwp = NULL;
INT count = m_Panel->CountSizableChildren();
@@ -1812,56 +1672,57 @@ VOID CApplicationView::OnSize(HWND hwnd, WPARAM wParam, LPARAM
lParam)
}
}
-VOID CApplicationView::OnCommand(WPARAM wParam, LPARAM lParam)
+VOID
+CApplicationView::OnCommand(WPARAM wParam, LPARAM lParam)
{
if (lParam)
{
if ((HWND)lParam == m_SearchBar->GetWindow())
{
- ATL::CStringW szBuf;
+ CStringW szBuf;
switch (HIWORD(wParam))
{
- case EN_SETFOCUS:
- {
- ATL::CStringW szWndText;
-
- szBuf.LoadStringW(IDS_SEARCH_TEXT);
- m_SearchBar->GetWindowTextW(szWndText);
- if (szBuf == szWndText)
+ case EN_SETFOCUS:
{
- m_SearchBar->SetWindowTextW(L"");
- }
- }
- break;
+ CStringW szWndText;
- case EN_KILLFOCUS:
- {
- m_SearchBar->GetWindowTextW(szBuf);
- if (szBuf.IsEmpty())
- {
szBuf.LoadStringW(IDS_SEARCH_TEXT);
- m_SearchBar->SetWindowTextW(szBuf.GetString());
+ m_SearchBar->GetWindowTextW(szWndText);
+ if (szBuf == szWndText)
+ {
+ m_SearchBar->SetWindowTextW(L"");
+ }
}
- }
- break;
-
- case EN_CHANGE:
- {
- ATL::CStringW szWndText;
+ break;
- szBuf.LoadStringW(IDS_SEARCH_TEXT);
- m_SearchBar->GetWindowTextW(szWndText);
- if (szBuf == szWndText)
+ case EN_KILLFOCUS:
{
- szWndText = L"";
- m_MainWindow->SearchTextChanged(szWndText);
+ m_SearchBar->GetWindowTextW(szBuf);
+ if (szBuf.IsEmpty())
+ {
+ szBuf.LoadStringW(IDS_SEARCH_TEXT);
+ m_SearchBar->SetWindowTextW(szBuf.GetString());
+ }
}
- else
+ break;
+
+ case EN_CHANGE:
{
- m_MainWindow->SearchTextChanged(szWndText);
+ CStringW szWndText;
+
+ szBuf.LoadStringW(IDS_SEARCH_TEXT);
+ m_SearchBar->GetWindowTextW(szWndText);
+ if (szBuf == szWndText)
+ {
+ szWndText = L"";
+ m_MainWindow->SearchTextChanged(szWndText);
+ }
+ else
+ {
+ m_MainWindow->SearchTextChanged(szWndText);
+ }
}
- }
- break;
+ break;
}
return;
@@ -1871,16 +1732,16 @@ VOID CApplicationView::OnCommand(WPARAM wParam, LPARAM lParam)
int NotifyCode = HIWORD(wParam);
switch (NotifyCode)
{
- case CBN_SELCHANGE:
- int CurrSelection = m_ComboBox->SendMessageW(CB_GETCURSEL);
+ case CBN_SELCHANGE:
+ int CurrSelection = m_ComboBox->SendMessageW(CB_GETCURSEL);
- int ViewModeList[] = { LV_VIEW_DETAILS, LV_VIEW_LIST, LV_VIEW_TILE };
- ATLASSERT(CurrSelection < (int)_countof(ViewModeList));
- if (!m_ListView->SetViewMode(ViewModeList[CurrSelection]))
- {
- MessageBoxW(L"View mode invalid or unimplemented");
- }
- break;
+ int ViewModeList[] = {LV_VIEW_DETAILS, LV_VIEW_LIST, LV_VIEW_TILE};
+ ATLASSERT(CurrSelection < (int)_countof(ViewModeList));
+ if (!m_ListView->SetViewMode(ViewModeList[CurrSelection]))
+ {
+ MessageBoxW(L"View mode invalid or unimplemented");
+ }
+ break;
}
return;
@@ -1900,38 +1761,19 @@ VOID CApplicationView::OnCommand(WPARAM wParam, LPARAM lParam)
switch (wCommand)
{
- case ID_INSTALL:
- m_MainWindow->InstallApplication((CAvailableApplicationInfo
*)GetFocusedItemData());
- break;
-
- case ID_TOOLBAR_INSTALL:
- m_MainWindow->SendMessageW(WM_COMMAND, ID_INSTALL, 0);
- break;
-
- case ID_UNINSTALL:
- m_MainWindow->SendMessageW(WM_COMMAND, ID_UNINSTALL, 0);
- break;
-
- case ID_MODIFY:
- m_MainWindow->SendMessageW(WM_COMMAND, ID_MODIFY, 0);
- break;
-
- case ID_REGREMOVE:
- m_MainWindow->SendMessageW(WM_COMMAND, ID_REGREMOVE, 0);
- break;
-
- case ID_REFRESH:
- m_MainWindow->SendMessageW(WM_COMMAND, ID_REFRESH, 0);
- break;
-
- case ID_RESETDB:
- m_MainWindow->SendMessageW(WM_COMMAND, ID_RESETDB, 0);
- break;
+ case ID_INSTALL:
+ case ID_UNINSTALL:
+ case ID_MODIFY:
+ case ID_REGREMOVE:
+ case ID_REFRESH:
+ case ID_RESETDB:
+ case ID_CHECK_ALL:
+ m_MainWindow->SendMessageW(WM_COMMAND, wCommand, 0);
+ break;
}
}
-CApplicationView::CApplicationView(CMainWindow *MainWindow)
- : m_MainWindow(MainWindow)
+CApplicationView::CApplicationView(CMainWindow *MainWindow) : m_MainWindow(MainWindow)
{
}
@@ -1944,40 +1786,34 @@ CApplicationView::~CApplicationView()
delete m_HSplitter;
}
-ATL::CWndClassInfo &CApplicationView::GetWndClassInfo()
+ATL::CWndClassInfo &
+CApplicationView::GetWndClassInfo()
{
DWORD csStyle = CS_VREDRAW | CS_HREDRAW;
- static ATL::CWndClassInfo wc =
- {
- {
- sizeof(WNDCLASSEX),
- csStyle,
- StartWindowProc,
- 0,
- 0,
- NULL,
- NULL,
- NULL,
- (HBRUSH)(COLOR_BTNFACE + 1),
- NULL,
- L"RAppsApplicationView",
- NULL
- },
- NULL, NULL, IDC_ARROW, TRUE, 0, _T("")
- };
+ static ATL::CWndClassInfo wc = {
+ {sizeof(WNDCLASSEX), csStyle, StartWindowProc, 0, 0, NULL, NULL, NULL,
(HBRUSH)(COLOR_BTNFACE + 1), NULL,
+ L"RAppsApplicationView", NULL},
+ NULL,
+ NULL,
+ IDC_ARROW,
+ TRUE,
+ 0,
+ _T("")};
return wc;
}
-HWND CApplicationView::Create(HWND hwndParent)
+HWND
+CApplicationView::Create(HWND hwndParent)
{
- RECT r = { 0,0,0,0 };
+ RECT r = {0, 0, 0, 0};
HMENU menu = GetSubMenu(LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_APPLICATIONMENU)), 0);
return CWindowImpl::Create(hwndParent, r, L"", WS_CHILD | WS_VISIBLE |
WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 0, menu);
}
-BOOL CApplicationView::SetDisplayAppType(APPLICATION_VIEW_TYPE AppType)
+BOOL
+CApplicationView::SetDisplayAppType(APPLICATION_VIEW_TYPE AppType)
{
if (!m_ListView->SetDisplayAppType(AppType))
{
@@ -1989,122 +1825,98 @@ BOOL CApplicationView::SetDisplayAppType(APPLICATION_VIEW_TYPE
AppType)
HMENU hMenu = ::GetMenu(m_hWnd);
switch (AppType)
{
- case AppViewTypeEmpty:
- default:
- EnableMenuItem(hMenu, ID_REGREMOVE, MF_GRAYED);
- EnableMenuItem(hMenu, ID_INSTALL, MF_GRAYED);
- EnableMenuItem(hMenu, ID_UNINSTALL, MF_GRAYED);
- EnableMenuItem(hMenu, ID_MODIFY, MF_GRAYED);
-
- m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_REGREMOVE, TRUE);
- m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_INSTALL, FALSE);
- m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_UNINSTALL, TRUE);
- m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_MODIFY, TRUE);
- break;
+ case AppViewTypeInstalledApps:
+ EnableMenuItem(hMenu, ID_REGREMOVE, MF_ENABLED);
+ EnableMenuItem(hMenu, ID_INSTALL, MF_GRAYED);
+ EnableMenuItem(hMenu, ID_UNINSTALL, MF_ENABLED);
+ EnableMenuItem(hMenu, ID_MODIFY, MF_ENABLED);
- case AppViewTypeInstalledApps:
- EnableMenuItem(hMenu, ID_REGREMOVE, MF_ENABLED);
- EnableMenuItem(hMenu, ID_INSTALL, MF_GRAYED);
- EnableMenuItem(hMenu, ID_UNINSTALL, MF_ENABLED);
- EnableMenuItem(hMenu, ID_MODIFY, MF_ENABLED);
-
- // TODO: instead of disable these button, I would rather remove them.
- m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_REGREMOVE, TRUE);
- m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_INSTALL, FALSE);
- m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_UNINSTALL, TRUE);
- m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_MODIFY, TRUE);
- break;
+ m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_INSTALL, FALSE);
+ m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_UNINSTALL, TRUE);
+ m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_MODIFY, TRUE);
+ break;
- case AppViewTypeAvailableApps:
- EnableMenuItem(hMenu, ID_REGREMOVE, MF_GRAYED);
- EnableMenuItem(hMenu, ID_INSTALL, MF_ENABLED);
- EnableMenuItem(hMenu, ID_UNINSTALL, MF_GRAYED);
- EnableMenuItem(hMenu, ID_MODIFY, MF_GRAYED);
-
- // TODO: instead of disable these button, I would rather remove them.
- m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_REGREMOVE, FALSE);
- m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_INSTALL, TRUE);
- m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_UNINSTALL, FALSE);
- m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_MODIFY, FALSE);
- break;
- }
- return TRUE;
-}
+ case AppViewTypeAvailableApps:
+ EnableMenuItem(hMenu, ID_REGREMOVE, MF_GRAYED);
+ EnableMenuItem(hMenu, ID_INSTALL, MF_ENABLED);
+ EnableMenuItem(hMenu, ID_UNINSTALL, MF_GRAYED);
+ EnableMenuItem(hMenu, ID_MODIFY, MF_GRAYED);
-BOOL CApplicationView::AddInstalledApplication(CInstalledApplicationInfo *InstAppInfo,
LPVOID param)
-{
- if (ApplicationViewType != AppViewTypeInstalledApps)
- {
- return FALSE;
+ m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_INSTALL, TRUE);
+ m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_UNINSTALL, FALSE);
+ m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_MODIFY, FALSE);
+ break;
}
- return m_ListView->AddInstalledApplication(InstAppInfo, param);
+ return TRUE;
}
-BOOL CApplicationView::AddAvailableApplication(CAvailableApplicationInfo *AvlbAppInfo,
BOOL InitCheckState, LPVOID param)
+BOOL
+CApplicationView::AddApplication(CApplicationInfo *AppInfo, BOOL InitialCheckState)
{
- if (ApplicationViewType != AppViewTypeAvailableApps)
- {
- return FALSE;
- }
- return m_ListView->AddAvailableApplication(AvlbAppInfo, InitCheckState, param);
+ return m_ListView->AddApplication(AppInfo, InitialCheckState);
}
-VOID CApplicationView::SetWatermark(const CStringW& Text)
+VOID
+CApplicationView::SetWatermark(const CStringW &Text)
{
m_ListView->SetWatermark(Text);
}
-void CApplicationView::CheckAll()
+void
+CApplicationView::CheckAll()
{
m_ListView->CheckAll();
- return;
}
-PVOID CApplicationView::GetFocusedItemData()
+PVOID
+CApplicationView::GetFocusedItemData()
{
return m_ListView->GetFocusedItemData();
}
-int CApplicationView::GetItemCount()
+int
+CApplicationView::GetItemCount()
{
return m_ListView->GetItemCount();
}
-VOID CApplicationView::AppendTabOrderWindow(int Direction, ATL::CSimpleArray<HWND>
&TabOrderList)
+VOID
+CApplicationView::AppendTabOrderWindow(int Direction, ATL::CSimpleArray<HWND>
&TabOrderList)
{
m_Toolbar->AppendTabOrderWindow(Direction, TabOrderList);
m_ComboBox->AppendTabOrderWindow(Direction, TabOrderList);
m_SearchBar->AppendTabOrderWindow(Direction, TabOrderList);
m_ListView->AppendTabOrderWindow(Direction, TabOrderList);
m_AppsInfo->AppendTabOrderWindow(Direction, TabOrderList);
-
- return;
}
// 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 CApplicationView::ItemGetFocus(LPVOID CallbackParam)
+VOID
+CApplicationView::ItemGetFocus(LPVOID CallbackParam)
{
- switch (ApplicationViewType)
+ if (CallbackParam)
{
- case AppViewTypeInstalledApps:
- return m_AppsInfo->ShowInstalledAppInfo((CInstalledApplicationInfo
*)CallbackParam);
+ CApplicationInfo *Info = static_cast<CApplicationInfo *>(CallbackParam);
+ m_AppsInfo->ShowAppInfo(Info);
- case AppViewTypeAvailableApps:
- return m_AppsInfo->ShowAvailableAppInfo((CAvailableApplicationInfo
*)CallbackParam);
+ if (ApplicationViewType == AppViewTypeInstalledApps)
+ {
+ HMENU hMenu = ::GetMenu(m_hWnd);
- case AppViewTypeEmpty:
- default:
- m_AppsInfo->SetWelcomeText();
- return FALSE;
+ BOOL CanModify = Info->CanModify();
+
+ EnableMenuItem(hMenu, ID_MODIFY, CanModify ? MF_ENABLED : MF_GRAYED);
+ m_Toolbar->SendMessageW(TB_ENABLEBUTTON, ID_MODIFY, CanModify);
+ }
}
}
// 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 CApplicationView::ItemCheckStateChanged(BOOL bChecked, LPVOID CallbackParam)
+// CallbackParam is the param passed to listview when adding the item (the one getting
changed now).
+VOID
+CApplicationView::ItemCheckStateChanged(BOOL bChecked, LPVOID CallbackParam)
{
m_MainWindow->ItemCheckStateChanged(bChecked, CallbackParam);
- return TRUE;
}
// **** CApplicationView ****
diff --git a/base/applications/rapps/available.cpp
b/base/applications/rapps/available.cpp
deleted file mode 100644
index d2da0043f33..00000000000
--- a/base/applications/rapps/available.cpp
+++ /dev/null
@@ -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(a)reactos.org)
- * Copyright 2015 Ismael Ferreras Morezuelas (swyterzone+ros(a)gmail.com)
- * Copyright 2017 Alexander Shaposhnikov (sanchaez(a)reactos.org)
- * Copyright 2020 He Yang (1160386205(a)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
diff --git a/base/applications/rapps/cabinet.cpp b/base/applications/rapps/cabinet.cpp
index 1d7bb691a19..609f28faf5b 100644
--- a/base/applications/rapps/cabinet.cpp
+++ b/base/applications/rapps/cabinet.cpp
@@ -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 */
@@ -177,76 +146,75 @@ FNFDINOTIFY(fnNotify)
switch (fdint)
{
- case fdintCOPY_FILE:
- {
- CStringW szExtractDir, szCabFileName;
+ case fdintCOPY_FILE:
+ {
+ CStringW szExtractDir, szCabFileName;
- // Append the destination directory to the file name.
- MultiByteToWide((LPCSTR) pfdin->pv, szExtractDir, CP_UTF8);
- MultiByteToWide(pfdin->psz1, szCabFileName, CP_ACP);
+ // Append the destination directory to the file name.
+ MultiByteToWide((LPCSTR)pfdin->pv, szExtractDir, CP_UTF8);
+ MultiByteToWide(pfdin->psz1, szCabFileName, CP_ACP);
- if (szCabFileName.Find('\\') >= 0)
- {
- CStringW szNewDirName = szExtractDir;
- int nTokenPos = 0;
- // We do not want to interpret the filename as directory,
- // so bail out before the last token!
- while (szCabFileName.Find('\\', nTokenPos) >= 0)
+ if (szCabFileName.Find('\\') >= 0)
{
- CStringW token = szCabFileName.Tokenize(L"\\", nTokenPos);
- if (token.IsEmpty())
- break;
-
- szNewDirName += L"\\" + token;
- if (!CreateDirectoryW(szNewDirName, NULL))
+ CStringW szNewDirName = szExtractDir;
+ int nTokenPos = 0;
+ // We do not want to interpret the filename as directory,
+ // so bail out before the last token!
+ while (szCabFileName.Find('\\', nTokenPos) >= 0)
{
- DWORD dwErr = GetLastError();
- if (dwErr != ERROR_ALREADY_EXISTS)
+ CStringW token = szCabFileName.Tokenize(L"\\", nTokenPos);
+ if (token.IsEmpty())
+ break;
+
+ szNewDirName += L"\\" + token;
+ if (!CreateDirectoryW(szNewDirName, NULL))
{
- DPRINT1("ERROR: Unable to create directory %S (err
%lu)\n", szNewDirName.GetString(), dwErr);
+ DWORD dwErr = GetLastError();
+ if (dwErr != ERROR_ALREADY_EXISTS)
+ {
+ DPRINT1(
+ "ERROR: Unable to create directory %S (err
%lu)\n", szNewDirName.GetString(), dwErr);
+ }
}
}
}
- }
- CStringW szNewFileName = szExtractDir + L"\\" + szCabFileName;
+ CStringW szNewFileName = szExtractDir + L"\\" + szCabFileName;
- CStringA szFilePathUTF8;
- WideToMultiByte(szNewFileName, szFilePathUTF8, CP_UTF8);
+ CStringA szFilePathUTF8;
+ WideToMultiByte(szNewFileName, szFilePathUTF8, CP_UTF8);
- // Open the file
- iResult = fnFileOpen((LPSTR) szFilePathUTF8.GetString(),
- _O_WRONLY | _O_CREAT,
- 0);
- }
- break;
-
- case fdintCLOSE_FILE_INFO:
- iResult = !fnFileClose(pfdin->hf);
- break;
-
- case fdintNEXT_CABINET:
- if (pfdin->fdie != FDIERROR_NONE)
- {
- iResult = -1;
+ // Open the file
+ iResult = fnFileOpen((LPSTR)szFilePathUTF8.GetString(), _O_WRONLY | _O_CREAT,
0);
}
break;
- case fdintPARTIAL_FILE:
- iResult = 0;
- break;
+ case fdintCLOSE_FILE_INFO:
+ iResult = !fnFileClose(pfdin->hf);
+ break;
- case fdintCABINET_INFO:
- iResult = 0;
- break;
+ case fdintNEXT_CABINET:
+ if (pfdin->fdie != FDIERROR_NONE)
+ {
+ iResult = -1;
+ }
+ break;
- case fdintENUMERATE:
- iResult = 0;
- break;
+ case fdintPARTIAL_FILE:
+ iResult = 0;
+ break;
- default:
- iResult = -1;
- break;
+ case fdintCABINET_INFO:
+ iResult = 0;
+ break;
+
+ case fdintENUMERATE:
+ iResult = 0;
+ break;
+
+ default:
+ iResult = -1;
+ break;
}
return iResult;
@@ -254,33 +222,18 @@ FNFDINOTIFY(fnNotify)
/* cabinet.dll FDI function pointers */
-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(*fnFDIDestroy)(HFDI);
+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 (*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,15 +263,9 @@ BOOL ExtractFilesFromCab(const ATL::CStringW& szCabName,
}
// Create FDI context
- ExtractHandler = pfnFDICreate(fnMemAlloc,
- fnMemFree,
- fnFileOpen,
- fnFileRead,
- fnFileWrite,
- fnFileClose,
- fnFileSeek,
- cpuUNKNOWN,
- &ExtractErrors);
+ 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);
diff --git a/base/applications/rapps/configparser.cpp
b/base/applications/rapps/configparser.cpp
index d5c65991daa..11355b7beca 100644
--- a/base/applications/rapps/configparser.cpp
+++ b/base/applications/rapps/configparser.cpp
@@ -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;
diff --git a/base/applications/rapps/gui.cpp b/base/applications/rapps/gui.cpp
index ec2b15366e0..d457cf148e9 100644
--- a/base/applications/rapps/gui.cpp
+++ b/base/applications/rapps/gui.cpp
@@ -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,262 +263,216 @@ 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)
{
- case WM_CREATE:
- if (!InitControls())
- ::PostMessageW(hwnd, WM_CLOSE, 0, 0);
- break;
-
- case WM_DESTROY:
- {
... 6093 lines suppressed ...