Skip to content

Commit

Permalink
Improved v2rayUpgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Oct 5, 2024
1 parent 20bb263 commit fe895b1
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions v2rayN/v2rayUpgrade/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Diagnostics;
using System.IO.Compression;
using System.Runtime.InteropServices;
using System.Text;

namespace v2rayUpgrade
Expand All @@ -26,15 +27,15 @@ private static void Main(string[] args)
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);
Expand Down Expand Up @@ -112,7 +113,16 @@ private static void Main(string[] args)
}

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()
Expand All @@ -134,5 +144,20 @@ public static string GetPath(string 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";
}
}
}
}

0 comments on commit fe895b1

Please sign in to comment.