Skip to content

Commit

Permalink
* some minor code changes
Browse files Browse the repository at this point in the history
- removed hotkey and NBUG for the time being
+ flushing DNS cache after changing DNS servers
  • Loading branch information
tryallthethings committed Jan 8, 2018
1 parent fc9ae49 commit e256b5f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 56 deletions.
15 changes: 4 additions & 11 deletions DNS-Swapper.sln
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.6
VisualStudioVersion = 15.0.27130.2010
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DNS-Swapper", "DNS-Swapper\DNS-Swapper.csproj", "{F2D68472-7913-4EF2-901E-4828BC05D7AD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "swap", "swap\swap.csproj", "{5005E928-8655-48BC-9A8B-C9471C1651DF}"
EndProject
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "Installer", "Installer\Installer.vdproj", "{C5A1A57E-C104-46E9-AC97-D88F88F692AA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NBug", "..\GitHub\NBug\NBug\NBug.csproj", "{62CED1D5-F603-40DE-8BF5-3E49D3A392F4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -41,16 +39,11 @@ Global
{C5A1A57E-C104-46E9-AC97-D88F88F692AA}.Release|Any CPU.ActiveCfg = Release
{C5A1A57E-C104-46E9-AC97-D88F88F692AA}.Release|x64.ActiveCfg = Release
{C5A1A57E-C104-46E9-AC97-D88F88F692AA}.Release|x64.Build.0 = Release
{62CED1D5-F603-40DE-8BF5-3E49D3A392F4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{62CED1D5-F603-40DE-8BF5-3E49D3A392F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{62CED1D5-F603-40DE-8BF5-3E49D3A392F4}.Debug|x64.ActiveCfg = Debug|Any CPU
{62CED1D5-F603-40DE-8BF5-3E49D3A392F4}.Debug|x64.Build.0 = Debug|Any CPU
{62CED1D5-F603-40DE-8BF5-3E49D3A392F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{62CED1D5-F603-40DE-8BF5-3E49D3A392F4}.Release|Any CPU.Build.0 = Release|Any CPU
{62CED1D5-F603-40DE-8BF5-3E49D3A392F4}.Release|x64.ActiveCfg = Release|Any CPU
{62CED1D5-F603-40DE-8BF5-3E49D3A392F4}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C3499FC6-5C15-4C9A-9B69-023690904708}
EndGlobalSection
EndGlobal
6 changes: 0 additions & 6 deletions DNS-Swapper/DNS-Swapper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,6 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\GitHub\NBug\NBug\NBug.csproj">
<Project>{62ced1d5-f603-40de-8bf5-3e49d3a392f4}</Project>
<Name>NBug</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
Expand Down
36 changes: 11 additions & 25 deletions DNS-Swapper/MainMenu.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NBug.Events;
using System;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
Expand All @@ -13,30 +12,15 @@ namespace DNS_Swapper
{
public partial class MainMenu : Form
{
public static string version = "b/1.1";
public static string version = "b/1.2";

public MainMenu()
{
InitializeComponent();
//WindowState = FormWindowState.Minimized;
//ShowInTaskbar = false;
//this.Hide();

//add handler on application load
NBug.Settings.CustomSubmissionEvent += Settings_CustomSubmissionEvent;

// Custom Submission Event handler
void Settings_CustomSubmissionEvent(object sender, CustomSubmissionEventArgs e)
{
//your sumbmission code here...
MessageBox.Show(e.FileName.ToString());
//
// var url = "mailto:[email protected]?subject=DNS-Swapper&body=crash";
// Process.Start(url);
//tell NBug if submission was successfull or not
e.Result = true;
}


WindowState = FormWindowState.Minimized;
ShowInTaskbar = false;

// Load network interfaces
foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
{
Expand Down Expand Up @@ -154,7 +138,7 @@ private void SwapDNS()
else if (DNS_servers.Equals(IPAddress.Parse(Regex.Replace(DNS_2.Text, @"\s+", ""))))
{
callSwapDNS(NIC_select.SelectedItem.ToString(), Regex.Replace(DNS_1.Text, @"\s+", ""));

if (NetworkManagement.getDNS().Equals(IPAddress.Parse(Regex.Replace(DNS_1.Text, @"\s+", ""))))
{
taskBarIcon.Icon = Resource1.icon_red;
Expand All @@ -166,12 +150,13 @@ private void SwapDNS()
taskBarIcon.Icon = Resource1.error;
}
}
NetworkManagement.FlushDNSCache();
}
else
{
MessageBox.Show("Please select a network interface and enter 2 valid IPs", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

}

private void exitToolStripMenuItem1_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -246,6 +231,7 @@ private void openToolStripMenuItem_Click(object sender, EventArgs e)
Show();
WindowState = FormWindowState.Normal;
ShowInTaskbar = true;
//RegisterHotKey(this.Handle, MYACTION_HOTKEY_ID, 0, (int)Keys.F11);
}

private void taskBarIcon_Click(object sender, MouseEventArgs e)
Expand Down Expand Up @@ -324,4 +310,4 @@ private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
MessageBox.Show(versiontext, "About", MessageBoxButtons.OK);
}
}
}
}
10 changes: 10 additions & 0 deletions DNS-Swapper/NetworkManagement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Management;
using System.Net;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices;

namespace DNS_Swapper
{
Expand Down Expand Up @@ -191,6 +192,15 @@ public void setWINS(string NIC, string priWINS, string secWINS)
}
}
}


[DllImport("dnsapi.dll", EntryPoint = "DnsFlushResolverCache")]
private static extern UInt32 DnsFlushResolverCache();

public static void FlushDNSCache() //This can be named whatever name you want and is the function you will call
{
UInt32 result = DnsFlushResolverCache();
}
}

public class Adapters
Expand Down
17 changes: 3 additions & 14 deletions DNS-Swapper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,11 @@ static class Program
[STAThread]
static void Main()
{
//NBug Crash Handling
//NBug.Settings.ReleaseMode = false;
NBug.Settings.HandleProcessCorruptedStateExceptions = true;
NBug.Settings.MiniDumpType = NBug.Enums.MiniDumpType.Normal;
NBug.Settings.StopReportingAfter = 365;
NBug.Settings.WriteLogToDisk = true;
NBug.Settings.ExitApplicationImmediately = true;
NBug.Settings.SleepBeforeSend = 5;
NBug.Settings.StoragePath = "WindowsTemp";

AppDomain.CurrentDomain.UnhandledException += NBug.Handler.UnhandledException;
Application.ThreadException += NBug.Handler.ThreadException;

Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainMenu());
MainMenu menu = new MainMenu();
Application.Run();

AppDomain.CurrentDomain.ProcessExit += new EventHandler(OnProcessExit);
}

Expand Down

0 comments on commit e256b5f

Please sign in to comment.