Skip to content

Commit 8c04941

Browse files
sachintaMSFTSantosh Chintalapati
andauthored
Deployment Manager Repair API (#2954)
* Deployment Manager Repair API Co-authored-by: Santosh Chintalapati <[email protected]>
1 parent 8d34c72 commit 8c04941

File tree

9 files changed

+200
-88
lines changed

9 files changed

+200
-88
lines changed

dev/Deployment/Deployment.idl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ namespace Microsoft.Windows.ApplicationModel.WindowsAppRuntime
1414
Ok,
1515
PackageInstallRequired,
1616
PackageInstallFailed,
17+
18+
[contract(DeploymentContract, 3)]
19+
PackageRepairFailed,
1720
};
1821

1922
/// Represents the result of a Deployment Manager method.
@@ -37,7 +40,7 @@ namespace Microsoft.Windows.ApplicationModel.WindowsAppRuntime
3740
DeploymentInitializeOptions();
3841

3942
/// Gets or sets a value that indicates whether the processes associated with the
40-
/// WindowsAppSDK main and singleton packages will be shut down forcibly if they are
43+
/// WindowsAppSDK Main and Singleton packages will be shut down forcibly if they are
4144
/// currently in use, when registering the WinAppSDK packages.
4245
Boolean ForceDeployment;
4346

@@ -64,5 +67,10 @@ namespace Microsoft.Windows.ApplicationModel.WindowsAppRuntime
6467
[contract(DeploymentContract, 2)]
6568
[overload("Initialize")]
6669
static DeploymentResult Initialize(Microsoft.Windows.ApplicationModel.WindowsAppRuntime.DeploymentInitializeOptions deploymentInitializeOptions);
70+
71+
/// Checks the status of the WindowsAppRuntime of the current package and attempts to
72+
/// repair already installed WinAppSDK packages.
73+
[contract(DeploymentContract, 3)]
74+
static DeploymentResult Repair();
6775
};
6876
}

dev/Deployment/DeploymentActivityContext.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ void WindowsAppRuntime::Deployment::Activity::Context::Reset()
1717
m_deploymentErrorExtendedHresult = S_OK;
1818
m_deploymentErrorText.clear();
1919
m_deploymentErrorActivityId = GUID{};
20+
m_useExistingPackageIfHigherVersion = false;
2021
}
2122

2223
void WindowsAppRuntime::Deployment::Activity::Context::SetDeploymentErrorInfo(

dev/Deployment/DeploymentActivityContext.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ namespace WindowsAppRuntime::Deployment::Activity
3636
GUID m_deploymentErrorActivityId{};
3737
WindowsAppRuntimeDeployment_TraceLogger::Initialize m_activity;
3838
WilFailure m_lastFailure;
39-
bool isFullTrustPackage{};
39+
bool m_isFullTrustPackage{};
40+
bool m_useExistingPackageIfHigherVersion{};
4041

4142
public:
4243
static WindowsAppRuntime::Deployment::Activity::Context& Get();
@@ -78,9 +79,14 @@ namespace WindowsAppRuntime::Deployment::Activity
7879
return m_lastFailure;
7980
}
8081

81-
const bool& GetIsFullTrustPackage() const
82+
const bool GetIsFullTrustPackage() const
8283
{
83-
return isFullTrustPackage;
84+
return m_isFullTrustPackage;
85+
}
86+
87+
const bool GetUseExistingPackageIfHigherVersion() const
88+
{
89+
return m_useExistingPackageIfHigherVersion;
8490
}
8591

8692
void SetInstallStage(const DeploymentStage& installStage)
@@ -112,7 +118,12 @@ namespace WindowsAppRuntime::Deployment::Activity
112118

113119
void SetIsFullTrustPackage()
114120
{
115-
isFullTrustPackage = true;
121+
m_isFullTrustPackage = true;
122+
}
123+
124+
void SetUseExistingPackageIfHigherVersion()
125+
{
126+
m_useExistingPackageIfHigherVersion = true;
116127
}
117128
};
118129

dev/Deployment/DeploymentManager.cpp

Lines changed: 113 additions & 55 deletions
Large diffs are not rendered by default.

dev/Deployment/DeploymentManager.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,30 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
1818
static WindowsAppRuntime::DeploymentResult GetStatus();
1919
static WindowsAppRuntime::DeploymentResult Initialize();
2020
static WindowsAppRuntime::DeploymentResult Initialize(WindowsAppRuntime::DeploymentInitializeOptions const& deploymentInitializeOptions);
21+
static WindowsAppRuntime::DeploymentResult Repair();
2122

2223
private:
2324
static WindowsAppRuntime::DeploymentResult GetStatus(hstring const& packageFullName);
2425
static WindowsAppRuntime::DeploymentResult Initialize(hstring const& packageFullName);
25-
static WindowsAppRuntime::DeploymentResult Initialize(hstring const& packageFullName, WindowsAppRuntime::DeploymentInitializeOptions const& deploymentInitializeOptions);
26+
static WindowsAppRuntime::DeploymentResult Initialize(hstring const& packageFullName,
27+
WindowsAppRuntime::DeploymentInitializeOptions const& deploymentInitializeOptions,
28+
bool isRepair = false);
2629

2730
private:
2831
static WindowsAppRuntime::DeploymentResult _Initialize(
2932
::WindowsAppRuntime::Deployment::Activity::Context& initializeActivityContext,
3033
hstring const& packageFullName,
31-
WindowsAppRuntime::DeploymentInitializeOptions const& deploymentInitializeOptions);
34+
WindowsAppRuntime::DeploymentInitializeOptions const& deploymentInitializeOptions,
35+
bool isRepair);
3236

3337
private:
3438
static MddCore::PackageInfo GetPackageInfoForPackage(std::wstring const& packageFullName);
3539
static std::vector<std::wstring> FindPackagesByFamily(std::wstring const& packageFamilyName);
36-
static HRESULT VerifyPackage(const std::wstring& packageFamilyName, const PACKAGE_VERSION targetVersion);
40+
static HRESULT VerifyPackage(const std::wstring& packageFamilyName, const PACKAGE_VERSION targetVersion, __out std::wstring& matchedPackageFullName);
3741
static std::wstring GetPackagePath(std::wstring const& packageFullName);
38-
static HRESULT AddPackageInBreakAwayProcess(const std::filesystem::path& packagePath, const bool forceDeployment);
42+
static HRESULT AddOrRegisterPackageInBreakAwayProcess(const std::filesystem::path& packagePath, const bool regiterHigherVersionPackage, const bool forceDeployment);
3943
static std::wstring GenerateDeploymentAgentPath();
40-
static HRESULT AddPackage(const std::filesystem::path& packagePath, const bool forceDeployment);
44+
static HRESULT AddOrRegisterPackage(const std::filesystem::path& package, const bool regiterHigherVersionPackage, const bool forceDeployment);
4145
static HRESULT DeployPackages(const std::wstring& frameworkPackageFullName, const bool forceDeployment);
4246
static HRESULT Deploy(const std::wstring& frameworkPackageFullName, const bool forceDeployment = false);
4347
static HRESULT InstallLicenses(const std::wstring& frameworkPackageFullName);

dev/Deployment/DeploymentTraceLogging.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class WindowsAppRuntimeDeployment_TraceLogger final : public wil::TraceLoggingPr
2020
public:
2121

2222
BEGIN_COMPLIANT_CRITICAL_DATA_ACTIVITY_CLASS(Initialize, PDT_ProductAndServicePerformance);
23-
void StartActivity(bool forceDeployment, bool isElevated, bool isPackagedProcess, DWORD integrityLevel)
23+
void StartActivity(bool forceDeployment, bool isElevated, bool isPackagedProcess, bool isFullTrustPackage, DWORD integrityLevel, bool isRepair)
2424
{
2525
// Clear the process-wide callback set in Start
2626
wil::SetResultLoggingCallback(nullptr);
@@ -33,7 +33,9 @@ class WindowsAppRuntimeDeployment_TraceLogger final : public wil::TraceLoggingPr
3333
TraceLoggingValue(forceDeployment, "forceDeployment"),
3434
TraceLoggingValue(isElevated, "isElevated"),
3535
TraceLoggingValue(isPackagedProcess, "isPackagedProcess"),
36-
TraceLoggingValue(integrityLevel, "integrityLevel"));
36+
TraceLoggingValue(isFullTrustPackage, "isFullTrustPackage"),
37+
TraceLoggingValue(integrityLevel, "integrityLevel"),
38+
TraceLoggingValue(isRepair, "isRepairAPI"));
3739
}
3840
void StopWithResult(
3941
HRESULT hresult,
@@ -48,7 +50,7 @@ class WindowsAppRuntimeDeployment_TraceLogger final : public wil::TraceLoggingPr
4850
HRESULT deploymentErrorExtendedHResult,
4951
PCWSTR deploymentErrorText,
5052
GUID deploymentErrorActivityId,
51-
bool isFullTrustPackage)
53+
bool useExistingPackageIfHigherVersion)
5254
{
5355
// Set a process-wide callback function for WIL to call each time it logs a failure.
5456
wil::SetResultLoggingCallback(nullptr);
@@ -69,7 +71,7 @@ class WindowsAppRuntimeDeployment_TraceLogger final : public wil::TraceLoggingPr
6971
TraceLoggingValue(deploymentErrorExtendedHResult, "DeploymentErrorExtendedHResult"),
7072
TraceLoggingValue(deploymentErrorText, "DeploymentErrorText"),
7173
TraceLoggingValue(deploymentErrorActivityId, "DeploymentErrorActivityId"),
72-
TraceLoggingValue(isFullTrustPackage, "isFullTrustPackage"));
74+
TraceLoggingValue(useExistingPackageIfHigherVersion, "useExistingPackageIfHigherVersion"));
7375
}
7476
else
7577
{

dev/Deployment/PackageDefinitions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define WINDOWSAPPRUNTIME_PACKAGE_SUBTYPENAME_DDLM L"DDLM"
1515
#define WINDOWSAPPRUNTIME_FRAMEWORK_PACKAGE_FOLDER L"MSIX"
1616
#define WINDOWSAPPRUNTIME_FRAMEWORK_PACKAGE_FILE_EXTENSION L".msix"
17+
#define WINDOWSAPPRUNTIME_PACKAGE_MANIFEST_FILE L"AppxManifest.xml"
1718

1819
namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implementation
1920
{
@@ -48,4 +49,7 @@ namespace winrt::Microsoft::Windows::ApplicationModel::WindowsAppRuntime::implem
4849
{ WINDOWSAPPRUNTIME_PACKAGE_NAME_MAINPREFIX, WINDOWSAPPRUNTIME_PACKAGE_SUBTYPENAME_MAIN, PackageVersionType::Versioned },
4950
{ WINDOWSAPPRUNTIME_PACKAGE_NAME_SINGLETONPREFIX, WINDOWSAPPRUNTIME_PACKAGE_SUBTYPENAME_SINGLETON, PackageVersionType::Unversioned },
5051
};
52+
53+
// Record existing target package full name(s) to deploy (specifically, re-register) if it's higher version than that of the current framework package version, in this global map.
54+
static std::map<std::wstring, std::wstring> g_existingTargetPackagesIfHigherVersion;
5155
}

dev/DeploymentAgent/main.cpp

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
using namespace winrt::Windows::Foundation;
88

9-
int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
9+
// argv[1] tells whether to use AddPackageAsync (argv[1] == "0") or RegisterPackageAsync (argv[1] == "1") on the path passed in argv[2].
10+
int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int) try
1011
{
1112
int argc{};
1213
const std::wstring cmdLine{ GetCommandLineW() };
@@ -17,22 +18,30 @@ int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
1718
WindowsAppRuntimeDeploymentAgent_TraceLogger::FailedDueToBadArguments(argc);
1819
return HRESULT_FROM_WIN32(ERROR_BAD_ARGUMENTS);
1920
}
20-
std::filesystem::path packagePath{ argv[1] };
21+
22+
bool useExistingPackageIfHigherVersion{};
23+
if (argc >= 2)
24+
{
25+
if (CompareStringOrdinal(argv[1], -1, L"1", -1, TRUE) == CSTR_EQUAL)
26+
{
27+
useExistingPackageIfHigherVersion = true;
28+
}
29+
}
2130

2231
bool forceDeployment{};
23-
if (argc >= 3)
32+
if (argc >= 4)
2433
{
25-
if (CompareStringOrdinal(argv[2], -1, L"1", -1, TRUE) == CSTR_EQUAL)
34+
if (CompareStringOrdinal(argv[3], -1, L"1", -1, TRUE) == CSTR_EQUAL)
2635
{
2736
forceDeployment = true;
2837
}
2938
}
3039

3140
GUID callerActivityId{};
32-
if (argc >= 4)
41+
if (argc >= 5)
3342
{
3443
// Best effort for telemetry purpose and a failure doesn't affect functionality.
35-
std::ignore = CLSIDFromString(argv[3], &callerActivityId);
44+
std::ignore = CLSIDFromString(argv[4], &callerActivityId);
3645
}
3746

3847
winrt::Windows::Management::Deployment::PackageManager packageManager;
@@ -41,30 +50,43 @@ int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int)
4150
winrt::Windows::Management::Deployment::DeploymentOptions::ForceTargetApplicationShutdown :
4251
winrt::Windows::Management::Deployment::DeploymentOptions::None };
4352

44-
const auto packagePathUri{ winrt::Windows::Foundation::Uri(packagePath.c_str()) };
45-
const auto deploymentOperation{ packageManager.AddPackageAsync(packagePathUri, nullptr, options) };
53+
winrt::Windows::Foundation::IAsyncOperationWithProgress<winrt::Windows::Management::Deployment::DeploymentResult,
54+
winrt::Windows::Management::Deployment::DeploymentProgress> deploymentOperation;
55+
const auto pathUri{ winrt::Windows::Foundation::Uri(argv[2]) };
56+
if (useExistingPackageIfHigherVersion)
57+
{
58+
deploymentOperation = packageManager.RegisterPackageAsync(pathUri, nullptr, options); }
59+
else
60+
{
61+
deploymentOperation = packageManager.AddPackageAsync(pathUri, nullptr, options);
62+
}
63+
4664
deploymentOperation.get();
4765
const auto deploymentResult{ deploymentOperation.GetResults() };
4866
if (deploymentOperation.Status() != AsyncStatus::Completed)
4967
{
50-
HRESULT hr = static_cast<HRESULT>(deploymentOperation.ErrorCode());
51-
if (FAILED(hr))
68+
HRESULT deploymentOperationHResult = static_cast<HRESULT>(deploymentOperation.ErrorCode());
69+
HRESULT deploymentOperationExtendedHResult = static_cast<HRESULT>(deploymentResult.ExtendedErrorCode());
70+
if (FAILED(deploymentOperationHResult))
5271
{
5372
WindowsAppRuntimeDeploymentAgent_TraceLogger::FailedInDeployment(
54-
hr,
55-
packagePath.wstring().c_str(),
73+
deploymentOperationHResult,
74+
argv[1],
75+
argv[2],
5676
forceDeployment,
5777
callerActivityId,
58-
deploymentResult.ExtendedErrorCode(),
78+
deploymentOperationExtendedHResult,
5979
deploymentResult.ErrorText().c_str(),
6080
deploymentResult.ActivityId());
6181
}
62-
return deploymentResult.ExtendedErrorCode();
82+
return deploymentOperationExtendedHResult ? deploymentOperationExtendedHResult : deploymentOperationHResult;
6383
}
6484

6585
WindowsAppRuntimeDeploymentAgent_TraceLogger::Success(
66-
packagePath.wstring().c_str(),
86+
argv[1],
87+
argv[2],
6788
forceDeployment,
6889
callerActivityId);
6990
return S_OK;
7091
}
92+
CATCH_RETURN()

dev/DeploymentAgent/tracelogging.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ class WindowsAppRuntimeDeploymentAgent_TraceLogger final : public wil::TraceLogg
1515

1616
public:
1717

18-
DEFINE_COMPLIANT_CRITICAL_DATA_EVENT_PARAM3(
18+
DEFINE_COMPLIANT_CRITICAL_DATA_EVENT_PARAM4(
1919
Success,
2020
PDT_ProductAndServicePerformance,
21-
PCWSTR, packagePath,
21+
bool, useExistingPackageIfHigherVersion,
22+
PCWSTR, path,
2223
bool, forceDeployment,
2324
GUID, callerActivityId);
2425

@@ -27,11 +28,12 @@ class WindowsAppRuntimeDeploymentAgent_TraceLogger final : public wil::TraceLogg
2728
PDT_ProductAndServicePerformance,
2829
UINT32, argsCount);
2930

30-
DEFINE_COMPLIANT_CRITICAL_DATA_EVENT_PARAM7(
31+
DEFINE_COMPLIANT_CRITICAL_DATA_EVENT_PARAM8(
3132
FailedInDeployment,
3233
PDT_ProductAndServicePerformance,
3334
HRESULT, hresult,
34-
PCWSTR, packagePath,
35+
bool, useExistingPackageIfHigherVersion,
36+
PCWSTR, path,
3537
bool, forceDeployment,
3638
GUID, callerActivityId,
3739
HRESULT, deploymentExtendedError,

0 commit comments

Comments
 (0)