summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-10-17 20:02:19 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-10-17 20:02:19 -0400
commit0e4dd8a7b446d85d4603d55043af42aac5968b5a (patch)
tree7f847f5b91227e0f66d84e55d325df4d2a89dc8c
parent4e91174b3ed265c31c54b2242711ca9d51bae1ca (diff)
downloadSMAPI-0e4dd8a7b446d85d4603d55043af42aac5968b5a.tar.gz
SMAPI-0e4dd8a7b446d85d4603d55043af42aac5968b5a.tar.bz2
SMAPI-0e4dd8a7b446d85d4603d55043af42aac5968b5a.zip
prevent Steam vdf read errors from crashing the installer
-rw-r--r--docs/release-notes.md3
-rw-r--r--src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs63
2 files changed, 40 insertions, 26 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md
index ff5d61ba..02d085d5 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -8,6 +8,9 @@
-->
## Upcoming release
+* For players:
+ * Fixed installer crash if Steam's library data is invalid or in an old format; it'll now be ignored instead.
+
* For mod authors:
* Fixed image patches sometimes applied one pixel higher than expected after 3.17.0 (thanks to atravita!).
diff --git a/src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs b/src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs
index 1d518738..88142805 100644
--- a/src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs
+++ b/src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs
@@ -261,39 +261,50 @@ namespace StardewModdingAPI.Toolkit.Framework.GameScanning
/// <returns>The game directory, if found.</returns>
private string? GetPathFromSteamLibrary(string? steamPath)
{
- if (steamPath == null)
- return null;
-
- // get .vdf file path
- string libraryFoldersPath = Path.Combine(steamPath.Replace('/', '\\'), "steamapps\\libraryfolders.vdf");
- if (!File.Exists(libraryFoldersPath))
- return null;
-
- // read data
- using FileStream fileStream = File.OpenRead(libraryFoldersPath);
- VdfDeserializer deserializer = new();
- dynamic libraries = deserializer.Deserialize(fileStream);
- if (libraries?.libraryfolders is null)
- return null;
-
- // get path from Stardew Valley app (if any)
- foreach (dynamic pair in libraries.libraryfolders)
+ try
{
- dynamic library = pair.Value;
-
- foreach (dynamic app in library.apps)
+ if (steamPath == null)
+ return null;
+
+ // get .vdf file path
+ string libraryFoldersPath = Path.Combine(steamPath.Replace('/', '\\'), "steamapps\\libraryfolders.vdf");
+ if (!File.Exists(libraryFoldersPath))
+ return null;
+
+ // read data
+ using FileStream fileStream = File.OpenRead(libraryFoldersPath);
+ VdfDeserializer deserializer = new();
+ dynamic libraries = deserializer.Deserialize(fileStream);
+ if (libraries?.libraryfolders is null)
+ return null;
+
+ // get path from Stardew Valley app (if any)
+ foreach (dynamic pair in libraries.libraryfolders)
{
- string key = app.Key;
- if (key == GameScanner.SteamAppId)
+ dynamic library = pair.Value;
+
+ foreach (dynamic app in library.apps)
{
- string path = library.path;
+ string key = app.Key;
+ if (key == GameScanner.SteamAppId)
+ {
+ string path = library.path;
- return Path.Combine(path.Replace("\\\\", "\\"), "steamapps", "common", "Stardew Valley");
+ return Path.Combine(path.Replace("\\\\", "\\"), "steamapps", "common", "Stardew Valley");
+ }
}
}
- }
- return null;
+ return null;
+ }
+ catch
+ {
+ // The file might not be parseable in some cases (e.g. some players have an older Steam version using
+ // a different format). Ideally we'd log an error to know when it's actually an issue, but the SMAPI
+ // installer doesn't have a logging mechanism (and third-party code calling the toolkit may not either).
+ // So for now, just ignore the error and fallback to the other discovery mechanisms.
+ return null;
+ }
}
#endif
}