From 98ec2532b2c5ed28107483ce99b227d4f3e56953 Mon Sep 17 00:00:00 2001 From: FrankH <4848285@qq.com> Date: Fri, 6 May 2022 17:34:06 +0800 Subject: [PATCH] Release 6.0.4: Add options to run in quiet mode: `-q|--quiet` --- src/IpFix/Program.cs | 73 +++++++++++++----------- src/IpFix/Properties/launchSettings.json | 7 ++- 2 files changed, 45 insertions(+), 35 deletions(-) diff --git a/src/IpFix/Program.cs b/src/IpFix/Program.cs index a4b2f2e..8b6acf1 100644 --- a/src/IpFix/Program.cs +++ b/src/IpFix/Program.cs @@ -1,7 +1,4 @@ -using System.Diagnostics; using System.Reflection; -using System.Security.Principal; -using System.Text.RegularExpressions; namespace Myvas.Tools.IpFix; @@ -53,56 +50,66 @@ static void Main(string[] args) return; } + var quietMode = args.Contains("-q") + || args.Contains("--quiet"); + if (quietMode) + { + args = args.Except(new[] { "-q", "--quiet" }).ToArray(); + } + foreach (var dns in args) { if (!dns.StartsWith('-') && !dns.StartsWith('/')) Fix(dns); } + + if (!quietMode) + { + Console.WriteLine(); + Console.WriteLine("Press any key to exit..."); + Console.ReadKey(); + } } catch (Exception ex) { Console.WriteLine(ex); + Console.WriteLine(); + Console.WriteLine("Press any key to exit..."); + Console.ReadKey(); } finally { - if ((args?.Contains("-q") ?? false) - || (args?.Contains("--quiet") ?? false)) - { } - else - { - try - { - var isInConsole = Console.CursorLeft >= int.MinValue; - Console.WriteLine(); - Console.WriteLine("Press any key to exit..."); - Console.ReadKey(); - } - catch { } - } } } public static void Fix(string dns) { - var ipAddress = IpAddressFetcher.RetrieveIpAddress(dns); - if (string.IsNullOrWhiteSpace(ipAddress)) + try { - Console.WriteLine($"No record of '{dns}' be found on {IpAddressFetcher.Name}."); - return; - } - Console.WriteLine($"The IP address of {dns} is {ipAddress}"); + var ipAddress = IpAddressFetcher.RetrieveIpAddress(dns); + if (string.IsNullOrWhiteSpace(ipAddress)) + { + Console.WriteLine($"No record of '{dns}' be found on {IpAddressFetcher.Name}."); + return; + } + Console.WriteLine($"The IP address of {dns} is {ipAddress}"); - var hostsFile = new HostsFile(); - var changed = hostsFile.UpdateHostsRecord(dns, ipAddress, IpAddressFetcher.Name); - if (!changed) - { - Console.WriteLine($"The record does not need to update."); - return; - } + var hostsFile = new HostsFile(); + var changed = hostsFile.UpdateHostsRecord(dns, ipAddress, IpAddressFetcher.Name); + if (!changed) + { + Console.WriteLine($"The record does not need to update."); + return; + } - hostsFile.Write(); - Console.WriteLine($"{dns} updated to {ipAddress}"); + hostsFile.Write(); + Console.WriteLine($"{dns} updated to {ipAddress}"); - IpConfigHelper.Flushdns(); + IpConfigHelper.Flushdns(); + } + catch (Exception ex) + { + Console.WriteLine(ex); + } } } diff --git a/src/IpFix/Properties/launchSettings.json b/src/IpFix/Properties/launchSettings.json index 50b66a8..ed5ffd6 100644 --- a/src/IpFix/Properties/launchSettings.json +++ b/src/IpFix/Properties/launchSettings.json @@ -1,8 +1,11 @@ { "profiles": { - "Myvas.Tools.IpFix": { + "ipfix github.com": { "commandName": "Project", - "commandLineArgs": "gmail.com" + "commandLineArgs": "github.com" + }, + "ipfix": { + "commandName": "Project" } } } \ No newline at end of file