RepairPackageCmdlet.cs (3142B)
1 // ----------------------------------------------------------------------------- 2 // <copyright file="RepairPackageCmdlet.cs" company="Microsoft Corporation"> 3 // Copyright (c) Microsoft Corporation. Licensed under the MIT License. 4 // </copyright> 5 // ----------------------------------------------------------------------------- 6 7 namespace Microsoft.WinGet.Client.Commands 8 { 9 using System.Management.Automation; 10 using Microsoft.WinGet.Client.Commands.Common; 11 using Microsoft.WinGet.Client.Common; 12 using Microsoft.WinGet.Client.Engine.Commands; 13 using Microsoft.WinGet.Client.Engine.PSObjects; 14 using Microsoft.WinGet.Client.PSObjects; 15 16 /// <summary> 17 /// This class defines the repair package command. 18 /// </summary> 19 [Cmdlet( 20 VerbsDiagnostic.Repair, 21 Constants.WinGetNouns.Package, 22 DefaultParameterSetName = Constants.FoundSet, 23 SupportsShouldProcess = true)] 24 [OutputType(typeof(PSRepairResult))] 25 public sealed class RepairPackageCmdlet : PackageCmdlet 26 { 27 private RepairPackageCommand command = null; 28 29 /// <summary> 30 /// Gets or sets the desired mode for the repair process. 31 /// </summary> 32 [Parameter(ValueFromPipelineByPropertyName = true)] 33 public PSPackageRepairMode Mode { get; set; } = PSPackageRepairMode.Default; 34 35 /// <summary> 36 /// Gets or sets the path to the logging file. 37 /// </summary> 38 [Parameter] 39 public string Log { get; set; } 40 41 /// <summary> 42 /// Gets or sets a value indicating whether to skip the installer hash validation check. 43 /// </summary> 44 [Parameter(ValueFromPipelineByPropertyName = true)] 45 public SwitchParameter AllowHashMismatch { get; set; } 46 47 /// <summary> 48 /// Gets or sets a value indicating whether to continue upon non security related failures. 49 /// </summary> 50 [Parameter(ValueFromPipelineByPropertyName = true)] 51 public SwitchParameter Force { get; set; } 52 53 /// <summary> 54 /// Repairs a package from the local system. 55 /// </summary> 56 protected override void ProcessRecord() 57 { 58 this.command = new RepairPackageCommand( 59 this, 60 this.AllowHashMismatch.ToBool(), 61 this.Force.ToBool(), 62 this.PSCatalogPackage, 63 this.Version, 64 this.Log, 65 this.Id, 66 this.Name, 67 this.Moniker, 68 this.Source, 69 this.Query); 70 this.command.Repair(this.MatchOption.ToString(), this.Mode.ToString()); 71 } 72 73 /// <summary> 74 /// Interrupts currently running code within the command. 75 /// </summary> 76 protected override void StopProcessing() 77 { 78 if (this.command != null) 79 { 80 this.command.Cancel(); 81 } 82 } 83 } 84 }