From fe895b1b27e0703c0fba9c7f2643e4dbc67d6940 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sat, 5 Oct 2024 10:43:37 +0800 Subject: [PATCH] Improved v2rayUpgrade --- v2rayN/v2rayUpgrade/Program.cs | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/v2rayN/v2rayUpgrade/Program.cs b/v2rayN/v2rayUpgrade/Program.cs index ab351ec5..0d057a96 100644 --- a/v2rayN/v2rayUpgrade/Program.cs +++ b/v2rayN/v2rayUpgrade/Program.cs @@ -1,5 +1,6 @@ using System.Diagnostics; using System.IO.Compression; +using System.Runtime.InteropServices; using System.Text; namespace v2rayUpgrade @@ -26,15 +27,15 @@ namespace v2rayUpgrade Console.WriteLine(fileName); Console.WriteLine("In progress, please wait...(正在进行中,请等待)"); - Thread.Sleep(10000); + Thread.Sleep(5000); try { - Process[] existing = Process.GetProcessesByName("v2rayN"); + Process[] existing = Process.GetProcessesByName(V2rayN()); foreach (Process p in existing) { var path = p.MainModule?.FileName ?? ""; - if (path.StartsWith(GetPath("v2rayN"))) + if (path.StartsWith(GetPath(V2rayN()))) { p.Kill(); p.WaitForExit(100); @@ -112,7 +113,16 @@ namespace v2rayUpgrade } Console.WriteLine("Start v2rayN, please wait...(正在重启,请等待)"); - Process.Start("v2rayN"); + Thread.Sleep(3000); + Process process = new() + { + StartInfo = new() + { + FileName = V2rayN(), + WorkingDirectory = StartupPath() + } + }; + process.Start(); } public static string GetExePath() @@ -134,5 +144,20 @@ namespace v2rayUpgrade } return Path.Combine(startupPath, fileName); } + + private static string V2rayN() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + if (File.Exists(GetPath("v2rayN.exe"))) + return "v2rayN"; + else + return "v2rayN.Desktop"; + } + else + { + return "v2rayN.Desktop"; + } + } } } \ No newline at end of file