add optional 'minimum API version' field to manifest (#176)
This commit is contained in:
parent
1ac930979a
commit
785af91952
|
@ -3,12 +3,13 @@
|
|||
## 1.1
|
||||
See [log](https://github.com/CLxS/SMAPI/compare/1.0...master).
|
||||
|
||||
* Improved logging:
|
||||
* simplified logging API;
|
||||
* added support for trace logs (written to the log file, but hidden in the console by default);
|
||||
* critical errors are now sent to the regular log instead of a separate file;
|
||||
* messages are now shown in order;
|
||||
* Added new logging interface:
|
||||
* simpler to use;
|
||||
* supports trace logs (written to the log file, but hidden in the console by default);
|
||||
* no longer puts critical errors in a separate log file;
|
||||
* messages now shown in order;
|
||||
* messages now show which mod logged them.
|
||||
* Added optional `MinimumApiVersion` to `manifest.json`.
|
||||
|
||||
## 1.0
|
||||
See [log](https://github.com/CLxS/SMAPI/compare/0.40.1.1-3...1.0).
|
||||
|
|
|
@ -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; } = "";
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue