From ea42246d1b2cc8740b31676d9a9d6343d0536592 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Fri, 25 Apr 2025 14:38:33 +0800 Subject: [PATCH] Improved AmazTool --- v2rayN/AmazTool/Program.cs | 84 +++++++++++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 11 deletions(-) diff --git a/v2rayN/AmazTool/Program.cs b/v2rayN/AmazTool/Program.cs index d71c25c2..4df39682 100644 --- a/v2rayN/AmazTool/Program.cs +++ b/v2rayN/AmazTool/Program.cs @@ -5,21 +5,83 @@ internal static class Program [STAThread] private static void Main(string[] args) { - if (args.Length == 0) + try { - Console.WriteLine(Resx.Resource.Guidelines); - Thread.Sleep(5000); - return; - } + // If no arguments are provided, display usage guidelines and exit + if (args.Length == 0) + { + ShowHelp(); + return; + } - var argData = Uri.UnescapeDataString(string.Join(" ", args)); - if (argData.Equals("rebootas")) + // Log all arguments for debugging purposes + foreach (var arg in args) + { + Console.WriteLine(arg); + } + + // Parse command based on first argument + switch (args[0].ToLowerInvariant()) + { + case "rebootas": + // Handle application restart + HandleRebootAsync(); + break; + + case "help": + case "--help": + case "-h": + case "/?": + // Display help information + ShowHelp(); + break; + + default: + // Default behavior: handle as upgrade data + // Maintain backward compatibility with existing usage pattern + var argData = Uri.UnescapeDataString(string.Join(" ", args)); + HandleUpgrade(argData); + break; + } + } + catch (Exception ex) { - Thread.Sleep(1000); - Utils.StartV2RayN(); - return; + // Global exception handling + Console.WriteLine($"An error occurred: {ex.Message}"); + Console.WriteLine("Press any key to exit..."); + Console.ReadKey(); } + } - UpgradeApp.Upgrade(argData); + /// + /// Display help information and usage guidelines + /// + private static void ShowHelp() + { + Console.WriteLine(Resx.Resource.Guidelines); + Console.WriteLine("Available commands:"); + Console.WriteLine(" rebootas - Restart the application"); + Console.WriteLine(" help - Display this help information"); + Thread.Sleep(5000); + } + + /// + /// Handle application restart + /// + private static void HandleRebootAsync() + { + Console.WriteLine("Restarting application..."); + Thread.Sleep(1000); + Utils.StartV2RayN(); + } + + /// + /// Handle application upgrade with the provided data + /// + /// Data for the upgrade process + private static void HandleUpgrade(string upgradeData) + { + Console.WriteLine("Upgrading application..."); + UpgradeApp.Upgrade(upgradeData); } }