From 69ffaf2e8c78d0ac49731e42ece2b7388807998f Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 7 Oct 2017 20:37:29 -0400 Subject: [PATCH] move manifest version parsing into method --- build/smapi.targets | 47 ++++++++++++++++++++++++++------------------- 1 file 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 data = (IDictionary)new JavaScriptSerializer().DeserializeObject(json); - IDictionary version = (IDictionary)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; } } + + /// Get a semantic version from the mod manifest (if available). + 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 data = (IDictionary)new JavaScriptSerializer().DeserializeObject(json); + IDictionary version = (IDictionary)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); + } } ]]>