Skip to content

Commit

Permalink
[Steam shortcuts] Small fixes (#386)
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
gablm authored Feb 6, 2024
1 parent 9f754dc commit 8265f08
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 35 deletions.
12 changes: 9 additions & 3 deletions CollapseLauncher/Classes/ShortcutCreator/ShortcutCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
35 changes: 23 additions & 12 deletions CollapseLauncher/Classes/ShortcutCreator/SteamShortcut.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<string, SteamGameProp> assets = preset.ZoneSteamAssets;

// Game background
Expand Down Expand Up @@ -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;
}

Expand Down
14 changes: 14 additions & 0 deletions CollapseLauncher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 1 addition & 4 deletions CollapseLauncher/XAMLs/MainApp/Pages/HomePage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
18 changes: 2 additions & 16 deletions CollapseLauncher/XAMLs/MainApp/Pages/SettingsPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8265f08

Please sign in to comment.