summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/StardewModdingAPI/Manifest.cs3
-rw-r--r--src/StardewModdingAPI/Program.cs21
-rw-r--r--src/StardewModdingAPI/Version.cs7
3 files changed, 30 insertions, 1 deletions
diff --git a/src/StardewModdingAPI/Manifest.cs b/src/StardewModdingAPI/Manifest.cs
index c07dc845..c7e54335 100644
--- a/src/StardewModdingAPI/Manifest.cs
+++ b/src/StardewModdingAPI/Manifest.cs
@@ -44,6 +44,9 @@ namespace StardewModdingAPI
[Obsolete("Use " + nameof(Mod) + "." + nameof(Mod.Helper) + "." + nameof(ModHelper.ReadConfig) + " instead")]
public virtual bool PerSaveConfigs { get; set; }
+ /// <summary>The minimum SMAPI version required by this mod, if any.</summary>
+ public string MinimumApiVersion { get; set; }
+
/// <summary>The name of the DLL in the directory that has the <see cref="Mod.Entry"/> method.</summary>
public virtual string EntryDll { get; set; } = "";
}
diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs
index 0e1a2527..ca45eba5 100644
--- a/src/StardewModdingAPI/Program.cs
+++ b/src/StardewModdingAPI/Program.cs
@@ -158,7 +158,7 @@ namespace StardewModdingAPI
{
GitRelease release = UpdateHelper.GetLatestVersionAsync(Constants.GitHubRepository).Result;
Version latestVersion = new Version(release.Tag);
- if (latestVersion.CompareTo(Constants.Version) > 0)
+ if (latestVersion.IsNewerThan(Constants.Version))
Program.Monitor.Log($"You can update SMAPI from version {Constants.Version} to {latestVersion}", LogLevel.Alert);
}
catch (Exception ex)
@@ -320,6 +320,25 @@ namespace StardewModdingAPI
continue;
}
+ // validate version
+ if (!string.IsNullOrWhiteSpace(manifest.MinimumApiVersion))
+ {
+ try
+ {
+ Version minVersion = new Version(manifest.MinimumApiVersion);
+ if (minVersion.IsNewerThan(Constants.Version))
+ {
+ Program.Monitor.Log($"{errorPrefix}: this mod requires SMAPI {minVersion} or later. Please update SMAPI to the latest version to use this mod.", LogLevel.Error);
+ continue;
+ }
+ }
+ catch (FormatException ex) when (ex.Message.Contains("not a semantic version"))
+ {
+ Program.Monitor.Log($"{errorPrefix}: the mod specified an invalid minimum SMAPI version '{manifest.MinimumApiVersion}'. This should be a semantic version number like {Constants.Version}.", LogLevel.Error);
+ continue;
+ }
+ }
+
// create per-save directory
if (manifest.PerSaveConfigs)
{
diff --git a/src/StardewModdingAPI/Version.cs b/src/StardewModdingAPI/Version.cs
index 3eacb2ae..bdecc8e0 100644
--- a/src/StardewModdingAPI/Version.cs
+++ b/src/StardewModdingAPI/Version.cs
@@ -98,6 +98,13 @@ namespace StardewModdingAPI
return string.Compare(this.ToString(), other.ToString(), StringComparison.InvariantCultureIgnoreCase);
}
+ /// <summary>Get whether this version is newer than the specified version.</summary>
+ /// <param name="other">The version to compare with this instance.</param>
+ public bool IsNewerThan(Version other)
+ {
+ return this.CompareTo(other) > 0;
+ }
+
/// <summary>Get a string representation of the version.</summary>
public override string ToString()
{