From 8a525f9d811bf720c2ecb67d93a8b1d8e9546ec8 Mon Sep 17 00:00:00 2001 From: Gabriel Lima <44784408+gablm@users.noreply.github.com> Date: Fri, 2 Feb 2024 11:32:19 +0000 Subject: [PATCH 1/4] Fix broken steamID check and better folder logging --- .../Classes/ShortcutCreator/ShortcutCreator.cs | 12 +++++++++--- .../Classes/ShortcutCreator/SteamShortcut.cs | 4 ++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CollapseLauncher/Classes/ShortcutCreator/ShortcutCreator.cs b/CollapseLauncher/Classes/ShortcutCreator/ShortcutCreator.cs index db35aa23b..edd70518c 100644 --- a/CollapseLauncher/Classes/ShortcutCreator/ShortcutCreator.cs +++ b/CollapseLauncher/Classes/ShortcutCreator/ShortcutCreator.cs @@ -54,7 +54,7 @@ public static bool AddToSteam(PresetConfigV2 preset, bool play) parser.Insert(preset, play); parser.Save(); - LogWriteLine(string.Format("Added shortcut for {0} - {1} for Steam3ID {2} ", preset.GameName, preset.ZoneName, userId)); + LogWriteLine(string.Format("[ShortcutCreator::AddToSteam] Added shortcut for {0} - {1} for Steam3ID {2} ", preset.GameName, preset.ZoneName, userId)); } return true; @@ -90,16 +90,22 @@ private static string[] GetShortcutsPath() string steamUserData = steamPath + @"\userdata"; if (!Directory.Exists(steamUserData)) + { + LogWriteLine("[ShortcutCreator::GetShortcutsPath] " + steamUserData + " is not a valid folder.", Hi3Helper.LogType.Error); return null; + } var res = Directory.GetDirectories(steamUserData) .Where(x => - !(x.EndsWith("ac") || x.EndsWith("0") || x.EndsWith("anonymous")) - ).ToArray(); + { + string y = x.Split("\\").Last(); + return y != "ac" && y != "0" && y != "anonymous"; + } ).ToArray(); for (int i = 0; i < res.Length; i++) { res[i] = Path.Combine(res[i], @"config\shortcuts.vdf"); + LogWriteLine("[ShortcutCreator::GetShortcutsPath] Found profile: " + res[i], Hi3Helper.LogType.Debug); } return res; diff --git a/CollapseLauncher/Classes/ShortcutCreator/SteamShortcut.cs b/CollapseLauncher/Classes/ShortcutCreator/SteamShortcut.cs index 5d44f6e05..9926c8e8a 100644 --- a/CollapseLauncher/Classes/ShortcutCreator/SteamShortcut.cs +++ b/CollapseLauncher/Classes/ShortcutCreator/SteamShortcut.cs @@ -169,10 +169,10 @@ private async void GetImageFromUrl(string gridPath, SteamGameProp asset, string File.Delete(steamPath); - LogWriteLine(string.Format("Invalid checksum for file {0}! {1} does not match {2}.", steamPath, hash, asset.MD5), Hi3Helper.LogType.Error); + LogWriteLine(string.Format("[SteamShortcut::GetImageFromUrl] Invalid checksum for file {0}! {1} does not match {2}.", steamPath, hash, asset.MD5), Hi3Helper.LogType.Error); } - LogWriteLine("After 3 tries, " + asset.URL + " could not be downloaded successfully.", Hi3Helper.LogType.Error); + LogWriteLine("[SteamShortcut::GetImageFromUrl] After 3 tries, " + asset.URL + " could not be downloaded successfully.", Hi3Helper.LogType.Error); return; } From bcb597d4ff1d65577e9b51d5602766807f635b05 Mon Sep 17 00:00:00 2001 From: Gabriel Lima <44784408+gablm@users.noreply.github.com> Date: Fri, 2 Feb 2024 12:40:14 +0000 Subject: [PATCH 2/4] Change Steam executable path to stub --- .../Classes/ShortcutCreator/SteamShortcut.cs | 6 +++--- CollapseLauncher/Program.cs | 14 ++++++++++++++ .../XAMLs/MainApp/Pages/SettingsPage.xaml.cs | 18 ++---------------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/CollapseLauncher/Classes/ShortcutCreator/SteamShortcut.cs b/CollapseLauncher/Classes/ShortcutCreator/SteamShortcut.cs index 9926c8e8a..eef61604f 100644 --- a/CollapseLauncher/Classes/ShortcutCreator/SteamShortcut.cs +++ b/CollapseLauncher/Classes/ShortcutCreator/SteamShortcut.cs @@ -46,11 +46,11 @@ public SteamShortcut() { } public SteamShortcut(PresetConfigV2 preset, bool play = false) { AppName = string.Format("{0} - {1}", preset.GameName, preset.ZoneName); - Exe = AppExecutablePath; + Exe = MainEntryPoint.FindCollapseStubPath(); var id = BitConverter.GetBytes(GenerateAppId(Exe, AppName)); appid = SteamShortcutParser.ANSI.GetString(id, 0, id.Length); - icon = Path.Combine(Path.GetDirectoryName(AppExecutablePath), "Assets/Images/GameIcon/" + preset.GameType switch + icon = Path.Combine(Path.GetDirectoryName(AppExecutablePath), "Assets\\Images\\GameIcon\\" + preset.GameType switch { GameType.StarRail => "icon-starrail.ico", GameType.Genshin => "icon-genshin.ico", @@ -59,7 +59,7 @@ public SteamShortcut(PresetConfigV2 preset, bool play = false) preliminaryAppID = GeneratePreliminaryId(Exe, AppName).ToString(); - StartDir = Path.GetDirectoryName(AppExecutablePath); + StartDir = Path.GetDirectoryName(Exe); LaunchOptions = string.Format("open -g \"{0}\" -r \"{1}\"", preset.GameName, preset.ZoneName); if (play) diff --git a/CollapseLauncher/Program.cs b/CollapseLauncher/Program.cs index 2de4c8245..d2c9b1958 100644 --- a/CollapseLauncher/Program.cs +++ b/CollapseLauncher/Program.cs @@ -186,6 +186,20 @@ private static void StartSquirrelHook() ); } + public static string FindCollapseStubPath() + { + var collapseExecName = "CollapseLauncher.exe"; + var collapseMainPath = Process.GetCurrentProcess().MainModule.FileName; + var collapseStubPath = Path.Combine(Directory.GetParent(Path.GetDirectoryName(collapseMainPath)).FullName, collapseExecName); + if (File.Exists(collapseStubPath)) + { + LogWriteLine($"Found stub at {collapseStubPath}", LogType.Default, true); + return collapseStubPath; + } + LogWriteLine($"Collapse stub does not exist, returning current executable path!\r\n\t{collapseStubPath}", LogType.Default, true); + return collapseMainPath; + } + public static void InitializeAppSettings() { InitializeLocale(); diff --git a/CollapseLauncher/XAMLs/MainApp/Pages/SettingsPage.xaml.cs b/CollapseLauncher/XAMLs/MainApp/Pages/SettingsPage.xaml.cs index e97959a7f..97be6ca23 100644 --- a/CollapseLauncher/XAMLs/MainApp/Pages/SettingsPage.xaml.cs +++ b/CollapseLauncher/XAMLs/MainApp/Pages/SettingsPage.xaml.cs @@ -317,7 +317,7 @@ private void Egg(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e private Task CreateScheduledTask(string taskName) { - string collapseStartupTarget = FindCollapseStubPath(); + string collapseStartupTarget = MainEntryPoint.FindCollapseStubPath(); using TaskService ts = new TaskService(); @@ -334,20 +334,6 @@ private Task CreateScheduledTask(string taskName) taskDefinition.Dispose(); return task; } - - public string FindCollapseStubPath() - { - var collapseExecName = "CollapseLauncher.exe"; - var collapseMainPath = Process.GetCurrentProcess().MainModule.FileName; - var collapseStubPath = Path.Combine(Directory.GetParent(Path.GetDirectoryName(collapseMainPath)).FullName, collapseExecName); - if (File.Exists(collapseStubPath)) - { - LogWriteLine($"Found stub at {collapseStubPath}", LogType.Default, true); - return collapseStubPath; - } - LogWriteLine($"Collapse stub does not exist, returning current executable path!\r\n\t{collapseStubPath}", LogType.Default, true); - return collapseMainPath; - } #endregion #region Settings UI Backend @@ -760,7 +746,7 @@ private bool IsStartupToTray } set { - string collapseStartupTarget = FindCollapseStubPath(); + string collapseStartupTarget = MainEntryPoint.FindCollapseStubPath(); using TaskService ts = new TaskService(); Task task = ts.GetTask(_collapseStartupTaskName); From e886477dd3c92bdd09faae14cd1af1fa8c56aa8f Mon Sep 17 00:00:00 2001 From: Gabriel Lima <44784408+gablm@users.noreply.github.com> Date: Fri, 2 Feb 2024 13:38:49 +0000 Subject: [PATCH 3/4] Fix formatting issue and playtime not updating when using protocols --- CollapseLauncher/Classes/ShortcutCreator/SteamShortcut.cs | 8 +++++--- CollapseLauncher/XAMLs/MainApp/Pages/HomePage.xaml.cs | 5 +---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/CollapseLauncher/Classes/ShortcutCreator/SteamShortcut.cs b/CollapseLauncher/Classes/ShortcutCreator/SteamShortcut.cs index eef61604f..3908887ad 100644 --- a/CollapseLauncher/Classes/ShortcutCreator/SteamShortcut.cs +++ b/CollapseLauncher/Classes/ShortcutCreator/SteamShortcut.cs @@ -46,7 +46,11 @@ public SteamShortcut() { } public SteamShortcut(PresetConfigV2 preset, bool play = false) { AppName = string.Format("{0} - {1}", preset.GameName, preset.ZoneName); - Exe = MainEntryPoint.FindCollapseStubPath(); + + string stubPath = MainEntryPoint.FindCollapseStubPath(); + Exe = string.Format("\"{0}\"", stubPath); + StartDir = string.Format("\"{0}\"", Path.GetDirectoryName(stubPath)); + var id = BitConverter.GetBytes(GenerateAppId(Exe, AppName)); appid = SteamShortcutParser.ANSI.GetString(id, 0, id.Length); @@ -59,8 +63,6 @@ public SteamShortcut(PresetConfigV2 preset, bool play = false) preliminaryAppID = GeneratePreliminaryId(Exe, AppName).ToString(); - StartDir = Path.GetDirectoryName(Exe); - LaunchOptions = string.Format("open -g \"{0}\" -r \"{1}\"", preset.GameName, preset.ZoneName); if (play) LaunchOptions += " -p"; diff --git a/CollapseLauncher/XAMLs/MainApp/Pages/HomePage.xaml.cs b/CollapseLauncher/XAMLs/MainApp/Pages/HomePage.xaml.cs index c9ce3f9ee..63a6f6a9d 100644 --- a/CollapseLauncher/XAMLs/MainApp/Pages/HomePage.xaml.cs +++ b/CollapseLauncher/XAMLs/MainApp/Pages/HomePage.xaml.cs @@ -166,10 +166,7 @@ private async void StartLoadedRoutine(object sender, RoutedEventArgs e) StartGame(null, null); m_arguments.StartGame.Play = false; } - else - { - AutoUpdatePlaytimeCounter(false, PlaytimeToken.Token); - } + AutoUpdatePlaytimeCounter(false, PlaytimeToken.Token); StartCarouselAutoScroll(CarouselToken.Token); } From 1c46b213b5415c9f38786a6ba62d326e95595233 Mon Sep 17 00:00:00 2001 From: Gabriel Lima <44784408+gablm@users.noreply.github.com> Date: Tue, 6 Feb 2024 01:32:03 +0000 Subject: [PATCH 4/4] Copy Game Icon to Steam grid folder --- .../Classes/ShortcutCreator/SteamShortcut.cs | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/CollapseLauncher/Classes/ShortcutCreator/SteamShortcut.cs b/CollapseLauncher/Classes/ShortcutCreator/SteamShortcut.cs index 3908887ad..763af5a65 100644 --- a/CollapseLauncher/Classes/ShortcutCreator/SteamShortcut.cs +++ b/CollapseLauncher/Classes/ShortcutCreator/SteamShortcut.cs @@ -54,13 +54,6 @@ public SteamShortcut(PresetConfigV2 preset, bool play = false) var id = BitConverter.GetBytes(GenerateAppId(Exe, AppName)); appid = SteamShortcutParser.ANSI.GetString(id, 0, id.Length); - icon = Path.Combine(Path.GetDirectoryName(AppExecutablePath), "Assets\\Images\\GameIcon\\" + preset.GameType switch - { - GameType.StarRail => "icon-starrail.ico", - GameType.Genshin => "icon-genshin.ico", - _ => "icon-honkai.ico", - }); - preliminaryAppID = GeneratePreliminaryId(Exe, AppName).ToString(); LaunchOptions = string.Format("open -g \"{0}\" -r \"{1}\"", preset.GameName, preset.ZoneName); @@ -125,6 +118,22 @@ public void MoveImages(string path, PresetConfigV2 preset) if (!Directory.Exists(gridPath)) Directory.CreateDirectory(gridPath); + string iconName = preset.GameType switch + { + GameType.StarRail => "icon-starrail.ico", + GameType.Genshin => "icon-genshin.ico", + _ => "icon-honkai.ico", + }; + + icon = Path.Combine(gridPath, iconName); + string iconAssetPath = Path.Combine(Path.GetDirectoryName(AppExecutablePath), "Assets\\Images\\GameIcon\\" + iconName); + + if (!Path.Exists(icon) && Path.Exists(iconAssetPath)) + { + File.Copy(iconAssetPath, icon); + LogWriteLine(string.Format("[SteamShortcut::MoveImages] Copied icon from {0} to {1}.", iconAssetPath, icon)); + } + Dictionary assets = preset.ZoneSteamAssets; // Game background