winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

RepairWinGetPackageManagerCmdlet.cs (2532B)


      1 // -----------------------------------------------------------------------------
      2 // <copyright file="RepairWinGetPackageManagerCmdlet.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 
     14     /// <summary>
     15     /// Repair-WinGetPackageManager. Repairs winget if needed.
     16     /// </summary>
     17     [Cmdlet(
     18         VerbsDiagnostic.Repair,
     19         Constants.WinGetNouns.WinGetPackageManager,
     20         DefaultParameterSetName = Constants.IntegrityVersionSet)]
     21     [Alias("rpwgpm")]
     22     [OutputType(typeof(int))]
     23     public class RepairWinGetPackageManagerCmdlet : WinGetPackageManagerCmdlet
     24     {
     25         private WinGetPackageManagerCommand command = null;
     26 
     27         /// <summary>
     28         /// Gets or sets a value indicating whether to repair for all users. Requires admin.
     29         /// </summary>
     30         [Parameter(ValueFromPipelineByPropertyName = true)]
     31         public SwitchParameter AllUsers { get; set; }
     32 
     33         /// <summary>
     34         /// Gets or sets a value indicating whether to force application shutdown.
     35         /// </summary>
     36         [Parameter(ValueFromPipelineByPropertyName = true)]
     37         public SwitchParameter Force { get; set; }
     38 
     39         /// <summary>
     40         /// Attempts to repair winget.
     41         /// TODO: consider WhatIf and Confirm options.
     42         /// </summary>
     43         protected override void ProcessRecord()
     44         {
     45             this.command = new WinGetPackageManagerCommand(this);
     46             if (this.ParameterSetName == Constants.IntegrityLatestSet)
     47             {
     48                 this.command.RepairUsingLatest(this.IncludePrerelease.ToBool(), this.AllUsers.ToBool(), this.Force.ToBool());
     49             }
     50             else
     51             {
     52                 this.command.Repair(this.Version, this.AllUsers.ToBool(), this.Force.ToBool());
     53             }
     54         }
     55 
     56         /// <summary>
     57         /// Interrupts currently running code within the command.
     58         /// </summary>
     59         protected override void StopProcessing()
     60         {
     61             if (this.command != null)
     62             {
     63                 this.command.Cancel();
     64             }
     65         }
     66     }
     67 }