/// <summary> /// Iterates over all existing Steam shortcuts and returns all SteamLauncher shortcuts (shortcuts with tag <see cref="DefaultShortcut.TAG"/>). /// </summary> /// <returns></returns> private static IEnumerable <UInt32> GetSteamLauncherShortcuts() { UInt32 shortcutCount = ClientShortcuts.GetShortcutCount(); Logger.Info($"Searching {shortcutCount} shortcuts to find all SteamLauncher shortcuts."); for (UInt32 sc = 0; sc < shortcutCount; sc++) { UInt32 appId = ClientShortcuts.GetShortcutAppIdByIndex(sc); if (appId == 0) { continue; } // TODO: The Steam update on 2018-10-13 broke SteamLauncher 0.9.0.4. The call to GetShortcutUserTagCountByAppId is returning a very large invalid number (in most cases it should be 0). I suspect something has changed in the vftable offsets again. // Check if the shortcut has the unique SteamLauncher user category tag for (UInt32 tc = 0; tc < ClientShortcuts.GetShortcutUserTagCountByAppId(appId); tc++) { if (!string.Equals(ClientShortcuts.GetShortcutUserTagByAppId(appId, tc), DefaultShortcut.TAG, StringComparison.OrdinalIgnoreCase)) { continue; } Logger.Info($"SteamLauncher shortcut found: [{appId}] {ClientShortcuts.GetShortcutAppNameByAppId(appId)}"); yield return(appId); break; } } }
/// <summary> /// Gets/creates Steam shortcut, assigns this instance's properties to the Steam shortcut, and then launches the shortcut in Steam. /// </summary> /// <returns>True if successful; otherwise, false.</returns> public bool LaunchShortcut() { AppId = GetNewOrExistingShortcut(out var isShortcutNew); if (AppId == 0) { return(false); } Logger.Info($"Assigning properties to {(isShortcutNew ? "new" : "existing")} Steam shortcut: " + $"[{AppId}] '{AppName}' | {ExePathInDoubleQuotes} | {StartDirInDoubleQuotes} | {CommandLine}"); ClientShortcuts.SetShortcutAppName(AppId, AppName); ClientShortcuts.SetShortcutExe(AppId, ExePathInDoubleQuotes); ClientShortcuts.SetShortcutStartDir(AppId, StartDirInDoubleQuotes); ClientShortcuts.SetShortcutCommandLine(AppId, CommandLine); // Wait a moment to ensure Steam is done altering the shortcut System.Threading.Thread.Sleep(500); // Get the ShortcutID for this shortcut so we can construct a Steam shortcut URL var crc = ResolveShortcutId(ExePathInDoubleQuotes, AppName); Logger.Info($"'{AppName}' ShortcutID resolved to: {crc}"); var steamUrl = $"steam://rungameid/{crc}"; Logger.Info($"Starting Steam shortcut: {steamUrl}"); // Start the shortcut Process.Start(steamUrl); return(true); }
/// <summary> /// Iterates over all existing Steam shortcuts and returns all SteamLauncher shortcuts (shortcuts with tag <see cref="DefaultShortcut.TAG"/>). /// </summary> /// <returns></returns> private static IEnumerable <UInt32> GetSteamLauncherShortcuts() { UInt32 shortcutCount = ClientShortcuts.GetShortcutCount(); Logger.Info($"Searching {shortcutCount} shortcuts to find all SteamLauncher shortcuts."); for (UInt32 sc = 0; sc < shortcutCount; sc++) { UInt32 appId = ClientShortcuts.GetShortcutAppIdByIndex(sc); if (appId == 0) { continue; } // Check if the shortcut has the unique SteamLauncher user category tag for (UInt32 tc = 0; tc < ClientShortcuts.GetShortcutUserTagCountByAppId(appId); tc++) { if (!string.Equals(ClientShortcuts.GetShortcutUserTagByAppId(appId, tc), DefaultShortcut.TAG, StringComparison.OrdinalIgnoreCase)) { continue; } Logger.Info($"SteamLauncher shortcut found: [{appId}] {ClientShortcuts.GetShortcutAppNameByAppId(appId)}"); yield return(appId); break; } } }
/// <summary> /// Resets the shortcut's properties to the SteamShortcutManager default settings. /// </summary> /// <returns>True if successful; otherwise, false.</returns> public bool ResetProxyShortcut() { if (AppId == 0) { return(false); } Logger.Info($"Resetting shortcut properties [{AppId}]."); ClientShortcuts.SetShortcutAppName(AppId, DefaultShortcut.NAME); ClientShortcuts.SetShortcutExe(AppId, DefaultShortcut.EXE); ClientShortcuts.SetShortcutStartDir(AppId, DefaultShortcut.START_DIR); ClientShortcuts.ClearShortcutUserTags(AppId); ClientShortcuts.AddShortcutUserTag(AppId, DefaultShortcut.TAG); ClientShortcuts.SetShortcutHidden(AppId, true); return(true); }
/// <summary> /// Creates a hidden Steam shortcut with the name '<see cref="DefaultShortcut.NAME"/>' and an exe path of '<see cref="DefaultShortcut.EXE"/>'. /// </summary> /// <returns>The AppID of the newly created shortcut.</returns> private static UInt32 CreateDefaultShortcut() { UInt32 appId = ClientShortcuts.AddShortcut(DefaultShortcut.NAME, DefaultShortcut.EXE, "", "", ""); if (appId == 0) { const string errorMsg = "An unexpected problem occurred while trying to create a default SteamLauncher shortcut."; Logger.Error(errorMsg); throw new InvalidOperationException(errorMsg); } ClientShortcuts.AddShortcutUserTag(appId, DefaultShortcut.TAG); ClientShortcuts.SetShortcutHidden(appId, true); ClientShortcuts.SetAllowOverlay(appId, true); ClientShortcuts.SetAllowDesktopConfig(appId, true); return(appId); }
/// <summary> /// Cleans up excess SteamLauncher shortcuts if more than one is found and returns AppID of remaining single instance. /// </summary> /// <returns>AppID of single remaining instance of SteamLauncher shortcut.</returns> private static UInt32 RecycleShortcut() { List <UInt32> steamLauncherShortcuts = GetSteamLauncherShortcuts().ToList(); if (steamLauncherShortcuts.Count == 0) { Logger.Info("No existing SteamLauncher shortcuts found."); return(0); } UInt32 keepShortcut = steamLauncherShortcuts[0]; Logger.Info($"Recycling shortcut with AppID: {keepShortcut}"); steamLauncherShortcuts.RemoveAt(0); if (steamLauncherShortcuts.Count > 0) { Logger.Info($"Removing {steamLauncherShortcuts.Count} residual shortcuts."); steamLauncherShortcuts.ForEach(shortcut => ClientShortcuts.RemoveShortcut(shortcut)); } return(keepShortcut); }