[PowerRename][ImageResizer] Tier1 Win11 Context menu (#19000)

* Test win11 tier1 context menu

* Try to test signing

* Cleanup

* Cleanup project file

* Sign dll
Add PowerToys preffix
Add assets to installer

* expect.txt

* Switch to named pipes
Unregister package on uninstall
Remove unneeded files
Cleanup

* Bring back check if package registered but use per-user method

* Fix win11 check

* expect.txt

* Check if package already registered

* Revert "Check if package already registered"

FindPackages() method needs admin privileges.

This reverts commit 5af584fed4.

* Fix PowerRename args checking

* Cleanup assets

* Tier1 context menu ImageResizer
Minor cleanups
Move logic to package.h

* [WIP] Signing and installer
Expect.txt

* Localized context menu title

* Retarget everything 10.0.18362.0 -> 10.0.19041.0

* Address PR comments
 - check if selection renamable
 - minor cleanup
 - struct initialization

* Fix ImageResizerLib project configuration

* More Windows version updates

* Remove unneeded file & try fix resource build error

* Add Microsoft.PowerToys prefix to packages

* Test

* Fix convert-resx-to-rc.ps1 script issue causing resource files compile error

Don't generate empty STRINGTABLE for resx files without data

* Avoid duplicate context menu items

* [BugReportTool] Report installed context menu packages
This commit is contained in:
Stefan Markovic
2022-06-30 22:10:14 +02:00
committed by GitHub
parent a0eacca17f
commit e637902892
148 changed files with 3163 additions and 384 deletions

112
src/common/utils/package.h Normal file
View File

@@ -0,0 +1,112 @@
#pragma once
#include <Windows.h>
#include <exception>
#include <string>
#include <winrt/Windows.ApplicationModel.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Management.Deployment.h>
#include "../logger/logger.h"
namespace package {
inline BOOL IsWin11OrGreater()
{
OSVERSIONINFOEX osvi{};
DWORDLONG dwlConditionMask = 0;
int op = VER_GREATER_EQUAL;
// Initialize the OSVERSIONINFOEX structure.
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
osvi.dwMajorVersion = HIBYTE(_WIN32_WINNT_WINTHRESHOLD);
osvi.dwMinorVersion = LOBYTE(_WIN32_WINNT_WINTHRESHOLD);
// Windows 11 build number
osvi.dwBuildNumber = 22000;
// Initialize the condition mask.
VER_SET_CONDITION(dwlConditionMask, VER_MAJORVERSION, op);
VER_SET_CONDITION(dwlConditionMask, VER_MINORVERSION, op);
VER_SET_CONDITION(dwlConditionMask, VER_BUILDNUMBER, op);
// Perform the test.
return VerifyVersionInfo(
&osvi,
VER_MAJORVERSION | VER_MINORVERSION | VER_BUILDNUMBER,
dwlConditionMask);
}
inline bool IsPackageRegistered(std::wstring packageDisplayName)
{
using namespace winrt::Windows::Foundation;
using namespace winrt::Windows::Management::Deployment;
PackageManager packageManager;
for (auto const& package : packageManager.FindPackagesForUser({}))
{
const auto& packageFullName = std::wstring{ package.Id().FullName() };
if (packageFullName.contains(packageDisplayName))
{
return true;
}
}
return false;
}
inline bool RegisterSparsePackage(std::wstring externalLocation, std::wstring sparsePkgPath)
{
using namespace winrt::Windows::Foundation;
using namespace winrt::Windows::Management::Deployment;
try
{
Uri externalUri{ externalLocation };
Uri packageUri{ sparsePkgPath };
PackageManager packageManager;
// Declare use of an external location
AddPackageOptions options;
options.ExternalLocationUri(externalUri);
IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> deploymentOperation = packageManager.AddPackageByUriAsync(packageUri, options);
deploymentOperation.get();
// Check the status of the operation
if (deploymentOperation.Status() == AsyncStatus::Error)
{
auto deploymentResult{ deploymentOperation.GetResults() };
auto errorCode = deploymentOperation.ErrorCode();
auto errorText = deploymentResult.ErrorText();
Logger::error(L"Register {} package failed. ErrorCode: {}, ErrorText: {}", sparsePkgPath, std::to_wstring(errorCode), errorText);
return false;
}
else if (deploymentOperation.Status() == AsyncStatus::Canceled)
{
Logger::error(L"Register {} package canceled.", sparsePkgPath);
return false;
}
else if (deploymentOperation.Status() == AsyncStatus::Completed)
{
Logger::info(L"Register {} package completed.", sparsePkgPath);
}
else
{
Logger::debug(L"Register {} package started.", sparsePkgPath);
}
return true;
}
catch (std::exception e)
{
Logger::error("Exception thrown while trying to register package: {}", e.what());
return false;
}
}
}