Skip to content

Commit

Permalink
Bug fix: Steam launch error on gamevault app location change + Added …
Browse files Browse the repository at this point in the history
…list icon to steam shortcuts
  • Loading branch information
Yelo420 committed Dec 10, 2024
1 parent 55dce79 commit fc7a0b2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
2 changes: 1 addition & 1 deletion gamevault/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
[assembly: AssemblyVersion("1.13.2.0")]
[assembly: AssemblyVersion("1.14.0.0")]
[assembly: AssemblyCopyright("© Phalcode™. All Rights Reserved.")]
#if DEBUG
[assembly: XmlnsDefinition("debug-mode", "Namespace")]
Expand Down
48 changes: 38 additions & 10 deletions gamevault/Helper/Integrations/SteamHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ await Task.Run(async () =>
shortcutFileMap = VdfUtilities.ReadVdf(File.ReadAllBytes(Path.Combine(shortcutsDirectory, "shortcuts.vdf")));
shortcutFileMap = TrimFirstOffsetEntry(shortcutFileMap);//Making sure to have a clean game list
shortcutFileMap = RemoveUninstalledGames(shortcutFileMap, games, out steamGridImageIDsToRemove);//Checks for gamevault games and compares them to the current installed game list. Extracts also the steam grid image ids for clean removal later on
shortcutFileMap = EnsureAssemblyPath(shortcutFileMap);//Checks if paths are up to date. Can change because of a manual move or a MC Store update
games = TrimExistingGames(games, shortcutFileMap);//No need for double entries. So they will be removed
}
catch { }
Expand All @@ -261,7 +262,7 @@ await Task.Run(async () =>
{
File.Create(shortcutFile).Close();
}
shortcutFileMap = AddGamesToShortcuts(shortcutFileMap, games);
shortcutFileMap = AddGamesToShortcuts(shortcutFileMap, games, shortcutsDirectory);

VdfMap root = new VdfMap();
root.Add("shortcuts", shortcutFileMap);//Adds back the first offset entry a vdf file needs to work
Expand Down Expand Up @@ -305,12 +306,13 @@ internal static void RemoveGameVaultGamesFromSteamShortcuts()
VdfMap shortcutFileMap = VdfUtilities.ReadVdf(File.ReadAllBytes(shortcutFile));
shortcutFileMap = TrimFirstOffsetEntry(shortcutFileMap);//Making sure to have a clean game list
List<string> steamGridImageIDsToRemove = new List<string>();
string exeFullPath = Process.GetCurrentProcess().MainModule.FileName;
//string exeFullPath = Process.GetCurrentProcess().MainModule.FileName;
for (int count = 0; count < shortcutFileMap.Count; count++)
{
string currentGameExe = ((VdfMap)shortcutFileMap.Values.ElementAt(count)).ElementAt(2).Value.ToString();
string currentGameTitle = ((VdfMap)shortcutFileMap.Values.ElementAt(count)).ElementAt(1).Value.ToString();
if (currentGameExe == exeFullPath)
//Check for gamevault exe instead of the path because MC store changes app directory on updates
if (currentGameExe.Contains("gamevault.exe", StringComparison.OrdinalIgnoreCase))
{
steamGridImageIDsToRemove.Add(((VdfMap)shortcutFileMap.Values.ElementAt(count)).ElementAt(0).Value.ToString());
shortcutFileMap.Remove(shortcutFileMap.ElementAt(count).Key);
Expand Down Expand Up @@ -356,15 +358,40 @@ private static void SetSteamGridImages(string steamGridDirectory, Game game, uin
File.Copy(imageCache["gbg"], Path.Combine(steamGridDirectory, $"{steamGridID}_hero.png"));
}
}
private static VdfMap EnsureAssemblyPath(VdfMap shortcutFileMap)
{
string exeFullPath = Process.GetCurrentProcess().MainModule.FileName;
for (int count = 0; count < shortcutFileMap.Count; count++)
{
string currentGameExe = ((VdfMap)shortcutFileMap.Values.ElementAt(count)).ElementAt(2).Value.ToString();
//string currentGameStartDir = ((VdfMap)shortcutFileMap.Values.ElementAt(count)).ElementAt(3).Value.ToString();
if (currentGameExe.Contains("gamevault.exe", StringComparison.OrdinalIgnoreCase) && currentGameExe != exeFullPath)
{
string workingDirectory = AppDomain.CurrentDomain.BaseDirectory;

//Set updated exe
var exeOuterKey = shortcutFileMap.Keys.ElementAt(count);
VdfMap exeInnerDictionary = (VdfMap)shortcutFileMap[exeOuterKey];
var exeInnerKey = exeInnerDictionary.Keys.ElementAt(2);
exeInnerDictionary[exeInnerKey] = exeFullPath;
//Set updated working dir
var workDirOuterKey = shortcutFileMap.Keys.ElementAt(count);
VdfMap workDirInnerDictionary = (VdfMap)shortcutFileMap[workDirOuterKey];
var workDirInnerKey = workDirInnerDictionary.Keys.ElementAt(3);
workDirInnerDictionary[workDirInnerKey] = workingDirectory;
}
}
return shortcutFileMap;
}
private static VdfMap RemoveUninstalledGames(VdfMap shortcutFileMap, Dictionary<Game, string> games, out List<string> steamGridImagesToRemove)
{
steamGridImagesToRemove = new List<string>();
string exeFullPath = Process.GetCurrentProcess().MainModule.FileName;
for (int count = 0; count < shortcutFileMap.Count; count++)
{
string currentGameExe = ((VdfMap)shortcutFileMap.Values.ElementAt(count)).ElementAt(2).Value.ToString();
string currentGameTitle = ((VdfMap)shortcutFileMap.Values.ElementAt(count)).ElementAt(1).Value.ToString();
if (currentGameExe == exeFullPath && !games.Keys.Any(g => g?.Title == currentGameTitle))
//Check for gamevault exe instead of the path because MC store changes app directory on updates
if (currentGameExe.Contains("gamevault.exe", StringComparison.OrdinalIgnoreCase) && !games.Keys.Any(g => g?.Title == currentGameTitle))
{
steamGridImagesToRemove.Add(((VdfMap)shortcutFileMap.Values.ElementAt(count)).ElementAt(0).Value.ToString());
shortcutFileMap.Remove(shortcutFileMap.ElementAt(count).Key);
Expand All @@ -373,7 +400,7 @@ private static VdfMap RemoveUninstalledGames(VdfMap shortcutFileMap, Dictionary<
}
return shortcutFileMap;
}
private static VdfMap AddGamesToShortcuts(VdfMap shortcutFileMap, Dictionary<Game, string> games)
private static VdfMap AddGamesToShortcuts(VdfMap shortcutFileMap, Dictionary<Game, string> games, string shortcutDir)
{
if (shortcutFileMap == null)
{
Expand All @@ -382,26 +409,27 @@ private static VdfMap AddGamesToShortcuts(VdfMap shortcutFileMap, Dictionary<Gam
int indexCount = shortcutFileMap.Count;
foreach (KeyValuePair<Game, string> game in games)
{
VdfMap newGameMap = GenerateVdfShortcutEntryFromGame(game.Key);
VdfMap newGameMap = GenerateVdfShortcutEntryFromGame(game.Key, shortcutDir);
shortcutFileMap.Add(indexCount.ToString(), newGameMap);
indexCount++;
}
return shortcutFileMap;
}
private static VdfMap GenerateVdfShortcutEntryFromGame(Game game)
private static VdfMap GenerateVdfShortcutEntryFromGame(Game game, string shortcutDir)
{
string idInput = game.Title + game.ID;
uint steamGridId = VdfUtilities.GenerateSteamGridID(idInput);
string steamGridIconPath = Path.Combine(shortcutDir, "grid", $"{steamGridId}p.png");
string exeFullPath = Process.GetCurrentProcess().MainModule.FileName;//Let GameVault handle the game startup
string workingDirectory = Directory.GetCurrentDirectory();
string workingDirectory = AppDomain.CurrentDomain.BaseDirectory;
string launchOptions = $"start --gameid={game.ID}";
var newGame = new VdfMap
{
{ "appid", steamGridId },
{ "AppName", game.Title },
{ "Exe", exeFullPath },
{ "StartDir", workingDirectory },
{ "icon", "" },
{ "icon", steamGridIconPath },
{ "ShortcutPath", "" },
{ "LaunchOptions", launchOptions },
{ "IsHidden", 0 },
Expand Down
2 changes: 1 addition & 1 deletion gamevault/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public string Version
{
get
{
return Assembly.GetExecutingAssembly().GetName().Version.ToString();
return Assembly.GetExecutingAssembly().GetName().Version.ToString() + " EA";
}
}

Expand Down

0 comments on commit fc7a0b2

Please sign in to comment.