Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 41 additions & 26 deletions dev/Deployment/DeploymentManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ inline void Initialize_StopSuccessActivity(
S_OK,
static_cast<PCWSTR>(nullptr),
GUID{},
::WindowsAppRuntime::Deployment::Activity::Context::Get().GetUseExistingPackageIfHigherVersion());
initializeActivityContext.GetUseExistingPackageIfHigherVersion());
}

namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implementation
Expand Down Expand Up @@ -212,7 +212,7 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
const int integrityLevel = Security::IntegrityLevel::GetIntegrityLevel();
if (isPackagedProcess && integrityLevel >= SECURITY_MANDATORY_MEDIUM_RID)
{
// Marking the package as full trust because the call originates from a MediumIL package.
// Marking the package as full trust because the call originates from a MediumIL package.
// For a packaged MediumIL app (with a non-Microsoft publisher) to deploy main and singleton packages, a breakaway helper process is required.
initializeActivityContext.SetIsFullTrustPackage();
}
Expand Down Expand Up @@ -290,7 +290,7 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
}

std::wstring frameworkPackageFullName{ packageFullName };
auto deployPackagesResult{ Deploy(frameworkPackageFullName, deploymentInitializeOptions.ForceDeployment()) };
auto deployPackagesResult{ Deploy(initializeActivityContext, frameworkPackageFullName, deploymentInitializeOptions.ForceDeployment()) };
DeploymentStatus status{};
if (SUCCEEDED(deployPackagesResult))
{
Expand Down Expand Up @@ -417,7 +417,11 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
// If useExistingPackageIfHigherVersion == false, Adds the current version package at the passed in path using PackageManager.
// If useExistingPackageIfHigherVersion == true, Registers the higher version package using the passed in path as manifest path and PackageManager.
// This requires the 'packageManagement' or 'runFullTrust' capabilities.
HRESULT DeploymentManager::AddOrRegisterPackage(const std::filesystem::path& path, const bool useExistingPackageIfHigherVersion, const bool forceDeployment) try
HRESULT DeploymentManager::AddOrRegisterPackage(
::WindowsAppRuntime::Deployment::Activity::Context& initializeActivityContext,
const std::filesystem::path& path,
const bool useExistingPackageIfHigherVersion,
const bool forceDeployment) try
{
winrt::Windows::Management::Deployment::PackageManager packageManager;

Expand Down Expand Up @@ -447,7 +451,7 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
deploymentOperationHResult = static_cast<HRESULT>(deploymentOperation.ErrorCode());
deploymentOperationExtendedHResult = deploymentResult.ExtendedErrorCode();

::WindowsAppRuntime::Deployment::Activity::Context::Get().SetDeploymentErrorInfo(
initializeActivityContext.SetDeploymentErrorInfo(
deploymentOperationExtendedHResult,
deploymentResult.ErrorText().c_str(),
deploymentResult.ActivityId());
Expand All @@ -471,10 +475,14 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
}

/// @warning This function is ONLY for processes with package identity. It's the caller's responsibility to ensure this.
HRESULT DeploymentManager::AddOrRegisterPackageInBreakAwayProcess(const std::filesystem::path& path, const bool useExistingPackageIfHigherVersion, const bool forceDeployment) try
HRESULT DeploymentManager::AddOrRegisterPackageInBreakAwayProcess(
::WindowsAppRuntime::Deployment::Activity::Context& initializeActivityContext,
const std::filesystem::path& path,
const bool useExistingPackageIfHigherVersion,
const bool forceDeployment) try
{
auto exePath{ GenerateDeploymentAgentPath() };
auto activityId{ winrt::to_hstring(*::WindowsAppRuntime::Deployment::Activity::Context::Get().GetActivity().Id()) };
auto activityId{ winrt::to_hstring(*initializeActivityContext.GetActivity().Id()) };

// <currentdirectory>\deploymentagent.exe <custom arguments passed by caller>
auto cmdLine{ wil::str_printf<wil::unique_cotaskmem_string>(L"\"%s\" %u \"%s\" %u %s", exePath.c_str(), (useExistingPackageIfHigherVersion ? 1 : 0), path.c_str(), (forceDeployment ? 1 : 0), activityId.c_str()) };
Expand Down Expand Up @@ -518,26 +526,31 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
CATCH_RETURN()

// Deploys all of the packages carried by the specified framework.
HRESULT DeploymentManager::Deploy(const std::wstring& frameworkPackageFullName, const bool forceDeployment) try
HRESULT DeploymentManager::Deploy(
::WindowsAppRuntime::Deployment::Activity::Context& initializeActivityContext,
const std::wstring& frameworkPackageFullName,
const bool forceDeployment) try
{
RETURN_IF_FAILED(InstallLicenses(frameworkPackageFullName));
RETURN_IF_FAILED(DeployPackages(frameworkPackageFullName, forceDeployment));
RETURN_IF_FAILED(InstallLicenses(initializeActivityContext, frameworkPackageFullName));
RETURN_IF_FAILED(DeployPackages(initializeActivityContext, frameworkPackageFullName, forceDeployment));
return S_OK;
}
CATCH_RETURN()

HRESULT DeploymentManager::InstallLicenses(const std::wstring& frameworkPackageFullName)
HRESULT DeploymentManager::InstallLicenses(
::WindowsAppRuntime::Deployment::Activity::Context& initializeActivityContext,
const std::wstring& frameworkPackageFullName)
{
::WindowsAppRuntime::Deployment::Activity::Context::Get().Reset();
::WindowsAppRuntime::Deployment::Activity::Context::Get().SetInstallStage(::WindowsAppRuntime::Deployment::Activity::DeploymentStage::GetLicensePath);
initializeActivityContext.Reset();
initializeActivityContext.SetInstallStage(::WindowsAppRuntime::Deployment::Activity::DeploymentStage::GetLicensePath);

// Build path for licenses
auto licensePath{ std::filesystem::path(GetPackagePath(frameworkPackageFullName)) };
licensePath /= WINDOWSAPPRUNTIME_FRAMEWORK_PACKAGE_FOLDER;
auto licenseFilespec{ licensePath };
licenseFilespec /= L"*_license.xml";

::WindowsAppRuntime::Deployment::Activity::Context::Get().SetInstallStage(::WindowsAppRuntime::Deployment::Activity::DeploymentStage::InstallLicense);
initializeActivityContext.SetInstallStage(::WindowsAppRuntime::Deployment::Activity::DeploymentStage::InstallLicense);

// Deploy the licenses (if any)
::Microsoft::Windows::ApplicationModel::Licensing::Installer licenseInstaller;
Expand All @@ -556,7 +569,7 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
auto licenseFilename{ licensePath };
licenseFilename /= findFileData.cFileName;

::WindowsAppRuntime::Deployment::Activity::Context::Get().SetCurrentResourceId(licenseFilename);
initializeActivityContext.SetCurrentResourceId(licenseFilename);

RETURN_IF_FAILED_MSG(licenseInstaller.InstallLicenseFile(licenseFilename.c_str()),
"LicenseFile:%ls", licenseFilename.c_str());
Expand All @@ -572,20 +585,22 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
return S_OK;
}

HRESULT DeploymentManager::DeployPackages(const std::wstring& frameworkPackageFullName, const bool forceDeployment)
HRESULT DeploymentManager::DeployPackages(
::WindowsAppRuntime::Deployment::Activity::Context& initializeActivityContext,
const std::wstring& frameworkPackageFullName,
const bool forceDeployment)
{
auto& initializeActivity{ ::WindowsAppRuntime::Deployment::Activity::Context::Get() };
initializeActivity.Reset();
initializeActivityContext.Reset();

initializeActivity.SetInstallStage(::WindowsAppRuntime::Deployment::Activity::DeploymentStage::GetPackagePath);
initializeActivityContext.SetInstallStage(::WindowsAppRuntime::Deployment::Activity::DeploymentStage::GetPackagePath);
const auto frameworkPath{ std::filesystem::path(GetPackagePath(frameworkPackageFullName)) };

for (auto package : c_targetPackages)
{
auto isSingleton{ CompareStringOrdinal(package.identifier.c_str(), -1, WINDOWSAPPRUNTIME_PACKAGE_SUBTYPENAME_SINGLETON, -1, TRUE) == CSTR_EQUAL };
initializeActivity.Reset();
initializeActivity.SetInstallStage(::WindowsAppRuntime::Deployment::Activity::DeploymentStage::AddPackage);
initializeActivity.SetCurrentResourceId(package.identifier);
initializeActivityContext.Reset();
initializeActivityContext.SetInstallStage(::WindowsAppRuntime::Deployment::Activity::DeploymentStage::AddPackage);
initializeActivityContext.SetCurrentResourceId(package.identifier);

std::filesystem::path packagePath{};

Expand All @@ -595,7 +610,7 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
auto useExistingPackageIfHigherVersion { existingPackageIfHigherVersion != g_existingTargetPackagesIfHigherVersion.end() };
if (useExistingPackageIfHigherVersion)
{
initializeActivity.SetUseExistingPackageIfHigherVersion();
initializeActivityContext.SetUseExistingPackageIfHigherVersion();
packagePath = std::filesystem::path(GetPackagePath(existingPackageIfHigherVersion->second));
packagePath /= WINDOWSAPPRUNTIME_PACKAGE_MANIFEST_FILE;
}
Expand All @@ -609,14 +624,14 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
// If the current application has runFullTrust capability, then Deploy the target package in a Breakaway process.
// Otherwise, call PackageManager API to deploy the target package.
// The Singleton package will always set true for forceDeployment and the running process will be terminated to update the package.
if (initializeActivity.GetIsFullTrustPackage())
if (initializeActivityContext.GetIsFullTrustPackage())
{

RETURN_IF_FAILED(AddOrRegisterPackageInBreakAwayProcess(packagePath, useExistingPackageIfHigherVersion, forceDeployment || isSingleton));
RETURN_IF_FAILED(AddOrRegisterPackageInBreakAwayProcess(initializeActivityContext, packagePath, useExistingPackageIfHigherVersion, forceDeployment || isSingleton));
}
else
{
RETURN_IF_FAILED(AddOrRegisterPackage(packagePath, useExistingPackageIfHigherVersion, forceDeployment || isSingleton));
RETURN_IF_FAILED(AddOrRegisterPackage(initializeActivityContext, packagePath, useExistingPackageIfHigherVersion, forceDeployment || isSingleton));
}

// Always restart Push Notifications Long Running Platform when Singleton package is processed and installed.
Expand Down
28 changes: 22 additions & 6 deletions dev/Deployment/DeploymentManager.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation and Contributors.
// Copyright (c) Microsoft Corporation and Contributors.
// Licensed under the MIT License.
#pragma once
#include <PackageInfo.h>
Expand Down Expand Up @@ -39,12 +39,28 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
static std::vector<std::wstring> FindPackagesByFamily(std::wstring const& packageFamilyName);
static HRESULT VerifyPackage(const std::wstring& packageFamilyName, const PACKAGE_VERSION targetVersion, const std::wstring& matchedPackageFullName);
static std::wstring GetPackagePath(std::wstring const& packageFullName);
static HRESULT AddOrRegisterPackageInBreakAwayProcess(const std::filesystem::path& packagePath, const bool regiterHigherVersionPackage, const bool forceDeployment);
static HRESULT AddOrRegisterPackageInBreakAwayProcess(
::WindowsAppRuntime::Deployment::Activity::Context& initializeActivityContext,
const std::filesystem::path& packagePath,
const bool regiterHigherVersionPackage,
const bool forceDeployment);
static std::wstring GenerateDeploymentAgentPath();
static HRESULT AddOrRegisterPackage(const std::filesystem::path& package, const bool regiterHigherVersionPackage, const bool forceDeployment);
static HRESULT DeployPackages(const std::wstring& frameworkPackageFullName, const bool forceDeployment);
static HRESULT Deploy(const std::wstring& frameworkPackageFullName, const bool forceDeployment = false);
static HRESULT InstallLicenses(const std::wstring& frameworkPackageFullName);
static HRESULT AddOrRegisterPackage(
::WindowsAppRuntime::Deployment::Activity::Context& initializeActivityContext,
const std::filesystem::path& package,
const bool regiterHigherVersionPackage,
const bool forceDeployment);
static HRESULT DeployPackages(
::WindowsAppRuntime::Deployment::Activity::Context& initializeActivityContext,
const std::wstring& frameworkPackageFullName,
const bool forceDeployment);
static HRESULT Deploy(
::WindowsAppRuntime::Deployment::Activity::Context& initializeActivityContext,
const std::wstring& frameworkPackageFullName,
const bool forceDeployment = false);
static HRESULT InstallLicenses(
::WindowsAppRuntime::Deployment::Activity::Context& initializeActivityContext,
const std::wstring& frameworkPackageFullName);
static hstring GetCurrentFrameworkPackageFullName();

};
Expand Down