Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.

Commit

Permalink
fixeded v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
tetra-fox committed Feb 7, 2016
1 parent f2eac64 commit 4558165
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 11 deletions.
46 changes: 35 additions & 11 deletions AdHate/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,24 @@ public partial class Form1 : Form
public Form1()
{
InitializeComponent();
// backup hosts
if (File.Exists(etc + "hosts") && Settings.Default.firstrun == false || !File.Exists(etc + "hosts.bak"))
try
{
File.Copy(etc + "hosts", etc + "hosts.bak", true);
Settings.Default.firstrun = true;
Settings.Default.Save();
// backup hosts
if (File.Exists(etc + "hosts") && Settings.Default.firstrun == false || !File.Exists(etc + "hosts.bak"))
{
File.Copy(etc + "hosts", etc + "hosts.bak", true);
Settings.Default.firstrun = true;
Settings.Default.Save();
}
}
catch (Exception ex)
{
textBox1.ForeColor = Color.Red;
textBox1.Text = textBox1.Text + "\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;
}
}

Expand All @@ -34,6 +46,8 @@ private void button1_Click(object sender, EventArgs e)
button2.Enabled = false;

// take ownership of hosts
textBox1.Text = "Taking ownership of hosts";

System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
Expand All @@ -43,11 +57,13 @@ private void button1_Click(object sender, EventArgs e)
process.StartInfo = startInfo;
process.Start();

textBox1.Text = "Took ownership of hosts file";
textBox1.Text = textBox1.Text + "\r\nTook ownership of hosts";

progressBar1.Value = 10;

// get mega-hosts file
textBox1.Text = textBox1.Text + "\r\nGetting mega-hosts file";

StringBuilder sb = new StringBuilder();

byte[] buf = new byte[8192];
Expand Down Expand Up @@ -76,18 +92,22 @@ private void button1_Click(object sender, EventArgs e)
}
while (count > 0);

textBox1.Text = textBox1.Text + "\r\nGot mega-hosts file (by StevenBlack)";
textBox1.Text = textBox1.Text + "\r\nGot mega-hosts file (by StevenBlack on GitHub)";

progressBar1.Value = 80;

// write to hosts
File.WriteAllText(etc + "hosts", sb.ToString());
textBox1.Text = textBox1.Text + "\r\nWriting to hosts";

File.AppendAllText(etc + "hosts", "\r\n# Begin mega-hosts file\r\n\r\n" + sb.ToString());

textBox1.Text = textBox1.Text + "\r\nWritten to hosts file";
textBox1.Text = textBox1.Text + "\r\nWritten to hosts";

progressBar1.Value = 90;

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

startInfo.Arguments = "/c ipconfig /flushdns";
process.StartInfo = startInfo;
process.Start();
Expand Down Expand Up @@ -123,6 +143,8 @@ private void button2_Click(object sender, EventArgs e)
button2.Enabled = false;

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

progressBar1.Value = 0;

if (File.Exists(etc + "hosts"))
Expand All @@ -134,9 +156,11 @@ private void button2_Click(object sender, EventArgs e)

progressBar1.Value = 90;

textBox1.Text = "Restored hosts";
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;
Expand Down
Binary file modified AdHate/bin/Debug/AdHate.exe
Binary file not shown.
Binary file modified AdHate/bin/Debug/AdHate.pdb
Binary file not shown.
9 changes: 9 additions & 0 deletions AdHate/obj/Debug/AdHate.csproj.FileListAbsolute.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,12 @@ c:\users\w\documents\visual studio 2015\Projects\AdHate\AdHate\obj\Debug\AdHate.
c:\users\w\documents\visual studio 2015\Projects\AdHate\AdHate\obj\Debug\AdHate.csproj.GenerateResource.Cache
c:\users\w\documents\visual studio 2015\Projects\AdHate\AdHate\obj\Debug\AdHate.exe
c:\users\w\documents\visual studio 2015\Projects\AdHate\AdHate\obj\Debug\AdHate.pdb
C:\Users\w\Documents\GitHub\AdHate\AdHate\bin\Debug\AdHate.exe.config
C:\Users\w\Documents\GitHub\AdHate\AdHate\obj\Debug\AdHate.exe
C:\Users\w\Documents\GitHub\AdHate\AdHate\obj\Debug\AdHate.pdb
C:\Users\w\Documents\GitHub\AdHate\AdHate\bin\Debug\AdHate.exe
C:\Users\w\Documents\GitHub\AdHate\AdHate\bin\Debug\AdHate.pdb
C:\Users\w\Documents\GitHub\AdHate\AdHate\obj\Debug\AdHate.csprojResolveAssemblyReference.cache
C:\Users\w\Documents\GitHub\AdHate\AdHate\obj\Debug\AdHate.Form1.resources
C:\Users\w\Documents\GitHub\AdHate\AdHate\obj\Debug\AdHate.Properties.Resources.resources
C:\Users\w\Documents\GitHub\AdHate\AdHate\obj\Debug\AdHate.csproj.GenerateResource.Cache
Binary file modified AdHate/obj/Debug/AdHate.csproj.GenerateResource.Cache
Binary file not shown.
Binary file modified AdHate/obj/Debug/AdHate.exe
Binary file not shown.
Binary file modified AdHate/obj/Debug/AdHate.pdb
Binary file not shown.
Binary file modified AdHate/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache
Binary file not shown.

0 comments on commit 4558165

Please sign in to comment.