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:
Shreyas Zare
2022-11-12 15:31:53 +05:30
parent 180f5515d9
commit bc1fead1b5

View File

@@ -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);
}
}