Skip to content

Commit

Permalink
Add new repair options and rename error codes (API Review Feedback)
Browse files Browse the repository at this point in the history
Updated `Converters.h` to use `NoApplicableRepairer` instead of `NoApplicableInstallers`. Added handling for `AllowHashMismatch`, `BypassIsStoreClientBlockedPolicyCheck`, and `Force` in `PackageManager.cpp` and `PackageManager.idl`.
- Renamed `NoApplicableInstallers` to `NoApplicableRepairer` and `RepairErrorCode` to `RepairerErrorCode` in `PackageManager.idl`.

Added getter and setter methods for new options in `RepairOptions.cpp` and declarations in `RepairOptions.h`. Updated `RepairResult.cpp` and `RepairResult.h` to use `repairerErrorCode`. Enhanced `RepairPackageCmdlet.cs` and `RepairPackageCommand.cs` to handle new parameters. Updated `PSRepairResult.cs` to use `RepairerErrorCode`.
  • Loading branch information
Madhusudhan-MSFT committed Sep 28, 2024
1 parent c3a2ccb commit e915dde
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Microsoft.Management.Deployment/Converters.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation
resultStatus = TStatus::InvalidOptions;
break;
case APPINSTALLER_CLI_ERROR_NO_APPLICABLE_INSTALLER:
WINGET_GET_OPERATION_RESULT_STATUS(NoApplicableInstallers, InternalError, NoApplicableInstallers, NoApplicableInstallers);
WINGET_GET_OPERATION_RESULT_STATUS(NoApplicableInstallers, InternalError, NoApplicableInstallers, NoApplicableRepairer);
break;
case APPINSTALLER_CLI_ERROR_UPDATE_NOT_APPLICABLE:
case APPINSTALLER_CLI_ERROR_UPGRADE_VERSION_UNKNOWN:
Expand Down
15 changes: 15 additions & 0 deletions src/Microsoft.Management.Deployment/PackageManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,21 @@ namespace winrt::Microsoft::Management::Deployment::implementation
context->Args.AddArg(Execution::Args::Type::AcceptPackageAgreements);
}

if (options.AllowHashMismatch())
{
context->Args.AddArg(Execution::Args::Type::HashOverride);
}

if (options.BypassIsStoreClientBlockedPolicyCheck())
{
context->SetFlags(Execution::ContextFlag::BypassIsStoreClientBlockedPolicyCheck);
}

if (options.Force())
{
context->Args.AddArg(Execution::Args::Type::Force);
}

auto repairScope = GetManifestRepairScope(options.PackageRepairScope());
if (repairScope != ::AppInstaller::Manifest::ScopeEnum::Unknown)
{
Expand Down
13 changes: 11 additions & 2 deletions src/Microsoft.Management.Deployment/PackageManager.idl
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ namespace Microsoft.Management.Deployment
InvalidOptions,
RepairError,
ManifestError,
NoApplicableInstallers,
NoApplicableRepairer,
PackageAgreementsNotAccepted,
};

Expand All @@ -215,7 +215,7 @@ namespace Microsoft.Management.Deployment

/// The error code from the repair attempt. Only valid if the Status is RepairError.
/// This value's meaning will require knowledge of the specific repairer or repair technology.
UInt32 RepairErrorCode { get; };
UInt32 RepairerErrorCode { get; };
}

/// State of the download
Expand Down Expand Up @@ -1189,8 +1189,17 @@ namespace Microsoft.Management.Deployment
/// The string must be JSON encoded.
String CorrelationData;

/// Continues the download even if the hash in the catalog does not match the linked installer used for repair.
Boolean AllowHashMismatch;

/// Directs the logging to a log file. If provided, the installer must have write access to the file
String LogOutputPath;

/// Force the operation to continue upon non security related failures.
Boolean Force;

/// Bypasses the Disabled Store Policy
Boolean BypassIsStoreClientBlockedPolicyCheck;
}

/// IMPLEMENTATION NOTE: Documentation from AppInstaller::Manifest::Documentation
Expand Down
30 changes: 30 additions & 0 deletions src/Microsoft.Management.Deployment/RepairOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,35 @@ namespace winrt::Microsoft::Management::Deployment::implementation
m_correlationData = value;
}

bool RepairOptions::AllowHashMismatch()
{
return m_allowHashMismatch;
}

void RepairOptions::AllowHashMismatch(bool value)
{
m_allowHashMismatch = value;
}

bool RepairOptions::BypassIsStoreClientBlockedPolicyCheck()
{
return m_bypassIsStoreClientBlockedPolicyCheck;
}

void RepairOptions::BypassIsStoreClientBlockedPolicyCheck(bool value)
{
m_bypassIsStoreClientBlockedPolicyCheck = value;
}

bool RepairOptions::Force()
{
return m_force;
}

void RepairOptions::Force(bool value)
{
m_force = value;
}

CoCreatableMicrosoftManagementDeploymentClass(RepairOptions);
}
10 changes: 10 additions & 0 deletions src/Microsoft.Management.Deployment/RepairOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,21 @@ namespace winrt::Microsoft::Management::Deployment::implementation
void LogOutputPath(hstring const& value);
hstring CorrelationData();
void CorrelationData(hstring const& value);
bool AllowHashMismatch();
void AllowHashMismatch(bool value);
bool BypassIsStoreClientBlockedPolicyCheck();
void BypassIsStoreClientBlockedPolicyCheck(bool value);
bool Force();
void Force(bool value);


#if !defined(INCLUDE_ONLY_INTERFACE_METHODS)
private:
winrt::Microsoft::Management::Deployment::PackageVersionId m_packageVersionId{ nullptr };
bool m_acceptPackageAgreements = false;
bool m_allowHashMismatch = false;
bool m_bypassIsStoreClientBlockedPolicyCheck = false;
bool m_force = false;
std::wstring m_logOutputPath = L"";
std::wstring m_correlationData = L"";
winrt::Microsoft::Management::Deployment::PackageRepairScope m_packageRepairScope = winrt::Microsoft::Management::Deployment::PackageRepairScope::Any;
Expand Down
8 changes: 4 additions & 4 deletions src/Microsoft.Management.Deployment/RepairResult.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ namespace winrt::Microsoft::Management::Deployment::implementation
void RepairResult::Initialize(
winrt::Microsoft::Management::Deployment::RepairResultStatus status,
winrt::hresult extendedErrorCode,
uint32_t repairErrorCode,
uint32_t repairerErrorCode,
hstring const& correlationData,
bool rebootRequired)
{
m_status = status;
m_extendedErrorCode = extendedErrorCode;
m_repairErrorCode = repairErrorCode;
m_repairerErrorCode = repairerErrorCode;
m_correlationData = correlationData;
m_rebootRequired = rebootRequired;
}
Expand All @@ -37,8 +37,8 @@ namespace winrt::Microsoft::Management::Deployment::implementation
{
return m_extendedErrorCode;
}
uint32_t RepairResult::RepairErrorCode()
uint32_t RepairResult::RepairerErrorCode()
{
return m_repairErrorCode;
return m_repairerErrorCode;
}
}
6 changes: 3 additions & 3 deletions src/Microsoft.Management.Deployment/RepairResult.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace winrt::Microsoft::Management::Deployment::implementation
void Initialize(
winrt::Microsoft::Management::Deployment::RepairResultStatus status,
winrt::hresult extendedErrorCode,
uint32_t repairErrorCode,
uint32_t repairerErrorCode,
hstring const& correlationData,
bool rebootRequired);
#endif
Expand All @@ -22,15 +22,15 @@ namespace winrt::Microsoft::Management::Deployment::implementation
bool RebootRequired();
winrt::Microsoft::Management::Deployment::RepairResultStatus Status();
winrt::hresult ExtendedErrorCode();
uint32_t RepairErrorCode();
uint32_t RepairerErrorCode();

#if !defined(INCLUDE_ONLY_INTERFACE_METHODS)
private:
std::wstring m_correlationData = L"";
bool m_rebootRequired = false;
winrt::Microsoft::Management::Deployment::RepairResultStatus m_status = winrt::Microsoft::Management::Deployment::RepairResultStatus::Ok;
winrt::hresult m_extendedErrorCode = S_OK;
uint32_t m_repairErrorCode = 0;
uint32_t m_repairerErrorCode = 0;
#endif
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,27 @@ public sealed class RepairPackageCmdlet : PackageCmdlet
[Parameter]
public string Log { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to skip the installer hash validation check.
/// </summary>
[Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter AllowHashMismatch { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to continue upon non security related failures.
/// </summary>
[Parameter(ValueFromPipelineByPropertyName = true)]
public SwitchParameter Force { get; set; }

/// <summary>
/// Repairs a package from the local system.
/// </summary>
protected override void ProcessRecord()
{
this.command = new RepairPackageCommand(
this,
this.AllowHashMismatch.ToBool(),
this.Force.ToBool(),
this.PSCatalogPackage,
this.Version,
this.Log,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public sealed class RepairPackageCommand : PackageCommand
/// </summary>
/// <param name="psCmdlet">Caller cmdlet.</param>
/// <param name="psCatalogPackage">PSCatalogPackage.</param>
/// <param name="allowHashMismatch">To skip the installer hash validation check.</param>
/// <param name="force">To continue upon non security related failures.</param>
/// <param name="version">Version to repair.</param>
/// <param name="log">Logging file location.</param>
/// <param name="id">Package identifier.</param>
Expand All @@ -34,6 +36,8 @@ public sealed class RepairPackageCommand : PackageCommand
/// <param name="query">Match against any field of a package.</param>
public RepairPackageCommand(
PSCmdlet psCmdlet,
bool allowHashMismatch,
bool force,
PSCatalogPackage psCatalogPackage,
string version,
string log,
Expand All @@ -44,6 +48,9 @@ public RepairPackageCommand(
string[] query)
: base(psCmdlet)
{
this.Force = force;
this.AllowHashMismatch = allowHashMismatch;

if (psCatalogPackage != null)
{
this.CatalogPackage = psCatalogPackage;
Expand All @@ -65,6 +72,16 @@ public RepairPackageCommand(
/// </summary>
private string? Log { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to continue upon non security related failures.
/// </summary>
private bool Force { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to skip the installer hash validation check.
/// </summary>
private bool AllowHashMismatch { get; set; }

/// <summary>
/// Process repair package.
/// </summary>
Expand Down Expand Up @@ -95,6 +112,8 @@ private RepairOptions GetRepairOptions(
PackageRepairMode repairMode)
{
var options = ManagementDeploymentFactory.Instance.CreateRepairOptions();
options.AllowHashMismatch = this.AllowHashMismatch;
options.Force = this.Force;

if (this.Log != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public uint RepairErrorCode
{
get
{
return this.repairResult.RepairErrorCode;
return this.repairResult.RepairerErrorCode;
}
}

Expand Down

0 comments on commit e915dde

Please sign in to comment.