AdHate.Form1.button2_Click C# (CSharp) Method

button2_Click() private method

private button2_Click ( object sender, EventArgs e ) : void
sender object
e System.EventArgs
return void
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                // just in case
                textBox1.ForeColor = Color.White;
                button1.Enabled = false;
                button2.Enabled = false;

                // restore hosts
                textBox1.Text = "Restoring hosts";

                progressBar1.Value = 0;

                if (File.Exists(etc + "hosts"))
                {
                    File.Delete(etc + "hosts");
                }

                File.Copy(etc + "hosts.bak", etc + "hosts", true);

                progressBar1.Value = 90;

                textBox1.Text = textBox1.Text + "\r\nRestored hosts";

                // flush dns
                textBox1.Text = textBox1.Text + "\r\nFlushing DNS cache";

                System.Diagnostics.Process process = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
                startInfo.FileName = "cmd.exe";
                startInfo.Arguments = "/c ipconfig /flushdns";
                process.StartInfo = startInfo;
                process.Start();

                textBox1.Text = textBox1.Text + "\r\nFlushed DNS cache\r\nDone.";

                textBox1.ForeColor = Color.Lime;

                progressBar1.Value = 100;
                button1.Enabled = true;
                button2.Enabled = true;
            }
            // if more bad things happen
            catch (Exception ex)
            {
                textBox1.ForeColor = Color.Red;
                textBox1.Text = textBox1.Text + "\r\n\r\nWARNING: " + Convert.ToString(ex);
                textBox1.Text = textBox1.Text + "\r\nNo changes to your system have been made.";
                progressBar1.Value = 0;
                button1.Enabled = true;
                button2.Enabled = true;
            }
        }