From 9b8d86858f555878ad93de2bf5311f69b1e623d2 Mon Sep 17 00:00:00 2001 From: seraphima Date: Fri, 28 Jun 2024 14:49:20 +0200 Subject: [PATCH] logs --- .../Projects/projects-common/AppUtils.h | 49 ++++++++++++------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/src/modules/Projects/projects-common/AppUtils.h b/src/modules/Projects/projects-common/AppUtils.h index 10921a52dc..8135bb375b 100644 --- a/src/modules/Projects/projects-common/AppUtils.h +++ b/src/modules/Projects/projects-common/AppUtils.h @@ -1,13 +1,14 @@ #pragma once -#include #include #include #include #include +#include #include +#include namespace Utils { @@ -41,6 +42,7 @@ namespace Utils HRESULT hr = SHGetKnownFolderItem(FOLDERID_AppsFolder, KF_FLAG_DEFAULT, nullptr, IID_PPV_ARGS(&folder)); if (FAILED(hr)) { + Logger::error(L"Failed to get known apps folder: {}", get_last_error_or_default(hr)); return result; } @@ -48,6 +50,7 @@ namespace Utils hr = folder->BindToHandler(nullptr, BHID_EnumItems, IID_PPV_ARGS(&enumItems)); if (FAILED(hr)) { + Logger::error(L"Failed to bind to enum items handler: {}", get_last_error_or_default(hr)); return result; } @@ -57,8 +60,10 @@ namespace Utils CComPtr item = items; CComHeapPtr name; - if (FAILED(item->GetDisplayName(SIGDN_NORMALDISPLAY, &name))) + hr = item->GetDisplayName(SIGDN_NORMALDISPLAY, &name); + if (FAILED(hr)) { + Logger::error(L"Failed to get display name for app: {}", get_last_error_or_default(hr)); continue; } @@ -68,8 +73,10 @@ namespace Utils // properties CComPtr store; - if (FAILED(item->BindToHandler(NULL, BHID_PropertyStore, IID_PPV_ARGS(&store)))) + hr = item->BindToHandler(NULL, BHID_PropertyStore, IID_PPV_ARGS(&store)); + if (FAILED(hr)) { + Logger::error(L"Failed to bind to property store handler: {}", get_last_error_or_default(hr)); continue; } @@ -78,8 +85,10 @@ namespace Utils for (DWORD i = 0; i < count; i++) { PROPERTYKEY pk; - if (FAILED(store->GetAt(i, &pk))) + hr = store->GetAt(i, &pk); + if (FAILED(hr)) { + Logger::error(L"Failed to get property key: {}", get_last_error_or_default(hr)); continue; } @@ -93,7 +102,8 @@ namespace Utils { PROPVARIANT pv; PropVariantInit(&pv); - if (SUCCEEDED(store->GetValue(pk, &pv))) + hr = store->GetValue(pk, &pv); + if (SUCCEEDED(hr)) { CComHeapPtr propVariantString; propVariantString.Allocate(512); @@ -109,6 +119,10 @@ namespace Utils data.installPath = propVariantString.m_pData; } } + else + { + Logger::error(L"Failed to get property value: {}", get_last_error_or_default(hr)); + } if (!data.packageFullName.empty() && !data.installPath.empty()) { @@ -133,20 +147,20 @@ namespace Utils inline std::optional GetApp(const std::wstring& appPath, const AppList& apps) { + std::wstring appPathUpper(appPath); + std::transform(appPathUpper.begin(), appPathUpper.end(), appPathUpper.begin(), towupper); + + // edge case, "Windows Software Development Kit" has the same app path as "File Explorer" + if (appPathUpper == NonLocalizable::FileExplorerPath) + { + return AppData{ + .name = NonLocalizable::FileExplorerName, + .installPath = appPath, + }; + } + for (const auto& appData : apps) { - std::wstring appPathUpper(appPath); - std::transform(appPathUpper.begin(), appPathUpper.end(), appPathUpper.begin(), towupper); - - // edge case, "Windows Software Development Kit" has the same app path as "File Explorer" - if (appPathUpper == NonLocalizable::FileExplorerPath) - { - return AppData{ - .name = NonLocalizable::FileExplorerName, - .installPath = appPath, - }; - } - if (!appData.installPath.empty()) { std::wstring installPathUpper(appData.installPath); @@ -166,7 +180,6 @@ namespace Utils } } - // TODO: not all installed apps found return AppData{ .installPath = appPath };