Skip to content

Commit

Permalink
Use Function Templates to implement Repair
Browse files Browse the repository at this point in the history
  • Loading branch information
Santosh Chintalapati committed Sep 29, 2022
1 parent 28e3b21 commit cd53458
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
2 changes: 0 additions & 2 deletions dev/Deployment/Deployment.idl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
}
22 changes: 13 additions & 9 deletions dev/Deployment/DeploymentManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem

winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::DeploymentResult DeploymentManager::Repair()
{
winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::DeploymentInitializeOptions options{};
winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::DeploymentRepairOptions options{};
return Initialize(GetCurrentFrameworkPackageFullName(), options, true);
}

Expand Down Expand Up @@ -165,11 +165,14 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
return DeploymentManager::Initialize(packageFullName, deploymentInitializeOptions);
}

template <typename TOptions>
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();
Expand All @@ -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(),
Expand All @@ -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)
{
Expand Down Expand Up @@ -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));
Expand All @@ -240,10 +243,11 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
return deploymentResult;
}

template <typename TOptions>
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) };
Expand All @@ -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))
{
Expand Down
8 changes: 4 additions & 4 deletions dev/Deployment/DeploymentManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename TOptions>
static WindowsAppRuntime::DeploymentResult Initialize(hstring const& packageFullName, TOptions const& tOoptions, bool isRepair = false);

private:
template <typename TOptions>
static WindowsAppRuntime::DeploymentResult _Initialize(
::WindowsAppRuntime::Deployment::Activity::Context& initializeActivityContext,
hstring const& packageFullName,
WindowsAppRuntime::DeploymentInitializeOptions const& deploymentInitializeOptions,
TOptions const& tOoptions,
bool isRepair);

private:
Expand Down

0 comments on commit cd53458

Please sign in to comment.