diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2016-11-16 16:21:17 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2016-11-16 16:21:17 -0500 |
commit | 785af919521124ea7f231aa1437525cf27f82d6c (patch) | |
tree | 7940b5edfd1a55510c3e945bf998af912cd0e4e7 /src | |
parent | 1ac930979a34c2fde4e0fb5ff5244ea18c68aa77 (diff) | |
download | SMAPI-785af919521124ea7f231aa1437525cf27f82d6c.tar.gz SMAPI-785af919521124ea7f231aa1437525cf27f82d6c.tar.bz2 SMAPI-785af919521124ea7f231aa1437525cf27f82d6c.zip |
add optional 'minimum API version' field to manifest (#176)
Diffstat (limited to 'src')
-rw-r--r-- | src/StardewModdingAPI/Manifest.cs | 3 | ||||
-rw-r--r-- | src/StardewModdingAPI/Program.cs | 21 | ||||
-rw-r--r-- | src/StardewModdingAPI/Version.cs | 7 |
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() { |