From e915726c52fd2f1dbd610d3b818f0b30963f2ca0 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Wed, 20 Nov 2024 10:29:04 +0800 Subject: [PATCH] Improved upgrade https://github.com/2dust/v2rayN/issues/6102 --- v2rayN/AmazTool/UpgradeApp.cs | 21 +++++++++++++++---- .../ViewModels/MainWindowViewModel.cs | 1 + 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/v2rayN/AmazTool/UpgradeApp.cs b/v2rayN/AmazTool/UpgradeApp.cs index e8ab76f2..06484950 100644 --- a/v2rayN/AmazTool/UpgradeApp.cs +++ b/v2rayN/AmazTool/UpgradeApp.cs @@ -10,7 +10,7 @@ namespace AmazTool { Console.WriteLine($"{LocalizationHelper.GetLocalizedValue("Start_Unzipping")}\n{fileName}"); - Thread.Sleep(9000); + Waiting(9); if (!File.Exists(fileName)) { @@ -24,8 +24,12 @@ namespace AmazTool var existing = Process.GetProcessesByName(V2rayN); foreach (var pp in existing) { - pp?.Kill(); - pp?.WaitForExit(1000); + var path = pp.MainModule?.FileName ?? ""; + if (path.StartsWith(GetPath(V2rayN))) + { + pp?.Kill(); + pp?.WaitForExit(1000); + } } } catch (Exception ex) @@ -87,7 +91,7 @@ namespace AmazTool } Console.WriteLine(LocalizationHelper.GetLocalizedValue("Restart_v2rayN")); - Thread.Sleep(9000); + Waiting(9); Process process = new() { StartInfo = new() @@ -120,6 +124,15 @@ namespace AmazTool return Path.Combine(startupPath, fileName); } + private static void Waiting(int second) + { + for (var i = second; i > 0; i--) + { + Console.WriteLine(i); + Thread.Sleep(1000); + } + } + private static string V2rayN => "v2rayN"; } } \ No newline at end of file diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs index 9660945e..3be5dcaa 100644 --- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs @@ -324,6 +324,7 @@ namespace ServiceLib.ViewModels if (process.Id > 0) { await MyAppExitAsync(false); + await MyAppExitAsync(false); } }