summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2016-12-22 12:47:12 -0500
committerJesse Plamondon-Willard <github@jplamondonw.com>2016-12-22 12:47:12 -0500
commitfdae87d340e90793ed00fa1766baf9dbd5bec9b6 (patch)
tree04f6640c912ccee58135e559233eaab0d05322c1 /src/StardewModdingAPI
parent3fd16a65f181c710fbbe872f36428176efee7ffb (diff)
downloadSMAPI-fdae87d340e90793ed00fa1766baf9dbd5bec9b6.tar.gz
SMAPI-fdae87d340e90793ed00fa1766baf9dbd5bec9b6.tar.bz2
SMAPI-fdae87d340e90793ed00fa1766baf9dbd5bec9b6.zip
skip mods known to be incompatible and display error with update links (#192)
Diffstat (limited to 'src/StardewModdingAPI')
-rw-r--r--src/StardewModdingAPI/Constants.cs3
-rw-r--r--src/StardewModdingAPI/Framework/Models/IncompatibleMod.cs24
-rw-r--r--src/StardewModdingAPI/Manifest.cs2
-rw-r--r--src/StardewModdingAPI/Program.cs22
-rw-r--r--src/StardewModdingAPI/StardewModdingAPI.csproj5
-rw-r--r--src/StardewModdingAPI/StardewModdingAPI.data.json16
6 files changed, 71 insertions, 1 deletions
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
/// <summary>The file path for the SMAPI configuration file.</summary>
internal static string ApiConfigPath => Path.Combine(Constants.ExecutionPath, $"{typeof(Program).Assembly.GetName().Name}.config.json");
+ /// <summary>The file path for the SMAPI data file containing metadata about known mods.</summary>
+ 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
+{
+ /// <summary>Contains abstract metadata about an incompatible mod.</summary>
+ internal class IncompatibleMod
+ {
+ /*********
+ ** Accessors
+ *********/
+ /// <summary>The unique mod ID.</summary>
+ public string ID { get; set; }
+
+ /// <summary>The mod name.</summary>
+ public string Name { get; set; }
+
+ /// <summary>The most recent incompatible mod version.</summary>
+ public string Version { get; set; }
+
+ /// <summary>The URL the user can check for an official updated version.</summary>
+ public string UpdateUrl { get; set; }
+
+ /// <summary>The URL the user can check for an unofficial updated version.</summary>
+ 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; }
/// <summary>The unique mod ID.</summary>
- 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<string, IncompatibleMod> incompatibleMods = File.Exists(Constants.ApiModMetadataPath)
+ ? JsonConvert.DeserializeObject<IncompatibleMod[]>(File.ReadAllText(Constants.ApiModMetadataPath)).ToDictionary(p => p.ID, p => p)
+ : new Dictionary<string, IncompatibleMod>(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 @@
<Compile Include="Framework\DeprecationLevel.cs" />
<Compile Include="Framework\DeprecationManager.cs" />
<Compile Include="Framework\InternalExtensions.cs" />
+ <Compile Include="Framework\Models\IncompatibleMod.cs" />
<Compile Include="Framework\ModAssemblyLoader.cs" />
<Compile Include="Framework\Reflection\CacheEntry.cs" />
<Compile Include="Framework\Reflection\PrivateField.cs" />
@@ -206,6 +207,9 @@
<Content Include="StardewModdingAPI.config.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
+ <Content Include="StardewModdingAPI.data.json">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </Content>
<None Include="unix-launcher.sh">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
@@ -253,6 +257,7 @@
<Target Name="AfterBuild" Condition="$(Configuration) == 'Debug'">
<Copy SourceFiles="$(TargetDir)\$(TargetName).exe" DestinationFolder="$(GamePath)" />
<Copy SourceFiles="$(TargetDir)\$(TargetName).config.json" DestinationFolder="$(GamePath)" />
+ <Copy SourceFiles="$(TargetDir)\$(TargetName).data.json" DestinationFolder="$(GamePath)" />
<Copy SourceFiles="$(TargetDir)\StardewModdingAPI.AssemblyRewriters.dll" DestinationFolder="$(GamePath)" />
<Copy SourceFiles="$(TargetDir)\$(TargetName).exe.mdb" DestinationFolder="$(GamePath)" Condition="$(OS) != 'Windows_NT'" />
<Copy SourceFiles="$(TargetDir)\$(TargetName).pdb" DestinationFolder="$(GamePath)" Condition="$(OS) == 'Windows_NT'" />
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"
+ }
+]