From fdae87d340e90793ed00fa1766baf9dbd5bec9b6 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 22 Dec 2016 12:47:12 -0500 Subject: skip mods known to be incompatible and display error with update links (#192) --- README.md | 2 ++ .../InteractiveInstaller.cs | 1 + .../StardewModdingAPI.Installer.csproj | 2 ++ src/StardewModdingAPI/Constants.cs | 3 +++ .../Framework/Models/IncompatibleMod.cs | 24 ++++++++++++++++++++++ src/StardewModdingAPI/Manifest.cs | 2 +- src/StardewModdingAPI/Program.cs | 22 ++++++++++++++++++++ src/StardewModdingAPI/StardewModdingAPI.csproj | 5 +++++ src/StardewModdingAPI/StardewModdingAPI.data.json | 16 +++++++++++++++ 9 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs create mode 100644 src/StardewModdingAPI/StardewModdingAPI.data.json diff --git a/README.md b/README.md index c4bcd8d4..eb21f379 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,7 @@ directory containing `src`). Newtonsoft.Json.dll StardewModdingAPI StardewModdingAPI.config.json + StardewModdingAPI.data.json StardewModdingAPI.exe StardewModdingAPI.exe.mdb StardewModdingAPI.AssemblyRewriters.dll @@ -91,6 +92,7 @@ directory containing `src`). Mono.Cecil.Rocks.dll Newtonsoft.Json.dll StardewModdingAPI.config.json + StardewModdingAPI.data.json StardewModdingAPI.exe StardewModdingAPI.pdb StardewModdingAPI.xml diff --git a/src/StardewModdingAPI.Installer/InteractiveInstaller.cs b/src/StardewModdingAPI.Installer/InteractiveInstaller.cs index ce6c83d9..5f89caf2 100644 --- a/src/StardewModdingAPI.Installer/InteractiveInstaller.cs +++ b/src/StardewModdingAPI.Installer/InteractiveInstaller.cs @@ -56,6 +56,7 @@ namespace StardewModdingApi.Installer // common "StardewModdingAPI.exe", "StardewModdingAPI.config.json", + "StardewModdingAPI.data.json", "StardewModdingAPI.AssemblyRewriters.dll", "steam_appid.txt", diff --git a/src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj b/src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj index c9dedd45..4e4872b6 100644 --- a/src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj +++ b/src/StardewModdingAPI.Installer/StardewModdingAPI.Installer.csproj @@ -74,6 +74,7 @@ + @@ -88,6 +89,7 @@ + diff --git a/src/StardewModdingAPI/Constants.cs b/src/StardewModdingAPI/Constants.cs index 6df9b76c..4f7a0c6e 100644 --- a/src/StardewModdingAPI/Constants.cs +++ b/src/StardewModdingAPI/Constants.cs @@ -71,6 +71,9 @@ namespace StardewModdingAPI /// The file path for the SMAPI configuration file. internal static string ApiConfigPath => Path.Combine(Constants.ExecutionPath, $"{typeof(Program).Assembly.GetName().Name}.config.json"); + /// The file path for the SMAPI data file containing metadata about known mods. + internal static string ApiModMetadataPath => Path.Combine(Constants.ExecutionPath, $"{typeof(Program).Assembly.GetName().Name}.data.json"); + /********* ** Protected methods diff --git a/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs b/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs new file mode 100644 index 00000000..f3ee7d0b --- /dev/null +++ b/src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs @@ -0,0 +1,24 @@ +namespace StardewModdingAPI.Framework.Models +{ + /// Contains abstract metadata about an incompatible mod. + internal class IncompatibleMod + { + /********* + ** Accessors + *********/ + /// The unique mod ID. + public string ID { get; set; } + + /// The mod name. + public string Name { get; set; } + + /// The most recent incompatible mod version. + public string Version { get; set; } + + /// The URL the user can check for an official updated version. + public string UpdateUrl { get; set; } + + /// The URL the user can check for an unofficial updated version. + public string UnofficialUpdateUrl { get; set; } + } +} \ No newline at end of file diff --git a/src/StardewModdingAPI/Manifest.cs b/src/StardewModdingAPI/Manifest.cs index 981ff023..018b31ae 100644 --- a/src/StardewModdingAPI/Manifest.cs +++ b/src/StardewModdingAPI/Manifest.cs @@ -40,7 +40,7 @@ namespace StardewModdingAPI public string EntryDll { get; set; } /// The unique mod ID. - public string UniqueID { get; set; } = Guid.NewGuid().ToString(); + public string UniqueID { get; set; } /**** diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index cc3cb2bc..7de22ee9 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -315,6 +315,11 @@ namespace StardewModdingAPI ModAssemblyLoader modAssemblyLoader = new ModAssemblyLoader(Program.CacheDirName, Program.TargetPlatform, Program.Monitor); AppDomain.CurrentDomain.AssemblyResolve += (sender, e) => modAssemblyLoader.ResolveAssembly(e.Name); + // get known incompatible mods + IDictionary incompatibleMods = File.Exists(Constants.ApiModMetadataPath) + ? JsonConvert.DeserializeObject(File.ReadAllText(Constants.ApiModMetadataPath)).ToDictionary(p => p.ID, p => p) + : new Dictionary(0); + // load mods foreach (string directory in Directory.GetDirectories(Program.ModPath)) { @@ -376,6 +381,23 @@ namespace StardewModdingAPI continue; } + // validate known incompatible mods + IncompatibleMod incompatible; + if (incompatibleMods.TryGetValue(manifest.UniqueID ?? $"{manifest.Name}|{manifest.Author}|{manifest.EntryDll}", out incompatible)) + { + if (!manifest.Version.IsNewerThan(new SemanticVersion(incompatible.Version))) + { + string warning = $"Skipped {incompatible.Name} ≤v{incompatible.Version} because this version is not compatible with the latest version of the game. Please check for a newer version of the mod here:"; + if (!string.IsNullOrWhiteSpace(incompatible.UpdateUrl)) + warning += $"{Environment.NewLine}- official mod: {incompatible.UpdateUrl}"; + if (!string.IsNullOrWhiteSpace(incompatible.UnofficialUpdateUrl)) + warning += $"{Environment.NewLine}- unofficial update: {incompatible.UnofficialUpdateUrl}"; + + Program.Monitor.Log(warning, LogLevel.Error); + continue; + } + } + // validate version if (!string.IsNullOrWhiteSpace(manifest.MinimumApiVersion)) { diff --git a/src/StardewModdingAPI/StardewModdingAPI.csproj b/src/StardewModdingAPI/StardewModdingAPI.csproj index 0c6697cb..07b1ff5e 100644 --- a/src/StardewModdingAPI/StardewModdingAPI.csproj +++ b/src/StardewModdingAPI/StardewModdingAPI.csproj @@ -161,6 +161,7 @@ + @@ -206,6 +207,9 @@ Always + + Always + Always @@ -253,6 +257,7 @@ + diff --git a/src/StardewModdingAPI/StardewModdingAPI.data.json b/src/StardewModdingAPI/StardewModdingAPI.data.json new file mode 100644 index 00000000..91321c69 --- /dev/null +++ b/src/StardewModdingAPI/StardewModdingAPI.data.json @@ -0,0 +1,16 @@ +/* + + +This file contains advanced metadata for SMAPI. You shouldn't change this file. + + +*/ +[ + { + "ID": "CJBCheatsMenu", + "Name": "CJB Cheats Menu", + "Version": "1.12", + "UpdateUrl": "http://www.nexusmods.com/stardewvalley/mods/4", + "UnofficialUpdateUrl": "http://community.playstarbound.com/threads/125031" + } +] -- cgit