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..763af5a65 100644 --- a/CollapseLauncher/Classes/ShortcutCreator/SteamShortcut.cs +++ b/CollapseLauncher/Classes/ShortcutCreator/SteamShortcut.cs @@ -46,21 +46,16 @@ public SteamShortcut() { } public SteamShortcut(PresetConfigV2 preset, bool play = false) { AppName = string.Format("{0} - {1}", preset.GameName, preset.ZoneName); - Exe = AppExecutablePath; + + 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); - 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(); - StartDir = Path.GetDirectoryName(AppExecutablePath); - LaunchOptions = string.Format("open -g \"{0}\" -r \"{1}\"", preset.GameName, preset.ZoneName); if (play) LaunchOptions += " -p"; @@ -123,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 @@ -169,10 +180,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; } 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/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); } 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);