From 333abebc5439e988a487594a74107912554894c8 Mon Sep 17 00:00:00 2001 From: IhateTrains Date: Wed, 10 Jan 2024 03:13:13 +0000 Subject: [PATCH] Fix the rakaly CLI binary not being made executable if its path contains a space (#1694) #patch --- ImperatorToCK3/Helpers/RakalyCaller.cs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/ImperatorToCK3/Helpers/RakalyCaller.cs b/ImperatorToCK3/Helpers/RakalyCaller.cs index 9cc368bc0..ee1e3f886 100644 --- a/ImperatorToCK3/Helpers/RakalyCaller.cs +++ b/ImperatorToCK3/Helpers/RakalyCaller.cs @@ -1,5 +1,4 @@ using commonItems; -using ImperatorToCK3.Exceptions; using System; using System.Diagnostics; using System.IO; @@ -8,17 +7,21 @@ namespace ImperatorToCK3.Helpers; public static class RakalyCaller { private const string RakalyVersion = "0.4.22"; - private static readonly string RakalyExecutablePath; + private static readonly string RelativeRakalyPath; static RakalyCaller() { string currentDir = Directory.GetCurrentDirectory(); - RakalyExecutablePath = $"Resources/rakaly/rakaly-{RakalyVersion}-x86_64-pc-windows-msvc/rakaly.exe"; + RelativeRakalyPath = $"Resources/rakaly/rakaly-{RakalyVersion}-x86_64-pc-windows-msvc/rakaly.exe"; if (OperatingSystem.IsMacOS()) { - RakalyExecutablePath = $"Resources/rakaly/rakaly-{RakalyVersion}-x86_64-apple-darwin/rakaly"; - Exec($"chmod +x {currentDir}/{RakalyExecutablePath}"); + RelativeRakalyPath = $"Resources/rakaly/rakaly-{RakalyVersion}-x86_64-apple-darwin/rakaly"; } else if (OperatingSystem.IsLinux()) { - RakalyExecutablePath = $"Resources/rakaly/rakaly-{RakalyVersion}-x86_64-unknown-linux-musl/rakaly"; - Exec($"chmod +x {currentDir}/{RakalyExecutablePath}"); + RelativeRakalyPath = $"Resources/rakaly/rakaly-{RakalyVersion}-x86_64-unknown-linux-musl/rakaly"; + } + + if (OperatingSystem.IsLinux() || OperatingSystem.IsMacOS()) { + // Make sure the file is executable. + var rakalyPath = Path.Combine(currentDir, RelativeRakalyPath).AddQuotes(); + Exec($"chmod +x {rakalyPath}"); } } @@ -28,7 +31,7 @@ public static string GetJson(string filePath) { using Process process = new(); process.StartInfo.UseShellExecute = false; - process.StartInfo.FileName = RakalyExecutablePath; + process.StartInfo.FileName = RelativeRakalyPath; process.StartInfo.Arguments = arguments; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardOutput = true; @@ -48,7 +51,7 @@ public static void MeltSave(string savePath) { using Process process = new(); process.StartInfo.UseShellExecute = false; - process.StartInfo.FileName = RakalyExecutablePath; + process.StartInfo.FileName = RelativeRakalyPath; process.StartInfo.Arguments = arguments; process.StartInfo.CreateNoWindow = true; process.StartInfo.RedirectStandardError = true; @@ -88,5 +91,10 @@ private static void Exec(string cmd) { process.Start(); process.WaitForExit(); + + var stdOut = process.StandardOutput.ReadToEnd().Trim(); + if (!string.IsNullOrEmpty(stdOut)) { + Logger.Debug("Exec output: " + stdOut); + } } } \ No newline at end of file