From 447632ff07e8770747d7f211b14f10a0fef7c5a2 Mon Sep 17 00:00:00 2001 From: Student Main Date: Fri, 18 Jan 2019 00:06:56 +0800 Subject: [PATCH] set command line parameter when register restart, for future --- shadowsocks-csharp/Controller/System/AutoStartup.cs | 13 ++++++++++--- shadowsocks-csharp/Program.cs | 7 +++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/shadowsocks-csharp/Controller/System/AutoStartup.cs b/shadowsocks-csharp/Controller/System/AutoStartup.cs index 8aa1f6d5..9f3e5ff2 100644 --- a/shadowsocks-csharp/Controller/System/AutoStartup.cs +++ b/shadowsocks-csharp/Controller/System/AutoStartup.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; using System.Reflection; using System.Runtime.InteropServices; using System.Windows.Forms; @@ -127,11 +129,16 @@ namespace Shadowsocks.Controller // requested register and not autostartup if (register && !Check()) { + // escape command line parameter + string[] args = new List(Program.Args) + .Select(p => p.Replace("\"", "\\\"")) // escape " to \" + .Select(p => p.IndexOf(" ") >= 0 ? "\"" + p + "\"" : p) // encapsule with " + .ToArray(); + string cmdline = string.Join(" ", args); // first parameter is process command line parameter - // if ss-windows use it in future, remember pass it // needn't include the name of the executable in the command line - RegisterApplicationRestart(null, (int)ApplicationRestartFlags.RESTART_NO_CRASH | (int)ApplicationRestartFlags.RESTART_NO_HANG); - Logging.Debug("Register restart after system reboot"); + RegisterApplicationRestart(cmdline, (int)ApplicationRestartFlags.RESTART_NO_CRASH | (int)ApplicationRestartFlags.RESTART_NO_HANG); + Logging.Debug("Register restart after system reboot, command line:" + cmdline); } // requested unregister, which has no side effect else if (!register) diff --git a/shadowsocks-csharp/Program.cs b/shadowsocks-csharp/Program.cs index 8914ccef..a1763e38 100755 --- a/shadowsocks-csharp/Program.cs +++ b/shadowsocks-csharp/Program.cs @@ -16,13 +16,16 @@ namespace Shadowsocks { public static ShadowsocksController MainController { get; private set; } public static MenuViewController MenuController { get; private set; } - + public static string[] Args { get; private set; } /// /// 应用程序的主入口点。 /// + /// [STAThread] - static void Main() + static void Main(string[] args) { + // store args for further use + Args = args; // Check OS since we are using dual-mode socket if (!Utils.IsWinVistaOrHigher()) {