From a3e45d206e1fb846ff7a368789bc2957b52d3f42 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Sun, 3 Nov 2024 21:15:50 +0800 Subject: [PATCH] Bug fix https://github.com/2dust/v2rayN/issues/5979 --- v2rayN/ServiceLib/Handler/AutoStartupHandler.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs b/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs index 97c867096d..42ec00863b 100644 --- a/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs +++ b/v2rayN/ServiceLib/Handler/AutoStartupHandler.cs @@ -113,7 +113,14 @@ private static string GetAutoRunNameWindows() private static async Task ClearTaskLinux() { - File.Delete(GetHomePathLinux()); + try + { + File.Delete(GetHomePathLinux()); + } + catch (Exception ex) + { + Logging.SaveLog(ex.Message, ex); + } } private static async Task SetTaskLinux() @@ -127,8 +134,6 @@ private static async Task SetTaskLinux() Logging.SaveLog(linuxConfig); var homePath = GetHomePathLinux(); - Directory.CreateDirectory(Path.GetDirectoryName(homePath)); - await File.WriteAllTextAsync(homePath, linuxConfig); } } @@ -140,7 +145,9 @@ private static async Task SetTaskLinux() private static string GetHomePathLinux() { - return Path.Combine(Utils.GetHomePath(), ".config", "autostart", $"{Global.AppName}.desktop"); + var homePath = Path.Combine(Utils.GetHomePath(), ".config", "autostart", $"{Global.AppName}.desktop"); + Directory.CreateDirectory(Path.GetDirectoryName(homePath)); + return homePath; } #endregion Linux