-
Notifications
You must be signed in to change notification settings - Fork 391
Refactoring and adding unit tests to deployment #5853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 57 commits
eba0fc5
62dcc52
a98dcc0
3737132
2b19bb2
bfeda67
a96f4b3
e11fd1c
610cc5c
6c5e345
bfbee0f
7a19ab5
6c3c31e
dd91f1f
a1224f2
b7a33b7
7476376
7aacedc
69fdaae
fe992f7
2a46465
a3e442f
1e11abb
2ff61a8
4938912
1c8db29
8612e5f
4f1ff76
29f25fe
b9d2453
d8d32be
4d65049
22740a0
cbc3599
0154acf
7c37c84
c0bc0db
857b2a4
be59d11
0c01e83
4779f01
d00d35a
0aea9e7
d6657c2
f134860
c7cb322
fa40aeb
67d3885
bbb2177
bf36c36
28518fb
cc2eb0b
cf992ba
f75bddf
f0c3505
4d36469
7dd4c79
6e369aa
b4c18b0
392382a
6135089
9e6e14d
97c9ba5
0067c0b
264a094
1a5dc32
3efa5e0
660bc3b
061bde8
fab4936
71a46a4
6d85985
4949039
49e5b9d
e3e8354
f3f3d58
bed2de6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
// Copyright (c) Microsoft Corporation and Contributors. | ||
// Licensed under the MIT License. | ||
|
||
#include <pch.h> | ||
#include <DeploymentActivityContext.h> | ||
#include <PackageDefinitions.h> | ||
#include <Deployer.h> | ||
#include <PackageUtilities.h> | ||
#include <PackageRegistrar.h> | ||
#include <functional> | ||
|
||
using namespace winrt; | ||
|
||
namespace WindowsAppRuntime::Deployment::Deployer | ||
{ | ||
// licenseFileSpec: This parameter specifies the file specification (e.g., path and pattern) for the license files to be retrieved. | ||
// licenseFiles: This is an output parameter that will be populated with the names of the license files found matching the specified file specification. | ||
HRESULT GetLicenseFiles(const std::wstring& licenseFileSpec, std::vector<std::wstring>& licenseFiles) | ||
{ | ||
licenseFiles.clear(); | ||
|
||
WIN32_FIND_DATA findFileData{}; | ||
wil::unique_hfind hfind{ FindFirstFileW(licenseFileSpec.c_str(), &findFileData) }; | ||
if (!hfind) | ||
{ | ||
const auto lastError{ GetLastError() }; | ||
RETURN_HR_IF_MSG(HRESULT_FROM_WIN32(lastError), (lastError != ERROR_FILE_NOT_FOUND) && (lastError != ERROR_PATH_NOT_FOUND), | ||
"FindFirstFile:%ls", licenseFileSpec.c_str()); | ||
return S_OK; | ||
} | ||
for (;;) | ||
{ | ||
// Add the license file | ||
licenseFiles.push_back(findFileData.cFileName); | ||
|
||
// Next! (if any) | ||
if (!FindNextFileW(hfind.get(), &findFileData)) | ||
{ | ||
const auto lastError{ GetLastError() }; | ||
RETURN_HR_IF(HRESULT_FROM_WIN32(lastError), lastError != ERROR_NO_MORE_FILES); | ||
break; | ||
} | ||
} | ||
return S_OK; | ||
} | ||
|
||
HRESULT InstallLicenses( | ||
const std::vector<std::wstring>& licenseFiles, | ||
std::filesystem::path licensePath, | ||
ILicenseInstaller& licenseInstaller, | ||
::WindowsAppRuntime::Deployment::Activity::Context& initializeActivityContext | ||
) | ||
{ | ||
initializeActivityContext.SetInstallStage(::WindowsAppRuntime::Deployment::Activity::DeploymentStage::InstallLicense); | ||
|
||
// Deploy the licenses (if any) | ||
for (const auto& licenseFileName : licenseFiles) | ||
{ | ||
// Install the license file | ||
auto licenseFileFullName{ licensePath }; | ||
licenseFileFullName /= licenseFileName; | ||
|
||
// initializeActivityContext.Reset(); --> Why are we reseting here? It clears out all the info. | ||
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
initializeActivityContext.SetCurrentResourceId(licenseFileFullName); | ||
|
||
RETURN_IF_FAILED_MSG(licenseInstaller.InstallLicenseFile(licenseFileFullName.c_str()), | ||
"LicenseFile:%ls", licenseFileFullName.c_str()); | ||
} | ||
return S_OK; | ||
} | ||
|
||
std::vector<DeploymentPackageArguments> GetDeploymentPackageArguments( | ||
const std::wstring& frameworkPackageFullName, | ||
::WindowsAppRuntime::Deployment::Activity::Context& initializeActivityContext, | ||
const std::function<std::wstring(const std::wstring&)>& getPackagePathFunc) | ||
{ | ||
initializeActivityContext.Reset(); | ||
initializeActivityContext.SetInstallStage(::WindowsAppRuntime::Deployment::Activity::DeploymentStage::GetPackagePath); | ||
|
||
std::vector<DeploymentPackageArguments> deploymentPackageArguments; | ||
|
||
const auto frameworkPath{ std::filesystem::path(getPackagePathFunc(frameworkPackageFullName)) }; | ||
for (auto package : winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implementation::c_targetPackages) | ||
{ | ||
auto isSingleton{ CompareStringOrdinal(package.identifier.c_str(), -1, WINDOWSAPPRUNTIME_PACKAGE_SUBTYPENAME_SINGLETON, -1, TRUE) == CSTR_EQUAL }; | ||
|
||
std::filesystem::path packagePath{}; | ||
|
||
// If there is exisiting target package version higher than that of framework current version package, then re-register it. | ||
// Otherwise, deploy the target msix package from the current framework package version. | ||
auto existingPackageIfHigherVersion = winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implementation::g_existingTargetPackagesIfHigherVersion.find(package.identifier); | ||
auto useExistingPackageIfHigherVersion { existingPackageIfHigherVersion != winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implementation::g_existingTargetPackagesIfHigherVersion.end() }; | ||
if (useExistingPackageIfHigherVersion) | ||
{ | ||
packagePath = std::filesystem::path(getPackagePathFunc(existingPackageIfHigherVersion->second)); | ||
packagePath /= WINDOWSAPPRUNTIME_PACKAGE_MANIFEST_FILE; | ||
} | ||
else | ||
{ | ||
packagePath = frameworkPath; | ||
packagePath /= WINDOWSAPPRUNTIME_FRAMEWORK_PACKAGE_FOLDER; | ||
packagePath /= package.identifier + WINDOWSAPPRUNTIME_FRAMEWORK_PACKAGE_FILE_EXTENSION; | ||
} | ||
|
||
deploymentPackageArguments.push_back(DeploymentPackageArguments{ package.identifier, packagePath, useExistingPackageIfHigherVersion, isSingleton }); | ||
} | ||
|
||
return deploymentPackageArguments; | ||
} | ||
|
||
HRESULT DeployPackages( | ||
const std::vector<DeploymentPackageArguments>& deploymentPackageArguments, | ||
const bool forceDeployment, | ||
::WindowsAppRuntime::Deployment::Activity::Context& initializeActivity, | ||
const std::function<HRESULT()>& startupNotificationsLongRunningPlatformFunc | ||
) | ||
{ | ||
for (auto package : deploymentPackageArguments) | ||
{ | ||
initializeActivity.Reset(); | ||
initializeActivity.SetInstallStage(::WindowsAppRuntime::Deployment::Activity::DeploymentStage::AddPackage); | ||
initializeActivity.SetCurrentResourceId(package.packageIdentifier); | ||
if (package.useExistingPackageIfHigherVersion) | ||
{ | ||
initializeActivity.SetUseExistingPackageIfHigherVersion(); | ||
} | ||
|
||
// 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()) | ||
{ | ||
|
||
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
RETURN_IF_FAILED(::WindowsAppRuntime::Deployment::PackageRegistrar::AddOrRegisterPackageInBreakAwayProcess( | ||
package.packagePath, | ||
package.useExistingPackageIfHigherVersion, | ||
forceDeployment || package.isSingleton, | ||
initializeActivity, | ||
::WindowsAppRuntime::Deployment::PackageRegistrar::GenerateDeploymentAgentPath() | ||
)); | ||
} | ||
else | ||
{ | ||
auto packageManager = winrt::Windows::Management::Deployment::PackageManager{}; | ||
RETURN_IF_FAILED(::WindowsAppRuntime::Deployment::PackageRegistrar::AddOrRegisterPackage( | ||
package.packagePath, | ||
package.useExistingPackageIfHigherVersion, | ||
forceDeployment || package.isSingleton, | ||
packageManager, | ||
initializeActivity | ||
)); | ||
} | ||
|
||
// Always restart Push Notifications Long Running Platform when Singleton package is processed and installed. | ||
if (package.isSingleton) | ||
{ | ||
// wil callback is set up to log telemetry events for Push Notifications LRP. | ||
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
LOG_IF_FAILED_MSG(startupNotificationsLongRunningPlatformFunc(), "Restarting Notifications LRP failed in all 3 attempts."); | ||
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
return S_OK; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) Microsoft Corporation and Contributors. | ||
// Licensed under the MIT License. | ||
#pragma once | ||
|
||
#include <string> | ||
#include <filesystem> | ||
#include <vector> | ||
#include <functional> | ||
#include <DeploymentActivityContext.h> | ||
|
||
namespace WindowsAppRuntime::Deployment::Deployer | ||
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
{ | ||
// Structure to hold deployment package arguments | ||
struct DeploymentPackageArguments | ||
{ | ||
const std::wstring packageIdentifier; | ||
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
const std::filesystem::path packagePath; | ||
const bool useExistingPackageIfHigherVersion; | ||
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
const bool isSingleton; | ||
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
}; | ||
|
||
// Proxy/Wrapper for license installer. Open possibility to add more methods if needed. | ||
struct ILicenseInstaller | ||
{ | ||
virtual HRESULT InstallLicenseFile(const std::wstring& licenseFilename) = 0; | ||
|
||
}; | ||
|
||
// Get license files from the specified path pattern | ||
HRESULT GetLicenseFiles(const std::wstring& licenseFileSpec, std::vector<std::wstring>& licenseFiles); | ||
|
||
// Install license files | ||
HRESULT InstallLicenses( | ||
const std::vector<std::wstring>& licenseFiles, | ||
std::filesystem::path licensePath, | ||
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
ILicenseInstaller& licenseInstaller, | ||
::WindowsAppRuntime::Deployment::Activity::Context& initializeActivityContext); | ||
|
||
// Get deployment package arguments | ||
std::vector<DeploymentPackageArguments> GetDeploymentPackageArguments( | ||
const std::wstring& frameworkPackageFullName, | ||
::WindowsAppRuntime::Deployment::Activity::Context& initializeActivityContext, | ||
const std::function<std::wstring(const std::wstring&)>& getPackagePathFunc); | ||
|
||
// Package deployment | ||
HRESULT DeployPackages( | ||
const std::vector<DeploymentPackageArguments>& deploymentPackageArguments, | ||
const bool forceDeployment, | ||
::WindowsAppRuntime::Deployment::Activity::Context& initializeActivity, | ||
const std::function<HRESULT()>& startupNotificationsLongRunningPlatformFunc); | ||
} | ||
guimafelipe marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
Uh oh!
There was an error while loading. Please reload this page.