winget-cli

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

NetworkSettings.cpp (1999B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #include "pch.h"
      4 #include "winget/NetworkSettings.h"
      5 #include "winget/AdminSettings.h"
      6 #include "AppInstallerLogging.h"
      7 
      8 namespace AppInstaller::Settings
      9 {
     10     void NetworkSettings::SetProxyUri(const std::optional<std::string>& proxyUri)
     11     {
     12         AICLI_LOG(Core, Info, << "Setting proxy");
     13 
     14         if (proxyUri)
     15         {
     16             m_proxyUri = proxyUri.value();
     17             AICLI_LOG(Core, Info, << "New value for proxy is " << m_proxyUri.value());
     18         }
     19         else
     20         {
     21             m_proxyUri.reset();
     22             AICLI_LOG(Core, Info, << "Proxy will not be used");
     23         }
     24     }
     25 
     26     InstallerDownloader NetworkSettings::GetInstallerDownloader() const
     27     {
     28         // The default is DeliveryOptimization.
     29         // We use WinINet if specified by settings, or if we want to use proxy (as DO does not support that)
     30         InstallerDownloader setting = User().Get<Setting::NetworkDownloader>();
     31 
     32         if (m_proxyUri && setting != InstallerDownloader::WinInet)
     33         {
     34             AICLI_LOG(Core, Info, << "Forcing use of wininet for download as DO does not support proxy");
     35             return InstallerDownloader::WinInet;
     36         }
     37         else if (setting == InstallerDownloader::Default)
     38         {
     39             return InstallerDownloader::DeliveryOptimization;
     40         }
     41         else
     42         {
     43             return setting;
     44         }
     45     }
     46 
     47     NetworkSettings::NetworkSettings()
     48     {
     49         // Get the default proxy
     50         try
     51         {
     52             m_proxyUri = GetAdminSetting(StringAdminSetting::DefaultProxy);
     53         }
     54         CATCH_LOG()
     55         AICLI_LOG(Core, Info, << "Default proxy is " << (m_proxyUri ? m_proxyUri.value() : "not set"));
     56     }
     57 
     58     NetworkSettings& NetworkSettings::Instance()
     59     {
     60         static NetworkSettings networkSettings;
     61         return networkSettings;
     62     }
     63 
     64     NetworkSettings& Network()
     65     {
     66         return NetworkSettings::Instance();
     67     }
     68 }