Пример #1
0
        private static void ConfigGradle(UrlTemplate urlTemplate)
        {
            // Configure gradle
            if (Msdos.IsInstalled("gradle"))
            {
                var gradlePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile));

                if (urlTemplate.ClearData)
                {
                    logger.Info("Clearing proxy for gradle");
                    StringBuilder sb = new StringBuilder();
                    File.WriteAllText(Path.Combine(gradlePath, ".gradle.properties"), sb.ToString());
                }
                else
                {
                    logger.Info("Setting proxy for gradle");

                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine($"systemProp.http.proxyHost=={urlTemplate.GetHost()}");
                    sb.AppendLine($"systemProp.http.proxyPort={urlTemplate.GetPort()}");
                    sb.AppendLine($"systemProp.http.nonProxyHosts={urlTemplate.GetProxyExceptions()}");
                    sb.AppendLine($"systemProp.https.proxyHost=={urlTemplate.GetHost()}");
                    sb.AppendLine($"systemProp.https.proxyPort={urlTemplate.GetPort()}");
                    sb.AppendLine($"systemProp.https.nonProxyHosts={urlTemplate.GetProxyExceptions()}");

                    File.WriteAllText(Path.Combine(gradlePath, ".gradle.properties"), sb.ToString());
                }
            }
        }
Пример #2
0
        private static string RenderConfigFileGradle(UrlTemplate urlTemplate)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine($"systemProp.http.proxyHost=={urlTemplate.GetHost()}");
            sb.AppendLine($"systemProp.http.proxyPort={urlTemplate.GetPort()}");
            sb.AppendLine($"systemProp.http.nonProxyHosts={urlTemplate.GetProxyExceptions()}");
            sb.AppendLine($"systemProp.https.proxyHost=={urlTemplate.GetHost()}");
            sb.AppendLine($"systemProp.https.proxyPort={urlTemplate.GetPort()}");
            sb.AppendLine($"systemProp.https.nonProxyHosts={urlTemplate.GetProxyExceptions()}");
            return(sb.ToString());
        }
Пример #3
0
        private static void ConfigBower(UrlTemplate urlTemplate)
        {
            // Configure bower
            if (Msdos.IsInstalled("bower.cmd"))
            {
                // bowerrc user file
                var bowerrc = Path.Combine(Windows.GetCurrentUserFolder(), ".bowerrc");

                if (urlTemplate.ClearData)
                {
                    logger.Info("Clearing proxy for bower");
                    Msdos.Run("npm.cmd", $@"config delete proxy");
                    Msdos.Run("npm.cmd", $@"config delete https-proxy");

                    if (File.Exists(bowerrc))
                    {
                        System.IO.File.Delete(bowerrc);
                    }
                }
                else
                {
                    logger.Info("Setting proxy for bower");
                    Msdos.Run("npm.cmd", $@"npm config set proxy {urlTemplate.GetProxy()}");
                    Msdos.Run("npm.cmd", $@"npm config set https-proxy {urlTemplate.GetProxySsl()}");

                    if (!File.Exists(bowerrc))
                    {
                        // create settings
                        var obj = new JObject();
                        obj.Add("proxy", urlTemplate.GetProxy());
                        obj.Add("https-proxy", urlTemplate.GetProxySsl());
                        obj.Add("no-proxy", urlTemplate.GetProxyExceptions());

                        System.IO.File.WriteAllText(bowerrc, obj.ToString());
                    }
                    else
                    {
                        // update settings
                        var content = System.IO.File.ReadAllText(bowerrc);
                        var obj     = JObject.Parse(content);
                        obj["proxy"]       = urlTemplate.GetProxy();
                        obj["https-proxy"] = urlTemplate.GetProxySsl();
                        obj["no-proxy"]    = urlTemplate.GetProxyExceptions();

                        System.IO.File.WriteAllText(bowerrc, obj.ToString());
                    }
                }
            }
        }
Пример #4
0
 private static void ConfigInternetSettings(UrlTemplate urlTemplate)
 {
     // Configure control panel
     if (urlTemplate.ClearData)
     {
         logger.Info("Clearing control panel");
         LanSettings.DisableProxy();
         LanSettings.ClearExceptions();
     }
     else
     {
         logger.Info("Setting control panel");
         LanSettings.SetProxy(urlTemplate.GetProxy(true));
         LanSettings.ClearExceptions();
         if (!string.IsNullOrEmpty(urlTemplate.GetProxyExceptions()))
         {
             LanSettings.AddExceptions($"{urlTemplate.GetProxyExceptions()}");
         }
         LanSettings.SetExceptionForLocal(true);
     }
 }
Пример #5
0
        private static void ConfigChocolatey(UrlTemplate urlTemplate)
        {
            // Configure CHOCOLATEY
            if (Msdos.IsInstalled("choco.exe", "--version"))
            {
                if (urlTemplate.ClearData)
                {
                    logger.Info("Clearing proxy for chocolatey");
                    Msdos.Run("choco.exe", $@"config unset proxy");
                    Msdos.Run("choco.exe", $@"config unset proxyUser");
                    Msdos.Run("choco.exe", $@"config unset proxyPassword");
                    Msdos.Run("choco.exe", $@"config unset proxyBypassList");
                    Msdos.Run("choco.exe", $@"config unset proxyBypassOnLocal");
                }
                else
                {
                    logger.Info("Setting proxy for chocolatey");
                    Msdos.Run("choco.exe", $@"config set proxy {urlTemplate.GetProxy()}");

                    if (!string.IsNullOrEmpty(urlTemplate.GetProxyUsername()))
                    {
                        Msdos.Run("choco.exe", $@"config set proxyUser {urlTemplate.GetProxyUsername()}");
                    }

                    if (!string.IsNullOrEmpty(urlTemplate.GetProxyPassword()))
                    {
                        Msdos.Run("choco.exe", $@"config set proxyPassword {urlTemplate.GetProxyPassword()}");
                    }

                    if (!string.IsNullOrEmpty(urlTemplate.GetProxyExceptions()))
                    {
                        Msdos.Run("choco.exe", $@"config set proxyBypassList ""{urlTemplate.GetProxyExceptions()}");
                    }

                    Msdos.Run("choco.exe", $@"config set proxyBypassOnLocal true");
                }
            }
        }