Improved v2rayUpgrade

pull/5829/head
2dust 2 months ago
parent 20bb263b06
commit fe895b1b27

@ -1,5 +1,6 @@
using System.Diagnostics; using System.Diagnostics;
using System.IO.Compression; using System.IO.Compression;
using System.Runtime.InteropServices;
using System.Text; using System.Text;
namespace v2rayUpgrade namespace v2rayUpgrade
@ -26,15 +27,15 @@ namespace v2rayUpgrade
Console.WriteLine(fileName); Console.WriteLine(fileName);
Console.WriteLine("In progress, please wait...(正在进行中,请等待)"); Console.WriteLine("In progress, please wait...(正在进行中,请等待)");
Thread.Sleep(10000); Thread.Sleep(5000);
try try
{ {
Process[] existing = Process.GetProcessesByName("v2rayN"); Process[] existing = Process.GetProcessesByName(V2rayN());
foreach (Process p in existing) foreach (Process p in existing)
{ {
var path = p.MainModule?.FileName ?? ""; var path = p.MainModule?.FileName ?? "";
if (path.StartsWith(GetPath("v2rayN"))) if (path.StartsWith(GetPath(V2rayN())))
{ {
p.Kill(); p.Kill();
p.WaitForExit(100); p.WaitForExit(100);
@ -112,7 +113,16 @@ namespace v2rayUpgrade
} }
Console.WriteLine("Start v2rayN, please wait...(正在重启,请等待)"); 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() public static string GetExePath()
@ -134,5 +144,20 @@ namespace v2rayUpgrade
} }
return Path.Combine(startupPath, fileName); 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";
}
}
} }
} }
Loading…
Cancel
Save