From 5337905c912b64082c4bf4041f6acf6aca53e3d4 Mon Sep 17 00:00:00 2001 From: Santosh Chintalapati Date: Wed, 28 Sep 2022 16:57:29 -0700 Subject: [PATCH] Use Function Templates to implement Repair --- dev/Deployment/Deployment.idl | 2 -- dev/Deployment/DeploymentManager.cpp | 20 ++++++++++++-------- dev/Deployment/DeploymentManager.h | 8 ++++---- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/dev/Deployment/Deployment.idl b/dev/Deployment/Deployment.idl index c034d9dec18..1bf9b177053 100644 --- a/dev/Deployment/Deployment.idl +++ b/dev/Deployment/Deployment.idl @@ -88,14 +88,12 @@ namespace Microsoft.Windows.ApplicationModel.WindowsAppRuntime /// Checks the status of the WindowsAppRuntime of the current package and attempts to /// repair already installed WinAppSDK packages. [contract(DeploymentContract, 3)] - [overload("Repair")] static DeploymentResult Repair(); /// Checks the status of the WindowsAppRuntime of the current package and attempts to /// repair already installed WinAppSDK packages, while applying the DeploymentRepairOptions /// passed in. [contract(DeploymentContract, 3)] - [overload("Repair")] static DeploymentResult Repair(Microsoft.Windows.ApplicationModel.WindowsAppRuntime.DeploymentRepairOptions deploymentRepairOptions); }; } diff --git a/dev/Deployment/DeploymentManager.cpp b/dev/Deployment/DeploymentManager.cpp index 0ebd0aef110..80a4c3798c8 100644 --- a/dev/Deployment/DeploymentManager.cpp +++ b/dev/Deployment/DeploymentManager.cpp @@ -165,11 +165,14 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem return DeploymentManager::Initialize(packageFullName, deploymentInitializeOptions); } + template winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::DeploymentResult DeploymentManager::Initialize( - hstring const& packageFullName, - winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::DeploymentInitializeOptions const& deploymentInitializeOptions, - bool isRepair) + hstring const& packageFullName, TOptions const& tOptions, bool isRepair) { + THROW_HR_IF(HRESULT_FROM_WIN32(ERROR_INVALID_DATATYPE), + (!isRepair && typeid(tOptions).name() != typeid(DeploymentInitializeOptions).name()) || + (isRepair && typeid(tOptions).name() != typeid(DeploymentRepairOptions).name())); + auto& initializeActivityContext{ ::WindowsAppRuntime::Deployment::Activity::Context::Get() }; const bool isPackagedProcess{ AppModel::Identity::IsPackagedProcess() }; const int integrityLevel = Security::IntegrityLevel::GetIntegrityLevel(); @@ -179,7 +182,7 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem } ::WindowsAppRuntime::Deployment::Activity::Context::Get().SetIsFullTrustPackage(); - initializeActivityContext.GetActivity().Start(deploymentInitializeOptions.ForceDeployment(), + initializeActivityContext.GetActivity().Start(tOptions.ForceDeployment(), Security::IntegrityLevel::IsElevated(), isPackagedProcess, initializeActivityContext.GetIsFullTrustPackage(), @@ -198,7 +201,7 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem try { - deploymentResult = _Initialize(initializeActivityContext, packageFullName, deploymentInitializeOptions, isRepair); + deploymentResult = _Initialize(initializeActivityContext, packageFullName, tOptions, isRepair); } catch (winrt::hresult_error const& e) { @@ -227,7 +230,7 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem DebugBreak(); } - if (deploymentInitializeOptions.OnErrorShowUI() || + if (tOptions.OnErrorShowUI() || ::Microsoft::Configuration::IsOptionEnabled(L"MICROSOFT_WINDOWSAPPRUNTIME_DEPLOYMENT_INITIALIZE_ONERRORSHOWUI")) { LOG_IF_FAILED(Initialize_OnError_ShowUI(packageIdentity, release)); @@ -240,10 +243,11 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem return deploymentResult; } + template winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::DeploymentResult DeploymentManager::_Initialize( ::WindowsAppRuntime::Deployment::Activity::Context& initializeActivityContext, hstring const& packageFullName, - winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::DeploymentInitializeOptions const& deploymentInitializeOptions, + TOptions const& tOptions, bool isRepair) { auto getStatusResult{ DeploymentManager::GetStatus(packageFullName) }; @@ -257,7 +261,7 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem } std::wstring frameworkPackageFullName{ packageFullName }; - auto deployPackagesResult{ Deploy(frameworkPackageFullName, deploymentInitializeOptions.ForceDeployment()) }; + auto deployPackagesResult{ Deploy(frameworkPackageFullName, tOptions.ForceDeployment()) }; DeploymentStatus status{}; if (SUCCEEDED(deployPackagesResult)) { diff --git a/dev/Deployment/DeploymentManager.h b/dev/Deployment/DeploymentManager.h index 1c444c4314f..42b818c1166 100644 --- a/dev/Deployment/DeploymentManager.h +++ b/dev/Deployment/DeploymentManager.h @@ -24,15 +24,15 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem private: static WindowsAppRuntime::DeploymentResult GetStatus(hstring const& packageFullName); static WindowsAppRuntime::DeploymentResult Initialize(hstring const& packageFullName); - static WindowsAppRuntime::DeploymentResult Initialize(hstring const& packageFullName, - WindowsAppRuntime::DeploymentInitializeOptions const& deploymentInitializeOptions, - bool isRepair = false); + template + static WindowsAppRuntime::DeploymentResult Initialize(hstring const& packageFullName, TOptions const& tOoptions, bool isRepair = false); private: + template static WindowsAppRuntime::DeploymentResult _Initialize( ::WindowsAppRuntime::Deployment::Activity::Context& initializeActivityContext, hstring const& packageFullName, - WindowsAppRuntime::DeploymentInitializeOptions const& deploymentInitializeOptions, + TOptions const& tOoptions, bool isRepair); private: