diff options
author | Death <DeathGameDev@gmail.com> | 2017-10-07 17:54:11 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2017-10-07 18:54:11 -0400 |
commit | 78e59e1a48e6d9d2583c9adf54422d15e6e7074e (patch) | |
tree | 6e904aa8d78efda73b62946903691d06132b85b8 /build/smapi.targets | |
parent | 6f3fc68dafcaaaab59352378a9cdae41040e271a (diff) | |
download | SMAPI-78e59e1a48e6d9d2583c9adf54422d15e6e7074e.tar.gz SMAPI-78e59e1a48e6d9d2583c9adf54422d15e6e7074e.tar.bz2 SMAPI-78e59e1a48e6d9d2583c9adf54422d15e6e7074e.zip |
add version support to zip filenames (#7)
Diffstat (limited to 'build/smapi.targets')
-rw-r--r-- | build/smapi.targets | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/build/smapi.targets b/build/smapi.targets index ab7fb71f..88408994 100644 --- a/build/smapi.targets +++ b/build/smapi.targets @@ -14,8 +14,10 @@ <Task> <Reference Include="System.IO" /> <Reference Include="System.IO.Compression" /> + <Reference Include="System.Web.Extensions"/> <Using Namespace="System.IO" /> <Using Namespace="System.IO.Compression" /> + <Using Namespace="System.Web.Script.Serialization"/> <Code Type="Fragment" Language="cs"> <![CDATA[ try @@ -23,8 +25,29 @@ // 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); + // clear old zip file if present - string zipPath = Path.Combine(OutputFolderPath, ModName + ".zip"); + string zipPath = Path.Combine(OutputFolderPath, fileName); if (File.Exists(zipPath)) File.Delete(zipPath); |