diff options
-rw-r--r-- | build/smapi.targets | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/build/smapi.targets b/build/smapi.targets index 3512d042..a1b6aab3 100644 --- a/build/smapi.targets +++ b/build/smapi.targets @@ -51,26 +51,8 @@ // create output path if needed Directory.CreateDirectory(OutputFolderPath); - // Get the file JSON string - string json = ""; - foreach(ITaskItem file in Files) - { - if(Path.GetFileName(file.ItemSpec).ToLower() != "manifest.json") - continue; - json = File.ReadAllText(file.ItemSpec); - break; - } - - // Serialize the manifest json into a data object, then get a version object from that. - IDictionary<string, object> data = (IDictionary<string, object>)new JavaScriptSerializer().DeserializeObject(json); - IDictionary<string, object> version = (IDictionary<string, object>)data["Version"]; - - // Store our version numbers for ease of use - int major = (int)version["MajorVersion"]; - int minor = (int)version["MinorVersion"]; - int patch = (int)version["PatchVersion"]; - - string fileName = String.Format("{0}-{1}.{2}.{3}.zip", ModName, major, minor, patch); + // get zip filename + string fileName = string.Format("{0}-{1}.zip", this.ModName, this.GetManifestVersion()); // clear old zip file if present string zipPath = Path.Combine(OutputFolderPath, fileName); @@ -106,6 +88,31 @@ return false; } } + + /// <summary>Get a semantic version from the mod manifest (if available).</summary> + public string GetManifestVersion() + { + // Get the file JSON string + string json = ""; + foreach(ITaskItem file in Files) + { + if(Path.GetFileName(file.ItemSpec).ToLower() != "manifest.json") + continue; + json = File.ReadAllText(file.ItemSpec); + break; + } + + // Serialize the manifest json into a data object, then get a version object from that. + IDictionary<string, object> data = (IDictionary<string, object>)new JavaScriptSerializer().DeserializeObject(json); + IDictionary<string, object> version = (IDictionary<string, object>)data["Version"]; + + // Store our version numbers for ease of use + int major = (int)version["MajorVersion"]; + int minor = (int)version["MinorVersion"]; + int patch = (int)version["PatchVersion"]; + + return String.Format("{0}.{1}.{2}", major, minor, patch); + } } ]]> </Code> |