winget-cli

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

PSInstallResult.cs (4041B)


      1 // -----------------------------------------------------------------------------
      2 // <copyright file="PSInstallResult.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     /// PSInstallResult.
     15     /// </summary>
     16     public sealed class PSInstallResult
     17     {
     18         private readonly InstallResult installResult;
     19         private readonly CatalogPackage catalogPackage;
     20 
     21         /// <summary>
     22         /// Initializes a new instance of the <see cref="PSInstallResult"/> class.
     23         /// </summary>
     24         /// <param name="installResult">The install result COM object.</param>
     25         /// <param name="catalogPackage">The catalog package COM object.</param>
     26         internal PSInstallResult(InstallResult installResult, CatalogPackage catalogPackage)
     27         {
     28             this.installResult = installResult;
     29             this.catalogPackage = catalogPackage;
     30         }
     31 
     32         /// <summary>
     33         /// Gets the id of the installed 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 installed 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 installed 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 install result.
     67         /// </summary>
     68         public string CorrelationData
     69         {
     70             get
     71             {
     72                 return this.installResult.CorrelationData;
     73             }
     74         }
     75 
     76         /// <summary>
     77         /// Gets the error code of an install.
     78         /// </summary>
     79         public uint InstallerErrorCode
     80         {
     81             get
     82             {
     83                 return this.installResult.InstallerErrorCode;
     84             }
     85         }
     86 
     87         /// <summary>
     88         /// Gets the extended error code exception of the failed install result.
     89         /// </summary>
     90         public Exception ExtendedErrorCode
     91         {
     92             get
     93             {
     94                 return this.installResult.ExtendedErrorCode;
     95             }
     96         }
     97 
     98         /// <summary>
     99         /// Gets a value indicating whether a reboot is required.
    100         /// </summary>
    101         public bool RebootRequired
    102         {
    103             get
    104             {
    105                 return this.installResult.RebootRequired;
    106             }
    107         }
    108 
    109         /// <summary>
    110         /// Gets the status of the install.
    111         /// </summary>
    112         public string Status
    113         {
    114             get
    115             {
    116                 return this.installResult.Status.ToString();
    117             }
    118         }
    119 
    120         /// <summary>
    121         /// If the installation succeeded.
    122         /// </summary>
    123         /// <returns>True if installation succeeded.</returns>
    124         public bool Succeeded()
    125         {
    126             return this.installResult.Status == InstallResultStatus.Ok;
    127         }
    128 
    129         /// <summary>
    130         /// Message with error information.
    131         /// </summary>
    132         /// <returns>Error message.</returns>
    133         public string ErrorMessage()
    134         {
    135             return $"InstallStatus '{this.Status}' InstallerErrorCode '{this.InstallerErrorCode}' ExtendedError '{this.ExtendedErrorCode.HResult}'";
    136         }
    137     }
    138 }