From 94d41cd67a1591fff01c17e3aece48e1f19d297b Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 5 Aug 2021 12:21:18 -0400 Subject: correct release date --- docs/release-notes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/release-notes.md b/docs/release-notes.md index 4e9dacbf..20fdd2c1 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -2,7 +2,7 @@ # Release notes ## 3.12.2 -Released 04 August 2021 for Stardew Valley 1.5.4 or later. +Released 05 August 2021 for Stardew Valley 1.5.4 or later. * For players: * Fixed error creating a new save or joining a multiplayer world in 3.12.1. -- cgit From 5e16ed0eea2cae21badd525afa0d464700bb8647 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 5 Aug 2021 14:28:29 -0400 Subject: prevent weird null reference exception in error-handling --- docs/release-notes.md | 4 ++++ src/SMAPI.Internal/ExceptionExtensions.cs | 27 +++++++++++++++++---------- 2 files changed, 21 insertions(+), 10 deletions(-) (limited to 'docs') diff --git a/docs/release-notes.md b/docs/release-notes.md index 20fdd2c1..8c98af5d 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -1,6 +1,10 @@ ← [README](README.md) # Release notes +## Upcoming release +* For mod authors: + * Fixed rare `NullReferenceException` in SMAPI's error-handling. + ## 3.12.2 Released 05 August 2021 for Stardew Valley 1.5.4 or later. diff --git a/src/SMAPI.Internal/ExceptionExtensions.cs b/src/SMAPI.Internal/ExceptionExtensions.cs index 5f1ee1fa..d8189048 100644 --- a/src/SMAPI.Internal/ExceptionExtensions.cs +++ b/src/SMAPI.Internal/ExceptionExtensions.cs @@ -13,19 +13,26 @@ namespace StardewModdingAPI.Internal /// The error to summarize. public static string GetLogSummary(this Exception exception) { - switch (exception) + try { - case TypeLoadException ex: - return $"Failed loading type '{ex.TypeName}': {exception}"; + switch (exception) + { + case TypeLoadException ex: + return $"Failed loading type '{ex.TypeName}': {exception}"; - case ReflectionTypeLoadException ex: - string summary = ex.ToString(); - foreach (Exception childEx in ex.LoaderExceptions ?? new Exception[0]) - summary += $"\n\n{childEx?.GetLogSummary()}"; - return summary; + case ReflectionTypeLoadException ex: + string summary = ex.ToString(); + foreach (Exception childEx in ex.LoaderExceptions ?? new Exception[0]) + summary += $"\n\n{childEx?.GetLogSummary()}"; + return summary; - default: - return exception.ToString(); + default: + return exception?.ToString() ?? $"\n{Environment.StackTrace}"; + } + } + catch (Exception ex) + { + throw new InvalidOperationException($"Failed handling {exception?.GetType().FullName} (original message: {exception?.Message})", ex); } } -- cgit From 976c66537c9f4493ce859c574675bb8651b5323f Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 8 Aug 2021 00:24:20 -0400 Subject: fix edge case where Netcode references aren't rewritten correctly --- docs/release-notes.md | 1 + src/SMAPI/Constants.cs | 11 +++++++++++ .../Framework/ModLoading/AssemblyDefinitionResolver.cs | 16 +++++++++++----- 3 files changed, 23 insertions(+), 5 deletions(-) (limited to 'docs') diff --git a/docs/release-notes.md b/docs/release-notes.md index 8c98af5d..9e42a847 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -4,6 +4,7 @@ ## Upcoming release * For mod authors: * Fixed rare `NullReferenceException` in SMAPI's error-handling. + * Internal changes to prepare for upcoming releases. ## 3.12.2 Released 05 August 2021 for Stardew Valley 1.5.4 or later. diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index 7f633a46..de6b63d6 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -243,6 +243,17 @@ namespace StardewModdingAPI // case involving unofficial 64-bit Stardew Valley when launched through Steam (for some players only) // where Mono.Cecil can't resolve references to SMAPI. resolver.Add(AssemblyDefinition.ReadAssembly(typeof(SGame).Assembly.Location)); + + // make sure game assembly names can be resolved + // The game assembly can have one of three names depending how the mod was compiled: + // - 'StardewValley': assembly name on Linux/macOS; + // - 'Stardew Valley': assembly name on Windows; + // - 'Netcode': an assembly that's separate on Windows only. + resolver.Add(AssemblyDefinition.ReadAssembly(typeof(Game1).Assembly.Location), "StardewValley", "Stardew Valley" +#if !SMAPI_FOR_WINDOWS + , "Netcode" +#endif + ); } /// Get metadata for mapping assemblies to the current platform. diff --git a/src/SMAPI/Framework/ModLoading/AssemblyDefinitionResolver.cs b/src/SMAPI/Framework/ModLoading/AssemblyDefinitionResolver.cs index aefb0126..b3415609 100644 --- a/src/SMAPI/Framework/ModLoading/AssemblyDefinitionResolver.cs +++ b/src/SMAPI/Framework/ModLoading/AssemblyDefinitionResolver.cs @@ -21,11 +21,17 @@ namespace StardewModdingAPI.Framework.ModLoading public void Add(params AssemblyDefinition[] assemblies) { foreach (AssemblyDefinition assembly in assemblies) - { - this.RegisterAssembly(assembly); - this.Lookup[assembly.Name.Name] = assembly; - this.Lookup[assembly.Name.FullName] = assembly; - } + this.Add(assembly, assembly.Name.Name, assembly.Name.FullName); + } + + /// Add known assemblies to the resolver. + /// The assembly to add. + /// The assembly names for which it should be returned. + public void Add(AssemblyDefinition assembly, params string[] names) + { + this.RegisterAssembly(assembly); + foreach (string name in names) + this.Lookup[name] = assembly; } /// Resolve an assembly reference. -- cgit From a4c6c6168405bb0441a40e4f6f4e86dfa46a76b2 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 8 Aug 2021 00:32:19 -0400 Subject: enable parallel analyzer execution --- docs/technical/mod-package.md | 33 ++++++++++++---------- .../NetFieldAnalyzer.cs | 3 ++ .../ObsoleteFieldAnalyzer.cs | 3 ++ 3 files changed, 24 insertions(+), 15 deletions(-) (limited to 'docs') diff --git a/docs/technical/mod-package.md b/docs/technical/mod-package.md index 91da971b..7eefc7a4 100644 --- a/docs/technical/mod-package.md +++ b/docs/technical/mod-package.md @@ -365,7 +365,10 @@ The NuGet package is generated automatically in `StardewModdingAPI.ModBuildConfi when you compile it. ## Release notes -## 3.3 +## Upcoming release +* Improved analyzer performance by enabling parallel execution. + +## 3.3.0 Released 30 March 2021. * Added a build warning when the mod isn't compiled for `Any CPU`. @@ -385,19 +388,19 @@ Released 11 September 2020. * Added more detailed logging. * Fixed _path's format is not supported_ error when using default `Mods` path in 3.2. -### 3.2 +### 3.2.0 Released 07 September 2020. * Added option to change `Mods` folder path. * Rewrote documentation to make it easier to read. -### 3.1 +### 3.1.0 Released 01 February 2020. * Added support for semantic versioning 2.0. * `0Harmony.dll` is now ignored if the mod references Harmony directly (it's bundled with SMAPI). -### 3.0 +### 3.0.0 Released 26 November 2019. * Updated for SMAPI 3.0 and Stardew Valley 1.4. @@ -412,14 +415,14 @@ Released 26 November 2019. * Dropped support for older versions of SMAPI and Visual Studio. * Migrated package icon to NuGet's new format. -### 2.2 +### 2.2.0 Released 28 October 2018. * Added support for SMAPI 2.8+ (still compatible with earlier versions). * Added default game paths for 32-bit Windows. * Fixed valid manifests marked invalid in some cases. -### 2.1 +### 2.1.0 Released 27 July 2018. * Added support for Stardew Valley 1.3. @@ -439,7 +442,7 @@ Released 11 October 2017. * Fixed mod deploy failing to create subfolders if they don't already exist. -### 2.0 +### 2.0.0 Released 11 October 2017. * Added: mods are now copied into the `Mods` folder automatically (configurable). @@ -457,7 +460,7 @@ Released 28 July 2017. * The manifest/i18n files in the project now take precedence over those in the build output if both are present. -### 1.7 +### 1.7.0 Released 28 July 2017. * Added option to create release zips on build. @@ -474,19 +477,19 @@ Released 09 July 2017. * Improved crossplatform game path detection. -### 1.6 +### 1.6.0 Released 05 June 2017. * Added support for deploying mod files into `Mods` automatically. * Added a build error if a game folder is found, but doesn't contain Stardew Valley or SMAPI. -### 1.5 +### 1.5.0 Released 23 January 2017. * Added support for setting a custom game path globally. * Added default GOG path on macOS. -### 1.4 +### 1.4.0 Released 11 January 2017. * Fixed detection of non-default game paths on 32-bit Windows. @@ -494,22 +497,22 @@ Released 11 January 2017. * Removed support for overriding the target platform (no longer needed since SMAPI crossplatforms mods automatically). -### 1.3 +### 1.3.0 Released 31 December 2016. * Added support for non-default game paths on Windows. -### 1.2 +### 1.2.0 Released 24 October 2016. * Exclude game binaries from mod build output. -### 1.1 +### 1.1.0 Released 21 October 2016. * Added support for overriding the target platform. -### 1.0 +### 1.0.0 Released 21 October 2016. * Initial release. diff --git a/src/SMAPI.ModBuildConfig.Analyzer/NetFieldAnalyzer.cs b/src/SMAPI.ModBuildConfig.Analyzer/NetFieldAnalyzer.cs index a9b981bd..1efc1616 100644 --- a/src/SMAPI.ModBuildConfig.Analyzer/NetFieldAnalyzer.cs +++ b/src/SMAPI.ModBuildConfig.Analyzer/NetFieldAnalyzer.cs @@ -174,6 +174,9 @@ namespace StardewModdingAPI.ModBuildConfig.Analyzer /// The analysis context. public override void Initialize(AnalysisContext context) { + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics); + context.EnableConcurrentExecution(); + context.RegisterSyntaxNodeAction( this.AnalyzeMemberAccess, SyntaxKind.SimpleMemberAccessExpression, diff --git a/src/SMAPI.ModBuildConfig.Analyzer/ObsoleteFieldAnalyzer.cs b/src/SMAPI.ModBuildConfig.Analyzer/ObsoleteFieldAnalyzer.cs index d071f0c1..722d5227 100644 --- a/src/SMAPI.ModBuildConfig.Analyzer/ObsoleteFieldAnalyzer.cs +++ b/src/SMAPI.ModBuildConfig.Analyzer/ObsoleteFieldAnalyzer.cs @@ -56,6 +56,9 @@ namespace StardewModdingAPI.ModBuildConfig.Analyzer /// The analysis context. public override void Initialize(AnalysisContext context) { + context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.Analyze | GeneratedCodeAnalysisFlags.ReportDiagnostics); + context.EnableConcurrentExecution(); + context.RegisterSyntaxNodeAction( this.AnalyzeObsoleteFields, SyntaxKind.SimpleMemberAccessExpression, -- cgit From 6cf7c49f34eac8edd18012d41d1f49a149fb1f5a Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 15 Aug 2021 01:25:56 -0400 Subject: add GetInAllLocales to translation API --- docs/release-notes.md | 1 + .../Framework/ModHelpers/TranslationHelper.cs | 6 ++ src/SMAPI/Framework/Translator.cs | 65 ++++++++++++++++++---- src/SMAPI/ITranslationHelper.cs | 7 ++- 4 files changed, 67 insertions(+), 12 deletions(-) (limited to 'docs') diff --git a/docs/release-notes.md b/docs/release-notes.md index 9e42a847..409c4bd5 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -3,6 +3,7 @@ # Release notes ## Upcoming release * For mod authors: + * Added `GetInAllLocales` method in translation API, to get a translation in every available locale. * Fixed rare `NullReferenceException` in SMAPI's error-handling. * Internal changes to prepare for upcoming releases. diff --git a/src/SMAPI/Framework/ModHelpers/TranslationHelper.cs b/src/SMAPI/Framework/ModHelpers/TranslationHelper.cs index a88ca9c9..869664fe 100644 --- a/src/SMAPI/Framework/ModHelpers/TranslationHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/TranslationHelper.cs @@ -55,6 +55,12 @@ namespace StardewModdingAPI.Framework.ModHelpers return this.Translator.Get(key, tokens); } + /// + public IDictionary GetInAllLocales(string key, bool withFallback = false) + { + return this.Translator.GetInAllLocales(key, withFallback); + } + /// Set the translations to use. /// The translations to use. internal TranslationHelper SetTranslations(IDictionary> translations) diff --git a/src/SMAPI/Framework/Translator.cs b/src/SMAPI/Framework/Translator.cs index 11ec983b..4492b17f 100644 --- a/src/SMAPI/Framework/Translator.cs +++ b/src/SMAPI/Framework/Translator.cs @@ -46,18 +46,10 @@ namespace StardewModdingAPI.Framework this.LocaleEnum = localeEnum; this.ForLocale = new Dictionary(StringComparer.OrdinalIgnoreCase); - foreach (string next in this.GetRelevantLocales(this.Locale)) + foreach (string key in this.GetAllKeysRaw()) { - // skip if locale not defined - if (!this.All.TryGetValue(next, out IDictionary translations)) - continue; - - // add missing translations - foreach (var pair in translations) - { - if (!this.ForLocale.ContainsKey(pair.Key)) - this.ForLocale.Add(pair.Key, new Translation(this.Locale, pair.Key, pair.Value)); - } + string text = this.GetRaw(key, locale, withFallback: true); + this.ForLocale.Add(key, new Translation(this.Locale, key, text)); } } @@ -83,6 +75,25 @@ namespace StardewModdingAPI.Framework return this.Get(key).Tokens(tokens); } + /// Get a translation in every locale for which it's defined. + /// The translation key. + /// Whether to add duplicate translations for locale fallback. For example, if a translation is defined in default.json but not fr.json, setting this to true will add a fr entry which duplicates the default text. + public IDictionary GetInAllLocales(string key, bool withFallback) + { + IDictionary translations = new Dictionary(); + + foreach (var localeSet in this.All) + { + string locale = localeSet.Key; + string text = this.GetRaw(key, locale, withFallback); + + if (text != null) + translations[locale] = new Translation(locale, key, text); + } + + return translations; + } + /// Set the translations to use. /// The translations to use. internal Translator SetTranslations(IDictionary> translations) @@ -102,6 +113,38 @@ namespace StardewModdingAPI.Framework /********* ** Private methods *********/ + /// Get all translation keys in the underlying translation data, ignoring the cache. + private IEnumerable GetAllKeysRaw() + { + return new HashSet( + this.All.SelectMany(p => p.Value.Keys), + StringComparer.OrdinalIgnoreCase + ); + } + + /// Get a translation from the underlying translation data, ignoring the cache. + /// The translation key. + /// The locale to get. + /// Whether to add duplicate translations for locale fallback. For example, if a translation is defined in default.json but not fr.json, setting this to true will add a fr entry which duplicates the default text. + private string GetRaw(string key, string locale, bool withFallback) + { + foreach (string next in this.GetRelevantLocales(locale)) + { + string translation = null; + bool hasTranslation = + this.All.TryGetValue(next, out IDictionary translations) + && translations.TryGetValue(key, out translation); + + if (hasTranslation) + return translation; + + if (!withFallback) + break; + } + + return null; + } + /// Get the locales which can provide translations for the given locale, in precedence order. /// The locale for which to find valid locales. private IEnumerable GetRelevantLocales(string locale) diff --git a/src/SMAPI/ITranslationHelper.cs b/src/SMAPI/ITranslationHelper.cs index c4b72444..b30d9b14 100644 --- a/src/SMAPI/ITranslationHelper.cs +++ b/src/SMAPI/ITranslationHelper.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using StardewValley; namespace StardewModdingAPI @@ -30,5 +30,10 @@ namespace StardewModdingAPI /// The translation key. /// An object containing token key/value pairs. This can be an anonymous object (like new { value = 42, name = "Cranberries" }), a dictionary, or a class instance. Translation Get(string key, object tokens); + + /// Get a translation in every locale for which it's defined. + /// The translation key. + /// Whether to add duplicate translations for locale fallback. For example, if a translation is defined in default.json but not fr.json, setting this to true will add a fr entry which duplicates the default text. + IDictionary GetInAllLocales(string key, bool withFallback = false); } } -- cgit From 68e629f17c349b685ef3c4836552adcbed0c4976 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 16 Aug 2021 17:22:44 -0400 Subject: fix data helper's WriteJsonFile not deleting file if data is null (#799) --- docs/release-notes.md | 5 +++-- src/SMAPI/Framework/ModHelpers/DataHelper.cs | 6 +++++- src/SMAPI/IDataHelper.cs | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) (limited to 'docs') diff --git a/docs/release-notes.md b/docs/release-notes.md index 409c4bd5..d0b794ee 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -3,8 +3,9 @@ # Release notes ## Upcoming release * For mod authors: - * Added `GetInAllLocales` method in translation API, to get a translation in every available locale. - * Fixed rare `NullReferenceException` in SMAPI's error-handling. + * Added `helper.Translation.GetInAllLocales` to get a translation in every available locale. + * Fixed `helper.Data.WriteJsonFile` not deleting the file if the model is null, unlike the other `Write*` methods. + * Fixed error-handling for `StackOverflowException` thrown on Linux/macOS. * Internal changes to prepare for upcoming releases. ## 3.12.2 diff --git a/src/SMAPI/Framework/ModHelpers/DataHelper.cs b/src/SMAPI/Framework/ModHelpers/DataHelper.cs index 0fe3209f..4cbfd73f 100644 --- a/src/SMAPI/Framework/ModHelpers/DataHelper.cs +++ b/src/SMAPI/Framework/ModHelpers/DataHelper.cs @@ -58,7 +58,11 @@ namespace StardewModdingAPI.Framework.ModHelpers throw new InvalidOperationException($"You must call {nameof(IMod.Helper)}.{nameof(IModHelper.Data)}.{nameof(this.WriteJsonFile)} with a relative path (without directory climbing)."); path = Path.Combine(this.ModFolderPath, PathUtilities.NormalizePath(path)); - this.JsonHelper.WriteJsonFile(path, data); + + if (data != null) + this.JsonHelper.WriteJsonFile(path, data); + else + File.Delete(path); } /**** diff --git a/src/SMAPI/IDataHelper.cs b/src/SMAPI/IDataHelper.cs index 4922c8da..901266d7 100644 --- a/src/SMAPI/IDataHelper.cs +++ b/src/SMAPI/IDataHelper.cs @@ -21,7 +21,7 @@ namespace StardewModdingAPI /// Save data to a JSON file in the mod's folder. /// The model type. This should be a plain class that has public properties for the data you want. The properties can be complex types. /// The file path relative to the mod folder. - /// The arbitrary data to save. + /// The arbitrary data to save, or null to delete the file. /// The is not relative or contains directory climbing (../). void WriteJsonFile(string path, TModel data) where TModel : class; -- cgit From 26a629f41b98faafed8af38a89f25d9b821fac0f Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 19 Aug 2021 21:21:57 -0400 Subject: fix prerelease update alerts shown for non-prerelease players --- docs/release-notes.md | 3 ++ src/SMAPI.Toolkit/SemanticVersionComparer.cs | 32 ++++++++++++ src/SMAPI.Web/Framework/ModSiteManager.cs | 73 +++++++++++++++++++--------- 3 files changed, 86 insertions(+), 22 deletions(-) create mode 100644 src/SMAPI.Toolkit/SemanticVersionComparer.cs (limited to 'docs') diff --git a/docs/release-notes.md b/docs/release-notes.md index d0b794ee..85971e1d 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -8,6 +8,9 @@ * Fixed error-handling for `StackOverflowException` thrown on Linux/macOS. * Internal changes to prepare for upcoming releases. +* For the web API: + * Fixed update checks recommending prerelease versions if the player has a working non-prerelease version. + ## 3.12.2 Released 05 August 2021 for Stardew Valley 1.5.4 or later. diff --git a/src/SMAPI.Toolkit/SemanticVersionComparer.cs b/src/SMAPI.Toolkit/SemanticVersionComparer.cs new file mode 100644 index 00000000..9f6b57a2 --- /dev/null +++ b/src/SMAPI.Toolkit/SemanticVersionComparer.cs @@ -0,0 +1,32 @@ +using System.Collections.Generic; + +namespace StardewModdingAPI.Toolkit +{ + /// A comparer for semantic versions based on the field. + public class SemanticVersionComparer : IComparer + { + /********* + ** Accessors + *********/ + /// A singleton instance of the comparer. + public static SemanticVersionComparer Instance { get; } = new SemanticVersionComparer(); + + + /********* + ** Public methods + *********/ + /// + public int Compare(ISemanticVersion x, ISemanticVersion y) + { + if (object.ReferenceEquals(x, y)) + return 0; + + if (x is null) + return -1; + if (y is null) + return 1; + + return x.CompareTo(y); + } + } +} diff --git a/src/SMAPI.Web/Framework/ModSiteManager.cs b/src/SMAPI.Web/Framework/ModSiteManager.cs index 68b4c6ac..8f21d2f5 100644 --- a/src/SMAPI.Web/Framework/ModSiteManager.cs +++ b/src/SMAPI.Web/Framework/ModSiteManager.cs @@ -110,41 +110,70 @@ namespace StardewModdingAPI.Web.Framework main = null; preview = null; - ISemanticVersion ParseVersion(string raw) + // parse all versions from the mod page + IEnumerable<(string name, string description, ISemanticVersion version)> GetAllVersions() { - raw = this.NormalizeVersion(raw); - return this.GetMappedVersion(raw, mapRemoteVersions, allowNonStandardVersions); + if (mod != null) + { + ISemanticVersion ParseAndMapVersion(string raw) + { + raw = this.NormalizeVersion(raw); + return this.GetMappedVersion(raw, mapRemoteVersions, allowNonStandardVersions); + } + + // get mod version + ISemanticVersion modVersion = ParseAndMapVersion(mod.Version); + if (modVersion != null) + yield return (name: null, description: null, version: ParseAndMapVersion(mod.Version)); + + // get file versions + foreach (IModDownload download in mod.Downloads) + { + ISemanticVersion cur = ParseAndMapVersion(download.Version); + if (cur != null) + yield return (download.Name, download.Description, cur); + } + } } + var versions = GetAllVersions() + .OrderByDescending(p => p.version, SemanticVersionComparer.Instance) + .ToArray(); - if (mod != null) + // get main + preview versions + void TryGetVersions(out ISemanticVersion mainVersion, out ISemanticVersion previewVersion, Func<(string name, string description, ISemanticVersion version), bool> filter = null) { - // get mod version - if (subkey == null) - main = ParseVersion(mod.Version); + mainVersion = null; + previewVersion = null; - // get file versions - foreach (IModDownload download in mod.Downloads) + // get latest main + preview version + foreach (var entry in versions) { - // check for subkey if specified - if (subkey != null && download.Name?.Contains(subkey, StringComparison.OrdinalIgnoreCase) != true && download.Description?.Contains(subkey, StringComparison.OrdinalIgnoreCase) != true) + if (filter?.Invoke(entry) == false) continue; - // parse version - ISemanticVersion cur = ParseVersion(download.Version); - if (cur == null) - continue; + if (entry.version.IsPrerelease()) + previewVersion ??= entry.version; + else + mainVersion ??= entry.version; - // track highest versions - if (main == null || cur.IsNewerThan(main)) - main = cur; - if (cur.IsPrerelease() && (preview == null || cur.IsNewerThan(preview))) - preview = cur; + if (mainVersion != null) + break; // any other values will be older } - if (preview != null && !preview.IsNewerThan(main)) - preview = null; + // normalize values + if (previewVersion is not null) + { + mainVersion ??= previewVersion; // if every version is prerelease, latest one is the main version + if (!previewVersion.IsNewerThan(mainVersion)) + previewVersion = null; + } } + if (subkey is not null) + TryGetVersions(out main, out preview, entry => entry.name?.Contains(subkey, StringComparison.OrdinalIgnoreCase) == true || entry.description?.Contains(subkey, StringComparison.OrdinalIgnoreCase) == true); + if (main is null) + TryGetVersions(out main, out preview); + return main != null; } -- cgit From 3804ae6284aeca449e1ca95c6ae7291519ed6937 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 22 Aug 2021 12:14:59 -0400 Subject: fix some installer errors not showing info header --- docs/release-notes.md | 3 +++ src/SMAPI.Installer/InteractiveInstaller.cs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/release-notes.md b/docs/release-notes.md index 85971e1d..9ad95a43 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -2,6 +2,9 @@ # Release notes ## Upcoming release +* For players: + * Fixed some installer errors now show info header. + * For mod authors: * Added `helper.Translation.GetInAllLocales` to get a translation in every available locale. * Fixed `helper.Data.WriteJsonFile` not deleting the file if the model is null, unlike the other `Write*` methods. diff --git a/src/SMAPI.Installer/InteractiveInstaller.cs b/src/SMAPI.Installer/InteractiveInstaller.cs index ab07c864..b91d0dd3 100644 --- a/src/SMAPI.Installer/InteractiveInstaller.cs +++ b/src/SMAPI.Installer/InteractiveInstaller.cs @@ -272,7 +272,6 @@ namespace StardewModdingApi.Installer DirectoryInfo bundleDir = new DirectoryInfo(this.BundlePath); paths = new InstallerPaths(bundleDir, installDir, context.ExecutableName); } - Console.Clear(); /********* @@ -309,6 +308,7 @@ namespace StardewModdingApi.Installer return; } } + Console.Clear(); /********* -- cgit From e1d8838587329bd64f3627c4cdc4ac57d187ad7f Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 24 Aug 2021 18:29:03 -0400 Subject: fix update checks not recommending prerelease mod versions for SMAPI beta --- docs/release-notes.md | 4 +++- src/SMAPI.Web/Controllers/ModsApiController.cs | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'docs') diff --git a/docs/release-notes.md b/docs/release-notes.md index 9ad95a43..e71457af 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -12,7 +12,9 @@ * Internal changes to prepare for upcoming releases. * For the web API: - * Fixed update checks recommending prerelease versions if the player has a working non-prerelease version. + * Fixed update checks... + * not recommending prerelease mod versions if the player has a beta SMAPI version; + * recommending prerelease versions if the player has a working non-prerelease version. ## 3.12.2 Released 05 August 2021 for Stardew Valley 1.5.4 or later. diff --git a/src/SMAPI.Web/Controllers/ModsApiController.cs b/src/SMAPI.Web/Controllers/ModsApiController.cs index 1956bf29..c6e9a713 100644 --- a/src/SMAPI.Web/Controllers/ModsApiController.cs +++ b/src/SMAPI.Web/Controllers/ModsApiController.cs @@ -123,6 +123,10 @@ namespace StardewModdingAPI.Web.Controllers ModOverrideConfig overrides = this.Config.Value.ModOverrides.FirstOrDefault(p => p.ID.Equals(search.ID?.Trim(), StringComparison.OrdinalIgnoreCase)); bool allowNonStandardVersions = overrides?.AllowNonStandardVersions ?? false; + // SMAPI versions with a '-beta' tag indicate major changes that may need beta mod versions. + // This doesn't apply to normal prerelease versions which have an '-alpha' tag. + bool isSmapiBeta = apiVersion.IsPrerelease() && apiVersion.PrereleaseTag.StartsWith("beta"); + // get latest versions ModEntryModel result = new ModEntryModel { ID = search.ID }; IList errors = new List(); @@ -198,7 +202,7 @@ namespace StardewModdingAPI.Web.Controllers List updates = new List(); if (this.IsRecommendedUpdate(installedVersion, main?.Version, useBetaChannel: true)) updates.Add(main); - if (this.IsRecommendedUpdate(installedVersion, optional?.Version, useBetaChannel: installedVersion.IsPrerelease() || search.IsBroken)) + if (this.IsRecommendedUpdate(installedVersion, optional?.Version, useBetaChannel: isSmapiBeta || installedVersion.IsPrerelease() || search.IsBroken)) updates.Add(optional); if (this.IsRecommendedUpdate(installedVersion, unofficial?.Version, useBetaChannel: true)) updates.Add(unofficial); -- cgit From f8c76bde39ba2afb11540c9af5d88aad4c73f789 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 24 Aug 2021 21:59:52 -0400 Subject: add 64-bit compatibility check before loading mods That reduces time spent trying to rewrite them (which won't work anyway), and shows a more informative message than the default 'DLL couldn't be loaded' error. --- docs/release-notes.md | 1 + src/SMAPI.Toolkit/Framework/LowLevelEnvironmentUtility.cs | 6 +++--- src/SMAPI.Toolkit/Utilities/EnvironmentUtility.cs | 7 +++++++ src/SMAPI/Framework/SCore.cs | 15 ++++++++++++--- 4 files changed, 23 insertions(+), 6 deletions(-) (limited to 'docs') diff --git a/docs/release-notes.md b/docs/release-notes.md index e71457af..a00c73da 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -3,6 +3,7 @@ # Release notes ## Upcoming release * For players: + * Added friendly error in 64-bit mode when a mod is 32-bit only. * Fixed some installer errors now show info header. * For mod authors: diff --git a/src/SMAPI.Toolkit/Framework/LowLevelEnvironmentUtility.cs b/src/SMAPI.Toolkit/Framework/LowLevelEnvironmentUtility.cs index be0c18ce..2636aae0 100644 --- a/src/SMAPI.Toolkit/Framework/LowLevelEnvironmentUtility.cs +++ b/src/SMAPI.Toolkit/Framework/LowLevelEnvironmentUtility.cs @@ -90,10 +90,10 @@ namespace StardewModdingAPI.Toolkit.Framework } /// Get whether an executable is 64-bit. - /// The absolute path to the executable file. - public static bool Is64BitAssembly(string executablePath) + /// The absolute path to the assembly file. + public static bool Is64BitAssembly(string path) { - return AssemblyName.GetAssemblyName(executablePath).ProcessorArchitecture != ProcessorArchitecture.X86; + return AssemblyName.GetAssemblyName(path).ProcessorArchitecture != ProcessorArchitecture.X86; } diff --git a/src/SMAPI.Toolkit/Utilities/EnvironmentUtility.cs b/src/SMAPI.Toolkit/Utilities/EnvironmentUtility.cs index 62bd13cd..6de79a85 100644 --- a/src/SMAPI.Toolkit/Utilities/EnvironmentUtility.cs +++ b/src/SMAPI.Toolkit/Utilities/EnvironmentUtility.cs @@ -46,5 +46,12 @@ namespace StardewModdingAPI.Toolkit.Utilities { return LowLevelEnvironmentUtility.GetExecutableName(platform.ToString()); } + + /// Get whether an executable is 64-bit. + /// The absolute path to the assembly file. + public static bool Is64BitAssembly(string path) + { + return LowLevelEnvironmentUtility.Is64BitAssembly(path); + } } } diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index 5fb4aa03..dff0fc55 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -1704,12 +1704,21 @@ namespace StardewModdingAPI.Framework // load as mod else { + // get mod info IManifest manifest = mod.Manifest; + string assemblyPath = Path.Combine(mod.DirectoryPath, manifest.EntryDll); + + // assert 64-bit +#if SMAPI_FOR_WINDOWS_64BIT_HACK + if (!EnvironmentUtility.Is64BitAssembly(assemblyPath)) + { + errorReasonPhrase = "it needs to be updated for 64-bit mode."; + failReason = ModFailReason.LoadFailed; + return false; + } +#endif // load mod - string assemblyPath = manifest?.EntryDll != null - ? Path.Combine(mod.DirectoryPath, manifest.EntryDll) - : null; Assembly modAssembly; try { -- cgit From 911843e1beb72a3fc0337a697f732215b66304c0 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 25 Aug 2021 18:26:02 -0400 Subject: fix console encoding issues (#798) --- docs/release-notes.md | 1 + src/SMAPI/Framework/Logging/LogManager.cs | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/release-notes.md b/docs/release-notes.md index a00c73da..79129024 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -4,6 +4,7 @@ ## Upcoming release * For players: * Added friendly error in 64-bit mode when a mod is 32-bit only. + * Fixed console encoding issues on Linux/macOS. * Fixed some installer errors now show info header. * For mod authors: diff --git a/src/SMAPI/Framework/Logging/LogManager.cs b/src/SMAPI/Framework/Logging/LogManager.cs index 7f1b76e7..c6faa90d 100644 --- a/src/SMAPI/Framework/Logging/LogManager.cs +++ b/src/SMAPI/Framework/Logging/LogManager.cs @@ -109,9 +109,12 @@ namespace StardewModdingAPI.Framework.Logging output.OnMessageIntercepted += message => this.HandleConsoleMessage(this.MonitorForGame, message); Console.SetOut(output); - // enable Unicode handling + // enable Unicode handling on Windows + // (the terminal defaults to UTF-8 on Linux/macOS) +#if SMAPI_FOR_WINDOWS Console.InputEncoding = Encoding.Unicode; Console.OutputEncoding = Encoding.Unicode; +#endif } /// Get a monitor instance derived from SMAPI's current settings. -- cgit From 8f77c1d1ef60e58356c5eef4ee0e5e58fd062809 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 25 Aug 2021 20:46:57 -0400 Subject: update release notes --- docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) (limited to 'docs') diff --git a/docs/release-notes.md b/docs/release-notes.md index 79129024..4f597758 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -9,6 +9,7 @@ * For mod authors: * Added `helper.Translation.GetInAllLocales` to get a translation in every available locale. + * Fixed Visual Studio debugger crash when any mods are rewritten for compatibility (thanks to spacechase0!). * Fixed `helper.Data.WriteJsonFile` not deleting the file if the model is null, unlike the other `Write*` methods. * Fixed error-handling for `StackOverflowException` thrown on Linux/macOS. * Internal changes to prepare for upcoming releases. -- cgit From 31ac964a8b19623b0472931403a33d51db6fb271 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 25 Aug 2021 21:53:45 -0400 Subject: prepare for release --- build/common.targets | 2 +- docs/release-notes.md | 13 +++++++------ src/SMAPI.Mods.ConsoleCommands/manifest.json | 4 ++-- src/SMAPI.Mods.ErrorHandler/manifest.json | 4 ++-- src/SMAPI.Mods.SaveBackup/manifest.json | 4 ++-- src/SMAPI/Constants.cs | 2 +- 6 files changed, 15 insertions(+), 14 deletions(-) (limited to 'docs') diff --git a/build/common.targets b/build/common.targets index 498ec7af..06e0a245 100644 --- a/build/common.targets +++ b/build/common.targets @@ -1,7 +1,7 @@ - 3.12.2 + 3.12.3 SMAPI latest $(AssemblySearchPaths);{GAC} diff --git a/docs/release-notes.md b/docs/release-notes.md index 4f597758..07eb6c03 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -1,23 +1,24 @@ ← [README](README.md) # Release notes -## Upcoming release +## 3.12.3 +Released 25 August 2021 for Stardew Valley 1.5.4 or later. + * For players: * Added friendly error in 64-bit mode when a mod is 32-bit only. * Fixed console encoding issues on Linux/macOS. - * Fixed some installer errors now show info header. + * Fixed some installer errors not showing info header. * For mod authors: * Added `helper.Translation.GetInAllLocales` to get a translation in every available locale. * Fixed Visual Studio debugger crash when any mods are rewritten for compatibility (thanks to spacechase0!). * Fixed `helper.Data.WriteJsonFile` not deleting the file if the model is null, unlike the other `Write*` methods. * Fixed error-handling for `StackOverflowException` thrown on Linux/macOS. - * Internal changes to prepare for upcoming releases. + * Internal changes to prepare for Stardew Valley 1.5.5. * For the web API: - * Fixed update checks... - * not recommending prerelease mod versions if the player has a beta SMAPI version; - * recommending prerelease versions if the player has a working non-prerelease version. + * Fixed update checks not shown for prerelease mod versions when you have a SMAPI beta. + * Fixed update checks shown for prerelease mod versions if you have a working non-prerelease version. ## 3.12.2 Released 05 August 2021 for Stardew Valley 1.5.4 or later. diff --git a/src/SMAPI.Mods.ConsoleCommands/manifest.json b/src/SMAPI.Mods.ConsoleCommands/manifest.json index 6b49cd5f..e04d3497 100644 --- a/src/SMAPI.Mods.ConsoleCommands/manifest.json +++ b/src/SMAPI.Mods.ConsoleCommands/manifest.json @@ -1,9 +1,9 @@ { "Name": "Console Commands", "Author": "SMAPI", - "Version": "3.12.2", + "Version": "3.12.3", "Description": "Adds SMAPI console commands that let you manipulate the game.", "UniqueID": "SMAPI.ConsoleCommands", "EntryDll": "ConsoleCommands.dll", - "MinimumApiVersion": "3.12.2" + "MinimumApiVersion": "3.12.3" } diff --git a/src/SMAPI.Mods.ErrorHandler/manifest.json b/src/SMAPI.Mods.ErrorHandler/manifest.json index 7759d1d5..54758a36 100644 --- a/src/SMAPI.Mods.ErrorHandler/manifest.json +++ b/src/SMAPI.Mods.ErrorHandler/manifest.json @@ -1,9 +1,9 @@ { "Name": "Error Handler", "Author": "SMAPI", - "Version": "3.12.2", + "Version": "3.12.3", "Description": "Handles some common vanilla errors to log more useful info or avoid breaking the game.", "UniqueID": "SMAPI.ErrorHandler", "EntryDll": "ErrorHandler.dll", - "MinimumApiVersion": "3.12.2" + "MinimumApiVersion": "3.12.3" } diff --git a/src/SMAPI.Mods.SaveBackup/manifest.json b/src/SMAPI.Mods.SaveBackup/manifest.json index 1e5b8b97..f23f0958 100644 --- a/src/SMAPI.Mods.SaveBackup/manifest.json +++ b/src/SMAPI.Mods.SaveBackup/manifest.json @@ -1,9 +1,9 @@ { "Name": "Save Backup", "Author": "SMAPI", - "Version": "3.12.2", + "Version": "3.12.3", "Description": "Automatically backs up all your saves once per day into its folder.", "UniqueID": "SMAPI.SaveBackup", "EntryDll": "SaveBackup.dll", - "MinimumApiVersion": "3.12.2" + "MinimumApiVersion": "3.12.3" } diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index de6b63d6..cce267ba 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -62,7 +62,7 @@ namespace StardewModdingAPI internal static int? LogScreenId { get; set; } /// SMAPI's current raw semantic version. - internal static string RawApiVersion = "3.12.2"; + internal static string RawApiVersion = "3.12.3"; } /// Contains SMAPI's constants and assumptions. -- cgit