예제 #1
0
        private void applySetting(string id, string name)
        {
            Hashtable ret = Xml.getSettingById(id);

            if (ret == null)
            {
                return;
            }

            foreach (ToolStripMenuItem item in this.ProxyList.DropDownItems)
            {
                item.Checked = item.Name == id;
            }

            Proxies.SetProxy((string)ret["ProxyServer"], (string)ret["ProxyOverride"]);
            string file = Environment.GetEnvironmentVariable("SystemRoot") + @"\system32\drivers\etc\hosts";
            string txt  = File.ReadAllText(file, Encoding.Default);

            txt = Regex.Replace(txt, @"#WhatEver Start[\s\S]+?#WhatEver End\r\n", "");
            string host = ((string)ret["Hosts"]);

            //把Hosts放在 hosts文件的最上面,优先级最高
            File.WriteAllText(file, string.Format("#WhatEver Start\r\n{0}\r\n#WhatEver End\r\n{1}", host, txt), Encoding.Default);
            ShowTips("配置 [" + name + "] 应用成功!");
        }
예제 #2
0
 private void 关闭代理CToolStripMenuItem_Click(object sender, EventArgs e)
 {
     Proxies.UnsetProxy();
     ShowTips("代理关闭成功!");
 }