private void InitHostPath() { try { hostAction = new HostAction(Environment.SystemDirectory + "\\drivers\\etc\\hosts"); } catch { hostEnable = false; } }
private void formLogin_Load(object sender, EventArgs e) { try { string path=Environment.SystemDirectory + "\\drivers\\etc\\hosts"; if (System.IO.File.Exists(path)) { HostAction hostAction = new HostAction(path); hostAction.RestoreHosts(); } else { formSelectTicket.hostEnable = false; MessageBox.Show("没有找到hosts文件,请新建后重新启动本程序以恢复自动切换功能,否则切换功能将不可用.", "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } catch(Exception ex) { formSelectTicket.hostEnable = false; MessageBox.Show(string.Format("由于加载Hosts文件失败,失败原因:{0}\r\n可能导致软件的IP切换功能无效,如果想启用,请允许程序访问Hosts文件或者去除Hosts文件的保护,然后重新启动本程序", ex.Message), "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning); } ConfigInfo.readfromfile(); txtName.Text =EncodeAndDecode.DecodeBase64(EncodeAndDecode.DecodeBase64(ConfigInfo.conf.username)); txtPwd.Text = EncodeAndDecode.DecodeBase64(EncodeAndDecode.DecodeBase64(ConfigInfo.conf.password)); IntPtr o = this.Handle; GetRandCodeImg(); formStyle.ShowForm(this.Handle, 500); }