Example #1
0
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ProxySettingItem item = new ProxySettingItem();

            item.Name = "New Item";
            this.ProxyEntries.Add(item);
            LoadUIList();
        }
Example #2
0
        private void SetProxy(ProxySettingItem proxy)
        {
            CurrentlyAppliedProxy = proxy;
            RegistryKey registry = Registry.CurrentUser.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings", true);

            if (proxy == null || (proxy != null && string.IsNullOrEmpty(proxy.Proxy) && string.IsNullOrEmpty(proxy.Port)))
            {
                registry.SetValue("ProxyEnable", 0);
                registry.SetValue("ProxyServer", "");
                registry.SetValue("ProxyUser", "");
                registry.SetValue("ProxyPass", "");
                registry.SetValue("ProxyOverride", "");
            }
            else
            {
                registry.SetValue("ProxyEnable", 1);
                registry.SetValue("ProxyServer", proxy.Proxy + ":" + proxy.Port);
                if (!string.IsNullOrEmpty(proxy.Username) && !string.IsNullOrEmpty(proxy.Password))
                {
                    registry.SetValue("ProxyUser", proxy.Username);
                    registry.SetValue("ProxyPass", StringEncryption.Unprotect(proxy.Password));
                }
                else
                {
                    registry.SetValue("ProxyUser", "");
                    registry.SetValue("ProxyPass", "");
                }

                if (proxy.Bypass)
                {
                    registry.SetValue("ProxyOverride", "<local>");
                }
                else
                {
                    registry.SetValue("ProxyOverride", "");
                }
            }

            settingsReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_SETTINGS_CHANGED, IntPtr.Zero, 0);
            refreshReturn  = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_REFRESH, IntPtr.Zero, 0);

            notifyIcon1.BalloonTipText = "Proxy Change (" + proxy.Name + ":" + proxy.NetworkID + ":" + proxy.Proxy + ":" + proxy.Port + ")";
            notifyIcon1.Text           = "Proxy (" + proxy.Name + ":" + proxy.NetworkID + ":" + proxy.Proxy + ":" + proxy.Port + ")";
            notifyIcon1.ShowBalloonTip(3000);
        }
Example #3
0
        public void LoadJson()
        {
            this.ProxyEntries = new List <ProxySwitcher.ProxySettingItem>();
            using (StreamReader r = new StreamReader("proxySettings.json"))
            {
                string json = r.ReadToEnd();
                this.ProxyEntries = JsonConvert.DeserializeObject <List <ProxySettingItem> >(json);
            }

            if (this.ProxyEntries.Count(x => x.Name.ToLower() == "default") == 0)
            {
                ProxySettingItem item = new ProxySettingItem();
                item.Name = "Default";
                this.ProxyEntries.Add(item);

                SaveJson();
            }
        }
Example #4
0
        private void CheckNetwork(object sender, ElapsedEventArgs e)
        {
            GetConnectedNetworkNames();

            //if current network already has proxy set
            if (CurrentlyAppliedProxy != null)
            {
                foreach (string network in ConnectedNetworks)
                {
                    if (!string.IsNullOrEmpty(CurrentlyAppliedProxy.NetworkID) && CurrentlyAppliedProxy.NetworkID.ToLower() == network.ToLower())
                    {
                        return;
                    }
                }
            }

            foreach (string network in ConnectedNetworks)
            {
                foreach (ProxySettingItem proxy in ProxyEntries)
                {
                    if (proxy != CurrentlyAppliedProxy && !string.IsNullOrEmpty(proxy.NetworkID) && network.ToLower() == proxy.NetworkID.ToLower())
                    {
                        //match found
                        SetProxy(proxy);
                        return;
                    }
                }
            }

            ProxySettingItem defaultProxy = ProxyEntries.SingleOrDefault(x => x.Name.ToLower() == "default");

            if (defaultProxy != CurrentlyAppliedProxy)
            {
                SetProxy(defaultProxy);
            }
        }