From 5af584fed4183d76d0a37dab4235e3f2557901c7 Mon Sep 17 00:00:00 2001 From: Stefan Markovic Date: Wed, 8 Jun 2022 17:07:37 +0200 Subject: [PATCH] Check if package already registered --- src/modules/powerrename/dll/dllmain.cpp | 27 ++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/modules/powerrename/dll/dllmain.cpp b/src/modules/powerrename/dll/dllmain.cpp index 3f528d2851..8c7e2b4605 100644 --- a/src/modules/powerrename/dll/dllmain.cpp +++ b/src/modules/powerrename/dll/dllmain.cpp @@ -48,6 +48,26 @@ namespace 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) { using namespace winrt::Windows::Foundation; @@ -274,7 +294,12 @@ public: { std::wstring path = get_module_folderpath(g_hInst); std::wstring packageUri = path + L"\\PowerRenameContextMenuPackage.msix"; - RegisterSparsePackage(path, packageUri); + + std::wstring packageDisplayName{ L"PowerRenameContextMenu" }; + if (!IsPackageRegistered(packageDisplayName)) + { + RegisterSparsePackage(path, packageUri); + } } save_settings();