From 715b9b09bae846e1f199ad2271283940c8fce7bd Mon Sep 17 00:00:00 2001 From: atravita-mods <94934860+atravita-mods@users.noreply.github.com> Date: Sun, 18 Sep 2022 12:05:46 -0400 Subject: Update ModScanner.cs Add a few more files to the ignored files like .7z --- src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/SMAPI.Toolkit') diff --git a/src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs b/src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs index a85ef109..d115810a 100644 --- a/src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs +++ b/src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs @@ -45,10 +45,14 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning ".png", ".psd", ".tif", + ".xcf", // gimp files // archives ".rar", ".zip", + ".7z", + ".tar", + ".tar.gz" // backup files ".backup", -- cgit From c6b3446e9cb1d1e02db9db86f143ecfe75e9908c Mon Sep 17 00:00:00 2001 From: pizzaoverhead Date: Thu, 29 Sep 2022 13:33:45 +0100 Subject: Added checking for alternative Steam library install locations when looking for the Stardew Valley install. --- .../Framework/GameScanning/GameScanner.cs | 36 +++++++++++++++++ .../GameScanning/SteamLibraryCollection.cs | 47 ++++++++++++++++++++++ src/SMAPI.Toolkit/SMAPI.Toolkit.csproj | 1 + 3 files changed, 84 insertions(+) create mode 100644 src/SMAPI.Toolkit/Framework/GameScanning/SteamLibraryCollection.cs (limited to 'src/SMAPI.Toolkit') diff --git a/src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs b/src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs index 8e1538a5..8e24dcdf 100644 --- a/src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs +++ b/src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs @@ -9,6 +9,7 @@ using StardewModdingAPI.Toolkit.Utilities; using System.Reflection; #if SMAPI_FOR_WINDOWS using Microsoft.Win32; +using VdfParser; #endif namespace StardewModdingAPI.Toolkit.Framework.GameScanning @@ -158,7 +159,14 @@ namespace StardewModdingAPI.Toolkit.Framework.GameScanning // via Steam library path string? steamPath = this.GetCurrentUserRegistryValue(@"Software\Valve\Steam", "SteamPath"); if (steamPath != null) + { yield return Path.Combine(steamPath.Replace('/', '\\'), @"steamapps\common\Stardew Valley"); + + // Check for Steam libraries in other locations + string? path = this.GetPathFromSteamLibrary(steamPath); + if (!string.IsNullOrWhiteSpace(path)) + yield return path; + } #endif // default GOG/Steam paths @@ -243,6 +251,34 @@ namespace StardewModdingAPI.Toolkit.Framework.GameScanning using (openKey) return (string?)openKey.GetValue(name); } + + /// Get the game directory path from alternative Steam library locations. + /// The full path to the directory containing steam.exe. + /// The game directory, if found. + private string? GetPathFromSteamLibrary(string? steamPath) + { + string stardewAppId = "413150"; + if (steamPath != null) + { + string? libraryFoldersPath = Path.Combine(steamPath.Replace('/', '\\'), "steamapps\\libraryfolders.vdf"); + using FileStream fs = File.OpenRead(libraryFoldersPath); + VdfDeserializer deserializer = new VdfDeserializer(); + SteamLibraryCollection libraries = deserializer.Deserialize(fs); + if (libraries.libraryfolders != null) + { + var stardewLibrary = libraries.libraryfolders.FirstOrDefault(f => + { + var apps = f.Value?.apps; + return apps != null && apps.Any(a => a.Key.Equals(stardewAppId)); + }); + if (stardewLibrary.Value?.path != null) + { + return Path.Combine(stardewLibrary.Value.path.Replace("\\\\", "\\"), @"steamapps\common\Stardew Valley"); + } + } + } + return null; + } #endif } } diff --git a/src/SMAPI.Toolkit/Framework/GameScanning/SteamLibraryCollection.cs b/src/SMAPI.Toolkit/Framework/GameScanning/SteamLibraryCollection.cs new file mode 100644 index 00000000..7a186f69 --- /dev/null +++ b/src/SMAPI.Toolkit/Framework/GameScanning/SteamLibraryCollection.cs @@ -0,0 +1,47 @@ +#if SMAPI_FOR_WINDOWS +using System.Collections.Generic; + +namespace StardewModdingAPI.Toolkit.Framework.GameScanning +{ +#pragma warning disable IDE1006 // Model requires lowercase naming. +#pragma warning disable CS8618 // Required for model. + /// Model for Steam's libraryfolders.vdf. + public class SteamLibraryCollection + { + /// Each entry identifies a different location that part of the Steam games library is installed to. + public LibraryFolders libraryfolders { get; set; } + } + + /// A collection of LibraryFolders. Like a dictionary, but has contentstatsid used as an index also. + /// + /// +#pragma warning disable CS8714 // Required for model. + public class LibraryFolders : Dictionary +#pragma warning restore CS8714 + { + /// Index of the library, starting from "0". + public string contentstatsid { get; set; } + } + + /// A Steam library folder, containing information on the location and size of games installed there. + public class LibraryFolder + { + /// The escaped path to this Steam library folder. There will be a steam.exe here, but this may not be the one the player generally launches. + public string path { get; set; } + /// Label for the library, or "" + public string label { get; set; } + /// ~19-digit identifier. + public string contentid { get; set; } + /// Size of the library in bytes. May show 0 when size is non-zero. + public string totalsize { get; set; } + /// Used for downloads. + public string update_clean_bytes_tally { get; set; } + /// Normally "0". + public string time_last_update_corruption { get; set; } + /// List of Steam app IDs, and their current size in bytes. + public Dictionary apps { get; set; } + } +#pragma warning restore IDE1006 +#pragma warning restore CS8618 +} +#endif diff --git a/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj b/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj index 7b79105f..411fd469 100644 --- a/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj +++ b/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj @@ -14,6 +14,7 @@ + -- cgit From 5a0d337fcf6d18eed55334361b3eef3021912498 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Fri, 7 Oct 2022 00:21:09 -0400 Subject: update FluentHttpClient --- src/SMAPI.Toolkit/SMAPI.Toolkit.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SMAPI.Toolkit') diff --git a/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj b/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj index 7b79105f..bd4f4e3d 100644 --- a/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj +++ b/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj @@ -11,7 +11,7 @@ - + -- cgit From a7f03abe25128dba78d8c22802370a3f9a8aff11 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 8 Oct 2022 13:16:38 -0400 Subject: change square brackets to round ones in manifest name --- src/SMAPI.Toolkit/Serialization/Models/Manifest.cs | 53 +++++++++++++++++----- 1 file changed, 42 insertions(+), 11 deletions(-) (limited to 'src/SMAPI.Toolkit') diff --git a/src/SMAPI.Toolkit/Serialization/Models/Manifest.cs b/src/SMAPI.Toolkit/Serialization/Models/Manifest.cs index da3ad608..8a449f0a 100644 --- a/src/SMAPI.Toolkit/Serialization/Models/Manifest.cs +++ b/src/SMAPI.Toolkit/Serialization/Models/Manifest.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Text; using Newtonsoft.Json; using StardewModdingAPI.Toolkit.Serialization.Converters; @@ -90,13 +91,13 @@ namespace StardewModdingAPI.Toolkit.Serialization.Models [JsonConstructor] public Manifest(string uniqueId, string name, string author, string description, ISemanticVersion version, ISemanticVersion? minimumApiVersion, string? entryDll, IManifestContentPackFor? contentPackFor, IManifestDependency[]? dependencies, string[]? updateKeys) { - this.UniqueID = this.NormalizeWhitespace(uniqueId); - this.Name = this.NormalizeWhitespace(name); - this.Author = this.NormalizeWhitespace(author); - this.Description = this.NormalizeWhitespace(description); + this.UniqueID = this.NormalizeField(uniqueId); + this.Name = this.NormalizeField(name, replaceSquareBrackets: true); + this.Author = this.NormalizeField(author); + this.Description = this.NormalizeField(description); this.Version = version; this.MinimumApiVersion = minimumApiVersion; - this.EntryDll = this.NormalizeWhitespace(entryDll); + this.EntryDll = this.NormalizeField(entryDll); this.ContentPackFor = contentPackFor; this.Dependencies = dependencies ?? Array.Empty(); this.UpdateKeys = updateKeys ?? Array.Empty(); @@ -113,17 +114,47 @@ namespace StardewModdingAPI.Toolkit.Serialization.Models /********* ** Private methods *********/ - /// Normalize whitespace in a raw string. + /// Normalize a manifest field to strip newlines, trim whitespace, and optionally strip square brackets. /// The input to strip. + /// Whether to replace square brackets with round ones. This is used in the mod name to avoid breaking the log format. #if NET5_0_OR_GREATER [return: NotNullIfNotNull("input")] #endif - private string? NormalizeWhitespace(string? input) + private string? NormalizeField(string? input, bool replaceSquareBrackets = false) { - return input - ?.Trim() - .Replace("\r", "") - .Replace("\n", ""); + input = input?.Trim(); + + if (!string.IsNullOrEmpty(input)) + { + StringBuilder? builder = null; + + for (int i = 0; i < input.Length; i++) + { + switch (input[i]) + { + case '\r': + case '\n': + builder ??= new StringBuilder(input); + builder[i] = ' '; + break; + + case '[' when replaceSquareBrackets: + builder ??= new StringBuilder(input); + builder[i] = '('; + break; + + case ']' when replaceSquareBrackets: + builder ??= new StringBuilder(input); + builder[i] = ')'; + break; + } + } + + if (builder != null) + input = builder.ToString(); + } + + return input; } } } -- cgit From ab66266b4bc4d7b1a7ae76d05693e9dd30c03989 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 8 Oct 2022 21:32:10 -0400 Subject: update installer for VdfConverter & rework avoid custom models --- .../Framework/GameScanning/GameScanner.cs | 44 ++++++++++++-------- .../GameScanning/SteamLibraryCollection.cs | 47 ---------------------- src/SMAPI.Toolkit/SMAPI.Toolkit.csproj | 2 +- 3 files changed, 29 insertions(+), 64 deletions(-) delete mode 100644 src/SMAPI.Toolkit/Framework/GameScanning/SteamLibraryCollection.cs (limited to 'src/SMAPI.Toolkit') diff --git a/src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs b/src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs index 8e24dcdf..66465ffe 100644 --- a/src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs +++ b/src/SMAPI.Toolkit/Framework/GameScanning/GameScanner.cs @@ -24,6 +24,9 @@ namespace StardewModdingAPI.Toolkit.Framework.GameScanning /// The current OS. private readonly Platform Platform; + /// The Steam app ID for Stardew Valley. + private const string SteamAppId = "413150"; + /********* ** Public methods @@ -146,7 +149,7 @@ namespace StardewModdingAPI.Toolkit.Framework.GameScanning #if SMAPI_FOR_WINDOWS IDictionary registryKeys = new Dictionary { - [@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 413150"] = "InstallLocation", // Steam + [@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App " + GameScanner.SteamAppId] = "InstallLocation", // Steam [@"SOFTWARE\WOW6432Node\GOG.com\Games\1453375253"] = "PATH", // GOG on 64-bit Windows }; foreach (var pair in registryKeys) @@ -160,9 +163,10 @@ namespace StardewModdingAPI.Toolkit.Framework.GameScanning string? steamPath = this.GetCurrentUserRegistryValue(@"Software\Valve\Steam", "SteamPath"); if (steamPath != null) { + // conventional path yield return Path.Combine(steamPath.Replace('/', '\\'), @"steamapps\common\Stardew Valley"); - // Check for Steam libraries in other locations + // from Steam's .vdf file string? path = this.GetPathFromSteamLibrary(steamPath); if (!string.IsNullOrWhiteSpace(path)) yield return path; @@ -257,26 +261,34 @@ namespace StardewModdingAPI.Toolkit.Framework.GameScanning /// The game directory, if found. private string? GetPathFromSteamLibrary(string? steamPath) { - string stardewAppId = "413150"; - if (steamPath != null) + if (steamPath == null) + return null; + + // get raw .vdf data + string libraryFoldersPath = Path.Combine(steamPath.Replace('/', '\\'), "steamapps\\libraryfolders.vdf"); + 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? libraryFoldersPath = Path.Combine(steamPath.Replace('/', '\\'), "steamapps\\libraryfolders.vdf"); - using FileStream fs = File.OpenRead(libraryFoldersPath); - VdfDeserializer deserializer = new VdfDeserializer(); - SteamLibraryCollection libraries = deserializer.Deserialize(fs); - if (libraries.libraryfolders != null) + dynamic library = pair.Value; + + foreach (dynamic app in library.apps) { - var stardewLibrary = libraries.libraryfolders.FirstOrDefault(f => - { - var apps = f.Value?.apps; - return apps != null && apps.Any(a => a.Key.Equals(stardewAppId)); - }); - if (stardewLibrary.Value?.path != null) + string key = app.Key; + if (key == GameScanner.SteamAppId) { - return Path.Combine(stardewLibrary.Value.path.Replace("\\\\", "\\"), @"steamapps\common\Stardew Valley"); + string path = library.path; + + return Path.Combine(path.Replace("\\\\", "\\"), "steamapps", "common", "Stardew Valley"); } } } + return null; } #endif diff --git a/src/SMAPI.Toolkit/Framework/GameScanning/SteamLibraryCollection.cs b/src/SMAPI.Toolkit/Framework/GameScanning/SteamLibraryCollection.cs deleted file mode 100644 index 7a186f69..00000000 --- a/src/SMAPI.Toolkit/Framework/GameScanning/SteamLibraryCollection.cs +++ /dev/null @@ -1,47 +0,0 @@ -#if SMAPI_FOR_WINDOWS -using System.Collections.Generic; - -namespace StardewModdingAPI.Toolkit.Framework.GameScanning -{ -#pragma warning disable IDE1006 // Model requires lowercase naming. -#pragma warning disable CS8618 // Required for model. - /// Model for Steam's libraryfolders.vdf. - public class SteamLibraryCollection - { - /// Each entry identifies a different location that part of the Steam games library is installed to. - public LibraryFolders libraryfolders { get; set; } - } - - /// A collection of LibraryFolders. Like a dictionary, but has contentstatsid used as an index also. - /// - /// -#pragma warning disable CS8714 // Required for model. - public class LibraryFolders : Dictionary -#pragma warning restore CS8714 - { - /// Index of the library, starting from "0". - public string contentstatsid { get; set; } - } - - /// A Steam library folder, containing information on the location and size of games installed there. - public class LibraryFolder - { - /// The escaped path to this Steam library folder. There will be a steam.exe here, but this may not be the one the player generally launches. - public string path { get; set; } - /// Label for the library, or "" - public string label { get; set; } - /// ~19-digit identifier. - public string contentid { get; set; } - /// Size of the library in bytes. May show 0 when size is non-zero. - public string totalsize { get; set; } - /// Used for downloads. - public string update_clean_bytes_tally { get; set; } - /// Normally "0". - public string time_last_update_corruption { get; set; } - /// List of Steam app IDs, and their current size in bytes. - public Dictionary apps { get; set; } - } -#pragma warning restore IDE1006 -#pragma warning restore CS8618 -} -#endif diff --git a/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj b/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj index 411fd469..6080a85e 100644 --- a/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj +++ b/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj @@ -14,7 +14,7 @@ - + -- cgit From a220e14f2d22f5d481c87bfd76d1b9eeaebf04e3 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 9 Oct 2022 13:50:24 -0400 Subject: polish recent changes & update release notes --- src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SMAPI.Toolkit') diff --git a/src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs b/src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs index d115810a..5e9e3c35 100644 --- a/src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs +++ b/src/SMAPI.Toolkit/Framework/ModScanning/ModScanner.cs @@ -52,7 +52,7 @@ namespace StardewModdingAPI.Toolkit.Framework.ModScanning ".zip", ".7z", ".tar", - ".tar.gz" + ".tar.gz", // backup files ".backup", -- cgit From 4d2ad379b4198fa7a341c6ba2bb6455d488b414f Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 9 Oct 2022 19:29:18 -0400 Subject: fix package error --- src/SMAPI.Toolkit/SMAPI.Toolkit.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SMAPI.Toolkit') diff --git a/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj b/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj index 0086f38a..10f1df70 100644 --- a/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj +++ b/src/SMAPI.Toolkit/SMAPI.Toolkit.csproj @@ -14,7 +14,7 @@ - + -- cgit