diff --git a/CelesteTAS-EverestInterop/EverestInterop/StudioHelper.cs b/CelesteTAS-EverestInterop/EverestInterop/StudioHelper.cs index 372e2f48..35ddf1cd 100644 --- a/CelesteTAS-EverestInterop/EverestInterop/StudioHelper.cs +++ b/CelesteTAS-EverestInterop/EverestInterop/StudioHelper.cs @@ -195,75 +195,54 @@ private static async Task DownloadStudio() { // Fix lost file permissions if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { - string? line; - - var chmodProc = Process.Start("chmod", ["+x", Path.Combine(StudioDirectory, "CelesteStudio")]); - await chmodProc.WaitForExitAsync().ConfigureAwait(false); - - if (chmodProc.ExitCode != 0) { - $"Install failed! Couldn't make Studio executable: {chmodProc.ExitCode}".Log(LogLevel.Error); - - while ((line = await chmodProc.StandardOutput.ReadLineAsync()) == null) { - line.Log(LogLevel.Info); - } - while ((line = await chmodProc.StandardError.ReadLineAsync()) == null) { - line.Log(LogLevel.Error); - } - + if (!await ExecuteCommand(["chmod", "+x", Path.Combine(StudioDirectory, "CelesteStudio")], + errorMessage: "Install failed! Couldn't make Studio executable").ConfigureAwait(false)) + { // Mark install as invalid, so that next launch will try again File.Delete(VersionFile); - return; - } else { - while ((line = await chmodProc.StandardOutput.ReadLineAsync()) == null) { - line.Log(LogLevel.Debug); - } } } else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { - string? line; - - var chmodProc = Process.Start("chmod", ["+x", Path.Combine(StudioDirectory, "CelesteStudio.app", "Contents", "MacOS", "CelesteStudio")]); - await chmodProc.WaitForExitAsync().ConfigureAwait(false); - - if (chmodProc.ExitCode != 0) { - $"Install failed! Couldn't make Studio executable: {chmodProc.ExitCode}".Log(LogLevel.Error); - - while ((line = await chmodProc.StandardOutput.ReadLineAsync()) == null) { - line.Log(LogLevel.Info); - } - while ((line = await chmodProc.StandardError.ReadLineAsync()) == null) { - line.Log(LogLevel.Error); - } - + if (!await ExecuteCommand(["chmod", "+x", Path.Combine(StudioDirectory, "CelesteStudio.app", "Contents", "MacOS", "CelesteStudio")], + errorMessage: "Install failed! Couldn't make Studio executable").ConfigureAwait(false) || + !await ExecuteCommand(["xattr", "-c", Path.Combine(StudioDirectory, "CelesteStudio.app")], + errorMessage: "Install failed! Couldn't clear Studio app bundle config").ConfigureAwait(false)) + { // Mark install as invalid, so that next launch will try again File.Delete(VersionFile); - return; - } else { - while ((line = await chmodProc.StandardOutput.ReadLineAsync()) == null) { - line.Log(LogLevel.Debug); - } } + } + } - var xattrProc = Process.Start("xattr", ["-c", Path.Combine(StudioDirectory, "CelesteStudio.app")]); - await xattrProc.WaitForExitAsync().ConfigureAwait(false); - if (xattrProc.ExitCode != 0) { - $"Install failed! Couldn't clear Studio app bundle config: {xattrProc.ExitCode}".Log(LogLevel.Error); + private static async Task ExecuteCommand(string[] parameters, string errorMessage) { + var startInfo = new ProcessStartInfo(parameters[0]) { + RedirectStandardOutput = true, + RedirectStandardError = true, + }; + foreach (string param in parameters[1..]) { + startInfo.ArgumentList.Add(param); + } - while ((line = await xattrProc.StandardOutput.ReadLineAsync()) == null) { - line.Log(LogLevel.Info); - } - while ((line = await xattrProc.StandardError.ReadLineAsync()) == null) { - line.Log(LogLevel.Error); - } + var proc = Process.Start(startInfo)!; + await proc.WaitForExitAsync().ConfigureAwait(false); - // Mark install as invalid, so that next launch will try again - File.Delete(VersionFile); - return; - } else { - while ((line = await xattrProc.StandardOutput.ReadLineAsync()) == null) { - line.Log(LogLevel.Debug); - } + string? line; + + if (proc.ExitCode != 0) { + $"{errorMessage}: Exit Code {proc.ExitCode}".Log(LogLevel.Error); + + while ((line = await proc.StandardOutput.ReadLineAsync()) != null) { + line.Log(LogLevel.Info); + } + while ((line = await proc.StandardError.ReadLineAsync()) != null) { + line.Log(LogLevel.Error); + } + } else { + while ((line = await proc.StandardOutput.ReadLineAsync()) != null) { + line.Log(LogLevel.Debug); } } + + return proc.ExitCode == 0; } internal static void LaunchStudio() => Task.Run(async () => { diff --git a/CelesteTAS-EverestInterop/Utils/LogUtil.cs b/CelesteTAS-EverestInterop/Utils/LogUtil.cs index 4df04930..50171f35 100644 --- a/CelesteTAS-EverestInterop/Utils/LogUtil.cs +++ b/CelesteTAS-EverestInterop/Utils/LogUtil.cs @@ -24,9 +24,9 @@ public static void DebugLog(this object text, bool outputToCommands, LogLevel lo } #endif - public static void LogException(this Exception e, string header, LogLevel logLevel = LogLevel.Warn) { + public static void LogException(this Exception e, string header, LogLevel logLevel = LogLevel.Error) { header.Log(logLevel); - e.LogDetailed(); + Logger.LogDetailed(e, Tag); } public static void Log(this object text, LogLevel logLevel = LogLevel.Info) { @@ -66,4 +66,4 @@ public static void ConsoleLog(this object text, LogLevel logLevel = LogLevel.Ver // ignored } } -} \ No newline at end of file +}