diff --git a/base/applications/rapps/CMakeLists.txt b/base/applications/rapps/CMakeLists.txt index 8a260cfb2e394..0e22cea8134e5 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 0000000000000..f1044c57ba8e4 --- /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@reactos.org) + * Copyright 2020 He Yang (1160386205@qq.com) + * Copyright 2021-2023 Mark Jansen + */ + +#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 &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 &List, AppsCategories Type) const +{ + const BOOL UseInstalled = IsInstalledEnum(Type); + const CAtlList &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(Cat), AppsPath); + if (Info->Valid()) + { + m_Available.AddTail(Info); + } + else + { + delete Info; + } + } + + } while (FindNextFileW(hFind, &FindFileData)); + + FindClose(hFind); + return TRUE; +} + +VOID +CApplicationDB::UpdateAvailable() +{ + if (!CreateDirectoryW(m_BasePath, NULL) && GetLastError() != ERROR_ALREADY_EXISTS) + return; + + if (EnumerateFiles()) + return; + + DownloadApplicationsDB( + SettingsInfo.bUseSource ? SettingsInfo.szSourceURL : APPLICATION_DATABASE_URL, !SettingsInfo.bUseSource); + + CPathW AppsPath = m_BasePath; + AppsPath += L"rapps"; + if (!ExtractFilesFromCab(APPLICATION_DATABASE_NAME, m_BasePath, AppsPath)) + return; + + CPathW CabFile = m_BasePath; + CabFile += APPLICATION_DATABASE_NAME; + DeleteFileW(CabFile); + + EnumerateFiles(); +} + +VOID +CApplicationDB::UpdateInstalled() +{ + // Remove all old entries + ClearList(m_Installed); + + int LoopKeys = 2; + + if (IsSystem64Bit()) + { + // loop for all 3 combination. + // note that HKEY_CURRENT_USER\Software don't have a redirect + // https://docs.microsoft.com/en-us/windows/win32/winprog64/shared-registry-keys#redirected-shared-and-reflected-keys-under-wow64 + LoopKeys = 3; + } + + for (int keyIndex = 0; keyIndex < LoopKeys; keyIndex++) + { + LONG ItemIndex = 0; + WCHAR szKeyName[MAX_PATH]; + + CRegKey hKey; + if (hKey.Open(g_RootKeyEnum[keyIndex], UNINSTALL_SUBKEY, KEY_READ | g_RegSamEnum[keyIndex]) != ERROR_SUCCESS) + { + continue; + } + + while (1) + { + DWORD dwSize = _countof(szKeyName); + if (hKey.EnumKey(ItemIndex, szKeyName, &dwSize) != ERROR_SUCCESS) + { + break; + } + + ItemIndex++; + + CRegKey hSubKey; + if (hSubKey.Open(hKey, szKeyName, KEY_READ) == ERROR_SUCCESS) + { + DWORD dwValue = 0; + + dwSize = sizeof(DWORD); + if (RegQueryValueExW(hSubKey, L"SystemComponent", NULL, NULL, (LPBYTE)&dwValue, &dwSize) == + ERROR_SUCCESS && + dwValue == 1) + { + // Ignore system components + continue; + } + + BOOL bIsUpdate = + (RegQueryValueExW(hSubKey, L"ParentKeyName", NULL, NULL, NULL, &dwSize) == ERROR_SUCCESS); + + CInstalledApplicationInfo *Info = new CInstalledApplicationInfo( + hSubKey.Detach(), szKeyName, bIsUpdate ? ENUM_UPDATES : ENUM_INSTALLED_APPLICATIONS, keyIndex); + + if (Info->Valid()) + { + m_Installed.AddTail(Info); + } + else + { + delete Info; + } + } + } + } +} + +static void +DeleteWithWildcard(const CPathW &Dir, const CStringW &Filter) +{ + HANDLE hFind = INVALID_HANDLE_VALUE; + WIN32_FIND_DATAW FindFileData; + + CPathW DirWithFilter = Dir; + DirWithFilter += Filter; + + hFind = FindFirstFileW(DirWithFilter, &FindFileData); + + if (hFind == INVALID_HANDLE_VALUE) + return; + + do + { + CPathW szTmp = Dir; + szTmp += FindFileData.cFileName; + + if (!(FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) + { + DeleteFileW(szTmp); + } + } while (FindNextFileW(hFind, &FindFileData) != 0); + FindClose(hFind); +} + +VOID +CApplicationDB::RemoveCached() +{ + // Delete icons + CPathW AppsPath = m_BasePath; + AppsPath += L"rapps"; + CPathW IconPath = AppsPath; + IconPath += L"icons"; + DeleteWithWildcard(IconPath, L"*.ico"); + + // Delete leftover screenshots + CPathW ScrnshotFolder = AppsPath; + ScrnshotFolder += L"screenshots"; + DeleteWithWildcard(ScrnshotFolder, L"*.tmp"); + + // Delete data base files (*.txt) + DeleteWithWildcard(AppsPath, L"*.txt"); + + RemoveDirectoryW(IconPath); + RemoveDirectoryW(ScrnshotFolder); + RemoveDirectoryW(AppsPath); + RemoveDirectoryW(m_BasePath); +} + +BOOL +CApplicationDB::RemoveInstalledAppFromRegistry(const CApplicationInfo *Info) +{ + // Validate that this is actually an installed app / update + ATLASSERT(Info->iCategory == ENUM_INSTALLED_APPLICATIONS || Info->iCategory == ENUM_UPDATES); + if (Info->iCategory != ENUM_INSTALLED_APPLICATIONS && Info->iCategory != ENUM_UPDATES) + return FALSE; + + // Grab the index in the registry keys + const CInstalledApplicationInfo *InstalledInfo = static_cast(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 0000000000000..942668e05dea9 --- /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@reactos.org) + * Copyright 2020 He Yang (1160386205@qq.com) + * Copyright 2021-2023 Mark Jansen + */ + +#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(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(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 11e442d28e39b..5c1c548b6a6a3 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@qq.com) + * COPYRIGHT: Copyright 2020 He Yang (1160386205@qq.com) + * Copyright 2022,2023 Mark Jansen */ #include "rapps.h" @@ -10,39 +11,34 @@ #include "gui.h" #include +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(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(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(); 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(); 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 &TabOrderList) +VOID +CApplicationView::AppendTabOrderWindow(int Direction, ATL::CSimpleArray &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(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 d2da0043f3319..0000000000000 --- 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@reactos.org) - * Copyright 2015 Ismael Ferreras Morezuelas (swyterzone+ros@gmail.com) - * Copyright 2017 Alexander Shaposhnikov (sanchaez@reactos.org) - * Copyright 2020 He Yang (1160386205@qq.com) - */ - -#include "rapps.h" - -#include "available.h" -#include "misc.h" -#include "dialogs.h" - - -// CAvailableApplicationInfo -CAvailableApplicationInfo::CAvailableApplicationInfo(const ATL::CStringW& sFileNameParam, AvailableStrings& AvlbStrings) - : m_LicenseType(LICENSE_NONE), m_SizeBytes(0), m_sFileName(sFileNameParam), - m_IsInstalled(FALSE), m_HasLanguageInfo(FALSE), m_HasInstalledVersion(FALSE) -{ - RetrieveGeneralInfo(AvlbStrings); -} - -VOID CAvailableApplicationInfo::RefreshAppInfo(AvailableStrings& AvlbStrings) -{ - if (m_szUrlDownload.IsEmpty()) - { - RetrieveGeneralInfo(AvlbStrings); - } -} - -// Lazily load general info from the file -VOID CAvailableApplicationInfo::RetrieveGeneralInfo(AvailableStrings& AvlbStrings) -{ - m_Parser = new CConfigParser(m_sFileName); - - // TODO: I temporarily use the file name (without suffix) as package name. - // It should be better to put this in a field of ini file. - // Consider writing a converter to do this and write a github action for - // rapps-db to ensure package_name is unique. - m_szPkgName = m_sFileName; - PathRemoveExtensionW(m_szPkgName.GetBuffer(MAX_PATH)); - m_szPkgName.ReleaseBuffer(); - - m_Parser->GetInt(L"Category", m_Category); - - if (!GetString(L"Name", m_szName) - || !GetString(L"URLDownload", m_szUrlDownload)) - { - delete m_Parser; - return; - } - - GetString(L"RegName", m_szRegName); - GetString(L"Version", m_szVersion); - GetString(L"License", m_szLicense); - GetString(L"Description", m_szDesc); - GetString(L"URLSite", m_szUrlSite); - GetString(L"SHA1", m_szSHA1); - - static_assert(MAX_SCRNSHOT_NUM < 10000, "MAX_SCRNSHOT_NUM is too big"); - for (int i = 0; i < MAX_SCRNSHOT_NUM; i++) - { - CStringW ScrnshotField; - ScrnshotField.Format(L"Screenshot%d", i + 1); - CStringW ScrnshotLocation; - if (!GetString(ScrnshotField, ScrnshotLocation)) - { - // We stop at the first screenshot not found, - // so screenshots _have_ to be consecutive - break; - } - - if (PathIsURLW(ScrnshotLocation.GetString())) - { - m_szScrnshotLocation.Add(ScrnshotLocation); - } - else - { - // TODO: Does the filename contain anything stuff like ":" "<" ">" ? - // these stuff may lead to security issues - ATL::CStringW ScrnshotName = AvlbStrings.szAppsPath; - PathAppendW(ScrnshotName.GetBuffer(MAX_PATH), L"screenshots"); - BOOL bSuccess = PathAppendNoDirEscapeW(ScrnshotName.GetBuffer(), ScrnshotLocation.GetString()); - ScrnshotName.ReleaseBuffer(); - if (bSuccess) - { - m_szScrnshotLocation.Add(ScrnshotName); - } - } - } - - ATL::CStringW IconPath = AvlbStrings.szAppsPath; - PathAppendW(IconPath.GetBuffer(MAX_PATH), L"icons"); - - // TODO: are we going to support specify an URL for an icon ? - ATL::CStringW IconLocation; - if (GetString(L"Icon", IconLocation)) - { - BOOL bSuccess = PathAppendNoDirEscapeW(IconPath.GetBuffer(), IconLocation.GetString()); - IconPath.ReleaseBuffer(); - - if (!bSuccess) - { - IconPath.Empty(); - } - } - else - { - // inifile.ico - PathAppendW(IconPath.GetBuffer(), m_szPkgName); - IconPath.ReleaseBuffer(); - IconPath += L".ico"; - } - - if (!IconPath.IsEmpty()) - { - if (PathFileExistsW(IconPath)) - { - m_szIconLocation = IconPath; - } - } - - RetrieveSize(); - RetrieveLicenseType(); - RetrieveLanguages(); - RetrieveInstalledStatus(); - - if (m_IsInstalled) - { - RetrieveInstalledVersion(); - } - - delete m_Parser; -} - -VOID CAvailableApplicationInfo::RetrieveInstalledStatus() -{ - m_IsInstalled = ::GetInstalledVersion(NULL, m_szRegName) - || ::GetInstalledVersion(NULL, m_szName); -} - -VOID CAvailableApplicationInfo::RetrieveInstalledVersion() -{ - ATL::CStringW szNameVersion; - szNameVersion = m_szName + L" " + m_szVersion; - m_HasInstalledVersion = ::GetInstalledVersion(&m_szInstalledVersion, m_szRegName) - || ::GetInstalledVersion(&m_szInstalledVersion, m_szName) - || ::GetInstalledVersion(&m_szInstalledVersion, szNameVersion); -} - -VOID CAvailableApplicationInfo::RetrieveLanguages() -{ - const WCHAR cDelimiter = L'|'; - ATL::CStringW szBuffer; - - // TODO: Get multiline parameter - if (!m_Parser->GetString(L"Languages", szBuffer)) - { - m_HasLanguageInfo = FALSE; - return; - } - - // Parse parameter string - ATL::CStringW m_szLocale; - INT iLCID; - for (INT i = 0; szBuffer[i] != UNICODE_NULL; ++i) - { - if (szBuffer[i] != cDelimiter && szBuffer[i] != L'\n') - { - m_szLocale += szBuffer[i]; - } - else - { - if (StrToIntExW(m_szLocale.GetString(), STIF_DEFAULT, &iLCID)) - { - m_LanguageLCIDs.Add(static_cast(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(iLCID)); - } - } - - m_HasLanguageInfo = TRUE; -} - -VOID CAvailableApplicationInfo::RetrieveLicenseType() -{ - INT IntBuffer; - - m_Parser->GetInt(L"LicenseType", IntBuffer); - - if (IsLicenseType(IntBuffer)) - { - m_LicenseType = static_cast(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 CAvailableApps::FindAppsByPkgNameList(const ATL::CSimpleArray &PkgNameList) const -{ - ATL::CSimpleArray 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 1d7bb691a19db..609f28faf5b21 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 d5c65991daa86..11355b7beca01 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 ec2b15366e0bc..d457cf148e922 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::AddItem(hParent, const_cast(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::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(); 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: - { - ShowWindow(SW_HIDE); - SaveSettings(hwnd, &SettingsInfo); + case WM_CREATE: + if (!InitControls()) + ::PostMessageW(hwnd, WM_CLOSE, 0, 0); + break; - FreeLogs(); - m_AvailableApps.FreeCachedEntries(); - m_InstalledApps.FreeCachedEntries(); + case WM_DESTROY: + { + ShowWindow(SW_HIDE); + SaveSettings(hwnd, &SettingsInfo); - delete m_ClientPanel; + FreeLogs(); - PostQuitMessage(0); - return 0; - } + delete m_ClientPanel; - case WM_COMMAND: - OnCommand(wParam, lParam); - break; + PostQuitMessage(0); + return 0; + } - case WM_NOTIFY: - { - LPNMHDR data = (LPNMHDR)lParam; + case WM_COMMAND: + OnCommand(wParam, lParam); + break; - switch (data->code) + case WM_NOTIFY: { - case TVN_SELCHANGED: - { - if (data->hwndFrom == m_TreeView->m_hWnd) + LPNMHDR data = (LPNMHDR)lParam; + + switch (data->code) { - switch (((LPNMTREEVIEW)lParam)->itemNew.lParam) + case TVN_SELCHANGED: { - case IDS_INSTALLED: - UpdateApplicationsList(ENUM_ALL_INSTALLED); - break; + if (data->hwndFrom == m_TreeView->m_hWnd) + { + switch (((LPNMTREEVIEW)lParam)->itemNew.lParam) + { + case IDS_INSTALLED: + UpdateApplicationsList(ENUM_ALL_INSTALLED); + break; - case IDS_APPLICATIONS: - UpdateApplicationsList(ENUM_INSTALLED_APPLICATIONS); - break; + case IDS_APPLICATIONS: + UpdateApplicationsList(ENUM_INSTALLED_APPLICATIONS); + break; - case IDS_UPDATES: - UpdateApplicationsList(ENUM_UPDATES); - break; + case IDS_UPDATES: + UpdateApplicationsList(ENUM_UPDATES); + break; - case IDS_AVAILABLEFORINST: - UpdateApplicationsList(ENUM_ALL_AVAILABLE); - break; + case IDS_AVAILABLEFORINST: + UpdateApplicationsList(ENUM_ALL_AVAILABLE); + break; - case IDS_CAT_AUDIO: - UpdateApplicationsList(ENUM_CAT_AUDIO); - break; + case IDS_CAT_AUDIO: + UpdateApplicationsList(ENUM_CAT_AUDIO); + break; - case IDS_CAT_DEVEL: - UpdateApplicationsList(ENUM_CAT_DEVEL); - break; + case IDS_CAT_DEVEL: + UpdateApplicationsList(ENUM_CAT_DEVEL); + break; - case IDS_CAT_DRIVERS: - UpdateApplicationsList(ENUM_CAT_DRIVERS); - break; + case IDS_CAT_DRIVERS: + UpdateApplicationsList(ENUM_CAT_DRIVERS); + break; - case IDS_CAT_EDU: - UpdateApplicationsList(ENUM_CAT_EDU); - break; + case IDS_CAT_EDU: + UpdateApplicationsList(ENUM_CAT_EDU); + break; - case IDS_CAT_ENGINEER: - UpdateApplicationsList(ENUM_CAT_ENGINEER); - break; + case IDS_CAT_ENGINEER: + UpdateApplicationsList(ENUM_CAT_ENGINEER); + break; - case IDS_CAT_FINANCE: - UpdateApplicationsList(ENUM_CAT_FINANCE); - break; + case IDS_CAT_FINANCE: + UpdateApplicationsList(ENUM_CAT_FINANCE); + break; - case IDS_CAT_GAMES: - UpdateApplicationsList(ENUM_CAT_GAMES); - break; + case IDS_CAT_GAMES: + UpdateApplicationsList(ENUM_CAT_GAMES); + break; - case IDS_CAT_GRAPHICS: - UpdateApplicationsList(ENUM_CAT_GRAPHICS); - break; + case IDS_CAT_GRAPHICS: + UpdateApplicationsList(ENUM_CAT_GRAPHICS); + break; - case IDS_CAT_INTERNET: - UpdateApplicationsList(ENUM_CAT_INTERNET); - break; + case IDS_CAT_INTERNET: + UpdateApplicationsList(ENUM_CAT_INTERNET); + break; - case IDS_CAT_LIBS: - UpdateApplicationsList(ENUM_CAT_LIBS); - break; + case IDS_CAT_LIBS: + UpdateApplicationsList(ENUM_CAT_LIBS); + break; - case IDS_CAT_OFFICE: - UpdateApplicationsList(ENUM_CAT_OFFICE); - break; + case IDS_CAT_OFFICE: + UpdateApplicationsList(ENUM_CAT_OFFICE); + break; - case IDS_CAT_OTHER: - UpdateApplicationsList(ENUM_CAT_OTHER); - break; + case IDS_CAT_OTHER: + UpdateApplicationsList(ENUM_CAT_OTHER); + break; - case IDS_CAT_SCIENCE: - UpdateApplicationsList(ENUM_CAT_SCIENCE); - break; + case IDS_CAT_SCIENCE: + UpdateApplicationsList(ENUM_CAT_SCIENCE); + break; - case IDS_CAT_TOOLS: - UpdateApplicationsList(ENUM_CAT_TOOLS); - break; + case IDS_CAT_TOOLS: + UpdateApplicationsList(ENUM_CAT_TOOLS); + break; - case IDS_CAT_VIDEO: - UpdateApplicationsList(ENUM_CAT_VIDEO); - break; + case IDS_CAT_VIDEO: + UpdateApplicationsList(ENUM_CAT_VIDEO); + break; - case IDS_CAT_THEMES: - UpdateApplicationsList(ENUM_CAT_THEMES); - break; + case IDS_CAT_THEMES: + UpdateApplicationsList(ENUM_CAT_THEMES); + break; - case IDS_SELECTEDFORINST: - UpdateApplicationsList(ENUM_CAT_SELECTED); - break; + case IDS_SELECTEDFORINST: + UpdateApplicationsList(ENUM_CAT_SELECTED); + break; + } + } } - } - - HMENU mainMenu = ::GetMenu(hwnd); - - /* Disable/enable items based on treeview selection */ - if (IsSelectedNodeInstalled()) - { - EnableMenuItem(mainMenu, ID_REGREMOVE, MF_ENABLED); - EnableMenuItem(mainMenu, ID_INSTALL, MF_GRAYED); - EnableMenuItem(mainMenu, ID_UNINSTALL, MF_ENABLED); - EnableMenuItem(mainMenu, ID_MODIFY, MF_ENABLED); - } - else - { - EnableMenuItem(mainMenu, ID_REGREMOVE, MF_GRAYED); - EnableMenuItem(mainMenu, ID_INSTALL, MF_ENABLED); - EnableMenuItem(mainMenu, ID_UNINSTALL, MF_GRAYED); - EnableMenuItem(mainMenu, ID_MODIFY, MF_GRAYED); + break; } } break; - } - } - break; - - case WM_SIZE: - OnSize(hwnd, wParam, lParam); - break; + case WM_SIZE: + OnSize(hwnd, wParam, lParam); + break; - case WM_SIZING: - { - LPRECT pRect = (LPRECT)lParam; + case WM_SIZING: + { + LPRECT pRect = (LPRECT)lParam; - if (pRect->right - pRect->left < 565) - pRect->right = pRect->left + 565; + if (pRect->right - pRect->left < 565) + pRect->right = pRect->left + 565; - if (pRect->bottom - pRect->top < 300) - pRect->bottom = pRect->top + 300; + if (pRect->bottom - pRect->top < 300) + pRect->bottom = pRect->top + 300; - return TRUE; - } - - case WM_SYSCOLORCHANGE: - { - /* Forward WM_SYSCOLORCHANGE to common controls */ - m_ApplicationView->SendMessageW(WM_SYSCOLORCHANGE, wParam, lParam); - m_TreeView->SendMessageW(WM_SYSCOLORCHANGE, wParam, lParam); - } - break; + return TRUE; + } - case WM_TIMER: - if (wParam == SEARCH_TIMER_ID) + case WM_SYSCOLORCHANGE: { - ::KillTimer(hwnd, SEARCH_TIMER_ID); - - UpdateApplicationsList(-1); + /* Forward WM_SYSCOLORCHANGE to common controls */ + m_ApplicationView->SendMessageW(WM_SYSCOLORCHANGE, wParam, lParam); + m_TreeView->SendMessageW(WM_SYSCOLORCHANGE, wParam, lParam); } break; - } - return FALSE; -} - -BOOL CMainWindow::IsSelectedNodeInstalled() -{ - HTREEITEM hSelectedItem = m_TreeView->GetSelection(); - TV_ITEM tItem; + case WM_TIMER: + if (wParam == SEARCH_TIMER_ID) + { + ::KillTimer(hwnd, SEARCH_TIMER_ID); - tItem.mask = TVIF_PARAM | TVIF_HANDLE; - tItem.hItem = hSelectedItem; - m_TreeView->GetItem(&tItem); - switch (tItem.lParam) - { - case IDS_INSTALLED: - case IDS_APPLICATIONS: - case IDS_UPDATES: - return TRUE; - default: - return FALSE; + UpdateApplicationsList(SelectedEnumType); + } + break; } + + return FALSE; } -VOID CMainWindow::ShowAboutDlg() +VOID +CMainWindow::ShowAboutDlg() { - ATL::CStringW szApp; - ATL::CStringW szAuthors; + CStringW szApp; + CStringW szAuthors; HICON hIcon; szApp.LoadStringW(IDS_APPTITLE); @@ -529,179 +482,164 @@ VOID CMainWindow::ShowAboutDlg() DestroyIcon(hIcon); } -VOID CMainWindow::OnCommand(WPARAM wParam, LPARAM lParam) +VOID +CMainWindow::OnCommand(WPARAM wParam, LPARAM lParam) { + const BOOL bReload = TRUE; WORD wCommand = LOWORD(wParam); if (!lParam) { switch (wCommand) { - case ID_SETTINGS: - CreateSettingsDlg(m_hWnd); - break; + case ID_SETTINGS: + CreateSettingsDlg(m_hWnd); + break; - case ID_EXIT: - PostMessageW(WM_CLOSE, 0, 0); - break; + case ID_EXIT: + PostMessageW(WM_CLOSE, 0, 0); + break; - case ID_SEARCH: - m_ApplicationView->SetFocusOnSearchBar(); - break; - - case ID_INSTALL: - if (IsAvailableEnum(SelectedEnumType)) - { - ATL::CSimpleArray AppsList; + case ID_SEARCH: + m_ApplicationView->SetFocusOnSearchBar(); + break; - // enum all selected apps - m_AvailableApps.Enum(ENUM_CAT_SELECTED, s_EnumSelectedAppForDownloadProc, (PVOID)&AppsList); - - if (AppsList.GetSize()) - { - if (DownloadListOfApplications(AppsList, FALSE)) - { - m_AvailableApps.RemoveAllSelected(); - UpdateApplicationsList(-1); - } - } - else + case ID_INSTALL: + if (IsAvailableEnum(SelectedEnumType)) { - // use the currently focused item in application-view - CAvailableApplicationInfo *FocusedApps = (CAvailableApplicationInfo *)m_ApplicationView->GetFocusedItemData(); - if (FocusedApps) + if (!m_Selected.IsEmpty()) { - if (DownloadApplication(FocusedApps)) + if (DownloadListOfApplications(m_Selected, FALSE)) { - UpdateApplicationsList(-1); + m_Selected.RemoveAll(); + UpdateApplicationsList(SelectedEnumType); } } else { - // TODO: in this case, Install button in toolbar (and all other places) should be disabled - // or at least popup a messagebox telling user to select/check some app first + CApplicationInfo *App = (CApplicationInfo *)m_ApplicationView->GetFocusedItemData(); + if (App) + { + InstallApplication(App); + } } } - } - break; - - case ID_UNINSTALL: - if (UninstallSelectedApp(FALSE)) - UpdateApplicationsList(-1); - break; - - case ID_MODIFY: - if (UninstallSelectedApp(TRUE)) - UpdateApplicationsList(-1); - break; - - case ID_REGREMOVE: - RemoveSelectedAppFromRegistry(); - break; - - case ID_REFRESH: - UpdateApplicationsList(-1); - break; - - case ID_RESETDB: - CAvailableApps::ForceUpdateAppsDB(); - UpdateApplicationsList(-1); - break; - - case ID_HELP: - MessageBoxW(L"Help not implemented yet", NULL, MB_OK); - break; - - case ID_ABOUT: - ShowAboutDlg(); - break; - - case ID_CHECK_ALL: - m_ApplicationView->CheckAll(); - break; + break; + + case ID_UNINSTALL: + if (UninstallSelectedApp(FALSE)) + UpdateApplicationsList(SelectedEnumType, bReload); + break; + + case ID_MODIFY: + if (UninstallSelectedApp(TRUE)) + UpdateApplicationsList(SelectedEnumType, bReload); + break; + + case ID_REGREMOVE: + if (RemoveSelectedAppFromRegistry()) + UpdateApplicationsList(SelectedEnumType, bReload); + break; + + case ID_REFRESH: + UpdateApplicationsList(SelectedEnumType); + break; + + case ID_RESETDB: + m_Db->RemoveCached(); + UpdateApplicationsList(SelectedEnumType, bReload); + break; + + case ID_HELP: + MessageBoxW(L"Help not implemented yet", NULL, MB_OK); + break; + + case ID_ABOUT: + ShowAboutDlg(); + break; + + case ID_CHECK_ALL: + m_ApplicationView->CheckAll(); + break; } } } -BOOL CALLBACK CMainWindow::EnumInstalledAppProc(CInstalledApplicationInfo *Info) +VOID +CMainWindow::UpdateStatusBarText() { - if (!SearchPatternMatch(Info->szDisplayName.GetString(), szSearchPattern)) + if (m_StatusBar) { - return TRUE; - } - return m_ApplicationView->AddInstalledApplication(Info, Info); // currently, the callback param is Info itself -} + CStringW szBuffer; -BOOL CALLBACK CMainWindow::EnumAvailableAppProc(CAvailableApplicationInfo *Info, BOOL bInitialCheckState) -{ - if (!SearchPatternMatch(Info->m_szName.GetString(), szSearchPattern) && - !SearchPatternMatch(Info->m_szDesc.GetString(), szSearchPattern)) - { - return TRUE; + szBuffer.Format(IDS_APPS_COUNT, m_ApplicationView->GetItemCount(), m_Selected.GetCount()); + m_StatusBar->SetText(szBuffer); } - return m_ApplicationView->AddAvailableApplication(Info, bInitialCheckState, Info); // currently, the callback param is Info itself } -BOOL CALLBACK CMainWindow::s_EnumInstalledAppProc(CInstalledApplicationInfo *Info, PVOID param) +VOID +CMainWindow::AddApplicationsToView(CAtlList &List) { - CMainWindow *pThis = (CMainWindow *)param; - return pThis->EnumInstalledAppProc(Info); -} - -BOOL CALLBACK CMainWindow::s_EnumAvailableAppProc(CAvailableApplicationInfo *Info, BOOL bInitialCheckState, PVOID param) -{ - CMainWindow *pThis = (CMainWindow *)param; - return pThis->EnumAvailableAppProc(Info, bInitialCheckState); -} - -BOOL CALLBACK CMainWindow::s_EnumSelectedAppForDownloadProc(CAvailableApplicationInfo *Info, BOOL bInitialCheckState, PVOID param) -{ - ATL::CSimpleArray *pAppList = (ATL::CSimpleArray *)param; - pAppList->Add(*Info); - return TRUE; -} - -VOID CMainWindow::UpdateStatusBarText() -{ - if (m_StatusBar) + POSITION CurrentListPosition = List.GetHeadPosition(); + while (CurrentListPosition) { - ATL::CStringW szBuffer; - - szBuffer.Format(IDS_APPS_COUNT, m_ApplicationView->GetItemCount(), m_AvailableApps.GetSelectedCount()); - m_StatusBar->SetText(szBuffer); + CApplicationInfo *Info = List.GetNext(CurrentListPosition); + if (szSearchPattern.IsEmpty() || SearchPatternMatch(Info->szDisplayName, szSearchPattern) || + SearchPatternMatch(Info->szComments, szSearchPattern)) + { + BOOL bSelected = m_Selected.Find(Info) != NULL; + m_ApplicationView->AddApplication(Info, bSelected); + } } } -VOID CMainWindow::UpdateApplicationsList(INT EnumType) +VOID +CMainWindow::UpdateApplicationsList(AppsCategories EnumType, BOOL bReload) { bUpdating = TRUE; - if (EnumType == -1) - { - // keep the old enum type - EnumType = SelectedEnumType; - } - else - { + if (SelectedEnumType != EnumType) SelectedEnumType = EnumType; - } + + if (bReload) + m_Selected.RemoveAll(); m_ApplicationView->SetRedraw(FALSE); if (IsInstalledEnum(EnumType)) { + if (bReload) + m_Db->UpdateInstalled(); + // set the display type of application-view. this will remove all the item in application-view too. m_ApplicationView->SetDisplayAppType(AppViewTypeInstalledApps); - // enum installed softwares - m_InstalledApps.Enum(EnumType, s_EnumInstalledAppProc, this); + CAtlList List; + m_Db->GetApps(List, EnumType); + AddApplicationsToView(List); } else if (IsAvailableEnum(EnumType)) { + if (bReload) + m_Db->UpdateAvailable(); + // set the display type of application-view. this will remove all the item in application-view too. m_ApplicationView->SetDisplayAppType(AppViewTypeAvailableApps); // enum available softwares - m_AvailableApps.Enum(EnumType, s_EnumAvailableAppProc, this); + if (EnumType == ENUM_CAT_SELECTED) + { + AddApplicationsToView(m_Selected); + } + else + { + CAtlList List; + m_Db->GetApps(List, EnumType); + AddApplicationsToView(List); + } + } + else + { + ATLASSERT(0 && "This should be unreachable!"); } m_ApplicationView->SetRedraw(TRUE); m_ApplicationView->RedrawWindow(0, 0, RDW_INVALIDATE | RDW_ALLCHILDREN); // force the child window to repaint @@ -717,111 +655,87 @@ VOID CMainWindow::UpdateApplicationsList(INT EnumType) bUpdating = FALSE; } -ATL::CWndClassInfo &CMainWindow::GetWndClassInfo() +ATL::CWndClassInfo & +CMainWindow::GetWndClassInfo() { DWORD csStyle = CS_VREDRAW | CS_HREDRAW; - static ATL::CWndClassInfo wc = - { - { - sizeof(WNDCLASSEX), - csStyle, - StartWindowProc, - 0, - 0, - NULL, - LoadIconW(_AtlBaseModule.GetModuleInstance(), MAKEINTRESOURCEW(IDI_MAIN)), - LoadCursorW(NULL, IDC_ARROW), - (HBRUSH)(COLOR_BTNFACE + 1), - MAKEINTRESOURCEW(IDR_MAINMENU), - szWindowClass, - NULL - }, - NULL, NULL, IDC_ARROW, TRUE, 0, _T("") - }; + static ATL::CWndClassInfo wc = { + {sizeof(WNDCLASSEX), csStyle, StartWindowProc, 0, 0, NULL, + LoadIconW(_AtlBaseModule.GetModuleInstance(), MAKEINTRESOURCEW(IDI_MAIN)), LoadCursorW(NULL, IDC_ARROW), + (HBRUSH)(COLOR_BTNFACE + 1), MAKEINTRESOURCEW(IDR_MAINMENU), szWindowClass, NULL}, + NULL, + NULL, + IDC_ARROW, + TRUE, + 0, + _T("")}; return wc; } -HWND CMainWindow::Create() +HWND +CMainWindow::Create() { - ATL::CStringW szWindowName; + CStringW szWindowName; szWindowName.LoadStringW(IDS_APPTITLE); RECT r = { (SettingsInfo.bSaveWndPos ? SettingsInfo.Left : CW_USEDEFAULT), (SettingsInfo.bSaveWndPos ? SettingsInfo.Top : CW_USEDEFAULT), - (SettingsInfo.bSaveWndPos ? SettingsInfo.Width : 680), - (SettingsInfo.bSaveWndPos ? SettingsInfo.Height : 450) - }; + (SettingsInfo.bSaveWndPos ? SettingsInfo.Width : 680), (SettingsInfo.bSaveWndPos ? SettingsInfo.Height : 450)}; r.right += r.left; r.bottom += r.top; - return CWindowImpl::Create(NULL, r, szWindowName.GetString(), WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE); + return CWindowImpl::Create( + NULL, r, szWindowName.GetString(), WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, WS_EX_WINDOWEDGE); } // this function is called when a item of application-view is checked/unchecked // CallbackParam is the param passed to application-view when adding the item (the one getting focus now). -BOOL CMainWindow::ItemCheckStateChanged(BOOL bChecked, LPVOID CallbackParam) +VOID +CMainWindow::ItemCheckStateChanged(BOOL bChecked, LPVOID CallbackParam) { - if (!bUpdating) - { - if (bChecked) - { - if (!m_AvailableApps.AddSelected((CAvailableApplicationInfo *)CallbackParam)) - { - return FALSE; - } - } - else - { - if (!m_AvailableApps.RemoveSelected((CAvailableApplicationInfo *)CallbackParam)) - { - return FALSE; - } - } + if (bUpdating) + return; - UpdateStatusBarText(); - return TRUE; + CApplicationInfo *Info = (CApplicationInfo *)CallbackParam; + + if (bChecked) + { + m_Selected.AddTail(Info); } else { - return TRUE; + POSITION Pos = m_Selected.Find(Info); + ATLASSERT(Pos != NULL); + + if (Pos != NULL) + { + m_Selected.RemoveAt(Pos); + } } + + UpdateStatusBarText(); } -// this function is called when one or more application(s) should be installed install +// this function is called when one or more application(s) should be installed // if Info is not zero, this app should be installed. otherwise those checked apps should be installed -BOOL CMainWindow::InstallApplication(CAvailableApplicationInfo *Info) +BOOL +CMainWindow::InstallApplication(CApplicationInfo *Info) { if (Info) { if (DownloadApplication(Info)) { - UpdateApplicationsList(-1); + UpdateApplicationsList(SelectedEnumType); return TRUE; } } - else - { - ATL::CSimpleArray AppsList; - - // enum all selected apps - m_AvailableApps.Enum(ENUM_CAT_SELECTED, s_EnumSelectedAppForDownloadProc, (PVOID)&AppsList); - - if (AppsList.GetSize()) - { - if (DownloadListOfApplications(AppsList, FALSE)) - { - m_AvailableApps.RemoveAllSelected(); - UpdateApplicationsList(-1); - return TRUE; - } - } - } return FALSE; } -BOOL CMainWindow::SearchTextChanged(ATL::CStringW &SearchText) +BOOL +CMainWindow::SearchTextChanged(CStringW &SearchText) { if (szSearchPattern == SearchText) { @@ -830,21 +744,21 @@ BOOL CMainWindow::SearchTextChanged(ATL::CStringW &SearchText) szSearchPattern = SearchText; - DWORD dwDelay; + DWORD dwDelay = 0; SystemParametersInfoW(SPI_GETMENUSHOWDELAY, 0, &dwDelay, 0); SetTimer(SEARCH_TIMER_ID, dwDelay); return TRUE; } -void CMainWindow::HandleTabOrder(int direction) +void +CMainWindow::HandleTabOrder(int direction) { ATL::CSimpleArray TabOrderHwndList; m_TreeView->AppendTabOrderWindow(direction, TabOrderHwndList); m_ApplicationView->AppendTabOrderWindow(direction, TabOrderHwndList); - if (TabOrderHwndList.GetSize() == 0) { // in case the list is empty @@ -860,7 +774,8 @@ void CMainWindow::HandleTabOrder(int direction) else { FocusIndex += direction; - FocusIndex += TabOrderHwndList.GetSize(); // FocusIndex might be negative. we don't want to mod a negative number + FocusIndex += + TabOrderHwndList.GetSize(); // FocusIndex might be negative. we don't want to mod a negative number FocusIndex %= TabOrderHwndList.GetSize(); } @@ -869,14 +784,13 @@ void CMainWindow::HandleTabOrder(int direction) } // **** CMainWindow **** - - -VOID MainWindowLoop(INT nShowCmd) +VOID +MainWindowLoop(CApplicationDB *db, INT nShowCmd) { HACCEL KeyBrd; MSG Msg; - CMainWindow* wnd = new CMainWindow(); + CMainWindow *wnd = new CMainWindow(db); if (!wnd) return; @@ -896,8 +810,7 @@ VOID MainWindowLoop(INT nShowCmd) { if (!TranslateAcceleratorW(hMainWnd, KeyBrd, &Msg)) { - if (Msg.message == WM_CHAR && - Msg.wParam == VK_TAB) + if (Msg.message == WM_CHAR && Msg.wParam == VK_TAB) { // Move backwards if shift is held down int direction = (GetKeyState(VK_SHIFT) & 0x8000) ? -1 : 1; diff --git a/base/applications/rapps/include/applicationdb.h b/base/applications/rapps/include/applicationdb.h new file mode 100644 index 0000000000000..c63b1698c05a7 --- /dev/null +++ b/base/applications/rapps/include/applicationdb.h @@ -0,0 +1,35 @@ +#pragma once + +#include +#include + +#include "applicationinfo.h" + +class CApplicationDB +{ + private: + CPathW m_BasePath; + CAtlList m_Available; + CAtlList m_Installed; + + BOOL + EnumerateFiles(); + + public: + CApplicationDB(const CStringW &path); + + VOID + GetApps(CAtlList &List, AppsCategories Type) const; + CApplicationInfo * + FindByPackageName(const CStringW &name); + + VOID + UpdateAvailable(); + VOID + UpdateInstalled(); + VOID + RemoveCached(); + + BOOL + RemoveInstalledAppFromRegistry(const CApplicationInfo *Info); +}; diff --git a/base/applications/rapps/include/applicationinfo.h b/base/applications/rapps/include/applicationinfo.h new file mode 100644 index 0000000000000..fb152d26bba5b --- /dev/null +++ b/base/applications/rapps/include/applicationinfo.h @@ -0,0 +1,186 @@ +#pragma once + +#include +#include +#include + + +enum LicenseType +{ + LICENSE_NONE, + LICENSE_OPENSOURCE, + LICENSE_FREEWARE, + LICENSE_TRIAL, + LICENSE_MIN = LICENSE_NONE, + LICENSE_MAX = LICENSE_TRIAL +}; + +inline BOOL +IsLicenseType(INT x) +{ + return (x >= LICENSE_MIN && x <= LICENSE_MAX); +} + +enum AppsCategories +{ + ENUM_ALL_AVAILABLE, + ENUM_CAT_AUDIO, + ENUM_CAT_VIDEO, + ENUM_CAT_GRAPHICS, + ENUM_CAT_GAMES, + ENUM_CAT_INTERNET, + ENUM_CAT_OFFICE, + ENUM_CAT_DEVEL, + ENUM_CAT_EDU, + ENUM_CAT_ENGINEER, + ENUM_CAT_FINANCE, + ENUM_CAT_SCIENCE, + ENUM_CAT_TOOLS, + ENUM_CAT_DRIVERS, + ENUM_CAT_LIBS, + ENUM_CAT_THEMES, + ENUM_CAT_OTHER, + ENUM_CAT_SELECTED, + ENUM_ALL_INSTALLED = 30, + ENUM_INSTALLED_APPLICATIONS, + ENUM_UPDATES, + ENUM_INVALID, + ENUM_INSTALLED_MIN = ENUM_ALL_INSTALLED, + ENUM_INSTALLED_MAX = ENUM_UPDATES, + ENUM_AVAILABLE_MIN = ENUM_ALL_AVAILABLE, + ENUM_AVAILABLE_MAX = ENUM_CAT_SELECTED, +}; + +inline BOOL +IsAvailableEnum(INT x) +{ + return (x >= ENUM_AVAILABLE_MIN && x <= ENUM_AVAILABLE_MAX); +} + +inline BOOL +IsInstalledEnum(INT x) +{ + return (x >= ENUM_INSTALLED_MIN && x <= ENUM_INSTALLED_MAX); +} + +class CAppRichEdit; + +class CApplicationInfo +{ + public: + CApplicationInfo(const CStringW &Identifier, AppsCategories Category); + virtual ~CApplicationInfo(); + + const CStringW szIdentifier; // PkgName or KeyName + const AppsCategories iCategory; + + CStringW szDisplayIcon; + CStringW szDisplayName; + CStringW szDisplayVersion; + CStringW szComments; + + virtual BOOL + Valid() const = 0; + virtual BOOL + CanModify() = 0; + virtual BOOL + RetrieveIcon(CStringW &Path) const = 0; + virtual BOOL + RetrieveScreenshot(CStringW &Path) = 0; + virtual VOID + ShowAppInfo(CAppRichEdit *RichEdit) = 0; + virtual VOID + GetDownloadInfo(CStringW &Url, CStringW &Sha1, ULONG &SizeInBytes) const = 0; + virtual VOID + GetDisplayInfo(CStringW &License, CStringW &Size, CStringW &UrlSite, CStringW &UrlDownload) = 0; + virtual BOOL + UninstallApplication(BOOL bModify) = 0; +}; + +class CAvailableApplicationInfo : public CApplicationInfo +{ + class CConfigParser *m_Parser; + CSimpleArray m_szScrnshotLocation; + bool m_ScrnshotRetrieved; + CStringW m_szUrlDownload; + CStringW m_szSize; + CStringW m_szUrlSite; + CSimpleArray m_LanguageLCIDs; + bool m_LanguagesLoaded; + + VOID + InsertVersionInfo(CAppRichEdit *RichEdit); + VOID + InsertLanguageInfo(CAppRichEdit *RichEdit); + VOID + RetrieveLanguages(); + CStringW + LicenseString(); + + public: + CAvailableApplicationInfo( + CConfigParser *Parser, + const CStringW &PkgName, + AppsCategories Category, + const CPathW &BasePath); + ~CAvailableApplicationInfo(); + + virtual BOOL + Valid() const override; + virtual BOOL + CanModify() override; + virtual BOOL + RetrieveIcon(CStringW &Path) const override; + virtual BOOL + RetrieveScreenshot(CStringW &Path) override; + virtual VOID + ShowAppInfo(CAppRichEdit *RichEdit) override; + virtual VOID + GetDownloadInfo(CStringW &Url, CStringW &Sha1, ULONG &SizeInBytes) const override; + virtual VOID + GetDisplayInfo(CStringW &License, CStringW &Size, CStringW &UrlSite, CStringW &UrlDownload) override; + virtual BOOL + UninstallApplication(BOOL bModify) override; +}; + +class CInstalledApplicationInfo : public CApplicationInfo +{ + CRegKey m_hKey; + CStringW m_szInstallDate; + CStringW m_szUninstallString; + CStringW m_szModifyString; + + BOOL + GetApplicationRegString(LPCWSTR lpKeyName, CStringW &String); + BOOL + GetApplicationRegDword(LPCWSTR lpKeyName, DWORD *lpValue); + VOID + AddApplicationRegString(CAppRichEdit *RichEdit, UINT StringID, const CStringW &String, DWORD TextFlags); + + VOID + RetrieveInstallDate(); + VOID + RetrieveUninstallStrings(); + + public: + const int iKeyIndex; + CInstalledApplicationInfo(HKEY Key, const CStringW &KeyName, AppsCategories Category, int KeyIndex); + ~CInstalledApplicationInfo(); + + virtual BOOL + Valid() const override; + virtual BOOL + CanModify() override; + virtual BOOL + RetrieveIcon(CStringW &Path) const override; + virtual BOOL + RetrieveScreenshot(CStringW &Path) override; + virtual VOID + ShowAppInfo(CAppRichEdit *RichEdit) override; + virtual VOID + GetDownloadInfo(CStringW &Url, CStringW &Sha1, ULONG &SizeInBytes) const override; + virtual VOID + GetDisplayInfo(CStringW &License, CStringW &Size, CStringW &UrlSite, CStringW &UrlDownload) override; + virtual BOOL + UninstallApplication(BOOL bModify) override; +}; diff --git a/base/applications/rapps/include/appview.h b/base/applications/rapps/include/appview.h index 3ac3eb21a6077..fcf18a9d905f1 100644 --- a/base/applications/rapps/include/appview.h +++ b/base/applications/rapps/include/appview.h @@ -18,7 +18,6 @@ #include #include -using namespace Gdiplus; #define LISTVIEW_ICON_SIZE 32 @@ -38,30 +37,30 @@ using namespace Gdiplus; #define TOOLBAR_PADDING 6 // user-defined window message -#define WM_RAPPS_DOWNLOAD_COMPLETE (WM_USER + 1) // notify download complete. wParam is error code, and lParam is a pointer to ScrnshotDownloadParam -#define WM_RAPPS_RESIZE_CHILDREN (WM_USER + 2) // ask parent window to resize children. +#define WM_RAPPS_DOWNLOAD_COMPLETE \ + (WM_USER + 1) // notify download complete. wParam is error code, and lParam is a pointer to ScrnshotDownloadParam +#define WM_RAPPS_RESIZE_CHILDREN (WM_USER + 2) // ask parent window to resize children. enum SCRNSHOT_STATUS { - SCRNSHOT_PREV_EMPTY, // show nothing - SCRNSHOT_PREV_LOADING, // image is loading (most likely downloading) - SCRNSHOT_PREV_IMAGE, // display image from a file - SCRNSHOT_PREV_FAILED // image can not be shown (download failure or wrong image) + SCRNSHOT_PREV_EMPTY, // show nothing + SCRNSHOT_PREV_LOADING, // image is loading (most likely downloading) + SCRNSHOT_PREV_IMAGE, // display image from a file + SCRNSHOT_PREV_FAILED // image can not be shown (download failure or wrong image) }; #define TIMER_LOADING_ANIMATION 1 // Timer ID #define LOADING_ANIMATION_PERIOD 3 // Animation cycling period (in seconds) -#define LOADING_ANIMATION_FPS 18 // Animation Frame Per Second - +#define LOADING_ANIMATION_FPS 18 // Animation Frame Per Second #define PI 3.1415927 // retrieve the value using a mask -#define STATEIMAGETOINDEX(x) (((x) & LVIS_STATEIMAGEMASK) >> 12) +#define STATEIMAGETOINDEX(x) (((x)&LVIS_STATEIMAGEMASK) >> 12) -// for listview with extend style LVS_EX_CHECKBOXES, State image 1 is the unchecked box, and state image 2 is the checked box. -// see this: https://docs.microsoft.com/en-us/windows/win32/controls/extended-list-view-styles +// for listview with extend style LVS_EX_CHECKBOXES, State image 1 is the unchecked box, and state image 2 is the +// checked box. see this: https://docs.microsoft.com/en-us/windows/win32/controls/extended-list-view-styles #define STATEIMAGE_UNCHECKED 1 #define STATEIMAGE_CHECKED 2 @@ -69,7 +68,6 @@ class CMainWindow; enum APPLICATION_VIEW_TYPE { - AppViewTypeEmpty, AppViewTypeAvailableApps, AppViewTypeInstalledApps }; @@ -79,129 +77,116 @@ typedef struct __ScrnshotDownloadParam LONGLONG ID; HANDLE hFile; HWND hwndNotify; - ATL::CStringW DownloadFileName; + CStringW DownloadFileName; } ScrnshotDownloadParam; - -class CAppRichEdit : - public CUiWindow +class CAppRichEdit : public CUiWindow { -private: - VOID LoadAndInsertText(UINT uStringID, - const ATL::CStringW &szText, - DWORD StringFlags, - DWORD TextFlags); - - VOID LoadAndInsertText(UINT uStringID, - DWORD StringFlags); - - VOID InsertVersionInfo(CAvailableApplicationInfo *Info); - - VOID InsertLicenseInfo(CAvailableApplicationInfo *Info); - - VOID InsertLanguageInfo(CAvailableApplicationInfo *Info); - -public: - BOOL ShowAvailableAppInfo(CAvailableApplicationInfo *Info); - - inline VOID InsertTextWithString(UINT StringID, DWORD StringFlags, const ATL::CStringW &Text, DWORD TextFlags); - - BOOL ShowInstalledAppInfo(CInstalledApplicationInfo *Info); - - VOID SetWelcomeText(); + public: + VOID + LoadAndInsertText(UINT uStringID, const CStringW &szText, DWORD TextFlags); + VOID + LoadAndInsertText(UINT uStringID, DWORD StringFlags); + VOID + InsertTextWithString(UINT StringID, const CStringW &Text, DWORD TextFlags); + VOID + SetWelcomeText(); }; -int ScrnshotDownloadCallback( - pASYNCINET AsyncInet, - ASYNC_EVENT Event, - WPARAM wParam, - LPARAM lParam, - VOID *Extension -); +int +ScrnshotDownloadCallback(pASYNCINET AsyncInet, ASYNC_EVENT Event, WPARAM wParam, LPARAM lParam, VOID *Extension); -class CAppScrnshotPreview : - public CWindowImpl +class CAppScrnshotPreview : public CWindowImpl { -private: - + private: + CStringW m_BasePath; SCRNSHOT_STATUS ScrnshotPrevStauts = SCRNSHOT_PREV_EMPTY; - Image *pImage = NULL; + Gdiplus::Image *pImage = NULL; HICON hBrokenImgIcon = NULL; BOOL bLoadingTimerOn = FALSE; int LoadingAnimationFrame = 0; int BrokenImgSize = BROKENIMG_ICON_SIZE; pASYNCINET AsyncInet = NULL; - LONGLONG ContentID = 0; // used to determine whether image has been switched when download complete. Increase by 1 each time the content of this window changed - ATL::CStringW TempImagePath; // currently displayed temp file - - BOOL ProcessWindowMessage(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT &theResult, DWORD dwMapId); - - VOID DisplayLoading(); - - VOID DisplayFailed(); - - BOOL DisplayFile(LPCWSTR lpszFileName); - - VOID SetStatus(SCRNSHOT_STATUS Status); - - VOID PaintOnDC(HDC hdc, int width, int height, BOOL bDrawBkgnd); - - float GetLoadingDotWidth(int width, int height); - - float GetFrameDotShift(int Frame, int width, int height); - -public: - static ATL::CWndClassInfo &GetWndClassInfo(); - - HWND Create(HWND hParent); - - VOID PreviousDisplayCleanup(); - - VOID DisplayEmpty(); - - BOOL DisplayImage(LPCWSTR lpszLocation); + LONGLONG ContentID = 0; // used to determine whether image has been switched when download complete. Increase by 1 + // each time the content of this window changed + CStringW TempImagePath; // currently displayed temp file + + BOOL + ProcessWindowMessage(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT &theResult, DWORD dwMapId); + + VOID + DisplayLoading(); + VOID + DisplayFailed(); + BOOL + DisplayFile(LPCWSTR lpszFileName); + VOID + SetStatus(SCRNSHOT_STATUS Status); + + VOID + PaintOnDC(HDC hdc, int width, int height, BOOL bDrawBkgnd); + float + GetLoadingDotWidth(int width, int height); + float + GetFrameDotShift(int Frame, int width, int height); + + public: + static ATL::CWndClassInfo & + GetWndClassInfo(); + + HWND + Create(HWND hParent); + VOID + PreviousDisplayCleanup(); + VOID + DisplayEmpty(); + BOOL + DisplayImage(LPCWSTR lpszLocation); // calculate requested window width by given height - int GetRequestedWidth(int Height); + int + GetRequestedWidth(int Height); + CAppScrnshotPreview(const CStringW &BasePath); ~CAppScrnshotPreview(); }; -class CAppInfoDisplay : - public CUiWindow> +class CAppInfoDisplay : public CUiWindow> { LPWSTR pLink = NULL; -private: - BOOL ProcessWindowMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT &theResult, DWORD dwMapId); - - VOID ResizeChildren(); + private: + BOOL + ProcessWindowMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT &theResult, DWORD dwMapId); + VOID + OnLink(ENLINK *Link); - VOID ResizeChildren(int Width, int Height); - - VOID OnLink(ENLINK *Link); - -public: + VOID + ResizeChildren(); + VOID + ResizeChildren(int Width, int Height); + public: CAppRichEdit *RichEdit = NULL; CAppScrnshotPreview *ScrnshotPrev = NULL; - static ATL::CWndClassInfo &GetWndClassInfo(); - - HWND Create(HWND hwndParent); - - BOOL ShowAvailableAppInfo(CAvailableApplicationInfo *Info); - BOOL ShowInstalledAppInfo(CInstalledApplicationInfo *Info); + static ATL::CWndClassInfo & + GetWndClassInfo(); - VOID SetWelcomeText(); + HWND + Create(HWND hwndParent); - VOID OnCommand(WPARAM wParam, LPARAM lParam); + VOID + ShowAppInfo(CApplicationInfo *Info); + VOID + SetWelcomeText(); + VOID + OnCommand(WPARAM wParam, LPARAM lParam); ~CAppInfoDisplay(); }; -class CAppsListView : - public CUiWindow> +class CAppsListView : public CUiWindow> { struct SortContext { @@ -218,65 +203,74 @@ class CAppsListView : INT nLastHeaderID = -1; - APPLICATION_VIEW_TYPE ApplicationViewType = AppViewTypeEmpty; + APPLICATION_VIEW_TYPE ApplicationViewType = AppViewTypeAvailableApps; HIMAGELIST m_hImageListView = NULL; CStringW m_Watermark; BEGIN_MSG_MAP(CAppsListView) - MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground) + MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBackground) END_MSG_MAP() + LRESULT + OnEraseBackground(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); - LRESULT OnEraseBackground(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); - -public: + public: CAppsListView(); ~CAppsListView(); - VOID SetWatermark(const CStringW& Text); - VOID SetCheckboxesVisible(BOOL bIsVisible); - - VOID ColumnClick(LPNMLISTVIEW pnmv); - - BOOL AddColumn(INT Index, ATL::CStringW &Text, INT Width, INT Format); + VOID + SetWatermark(const CStringW &Text); + VOID + SetCheckboxesVisible(BOOL bIsVisible); - int AddColumn(INT Index, LPWSTR lpText, INT Width, INT Format); + VOID + ColumnClick(LPNMLISTVIEW pnmv); - void DeleteColumn(INT Index); + BOOL + AddColumn(INT Index, CStringW &Text, INT Width, INT Format); + void + DeleteColumn(INT Index); - INT AddItem(INT ItemIndex, INT IconIndex, LPCWSTR lpText, LPARAM lParam); + INT + AddItem(INT ItemIndex, INT IconIndex, LPCWSTR lpText, LPARAM lParam); - HIMAGELIST GetImageList(int iImageList); + HIMAGELIST + GetImageList(int iImageList); - static INT CALLBACK s_CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort); + static INT CALLBACK + s_CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort); - INT CompareFunc(LPARAM lParam1, LPARAM lParam2, INT iSubItem); + INT + CompareFunc(LPARAM lParam1, LPARAM lParam2, INT iSubItem); - HWND Create(HWND hwndParent); + HWND + Create(HWND hwndParent); - BOOL GetCheckState(INT item); + BOOL + GetCheckState(INT item); + VOID + SetCheckState(INT item, BOOL fCheck); + VOID + CheckAll(); - VOID SetCheckState(INT item, BOOL fCheck); + PVOID + GetFocusedItemData(); - VOID CheckAll(); + BOOL + SetDisplayAppType(APPLICATION_VIEW_TYPE AppType); + BOOL + SetViewMode(DWORD ViewMode); - PVOID GetFocusedItemData(); - - BOOL SetDisplayAppType(APPLICATION_VIEW_TYPE AppType); - - BOOL SetViewMode(DWORD ViewMode); - - BOOL AddInstalledApplication(CInstalledApplicationInfo *InstAppInfo, LPVOID CallbackParam); - - BOOL AddAvailableApplication(CAvailableApplicationInfo *AvlbAppInfo, BOOL InitCheckState, LPVOID CallbackParam); + BOOL + AddApplication(CApplicationInfo *AppInfo, BOOL InitialCheckState); // this function is called when parent window receiving an notification about checkstate changing - VOID ItemCheckStateNotify(int iItem, BOOL bCheck); + VOID + ItemCheckStateNotify(int iItem, BOOL bCheck); }; -class CMainToolbar : - public CUiWindow< CToolbar<> > +class CMainToolbar : public CUiWindow> { const INT m_iToolbarHeight; DWORD m_dButtonsWidthMax; @@ -288,66 +282,73 @@ class CMainToolbar : WCHAR szRefreshBtn[MAX_STR_LEN]; WCHAR szUpdateDbBtn[MAX_STR_LEN]; - VOID AddImageToImageList(HIMAGELIST hImageList, UINT ImageIndex); - - HIMAGELIST InitImageList(); + VOID + AddImageToImageList(HIMAGELIST hImageList, UINT ImageIndex); -public: + HIMAGELIST + InitImageList(); + public: CMainToolbar(); - VOID OnGetDispInfo(LPTOOLTIPTEXT lpttt); - - HWND Create(HWND hwndParent); + VOID + OnGetDispInfo(LPTOOLTIPTEXT lpttt); - VOID HideButtonCaption(); + HWND + Create(HWND hwndParent); - VOID ShowButtonCaption(); + VOID + HideButtonCaption(); + VOID + ShowButtonCaption(); - DWORD GetMaxButtonsWidth() const; + DWORD + GetMaxButtonsWidth() const; }; -class CSearchBar : - public CWindow +class CSearchBar : public CWindow { -public: + public: const INT m_Width; const INT m_Height; CSearchBar(); - VOID SetText(LPCWSTR lpszText); - - HWND Create(HWND hwndParent); + VOID + SetText(LPCWSTR lpszText); + HWND + Create(HWND hwndParent); }; -class CComboBox : - public CWindow +class CComboBox : public CWindow { // ID refers to different types of view enum - { m_AppDisplayTypeDetails, m_AppDisplayTypeList, m_AppDisplayTypeTile }; + { + m_AppDisplayTypeDetails, + m_AppDisplayTypeList, + m_AppDisplayTypeTile + }; // string ID for different. this should correspond with the enum above. - const UINT m_TypeStringID[3] = - { IDS_APP_DISPLAY_DETAILS, IDS_APP_DISPLAY_LIST, IDS_APP_DISPLAY_TILE }; + const UINT m_TypeStringID[3] = {IDS_APP_DISPLAY_DETAILS, IDS_APP_DISPLAY_LIST, IDS_APP_DISPLAY_TILE}; const int m_DefaultSelectType = m_AppDisplayTypeDetails; -public: + public: int m_Width; int m_Height; CComboBox(); - HWND Create(HWND hwndParent); + HWND + Create(HWND hwndParent); }; -class CApplicationView : - public CUiWindow> +class CApplicationView : public CUiWindow> { -private: + private: CUiPanel *m_Panel = NULL; CMainToolbar *m_Toolbar = NULL; CUiWindow *m_ComboBox = NULL; @@ -356,47 +357,66 @@ class CApplicationView : CAppInfoDisplay *m_AppsInfo = NULL; CUiSplitPanel *m_HSplitter = NULL; CMainWindow *m_MainWindow = NULL; - APPLICATION_VIEW_TYPE ApplicationViewType = AppViewTypeEmpty; - - BOOL ProcessWindowMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT &theResult, DWORD dwMapId); - - BOOL CreateToolbar(); - BOOL CreateSearchBar(); - BOOL CreateComboBox(); - BOOL CreateHSplitter(); - BOOL CreateListView(); - BOOL CreateAppInfoDisplay(); - - VOID OnSize(HWND hwnd, WPARAM wParam, LPARAM lParam); - VOID OnCommand(WPARAM wParam, LPARAM lParam); -public: - + APPLICATION_VIEW_TYPE ApplicationViewType = AppViewTypeAvailableApps; + + BOOL + ProcessWindowMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT &theResult, DWORD dwMapId); + + BOOL + CreateToolbar(); + BOOL + CreateSearchBar(); + BOOL + CreateComboBox(); + BOOL + CreateHSplitter(); + BOOL + CreateListView(); + BOOL + CreateAppInfoDisplay(); + + VOID + OnSize(HWND hwnd, WPARAM wParam, LPARAM lParam); + VOID + OnCommand(WPARAM wParam, LPARAM lParam); + + public: CApplicationView(CMainWindow *MainWindow); ~CApplicationView(); - static ATL::CWndClassInfo &GetWndClassInfo(); - - HWND Create(HWND hwndParent); - void SetRedraw(BOOL bRedraw); - void SetFocusOnSearchBar(); - BOOL SetDisplayAppType(APPLICATION_VIEW_TYPE AppType); - - BOOL AddInstalledApplication(CInstalledApplicationInfo *InstAppInfo, LPVOID param); - BOOL AddAvailableApplication(CAvailableApplicationInfo *AvlbAppInfo, BOOL InitCheckState, LPVOID param); - VOID SetWatermark(const CStringW& Text); - - - void CheckAll(); - PVOID GetFocusedItemData(); - int GetItemCount(); - VOID AppendTabOrderWindow(int Direction, ATL::CSimpleArray &TabOrderList); + static ATL::CWndClassInfo & + GetWndClassInfo(); + + HWND + Create(HWND hwndParent); + void + SetRedraw(BOOL bRedraw); + void + SetFocusOnSearchBar(); + BOOL + SetDisplayAppType(APPLICATION_VIEW_TYPE AppType); + + BOOL + AddApplication(CApplicationInfo *InstAppInfo, BOOL InitialCheckState); + VOID + SetWatermark(const CStringW &Text); + + void + CheckAll(); + PVOID + GetFocusedItemData(); + int + GetItemCount(); + VOID + AppendTabOrderWindow(int Direction, ATL::CSimpleArray &TabOrderList); // this function is called when a item of listview get focus. // CallbackParam is the param passed to listview when adding the item (the one getting focus now). - BOOL ItemGetFocus(LPVOID CallbackParam); + VOID + ItemGetFocus(LPVOID CallbackParam); // this function is called when a item of listview is checked/unchecked // CallbackParam is the param passed to listview when adding the item (the one getting focus now). - BOOL ItemCheckStateChanged(BOOL bChecked, LPVOID CallbackParam); - + VOID + ItemCheckStateChanged(BOOL bChecked, LPVOID CallbackParam); }; diff --git a/base/applications/rapps/include/available.h b/base/applications/rapps/include/available.h deleted file mode 100644 index fa2a13a144f25..0000000000000 --- a/base/applications/rapps/include/available.h +++ /dev/null @@ -1,132 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -#include "misc.h" -#include "configparser.h" - - -#define MAX_SCRNSHOT_NUM 16 - -enum LicenseType -{ - LICENSE_NONE, - LICENSE_OPENSOURCE, - LICENSE_FREEWARE, - LICENSE_TRIAL, - LICENSE_MIN = LICENSE_NONE, - LICENSE_MAX = LICENSE_TRIAL -}; - -inline BOOL IsLicenseType(INT x) -{ - return (x >= LICENSE_MIN && x <= LICENSE_MAX); -} - -struct AvailableStrings -{ - ATL::CStringW szPath; - ATL::CStringW szCabPath; - ATL::CStringW szAppsPath; - ATL::CStringW szSearchPath; - ATL::CStringW szCabName; - ATL::CStringW szCabDir; - - AvailableStrings(); -}; - -class CAvailableApplicationInfo -{ -public: - INT m_Category; - //BOOL m_IsSelected; - LicenseType m_LicenseType; - ATL::CStringW m_szName; // software's display name. - ATL::CStringW m_szRegName; - ATL::CStringW m_szVersion; - ATL::CStringW m_szLicense; - ATL::CStringW m_szDesc; - ATL::CStringW m_szSize; - ATL::CStringW m_szUrlSite; - ATL::CStringW m_szUrlDownload; - ATL::CSimpleArray m_LanguageLCIDs; - ATL::CSimpleArray m_szScrnshotLocation; - ATL::CStringW m_szIconLocation; - ATL::CStringW m_szPkgName; // software's package name. - - ULONG m_SizeBytes; - - // Caching mechanism related entries - ATL::CStringW m_sFileName; - FILETIME m_ftCacheStamp; - - // Optional integrity checks (SHA-1 digests are 160 bit = 40 characters in hex string form) - ATL::CStringW m_szSHA1; - ATL::CStringW m_szInstalledVersion; - - // Create an object from file - CAvailableApplicationInfo(const ATL::CStringW& sFileNameParam, AvailableStrings& m_Strings); - - // Load all info from the file - VOID RefreshAppInfo(AvailableStrings& m_Strings); - BOOL HasLanguageInfo() const; - BOOL HasNativeLanguage() const; - BOOL HasEnglishLanguage() const; - BOOL IsInstalled() const; - BOOL HasInstalledVersion() const; - BOOL HasUpdate() const; - BOOL RetrieveScrnshot(UINT Index, ATL::CStringW& ScrnshotLocation) const; - BOOL RetrieveIcon(ATL::CStringW& IconLocation) const; - // Set a timestamp - VOID SetLastWriteTime(FILETIME* ftTime); - -private: - BOOL m_IsInstalled; - BOOL m_HasLanguageInfo; - BOOL m_HasInstalledVersion; - CConfigParser* m_Parser; - - inline BOOL GetString(LPCWSTR lpKeyName, ATL::CStringW& ReturnedString); - - // Lazily load general info from the file - VOID RetrieveGeneralInfo(AvailableStrings& m_Strings); - VOID RetrieveInstalledStatus(); - VOID RetrieveInstalledVersion(); - VOID RetrieveLanguages(); - VOID RetrieveLicenseType(); - VOID RetrieveSize(); - inline BOOL FindInLanguages(LCID what) const; -}; - -typedef BOOL(CALLBACK *AVAILENUMPROC)(CAvailableApplicationInfo *Info, BOOL bInitialCheckState, PVOID param); - -class CAvailableApps -{ - ATL::CAtlList m_InfoList; - ATL::CAtlList< CAvailableApplicationInfo*> m_SelectedList; - -public: - static AvailableStrings m_Strings; - - CAvailableApps(); - - static BOOL UpdateAppsDB(); - static BOOL ForceUpdateAppsDB(); - static VOID DeleteCurrentAppsDB(); - - VOID FreeCachedEntries(); - BOOL Enum(INT EnumType, AVAILENUMPROC lpEnumProc, PVOID param); - - BOOL AddSelected(CAvailableApplicationInfo *AvlbInfo); - BOOL RemoveSelected(CAvailableApplicationInfo *AvlbInfo); - - VOID RemoveAllSelected(); - int GetSelectedCount(); - - CAvailableApplicationInfo* FindAppByPkgName(const ATL::CStringW& szPkgName) const; - ATL::CSimpleArray FindAppsByPkgNameList(const ATL::CSimpleArray &arrAppsNames) const; - //ATL::CSimpleArray GetSelected() const; -}; diff --git a/base/applications/rapps/include/configparser.h b/base/applications/rapps/include/configparser.h index 7ccfa115bd464..10868d5e49f6e 100644 --- a/base/applications/rapps/include/configparser.h +++ b/base/applications/rapps/include/configparser.h @@ -5,16 +5,19 @@ class CConfigParser { - const ATL::CStringW szConfigPath; + const CStringW szConfigPath; CSimpleMap m_Keys; - void CacheINI(); - void ReadSection(ATL::CStringW& Buffer, const ATL::CStringW& Section, BOOL isArch); + void + CacheINI(); + void + ReadSection(CStringW &Buffer, const CStringW &Section, BOOL isArch); -public: - CConfigParser(const ATL::CStringW& FileName); + public: + CConfigParser(const CStringW &FileName); - BOOL GetString(const ATL::CStringW& KeyName, ATL::CStringW& ResultString); - BOOL GetInt(const ATL::CStringW& KeyName, INT& iResult); + BOOL + GetString(const CStringW &KeyName, CStringW &ResultString); + BOOL + GetInt(const CStringW &KeyName, INT &iResult); }; - diff --git a/base/applications/rapps/include/crichedit.h b/base/applications/rapps/include/crichedit.h index 6c6a2222cefa0..01d751c1834aa 100644 --- a/base/applications/rapps/include/crichedit.h +++ b/base/applications/rapps/include/crichedit.h @@ -1,12 +1,12 @@ #pragma once #include -class CRichEdit : - public CWindow +class CRichEdit : public CWindow { HMODULE m_LoadedLibrary; - VOID GenericInsertText(LPCWSTR lpszText, SIZE_T InsertedTextLen, DWORD dwEffects) + VOID + GenericInsertText(LPCWSTR lpszText, SIZE_T InsertedTextLen, DWORD dwEffects) { SETTEXTEX SetText; SIZE_T Len = GetTextLen(); @@ -17,7 +17,7 @@ class CRichEdit : SetText.flags = ST_SELECTION; SetText.codepage = 1200; - SendMessageW(EM_SETTEXTEX, (WPARAM) &SetText, (LPARAM) lpszText); + SendMessageW(EM_SETTEXTEX, (WPARAM)&SetText, (LPARAM)lpszText); if ((dwEffects == CFM_LINK) && !PathIsURLW(lpszText)) { @@ -31,10 +31,13 @@ class CRichEdit : } } -public: - CRichEdit() : CWindow(), m_LoadedLibrary(NULL) {} + public: + CRichEdit() : CWindow(), m_LoadedLibrary(NULL) + { + } - VOID SetRangeFormatting(SIZE_T Start, SIZE_T End, DWORD dwEffects) + VOID + SetRangeFormatting(SIZE_T Start, SIZE_T End, DWORD dwEffects) { CHARFORMAT2W CharFormat; @@ -46,71 +49,70 @@ class CRichEdit : CharFormat.dwMask = dwEffects; CharFormat.dwEffects = dwEffects; - SendMessageW(EM_SETCHARFORMAT, SCF_WORD | SCF_SELECTION, (LPARAM) &CharFormat); + SendMessageW(EM_SETCHARFORMAT, SCF_WORD | SCF_SELECTION, (LPARAM)&CharFormat); SendMessageW(EM_SETSEL, End, End + 1); } - LONG GetTextLen() + LONG + GetTextLen() { GETTEXTLENGTHEX TxtLenStruct; TxtLenStruct.flags = GTL_NUMCHARS; TxtLenStruct.codepage = 1200; - return (LONG) SendMessageW(EM_GETTEXTLENGTHEX, (WPARAM) &TxtLenStruct, 0); + return (LONG)SendMessageW(EM_GETTEXTLENGTHEX, (WPARAM)&TxtLenStruct, 0); } /* - * Insert text (without cleaning old text) - * Supported effects: - * - CFM_BOLD - * - CFM_ITALIC - * - CFM_UNDERLINE - * - CFM_LINK - */ - VOID InsertText(LPCWSTR lpszText, DWORD dwEffects) + * Insert text (without cleaning old text) + * Supported effects: + * - CFM_BOLD + * - CFM_ITALIC + * - CFM_UNDERLINE + * - CFM_LINK + */ + VOID + InsertText(LPCWSTR lpszText, DWORD dwEffects) { GenericInsertText(lpszText, wcslen(lpszText), dwEffects); } - VOID InsertText(const ATL::CStringW& szText, DWORD dwEffects) + VOID + InsertText(const CStringW &szText, DWORD dwEffects) { GenericInsertText(szText.GetString(), szText.GetLength(), dwEffects); } /* - * Clear old text and add new - */ - VOID SetText(LPCWSTR lpszText, DWORD dwEffects) + * Clear old text and add new + */ + VOID + SetText(LPCWSTR lpszText, DWORD dwEffects) { SetWindowTextW(L""); InsertText(lpszText, dwEffects); } - VOID SetText(const ATL::CStringW& szText, DWORD dwEffects) + VOID + SetText(const CStringW &szText, DWORD dwEffects) { SetText(szText.GetString(), dwEffects); } - HWND Create(HWND hwndParent) + HWND + Create(HWND hwndParent) { m_LoadedLibrary = LoadLibraryW(L"riched20.dll"); - m_hWnd = CreateWindowExW(0, - L"RichEdit20W", - NULL, - WS_CHILD | WS_VISIBLE | ES_MULTILINE | - ES_LEFT | ES_READONLY, - 205, 28, 465, 100, - hwndParent, - NULL, - _AtlBaseModule.GetModuleInstance(), - NULL); + m_hWnd = CreateWindowExW( + 0, L"RichEdit20W", NULL, WS_CHILD | WS_VISIBLE | ES_MULTILINE | ES_LEFT | ES_READONLY, 205, 28, 465, 100, + hwndParent, NULL, _AtlBaseModule.GetModuleInstance(), NULL); if (m_hWnd) { SendMessageW(EM_SETBKGNDCOLOR, 0, GetSysColor(COLOR_BTNFACE)); - SendMessageW(WM_SETFONT, (WPARAM) GetStockObject(DEFAULT_GUI_FONT), 0); + SendMessageW(WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 0); SendMessageW(EM_SETEVENTMASK, 0, ENM_LINK | ENM_MOUSEEVENTS); SendMessageW(EM_SHOWSCROLLBAR, SB_VERT, TRUE); } @@ -118,7 +120,8 @@ class CRichEdit : return m_hWnd; } - virtual VOID OnLink(ENLINK *Link) + virtual VOID + OnLink(ENLINK *Link) { } @@ -129,5 +132,4 @@ class CRichEdit : FreeLibrary(m_LoadedLibrary); } } - }; diff --git a/base/applications/rapps/include/defines.h b/base/applications/rapps/include/defines.h index a8177811a1dc8..f9d1d6d65ce51 100644 --- a/base/applications/rapps/include/defines.h +++ b/base/applications/rapps/include/defines.h @@ -31,43 +31,4 @@ #define APPLICATION_DATABASE_URL L"https://rapps.reactos.org/rappmgr2.cab" #define APPLICATION_DATABASE_NAME L"rappmgr2.cab" -#define MAX_STR_LEN 256 - -enum AppsCategories -{ - ENUM_ALL_AVAILABLE, - ENUM_CAT_AUDIO, - ENUM_CAT_VIDEO, - ENUM_CAT_GRAPHICS, - ENUM_CAT_GAMES, - ENUM_CAT_INTERNET, - ENUM_CAT_OFFICE, - ENUM_CAT_DEVEL, - ENUM_CAT_EDU, - ENUM_CAT_ENGINEER, - ENUM_CAT_FINANCE, - ENUM_CAT_SCIENCE, - ENUM_CAT_TOOLS, - ENUM_CAT_DRIVERS, - ENUM_CAT_LIBS, - ENUM_CAT_THEMES, - ENUM_CAT_OTHER, - ENUM_CAT_SELECTED, - ENUM_ALL_INSTALLED, - ENUM_INSTALLED_APPLICATIONS = 31, - ENUM_UPDATES = 32, - ENUM_INSTALLED_MIN = ENUM_ALL_INSTALLED, - ENUM_INSTALLED_MAX = ENUM_UPDATES, - ENUM_AVAILABLE_MIN = ENUM_ALL_AVAILABLE, - ENUM_AVAILABLE_MAX = ENUM_CAT_SELECTED, -}; - -inline BOOL IsAvailableEnum(INT x) -{ - return (x >= ENUM_AVAILABLE_MIN && x <= ENUM_AVAILABLE_MAX); -} - -inline BOOL IsInstalledEnum(INT x) -{ - return (x >= ENUM_INSTALLED_MIN && x <= ENUM_INSTALLED_MAX); -} +#define MAX_STR_LEN 256 diff --git a/base/applications/rapps/include/dialogs.h b/base/applications/rapps/include/dialogs.h index 79d7d494017e7..0301dbb739330 100644 --- a/base/applications/rapps/include/dialogs.h +++ b/base/applications/rapps/include/dialogs.h @@ -1,17 +1,22 @@ #pragma once -#include "available.h" +#include "applicationinfo.h" #include #include // Settings dialog (settingsdlg.cpp) -VOID CreateSettingsDlg(HWND hwnd); +VOID +CreateSettingsDlg(HWND hwnd); -//Main window -VOID MainWindowLoop(INT nShowCmd); +// Main window +VOID +MainWindowLoop(class CApplicationDB *db, INT nShowCmd); // Download dialogs -VOID DownloadApplicationsDB(LPCWSTR lpUrl, BOOL IsOfficial); -BOOL DownloadApplication(CAvailableApplicationInfo* pAppInfo); -BOOL DownloadListOfApplications(const ATL::CSimpleArray& AppsList, BOOL bIsModal); +VOID +DownloadApplicationsDB(LPCWSTR lpUrl, BOOL IsOfficial); +BOOL +DownloadApplication(CApplicationInfo *pAppInfo); +BOOL +DownloadListOfApplications(const CAtlList &AppsList, BOOL bIsModal); diff --git a/base/applications/rapps/include/gui.h b/base/applications/rapps/include/gui.h index 3a000b1ba6004..48befeaf9f9d7 100644 --- a/base/applications/rapps/include/gui.h +++ b/base/applications/rapps/include/gui.h @@ -22,29 +22,29 @@ #define SEARCH_TIMER_ID 'SR' #define TREEVIEW_ICON_SIZE 24 - - -class CSideTreeView : - public CUiWindow +class CSideTreeView : public CUiWindow { HIMAGELIST hImageTreeView; -public: + public: CSideTreeView(); - HTREEITEM AddItem(HTREEITEM hParent, ATL::CStringW &Text, INT Image, INT SelectedImage, LPARAM lParam); + HTREEITEM + AddItem(HTREEITEM hParent, CStringW &Text, INT Image, INT SelectedImage, LPARAM lParam); - HTREEITEM AddCategory(HTREEITEM hRootItem, UINT TextIndex, UINT IconIndex); + HTREEITEM + AddCategory(HTREEITEM hRootItem, UINT TextIndex, UINT IconIndex); - HIMAGELIST SetImageList(); + HIMAGELIST + SetImageList(); - VOID DestroyImageList(); + VOID + DestroyImageList(); ~CSideTreeView(); }; -class CMainWindow : - public CWindowImpl +class CMainWindow : public CWindowImpl { CUiPanel *m_ClientPanel = NULL; CUiSplitPanel *m_VSplitter = NULL; @@ -54,75 +54,81 @@ class CMainWindow : CApplicationView *m_ApplicationView = NULL; - CAvailableApps m_AvailableApps; - CInstalledApps m_InstalledApps; + CApplicationDB *m_Db; + CAtlList m_Selected; BOOL bUpdating = FALSE; - ATL::CStringW szSearchPattern; - INT SelectedEnumType; + CStringW szSearchPattern; + AppsCategories SelectedEnumType; -public: - CMainWindow(); + public: + CMainWindow(CApplicationDB *db); ~CMainWindow(); -private: - - VOID InitCategoriesList(); - - BOOL CreateStatusBar(); - BOOL CreateTreeView(); - BOOL CreateApplicationView(); - BOOL CreateVSplitter(); - BOOL CreateLayout(); - - VOID LayoutCleanup(); - - BOOL InitControls(); - - VOID OnSize(HWND hwnd, WPARAM wParam, LPARAM lParam); - - BOOL RemoveSelectedAppFromRegistry(); - - BOOL UninstallSelectedApp(BOOL bModify); - - BOOL ProcessWindowMessage(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT &theResult, DWORD dwMapId); - BOOL IsSelectedNodeInstalled(); - - VOID ShowAboutDlg(); - - VOID OnCommand(WPARAM wParam, LPARAM lParam); - - BOOL CALLBACK EnumInstalledAppProc(CInstalledApplicationInfo *Info); - BOOL CALLBACK EnumAvailableAppProc(CAvailableApplicationInfo *Info, BOOL bInitialCheckState); - static BOOL CALLBACK s_EnumInstalledAppProc(CInstalledApplicationInfo *Info, PVOID param); - static BOOL CALLBACK s_EnumAvailableAppProc(CAvailableApplicationInfo *Info, BOOL bInitialCheckState, PVOID param); - - static BOOL CALLBACK s_EnumSelectedAppForDownloadProc(CAvailableApplicationInfo *Info, BOOL bInitialCheckState, PVOID param); - - VOID UpdateStatusBarText(); - - VOID UpdateApplicationsList(INT EnumType); - -public: - static ATL::CWndClassInfo &GetWndClassInfo(); - - HWND Create(); + private: + VOID + InitCategoriesList(); + + BOOL + CreateStatusBar(); + BOOL + CreateTreeView(); + BOOL + CreateApplicationView(); + BOOL + CreateVSplitter(); + BOOL + CreateLayout(); + VOID + LayoutCleanup(); + BOOL + InitControls(); + + VOID + OnSize(HWND hwnd, WPARAM wParam, LPARAM lParam); + + BOOL + RemoveSelectedAppFromRegistry(); + BOOL + UninstallSelectedApp(BOOL bModify); + + BOOL + ProcessWindowMessage(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT &theResult, DWORD dwMapId); + VOID + ShowAboutDlg(); + VOID + OnCommand(WPARAM wParam, LPARAM lParam); + VOID + UpdateStatusBarText(); + + VOID + UpdateApplicationsList(AppsCategories EnumType, BOOL bReload = FALSE); + VOID + AddApplicationsToView(CAtlList &List); + + public: + static ATL::CWndClassInfo & + GetWndClassInfo(); + + HWND + Create(); // this function is called when a item of application-view is checked/unchecked // CallbackParam is the param passed to application-view when adding the item (the one getting focus now). - BOOL ItemCheckStateChanged(BOOL bChecked, LPVOID CallbackParam); + VOID + ItemCheckStateChanged(BOOL bChecked, LPVOID CallbackParam); // this function is called when application-view is asked to install an application // if Info is not zero, this app should be installed. otherwise those checked apps should be installed - BOOL InstallApplication(CAvailableApplicationInfo *Info); + BOOL + InstallApplication(CApplicationInfo *Info); // this function is called when search text is changed - BOOL SearchTextChanged(ATL::CStringW &SearchText); + BOOL + SearchTextChanged(CStringW &SearchText); - void HandleTabOrder(int direction); + void + HandleTabOrder(int direction); }; - - -VOID MainWindowLoop(INT nShowCmd); diff --git a/base/applications/rapps/include/installed.h b/base/applications/rapps/include/installed.h deleted file mode 100644 index 68ada9da094c1..0000000000000 --- a/base/applications/rapps/include/installed.h +++ /dev/null @@ -1,63 +0,0 @@ -#pragma once - -#include -#include - -class CInstalledApplicationInfo -{ -private: - BOOL m_IsUserKey; - REGSAM m_WowKey; - HKEY m_hSubKey; - - CStringW m_szKeyName; - -public: - CInstalledApplicationInfo(BOOL bIsUserKey, REGSAM RegWowKey, HKEY hKey, const CStringW& szKeyName); - ~CInstalledApplicationInfo(); - - VOID EnsureDetailsLoaded(); - - BOOL GetApplicationRegString(LPCWSTR lpKeyName, ATL::CStringW& String); - BOOL GetApplicationRegDword(LPCWSTR lpKeyName, DWORD *lpValue); - BOOL RetrieveIcon(ATL::CStringW& IconLocation); - BOOL UninstallApplication(BOOL bModify); - LSTATUS RemoveFromRegistry(); - - // These fields are always loaded - BOOL bIsUpdate; - CStringW szDisplayIcon; - CStringW szDisplayName; - CStringW szDisplayVersion; - CStringW szComments; - - // These details are loaded on demand - CStringW szPublisher; - CStringW szRegOwner; - CStringW szProductID; - CStringW szHelpLink; - CStringW szHelpTelephone; - CStringW szReadme; - CStringW szContact; - CStringW szURLUpdateInfo; - CStringW szURLInfoAbout; - CStringW szInstallDate; - CStringW szInstallLocation; - CStringW szInstallSource; - CStringW szUninstallString; - CStringW szModifyPath; - -}; - -typedef BOOL(CALLBACK *APPENUMPROC)(CInstalledApplicationInfo * Info, PVOID param); - -class CInstalledApps -{ - ATL::CAtlList m_InfoList; - -public: - BOOL Enum(INT EnumType, APPENUMPROC lpEnumProc, PVOID param); - - VOID FreeCachedEntries(); -}; - diff --git a/base/applications/rapps/include/misc.h b/base/applications/rapps/include/misc.h index ff78d0a45bd7d..ff4ff9029e960 100644 --- a/base/applications/rapps/include/misc.h +++ b/base/applications/rapps/include/misc.h @@ -17,32 +17,39 @@ #define CurrentArchitecture L"ppc" #endif -VOID CopyTextToClipboard(LPCWSTR lpszText); -VOID ShowPopupMenuEx(HWND hwnd, HWND hwndOwner, UINT MenuID, UINT DefaultItem); -BOOL StartProcess(const ATL::CStringW &Path, BOOL Wait); -BOOL GetStorageDirectory(ATL::CStringW &lpDirectory); - -VOID InitLogs(); -VOID FreeLogs(); -BOOL WriteLogMessage(WORD wType, DWORD dwEventID, LPCWSTR lpMsg); -BOOL GetInstalledVersion(ATL::CStringW *pszVersion, const ATL::CStringW &szRegName); - -BOOL ExtractFilesFromCab(const ATL::CStringW& szCabName, - const ATL::CStringW& szCabDir, - const ATL::CStringW& szOutputDir); - -BOOL PathAppendNoDirEscapeW(LPWSTR pszPath, LPCWSTR pszMore); - -BOOL IsSystem64Bit(); - -INT GetSystemColorDepth(); - -void UnixTimeToFileTime(DWORD dwUnixTime, LPFILETIME pFileTime); - -BOOL SearchPatternMatch(LPCWSTR szHaystack, LPCWSTR szNeedle); - -template -class CLocalPtr : public CHeapPtr +VOID +CopyTextToClipboard(LPCWSTR lpszText); +VOID +ShowPopupMenuEx(HWND hwnd, HWND hwndOwner, UINT MenuID, UINT DefaultItem); +BOOL +StartProcess(const CStringW &Path, BOOL Wait); +BOOL +GetStorageDirectory(CStringW &lpDirectory); + +VOID +InitLogs(); +VOID +FreeLogs(); +BOOL +WriteLogMessage(WORD wType, DWORD dwEventID, LPCWSTR lpMsg); +BOOL +GetInstalledVersion(CStringW *pszVersion, const CStringW &szRegName); + +BOOL +ExtractFilesFromCab(const CStringW &szCabName, const CStringW &szCabDir, const CStringW &szOutputDir); + +BOOL +IsSystem64Bit(); + +INT +GetSystemColorDepth(); + +void +UnixTimeToFileTime(DWORD dwUnixTime, LPFILETIME pFileTime); + +BOOL +SearchPatternMatch(LPCWSTR szHaystack, LPCWSTR szNeedle); + +template class CLocalPtr : public CHeapPtr { }; - diff --git a/base/applications/rapps/include/rapps.h b/base/applications/rapps/include/rapps.h index ca31dd2e16b18..3a72072cadcbc 100644 --- a/base/applications/rapps/include/rapps.h +++ b/base/applications/rapps/include/rapps.h @@ -2,14 +2,14 @@ #define _RAPPS_H #if DBG && !defined(_DEBUG) - #define _DEBUG // CORE-17505 +#define _DEBUG // CORE-17505 #endif #include "defines.h" #include "dialogs.h" -#include "installed.h" -#include "available.h" +#include "applicationinfo.h" +#include "applicationdb.h" #include "misc.h" #include "configparser.h" diff --git a/base/applications/rapps/include/resource.h b/base/applications/rapps/include/resource.h index bb4249cedc147..e85d2d3a024b0 100644 --- a/base/applications/rapps/include/resource.h +++ b/base/applications/rapps/include/resource.h @@ -84,7 +84,6 @@ #define ID_RESETDB 561 #define ID_CHECK_ALL 562 #define ID_SEARCH 563 -#define ID_TOOLBAR_INSTALL 564 /* Strings */ #define IDS_APPTITLE 100 diff --git a/base/applications/rapps/include/rosui.h b/base/applications/rapps/include/rosui.h index 4402b26f28b69..a68100a6118cf 100644 --- a/base/applications/rapps/include/rosui.h +++ b/base/applications/rapps/include/rosui.h @@ -9,13 +9,12 @@ #include -template -class CPointerArray +template class CPointerArray { -protected: + protected: HDPA m_hDpa; -public: + public: CPointerArray() { m_hDpa = DPA_Create(GrowthRate); @@ -26,26 +25,30 @@ class CPointerArray DPA_DestroyCallback(m_hDpa, s_OnRemoveItem, this); } -private: - static INT CALLBACK s_OnRemoveItem(PVOID ptr, PVOID context) + private: + static INT CALLBACK + s_OnRemoveItem(PVOID ptr, PVOID context) { - CPointerArray * self = (CPointerArray*) context; - return (INT) self->OnRemoveItem(reinterpret_cast(ptr)); + CPointerArray *self = (CPointerArray *)context; + return (INT)self->OnRemoveItem(reinterpret_cast(ptr)); } - static INT CALLBACK s_OnCompareItems(PVOID p1, PVOID p2, LPARAM lParam) + static INT CALLBACK + s_OnCompareItems(PVOID p1, PVOID p2, LPARAM lParam) { - CPointerArray * self = (CPointerArray*) lParam; - return self->OnCompareItems(reinterpret_cast(p1), reinterpret_cast(p2)); + CPointerArray *self = (CPointerArray *)lParam; + return self->OnCompareItems(reinterpret_cast(p1), reinterpret_cast(p2)); } -public: - virtual BOOL OnRemoveItem(T * ptr) + public: + virtual BOOL + OnRemoveItem(T *ptr) { return TRUE; } - virtual INT OnCompareItems(T * p1, T * p2) + virtual INT + OnCompareItems(T *p1, T *p2) { INT_PTR t = (reinterpret_cast(p2) - reinterpret_cast(p1)); if (t > 0) @@ -55,38 +58,45 @@ class CPointerArray return 0; } -public: - INT GetCount() const + public: + INT + GetCount() const { return DPA_GetPtrCount(m_hDpa); } - T* Get(INT i) const + T * + Get(INT i) const { - return (T*) DPA_GetPtr(m_hDpa, i); + return (T *)DPA_GetPtr(m_hDpa, i); } - BOOL Set(INT i, T* ptr) + BOOL + Set(INT i, T *ptr) { return DPA_SetPtr(m_hDpa, i, ptr); } - INT Insert(INT at, T* ptr) + INT + Insert(INT at, T *ptr) { return DPA_InsertPtr(m_hDpa, at, ptr); } - INT Append(T* ptr) + INT + Append(T *ptr) { return DPA_InsertPtr(m_hDpa, DA_LAST, ptr); } - INT IndexOf(T* ptr) const + INT + IndexOf(T *ptr) const { return DPA_GetPtrIndex(m_hDpa, ptr); } - BOOL Remove(T* ptr) + BOOL + Remove(T *ptr) { INT i = IndexOf(ptr); if (i < 0) @@ -94,38 +104,41 @@ class CPointerArray return RemoveAt(i); } - BOOL RemoveAt(INT i) + BOOL + RemoveAt(INT i) { PVOID ptr = DPA_DeletePtr(m_hDpa, i); if (ptr != NULL) { - OnRemoveItem(reinterpret_cast(ptr)); + OnRemoveItem(reinterpret_cast(ptr)); return TRUE; } return FALSE; } - BOOL Clear() + BOOL + Clear() { DPA_EnumCallback(s_OnRemoveItem, this); return DPA_DeleteAllPtrs(m_hDpa); } - BOOL Sort() + BOOL + Sort() { return DPA_Sort(m_hDpa, s_OnCompareItems, (LPARAM)this); } - INT Search(T* item, INT iStart, UINT uFlags) + INT + Search(T *item, INT iStart, UINT uFlags) { return DPA_Search(m_hDpa, item, 0, s_OnCompareItems, (LPARAM)this, 0); } }; -class CUiRect - : public RECT +class CUiRect : public RECT { -public: + public: CUiRect() { left = right = top = bottom = 0; @@ -140,28 +153,25 @@ class CUiRect } }; -class CUiMargin - : public CUiRect +class CUiMargin : public CUiRect { -public: + public: CUiMargin() { } - CUiMargin(INT all) - : CUiRect(all, all, all, all) + CUiMargin(INT all) : CUiRect(all, all, all, all) { } - CUiMargin(INT horz, INT vert) - : CUiRect(horz, vert, horz, vert) + CUiMargin(INT horz, INT vert) : CUiRect(horz, vert, horz, vert) { } }; class CUiMeasure { -public: + public: enum MeasureType { Type_FitContent = 0, @@ -170,11 +180,11 @@ class CUiMeasure Type_FitParent = 3 }; -private: + private: MeasureType m_Type; INT m_Value; -public: + public: CUiMeasure() { m_Type = Type_FitContent; @@ -187,40 +197,45 @@ class CUiMeasure m_Value = value; } - INT ComputeMeasure(INT parent, INT content) + INT + ComputeMeasure(INT parent, INT content) { switch (m_Type) { - case Type_FitContent: - return content; - case Type_Fixed: - return m_Value; - case Type_Percent: - return max(content, parent * m_Value / 100); - case Type_FitParent: - return parent; + case Type_FitContent: + return content; + case Type_Fixed: + return m_Value; + case Type_Percent: + return max(content, parent * m_Value / 100); + case Type_FitParent: + return parent; } return 0; } -public: - static CUiMeasure FitContent() + public: + static CUiMeasure + FitContent() { return CUiMeasure(Type_FitContent, 0); } - static CUiMeasure FitParent() + static CUiMeasure + FitParent() { return CUiMeasure(Type_FitParent, 0); } - static CUiMeasure Fixed(INT pixels) + static CUiMeasure + Fixed(INT pixels) { return CUiMeasure(Type_Fixed, pixels); } - static CUiMeasure Percent(INT percent) + static CUiMeasure + Percent(INT percent) { return CUiMeasure(Type_Percent, percent); } @@ -236,20 +251,21 @@ enum CUiAlignment class CUiBox { -public: + public: CUiMargin m_Margin; CUiAlignment m_HorizontalAlignment; CUiAlignment m_VerticalAlignment; -protected: + protected: CUiBox() { m_HorizontalAlignment = UiAlign_LeftTop; m_VerticalAlignment = UiAlign_LeftTop; } - virtual VOID ComputeRect(RECT parentRect, RECT currentRect, RECT* newRect) + virtual VOID + ComputeRect(RECT parentRect, RECT currentRect, RECT *newRect) { parentRect.left += m_Margin.left; parentRect.right -= m_Margin.right; @@ -269,60 +285,62 @@ class CUiBox switch (m_HorizontalAlignment) { - case UiAlign_LeftTop: - currentRect.right = currentRect.left + szCurrent.cx; - break; - case UiAlign_Middle: - currentRect.left = parentRect.left + (szParent.cx - szCurrent.cx) / 2; - currentRect.right = currentRect.left + szCurrent.cx; - break; - case UiAlign_RightBtm: - currentRect.left = currentRect.right - szCurrent.cx; - break; - default: - break; + case UiAlign_LeftTop: + currentRect.right = currentRect.left + szCurrent.cx; + break; + case UiAlign_Middle: + currentRect.left = parentRect.left + (szParent.cx - szCurrent.cx) / 2; + currentRect.right = currentRect.left + szCurrent.cx; + break; + case UiAlign_RightBtm: + currentRect.left = currentRect.right - szCurrent.cx; + break; + default: + break; } switch (m_VerticalAlignment) { - case UiAlign_LeftTop: - currentRect.bottom = currentRect.top + szCurrent.cy; - break; - case UiAlign_Middle: - currentRect.top = parentRect.top + (szParent.cy - szCurrent.cy) / 2; - currentRect.bottom = currentRect.top + szCurrent.cy; - break; - case UiAlign_RightBtm: - currentRect.top = currentRect.bottom - szCurrent.cy; - break; - default: - break; + case UiAlign_LeftTop: + currentRect.bottom = currentRect.top + szCurrent.cy; + break; + case UiAlign_Middle: + currentRect.top = parentRect.top + (szParent.cy - szCurrent.cy) / 2; + currentRect.bottom = currentRect.top + szCurrent.cy; + break; + case UiAlign_RightBtm: + currentRect.top = currentRect.bottom - szCurrent.cy; + break; + default: + break; } *newRect = currentRect; } - -public: - virtual VOID ComputeMinimalSize(SIZE* size) + public: + virtual VOID + ComputeMinimalSize(SIZE *size) { // Override in subclass size->cx = max(size->cx, 0); size->cy = min(size->cy, 0); }; - virtual VOID ComputeContentBounds(RECT* rect) - { + virtual VOID + ComputeContentBounds(RECT *rect){ // Override in subclass }; - virtual DWORD_PTR CountSizableChildren() + virtual DWORD_PTR + CountSizableChildren() { // Override in subclass return 0; }; - virtual HDWP OnParentSize(RECT parentRect, HDWP hDwp) + virtual HDWP + OnParentSize(RECT parentRect, HDWP hDwp) { // Override in subclass return NULL; @@ -331,19 +349,25 @@ class CUiBox class CUiPrimitive { -protected: - CUiPrimitive * m_Parent; + protected: + CUiPrimitive *m_Parent; -public: - virtual ~CUiPrimitive() {} + public: + virtual ~CUiPrimitive() + { + } - virtual CUiBox * AsBox() { return NULL; } + virtual CUiBox * + AsBox() + { + return NULL; + } }; -class CUiCollection : - public CPointerArray < CUiPrimitive > +class CUiCollection : public CPointerArray { - virtual BOOL OnRemoveItem(CUiPrimitive * ptr) + virtual BOOL + OnRemoveItem(CUiPrimitive *ptr) { delete ptr; return TRUE; @@ -352,19 +376,20 @@ class CUiCollection : class CUiContainer { -protected: + protected: CUiCollection m_Children; -public: - CUiCollection& Children() { return m_Children; } + public: + CUiCollection & + Children() + { + return m_Children; + } }; -class CUiPanel : - public CUiPrimitive, - public CUiBox, - public CUiContainer +class CUiPanel : public CUiPrimitive, public CUiBox, public CUiContainer { -public: + public: CUiMeasure m_Width; CUiMeasure m_Height; @@ -378,13 +403,18 @@ class CUiPanel : { } - virtual CUiBox * AsBox() { return this; } + virtual CUiBox * + AsBox() + { + return this; + } - virtual VOID ComputeMinimalSize(SIZE* size) + virtual VOID + ComputeMinimalSize(SIZE *size) { for (INT i = 0; i < m_Children.GetCount(); i++) { - CUiBox * box = m_Children.Get(i)->AsBox(); + CUiBox *box = m_Children.Get(i)->AsBox(); if (box) { box->ComputeMinimalSize(size); @@ -392,11 +422,12 @@ class CUiPanel : } }; - virtual VOID ComputeContentBounds(RECT* rect) + virtual VOID + ComputeContentBounds(RECT *rect) { for (INT i = 0; i < m_Children.GetCount(); i++) { - CUiBox * box = m_Children.Get(i)->AsBox(); + CUiBox *box = m_Children.Get(i)->AsBox(); if (box) { box->ComputeContentBounds(rect); @@ -404,12 +435,13 @@ class CUiPanel : } }; - virtual DWORD_PTR CountSizableChildren() + virtual DWORD_PTR + CountSizableChildren() { INT count = 0; for (INT i = 0; i < m_Children.GetCount(); i++) { - CUiBox * box = m_Children.Get(i)->AsBox(); + CUiBox *box = m_Children.Get(i)->AsBox(); if (box) { count += box->CountSizableChildren(); @@ -418,7 +450,8 @@ class CUiPanel : return count; } - virtual HDWP OnParentSize(RECT parentRect, HDWP hDwp) + virtual HDWP + OnParentSize(RECT parentRect, HDWP hDwp) { RECT rect = {0}; @@ -435,7 +468,7 @@ class CUiPanel : for (INT i = 0; i < m_Children.GetCount(); i++) { - CUiBox * box = m_Children.Get(i)->AsBox(); + CUiBox *box = m_Children.Get(i)->AsBox(); if (box) { hDwp = box->OnParentSize(rect, hDwp); @@ -446,24 +479,30 @@ class CUiPanel : } }; -template -class CUiWindow : - public CUiPrimitive, - public CUiBox, - public T +template class CUiWindow : public CUiPrimitive, public CUiBox, public T { -public: - virtual CUiBox * AsBox() { return this; } + public: + virtual CUiBox * + AsBox() + { + return this; + } - HWND GetWindow() { return T::m_hWnd; } + HWND + GetWindow() + { + return T::m_hWnd; + } - virtual VOID ComputeMinimalSize(SIZE* size) + virtual VOID + ComputeMinimalSize(SIZE *size) { // TODO: Maybe use WM_GETMINMAXINFO? return CUiBox::ComputeMinimalSize(size); }; - virtual VOID ComputeContentBounds(RECT* rect) + virtual VOID + ComputeContentBounds(RECT *rect) { RECT r; ::GetWindowRect(T::m_hWnd, &r); @@ -473,12 +512,14 @@ class CUiWindow : rect->bottom = max(rect->bottom, r.bottom); }; - virtual DWORD_PTR CountSizableChildren() + virtual DWORD_PTR + CountSizableChildren() { return 1; }; - virtual HDWP OnParentSize(RECT parentRect, HDWP hDwp) + virtual HDWP + OnParentSize(RECT parentRect, HDWP hDwp) { RECT rect; @@ -488,16 +529,21 @@ class CUiWindow : if (hDwp) { - return ::DeferWindowPos(hDwp, T::m_hWnd, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOACTIVATE | SWP_NOZORDER); + return ::DeferWindowPos( + hDwp, T::m_hWnd, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, + SWP_NOACTIVATE | SWP_NOZORDER); } else { - T::SetWindowPos(NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOACTIVATE | SWP_NOZORDER | SWP_DEFERERASE); + T::SetWindowPos( + NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, + SWP_NOACTIVATE | SWP_NOZORDER | SWP_DEFERERASE); return NULL; } }; - virtual VOID AppendTabOrderWindow(int Direction, ATL::CSimpleArray & TabOrderList) + virtual VOID + AppendTabOrderWindow(int Direction, ATL::CSimpleArray &TabOrderList) { TabOrderList.Add(T::m_hWnd); return; @@ -511,7 +557,8 @@ class CUiWindow : } } - VOID GetWindowTextW(ATL::CStringW& szText) + VOID + GetWindowTextW(CStringW &szText) { INT length = CWindow::GetWindowTextLengthW() + 1; CWindow::GetWindowTextW(szText.GetBuffer(length), length); @@ -519,15 +566,11 @@ class CUiWindow : } }; -class CUiSplitPanel : - public CUiPrimitive, - public CUiBox, - public CWindowImpl +class CUiSplitPanel : public CUiPrimitive, public CUiBox, public CWindowImpl { static const INT THICKNESS = 4; -protected: - + protected: HCURSOR m_hCursor; CUiPanel m_First; @@ -537,7 +580,7 @@ class CUiSplitPanel : BOOL m_HasOldRect; -public: + public: INT m_Pos; BOOL m_Horizontal; BOOL m_DynamicFirst; @@ -549,25 +592,41 @@ class CUiSplitPanel : CUiSplitPanel() { + m_hCursor = NULL; m_Width = CUiMeasure::FitParent(); m_Height = CUiMeasure::FitParent(); m_Pos = 100; + m_Horizontal = FALSE; m_MinFirst = 100; m_MinSecond = 100; m_DynamicFirst = FALSE; m_HasOldRect = FALSE; + memset(&m_LastRect, 0, sizeof(m_LastRect)); } virtual ~CUiSplitPanel() { } - virtual CUiBox * AsBox() { return this; } + virtual CUiBox * + AsBox() + { + return this; + } - CUiCollection& First() { return m_First.Children(); } - CUiCollection& Second() { return m_Second.Children(); } + CUiCollection & + First() + { + return m_First.Children(); + } + CUiCollection & + Second() + { + return m_Second.Children(); + } - virtual VOID ComputeMinimalSize(SIZE* size) + virtual VOID + ComputeMinimalSize(SIZE *size) { if (m_Horizontal) size->cx = max(size->cx, THICKNESS); @@ -577,7 +636,8 @@ class CUiSplitPanel : m_Second.ComputeMinimalSize(size); }; - virtual VOID ComputeContentBounds(RECT* rect) + virtual VOID + ComputeContentBounds(RECT *rect) { RECT r; @@ -592,7 +652,8 @@ class CUiSplitPanel : rect->bottom = max(rect->bottom, r.bottom); }; - virtual DWORD_PTR CountSizableChildren() + virtual DWORD_PTR + CountSizableChildren() { INT count = 1; count += m_First.CountSizableChildren(); @@ -600,7 +661,8 @@ class CUiSplitPanel : return count; }; - virtual HDWP OnParentSize(RECT parentRect, HDWP hDwp) + virtual HDWP + OnParentSize(RECT parentRect, HDWP hDwp) { RECT rect = {0}; @@ -691,73 +753,72 @@ class CUiSplitPanel : if (hDwp) { - return DeferWindowPos(hDwp, NULL, - splitter.left, splitter.top, - splitter.right - splitter.left, - splitter.bottom - splitter.top, - SWP_NOACTIVATE | SWP_NOZORDER); + return DeferWindowPos( + hDwp, NULL, splitter.left, splitter.top, splitter.right - splitter.left, splitter.bottom - splitter.top, + SWP_NOACTIVATE | SWP_NOZORDER); } else { - SetWindowPos(NULL, - splitter.left, splitter.top, - splitter.right - splitter.left, - splitter.bottom - splitter.top, - SWP_NOACTIVATE | SWP_NOZORDER); + SetWindowPos( + NULL, splitter.left, splitter.top, splitter.right - splitter.left, splitter.bottom - splitter.top, + SWP_NOACTIVATE | SWP_NOZORDER); return NULL; } }; -private: - BOOL ProcessWindowMessage(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT& theResult, DWORD dwMapId) + private: + BOOL + ProcessWindowMessage(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT &theResult, DWORD dwMapId) { theResult = 0; switch (Msg) { - case WM_SETCURSOR: - SetCursor(m_hCursor); - theResult = TRUE; - break; - - case WM_LBUTTONDOWN: - SetCapture(); - break; - - case WM_LBUTTONUP: - case WM_RBUTTONDOWN: - if (GetCapture() == m_hWnd) - { - ReleaseCapture(); - } - break; + case WM_SETCURSOR: + SetCursor(m_hCursor); + theResult = TRUE; + break; + + case WM_LBUTTONDOWN: + SetCapture(); + break; + + case WM_LBUTTONUP: + case WM_RBUTTONDOWN: + if (GetCapture() == m_hWnd) + { + ReleaseCapture(); + } + break; - case WM_MOUSEMOVE: - if (GetCapture() == m_hWnd) - { - POINT Point; - GetCursorPos(&Point); - ::ScreenToClient(GetParent(), &Point); - if (m_Horizontal) - SetPos(Point.y); - else - SetPos(Point.x); - } - break; + case WM_MOUSEMOVE: + if (GetCapture() == m_hWnd) + { + POINT Point; + GetCursorPos(&Point); + ::ScreenToClient(GetParent(), &Point); + if (m_Horizontal) + SetPos(Point.y); + else + SetPos(Point.x); + } + break; - default: - return FALSE; + default: + return FALSE; } return TRUE; } -public: - INT GetPos() + public: + INT + GetPos() { return m_Pos; } - VOID SetPos(INT NewPos) + VOID + SetPos(INT NewPos) { RECT rcParent; @@ -792,15 +853,18 @@ class CUiSplitPanel : HDWP hdwp = NULL; hdwp = BeginDeferWindowPos(count); - if (hdwp) hdwp = OnParentSize(m_LastRect, hdwp); - if (hdwp) EndDeferWindowPos(hdwp); + if (hdwp) + hdwp = OnParentSize(m_LastRect, hdwp); + if (hdwp) + EndDeferWindowPos(hdwp); } -public: + public: DECLARE_WND_CLASS_EX(_T("SplitterWindowClass"), CS_HREDRAW | CS_VREDRAW, COLOR_BTNFACE) /* Create splitter bar */ - HWND Create(HWND hwndParent) + HWND + Create(HWND hwndParent) { if (m_Horizontal) m_hCursor = LoadCursor(0, IDC_SIZENS); diff --git a/base/applications/rapps/installed.cpp b/base/applications/rapps/installed.cpp deleted file mode 100644 index 054bcf1736d37..0000000000000 --- a/base/applications/rapps/installed.cpp +++ /dev/null @@ -1,371 +0,0 @@ -/* - * PROJECT: ReactOS Applications Manager - * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later) - * PURPOSE: Classes for working with installed applications - * COPYRIGHT: Copyright 2009 Dmitry Chapyshev - * Copyright 2017 Alexander Shaposhnikov - * Copyright 2020 He Yang <1160386205@qq.com> - * Copyright 2021 Mark Jansen - */ - -#include "rapps.h" -#include "installed.h" -#include "misc.h" - -CInstalledApplicationInfo::CInstalledApplicationInfo(BOOL bIsUserKey, REGSAM RegWowKey, HKEY hKey, const CStringW& szKeyName) - : m_IsUserKey(bIsUserKey) - , m_WowKey(RegWowKey) - , m_hSubKey(hKey) - , m_szKeyName(szKeyName) -{ - DWORD dwSize = 0; - bIsUpdate = (RegQueryValueExW(m_hSubKey, L"ParentKeyName", NULL, NULL, NULL, &dwSize) == ERROR_SUCCESS); -} - -CInstalledApplicationInfo::~CInstalledApplicationInfo() -{ - if (m_hSubKey) - { - CloseHandle(m_hSubKey); - m_hSubKey = NULL; - } -} - -void CInstalledApplicationInfo::EnsureDetailsLoaded() -{ - // Key not closed, so we have not loaded details yet - if (m_hSubKey) - { - GetApplicationRegString(L"Publisher", szPublisher); - GetApplicationRegString(L"RegOwner", szRegOwner); - GetApplicationRegString(L"ProductID", szProductID); - GetApplicationRegString(L"HelpLink", szHelpLink); - GetApplicationRegString(L"HelpTelephone", szHelpTelephone); - GetApplicationRegString(L"Readme", szReadme); - GetApplicationRegString(L"Contact", szContact); - GetApplicationRegString(L"URLUpdateInfo", szURLUpdateInfo); - GetApplicationRegString(L"URLInfoAbout", szURLInfoAbout); - - DWORD dwInstallTimeStamp; - SYSTEMTIME InstallLocalTime; - if (GetApplicationRegString(L"InstallDate", szInstallDate)) - { - ZeroMemory(&InstallLocalTime, sizeof(InstallLocalTime)); - // Check if we have 8 characters to parse the datetime. - // Maybe other formats exist as well? - szInstallDate = szInstallDate.Trim(); - if (szInstallDate.GetLength() == 8) - { - InstallLocalTime.wYear = wcstol(szInstallDate.Left(4).GetString(), NULL, 10); - InstallLocalTime.wMonth = wcstol(szInstallDate.Mid(4, 2).GetString(), NULL, 10); - InstallLocalTime.wDay = wcstol(szInstallDate.Mid(6, 2).GetString(), NULL, 10); - } - } - // It might be a DWORD (Unix timestamp). try again. - else if (GetApplicationRegDword(L"InstallDate", &dwInstallTimeStamp)) - { - FILETIME InstallFileTime; - SYSTEMTIME InstallSystemTime; - - UnixTimeToFileTime(dwInstallTimeStamp, &InstallFileTime); - FileTimeToSystemTime(&InstallFileTime, &InstallSystemTime); - - // convert to localtime - SystemTimeToTzSpecificLocalTime(NULL, &InstallSystemTime, &InstallLocalTime); - } - - // convert to readable date string - int cchTimeStrLen = GetDateFormatW(LOCALE_USER_DEFAULT, 0, &InstallLocalTime, NULL, 0, 0); - - GetDateFormatW( - LOCALE_USER_DEFAULT, // use default locale for current user - 0, &InstallLocalTime, NULL, szInstallDate.GetBuffer(cchTimeStrLen), cchTimeStrLen); - szInstallDate.ReleaseBuffer(); - - GetApplicationRegString(L"InstallLocation", szInstallLocation); - GetApplicationRegString(L"InstallSource", szInstallSource); - DWORD dwWindowsInstaller = 0; - if (GetApplicationRegDword(L"WindowsInstaller", &dwWindowsInstaller) && dwWindowsInstaller) - { - // MSI has the same info in Uninstall / modify, so manually build it - szUninstallString.Format(L"msiexec /x%s", m_szKeyName.GetString()); - } - else - { - GetApplicationRegString(L"UninstallString", szUninstallString); - } - DWORD dwNoModify = 0; - if (!GetApplicationRegDword(L"NoModify", &dwNoModify)) - { - CStringW Tmp; - if (GetApplicationRegString(L"NoModify", Tmp)) - { - dwNoModify = Tmp.GetLength() > 0 ? (Tmp[0] == '1') : 0; - } - else - { - dwNoModify = 0; - } - } - if (!dwNoModify) - { - if (dwWindowsInstaller) - { - szModifyPath.Format(L"msiexec /i%s", m_szKeyName.GetString()); - } - else - { - GetApplicationRegString(L"ModifyPath", szModifyPath); - } - } - - CloseHandle(m_hSubKey); - m_hSubKey = NULL; - } -} - -BOOL CInstalledApplicationInfo::GetApplicationRegString(LPCWSTR lpKeyName, ATL::CStringW& String) -{ - DWORD dwAllocated = 0, dwSize, dwType; - - // retrieve the size of value first. - if (RegQueryValueExW(m_hSubKey, lpKeyName, NULL, &dwType, NULL, &dwAllocated) != ERROR_SUCCESS) - { - String.Empty(); - return FALSE; - } - - if (dwType != REG_SZ && dwType != REG_EXPAND_SZ) - { - String.Empty(); - return FALSE; - } - - // query the value - dwSize = dwAllocated; - LSTATUS Result = - RegQueryValueExW(m_hSubKey, lpKeyName, NULL, NULL, (LPBYTE)String.GetBuffer(dwAllocated / sizeof(WCHAR)), &dwSize); - - dwSize = min(dwAllocated, dwSize); - // CString takes care of zero-terminating it - String.ReleaseBuffer(); - - if (Result != ERROR_SUCCESS) - { - String.Empty(); - return FALSE; - } - - if (dwType == REG_EXPAND_SZ) - { - CStringW Tmp; - - DWORD dwLen = ExpandEnvironmentStringsW(String, NULL, 0); - if (dwLen > 0) - { - BOOL bSuccess = ExpandEnvironmentStringsW(String, Tmp.GetBuffer(dwLen), dwLen) == dwLen; - Tmp.ReleaseBuffer(); - if (bSuccess) - { - String = Tmp; - } - else - { - String.Empty(); - return FALSE; - } - } - } - - return TRUE; -} - -BOOL CInstalledApplicationInfo::GetApplicationRegDword(LPCWSTR lpKeyName, DWORD *lpValue) -{ - DWORD dwSize = sizeof(DWORD), dwType; - if (RegQueryValueExW(m_hSubKey, - lpKeyName, - NULL, - &dwType, - (LPBYTE)lpValue, - &dwSize) != ERROR_SUCCESS || dwType != REG_DWORD) - { - return FALSE; - } - - return TRUE; -} - -BOOL CInstalledApplicationInfo::RetrieveIcon(ATL::CStringW& IconLocation) -{ - if (szDisplayIcon.IsEmpty()) - { - return FALSE; - } - IconLocation = szDisplayIcon; - return TRUE; -} - -BOOL CInstalledApplicationInfo::UninstallApplication(BOOL bModify) -{ - if (!bModify) - WriteLogMessage(EVENTLOG_SUCCESS, MSG_SUCCESS_REMOVE, szDisplayName); - - return StartProcess(bModify ? szModifyPath : szUninstallString, TRUE); -} - -typedef LSTATUS (WINAPI *RegDeleteKeyExWProc)(HKEY, LPCWSTR, REGSAM, DWORD); - -LSTATUS CInstalledApplicationInfo::RemoveFromRegistry() -{ - ATL::CStringW szFullName = L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + m_szKeyName; - HMODULE hMod = GetModuleHandleW(L"advapi32.dll"); - RegDeleteKeyExWProc pRegDeleteKeyExW; - - // TODO: if there are subkeys inside, simply RegDeleteKeyExW - // (or RegDeleteKeyW on Server 2003 SP0 and earlier) will fail - // we don't have RegDeleteTree for ReactOS now. (It's a WinVista API) - // write a function to delete all subkeys recursively to solve this - // or consider letting ReactOS having this API - - /* Load RegDeleteKeyExW from advapi32.dll if available */ - if (hMod) - { - pRegDeleteKeyExW = (RegDeleteKeyExWProc)GetProcAddress(hMod, "RegDeleteKeyExW"); - - if (pRegDeleteKeyExW) - { - /* Return it */ - return pRegDeleteKeyExW(m_IsUserKey ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, szFullName, m_WowKey, 0); - } - } - - /* Otherwise, return non-Ex function */ - return RegDeleteKeyW(m_IsUserKey ? HKEY_CURRENT_USER : HKEY_LOCAL_MACHINE, szFullName); -} - -BOOL CInstalledApps::Enum(INT EnumType, APPENUMPROC lpEnumProc, PVOID param) -{ - FreeCachedEntries(); - - HKEY RootKeyEnum[3] = { HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_LOCAL_MACHINE }; - REGSAM RegSamEnum[3] = { KEY_WOW64_32KEY, KEY_WOW64_32KEY, KEY_WOW64_64KEY }; - - int LoopTime; - - // test if the OS is 64 bit. - if (IsSystem64Bit()) - { - // loop for all 3 combination. - // note that HKEY_CURRENT_USER\Software don't have a redirect - // https://docs.microsoft.com/en-us/windows/win32/winprog64/shared-registry-keys#redirected-shared-and-reflected-keys-under-wow64 - LoopTime = 3; - } - else - { - // loop for 2 combination for KEY_WOW64_32KEY only - LoopTime = 2; - } - - // loop for all combination - for (int i = 0; i < LoopTime; i++) - { - DWORD dwSize = MAX_PATH; - HKEY hKey, hSubKey; - LONG ItemIndex = 0; - ATL::CStringW szKeyName; - - if (RegOpenKeyExW(RootKeyEnum[i], - L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall", - NULL, - KEY_READ | RegSamEnum[i], - &hKey) != ERROR_SUCCESS) - { - return FALSE; - } - - while (1) - { - dwSize = MAX_PATH; - if (RegEnumKeyExW(hKey, ItemIndex, szKeyName.GetBuffer(MAX_PATH), &dwSize, NULL, NULL, NULL, NULL) != ERROR_SUCCESS) - { - break; - } - - ItemIndex++; - - szKeyName.ReleaseBuffer(); - if (RegOpenKeyW(hKey, szKeyName, &hSubKey) == ERROR_SUCCESS) - { - DWORD dwValue = 0; - BOOL bIsSystemComponent = FALSE; - - dwSize = sizeof(DWORD); - if (RegQueryValueExW(hSubKey, L"SystemComponent", NULL, NULL, (LPBYTE)&dwValue, &dwSize) == ERROR_SUCCESS) - { - bIsSystemComponent = (dwValue == 0x1); - } - // Ignore system components - if (bIsSystemComponent) - { - RegCloseKey(hSubKey); - continue; - } - - BOOL bSuccess = FALSE; - CInstalledApplicationInfo *Info = new CInstalledApplicationInfo(RootKeyEnum[i] == HKEY_CURRENT_USER, RegSamEnum[i], hSubKey, szKeyName); - - // items without display name are ignored - if (Info->GetApplicationRegString(L"DisplayName", Info->szDisplayName)) - { - Info->GetApplicationRegString(L"DisplayIcon", Info->szDisplayIcon); - Info->GetApplicationRegString(L"DisplayVersion", Info->szDisplayVersion); - Info->GetApplicationRegString(L"Comments", Info->szComments); - - bSuccess = TRUE; - } - - if (bSuccess) - { - // add to InfoList. - m_InfoList.AddTail(Info); - - // invoke callback - if (lpEnumProc) - { - if ((EnumType == ENUM_ALL_INSTALLED) || /* All components */ - ((EnumType == ENUM_INSTALLED_APPLICATIONS) && (!Info->bIsUpdate)) || /* Applications only */ - ((EnumType == ENUM_UPDATES) && (Info->bIsUpdate))) /* Updates only */ - { - lpEnumProc(Info, param); - } - } - } - else - { - // destory object - delete Info; - } - } - } - - szKeyName.ReleaseBuffer(); - RegCloseKey(hKey); - } - - return TRUE; -} - -VOID CInstalledApps::FreeCachedEntries() -{ - POSITION InfoListPosition = m_InfoList.GetHeadPosition(); - - /* loop and deallocate all the cached app infos in the list */ - while (InfoListPosition) - { - CInstalledApplicationInfo *Info = m_InfoList.GetNext(InfoListPosition); - delete Info; - } - - m_InfoList.RemoveAll(); -} diff --git a/base/applications/rapps/integrity.cpp b/base/applications/rapps/integrity.cpp index 493a27d69c863..caae4c96dfe8a 100644 --- a/base/applications/rapps/integrity.cpp +++ b/base/applications/rapps/integrity.cpp @@ -3,14 +3,15 @@ * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later) * PURPOSE: Various integrity check mechanisms * COPYRIGHT: Copyright Ismael Ferreras Morezuelas (swyterzone+ros@gmail.com) - * Copyright Mark Jansen + * Copyright 2016 Mark Jansen */ #include "rapps.h" #include -BOOL VerifyInteg(LPCWSTR lpSHA1Hash, LPCWSTR lpFileName) +BOOL +VerifyInteg(LPCWSTR lpSHA1Hash, LPCWSTR lpFileName) { BOOL ret = FALSE; @@ -48,7 +49,7 @@ BOOL VerifyInteg(LPCWSTR lpSHA1Hash, LPCWSTR lpFileName) WCHAR buf[(sizeof(sha) * 2) + 1]; for (UINT i = 0; i < sizeof(sha); i++) - swprintf(buf + 2 * i, L"%02x", ((unsigned char *) sha)[i]); + swprintf(buf + 2 * i, L"%02x", ((unsigned char *)sha)[i]); /* does the resulting SHA1 match with the provided one? */ if (!_wcsicmp(buf, lpSHA1Hash)) ret = TRUE; diff --git a/base/applications/rapps/loaddlg.cpp b/base/applications/rapps/loaddlg.cpp index e3f2c7129d608..618ac035e5c47 100644 --- a/base/applications/rapps/loaddlg.cpp +++ b/base/applications/rapps/loaddlg.cpp @@ -10,23 +10,23 @@ * Copyright 2017 Alexander Shaposhnikov (sanchaez@reactos.org) */ - /* - * Based on Wine dlls/shdocvw/shdocvw_main.c - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - */ +/* + * Based on Wine dlls/shdocvw/shdocvw_main.c + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ #include "rapps.h" #include @@ -55,7 +55,6 @@ #define CERT_SUBJECT_INFO "rapps.reactos.org" #endif - enum DownloadType { DLTYPE_APPLICATION, @@ -73,35 +72,37 @@ enum DownloadStatus DLSTATUS_FINISHED = IDS_STATUS_FINISHED }; -ATL::CStringW LoadStatusString(DownloadStatus StatusParam) +CStringW +LoadStatusString(DownloadStatus StatusParam) { - ATL::CStringW szString; + CStringW szString; szString.LoadStringW(StatusParam); return szString; } struct DownloadInfo { - DownloadInfo() {} - DownloadInfo(const CAvailableApplicationInfo& AppInfo) - : DLType(DLTYPE_APPLICATION) - , szUrl(AppInfo.m_szUrlDownload) - , szName(AppInfo.m_szName) - , szSHA1(AppInfo.m_szSHA1) - , SizeInBytes(AppInfo.m_SizeBytes) + DownloadInfo() { } + DownloadInfo(const CApplicationInfo &AppInfo) : DLType(DLTYPE_APPLICATION) + { + AppInfo.GetDownloadInfo(szUrl, szSHA1, SizeInBytes); + szName = AppInfo.szDisplayName; + } DownloadType DLType; - ATL::CStringW szUrl; - ATL::CStringW szName; - ATL::CStringW szSHA1; + CStringW szUrl; + CStringW szName; + CStringW szSHA1; ULONG SizeInBytes; }; struct DownloadParam { - DownloadParam() : Dialog(NULL), AppInfo(), szCaption(NULL) {} + DownloadParam() : Dialog(NULL), AppInfo(), szCaption(NULL) + { + } DownloadParam(HWND dlg, const ATL::CSimpleArray &info, LPCWSTR caption) : Dialog(dlg), AppInfo(info), szCaption(caption) { @@ -112,18 +113,17 @@ struct DownloadParam LPCWSTR szCaption; }; - -class CDownloaderProgress - : public CWindowImpl +class CDownloaderProgress : public CWindowImpl { - ATL::CStringW m_szProgressText; + CStringW m_szProgressText; -public: + public: CDownloaderProgress() { } - VOID SetMarquee(BOOL Enable) + VOID + SetMarquee(BOOL Enable) { if (Enable) ModifyStyle(0, PBS_MARQUEE, 0); @@ -133,7 +133,8 @@ class CDownloaderProgress SendMessage(PBM_SETMARQUEE, Enable, 0); } - VOID SetProgress(ULONG ulProgress, ULONG ulProgressMax) + VOID + SetProgress(ULONG ulProgress, ULONG ulProgressMax) { WCHAR szProgress[100]; @@ -141,31 +142,30 @@ class CDownloaderProgress StrFormatByteSizeW(ulProgress, szProgress, _countof(szProgress)); /* use our subclassed progress bar text subroutine */ - ATL::CStringW ProgressText; + CStringW ProgressText; if (ulProgressMax) { /* total size is known */ WCHAR szProgressMax[100]; - UINT uiPercentage = ((ULONGLONG) ulProgress * 100) / ulProgressMax; + UINT uiPercentage = ((ULONGLONG)ulProgress * 100) / ulProgressMax; /* send the current progress to the progress bar */ - if (!IsWindow()) return; + if (!IsWindow()) + return; SendMessage(PBM_SETPOS, uiPercentage, 0); /* format total download size */ StrFormatByteSizeW(ulProgressMax, szProgressMax, _countof(szProgressMax)); /* generate the text on progress bar */ - ProgressText.Format(L"%u%% \x2014 %ls / %ls", - uiPercentage, - szProgress, - szProgressMax); + ProgressText.Format(L"%u%% \x2014 %ls / %ls", uiPercentage, szProgress, szProgressMax); } else { /* send the current progress to the progress bar */ - if (!IsWindow()) return; + if (!IsWindow()) + return; SendMessage(PBM_SETPOS, 0, 0); /* total size is not known, display only current size */ @@ -173,18 +173,21 @@ class CDownloaderProgress } /* and finally display it */ - if (!IsWindow()) return; + if (!IsWindow()) + return; SetWindowText(ProgressText.GetString()); } - LRESULT OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) + LRESULT + OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) { return TRUE; } - LRESULT OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) + LRESULT + OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) { - PAINTSTRUCT ps; + PAINTSTRUCT ps; HDC hDC = BeginPaint(&ps), hdcMem; HBITMAP hbmMem; HANDLE hOld; @@ -204,16 +207,14 @@ class CDownloaderProgress hOld = SelectObject(hdcMem, hbmMem); /* call the original draw code and redirect it to our memory buffer */ - DefWindowProc(uMsg, (WPARAM) hdcMem, lParam); + DefWindowProc(uMsg, (WPARAM)hdcMem, lParam); /* draw our nifty progress text over it */ SelectFont(hdcMem, GetStockFont(DEFAULT_GUI_FONT)); - DrawShadowText(hdcMem, m_szProgressText.GetString(), m_szProgressText.GetLength(), - &myRect, - DT_CENTER | DT_VCENTER | DT_NOPREFIX | DT_SINGLELINE, - GetSysColor(COLOR_CAPTIONTEXT), - GetSysColor(COLOR_3DDKSHADOW), - 1, 1); + DrawShadowText( + hdcMem, m_szProgressText.GetString(), m_szProgressText.GetLength(), &myRect, + DT_CENTER | DT_VCENTER | DT_NOPREFIX | DT_SINGLELINE, GetSysColor(COLOR_CAPTIONTEXT), + GetSysColor(COLOR_3DDKSHADOW), 1, 1); /* transfer the off-screen DC to the screen */ BitBlt(hDC, 0, 0, win_width, win_height, hdcMem, 0, 0, SRCCOPY); @@ -227,7 +228,8 @@ class CDownloaderProgress return 0; } - LRESULT OnSetText(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) + LRESULT + OnSetText(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled) { PCWSTR pszText = (PCWSTR)lParam; if (pszText) @@ -250,21 +252,21 @@ class CDownloaderProgress } BEGIN_MSG_MAP(CDownloaderProgress) - MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd) - MESSAGE_HANDLER(WM_PAINT, OnPaint) - MESSAGE_HANDLER(WM_SETTEXT, OnSetText) + MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd) + MESSAGE_HANDLER(WM_PAINT, OnPaint) + MESSAGE_HANDLER(WM_SETTEXT, OnSetText) END_MSG_MAP() }; -class CDowloadingAppsListView - : public CListView +class CDowloadingAppsListView : public CListView { -public: - HWND Create(HWND hwndParent) + public: + HWND + Create(HWND hwndParent) { RECT r = {10, 150, 320, 350}; - const DWORD style = WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_SINGLESEL - | LVS_SHOWSELALWAYS | LVS_NOSORTHEADER | LVS_NOCOLUMNHEADER; + const DWORD style = WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS | LVS_NOSORTHEADER | + LVS_NOCOLUMNHEADER; HWND hwnd = CListView::Create(hwndParent, r, NULL, style, WS_EX_CLIENTEDGE); @@ -274,7 +276,8 @@ class CDowloadingAppsListView return hwnd; } - VOID LoadList(ATL::CSimpleArray arrInfo) + VOID + LoadList(ATL::CSimpleArray arrInfo) { for (INT i = 0; i < arrInfo.GetSize(); ++i) { @@ -282,13 +285,15 @@ class CDowloadingAppsListView } } - VOID SetDownloadStatus(INT ItemIndex, DownloadStatus Status) + VOID + SetDownloadStatus(INT ItemIndex, DownloadStatus Status) { - ATL::CStringW szBuffer = LoadStatusString(Status); + CStringW szBuffer = LoadStatusString(Status); SetItemText(ItemIndex, 1, szBuffer.GetString()); } - BOOL AddItem(INT ItemIndex, LPWSTR lpText) + BOOL + AddItem(INT ItemIndex, LPWSTR lpText) { LVITEMW Item; @@ -301,15 +306,16 @@ class CDowloadingAppsListView return InsertItem(&Item); } - VOID AddRow(INT RowIndex, LPCWSTR szAppName, const DownloadStatus Status) + VOID + AddRow(INT RowIndex, LPCWSTR szAppName, const DownloadStatus Status) { - ATL::CStringW szStatus = LoadStatusString(Status); - AddItem(RowIndex, - const_cast(szAppName)); + CStringW szStatus = LoadStatusString(Status); + AddItem(RowIndex, const_cast(szAppName)); SetDownloadStatus(RowIndex, Status); } - BOOL AddColumn(INT Index, INT Width, INT Format) + BOOL + AddColumn(INT Index, INT Width, INT Format) { LVCOLUMNW Column; ZeroMemory(&Column, sizeof(Column)); @@ -324,7 +330,8 @@ class CDowloadingAppsListView }; #ifdef USE_CERT_PINNING -static BOOL CertGetSubjectAndIssuer(HINTERNET hFile, CLocalPtr& subjectInfo, CLocalPtr& issuerInfo) +static BOOL +CertGetSubjectAndIssuer(HINTERNET hFile, CLocalPtr &subjectInfo, CLocalPtr &issuerInfo) { DWORD certInfoLength; INTERNET_CERTIFICATE_INFOA certInfo; @@ -343,10 +350,7 @@ static BOOL CertGetSubjectAndIssuer(HINTERNET hFile, CLocalPtr& subjectInf /* Despite what the header indicates, the implementation of INTERNET_CERTIFICATE_INFO is not Unicode-aware. */ certInfoLength = sizeof(certInfo); - if (!InternetQueryOptionA(hFile, - INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, - &certInfo, - &certInfoLength)) + if (!InternetQueryOptionA(hFile, INTERNET_OPTION_SECURITY_CERTIFICATE_STRUCT, &certInfo, &certInfoLength)) { return FALSE; } @@ -365,9 +369,10 @@ static BOOL CertGetSubjectAndIssuer(HINTERNET hFile, CLocalPtr& subjectInf } #endif -inline VOID MessageBox_LoadString(HWND hMainWnd, INT StringID) +inline VOID +MessageBox_LoadString(HWND hMainWnd, INT StringID) { - ATL::CStringW szMsgText; + CStringW szMsgText; if (szMsgText.LoadStringW(StringID)) { MessageBoxW(hMainWnd, szMsgText.GetString(), NULL, MB_OK | MB_ICONERROR); @@ -382,138 +387,147 @@ class CDownloadManager static CDownloaderProgress ProgressBar; static BOOL bCancelled; static BOOL bModal; - static VOID UpdateProgress(HWND hDlg, ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText); -public: - static VOID Add(DownloadInfo info); - static VOID Download(const DownloadInfo& DLInfo, BOOL bIsModal = FALSE); - static INT_PTR CALLBACK DownloadDlgProc(HWND Dlg, UINT uMsg, WPARAM wParam, LPARAM lParam); - static unsigned int WINAPI ThreadFunc(LPVOID Context); + static VOID + UpdateProgress(HWND hDlg, ULONG ulProgress, ULONG ulProgressMax, ULONG ulStatusCode, LPCWSTR szStatusText); + + public: + static VOID + Add(DownloadInfo info); + static VOID + Download(const DownloadInfo &DLInfo, BOOL bIsModal = FALSE); + static INT_PTR CALLBACK + DownloadDlgProc(HWND Dlg, UINT uMsg, WPARAM wParam, LPARAM lParam); + static unsigned int WINAPI + ThreadFunc(LPVOID Context); static VOID LaunchDownloadDialog(BOOL); }; - // CDownloadManager -ATL::CSimpleArray CDownloadManager::AppsDownloadList; -CDowloadingAppsListView CDownloadManager::DownloadsListView; -CDownloaderProgress CDownloadManager::ProgressBar; -BOOL CDownloadManager::bCancelled = FALSE; -BOOL CDownloadManager::bModal = FALSE; - -VOID CDownloadManager::Add(DownloadInfo info) +ATL::CSimpleArray CDownloadManager::AppsDownloadList; +CDowloadingAppsListView CDownloadManager::DownloadsListView; +CDownloaderProgress CDownloadManager::ProgressBar; +BOOL CDownloadManager::bCancelled = FALSE; +BOOL CDownloadManager::bModal = FALSE; + +VOID +CDownloadManager::Add(DownloadInfo info) { AppsDownloadList.Add(info); } -VOID CDownloadManager::Download(const DownloadInfo &DLInfo, BOOL bIsModal) +VOID +CDownloadManager::Download(const DownloadInfo &DLInfo, BOOL bIsModal) { AppsDownloadList.RemoveAll(); AppsDownloadList.Add(DLInfo); LaunchDownloadDialog(bIsModal); } -INT_PTR CALLBACK CDownloadManager::DownloadDlgProc(HWND Dlg, UINT uMsg, WPARAM wParam, LPARAM lParam) +INT_PTR CALLBACK +CDownloadManager::DownloadDlgProc(HWND Dlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { static WCHAR szCaption[MAX_PATH]; switch (uMsg) { - case WM_INITDIALOG: - { - HICON hIconSm, hIconBg; - ATL::CStringW szTempCaption; - - bCancelled = FALSE; - - if (hMainWnd) - { - hIconBg = (HICON)GetClassLongPtrW(hMainWnd, GCLP_HICON); - hIconSm = (HICON)GetClassLongPtrW(hMainWnd, GCLP_HICONSM); - } - if (!hMainWnd || (!hIconBg || !hIconSm)) + case WM_INITDIALOG: { - /* Load the default icon */ - hIconBg = hIconSm = LoadIconW(hInst, MAKEINTRESOURCEW(IDI_MAIN)); - } + HICON hIconSm, hIconBg; + CStringW szTempCaption; - if (hIconBg && hIconSm) - { - SendMessageW(Dlg, WM_SETICON, ICON_BIG, (LPARAM)hIconBg); - SendMessageW(Dlg, WM_SETICON, ICON_SMALL, (LPARAM)hIconSm); - } + bCancelled = FALSE; - HWND Item = GetDlgItem(Dlg, IDC_DOWNLOAD_PROGRESS); - if (Item) - { - // initialize the default values for our nifty progress bar - // and subclass it so that it learns to print a status text - ProgressBar.SubclassWindow(Item); - ProgressBar.SendMessage(PBM_SETRANGE, 0, MAKELPARAM(0, 100)); - ProgressBar.SendMessage(PBM_SETPOS, 0, 0); - if (AppsDownloadList.GetSize() > 0) - ProgressBar.SetProgress(0, AppsDownloadList[0].SizeInBytes); - } + if (hMainWnd) + { + hIconBg = (HICON)GetClassLongPtrW(hMainWnd, GCLP_HICON); + hIconSm = (HICON)GetClassLongPtrW(hMainWnd, GCLP_HICONSM); + } + if (!hMainWnd || (!hIconBg || !hIconSm)) + { + /* Load the default icon */ + hIconBg = hIconSm = LoadIconW(hInst, MAKEINTRESOURCEW(IDI_MAIN)); + } - // Add a ListView - HWND hListView = DownloadsListView.Create(Dlg); - if (!hListView) - { - return FALSE; - } - DownloadsListView.LoadList(AppsDownloadList); + if (hIconBg && hIconSm) + { + SendMessageW(Dlg, WM_SETICON, ICON_BIG, (LPARAM)hIconBg); + SendMessageW(Dlg, WM_SETICON, ICON_SMALL, (LPARAM)hIconSm); + } - // Get a dlg string for later use - GetWindowTextW(Dlg, szCaption, _countof(szCaption)); + HWND Item = GetDlgItem(Dlg, IDC_DOWNLOAD_PROGRESS); + if (Item) + { + // initialize the default values for our nifty progress bar + // and subclass it so that it learns to print a status text + ProgressBar.SubclassWindow(Item); + ProgressBar.SendMessage(PBM_SETRANGE, 0, MAKELPARAM(0, 100)); + ProgressBar.SendMessage(PBM_SETPOS, 0, 0); + if (AppsDownloadList.GetSize() > 0) + ProgressBar.SetProgress(0, AppsDownloadList[0].SizeInBytes); + } - // Hide a placeholder from displaying - szTempCaption = szCaption; - szTempCaption.Replace(L"%ls", L""); - SetWindowText(Dlg, szTempCaption.GetString()); + // Add a ListView + HWND hListView = DownloadsListView.Create(Dlg); + if (!hListView) + { + return FALSE; + } + DownloadsListView.LoadList(AppsDownloadList); - ShowWindow(Dlg, SW_SHOW); + // Get a dlg string for later use + GetWindowTextW(Dlg, szCaption, _countof(szCaption)); - // Start download process - DownloadParam *param = new DownloadParam(Dlg, AppsDownloadList, szCaption); - unsigned int ThreadId; - HANDLE Thread = (HANDLE)_beginthreadex(NULL, 0, ThreadFunc, (void *) param, 0, &ThreadId); - if (!Thread) - { - return FALSE; - } + // Hide a placeholder from displaying + szTempCaption = szCaption; + szTempCaption.Replace(L"%ls", L""); + SetWindowText(Dlg, szTempCaption.GetString()); - CloseHandle(Thread); - AppsDownloadList.RemoveAll(); - return TRUE; - } + ShowWindow(Dlg, SW_SHOW); - case WM_COMMAND: - if (wParam == IDCANCEL) - { - bCancelled = TRUE; - PostMessageW(Dlg, WM_CLOSE, 0, 0); - } - return FALSE; + // Start download process + DownloadParam *param = new DownloadParam(Dlg, AppsDownloadList, szCaption); + unsigned int ThreadId; + HANDLE Thread = (HANDLE)_beginthreadex(NULL, 0, ThreadFunc, (void *)param, 0, &ThreadId); + if (!Thread) + { + return FALSE; + } - case WM_CLOSE: - if (ProgressBar) - ProgressBar.UnsubclassWindow(TRUE); - if (CDownloadManager::bModal) - { - ::EndDialog(Dlg, 0); - } - else - { - ::DestroyWindow(Dlg); + CloseHandle(Thread); + AppsDownloadList.RemoveAll(); + return TRUE; } - return TRUE; - default: - return FALSE; + case WM_COMMAND: + if (wParam == IDCANCEL) + { + bCancelled = TRUE; + PostMessageW(Dlg, WM_CLOSE, 0, 0); + } + return FALSE; + + case WM_CLOSE: + if (ProgressBar) + ProgressBar.UnsubclassWindow(TRUE); + if (CDownloadManager::bModal) + { + ::EndDialog(Dlg, 0); + } + else + { + ::DestroyWindow(Dlg); + } + return TRUE; + + default: + return FALSE; } } BOOL UrlHasBeenCopied; -VOID CDownloadManager::UpdateProgress( +VOID +CDownloadManager::UpdateProgress( HWND hDlg, ULONG ulProgress, ULONG ulProgressMax, @@ -522,15 +536,17 @@ VOID CDownloadManager::UpdateProgress( { HWND Item; - if (!IsWindow(hDlg)) return; + if (!IsWindow(hDlg)) + return; ProgressBar.SetProgress(ulProgress, ulProgressMax); - if (!IsWindow(hDlg)) return; + if (!IsWindow(hDlg)) + return; Item = GetDlgItem(hDlg, IDC_DOWNLOAD_STATUS); if (Item && szStatusText && wcslen(szStatusText) > 0 && UrlHasBeenCopied == FALSE) { SIZE_T len = wcslen(szStatusText) + 1; - ATL::CStringW buf; + CStringW buf; DWORD dummyLen; /* beautify our url for display purposes */ @@ -551,21 +567,16 @@ VOID CDownloadManager::UpdateProgress( } } -BOOL ShowLastError( - HWND hWndOwner, - BOOL bInetError, - DWORD dwLastError) +BOOL +ShowLastError(HWND hWndOwner, BOOL bInetError, DWORD dwLastError) { CLocalPtr lpMsg; - if (!FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_IGNORE_INSERTS | - (bInetError ? FORMAT_MESSAGE_FROM_HMODULE : FORMAT_MESSAGE_FROM_SYSTEM), - (bInetError ? GetModuleHandleW(L"wininet.dll") : NULL), - dwLastError, - LANG_USER_DEFAULT, - (LPWSTR)&lpMsg, - 0, NULL)) + if (!FormatMessageW( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS | + (bInetError ? FORMAT_MESSAGE_FROM_HMODULE : FORMAT_MESSAGE_FROM_SYSTEM), + (bInetError ? GetModuleHandleW(L"wininet.dll") : NULL), dwLastError, LANG_USER_DEFAULT, (LPWSTR)&lpMsg, 0, + NULL)) { DPRINT1("FormatMessageW unexpected failure (err %d)\n", GetLastError()); return FALSE; @@ -575,12 +586,13 @@ BOOL ShowLastError( return TRUE; } -unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param) +unsigned int WINAPI +CDownloadManager::ThreadFunc(LPVOID param) { - ATL::CStringW Path; + CPathW Path; PWSTR p, q; - HWND hDlg = static_cast(param)->Dialog; + HWND hDlg = static_cast(param)->Dialog; HWND Item; INT iAppId; @@ -599,11 +611,12 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param) URL_COMPONENTSW urlComponents; size_t urlLength, filenameLength; - const ATL::CSimpleArray &InfoArray = static_cast(param)->AppInfo; - LPCWSTR szCaption = static_cast(param)->szCaption; - ATL::CStringW szNewCaption; + const ATL::CSimpleArray &InfoArray = static_cast(param)->AppInfo; + LPCWSTR szCaption = static_cast(param)->szCaption; + CStringW szNewCaption; - const DWORD dwUrlConnectFlags = INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_KEEP_CONNECTION; + const DWORD dwUrlConnectFlags = + INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_KEEP_CONNECTION; if (InfoArray.GetSize() <= 0) { @@ -614,7 +627,8 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param) for (iAppId = 0; iAppId < InfoArray.GetSize(); ++iAppId) { // Reset progress bar - if (!IsWindow(hDlg)) break; + if (!IsWindow(hDlg)) + break; Item = GetDlgItem(hDlg, IDC_DOWNLOAD_PROGRESS); if (Item) { @@ -638,20 +652,21 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param) } // Change caption to show the currently downloaded app - switch(InfoArray[iAppId].DLType) + switch (InfoArray[iAppId].DLType) { - case DLTYPE_APPLICATION: - szNewCaption.Format(szCaption, InfoArray[iAppId].szName.GetString()); - break; - case DLTYPE_DBUPDATE: - szNewCaption.LoadStringW(IDS_DL_DIALOG_DB_DOWNLOAD_DISP); - break; - case DLTYPE_DBUPDATE_UNOFFICIAL: - szNewCaption.LoadStringW(IDS_DL_DIALOG_DB_UNOFFICIAL_DOWNLOAD_DISP); - break; + case DLTYPE_APPLICATION: + szNewCaption.Format(szCaption, InfoArray[iAppId].szName.GetString()); + break; + case DLTYPE_DBUPDATE: + szNewCaption.LoadStringW(IDS_DL_DIALOG_DB_DOWNLOAD_DISP); + break; + case DLTYPE_DBUPDATE_UNOFFICIAL: + szNewCaption.LoadStringW(IDS_DL_DIALOG_DB_UNOFFICIAL_DOWNLOAD_DISP); + break; } - if (!IsWindow(hDlg)) goto end; + if (!IsWindow(hDlg)) + goto end; SetWindowTextW(hDlg, szNewCaption.GetString()); // build the path for the download @@ -674,31 +689,28 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param) filenameLength -= wcslen(q - 1) * sizeof(WCHAR); // is the path valid? can we access it? - if (GetFileAttributesW(Path.GetString()) == INVALID_FILE_ATTRIBUTES) + if (GetFileAttributesW(Path) == INVALID_FILE_ATTRIBUTES) { - if (!CreateDirectoryW(Path.GetString(), NULL)) + if (!CreateDirectoryW(Path, NULL)) { ShowLastError(hMainWnd, FALSE, GetLastError()); goto end; } } - // append a \ to the provided file system path, and the filename portion from the URL after that - - PathAddBackslashW(Path.GetBuffer(MAX_PATH)); switch (InfoArray[iAppId].DLType) { - case DLTYPE_DBUPDATE: - case DLTYPE_DBUPDATE_UNOFFICIAL: - PathAppendW(Path.GetBuffer(), APPLICATION_DATABASE_NAME); - break; - case DLTYPE_APPLICATION: - PathAppendW(Path.GetBuffer(), (LPWSTR)(p + 1)); // use the filename retrieved from URL - break; + case DLTYPE_DBUPDATE: + case DLTYPE_DBUPDATE_UNOFFICIAL: + Path += APPLICATION_DATABASE_NAME; + break; + case DLTYPE_APPLICATION: + Path += (LPWSTR)(p + 1); // use the filename retrieved from URL + break; } - Path.ReleaseBuffer(); - if ((InfoArray[iAppId].DLType == DLTYPE_APPLICATION) && InfoArray[iAppId].szSHA1[0] && GetFileAttributesW(Path.GetString()) != INVALID_FILE_ATTRIBUTES) + if ((InfoArray[iAppId].DLType == DLTYPE_APPLICATION) && InfoArray[iAppId].szSHA1[0] && + GetFileAttributesW(Path) != INVALID_FILE_ATTRIBUTES) { // only open it in case of total correctness if (VerifyInteg(InfoArray[iAppId].szSHA1.GetString(), Path)) @@ -706,7 +718,8 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param) } // Add the download URL - if (!IsWindow(hDlg)) goto end; + if (!IsWindow(hDlg)) + goto end; SetDlgItemTextW(hDlg, IDC_DOWNLOAD_STATUS, InfoArray[iAppId].szUrl.GetString()); DownloadsListView.SetDownloadStatus(iAppId, DLSTATUS_DOWNLOADING); @@ -718,16 +731,17 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param) /* FIXME: this should just be using the system-wide proxy settings */ switch (SettingsInfo.Proxy) { - case 0: // preconfig - default: - hOpen = InternetOpenW(lpszAgent, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); - break; - case 1: // direct (no proxy) - hOpen = InternetOpenW(lpszAgent, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); - break; - case 2: // use proxy - hOpen = InternetOpenW(lpszAgent, INTERNET_OPEN_TYPE_PROXY, SettingsInfo.szProxyServer, SettingsInfo.szNoProxyFor, 0); - break; + case 0: // preconfig + default: + hOpen = InternetOpenW(lpszAgent, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); + break; + case 1: // direct (no proxy) + hOpen = InternetOpenW(lpszAgent, INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0); + break; + case 2: // use proxy + hOpen = InternetOpenW( + lpszAgent, INTERNET_OPEN_TYPE_PROXY, SettingsInfo.szProxyServer, SettingsInfo.szNoProxyFor, 0); + break; } if (!hOpen) @@ -743,7 +757,7 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param) urlLength = InfoArray[iAppId].szUrl.GetLength(); urlComponents.dwSchemeLength = urlLength + 1; - urlComponents.lpszScheme = (LPWSTR) malloc(urlComponents.dwSchemeLength * sizeof(WCHAR)); + urlComponents.lpszScheme = (LPWSTR)malloc(urlComponents.dwSchemeLength * sizeof(WCHAR)); if (!InternetCrackUrlW(InfoArray[iAppId].szUrl, urlLength + 1, ICU_DECODE | ICU_ESCAPE, &urlComponents)) { @@ -753,12 +767,9 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param) dwContentLen = 0; - if (urlComponents.nScheme == INTERNET_SCHEME_HTTP || - urlComponents.nScheme == INTERNET_SCHEME_HTTPS) + if (urlComponents.nScheme == INTERNET_SCHEME_HTTP || urlComponents.nScheme == INTERNET_SCHEME_HTTPS) { - hFile = InternetOpenUrlW(hOpen, InfoArray[iAppId].szUrl.GetString(), NULL, 0, - dwUrlConnectFlags, - 0); + hFile = InternetOpenUrlW(hOpen, InfoArray[iAppId].szUrl.GetString(), NULL, 0, dwUrlConnectFlags, 0); if (!hFile) { if (!ShowLastError(hMainWnd, TRUE, GetLastError())) @@ -783,14 +794,14 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param) } // query content length - HttpQueryInfoW(hFile, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &dwContentLen, &dwStatusLen, NULL); + HttpQueryInfoW( + hFile, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, &dwContentLen, &dwStatusLen, NULL); } else if (urlComponents.nScheme == INTERNET_SCHEME_FTP) { // force passive mode on FTP - hFile = InternetOpenUrlW(hOpen, InfoArray[iAppId].szUrl, NULL, 0, - dwUrlConnectFlags | INTERNET_FLAG_PASSIVE, - 0); + hFile = + InternetOpenUrlW(hOpen, InfoArray[iAppId].szUrl, NULL, 0, dwUrlConnectFlags | INTERNET_FLAG_PASSIVE, 0); if (!hFile) { if (!ShowLastError(hMainWnd, TRUE, GetLastError())) @@ -847,8 +858,7 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param) #ifdef USE_CERT_PINNING // are we using HTTPS to download the RAPPS update package? check if the certificate is original - if ((urlComponents.nScheme == INTERNET_SCHEME_HTTPS) && - (InfoArray[iAppId].DLType == DLTYPE_DBUPDATE)) + if ((urlComponents.nScheme == INTERNET_SCHEME_HTTPS) && (InfoArray[iAppId].DLType == DLTYPE_DBUPDATE)) { CLocalPtr subjectName, issuerName; CStringA szMsgText; @@ -861,10 +871,9 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param) else { if (strcmp(subjectName, CERT_SUBJECT_INFO) || - (strcmp(issuerName, CERT_ISSUER_INFO_OLD) && - strcmp(issuerName, CERT_ISSUER_INFO_NEW))) + (strcmp(issuerName, CERT_ISSUER_INFO_OLD) && strcmp(issuerName, CERT_ISSUER_INFO_NEW))) { - szMsgText.Format(IDS_MISMATCH_CERT_INFO, (char*)subjectName, (const char*)issuerName); + szMsgText.Format(IDS_MISMATCH_CERT_INFO, (char *)subjectName, (const char *)issuerName); bAskQuestion = true; } } @@ -879,7 +888,7 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param) } #endif - hOut = CreateFileW(Path.GetString(), GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, NULL); + hOut = CreateFileW(Path, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, NULL); if (hOut == INVALID_HANDLE_VALUE) { @@ -903,7 +912,8 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param) } dwCurrentBytesRead += dwBytesRead; - if (!IsWindow(hDlg)) goto end; + if (!IsWindow(hDlg)) + goto end; UpdateProgress(hDlg, dwCurrentBytesRead, dwContentLen, 0, InfoArray[iAppId].szUrl.GetString()); } while (dwBytesRead && !bCancelled); @@ -922,7 +932,8 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param) ProgressBar.SetMarquee(FALSE); dwContentLen = dwCurrentBytesRead; - if (!IsWindow(hDlg)) goto end; + if (!IsWindow(hDlg)) + goto end; UpdateProgress(hDlg, dwCurrentBytesRead, dwContentLen, 0, InfoArray[iAppId].szUrl.GetString()); } @@ -930,7 +941,7 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param) verify its integrity by using the native advapi32.A_SHA1 functions */ if ((InfoArray[iAppId].DLType == DLTYPE_APPLICATION) && InfoArray[iAppId].szSHA1[0] != 0) { - ATL::CStringW szMsgText; + CStringW szMsgText; // change a few strings in the download dialog to reflect the verification process if (!szMsgText.LoadStringW(IDS_INTEG_CHECK_TITLE)) @@ -939,12 +950,13 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param) goto end; } - if (!IsWindow(hDlg)) goto end; + if (!IsWindow(hDlg)) + goto end; SetWindowTextW(hDlg, szMsgText.GetString()); - ::SetDlgItemText(hDlg, IDC_DOWNLOAD_STATUS, Path.GetString()); + ::SetDlgItemTextW(hDlg, IDC_DOWNLOAD_STATUS, Path); // this may take a while, depending on the file size - if (!VerifyInteg(InfoArray[iAppId].szSHA1.GetString(), Path.GetString())) + if (!VerifyInteg(InfoArray[iAppId].szSHA1.GetString(), Path)) { if (!szMsgText.LoadStringW(IDS_INTEG_CHECK_FAIL)) { @@ -952,13 +964,14 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param) goto end; } - if (!IsWindow(hDlg)) goto end; + if (!IsWindow(hDlg)) + goto end; MessageBoxW(hDlg, szMsgText.GetString(), NULL, MB_OK | MB_ICONERROR); goto end; } } -run: + run: DownloadsListView.SetDownloadStatus(iAppId, DLSTATUS_WAITING_INSTALL); // run it @@ -968,7 +981,7 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param) shExInfo.cbSize = sizeof(shExInfo); shExInfo.fMask = SEE_MASK_NOCLOSEPROCESS; shExInfo.lpVerb = L"open"; - shExInfo.lpFile = Path.GetString(); + shExInfo.lpFile = Path; shExInfo.lpParameters = L""; shExInfo.nShow = SW_SHOW; @@ -977,15 +990,16 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param) if (ShellExecuteExW(&shExInfo)) { - //reflect installation progress in the titlebar - //TODO: make a separate string with a placeholder to include app name? - ATL::CStringW szMsgText = LoadStatusString(DLSTATUS_INSTALLING); - if (!IsWindow(hDlg)) goto end; + // reflect installation progress in the titlebar + // TODO: make a separate string with a placeholder to include app name? + CStringW szMsgText = LoadStatusString(DLSTATUS_INSTALLING); + if (!IsWindow(hDlg)) + goto end; SetWindowTextW(hDlg, szMsgText.GetString()); DownloadsListView.SetDownloadStatus(iAppId, DLSTATUS_INSTALLING); - //TODO: issue an install operation separately so that the apps could be downloaded in the background + // TODO: issue an install operation separately so that the apps could be downloaded in the background WaitForSingleObject(shExInfo.hProcess, INFINITE); CloseHandle(shExInfo.hProcess); } @@ -995,7 +1009,7 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param) } } -end: + end: if (hOut != INVALID_HANDLE_VALUE) CloseHandle(hOut); @@ -1006,50 +1020,48 @@ unsigned int WINAPI CDownloadManager::ThreadFunc(LPVOID param) if (bTempfile) { if (bCancelled || (SettingsInfo.bDelInstaller && (InfoArray[iAppId].DLType == DLTYPE_APPLICATION))) - DeleteFileW(Path.GetString()); + DeleteFileW(Path); } - if (!IsWindow(hDlg)) return 0; + if (!IsWindow(hDlg)) + return 0; DownloadsListView.SetDownloadStatus(iAppId, DLSTATUS_FINISHED); } - delete static_cast(param); - if (!IsWindow(hDlg)) return 0; + delete static_cast(param); + if (!IsWindow(hDlg)) + return 0; SendMessageW(hDlg, WM_CLOSE, 0, 0); return 0; } -//TODO: Reuse the dialog -VOID CDownloadManager::LaunchDownloadDialog(BOOL bIsModal) +// TODO: Reuse the dialog +VOID +CDownloadManager::LaunchDownloadDialog(BOOL bIsModal) { CDownloadManager::bModal = bIsModal; if (bIsModal) { - DialogBoxW(hInst, - MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG), - hMainWnd, - DownloadDlgProc); + DialogBoxW(hInst, MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG), hMainWnd, DownloadDlgProc); } else { - CreateDialogW(hInst, - MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG), - hMainWnd, - DownloadDlgProc); + CreateDialogW(hInst, MAKEINTRESOURCEW(IDD_DOWNLOAD_DIALOG), hMainWnd, DownloadDlgProc); } } // CDownloadManager - -BOOL DownloadListOfApplications(const ATL::CSimpleArray& AppsList, BOOL bIsModal) +BOOL +DownloadListOfApplications(const CAtlList &AppsList, BOOL bIsModal) { - if (AppsList.GetSize() == 0) + if (AppsList.IsEmpty()) return FALSE; - // Initialize shared variables - for (INT i = 0; i < AppsList.GetSize(); ++i) + POSITION CurrentListPosition = AppsList.GetHeadPosition(); + while (CurrentListPosition) { - CDownloadManager::Add(AppsList[i]); // implicit conversion to DownloadInfo + const CApplicationInfo *Info = AppsList.GetNext(CurrentListPosition); + CDownloadManager::Add(DownloadInfo(*Info)); } // Create a dialog and issue a download process @@ -1058,7 +1070,8 @@ BOOL DownloadListOfApplications(const ATL::CSimpleArraydwHighDateTime = ll >> 32; } -BOOL SearchPatternMatch(LPCWSTR szHaystack, LPCWSTR szNeedle) +BOOL +SearchPatternMatch(LPCWSTR szHaystack, LPCWSTR szNeedle) { if (!*szNeedle) return TRUE; diff --git a/base/applications/rapps/settings.cpp b/base/applications/rapps/settings.cpp index 57c7b55ba062b..bac3f908349d8 100644 --- a/base/applications/rapps/settings.cpp +++ b/base/applications/rapps/settings.cpp @@ -11,25 +11,31 @@ class SettingsField { -public: - virtual ~SettingsField() { ; } - virtual BOOL Save(CRegKey &key) = 0; - virtual BOOL Load(CRegKey &key) = 0; + public: + virtual ~SettingsField() + { + ; + } + virtual BOOL + Save(CRegKey &key) = 0; + virtual BOOL + Load(CRegKey &key) = 0; }; class SettingsFieldBool : public SettingsField { -public: - SettingsFieldBool(BOOL *pValue, LPCWSTR szRegName) - : m_pValueStore(pValue), m_RegName(szRegName) + public: + SettingsFieldBool(BOOL *pValue, LPCWSTR szRegName) : m_pValueStore(pValue), m_RegName(szRegName) { } - virtual BOOL Save(CRegKey &key) override + virtual BOOL + Save(CRegKey &key) override { return key.SetDWORDValue(m_RegName, (DWORD)(*m_pValueStore)) == ERROR_SUCCESS; } - virtual BOOL Load(CRegKey &key) override + virtual BOOL + Load(CRegKey &key) override { DWORD dwField; LONG lResult = key.QueryDWORDValue(m_RegName, dwField); @@ -41,24 +47,25 @@ class SettingsFieldBool : public SettingsField return TRUE; } -private: - BOOL *m_pValueStore; // where to read/store the value - LPCWSTR m_RegName; // key name in registery + private: + BOOL *m_pValueStore; // where to read/store the value + LPCWSTR m_RegName; // key name in registery }; class SettingsFieldInt : public SettingsField { -public: - SettingsFieldInt(INT *pValue, LPCWSTR szRegName) - : m_pValueStore(pValue), m_RegName(szRegName) + public: + SettingsFieldInt(INT *pValue, LPCWSTR szRegName) : m_pValueStore(pValue), m_RegName(szRegName) { } - virtual BOOL Save(CRegKey &key) override + virtual BOOL + Save(CRegKey &key) override { return key.SetDWORDValue(m_RegName, (DWORD)(*m_pValueStore)) == ERROR_SUCCESS; } - virtual BOOL Load(CRegKey &key) override + virtual BOOL + Load(CRegKey &key) override { DWORD dwField; LONG lResult = key.QueryDWORDValue(m_RegName, dwField); @@ -70,38 +77,40 @@ class SettingsFieldInt : public SettingsField return TRUE; } -private: - INT *m_pValueStore; // where to read/store the value - LPCWSTR m_RegName; // key name in registery + private: + INT *m_pValueStore; // where to read/store the value + LPCWSTR m_RegName; // key name in registery }; class SettingsFieldString : public SettingsField { -public: + public: SettingsFieldString(WCHAR *pString, ULONG cchLen, LPCWSTR szRegName) : m_pStringStore(pString), m_StringLen(cchLen), m_RegName(szRegName) { } - virtual BOOL Save(CRegKey &key) override + virtual BOOL + Save(CRegKey &key) override { return key.SetStringValue(m_RegName, m_pStringStore) == ERROR_SUCCESS; } - virtual BOOL Load(CRegKey &key) override + virtual BOOL + Load(CRegKey &key) override { ULONG nChar = m_StringLen - 1; // make sure the terminating L'\0' LONG lResult = key.QueryStringValue(m_RegName, m_pStringStore, &nChar); return lResult == ERROR_SUCCESS; } -private: - WCHAR *m_pStringStore; // where to read/store the value - ULONG m_StringLen; // string length, in chars - LPCWSTR m_RegName; // key name in registery + private: + WCHAR *m_pStringStore; // where to read/store the value + ULONG m_StringLen; // string length, in chars + LPCWSTR m_RegName; // key name in registery }; - -void AddInfoFields(ATL::CAtlList &infoFields, SETTINGS_INFO &settings) +void +AddInfoFields(ATL::CAtlList &infoFields, SETTINGS_INFO &settings) { infoFields.AddTail(new SettingsFieldBool(&(settings.bSaveWndPos), L"bSaveWndPos")); infoFields.AddTail(new SettingsFieldBool(&(settings.bUpdateAtStart), L"bUpdateAtStart")); @@ -122,7 +131,8 @@ void AddInfoFields(ATL::CAtlList &infoFields, SETTINGS_INFO &se return; } -BOOL SaveAllSettings(CRegKey &key, SETTINGS_INFO &settings) +BOOL +SaveAllSettings(CRegKey &key, SETTINGS_INFO &settings) { BOOL bAllSuccess = TRUE; ATL::CAtlList infoFields; @@ -143,7 +153,8 @@ BOOL SaveAllSettings(CRegKey &key, SETTINGS_INFO &settings) return bAllSuccess; } -BOOL LoadAllSettings(CRegKey &key, SETTINGS_INFO &settings) +BOOL +LoadAllSettings(CRegKey &key, SETTINGS_INFO &settings) { BOOL bAllSuccess = TRUE; ATL::CAtlList infoFields; @@ -164,9 +175,10 @@ BOOL LoadAllSettings(CRegKey &key, SETTINGS_INFO &settings) return bAllSuccess; } -VOID FillDefaultSettings(PSETTINGS_INFO pSettingsInfo) +VOID +FillDefaultSettings(PSETTINGS_INFO pSettingsInfo) { - ATL::CStringW szDownloadDir; + CStringW szDownloadDir; ZeroMemory(pSettingsInfo, sizeof(SETTINGS_INFO)); pSettingsInfo->bSaveWndPos = TRUE; @@ -190,9 +202,8 @@ VOID FillDefaultSettings(PSETTINGS_INFO pSettingsInfo) PathAppendW(szDownloadDir.GetBuffer(MAX_PATH), L"\\RAPPS Downloads"); szDownloadDir.ReleaseBuffer(); - ATL::CStringW::CopyChars(pSettingsInfo->szDownloadDir, - _countof(pSettingsInfo->szDownloadDir), - szDownloadDir.GetString(), + CStringW::CopyChars( + pSettingsInfo->szDownloadDir, _countof(pSettingsInfo->szDownloadDir), szDownloadDir.GetString(), szDownloadDir.GetLength() + 1); pSettingsInfo->bDelInstaller = FALSE; @@ -203,7 +214,8 @@ VOID FillDefaultSettings(PSETTINGS_INFO pSettingsInfo) pSettingsInfo->Height = 450; } -BOOL LoadSettings(PSETTINGS_INFO pSettingsInfo) +BOOL +LoadSettings(PSETTINGS_INFO pSettingsInfo) { ATL::CRegKey RegKey; if (RegKey.Open(HKEY_CURRENT_USER, L"Software\\ReactOS\\rapps", KEY_READ) != ERROR_SUCCESS) @@ -214,7 +226,8 @@ BOOL LoadSettings(PSETTINGS_INFO pSettingsInfo) return LoadAllSettings(RegKey, *pSettingsInfo); } -BOOL SaveSettings(HWND hwnd, PSETTINGS_INFO pSettingsInfo) +BOOL +SaveSettings(HWND hwnd, PSETTINGS_INFO pSettingsInfo) { WINDOWPLACEMENT wp; ATL::CRegKey RegKey; @@ -228,13 +241,13 @@ BOOL SaveSettings(HWND hwnd, PSETTINGS_INFO pSettingsInfo) pSettingsInfo->Top = wp.rcNormalPosition.top; pSettingsInfo->Width = wp.rcNormalPosition.right - wp.rcNormalPosition.left; pSettingsInfo->Height = wp.rcNormalPosition.bottom - wp.rcNormalPosition.top; - pSettingsInfo->Maximized = (wp.showCmd == SW_MAXIMIZE - || (wp.showCmd == SW_SHOWMINIMIZED - && (wp.flags & WPF_RESTORETOMAXIMIZED))); + pSettingsInfo->Maximized = + (wp.showCmd == SW_MAXIMIZE || (wp.showCmd == SW_SHOWMINIMIZED && (wp.flags & WPF_RESTORETOMAXIMIZED))); } - if (RegKey.Create(HKEY_CURRENT_USER, L"Software\\ReactOS\\rapps", NULL, - REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, NULL) != ERROR_SUCCESS) + if (RegKey.Create( + HKEY_CURRENT_USER, L"Software\\ReactOS\\rapps", NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, NULL) != + ERROR_SUCCESS) { return FALSE; } diff --git a/base/applications/rapps/settingsdlg.cpp b/base/applications/rapps/settingsdlg.cpp index 8fda86e9ca404..c7db4c7c5dd9f 100644 --- a/base/applications/rapps/settingsdlg.cpp +++ b/base/applications/rapps/settingsdlg.cpp @@ -9,23 +9,25 @@ SETTINGS_INFO NewSettingsInfo; -BOOL ChooseFolder(HWND hwnd) +BOOL +ChooseFolder(HWND hwnd) { BOOL bRet = FALSE; BROWSEINFOW bi; - ATL::CStringW szChooseFolderText; + CStringW szChooseFolderText; szChooseFolderText.LoadStringW(IDS_CHOOSE_FOLDER_TEXT); ZeroMemory(&bi, sizeof(bi)); bi.hwndOwner = hwnd; bi.pidlRoot = NULL; - bi.lpszTitle = szChooseFolderText.GetString(); - bi.ulFlags = BIF_USENEWUI | BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | /* BIF_BROWSEFILEJUNCTIONS | */ BIF_VALIDATE; + bi.lpszTitle = szChooseFolderText; + bi.ulFlags = + BIF_USENEWUI | BIF_DONTGOBELOWDOMAIN | BIF_RETURNONLYFSDIRS | /* BIF_BROWSEFILEJUNCTIONS | */ BIF_VALIDATE; if (SUCCEEDED(CoInitializeEx(NULL, COINIT_APARTMENTTHREADED))) { - ATL::CStringW szBuf; + CStringW szBuf; LPITEMIDLIST lpItemList = SHBrowseForFolderW(&bi); if (lpItemList && SHGetPathFromIDListW(lpItemList, szBuf.GetBuffer(MAX_PATH))) @@ -33,7 +35,7 @@ BOOL ChooseFolder(HWND hwnd) szBuf.ReleaseBuffer(); if (!szBuf.IsEmpty()) { - SetDlgItemTextW(hwnd, IDC_DOWNLOAD_DIR_EDIT, szBuf.GetString()); + SetDlgItemTextW(hwnd, IDC_DOWNLOAD_DIR_EDIT, szBuf); bRet = TRUE; } } @@ -49,25 +51,26 @@ BOOL ChooseFolder(HWND hwnd) return bRet; } -BOOL IsUrlValid(const WCHAR * Url) +BOOL +IsUrlValid(const WCHAR *Url) { - URL_COMPONENTSW UrlComponmentInfo = { 0 }; + URL_COMPONENTSW UrlComponmentInfo = {0}; UrlComponmentInfo.dwStructSize = sizeof(UrlComponmentInfo); UrlComponmentInfo.dwSchemeLength = 1; BOOL bSuccess = InternetCrackUrlW(Url, wcslen(Url), 0, &UrlComponmentInfo); - if(!bSuccess) + if (!bSuccess) { return FALSE; } - switch(UrlComponmentInfo.nScheme) + switch (UrlComponmentInfo.nScheme) { case INTERNET_SCHEME_HTTP: case INTERNET_SCHEME_HTTPS: case INTERNET_SCHEME_FTP: case INTERNET_SCHEME_FILE: - // supported + // supported return TRUE; default: @@ -77,47 +80,49 @@ BOOL IsUrlValid(const WCHAR * Url) namespace { - inline BOOL IsCheckedDlgItem(HWND hDlg, INT nIDDlgItem) - { - return (SendDlgItemMessageW(hDlg, nIDDlgItem, BM_GETCHECK, 0, 0) == BST_CHECKED) ? TRUE : FALSE; - } +inline BOOL +IsCheckedDlgItem(HWND hDlg, INT nIDDlgItem) +{ + return (SendDlgItemMessageW(hDlg, nIDDlgItem, BM_GETCHECK, 0, 0) == BST_CHECKED) ? TRUE : FALSE; +} - VOID InitSettingsControls(HWND hDlg, PSETTINGS_INFO Info) - { - SendDlgItemMessageW(hDlg, IDC_SAVE_WINDOW_POS, BM_SETCHECK, Info->bSaveWndPos, 0); - SendDlgItemMessageW(hDlg, IDC_UPDATE_AVLIST, BM_SETCHECK, Info->bUpdateAtStart, 0); - SendDlgItemMessageW(hDlg, IDC_LOG_ENABLED, BM_SETCHECK, Info->bLogEnabled, 0); - SendDlgItemMessageW(hDlg, IDC_DEL_AFTER_INSTALL, BM_SETCHECK, Info->bDelInstaller, 0); +VOID +InitSettingsControls(HWND hDlg, PSETTINGS_INFO Info) +{ + SendDlgItemMessageW(hDlg, IDC_SAVE_WINDOW_POS, BM_SETCHECK, Info->bSaveWndPos, 0); + SendDlgItemMessageW(hDlg, IDC_UPDATE_AVLIST, BM_SETCHECK, Info->bUpdateAtStart, 0); + SendDlgItemMessageW(hDlg, IDC_LOG_ENABLED, BM_SETCHECK, Info->bLogEnabled, 0); + SendDlgItemMessageW(hDlg, IDC_DEL_AFTER_INSTALL, BM_SETCHECK, Info->bDelInstaller, 0); - SetWindowTextW(GetDlgItem(hDlg, IDC_DOWNLOAD_DIR_EDIT), - Info->szDownloadDir); + SetWindowTextW(GetDlgItem(hDlg, IDC_DOWNLOAD_DIR_EDIT), Info->szDownloadDir); - CheckRadioButton(hDlg, IDC_PROXY_DEFAULT, IDC_USE_PROXY, IDC_PROXY_DEFAULT + Info->Proxy); + CheckRadioButton(hDlg, IDC_PROXY_DEFAULT, IDC_USE_PROXY, IDC_PROXY_DEFAULT + Info->Proxy); - if (Info->Proxy == 2) - { - EnableWindow(GetDlgItem(hDlg, IDC_PROXY_SERVER), TRUE); - EnableWindow(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), TRUE); - } - else - { - EnableWindow(GetDlgItem(hDlg, IDC_PROXY_SERVER), FALSE); - EnableWindow(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), FALSE); - } + if (Info->Proxy == 2) + { + EnableWindow(GetDlgItem(hDlg, IDC_PROXY_SERVER), TRUE); + EnableWindow(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), TRUE); + } + else + { + EnableWindow(GetDlgItem(hDlg, IDC_PROXY_SERVER), FALSE); + EnableWindow(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), FALSE); + } - CheckRadioButton(hDlg, IDC_SOURCE_DEFAULT, IDC_USE_SOURCE, Info->bUseSource ? IDC_USE_SOURCE : IDC_SOURCE_DEFAULT); + CheckRadioButton(hDlg, IDC_SOURCE_DEFAULT, IDC_USE_SOURCE, Info->bUseSource ? IDC_USE_SOURCE : IDC_SOURCE_DEFAULT); - EnableWindow(GetDlgItem(hDlg, IDC_SOURCE_URL), Info->bUseSource); + EnableWindow(GetDlgItem(hDlg, IDC_SOURCE_URL), Info->bUseSource); - SetWindowTextW(GetDlgItem(hDlg, IDC_SOURCE_URL), Info->szSourceURL); - SetWindowTextW(GetDlgItem(hDlg, IDC_PROXY_SERVER), Info->szProxyServer); - SetWindowTextW(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), Info->szNoProxyFor); - } + SetWindowTextW(GetDlgItem(hDlg, IDC_SOURCE_URL), Info->szSourceURL); + SetWindowTextW(GetDlgItem(hDlg, IDC_PROXY_SERVER), Info->szProxyServer); + SetWindowTextW(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), Info->szNoProxyFor); +} - INT_PTR CALLBACK SettingsDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam) +INT_PTR CALLBACK +SettingsDlgProc(HWND hDlg, UINT Msg, WPARAM wParam, LPARAM lParam) +{ + switch (Msg) { - switch (Msg) - { case WM_INITDIALOG: { NewSettingsInfo = SettingsInfo; @@ -129,159 +134,149 @@ namespace { switch (LOWORD(wParam)) { - case IDC_CHOOSE: - ChooseFolder(hDlg); - break; + case IDC_CHOOSE: + ChooseFolder(hDlg); + break; - case IDC_SAVE_WINDOW_POS: - NewSettingsInfo.bSaveWndPos = IsCheckedDlgItem(hDlg, IDC_SAVE_WINDOW_POS); - break; + case IDC_SAVE_WINDOW_POS: + NewSettingsInfo.bSaveWndPos = IsCheckedDlgItem(hDlg, IDC_SAVE_WINDOW_POS); + break; - case IDC_UPDATE_AVLIST: - NewSettingsInfo.bUpdateAtStart = IsCheckedDlgItem(hDlg, IDC_UPDATE_AVLIST); - break; + case IDC_UPDATE_AVLIST: + NewSettingsInfo.bUpdateAtStart = IsCheckedDlgItem(hDlg, IDC_UPDATE_AVLIST); + break; - case IDC_LOG_ENABLED: - NewSettingsInfo.bLogEnabled = IsCheckedDlgItem(hDlg, IDC_LOG_ENABLED); - break; + case IDC_LOG_ENABLED: + NewSettingsInfo.bLogEnabled = IsCheckedDlgItem(hDlg, IDC_LOG_ENABLED); + break; - case IDC_DEL_AFTER_INSTALL: - NewSettingsInfo.bDelInstaller = IsCheckedDlgItem(hDlg, IDC_DEL_AFTER_INSTALL); - break; + case IDC_DEL_AFTER_INSTALL: + NewSettingsInfo.bDelInstaller = IsCheckedDlgItem(hDlg, IDC_DEL_AFTER_INSTALL); + break; - case IDC_SOURCE_DEFAULT: - NewSettingsInfo.bUseSource = FALSE; - EnableWindow(GetDlgItem(hDlg, IDC_SOURCE_URL), NewSettingsInfo.bUseSource); - break; + case IDC_SOURCE_DEFAULT: + NewSettingsInfo.bUseSource = FALSE; + EnableWindow(GetDlgItem(hDlg, IDC_SOURCE_URL), NewSettingsInfo.bUseSource); + break; - case IDC_USE_SOURCE: - NewSettingsInfo.bUseSource = TRUE; - EnableWindow(GetDlgItem(hDlg, IDC_SOURCE_URL), NewSettingsInfo.bUseSource); - break; + case IDC_USE_SOURCE: + NewSettingsInfo.bUseSource = TRUE; + EnableWindow(GetDlgItem(hDlg, IDC_SOURCE_URL), NewSettingsInfo.bUseSource); + break; - case IDC_PROXY_DEFAULT: - NewSettingsInfo.Proxy = 0; - EnableWindow(GetDlgItem(hDlg, IDC_PROXY_SERVER), FALSE); - EnableWindow(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), FALSE); - break; + case IDC_PROXY_DEFAULT: + NewSettingsInfo.Proxy = 0; + EnableWindow(GetDlgItem(hDlg, IDC_PROXY_SERVER), FALSE); + EnableWindow(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), FALSE); + break; - case IDC_NO_PROXY: - NewSettingsInfo.Proxy = 1; - EnableWindow(GetDlgItem(hDlg, IDC_PROXY_SERVER), FALSE); - EnableWindow(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), FALSE); - break; + case IDC_NO_PROXY: + NewSettingsInfo.Proxy = 1; + EnableWindow(GetDlgItem(hDlg, IDC_PROXY_SERVER), FALSE); + EnableWindow(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), FALSE); + break; - case IDC_USE_PROXY: - NewSettingsInfo.Proxy = 2; - EnableWindow(GetDlgItem(hDlg, IDC_PROXY_SERVER), TRUE); - EnableWindow(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), TRUE); - break; + case IDC_USE_PROXY: + NewSettingsInfo.Proxy = 2; + EnableWindow(GetDlgItem(hDlg, IDC_PROXY_SERVER), TRUE); + EnableWindow(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), TRUE); + break; - case IDC_DEFAULT_SETTINGS: - FillDefaultSettings(&NewSettingsInfo); - InitSettingsControls(hDlg, &NewSettingsInfo); - break; + case IDC_DEFAULT_SETTINGS: + FillDefaultSettings(&NewSettingsInfo); + InitSettingsControls(hDlg, &NewSettingsInfo); + break; - case IDOK: - { - ATL::CStringW szDir; - ATL::CStringW szSource; - ATL::CStringW szProxy; - ATL::CStringW szNoProxy; - DWORD dwAttr; - - GetWindowTextW(GetDlgItem(hDlg, IDC_DOWNLOAD_DIR_EDIT), - szDir.GetBuffer(MAX_PATH), MAX_PATH); - szDir.ReleaseBuffer(); - - GetWindowTextW(GetDlgItem(hDlg, IDC_SOURCE_URL), - szSource.GetBuffer(INTERNET_MAX_URL_LENGTH), INTERNET_MAX_URL_LENGTH); - szSource.ReleaseBuffer(); - - GetWindowTextW(GetDlgItem(hDlg, IDC_PROXY_SERVER), - szProxy.GetBuffer(MAX_PATH), MAX_PATH); - szProxy.ReleaseBuffer(); - ATL::CStringW::CopyChars(NewSettingsInfo.szProxyServer, - _countof(NewSettingsInfo.szProxyServer), - szProxy.GetString(), - szProxy.GetLength() + 1); - - GetWindowTextW(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), - szNoProxy.GetBuffer(MAX_PATH), MAX_PATH); - szNoProxy.ReleaseBuffer(); - ATL::CStringW::CopyChars(NewSettingsInfo.szNoProxyFor, - _countof(NewSettingsInfo.szNoProxyFor), - szNoProxy.GetString(), - szNoProxy.GetLength() + 1); - - dwAttr = GetFileAttributesW(szDir.GetString()); - if (dwAttr != INVALID_FILE_ATTRIBUTES && - (dwAttr & FILE_ATTRIBUTE_DIRECTORY)) + case IDOK: { - ATL::CStringW::CopyChars(NewSettingsInfo.szDownloadDir, - _countof(NewSettingsInfo.szDownloadDir), - szDir.GetString(), - szDir.GetLength() + 1); - } - else - { - ATL::CStringW szMsgText; - szMsgText.LoadStringW(IDS_CHOOSE_FOLDER_ERROR); - - if (MessageBoxW(hDlg, szMsgText.GetString(), NULL, MB_YESNO) == IDYES) + CStringW szDir; + CStringW szSource; + CStringW szProxy; + CStringW szNoProxy; + DWORD dwAttr; + + GetWindowTextW(GetDlgItem(hDlg, IDC_DOWNLOAD_DIR_EDIT), szDir.GetBuffer(MAX_PATH), MAX_PATH); + szDir.ReleaseBuffer(); + + GetWindowTextW( + GetDlgItem(hDlg, IDC_SOURCE_URL), szSource.GetBuffer(INTERNET_MAX_URL_LENGTH), + INTERNET_MAX_URL_LENGTH); + szSource.ReleaseBuffer(); + + GetWindowTextW(GetDlgItem(hDlg, IDC_PROXY_SERVER), szProxy.GetBuffer(MAX_PATH), MAX_PATH); + szProxy.ReleaseBuffer(); + CStringW::CopyChars( + NewSettingsInfo.szProxyServer, _countof(NewSettingsInfo.szProxyServer), szProxy, + szProxy.GetLength() + 1); + + GetWindowTextW(GetDlgItem(hDlg, IDC_NO_PROXY_FOR), szNoProxy.GetBuffer(MAX_PATH), MAX_PATH); + szNoProxy.ReleaseBuffer(); + CStringW::CopyChars( + NewSettingsInfo.szNoProxyFor, _countof(NewSettingsInfo.szNoProxyFor), szNoProxy, + szNoProxy.GetLength() + 1); + + dwAttr = GetFileAttributesW(szDir); + if (dwAttr != INVALID_FILE_ATTRIBUTES && (dwAttr & FILE_ATTRIBUTE_DIRECTORY)) { - if (CreateDirectoryW(szDir.GetString(), NULL)) - { - EndDialog(hDlg, LOWORD(wParam)); - } + CStringW::CopyChars( + NewSettingsInfo.szDownloadDir, _countof(NewSettingsInfo.szDownloadDir), szDir, + szDir.GetLength() + 1); } else { - SetFocus(GetDlgItem(hDlg, IDC_DOWNLOAD_DIR_EDIT)); - break; + CStringW szMsgText; + szMsgText.LoadStringW(IDS_CHOOSE_FOLDER_ERROR); + + if (MessageBoxW(hDlg, szMsgText, NULL, MB_YESNO) == IDYES) + { + if (CreateDirectoryW(szDir, NULL)) + { + EndDialog(hDlg, LOWORD(wParam)); + } + } + else + { + SetFocus(GetDlgItem(hDlg, IDC_DOWNLOAD_DIR_EDIT)); + break; + } } - } + if (NewSettingsInfo.bUseSource && !IsUrlValid(szSource)) + { + CStringW szMsgText; + szMsgText.LoadStringW(IDS_URL_INVALID); - if(NewSettingsInfo.bUseSource && !IsUrlValid(szSource.GetString())) - { - ATL::CStringW szMsgText; - szMsgText.LoadStringW(IDS_URL_INVALID); + MessageBoxW(hDlg, szMsgText, NULL, 0); + SetFocus(GetDlgItem(hDlg, IDC_SOURCE_URL)); + break; + } + else + { + CStringW::CopyChars( + NewSettingsInfo.szSourceURL, _countof(NewSettingsInfo.szSourceURL), szSource, + szSource.GetLength() + 1); + } - MessageBoxW(hDlg, szMsgText.GetString(), NULL, 0); - SetFocus(GetDlgItem(hDlg, IDC_SOURCE_URL)); - break; - } - else - { - ATL::CStringW::CopyChars(NewSettingsInfo.szSourceURL, - _countof(NewSettingsInfo.szSourceURL), - szSource.GetString(), - szSource.GetLength() + 1); + SettingsInfo = NewSettingsInfo; + SaveSettings(GetParent(hDlg), &SettingsInfo); + EndDialog(hDlg, LOWORD(wParam)); } - - SettingsInfo = NewSettingsInfo; - SaveSettings(GetParent(hDlg), &SettingsInfo); - EndDialog(hDlg, LOWORD(wParam)); - } - break; - - case IDCANCEL: - EndDialog(hDlg, LOWORD(wParam)); break; + + case IDCANCEL: + EndDialog(hDlg, LOWORD(wParam)); + break; } } break; - } - - return FALSE; } + + return FALSE; } +} // namespace -VOID CreateSettingsDlg(HWND hwnd) +VOID +CreateSettingsDlg(HWND hwnd) { - DialogBoxW(hInst, - MAKEINTRESOURCEW(IDD_SETTINGS_DIALOG), - hwnd, - SettingsDlgProc); + DialogBoxW(hInst, MAKEINTRESOURCEW(IDD_SETTINGS_DIALOG), hwnd, SettingsDlgProc); } diff --git a/base/applications/rapps/unattended.cpp b/base/applications/rapps/unattended.cpp index 885c604fd5e7c..858f24ee23b88 100644 --- a/base/applications/rapps/unattended.cpp +++ b/base/applications/rapps/unattended.cpp @@ -12,9 +12,10 @@ #include #include -BOOL MatchCmdOption(LPWSTR argvOption, LPCWSTR szOptToMacth) +static BOOL +MatchCmdOption(LPWSTR argvOption, LPCWSTR szOptToMacth) { - WCHAR FirstCharList[] = { L'-', L'/' }; + WCHAR FirstCharList[] = {L'-', L'/'}; for (UINT i = 0; i < _countof(FirstCharList); i++) { @@ -26,7 +27,8 @@ BOOL MatchCmdOption(LPWSTR argvOption, LPCWSTR szOptToMacth) return FALSE; } -void InitRappsConsole() +static void +InitRappsConsole() { // First, try to attach to our parent's console if (!AttachConsole(ATTACH_PARENT_PROCESS)) @@ -41,40 +43,32 @@ void InitRappsConsole() ConInitStdStreams(); // Initialize the Console Standard Streams } - -BOOL HandleInstallCommand(LPWSTR szCommand, int argcLeft, LPWSTR * argvLeft) +static BOOL +HandleInstallCommand(CApplicationDB *db, LPWSTR szCommand, int argcLeft, LPWSTR *argvLeft) { - if (argcLeft == 0) + if (argcLeft < 1) { InitRappsConsole(); ConResMsgPrintf(StdOut, NULL, IDS_CMD_NEED_PACKAGE_NAME, szCommand); return FALSE; } - ATL::CSimpleArray PkgNameList; - + CAtlList Applications; for (int i = 0; i < argcLeft; i++) { - PkgNameList.Add(argvLeft[i]); + LPCWSTR PackageName = argvLeft[i]; + CApplicationInfo *AppInfo = db->FindByPackageName(PackageName); + if (AppInfo) + { + Applications.AddTail(AppInfo); + } } - CAvailableApps apps; - apps.UpdateAppsDB(); - apps.Enum(ENUM_ALL_AVAILABLE, NULL, NULL); - - ATL::CSimpleArray arrAppInfo = apps.FindAppsByPkgNameList(PkgNameList); - if (arrAppInfo.GetSize() > 0) - { - DownloadListOfApplications(arrAppInfo, TRUE); - return TRUE; - } - else - { - return FALSE; - } + return DownloadListOfApplications(Applications, TRUE); } -BOOL HandleSetupCommand(LPWSTR szCommand, int argcLeft, LPWSTR * argvLeft) +static BOOL +HandleSetupCommand(CApplicationDB *db, LPWSTR szCommand, int argcLeft, LPWSTR *argvLeft) { if (argcLeft != 1) { @@ -83,7 +77,7 @@ BOOL HandleSetupCommand(LPWSTR szCommand, int argcLeft, LPWSTR * argvLeft) return FALSE; } - ATL::CSimpleArray PkgNameList; + CAtlList Applications; HINF InfHandle = SetupOpenInfFileW(argvLeft[0], NULL, INF_STYLE_WIN4, NULL); if (InfHandle == INVALID_HANDLE_VALUE) { @@ -98,42 +92,21 @@ BOOL HandleSetupCommand(LPWSTR szCommand, int argcLeft, LPWSTR * argvLeft) { if (SetupGetStringFieldW(&Context, 1, szPkgName, _countof(szPkgName), NULL)) { - PkgNameList.Add(szPkgName); + CApplicationInfo *AppInfo = db->FindByPackageName(szPkgName); + if (AppInfo) + { + Applications.AddTail(AppInfo); + } } } while (SetupFindNextLine(&Context, &Context)); } SetupCloseInfFile(InfHandle); - CAvailableApps apps; - apps.UpdateAppsDB(); - apps.Enum(ENUM_ALL_AVAILABLE, NULL, NULL); - - ATL::CSimpleArray arrAppInfo = apps.FindAppsByPkgNameList(PkgNameList); - if (arrAppInfo.GetSize() > 0) - { - DownloadListOfApplications(arrAppInfo, TRUE); - return TRUE; - } - else - { - return FALSE; - } + return DownloadListOfApplications(Applications, TRUE); } -BOOL CALLBACK CmdFindAppEnum(CAvailableApplicationInfo *Info, BOOL bInitialCheckState, PVOID param) -{ - LPCWSTR lpszSearch = (LPCWSTR)param; - if (!SearchPatternMatch(Info->m_szName, lpszSearch) && - !SearchPatternMatch(Info->m_szDesc, lpszSearch)) - { - return TRUE; - } - - ConPrintf(StdOut, L"%s (%s)\n", Info->m_szName.GetString(), Info->m_szPkgName.GetString()); - return TRUE; -} - -BOOL HandleFindCommand(LPWSTR szCommand, int argcLeft, LPWSTR *argvLeft) +static BOOL +HandleFindCommand(CApplicationDB *db, LPWSTR szCommand, int argcLeft, LPWSTR *argvLeft) { if (argcLeft < 1) { @@ -141,20 +114,33 @@ BOOL HandleFindCommand(LPWSTR szCommand, int argcLeft, LPWSTR *argvLeft) return FALSE; } - CAvailableApps apps; - apps.UpdateAppsDB(); + CAtlList List; + db->GetApps(List, ENUM_ALL_AVAILABLE); for (int i = 0; i < argcLeft; i++) { - ConResMsgPrintf(StdOut, NULL, IDS_CMD_FIND_RESULT_FOR, argvLeft[i]); - apps.Enum(ENUM_ALL_AVAILABLE, CmdFindAppEnum, argvLeft[i]); + LPCWSTR lpszSearch = argvLeft[i]; + ConResMsgPrintf(StdOut, NULL, IDS_CMD_FIND_RESULT_FOR, lpszSearch); + + POSITION CurrentListPosition = List.GetHeadPosition(); + while (CurrentListPosition) + { + CApplicationInfo *Info = List.GetNext(CurrentListPosition); + + if (SearchPatternMatch(Info->szDisplayName, lpszSearch) || SearchPatternMatch(Info->szComments, lpszSearch)) + { + ConPrintf(StdOut, L"%s (%s)\n", Info->szDisplayName.GetString(), Info->szIdentifier.GetString()); + } + } + ConPrintf(StdOut, L"\n"); } return TRUE; } -BOOL HandleInfoCommand(LPWSTR szCommand, int argcLeft, LPWSTR *argvLeft) +static BOOL +HandleInfoCommand(CApplicationDB *db, LPWSTR szCommand, int argcLeft, LPWSTR *argvLeft) { if (argcLeft < 1) { @@ -162,70 +148,67 @@ BOOL HandleInfoCommand(LPWSTR szCommand, int argcLeft, LPWSTR *argvLeft) return FALSE; } - CAvailableApps apps; - apps.UpdateAppsDB(); - apps.Enum(ENUM_ALL_AVAILABLE, NULL, NULL); - for (int i = 0; i < argcLeft; i++) { - CAvailableApplicationInfo *AppInfo = apps.FindAppByPkgName(argvLeft[i]); + LPCWSTR PackageName = argvLeft[i]; + CApplicationInfo *AppInfo = db->FindByPackageName(PackageName); if (!AppInfo) { - ConResMsgPrintf(StdOut, NULL, IDS_CMD_PACKAGE_NOT_FOUND, argvLeft[i]); + ConResMsgPrintf(StdOut, NULL, IDS_CMD_PACKAGE_NOT_FOUND, PackageName); } else { - ConResMsgPrintf(StdOut, NULL, IDS_CMD_PACKAGE_INFO, argvLeft[i]); - // TODO: code about extracting information from CAvailableApplicationInfo (in appview.cpp, class CAppRichEdit) - // is in a mess. It should be refactored, and should not placed in class CAppRichEdit. - // and the code here should reused that code after refactor. + ConResMsgPrintf(StdOut, NULL, IDS_CMD_PACKAGE_INFO, PackageName); - ConPuts(StdOut, AppInfo->m_szName); + ConPuts(StdOut, AppInfo->szDisplayName); - if (AppInfo->m_szVersion) + if (!AppInfo->szDisplayVersion.IsEmpty()) { ConResPrintf(StdOut, IDS_AINFO_VERSION); - ConPuts(StdOut, AppInfo->m_szVersion); + ConPuts(StdOut, AppInfo->szDisplayVersion); } - if (AppInfo->m_szLicense) + CStringW License, Size, UrlSite, UrlDownload; + AppInfo->GetDisplayInfo(License, Size, UrlSite, UrlDownload); + + if (!License.IsEmpty()) { ConResPrintf(StdOut, IDS_AINFO_LICENSE); - ConPuts(StdOut, AppInfo->m_szLicense); + ConPuts(StdOut, License); } - if (AppInfo->m_szSize) + if (!Size.IsEmpty()) { ConResPrintf(StdOut, IDS_AINFO_SIZE); - ConPuts(StdOut, AppInfo->m_szSize); + ConPuts(StdOut, Size); } - if (AppInfo->m_szUrlSite) + if (!UrlSite.IsEmpty()) { ConResPrintf(StdOut, IDS_AINFO_URLSITE); - ConPuts(StdOut, AppInfo->m_szUrlSite); + ConPuts(StdOut, UrlSite); } - if (AppInfo->m_szDesc) + if (AppInfo->szComments) { ConResPrintf(StdOut, IDS_AINFO_DESCRIPTION); - ConPuts(StdOut, AppInfo->m_szDesc); + ConPuts(StdOut, AppInfo->szComments); } - if (AppInfo->m_szUrlDownload) + if (!UrlDownload.IsEmpty()) { ConResPrintf(StdOut, IDS_AINFO_URLDOWNLOAD); - ConPuts(StdOut, AppInfo->m_szUrlDownload); + ConPuts(StdOut, UrlDownload); } - - ConPrintf(StdOut, L"\n"); + ConPuts(StdOut, L"\n"); } - ConPrintf(StdOut, L"\n"); + ConPuts(StdOut, L"\n"); } return TRUE; } -VOID PrintHelpCommand() +static VOID +PrintHelpCommand() { ConPrintf(StdOut, L"\n"); ConResPuts(StdOut, IDS_APPTITLE); @@ -235,7 +218,8 @@ VOID PrintHelpCommand() ConPrintf(StdOut, L"%ls\n", UsageString); } -BOOL ParseCmdAndExecute(LPWSTR lpCmdLine, BOOL bIsFirstLaunch, int nCmdShow) +BOOL +ParseCmdAndExecute(LPWSTR lpCmdLine, BOOL bIsFirstLaunch, int nCmdShow) { INT argc; LPWSTR *argv = CommandLineToArgvW(lpCmdLine, &argc); @@ -245,6 +229,17 @@ BOOL ParseCmdAndExecute(LPWSTR lpCmdLine, BOOL bIsFirstLaunch, int nCmdShow) return FALSE; } + CStringW Directory; + GetStorageDirectory(Directory); + CApplicationDB db(Directory); + + if (SettingsInfo.bUpdateAtStart || bIsFirstLaunch) + { + db.RemoveCached(); + } + db.UpdateAvailable(); + db.UpdateInstalled(); + if (argc == 1) // RAPPS is launched without options { // Check for if rapps MainWindow is already launched in another process @@ -262,10 +257,7 @@ BOOL ParseCmdAndExecute(LPWSTR lpCmdLine, BOOL bIsFirstLaunch, int nCmdShow) return FALSE; } - if (SettingsInfo.bUpdateAtStart || bIsFirstLaunch) - CAvailableApps::ForceUpdateAppsDB(); - - MainWindowLoop(nCmdShow); + MainWindowLoop(&db, nCmdShow); if (hMutex) CloseHandle(hMutex); @@ -275,22 +267,22 @@ BOOL ParseCmdAndExecute(LPWSTR lpCmdLine, BOOL bIsFirstLaunch, int nCmdShow) if (MatchCmdOption(argv[1], CMD_KEY_INSTALL)) { - return HandleInstallCommand(argv[1], argc - 2, argv + 2); + return HandleInstallCommand(&db, argv[1], argc - 2, argv + 2); } else if (MatchCmdOption(argv[1], CMD_KEY_SETUP)) { - return HandleSetupCommand(argv[1], argc - 2, argv + 2); + return HandleSetupCommand(&db, argv[1], argc - 2, argv + 2); } InitRappsConsole(); if (MatchCmdOption(argv[1], CMD_KEY_FIND)) { - return HandleFindCommand(argv[1], argc - 2, argv + 2); + return HandleFindCommand(&db, argv[1], argc - 2, argv + 2); } else if (MatchCmdOption(argv[1], CMD_KEY_INFO)) { - return HandleInfoCommand(argv[1], argc - 2, argv + 2); + return HandleInfoCommand(&db, argv[1], argc - 2, argv + 2); } else if (MatchCmdOption(argv[1], CMD_KEY_HELP) || MatchCmdOption(argv[1], CMD_KEY_HELP_ALT)) { diff --git a/base/applications/rapps/winmain.cpp b/base/applications/rapps/winmain.cpp index cd2d82302b1d7..cf3285a278339 100644 --- a/base/applications/rapps/winmain.cpp +++ b/base/applications/rapps/winmain.cpp @@ -13,7 +13,7 @@ #include #include -LPCWSTR szWindowClass = L"ROSAPPMGR"; +LPCWSTR szWindowClass = L"ROSAPPMGR2"; HWND hMainWnd; HINSTANCE hInst; @@ -25,8 +25,8 @@ END_OBJECT_MAP() CComModule gModule; CAtlWinModule gWinModule; - -INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nShowCmd) +INT WINAPI +wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, INT nShowCmd) { Gdiplus::GdiplusStartupInput gdiplusStartupInput; ULONG_PTR gdiplusToken;