Repository: microsoft/PowerToys
File: installer/PowerToysSetupCustomActions/CustomAction.cpp (C++)

Code before:
}

UINT __stdcall UnRegisterCmdPalPackageCA(MSIHANDLE hInstall)
{
    using namespace winrt::Windows::Foundation;
    using namespace winrt::Windows::Management::Deployment;

    HRESULT hr = S_OK;
    UINT er = ERROR_SUCCESS;

    hr = WcaInitialize(hInstall, "UnRegisterCmdPalPackageCA");

    try
    {
        // Packages to unregister
        std::wstring packageToRemoveDisplayName {L"Microsoft.CommandPalette"};

        if (!package::UnRegisterPackage(packageToRemoveDisplayName))
        {
            Logger::error(L"Failed to unregister package: " + packageToRemoveDisplayName);
            er = ERROR_INSTALL_FAILURE;
        }
    }
    catch (std::exception &e)
    {
        std::string errorMessage{"Exception thrown while trying to unregister packages: "};
        errorMessage += e.what();
        Logger::error(errorMessage);

        er = ERROR_INSTALL_FAILURE;
    }

    er = er == ERROR_SUCCESS ? (SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE) : er;
    return WcaFinalize(er);
}


UINT __stdcall UnRegisterContextMenuPackagesCA(MSIHANDLE hInstall)
{
    using namespace winrt::Windows::Foundation;
    using namespace winrt::Windows::Management::Deployment;

    HRESULT hr = S_OK;
    UINT er = ERROR_SUCCESS;

    hr = WcaInitialize(hInstall, "UnRegisterContextMenuPackagesCA"); // original func name is too long

    try
    {
        // Packages to unregister
        const std::vector<std::wstring> packagesToRemoveDisplayName{{L"PowerRenameContextMenu"}, {L"ImageResizerContextMenu"}, {L"FileLocksmithContextMenu"}, {L"NewPlusContextMenu"}};

Review comment (suggestion):
```suggestion
        std::string errorMessage{"Exception thrown while trying to unregister the CmdPal package: "};
```

Code after:
}

UINT __stdcall UnRegisterCmdPalPackageCA(MSIHANDLE hInstall)
{
    using namespace winrt::Windows::Foundation;
    using namespace winrt::Windows::Management::Deployment;

    HRESULT hr = S_OK;
    UINT er = ERROR_SUCCESS;

    hr = WcaInitialize(hInstall, "UnRegisterCmdPalPackageCA");

    try
    {
        // Packages to unregister
        std::wstring packageToRemoveDisplayName {L"Microsoft.CommandPalette"};

        if (!package::UnRegisterPackage(packageToRemoveDisplayName))
        {
            Logger::error(L"Failed to unregister package: " + packageToRemoveDisplayName);
            er = ERROR_INSTALL_FAILURE;
        }
    }
    catch (std::exception &e)
    {
        std::string errorMessage{"Exception thrown while trying to unregister the CmdPal package: "};
        errorMessage += e.what();
        Logger::error(errorMessage);

        er = ERROR_INSTALL_FAILURE;
    }

    er = er == ERROR_SUCCESS ? (SUCCEEDED(hr) ? ERROR_SUCCESS : ERROR_INSTALL_FAILURE) : er;
    return WcaFinalize(er);
}


UINT __stdcall UnRegisterContextMenuPackagesCA(MSIHANDLE hInstall)
{
    using namespace winrt::Windows::Foundation;
    using namespace winrt::Windows::Management::Deployment;

    HRESULT hr = S_OK;
    UINT er = ERROR_SUCCESS;

    hr = WcaInitialize(hInstall, "UnRegisterContextMenuPackagesCA"); // original func name is too long

    try
    {
        // Packages to unregister
        const std::vector<std::wstring> packagesToRemoveDisplayName{{L"PowerRenameContextMenu"}, {L"ImageResizerContextMenu"}, {L"FileLocksmithContextMenu"}, {L"NewPlusContextMenu"}};