mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-16 11:48:06 +01:00
Check if package already registered
This commit is contained in:
@@ -48,6 +48,26 @@ namespace
|
|||||||
dwlConditionMask);
|
dwlConditionMask);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsPackageRegistered(std::wstring packageDisplayName)
|
||||||
|
{
|
||||||
|
using namespace winrt::Windows::Foundation;
|
||||||
|
using namespace winrt::Windows::Management::Deployment;
|
||||||
|
|
||||||
|
PackageManager packageManager;
|
||||||
|
|
||||||
|
for (auto const& package : packageManager.FindPackages())
|
||||||
|
{
|
||||||
|
const auto& packageFullName = std::wstring{ package.Id().FullName() };
|
||||||
|
|
||||||
|
if (packageFullName.contains(packageDisplayName))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool RegisterSparsePackage(std::wstring externalLocation, std::wstring sparsePkgPath)
|
bool RegisterSparsePackage(std::wstring externalLocation, std::wstring sparsePkgPath)
|
||||||
{
|
{
|
||||||
using namespace winrt::Windows::Foundation;
|
using namespace winrt::Windows::Foundation;
|
||||||
@@ -274,8 +294,13 @@ public:
|
|||||||
{
|
{
|
||||||
std::wstring path = get_module_folderpath(g_hInst);
|
std::wstring path = get_module_folderpath(g_hInst);
|
||||||
std::wstring packageUri = path + L"\\PowerRenameContextMenuPackage.msix";
|
std::wstring packageUri = path + L"\\PowerRenameContextMenuPackage.msix";
|
||||||
|
|
||||||
|
std::wstring packageDisplayName{ L"PowerRenameContextMenu" };
|
||||||
|
if (!IsPackageRegistered(packageDisplayName))
|
||||||
|
{
|
||||||
RegisterSparsePackage(path, packageUri);
|
RegisterSparsePackage(path, packageUri);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
save_settings();
|
save_settings();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user