Skip to content

Commit

Permalink
bugfix, graphic changes if is on/off, terminate if already running
Browse files Browse the repository at this point in the history
butter fly
  • Loading branch information
piopy committed Apr 14, 2017
1 parent ab49524 commit 658447a
Show file tree
Hide file tree
Showing 21 changed files with 207 additions and 49 deletions.
Binary file modified .vs/Ad_Catch_v1.8/v14/.suo
Binary file not shown.
2 changes: 2 additions & 0 deletions Ad_Catch_v1.0/Ad_Catch.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@
</ItemGroup>
<ItemGroup>
<Content Include="ico.ico" />
<None Include="Resources\ico_stopped_small.png" />
<None Include="Resources\ico_stopped.png" />
<None Include="Resources\host.bmp" />
<EmbeddedResource Include="Resources\ico_small.png" />
<None Include="Resources\hostparental" />
Expand Down
44 changes: 18 additions & 26 deletions Ad_Catch_v1.0/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

105 changes: 86 additions & 19 deletions Ad_Catch_v1.0/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public partial class Form1 : Form
private System.Windows.Forms.ContextMenu contextMenu1= new System.Windows.Forms.ContextMenu();
private System.Windows.Forms.MenuItem menuItem1;
public int status = 0;
public bool elevated;
//cambiare host/hostparental/hostnospotify per generare versioni diverse
public byte[] host= Properties.Resources.host;
//
Expand All @@ -41,6 +42,15 @@ public Form1()

private void Form1_Load(object sender, EventArgs e)
{
//check if is running

if (System.Diagnostics.Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location)).Count() > 1)
{
MessageBox.Show("Another instance of this application is running.");
Close();
return;
}

// check admin or root
bool isElevated;
WindowsIdentity identity = WindowsIdentity.GetCurrent();
Expand All @@ -64,15 +74,26 @@ private void Form1_Load(object sender, EventArgs e)

this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(new System.ComponentModel.Container());
//notifyIcon1.Icon = new Icon(Directory.GetCurrentDirectory() + "\\files\\ico_small.ico"); OLD METHOD

//
System.IntPtr icH = Properties.Resources.ico_stopped_small.GetHicon();
Icon icoStopped = Icon.FromHandle(icH);
icH = Properties.Resources.ico_small.GetHicon();
Icon icoStarted = Icon.FromHandle(icH);

if (status == 0) notifyIcon1.Icon = icoStopped;
else notifyIcon1.Icon = icoStarted;

notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
notifyIcon1.Text = "Ad_Catch_v1.8";
//notifyIcon1.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
notifyIcon1.Text = "Ad_Catch";
notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);
notifyIcon1.ContextMenu = this.contextMenu1;
#endregion

this.FormClosed += FormClosed;


if (status == 0) this.BackgroundImage = Properties.Resources.ico_stopped;
else this.BackgroundImage = Properties.Resources.ico;

if (!isElevated)
{
Expand All @@ -81,7 +102,7 @@ private void Form1_Load(object sender, EventArgs e)
//hostUpdatesToolStripMenuItem.Enabled = false;

}

elevated = isElevated;

}

Expand Down Expand Up @@ -153,7 +174,14 @@ private void button3_Click(object sender, EventArgs e)
if(this.WindowState == FormWindowState.Minimized)
{
this.Hide();
notifyIcon1.Visible = true;
System.IntPtr icH = Properties.Resources.ico_stopped_small.GetHicon();
Icon icoStopped = Icon.FromHandle(icH);
icH = Properties.Resources.ico_small.GetHicon();
Icon icoStarted = Icon.FromHandle(icH);

if (status == 0) notifyIcon1.Icon = icoStopped;
else notifyIcon1.Icon = icoStarted;
notifyIcon1.Visible = true;
}
}

Expand Down Expand Up @@ -194,8 +222,14 @@ private void start()
{
string location = "C:\\Windows\\System32\\drivers\\etc\\hosts";
string backup = "C:\\Windows\\System32\\drivers\\etc\\hosts.backupAdCatch";


if (File.Exists(backup) && this.status == 0)
{
File.Delete(location);
System.IO.File.Copy(backup, location);
File.Delete(backup);
this.status = 0;
}
if (this.status == 1) MessageBox.Show("Service already started!");
if (this.status == 0)
{
Expand All @@ -213,8 +247,9 @@ private void start()
File.WriteAllBytes(location, host);
System.IO.File.AppendAllText(location, targ);
System.IO.File.AppendAllText(location, oldhostcontent); //mette cio che c' era prima nell host

MessageBox.Show("Service successfully started!");
this.BackgroundImage = Properties.Resources.ico;
this.BackColor= System.Drawing.SystemColors.ActiveCaption;
//MessageBox.Show("Service successfully started!");
this.status = 1;
}
}
Expand All @@ -226,32 +261,45 @@ private void stop()
{
string location = "C:\\Windows\\System32\\drivers\\etc\\hosts";
string backup = "C:\\Windows\\System32\\drivers\\etc\\hosts.backupAdCatch";

if (File.Exists(backup) && this.status==0)
{
File.Delete(location);
System.IO.File.Copy(backup, location);
File.Delete(backup);
this.status = 1;
}
if (this.status == 0) MessageBox.Show("Service already stopped!");
if (this.status == 1)
{
if (!File.Exists(location)) { MessageBox.Show("Host file not found"); }
if (!File.Exists(backup)) { MessageBox.Show("Backup file not found"); }
else if (File.Exists(location) && File.Exists(backup))
{
File.Delete(location); //
try { File.Delete(location); }
catch (Exception egeneric)
{
MessageBox.Show("Something went wrong. Try to manually restore backup");
System.Diagnostics.Process.Start("C:\\Windows\\System32\\drivers\\etc\\");
}//
System.IO.File.Copy(backup, location); //ripristina backup
File.Delete(backup); //
MessageBox.Show("Service successfully stopped!");
this.BackgroundImage = Properties.Resources.ico_stopped;
this.BackColor = System.Drawing.SystemColors.ActiveBorder;
// MessageBox.Show("Service successfully stopped!");
this.status = 0;
}
}
}

private void startAdCatchToolStripMenuItem_Click(object sender, EventArgs e)
{
start();
}
//private void startAdCatchToolStripMenuItem_Click(object sender, EventArgs e)
//{
// start();
//}

private void stopAdCatchToolStripMenuItem_Click(object sender, EventArgs e)
{
stop();
}
//private void stopAdCatchToolStripMenuItem_Click(object sender, EventArgs e)
//{
// stop();
//}

private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
Expand All @@ -267,5 +315,24 @@ private void hostUpdatesToolStripMenuItem_Click(object sender, EventArgs e)
{
updatehost();
}

private void OnOffButtonClick(object sender, EventArgs e)
{
if (!elevated) return;
else
{
if (startToolStripMenuItem.Text == "Start")
{
start();
startToolStripMenuItem.Text = "Stop";
}
else if (startToolStripMenuItem.Text == "Stop")
{
stop();
startToolStripMenuItem.Text = "Start";
}
}

}
}
}
8 changes: 4 additions & 4 deletions Ad_Catch_v1.0/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
// Le informazioni generali relative a un assembly sono controllate dal seguente
// set di attributi. Modificare i valori di questi attributi per modificare le informazioni
// associate a un assembly.
[assembly: AssemblyTitle("Ad_Catch_v1.881")]
[assembly: AssemblyTitle("Ad_Catch")]
[assembly: AssemblyDescription("A simple undetectable Ad-Block")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("BurningHAM18")]
[assembly: AssemblyProduct("Ad_Catch_v1.881")]
[assembly: AssemblyProduct("Ad_Catch")]
[assembly: AssemblyCopyright("Copyright © 2016 BurningHAM18")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
Expand All @@ -32,5 +32,5 @@
// È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build
// usando l'asterisco '*' come illustrato di seguito:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.8.0.0")]
[assembly: AssemblyFileVersion("1.8.0.0")]
[assembly: AssemblyVersion("1.8.0.1")]
[assembly: AssemblyFileVersion("1.8.0.1")]
20 changes: 20 additions & 0 deletions Ad_Catch_v1.0/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Ad_Catch_v1.0/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,10 @@
<data name="ico_small" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ico_small.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ico_stopped" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ico_stopped.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ico_stopped_small" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ico_stopped_small.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>
Binary file added Ad_Catch_v1.0/Resources/ico_stopped.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Ad_Catch_v1.0/Resources/ico_stopped_small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Ad_Catch_v1.0/bin/Debug/Ad_Catch.exe
Binary file not shown.
Binary file modified Ad_Catch_v1.0/bin/Debug/Ad_Catch.pdb
Binary file not shown.
Loading

0 comments on commit 658447a

Please sign in to comment.