winget-cli

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

WinGetRepairException.cs (2465B)


      1 // -----------------------------------------------------------------------------
      2 // <copyright file="WinGetRepairException.cs" company="Microsoft Corporation">
      3 //     Copyright (c) Microsoft Corporation. Licensed under the MIT License.
      4 // </copyright>
      5 // -----------------------------------------------------------------------------
      6 
      7 namespace Microsoft.WinGet.Client.Engine.Exceptions
      8 {
      9     using System;
     10     using System.Management.Automation;
     11     using Microsoft.WinGet.Client.Engine.Common;
     12     using Microsoft.WinGet.Resources;
     13 
     14     /// <summary>
     15     /// WinGet repair exception.
     16     /// </summary>
     17     [Serializable]
     18     public class WinGetRepairException : RuntimeException
     19     {
     20         /// <summary>
     21         /// Initializes a new instance of the <see cref="WinGetRepairException"/> class.
     22         /// </summary>
     23         /// <param name="ie">Integrity exception.</param>
     24         public WinGetRepairException(WinGetIntegrityException ie)
     25             : base(GetMessage(ie), ie)
     26         {
     27         }
     28 
     29         /// <summary>
     30         /// Initializes a new instance of the <see cref="WinGetRepairException"/> class.
     31         /// </summary>
     32         /// <param name="e">Inner exception.</param>
     33         public WinGetRepairException(Exception e)
     34             : base(Resources.RepairFailureMessage, e)
     35         {
     36         }
     37 
     38         /// <summary>
     39         /// Initializes a new instance of the <see cref="WinGetRepairException"/> class.
     40         /// </summary>
     41         public WinGetRepairException()
     42             : base(Resources.RepairFailureMessage)
     43         {
     44         }
     45 
     46         /// <summary>
     47         /// Initializes a new instance of the <see cref="WinGetRepairException"/> class.
     48         /// </summary>
     49         /// <param name="message">Message.</param>.
     50         public WinGetRepairException(string message)
     51             : base(message)
     52         {
     53         }
     54 
     55         private static string GetMessage(WinGetIntegrityException ie)
     56         {
     57             string message = Resources.RepairFailureMessage;
     58             if (ie.Category == IntegrityCategory.AppInstallerNoLicense)
     59             {
     60                 message += $" {Resources.RepairAllUsersHelpMessage}";
     61             }
     62             else if (ie.Category == IntegrityCategory.AppExecutionAliasDisabled)
     63             {
     64                 message += $" {Resources.RepairAppExecutionAliasMessage}";
     65             }
     66 
     67             return message;
     68         }
     69     }
     70 }