private void stopButton_Click(object sender, EventArgs e) { stopButton.Text = "Stopping..."; stopButton.Enabled = false; startButton.Enabled = false; updateButton.Enabled = false; string log; try { _controller.Stop(); SystemProxy.SetProxy(false); log = DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss] ") + "Stop Success, DNSlocal stopped, unset system proxy ok, DNS automatically" + Environment.NewLine; stopButton.Text = "Stopped"; startButton.Text = "Start"; startButton.Enabled = true; stopButton.Enabled = false; updateButton.Enabled = true; } catch (Exception ex) { log = DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss] ") + "Stop Failed..." + Environment.NewLine + ex.ToString() + Environment.NewLine; stopButton.Text = "Stop"; startButton.Enabled = false; stopButton.Enabled = true; updateButton.Enabled = true; } logTextBox.AppendText(log); }
private void startButton_Click(object sender, EventArgs e) { startButton.Text = "Starting..."; startButton.Enabled = false; stopButton.Enabled = false; updateButton.Enabled = false; string log; try { if (deleteHostsCheckBox.Checked) { if (File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "drivers/etc/hosts"))) { File.Delete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "drivers/etc/hosts")); } } _controller.Start(); SystemProxy.SetProxy(true); log = DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss] ") + "Start Success, set http proxy ok, DNS set 127.0.0.1/::1" + Environment.NewLine; startButton.Text = "Started"; startButton.Enabled = false; stopButton.Text = "Stop"; stopButton.Enabled = true; updateButton.Enabled = true; } catch (Exception ex) { log = DateTime.Now.ToString("[yyyy-MM-dd HH:mm:ss] ") + "Start Failed..." + Environment.NewLine + ex.ToString() + Environment.NewLine; startButton.Text = "Start"; startButton.Enabled = true; stopButton.Enabled = true; updateButton.Enabled = true; } logTextBox.AppendText(log); }