diff --git a/v2rayN/ServiceLib/Common/Utils.cs b/v2rayN/ServiceLib/Common/Utils.cs index 03a1a860..f7447dfb 100644 --- a/v2rayN/ServiceLib/Common/Utils.cs +++ b/v2rayN/ServiceLib/Common/Utils.cs @@ -582,7 +582,7 @@ public class Utils var result = await cmd.ExecuteBufferedAsync(); if (result.IsSuccess) { - return result.StandardOutput.ToString(); + return result.StandardOutput ?? ""; } Logging.SaveLog(result.ToString() ?? ""); @@ -839,14 +839,46 @@ public class Utils public static async Task SetLinuxChmod(string? fileName) { if (fileName.IsNullOrEmpty()) + { return null; + } + if (SetUnixFileMode(fileName)) + { + Logging.SaveLog($"Successfully set the file execution permission, {fileName}"); + return ""; + } + if (fileName.Contains(' ')) + { fileName = fileName.AppendQuotes(); - //File.SetUnixFileMode(fileName, UnixFileMode.UserRead | UnixFileMode.UserWrite | UnixFileMode.UserExecute); + } var arg = new List() { "-c", $"chmod +x {fileName}" }; return await GetCliWrapOutput(Global.LinuxBash, arg); } + public static bool SetUnixFileMode(string? fileName) + { + try + { + if (fileName.IsNullOrEmpty()) + { + return false; + } + + if (File.Exists(fileName)) + { + var currentMode = File.GetUnixFileMode(fileName); + File.SetUnixFileMode(fileName, currentMode | UnixFileMode.UserExecute | UnixFileMode.GroupExecute | UnixFileMode.OtherExecute); + return true; + } + } + catch (Exception ex) + { + Logging.SaveLog("SetUnixFileMode", ex); + } + return false; + } + public static async Task GetLinuxFontFamily(string lang) { // var arg = new List() { "-c", $"fc-list :lang={lang} family" };