From c3098abd5a81ecde3c8e3b79a0b7477ede48e592 Mon Sep 17 00:00:00 2001 From: Rankyn Bass Date: Fri, 19 Apr 2024 16:26:58 -0700 Subject: [PATCH] Improve CL options --- .../SettingsPage/Tabs/SettingsTabSteamTool.cs | 8 +- .../Configuration/ILauncherConfig.cs | 4 + src/XIVLauncher.Core/Program.cs | 168 +++++++++++++----- src/XIVLauncher.Core/Resources/xlcore | 9 +- .../SteamCompatibilityTool.cs | 126 ++++++++++++- src/XIVLauncher.Core/UpdateCheck.cs | 2 +- 6 files changed, 257 insertions(+), 60 deletions(-) diff --git a/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabSteamTool.cs b/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabSteamTool.cs index 1e6df5b0..58a84036 100644 --- a/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabSteamTool.cs +++ b/src/XIVLauncher.Core/Components/SettingsPage/Tabs/SettingsTabSteamTool.cs @@ -78,7 +78,7 @@ public override void Draw() if (ImGui.Button($"{(steamToolInstalled ? "Re-i" : "I")}nstall to native Steam")) { this.Save(); - SteamCompatibilityTool.CreateTool(Program.Config.SteamPath ?? ""); + SteamCompatibilityTool.CreateTool(isFlatpak: false); steamToolInstalled = SteamCompatibilityTool.IsSteamToolInstalled; } if (!steamInstalled) ImGui.EndDisabled(); @@ -87,7 +87,7 @@ public override void Draw() if (ImGui.Button("Uninstall from native Steam")) { this.Save(); - SteamCompatibilityTool.DeleteTool(Program.Config.SteamPath ?? ""); + SteamCompatibilityTool.DeleteTool(isFlatpak: false); steamToolInstalled = SteamCompatibilityTool.IsSteamToolInstalled; } if (!steamToolInstalled) ImGui.EndDisabled(); @@ -104,7 +104,7 @@ public override void Draw() if (ImGui.Button($"{(steamFlatpakToolInstalled ? "Re-i" : "I")}nstall to flatpak Steam")) { this.Save(); - SteamCompatibilityTool.CreateTool(Program.Config.SteamFlatpakPath ?? ""); + SteamCompatibilityTool.CreateTool(isFlatpak: true); steamFlatpakToolInstalled = SteamCompatibilityTool.IsSteamFlatpakToolInstalled; } if (!steamFlatpakInstalled) ImGui.EndDisabled(); @@ -116,7 +116,7 @@ public override void Draw() if (ImGui.Button("Uninstall from Flatpak Steam")) { this.Save(); - SteamCompatibilityTool.DeleteTool(Program.Config.SteamFlatpakPath ?? ""); + SteamCompatibilityTool.DeleteTool(isFlatpak: true); steamFlatpakToolInstalled = SteamCompatibilityTool.IsSteamFlatpakToolInstalled; } if (!steamFlatpakToolInstalled) diff --git a/src/XIVLauncher.Core/Configuration/ILauncherConfig.cs b/src/XIVLauncher.Core/Configuration/ILauncherConfig.cs index 91120dd1..ac62ee07 100644 --- a/src/XIVLauncher.Core/Configuration/ILauncherConfig.cs +++ b/src/XIVLauncher.Core/Configuration/ILauncherConfig.cs @@ -88,6 +88,10 @@ public interface ILauncherConfig public string? SteamFlatpakPath { get; set; } + public bool? SteamToolInstalled { get; set; } + + public bool? SteamFlatpakToolInstalled { get; set; } + #endregion #region Dalamud diff --git a/src/XIVLauncher.Core/Program.cs b/src/XIVLauncher.Core/Program.cs index a9a174e7..ccfe298c 100644 --- a/src/XIVLauncher.Core/Program.cs +++ b/src/XIVLauncher.Core/Program.cs @@ -73,6 +73,10 @@ class Program public static string CType = CoreEnvironmentSettings.GetCType(); + public static Version CoreVersion = Version.Parse(AppUtil.GetAssemblyVersion()); + + public static string CoreHash = AppUtil.GetGitHash() ?? ""; + public static void Invalidate(uint frames = 100) { invalidationFrames = frames; @@ -138,6 +142,8 @@ private static void LoadConfig(Storage storage) Config.SteamPath ??= Path.Combine(CoreEnvironmentSettings.HOME, ".local", "share"); Config.SteamFlatpakPath ??= Path.Combine(CoreEnvironmentSettings.HOME, ".var", "app", "com.valvesoftware.Steam", "data", "Steam" ); + Config.SteamToolInstalled ??= false; + Config.SteamFlatpakToolInstalled ??= false; } public const uint STEAM_APP_ID = 39210; @@ -200,6 +206,19 @@ private static void Main(string[] args) Loc.SetupWithFallbacks(); + if (System.OperatingSystem.IsLinux()) + { + if (mainArgs.Length > 0) + Log.Information("Command Line option selected: {args}", string.Join(' ', mainArgs)); + var exitValue = LinuxCommandLineOptions(); + if (exitValue) + { + Log.Information("Exiting..."); + return; + } + SteamCompatibilityTool.UpdateSteamTools(); + } + uint appId, altId; string appName, altName; if (Config.IsFt == true) @@ -225,8 +244,6 @@ private static void Main(string[] args) break; case PlatformID.Unix: - // We should only run the script on Linux (maybe Unix) systems. - if (CommandLineInstaller()) return; Steam = new UnixSteam(); break; @@ -261,9 +278,9 @@ private static void Main(string[] args) Log.Debug("Creating Veldrid devices..."); #if DEBUG - var version = AppUtil.GetGitHash(); + var version = CoreHash; #else - var version = $"{AppUtil.GetAssemblyVersion()} ({AppUtil.GetGitHash()})"; + var version = $"{CoreVersion} ({CoreHash})"; #endif // Create window, GraphicsDevice, and all resources necessary for the demo. @@ -478,53 +495,106 @@ public static void ClearAll(bool tsbutton = false) ClearLogs(true); } - private static bool CommandLineInstaller() + private static bool LinuxCommandLineOptions() { - foreach (var arg in mainArgs) + bool exit = false; + + if (mainArgs.Contains("-v")) { - if (arg == "--deck-install") - { - SteamCompatibilityTool.CreateTool(Path.Combine(CoreEnvironmentSettings.HOME, ".local", "share", "Steam")); - Console.WriteLine($"Installed as Steam compatibility tool to {Path.Combine(CoreEnvironmentSettings.HOME, ".local", "share", "Steam", "compatibilitytools.d", "xlcore")}"); - return true; - } - if (arg.StartsWith("--install=")) - { - var path = arg.Split('=', 2)[1]; - if (path.StartsWith("~/")) - path = CoreEnvironmentSettings.HOME + path.TrimStart('~'); - if (Directory.Exists(path) && (path.EndsWith("/Steam") || path.EndsWith("/Steam/"))) - { - SteamCompatibilityTool.CreateTool(path); - Console.WriteLine($"Installed as Steam compatibility tool to path {Path.Combine(path, "compatibilitytools.d", "xlcore")}"); - } - else - Console.WriteLine($"Invalid path. Path does not exist or is not a Steam folder: {path}"); - - return true; - } - if (arg == "--deck-remove") - { - SteamCompatibilityTool.DeleteTool(Path.Combine(CoreEnvironmentSettings.HOME, ".local", "share", "Steam")); - Console.WriteLine($"Removed XIVLauncher.Core as a Steam compatibility tool from {Path.Combine(CoreEnvironmentSettings.HOME, ".local", "share", "Steam", "compatibilitytools.d")}"); - return true; - } - if (arg.StartsWith("--remove=")) - { - var path = arg.Split('=', 2)[1]; - if (path.StartsWith("~/")) - path = CoreEnvironmentSettings.HOME + path.TrimStart('~'); - if (Directory.Exists(path) && (path.EndsWith("/Steam") || path.EndsWith("/Steam/"))) - { - SteamCompatibilityTool.DeleteTool(path); - Console.WriteLine($"Removed XIVLauncher.Core as a Steam compatibility tool from {Path.Combine(path, "compatibilitytools.d")}"); - } - else - Console.WriteLine($"Invalid path. Path does not exist or is not a Steam folder: {path}"); - - return true; - } + Console.WriteLine("Verbose Logging enabled..."); + } + + if (mainArgs.Contains("--update-tools") || mainArgs.Contains("-u")) + { + SteamCompatibilityTool.UpdateSteamTools(true); + exit = true; + } + + if (mainArgs.Contains("--info")) + { + Console.WriteLine($"Steam compatibility tool {(SteamCompatibilityTool.IsSteamToolInstalled ? "is installed: " + SteamCompatibilityTool.CheckVersion(isFlatpak: false).Replace(",", " ") : "is not installed.")}"); + Console.WriteLine($"Steam (flatpak) compatibility tool {(SteamCompatibilityTool.IsSteamFlatpakToolInstalled ? "is installed: " + SteamCompatibilityTool.CheckVersion(isFlatpak: true).Replace(",", " ") : "is not installed.")}"); + exit = true; + } + + if (mainArgs.Contains("--deck-install") && mainArgs.Contains("--deck-remove")) + { + SteamCompatibilityTool.DeleteTool(isFlatpak: false); + Console.WriteLine("Using both --deck-install and --deck-remove. Doing --deck-remove first"); + Console.WriteLine($"Removed XIVLauncher.Core as a Steam compatibility tool from {Program.Config.SteamPath ?? ""}"); + SteamCompatibilityTool.CreateTool(isFlatpak: false); + Console.WriteLine($"Installed as Steam compatibility tool to {Program.Config.SteamPath ?? ""}"); + exit = true; + } + else if (mainArgs.Contains("--deck-install")) + { + SteamCompatibilityTool.CreateTool(isFlatpak: false); + Console.WriteLine($"Installed as Steam compatibility tool to {Program.Config.SteamPath ?? ""}"); + exit = true; + } + else if (mainArgs.Contains("--deck-remove")) + { + SteamCompatibilityTool.DeleteTool(isFlatpak: false); + Console.WriteLine($"Removed XIVLauncher.Core as a Steam compatibility tool from {Program.Config.SteamPath ?? ""}"); + exit = true; + } + + if (mainArgs.Contains("--flatpak-install") && mainArgs.Contains("--flatpak-remove")) + { + Console.WriteLine("Using both --flatpak-install and --flatpak-remove. Doing --deck-remove first"); + SteamCompatibilityTool.DeleteTool(isFlatpak: true); + Console.WriteLine($"Removed XIVLauncher.Core as a Steam compatibility tool from {Program.Config.SteamFlatpakPath ?? ""}"); + SteamCompatibilityTool.CreateTool(isFlatpak: true); + Console.WriteLine($"Installed as Steam compatibility tool to {Program.Config.SteamFlatpakPath ?? ""}"); + exit = true; + } + else if (mainArgs.Contains("--flatpak-install")) + { + SteamCompatibilityTool.CreateTool(isFlatpak: true); + Console.WriteLine($"Installed as Steam compatibility tool to {Program.Config.SteamFlatpakPath ?? ""}"); + exit = true; + } + else if (mainArgs.Contains("--flatpak-remove")) + { + SteamCompatibilityTool.DeleteTool(isFlatpak: true); + Console.WriteLine($"Removed XIVLauncher.Core as a Steam compatibility tool from {Program.Config.SteamFlatpakPath ?? ""}"); + exit = true; + } + + if (mainArgs.Contains("--version")) + { + Console.WriteLine($"XIVLauncher.Core {CoreVersion.ToString()}"); + Console.WriteLine("Copyright (C) 2024 goatcorp.\nLicense GPLv3+: GNU GPL version 3 or later ."); + exit = true; + } + + if (mainArgs.Contains("-V")) + { + Console.WriteLine(CoreVersion.ToString()); + exit = true; + } + + if (mainArgs.Contains("--help") || mainArgs.Contains("-h")) + { + Console.WriteLine($"XIVLaunher.Core {CoreVersion.ToString()}\nA third-party launcher for Final Fantasy XIV.\n\nOptions (use only one):"); + Console.WriteLine(" -v Turn on verbose logging, then run the launcher."); + Console.WriteLine(" -h, --help Display this message."); + Console.WriteLine(" -V Display brief version info."); + Console.WriteLine(" --version Display version and copywrite info."); + Console.WriteLine(" --info Display Steam compatibility tool install status"); + Console.WriteLine(" -u, --update-tools Try to update any installed xlcore steam compatibility tools."); + Console.WriteLine("\nFor Steam Deck and native Steam"); + Console.WriteLine(" --deck-install Install as a compatibility tool in the default location."); + Console.WriteLine($" Path: {Program.Config.SteamPath ?? ""}"); + Console.WriteLine(" --deck-remove Remove compatibility tool install from the defualt location."); + Console.WriteLine("\nFor Flatpak Steam"); + Console.WriteLine(" --flatpak-install Install as a compatibility tool to flatpak Steam."); + Console.WriteLine($" Path: {Program.Config.SteamFlatpakPath ?? ""}"); + Console.WriteLine(" --flatpak-remove Remove compatibility tool from flatpak Steam."); + Console.WriteLine(""); + exit = true; } - return false; + + return exit; } } diff --git a/src/XIVLauncher.Core/Resources/xlcore b/src/XIVLauncher.Core/Resources/xlcore index 0bdfadd2..4bcf06fd 100755 --- a/src/XIVLauncher.Core/Resources/xlcore +++ b/src/XIVLauncher.Core/Resources/xlcore @@ -1,7 +1,13 @@ #!/bin/env sh +# Working directory is actually the steam install location, so we need to find the path of this script +tooldir="$(realpath "$(dirname "$0")")" + # Prevent double launch if [ "$1" = "run" ]; then + if [ ! -f "$tooldir/version" ]; then + "$tooldir/XIVLauncher/XIVLauncher.Core" -V > "$tooldir/version" + fi sleep 1 exit 0 fi @@ -11,9 +17,6 @@ logDir=$xlcoreDir/logs mkdir -p $xlcoreDir mkdir -p $logDir -# Working directory is actually the steam install location, so we need to find the path of this script -tooldir="$(realpath "$(dirname "$0")")" - # If aria2c isn't found, add our local copy to the $PATH count=$(find /usr -type f -executable -name "aria2c" 2>/dev/null | wc -l) if [ $count -eq 0 ] && [ -e "$tooldir/bin/aria2c" ]; then diff --git a/src/XIVLauncher.Core/UnixCompatibility/SteamCompatibilityTool.cs b/src/XIVLauncher.Core/UnixCompatibility/SteamCompatibilityTool.cs index c65e7f32..ac743ebb 100644 --- a/src/XIVLauncher.Core/UnixCompatibility/SteamCompatibilityTool.cs +++ b/src/XIVLauncher.Core/UnixCompatibility/SteamCompatibilityTool.cs @@ -9,6 +9,8 @@ namespace XIVLauncher.Core.UnixCompatibility; public static class SteamCompatibilityTool { + // This is here to prevent auto-updating with different releases of XLCore. So XIVLauncher-RB will not overwrite official, vice versa. + private const string RELEASE = "Official"; public static bool IsSteamInstalled => Directory.Exists(Program.Config.SteamPath); public static bool IsSteamFlatpakInstalled => Directory.Exists(Program.Config.SteamFlatpakPath); @@ -22,8 +24,17 @@ private static string findXIVLauncherFiles() return System.AppDomain.CurrentDomain.BaseDirectory; } - public static void CreateTool(string path) + private static void SetConfigValues(bool isFlatpak) { + if (isFlatpak) + Program.Config.SteamFlatpakToolInstalled = IsSteamFlatpakToolInstalled; + else + Program.Config.SteamToolInstalled = IsSteamToolInstalled; + } + + public static void CreateTool(bool isFlatpak) + { + var path = isFlatpak ? Program.Config.SteamFlatpakPath : Program.Config.SteamPath; var compatfolder = new DirectoryInfo(Path.Combine(path, "compatibilitytools.d")); compatfolder.Create(); var destination = new DirectoryInfo(Path.Combine(compatfolder.FullName, "xlcore")); @@ -41,11 +52,13 @@ public static void CreateTool(string path) var compatibilitytool_vdf = new FileInfo(Path.Combine(destination.FullName, "compatibilitytool.vdf")); var toolmanifest_vdf = new FileInfo(Path.Combine(destination.FullName, "toolmanifest.vdf")); var openssl_fix = new FileInfo(Path.Combine(destination.FullName, "openssl_fix.cnf")); - + var version = new FileInfo(Path.Combine(destination.FullName, "version")); + xlcore.Delete(); compatibilitytool_vdf.Delete(); toolmanifest_vdf.Delete(); openssl_fix.Delete(); + version.Delete(); using (var fs = xlcore.Create()) { @@ -85,6 +98,12 @@ public static void CreateTool(string path) resource.CopyTo(fs); fs.Close(); } + using (var fs = version.Create()) + { + byte[] resource = new System.Text.UTF8Encoding(true).GetBytes(Program.CoreVersion.ToString() + "\n" + RELEASE); + fs.Write(resource, 0, resource.Length); + fs.Close(); + } // Copy XIVLauncher files var XIVLauncherFiles = new DirectoryInfo(findXIVLauncherFiles()); @@ -107,13 +126,114 @@ public static void CreateTool(string path) } Log.Verbose($"[SCT] XIVLauncher installed as Steam compatibility tool to folder {destination.FullName}"); + SetConfigValues(isFlatpak); } - public static void DeleteTool(string path) + public static void DeleteTool(bool isFlatpak) { + var path = isFlatpak ? Program.Config.SteamFlatpakPath : Program.Config.SteamPath; var steamToolFolder = new DirectoryInfo(Path.Combine(path, "compatibilitytools.d", "xlcore")); if (!steamToolFolder.Exists) return; steamToolFolder.Delete(true); Log.Verbose($"[SCT] Deleted Steam compatibility tool at folder {steamToolFolder.FullName}"); + SetConfigValues(isFlatpak); + } + + public static void UpdateSteamTools(bool console = false) + { + if (CoreEnvironmentSettings.IsSteamCompatTool) + return; + + var message = UpdateTool(false); + if (console) + Console.WriteLine(message); + + message = UpdateTool(true); + if (console) + Console.WriteLine(message); + } + + public static string CheckVersion(bool isFlatpak) + { + var path = isFlatpak ? Program.Config.SteamFlatpakPath : Program.Config.SteamPath; + var versionFile = new FileInfo(Path.Combine(path, "compatibilitytools.d", "xlcore", "version")); + + if (!versionFile.Exists) + return ""; + + var version = ""; + try + { + using (var sr = new StreamReader(versionFile.FullName)) + { + var toolVersion = sr.ReadLine() ?? ""; + var release = sr.ReadLine() ?? ""; + sr.Close(); + if (string.IsNullOrEmpty(toolVersion)) + toolVersion = "Unknown"; + if (string.IsNullOrEmpty(release)) + release = "Unknown"; + version = toolVersion + ',' + release; + } + } + catch (Exception e) + { + Log.Error(e, $"Could not get the Steam {(isFlatpak ? "(flatpak) " : "")}compatibility tool version at {path}."); + version = "Unknown,Unknown"; + } + return version; + } + + private static string UpdateTool(bool isFlatpak) + { + var message = string.Empty; + + if ((isFlatpak && !IsSteamFlatpakToolInstalled) || (!isFlatpak && !IsSteamToolInstalled)) + { + message = $"Steam {(isFlatpak ? "(flatpak) " : "")}compatibility tool is not installed. Nothing to update."; + Log.Information(message); + return message; + } + var path = isFlatpak ? Program.Config.SteamFlatpakPath : Program.Config.SteamPath; + var versionFile = new FileInfo(Path.Combine(path, "compatibilitytools.d", "xlcore", "version")); + + if (!versionFile.Exists) + { + CreateTool(isFlatpak); + message = $"Updating Steam {(isFlatpak ? "(flatpak) " : "")}compatibility tool at {path}/compatibilitytools.d/xlcore to version {Program.CoreVersion.ToString()}"; + Log.Information(message); + return message; + } + + var toolInfo = CheckVersion(isFlatpak).Split(',', 2); + var toolVersion = toolInfo[0]; + var release = toolInfo[1]; + + try + { + if (release != RELEASE) + { + message = $"Steam {(isFlatpak ? "(flatpak) " : "")}compatibility Tool mismatch! \"{release}\" release is installed, but this is \"{RELEASE}\" release. Not installing update."; + Log.Warning(message); + return message; + } + if (Version.Parse(toolVersion) < Program.CoreVersion) + { + CreateTool(isFlatpak); + message = $"Updating Steam {(isFlatpak ? "(flatpak) " : "")}compatibility tool at {path}/compatibilitytools.d/xlcore to version {Program.CoreVersion.ToString()}"; + Log.Information(message); + } + else + { + message = $"Steam {(isFlatpak ? "(flatpak) " : "")}compatibility tool version at {path} is {toolVersion} >= {Program.CoreVersion.ToString()}, nothing to do."; + Log.Information(message); + } + } + catch (Exception e) + { + message = $"Could not get the Steam {(isFlatpak ? "(flatpak) " : "")}compatibility tool version at {path}. Not installing update."; + Log.Error(e, message); + } + return message; } } \ No newline at end of file diff --git a/src/XIVLauncher.Core/UpdateCheck.cs b/src/XIVLauncher.Core/UpdateCheck.cs index 1f22bd0f..a92b97da 100644 --- a/src/XIVLauncher.Core/UpdateCheck.cs +++ b/src/XIVLauncher.Core/UpdateCheck.cs @@ -16,7 +16,7 @@ public static async Task CheckForUpdate() var response = await client.GetStringAsync(UPDATE_URL).ConfigureAwait(false); var remoteVersion = Version.Parse(response); - var localVersion = Version.Parse(AppUtil.GetAssemblyVersion()); + var localVersion = Program.CoreVersion; return new VersionCheckResult {