Skip to content

Commit 8265f08

Browse files
authored
[Steam shortcuts] Small fixes (#386)
- Fixes folders not being found if the steamID ended with an 0. - Adds/improves some logging when searching for valid userdata folders - Changes target exe/folder to the stub executable/folder * Fix broken steamID check and better folder logging * Change Steam executable path to stub * Fix formatting issue and playtime not updating when using protocols * Copy Game Icon to Steam grid folder
1 parent 9f754dc commit 8265f08

File tree

5 files changed

+49
-35
lines changed

5 files changed

+49
-35
lines changed

CollapseLauncher/Classes/ShortcutCreator/ShortcutCreator.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static bool AddToSteam(PresetConfigV2 preset, bool play)
5454
parser.Insert(preset, play);
5555

5656
parser.Save();
57-
LogWriteLine(string.Format("Added shortcut for {0} - {1} for Steam3ID {2} ", preset.GameName, preset.ZoneName, userId));
57+
LogWriteLine(string.Format("[ShortcutCreator::AddToSteam] Added shortcut for {0} - {1} for Steam3ID {2} ", preset.GameName, preset.ZoneName, userId));
5858
}
5959

6060
return true;
@@ -90,16 +90,22 @@ private static string[] GetShortcutsPath()
9090
string steamUserData = steamPath + @"\userdata";
9191

9292
if (!Directory.Exists(steamUserData))
93+
{
94+
LogWriteLine("[ShortcutCreator::GetShortcutsPath] " + steamUserData + " is not a valid folder.", Hi3Helper.LogType.Error);
9395
return null;
96+
}
9497

9598
var res = Directory.GetDirectories(steamUserData)
9699
.Where(x =>
97-
!(x.EndsWith("ac") || x.EndsWith("0") || x.EndsWith("anonymous"))
98-
).ToArray();
100+
{
101+
string y = x.Split("\\").Last();
102+
return y != "ac" && y != "0" && y != "anonymous";
103+
} ).ToArray();
99104

100105
for (int i = 0; i < res.Length; i++)
101106
{
102107
res[i] = Path.Combine(res[i], @"config\shortcuts.vdf");
108+
LogWriteLine("[ShortcutCreator::GetShortcutsPath] Found profile: " + res[i], Hi3Helper.LogType.Debug);
103109
}
104110

105111
return res;

CollapseLauncher/Classes/ShortcutCreator/SteamShortcut.cs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,16 @@ public SteamShortcut() { }
4646
public SteamShortcut(PresetConfigV2 preset, bool play = false)
4747
{
4848
AppName = string.Format("{0} - {1}", preset.GameName, preset.ZoneName);
49-
Exe = AppExecutablePath;
49+
50+
string stubPath = MainEntryPoint.FindCollapseStubPath();
51+
Exe = string.Format("\"{0}\"", stubPath);
52+
StartDir = string.Format("\"{0}\"", Path.GetDirectoryName(stubPath));
53+
5054
var id = BitConverter.GetBytes(GenerateAppId(Exe, AppName));
5155
appid = SteamShortcutParser.ANSI.GetString(id, 0, id.Length);
5256

53-
icon = Path.Combine(Path.GetDirectoryName(AppExecutablePath), "Assets/Images/GameIcon/" + preset.GameType switch
54-
{
55-
GameType.StarRail => "icon-starrail.ico",
56-
GameType.Genshin => "icon-genshin.ico",
57-
_ => "icon-honkai.ico",
58-
});
59-
6057
preliminaryAppID = GeneratePreliminaryId(Exe, AppName).ToString();
6158

62-
StartDir = Path.GetDirectoryName(AppExecutablePath);
63-
6459
LaunchOptions = string.Format("open -g \"{0}\" -r \"{1}\"", preset.GameName, preset.ZoneName);
6560
if (play)
6661
LaunchOptions += " -p";
@@ -123,6 +118,22 @@ public void MoveImages(string path, PresetConfigV2 preset)
123118
if (!Directory.Exists(gridPath))
124119
Directory.CreateDirectory(gridPath);
125120

121+
string iconName = preset.GameType switch
122+
{
123+
GameType.StarRail => "icon-starrail.ico",
124+
GameType.Genshin => "icon-genshin.ico",
125+
_ => "icon-honkai.ico",
126+
};
127+
128+
icon = Path.Combine(gridPath, iconName);
129+
string iconAssetPath = Path.Combine(Path.GetDirectoryName(AppExecutablePath), "Assets\\Images\\GameIcon\\" + iconName);
130+
131+
if (!Path.Exists(icon) && Path.Exists(iconAssetPath))
132+
{
133+
File.Copy(iconAssetPath, icon);
134+
LogWriteLine(string.Format("[SteamShortcut::MoveImages] Copied icon from {0} to {1}.", iconAssetPath, icon));
135+
}
136+
126137
Dictionary<string, SteamGameProp> assets = preset.ZoneSteamAssets;
127138

128139
// Game background
@@ -169,10 +180,10 @@ private async void GetImageFromUrl(string gridPath, SteamGameProp asset, string
169180

170181
File.Delete(steamPath);
171182

172-
LogWriteLine(string.Format("Invalid checksum for file {0}! {1} does not match {2}.", steamPath, hash, asset.MD5), Hi3Helper.LogType.Error);
183+
LogWriteLine(string.Format("[SteamShortcut::GetImageFromUrl] Invalid checksum for file {0}! {1} does not match {2}.", steamPath, hash, asset.MD5), Hi3Helper.LogType.Error);
173184
}
174185

175-
LogWriteLine("After 3 tries, " + asset.URL + " could not be downloaded successfully.", Hi3Helper.LogType.Error);
186+
LogWriteLine("[SteamShortcut::GetImageFromUrl] After 3 tries, " + asset.URL + " could not be downloaded successfully.", Hi3Helper.LogType.Error);
176187
return;
177188
}
178189

CollapseLauncher/Program.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,20 @@ private static void StartSquirrelHook()
186186
);
187187
}
188188

189+
public static string FindCollapseStubPath()
190+
{
191+
var collapseExecName = "CollapseLauncher.exe";
192+
var collapseMainPath = Process.GetCurrentProcess().MainModule.FileName;
193+
var collapseStubPath = Path.Combine(Directory.GetParent(Path.GetDirectoryName(collapseMainPath)).FullName, collapseExecName);
194+
if (File.Exists(collapseStubPath))
195+
{
196+
LogWriteLine($"Found stub at {collapseStubPath}", LogType.Default, true);
197+
return collapseStubPath;
198+
}
199+
LogWriteLine($"Collapse stub does not exist, returning current executable path!\r\n\t{collapseStubPath}", LogType.Default, true);
200+
return collapseMainPath;
201+
}
202+
189203
public static void InitializeAppSettings()
190204
{
191205
InitializeLocale();

CollapseLauncher/XAMLs/MainApp/Pages/HomePage.xaml.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,7 @@ private async void StartLoadedRoutine(object sender, RoutedEventArgs e)
166166
StartGame(null, null);
167167
m_arguments.StartGame.Play = false;
168168
}
169-
else
170-
{
171-
AutoUpdatePlaytimeCounter(false, PlaytimeToken.Token);
172-
}
169+
AutoUpdatePlaytimeCounter(false, PlaytimeToken.Token);
173170

174171
StartCarouselAutoScroll(CarouselToken.Token);
175172
}

CollapseLauncher/XAMLs/MainApp/Pages/SettingsPage.xaml.cs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ private void Egg(object sender, Microsoft.UI.Xaml.Input.PointerRoutedEventArgs e
317317

318318
private Task CreateScheduledTask(string taskName)
319319
{
320-
string collapseStartupTarget = FindCollapseStubPath();
320+
string collapseStartupTarget = MainEntryPoint.FindCollapseStubPath();
321321

322322
using TaskService ts = new TaskService();
323323

@@ -334,20 +334,6 @@ private Task CreateScheduledTask(string taskName)
334334
taskDefinition.Dispose();
335335
return task;
336336
}
337-
338-
public string FindCollapseStubPath()
339-
{
340-
var collapseExecName = "CollapseLauncher.exe";
341-
var collapseMainPath = Process.GetCurrentProcess().MainModule.FileName;
342-
var collapseStubPath = Path.Combine(Directory.GetParent(Path.GetDirectoryName(collapseMainPath)).FullName, collapseExecName);
343-
if (File.Exists(collapseStubPath))
344-
{
345-
LogWriteLine($"Found stub at {collapseStubPath}", LogType.Default, true);
346-
return collapseStubPath;
347-
}
348-
LogWriteLine($"Collapse stub does not exist, returning current executable path!\r\n\t{collapseStubPath}", LogType.Default, true);
349-
return collapseMainPath;
350-
}
351337
#endregion
352338

353339
#region Settings UI Backend
@@ -760,7 +746,7 @@ private bool IsStartupToTray
760746
}
761747
set
762748
{
763-
string collapseStartupTarget = FindCollapseStubPath();
749+
string collapseStartupTarget = MainEntryPoint.FindCollapseStubPath();
764750
using TaskService ts = new TaskService();
765751

766752
Task task = ts.GetTask(_collapseStartupTaskName);

0 commit comments

Comments
 (0)