Skip to content

Commit 048b07c

Browse files
[Installer]Properly update CmdPal on upgrade (#38070)
* [Installer]Properly update CmdPal on upgrade * Update installer/PowerToysSetupCustomActions/CustomAction.cpp
1 parent 7575c04 commit 048b07c

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

installer/PowerToysSetup/Product.wxs

+11
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@
179179
<Custom Action="UnRegisterContextMenuPackages" Before="RemoveFiles">
180180
Installed AND (REMOVE="ALL")
181181
</Custom>
182+
<Custom Action="UnRegisterCmdPalPackage" Before="RemoveFiles">
183+
Installed AND (NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")
184+
</Custom>
182185
<Custom Action="UnsetAdvancedPasteAPIKey" Before="RemoveFiles">
183186
Installed AND (NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")
184187
</Custom>
@@ -439,6 +442,14 @@
439442
DllEntry="UnRegisterContextMenuPackagesCA"
440443
/>
441444

445+
<CustomAction Id="UnRegisterCmdPalPackage"
446+
Return="ignore"
447+
Impersonate="yes"
448+
Execute="deferred"
449+
BinaryKey="PTCustomActions"
450+
DllEntry="UnRegisterCmdPalPackageCA"
451+
/>
452+
442453
<CustomAction Id="CheckGPO"
443454
Return="check"
444455
Impersonate="yes"

installer/PowerToysSetupCustomActions/CustomAction.cpp

+36-1
Original file line numberDiff line numberDiff line change
@@ -1081,6 +1081,41 @@ UINT __stdcall InstallCmdPalPackageCA(MSIHANDLE hInstall)
10811081
return WcaFinalize(er);
10821082
}
10831083

1084+
UINT __stdcall UnRegisterCmdPalPackageCA(MSIHANDLE hInstall)
1085+
{
1086+
using namespace winrt::Windows::Foundation;
1087+
using namespace winrt::Windows::Management::Deployment;
1088+
1089+
HRESULT hr = S_OK;
1090+
UINT er = ERROR_SUCCESS;
1091+
1092+
hr = WcaInitialize(hInstall, "UnRegisterCmdPalPackageCA");
1093+
1094+
try
1095+
{
1096+
// Packages to unregister
1097+
std::wstring packageToRemoveDisplayName {L"Microsoft.CommandPalette"};
1098+
1099+
if (!package::UnRegisterPackage(packageToRemoveDisplayName))
1100+
{
1101+
Logger::error(L"Failed to unregister package: " + packageToRemoveDisplayName);
1102+
er = ERROR_INSTALL_FAILURE;
1103+
}
1104+
}
1105+
catch (std::exception &e)
1106+
{
1107+
std::string errorMessage{"Exception thrown while trying to unregister the CmdPal package: "};
1108+
errorMessage += e.what();
1109+
Logger::error(errorMessage);
1110+
1111+
er = ERROR_INSTALL_FAILURE;
1112+
}
1113+
1114+
er = er == ERROR_SUCCESS ? (SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE) : er;
1115+
return WcaFinalize(er);
1116+
}
1117+
1118+
10841119
UINT __stdcall UnRegisterContextMenuPackagesCA(MSIHANDLE hInstall)
10851120
{
10861121
using namespace winrt::Windows::Foundation;
@@ -1094,7 +1129,7 @@ UINT __stdcall UnRegisterContextMenuPackagesCA(MSIHANDLE hInstall)
10941129
try
10951130
{
10961131
// Packages to unregister
1097-
const std::vector<std::wstring> packagesToRemoveDisplayName{{L"PowerRenameContextMenu"}, {L"ImageResizerContextMenu"}, {L"FileLocksmithContextMenu"}, {L"NewPlusContextMenu"}, {L"Microsoft.CommandPalette"}};
1132+
const std::vector<std::wstring> packagesToRemoveDisplayName{{L"PowerRenameContextMenu"}, {L"ImageResizerContextMenu"}, {L"FileLocksmithContextMenu"}, {L"NewPlusContextMenu"}};
10981133

10991134
for (auto const &package : packagesToRemoveDisplayName)
11001135
{

installer/PowerToysSetupCustomActions/CustomAction.def

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ EXPORTS
2020
InstallDSCModuleCA
2121
InstallCmdPalPackageCA
2222
UnApplyModulesRegistryChangeSetsCA
23+
UnRegisterCmdPalPackageCA
2324
UnRegisterContextMenuPackagesCA
2425
UninstallEmbeddedMSIXCA
2526
UninstallDSCModuleCA

0 commit comments

Comments
 (0)