Beispiel #1
0
        /// <summary>
        /// Handles the Click event of the useAutoConfigProxyToolStripMenuItem control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void useAutoConfigProxyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            bool useProxy = !useAutoConfigProxyToolStripMenuItem.Checked;

            useAutoConfigProxyToolStripMenuItem.Checked = useProxy;

            if (useProxy)
            {
                string currentAutoConfigURL = ProxySetting.GetCurrentActiveAutoConfigURL();
                AutoConfigScriptPromptForm frmConfigScript = new AutoConfigScriptPromptForm();
                frmConfigScript.txtAddress.Text = currentAutoConfigURL;
                DialogResult result = frmConfigScript.ShowDialog();
                if (result == DialogResult.OK)
                {
                    ProxySetting.ModifyCurrentActiveAutoConfigProxyURL(frmConfigScript.txtAddress.Text);
                }
                else
                {
                    return;
                }
            }

            ProxySetting.ModifyCurrentActiveAutoConfigProxy(useProxy);

            RefreshTrayIcon();
        }
        public static ProxySetting GetCurrentProxyFromInternetExplorer()
        {
            ProxySetting returnProxy = new ProxySetting();

            returnProxy.AutoDetectSettings            = ProxySetting.GetCurrentActiveAutoDetectProxy();
            returnProxy.UseAutoConfigureScript        = ProxySetting.GetCurrentActiveAutoConfigProxy();
            returnProxy.UseAutoConfigureScriptAddress = ProxySetting.GetCurrentActiveAutoConfigURL();
            returnProxy.UseProxyServer = ProxySetting.GetCurrentActiveUseProxy();

            string proxyServerString = ProxySetting.GetCurrentActiveProxyServerURLs();

            if (!string.IsNullOrEmpty(proxyServerString.Trim()))
            {
                string[] proxyServerList = proxyServerString.Split(';');
                if (proxyServerList.Length > 1)
                {
                    returnProxy.UseSameProxyServerForAllProtocols = false;
                    foreach (string aProxyServer in proxyServerList)
                    {
                        string[] proxyServer          = aProxyServer.Split('=');
                        string   type                 = proxyServer[0];
                        string[] serverAddressAndPort = proxyServer[1].Split(':');
                        switch (type)
                        {
                        case ("http"):
                            returnProxy.HTTPProxyAddress = serverAddressAndPort[0];
                            returnProxy.HTTPProxyPort    = serverAddressAndPort[1];
                            break;

                        case ("https"):
                            returnProxy.SecureProxyAddress = serverAddressAndPort[0];
                            returnProxy.SecureProxyPort    = serverAddressAndPort[1];
                            break;

                        case ("ftp"):
                            returnProxy.FTPProxyAddress = serverAddressAndPort[0];
                            returnProxy.FTPProxyPort    = serverAddressAndPort[1];
                            break;

                        case ("gopher"):
                            returnProxy.GopherProxyAddress = serverAddressAndPort[0];
                            returnProxy.GopherProxyPort    = serverAddressAndPort[1];
                            break;

                        case ("socks"):
                            returnProxy.SocksProxyAddress = serverAddressAndPort[0];
                            returnProxy.SocksProxyPort    = serverAddressAndPort[1];
                            break;
                        }
                    }
                }
                else
                {
                    returnProxy.UseSameProxyServerForAllProtocols = true;
                    string[] serverAddressAndPort = proxyServerString.Split(':');
                    returnProxy.UseProxyServerAddress = serverAddressAndPort[0];
                    returnProxy.UseProxyServerPort    = serverAddressAndPort[1];
                }

                returnProxy.Name = "Initial Proxy Settings";
            }

            returnProxy.ExcludeAddressesFromProxy = ProxySetting.GetCurrentActiveBypassProxy();
            if (returnProxy.ExcludeAddressesFromProxy.EndsWith("<local>"))
            {
                returnProxy.BypassProxyForLocalAddress = true;
                returnProxy.ExcludeAddressesFromProxy  = returnProxy.ExcludeAddressesFromProxy.Substring(0, returnProxy.ExcludeAddressesFromProxy.Length - 8);
            }
            else
            {
                returnProxy.BypassProxyForLocalAddress = false;
            }

            return(returnProxy);
        }