add support for SMAPI 2.0 version strings in mod release zip code

This commit is contained in:
Jesse Plamondon-Willard 2017-10-08 02:31:51 -04:00
parent aae482255c
commit ef3a89587c
1 changed files with 14 additions and 7 deletions

View File

@ -106,15 +106,22 @@ namespace StardewModdingAPI.ModBuildConfig.Tasks
throw new InvalidOperationException($"The mod's {this.ManifestFileName} couldn't be parsed. It doesn't seem to be valid JSON.", ex);
}
// extract version dictionary
IDictionary<string, object> versionFields = (IDictionary<string, object>)data["Version"];
// get version field
object versionObj = data.ContainsKey("Version") ? data["Version"] : null;
if (versionObj == null)
throw new InvalidOperationException($"The mod's {this.ManifestFileName} must have a version field.");
// get version string
if (versionObj is IDictionary<string, object> versionFields) // SMAPI 1.x
{
int major = versionFields.ContainsKey("MajorVersion") ? (int) versionFields["MajorVersion"] : 0;
int minor = versionFields.ContainsKey("MinorVersion") ? (int) versionFields["MinorVersion"] : 0;
int patch = versionFields.ContainsKey("PatchVersion") ? (int) versionFields["PatchVersion"] : 0;
string tag = versionFields.ContainsKey("Build") ? (string) versionFields["Build"] : null;
return new SemanticVersionImpl(major, minor, patch, tag).ToString();
}
return new SemanticVersionImpl(versionObj.ToString()).ToString(); // SMAPI 2.0+
}
/// <summary>Get a case-insensitive dictionary matching the given JSON.</summary>
/// <param name="json">The JSON to parse.</param>