Exemple #1
0
        public static void Update(Configuration config, bool forceDisable)
        {
            bool global  = config.global;
            bool enabled = config.enabled;

            if (forceDisable)
            {
                enabled = false;
            }

            if (enabled)
            {
                if (global)
                {
                    WinINet.SetIEProxy(true, true, "127.0.0.1:" + config.localPort.ToString(), "");
                }
                else
                {
                    string pacUrl;
                    if (config.useOnlinePac && !config.pacUrl.IsNullOrEmpty())
                    {
                        pacUrl = config.pacUrl;
                    }
                    else
                    {
                        pacUrl = $"http://127.0.0.1:{config.localPort}/pac?t={GetTimestamp(DateTime.Now)}";
                    }
                    WinINet.SetIEProxy(true, false, "", pacUrl);
                }
            }
            else
            {
                WinINet.SetIEProxy(false, false, "", "");
            }
        }
        public static void Update(Configuration config, bool forceDisable)
        {
            int sysProxyMode = config.sysProxyMode;

            if (sysProxyMode == (int)ProxyMode.NoModify)
            {
                return;
            }
            if (forceDisable)
            {
                sysProxyMode = (int)ProxyMode.Direct;
            }
            bool    global  = sysProxyMode == (int)ProxyMode.Global;
            bool    enabled = sysProxyMode != (int)ProxyMode.Direct;
            Version win8    = new Version("6.2");

            //if (Environment.OSVersion.Version.CompareTo(win8) < 0)
            {
                using (RegistryKey registry = OpenUserRegKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", true))
                {
                    try
                    {
                        if (enabled)
                        {
                            if (global)
                            {
                                RegistrySetValue(registry, "ProxyEnable", 1);
                                RegistrySetValue(registry, "ProxyServer", "127.0.0.1:" + config.localPort.ToString());
                                RegistrySetValue(registry, "AutoConfigURL", "");
                            }
                            else
                            {
                                string pacUrl;
                                pacUrl = "http://127.0.0.1:" + config.localPort.ToString() + "/pac?" + "auth=" + config.localAuthPassword + "&t=" + Util.Utils.GetTimestamp(DateTime.Now);
                                RegistrySetValue(registry, "ProxyEnable", 0);
                                RegistrySetValue(registry, "ProxyServer", "");
                                RegistrySetValue(registry, "AutoConfigURL", pacUrl);
                            }
                        }
                        else
                        {
                            RegistrySetValue(registry, "ProxyEnable", 0);
                            RegistrySetValue(registry, "ProxyServer", "");
                            RegistrySetValue(registry, "AutoConfigURL", "");
                        }
                        IEProxyUpdate(config, sysProxyMode);
                        SystemProxy.NotifyIE();
                        //Must Notify IE first, or the connections do not chanage
                        CopyProxySettingFromLan();
                    }
                    catch (Exception e)
                    {
                        Logging.LogUsefulException(e);
                        // TODO this should be moved into views
                        //MessageBox.Show(I18N.GetString("Failed to update registry"));
                    }
                }
            }
            if (Environment.OSVersion.Version.CompareTo(win8) >= 0)
            {
                try
                {
                    if (enabled)
                    {
                        if (global)
                        {
                            WinINet.SetIEProxy(true, true, "127.0.0.1:" + config.localPort.ToString(), "");
                        }
                        else
                        {
                            string pacUrl;
                            pacUrl = $"http://127.0.0.1:{config.localPort}/pac?auth={config.localAuthPassword}&t={Util.Utils.GetTimestamp(DateTime.Now)}";
                            WinINet.SetIEProxy(true, false, "", pacUrl);
                        }
                    }
                    else
                    {
                        WinINet.SetIEProxy(false, false, "", "");
                    }
                }
                catch (Exception ex)
                {
                    Logging.LogUsefulException(ex);
                }
            }
        }
 public static void Disable()
 {
     WinINet.SetIEProxy(false, false, "", "");
 }