winget-cli

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

PSUninstallResult.cs (4141B)


      1 // -----------------------------------------------------------------------------
      2 // <copyright file="PSUninstallResult.cs" company="Microsoft Corporation">
      3 //     Copyright (c) Microsoft Corporation. Licensed under the MIT License.
      4 // </copyright>
      5 // -----------------------------------------------------------------------------
      6 
      7 namespace Microsoft.WinGet.Client.Engine.PSObjects
      8 {
      9     using System;
     10     using Microsoft.Management.Deployment;
     11     using Microsoft.WinGet.Client.Engine.Extensions;
     12 
     13     /// <summary>
     14     /// UninstallResult wrapper object for displaying to PowerShell.
     15     /// </summary>
     16     public sealed class PSUninstallResult
     17     {
     18         private readonly UninstallResult uninstallResult;
     19         private readonly CatalogPackage catalogPackage;
     20 
     21         /// <summary>
     22         /// Initializes a new instance of the <see cref="PSUninstallResult"/> class.
     23         /// </summary>
     24         /// <param name="uninstallResult">The uninstall result COM object.</param>
     25         /// <param name="catalogPackage">The catalog package COM object.</param>
     26         internal PSUninstallResult(UninstallResult uninstallResult, CatalogPackage catalogPackage)
     27         {
     28             this.uninstallResult = uninstallResult;
     29             this.catalogPackage = catalogPackage;
     30         }
     31 
     32         /// <summary>
     33         /// Gets the id of the uninstalled package.
     34         /// </summary>
     35         public string Id
     36         {
     37             get
     38             {
     39                 return this.catalogPackage.Id;
     40             }
     41         }
     42 
     43         /// <summary>
     44         /// Gets the name of the uninstalled package.
     45         /// </summary>
     46         public string Name
     47         {
     48             get
     49             {
     50                 return this.catalogPackage.Name;
     51             }
     52         }
     53 
     54         /// <summary>
     55         /// Gets the source name of the uninstalled package.
     56         /// </summary>
     57         public string? Source
     58         {
     59             get
     60             {
     61                 return this.catalogPackage.GetSourceName();
     62             }
     63         }
     64 
     65         /// <summary>
     66         /// Gets the correlation data of the uninstall result.
     67         /// </summary>
     68         public string CorrelationData
     69         {
     70             get
     71             {
     72                 return this.uninstallResult.CorrelationData;
     73             }
     74         }
     75 
     76         /// <summary>
     77         /// Gets the extended error code exception of the failed uninstall result.
     78         /// </summary>
     79         public Exception ExtendedErrorCode
     80         {
     81             get
     82             {
     83                 return this.uninstallResult.ExtendedErrorCode;
     84             }
     85         }
     86 
     87         /// <summary>
     88         /// Gets a value indicating whether a reboot is required.
     89         /// </summary>
     90         public bool RebootRequired
     91         {
     92             get
     93             {
     94                 return this.uninstallResult.RebootRequired;
     95             }
     96         }
     97 
     98         /// <summary>
     99         /// Gets the status of the uninstall.
    100         /// </summary>
    101         public string Status
    102         {
    103             get
    104             {
    105                 return this.uninstallResult.Status.ToString();
    106             }
    107         }
    108 
    109         /// <summary>
    110         /// Gets the error code of an uninstall.
    111         /// </summary>
    112         public uint UninstallerErrorCode
    113         {
    114             get
    115             {
    116                 return this.uninstallResult.UninstallerErrorCode;
    117             }
    118         }
    119 
    120         /// <summary>
    121         /// If the uninstall succeeded.
    122         /// </summary>
    123         /// <returns>True if uninstall succeeded.</returns>
    124         public bool Succeeded()
    125         {
    126             return this.uninstallResult.Status == UninstallResultStatus.Ok;
    127         }
    128 
    129         /// <summary>
    130         /// Message with error information.
    131         /// </summary>
    132         /// <returns>Error message.</returns>
    133         public string ErrorMessage()
    134         {
    135             return $"UninstallStatus '{this.Status}' UninstallerErrorCode '{this.UninstallerErrorCode}' ExtendedError '{this.ExtendedErrorCode.HResult}'";
    136         }
    137     }
    138 }