mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
fix update
This commit is contained in:
@@ -19,6 +19,10 @@ namespace registry
|
|||||||
namespace install_scope
|
namespace install_scope
|
||||||
{
|
{
|
||||||
const wchar_t INSTALL_SCOPE_REG_KEY[] = L"Software\\Classes\\powertoys\\";
|
const wchar_t INSTALL_SCOPE_REG_KEY[] = L"Software\\Classes\\powertoys\\";
|
||||||
|
const wchar_t UNINSTALL_REG_KEY[] = L"Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall";
|
||||||
|
|
||||||
|
// Bundle UpgradeCode from PowerToys.wxs
|
||||||
|
const wchar_t BUNDLE_UPGRADE_CODE[] = L"6341382d-c0a9-4238-9188-be9607e3fab2";
|
||||||
|
|
||||||
enum class InstallScope
|
enum class InstallScope
|
||||||
{
|
{
|
||||||
@@ -26,8 +30,67 @@ namespace registry
|
|||||||
PerUser,
|
PerUser,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Helper function to find PowerToys bundle in Windows Uninstall registry by BundleUpgradeCode
|
||||||
|
inline bool find_powertoys_bundle_in_uninstall_registry(HKEY rootKey)
|
||||||
|
{
|
||||||
|
HKEY uninstallKey{};
|
||||||
|
if (RegOpenKeyExW(rootKey, UNINSTALL_REG_KEY, 0, KEY_READ, &uninstallKey) != ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
detail::on_exit closeUninstallKey{ [uninstallKey] { RegCloseKey(uninstallKey); } };
|
||||||
|
|
||||||
|
DWORD index = 0;
|
||||||
|
wchar_t subKeyName[256];
|
||||||
|
|
||||||
|
// Enumerate all subkeys under Uninstall
|
||||||
|
while (RegEnumKeyW(uninstallKey, index++, subKeyName, 256) == ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
HKEY productKey{};
|
||||||
|
if (RegOpenKeyExW(uninstallKey, subKeyName, 0, KEY_READ, &productKey) != ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
detail::on_exit closeProductKey{ [productKey] { RegCloseKey(productKey); } };
|
||||||
|
|
||||||
|
// Check BundleUpgradeCode value (specific to WiX Bundle installations)
|
||||||
|
wchar_t bundleUpgradeCode[256]{};
|
||||||
|
DWORD bundleUpgradeCodeSize = sizeof(bundleUpgradeCode);
|
||||||
|
|
||||||
|
if (RegQueryValueExW(productKey, L"BundleUpgradeCode", nullptr, nullptr,
|
||||||
|
reinterpret_cast<LPBYTE>(bundleUpgradeCode), &bundleUpgradeCodeSize) == ERROR_SUCCESS)
|
||||||
|
{
|
||||||
|
if (_wcsicmp(bundleUpgradeCode, BUNDLE_UPGRADE_CODE) == 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
inline const InstallScope get_current_install_scope()
|
inline const InstallScope get_current_install_scope()
|
||||||
{
|
{
|
||||||
|
// 1. Check HKCU Uninstall registry first (user-level bundle)
|
||||||
|
// Note: MSI components are always in HKLM regardless of install scope,
|
||||||
|
// but the Bundle entry will be in HKCU for per-user installations
|
||||||
|
if (find_powertoys_bundle_in_uninstall_registry(HKEY_CURRENT_USER))
|
||||||
|
{
|
||||||
|
Logger::info(L"Found user-level PowerToys bundle via BundleUpgradeCode in HKCU");
|
||||||
|
return InstallScope::PerUser;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Check HKLM Uninstall registry (machine-level bundle)
|
||||||
|
if (find_powertoys_bundle_in_uninstall_registry(HKEY_LOCAL_MACHINE))
|
||||||
|
{
|
||||||
|
Logger::info(L"Found machine-level PowerToys bundle via BundleUpgradeCode in HKLM");
|
||||||
|
return InstallScope::PerMachine;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Fallback to legacy custom registry key detection
|
||||||
|
Logger::info(L"PowerToys bundle not found in Uninstall registry, falling back to legacy detection");
|
||||||
|
|
||||||
// Open HKLM key
|
// Open HKLM key
|
||||||
HKEY perMachineKey{};
|
HKEY perMachineKey{};
|
||||||
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
||||||
@@ -45,6 +108,7 @@ namespace registry
|
|||||||
&perUserKey) != ERROR_SUCCESS)
|
&perUserKey) != ERROR_SUCCESS)
|
||||||
{
|
{
|
||||||
// both keys are missing
|
// both keys are missing
|
||||||
|
Logger::warn(L"No PowerToys installation detected, defaulting to PerMachine");
|
||||||
return InstallScope::PerMachine;
|
return InstallScope::PerMachine;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user