mirror of
https://github.com/fergalmoran/DnsServer.git
synced 2025-12-22 09:29:50 +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
|
||||
|
||||
public MainApplicationContext(string configFile, string[] args)
|
||||
public MainApplicationContext(string configFile, string[] args, ref bool exitApp)
|
||||
{
|
||||
_configFile = configFile;
|
||||
LoadConfig();
|
||||
@@ -73,8 +73,13 @@ namespace DnsServerSystemTrayApp
|
||||
{
|
||||
switch (args[0])
|
||||
{
|
||||
case "--network-dns-default-exit":
|
||||
SetNetworkDnsToDefault(true);
|
||||
exitApp = true;
|
||||
break;
|
||||
|
||||
case "--network-dns-default":
|
||||
DefaultNetworkDnsMenuItem_Click(this, EventArgs.Empty);
|
||||
SetNetworkDnsToDefault();
|
||||
break;
|
||||
|
||||
case "--network-dns-item":
|
||||
@@ -619,10 +624,17 @@ namespace DnsServerSystemTrayApp
|
||||
}
|
||||
|
||||
private void DefaultNetworkDnsMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
SetNetworkDnsToDefault();
|
||||
}
|
||||
|
||||
private void SetNetworkDnsToDefault(bool silent = false)
|
||||
{
|
||||
if (!Program.IsAdmin)
|
||||
{
|
||||
if (!silent)
|
||||
Program.RunAsAdmin("--network-dns-default");
|
||||
|
||||
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);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (!silent)
|
||||
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