ExtensionCatalog.cpp (2575B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #include "pch.h" 4 #include "winget/ExtensionCatalog.h" 5 #include "AppInstallerErrors.h" 6 #include "AppInstallerLogging.h" 7 #include "AppInstallerStrings.h" 8 9 namespace AppInstaller::Deployment 10 { 11 namespace AppExt = winrt::Windows::ApplicationModel::AppExtensions; 12 13 Extension::Extension(AppExt::AppExtension extension) : m_extension(extension) {} 14 15 std::filesystem::path Extension::GetPackagePath() const 16 { 17 return m_extension.Package().InstalledLocation().Path().c_str(); 18 } 19 20 std::filesystem::path Extension::GetPublicFolderPath() const 21 { 22 auto folder = m_extension.GetPublicFolderAsync().get(); 23 THROW_HR_IF(APPINSTALLER_CLI_ERROR_EXTENSION_PUBLIC_FAILED, !folder); 24 return folder.Path().c_str(); 25 } 26 27 winrt::Windows::ApplicationModel::PackageVersion Extension::GetPackageVersion() const 28 { 29 return m_extension.Package().Id().Version(); 30 } 31 32 bool Extension::VerifyContentIntegrity(IProgressCallback& progress) 33 { 34 auto operation = m_extension.Package().VerifyContentIntegrityAsync(); 35 auto removeCancel = progress.SetCancellationFunction([&]() { operation.Cancel(); }); 36 return operation.get(); 37 } 38 39 ExtensionCatalog::ExtensionCatalog(std::wstring_view extensionName) 40 { 41 m_catalog = AppExt::AppExtensionCatalog::Open(winrt::hstring(extensionName)); 42 } 43 44 std::optional<Extension> ExtensionCatalog::FindByPackageFamilyAndId(std::string_view packageFamilyName, std::wstring_view id) const 45 { 46 std::wstring wpfn = Utility::ConvertToUTF16(packageFamilyName); 47 std::optional<Extension> result; 48 49 auto extensions = m_catalog.FindAllAsync().get(); 50 for (const auto& extension : extensions) 51 { 52 auto info = extension.AppInfo(); 53 54 AICLI_LOG(Core, Info, << "Examining extension: PFN = " << Utility::ConvertToUTF8(info.PackageFamilyName()) << ", ID = " << Utility::ConvertToUTF8(extension.Id())); 55 56 if (info.PackageFamilyName() == wpfn && extension.Id() == id) 57 { 58 AICLI_LOG(Core, Info, << "Found matching extension."); 59 result = Extension{ extension }; 60 break; 61 } 62 } 63 64 if (!result) 65 { 66 AICLI_LOG(Core, Info, << "Did not find extension: PFN = " << packageFamilyName << ", ID = " << Utility::ConvertToUTF8(id)); 67 } 68 69 return result; 70 } 71 }