From bc2adbfa771abeb49bce59adb741f3b0f485ce45 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sat, 4 Jan 2025 17:03:12 +0800 Subject: [PATCH] Add restart to Linux restore backup function --- v2rayN/ServiceLib/Common/Utils.cs | 6 +++--- v2rayN/ServiceLib/Handler/CoreHandler.cs | 4 ++-- v2rayN/ServiceLib/ViewModels/BackupAndRestoreViewModel.cs | 7 +++++++ v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs | 4 ++-- 4 files changed, 14 insertions(+), 7 deletions(-) diff --git a/v2rayN/ServiceLib/Common/Utils.cs b/v2rayN/ServiceLib/Common/Utils.cs index 10a5302e..15023f2b 100644 --- a/v2rayN/ServiceLib/Common/Utils.cs +++ b/v2rayN/ServiceLib/Common/Utils.cs @@ -517,10 +517,10 @@ namespace ServiceLib.Common #region 杂项 - public static bool UpgradeAppExists(out string fileName) + public static bool UpgradeAppExists(out string upgradeFileName) { - fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, GetExeName("AmazTool")); - return File.Exists(fileName); + upgradeFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, GetExeName("AmazTool")); + return File.Exists(upgradeFileName); } /// diff --git a/v2rayN/ServiceLib/Handler/CoreHandler.cs b/v2rayN/ServiceLib/Handler/CoreHandler.cs index 861bcd30..32451ba1 100644 --- a/v2rayN/ServiceLib/Handler/CoreHandler.cs +++ b/v2rayN/ServiceLib/Handler/CoreHandler.cs @@ -32,9 +32,9 @@ namespace ServiceLib.Handler { if (it.CoreType == ECoreType.v2rayN) { - if (Utils.UpgradeAppExists(out var fileName)) + if (Utils.UpgradeAppExists(out var upgradeFileName)) { - await Utils.SetLinuxChmod(fileName); + await Utils.SetLinuxChmod(upgradeFileName); } continue; } diff --git a/v2rayN/ServiceLib/ViewModels/BackupAndRestoreViewModel.cs b/v2rayN/ServiceLib/ViewModels/BackupAndRestoreViewModel.cs index 947bac03..cbf6beb3 100644 --- a/v2rayN/ServiceLib/ViewModels/BackupAndRestoreViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/BackupAndRestoreViewModel.cs @@ -147,6 +147,13 @@ namespace ServiceLib.ViewModels { ProcUtils.RebootAsAdmin(false); } + else + { + if (Utils.UpgradeAppExists(out var upgradeFileName)) + { + ProcUtils.ProcessStart(upgradeFileName, Global.RebootAs, Utils.StartupPath()); + } + } service?.Shutdown(); } else diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs index b052b6c7..929ea1eb 100644 --- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs @@ -310,14 +310,14 @@ namespace ServiceLib.ViewModels public async Task UpgradeApp(string arg) { - if (!Utils.UpgradeAppExists(out var fileName)) + if (!Utils.UpgradeAppExists(out var upgradeFileName)) { NoticeHandler.Instance.SendMessageAndEnqueue(ResUI.UpgradeAppNotExistTip); Logging.SaveLog("UpgradeApp does not exist"); return; } - var id = ProcUtils.ProcessStart(fileName, arg, Utils.StartupPath()); + var id = ProcUtils.ProcessStart(upgradeFileName, arg, Utils.StartupPath()); if (id > 0) { await MyAppExitAsync(false);