diff --git a/Netch/Constants.cs b/Netch/Constants.cs index 4e4e8754..1981cfdf 100644 --- a/Netch/Constants.cs +++ b/Netch/Constants.cs @@ -5,6 +5,12 @@ public const string EOF = "\r\n"; public const string UserACL = "data\\user.acl"; public const string BuiltinACL = "bin\\default.acl"; - public const string ParameterShow = "-show"; + + public static class Parameter + { + public const string Show = "-show"; + public const string ForceUpdate = "-forceUpdate"; + public const string Console = "-console"; + } } } \ No newline at end of file diff --git a/Netch/Flags.cs b/Netch/Flags.cs index 656d55b6..1b5a445a 100644 --- a/Netch/Flags.cs +++ b/Netch/Flags.cs @@ -10,5 +10,7 @@ namespace Netch private static readonly Lazy LazySupportFakeDns = new(() => new TUNTAPController().TestFakeDNS()); public static bool SupportFakeDns => LazySupportFakeDns.Value; + + public static bool AlwaysShowNewVersionFound { get; set; } } } \ No newline at end of file diff --git a/Netch/Forms/MainForm.cs b/Netch/Forms/MainForm.cs index d7ed7922..c7b973ca 100644 --- a/Netch/Forms/MainForm.cs +++ b/Netch/Forms/MainForm.cs @@ -1383,7 +1383,8 @@ namespace Netch.Forms if (File.Exists(file)) File.Delete(file); - Stop(); + if (IsWaiting()) + await StopAsyncCore(); Dispose(); Environment.Exit(Environment.ExitCode); @@ -1419,6 +1420,8 @@ namespace Netch.Forms { UpdateChecker.NewVersionFound += OnUpdateCheckerOnNewVersionFound; UpdateChecker.Check(Global.Settings.CheckBetaUpdate).Wait(); + if (Flags.AlwaysShowNewVersionFound) + OnUpdateCheckerOnNewVersionFound(null!, null!); } finally { diff --git a/Netch/Netch.cs b/Netch/Netch.cs index 1779db31..7fa88b78 100644 --- a/Netch/Netch.cs +++ b/Netch/Netch.cs @@ -24,10 +24,12 @@ namespace Netch #if DEBUG AttachConsole(); #else - if (args.Contains("-console")) + if (args.Contains(Constants.Parameter.Console)) AttachConsole(); #endif + if (args.Contains(Constants.Parameter.ForceUpdate)) + Flags.AlwaysShowNewVersionFound = true; // 设置当前目录 Directory.SetCurrentDirectory(Global.NetchDir); @@ -48,7 +50,7 @@ namespace Netch if (!SingleInstance.IsFirstInstance) { - SingleInstance.PassArgumentsToFirstInstance(args.Append(Constants.ParameterShow)); + SingleInstance.PassArgumentsToFirstInstance(args.Append(Constants.Parameter.Show)); Environment.Exit(0); return; } @@ -103,7 +105,7 @@ namespace Netch private static void SingleInstance_ArgumentsReceived(IEnumerable args) { - if (args.Contains(Constants.ParameterShow)) + if (args.Contains(Constants.Parameter.Show)) { Global.MainForm.ShowMainFormToolStripButton_Click(null!, null!); }