mirror of
https://github.com/fergalmoran/DnsServer.git
synced 2025-12-26 03:17:55 +00:00
MainApplicationContext: added '--network-dns-default-exit' command line option to reset network dns to default and exit app. Code refactoring done.
This commit is contained in:
@@ -62,7 +62,7 @@ namespace DnsServerSystemTrayApp
|
|||||||
|
|
||||||
#region constructor
|
#region constructor
|
||||||
|
|
||||||
public MainApplicationContext(string configFile, string[] args)
|
public MainApplicationContext(string configFile, string[] args, ref bool exitApp)
|
||||||
{
|
{
|
||||||
_configFile = configFile;
|
_configFile = configFile;
|
||||||
LoadConfig();
|
LoadConfig();
|
||||||
@@ -73,8 +73,13 @@ namespace DnsServerSystemTrayApp
|
|||||||
{
|
{
|
||||||
switch (args[0])
|
switch (args[0])
|
||||||
{
|
{
|
||||||
|
case "--network-dns-default-exit":
|
||||||
|
SetNetworkDnsToDefault(true);
|
||||||
|
exitApp = true;
|
||||||
|
break;
|
||||||
|
|
||||||
case "--network-dns-default":
|
case "--network-dns-default":
|
||||||
DefaultNetworkDnsMenuItem_Click(this, EventArgs.Empty);
|
SetNetworkDnsToDefault();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "--network-dns-item":
|
case "--network-dns-item":
|
||||||
@@ -619,10 +624,17 @@ namespace DnsServerSystemTrayApp
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void DefaultNetworkDnsMenuItem_Click(object sender, EventArgs e)
|
private void DefaultNetworkDnsMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
SetNetworkDnsToDefault();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetNetworkDnsToDefault(bool silent = false)
|
||||||
{
|
{
|
||||||
if (!Program.IsAdmin)
|
if (!Program.IsAdmin)
|
||||||
{
|
{
|
||||||
|
if (!silent)
|
||||||
Program.RunAsAdmin("--network-dns-default");
|
Program.RunAsAdmin("--network-dns-default");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -656,10 +668,12 @@ namespace DnsServerSystemTrayApp
|
|||||||
{ }
|
{ }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!silent)
|
||||||
MessageBox.Show("The network DNS servers were set to default successfully.", "Default DNS Set - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBox.Show("The network DNS servers were set to default successfully.", "Default DNS Set - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
if (!silent)
|
||||||
MessageBox.Show("Error occured while setting default network DNS servers. " + ex.Message, "Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Error occured while setting default network DNS servers. " + ex.Message, "Error - " + Resources.ServiceName, MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user