winget-cli

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

ConfigurationUnitResultInformation.cpp (3753B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #include "pch.h"
      4 #include "ConfigurationUnitResultInformation.h"
      5 #include "AppInstallerErrors.h"
      6 #include "AppInstallerStrings.h"
      7 
      8 namespace winrt::Microsoft::Management::Configuration::implementation
      9 {
     10     namespace
     11     {
     12         ConfigurationUnitResultSource FromHRESULT(hresult resultCode)
     13         {
     14             switch (resultCode)
     15             {
     16                 case WINGET_CONFIG_ERROR_UNIT_NOT_INSTALLED:
     17                 case WINGET_CONFIG_ERROR_UNIT_NOT_FOUND_REPOSITORY:
     18                 case WINGET_CONFIG_ERROR_UNIT_MULTIPLE_MATCHES:
     19                 case WINGET_CONFIG_ERROR_UNIT_IMPORT_MODULE:
     20                 case WINGET_CONFIG_ERROR_UNIT_SETTING_CONFIG_ROOT:
     21                 case WINGET_CONFIG_ERROR_UNIT_IMPORT_MODULE_ADMIN:
     22                     return ConfigurationUnitResultSource::ConfigurationSet;
     23                 case WINGET_CONFIG_ERROR_UNIT_MODULE_CONFLICT:
     24                     return ConfigurationUnitResultSource::SystemState;
     25             }
     26 
     27             return ConfigurationUnitResultSource::Internal;
     28         }
     29 
     30         hstring SanitizeString(std::wstring_view value)
     31         {
     32             using namespace AppInstaller::Utility;
     33             return hstring{ ConvertToUTF16(ConvertControlCodesToPictures(ConvertToUTF8(value))) };
     34         }
     35     }
     36 
     37     void ConfigurationUnitResultInformation::Initialize(const Configuration::IConfigurationUnitResultInformation& other)
     38     {
     39         if (other)
     40         {
     41             m_resultCode = other.ResultCode();
     42             m_description = SanitizeString(other.Description());
     43             m_details = SanitizeString(other.Details());
     44             m_resultSource = other.ResultSource();
     45         }
     46     }
     47 
     48     void ConfigurationUnitResultInformation::Initialize(hresult resultCode, std::wstring_view description)
     49     {
     50         m_resultCode = resultCode;
     51         m_description = SanitizeString(description);
     52         m_resultSource = FromHRESULT(resultCode);
     53     }
     54 
     55     void ConfigurationUnitResultInformation::Initialize(hresult resultCode, hstring description)
     56     {
     57         m_resultCode = resultCode;
     58         m_description = SanitizeString(description);
     59         m_resultSource = FromHRESULT(resultCode);
     60     }
     61 
     62     void ConfigurationUnitResultInformation::Initialize(hresult resultCode, ConfigurationUnitResultSource resultSource)
     63     {
     64         m_resultCode = resultCode;
     65         m_resultSource = resultSource;
     66     }
     67 
     68     void ConfigurationUnitResultInformation::Initialize(hresult resultCode, std::wstring_view description, std::wstring_view details, ConfigurationUnitResultSource resultSource)
     69     {
     70         m_resultCode = resultCode;
     71         m_description = SanitizeString(description);
     72         m_details = SanitizeString(details);
     73         m_resultSource = resultSource;
     74     }
     75 
     76     hresult ConfigurationUnitResultInformation::ResultCode() const
     77     {
     78         return m_resultCode;
     79     }
     80 
     81     void ConfigurationUnitResultInformation::ResultCode(hresult resultCode)
     82     {
     83         m_resultCode = resultCode;
     84     }
     85 
     86     hstring ConfigurationUnitResultInformation::Description()
     87     {
     88         return m_description;
     89     }
     90 
     91     void ConfigurationUnitResultInformation::Description(hstring value)
     92     {
     93         m_description = value;
     94     }
     95 
     96     hstring ConfigurationUnitResultInformation::Details()
     97     {
     98         return m_details;
     99     }
    100 
    101     void ConfigurationUnitResultInformation::Details(hstring value)
    102     {
    103         m_details = value;
    104     }
    105 
    106     ConfigurationUnitResultSource ConfigurationUnitResultInformation::ResultSource() const
    107     {
    108         return m_resultSource;
    109     }
    110 
    111     void ConfigurationUnitResultInformation::ResultSource(ConfigurationUnitResultSource value)
    112     {
    113         m_resultSource = value;
    114     }
    115 }