move manifest version parsing into method
This commit is contained in:
parent
4d32b37790
commit
69ffaf2e8c
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue