From af68910685326a660cc88cd92582b38cbc0d9b2f Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 8 Oct 2017 00:20:13 -0400 Subject: convert mod build config into .NET project to simplify C# build tasks --- src/SMAPI.ModBuildConfig/build/smapi.targets | 273 +++++++++++++++++++++++++++ 1 file changed, 273 insertions(+) create mode 100644 src/SMAPI.ModBuildConfig/build/smapi.targets (limited to 'src/SMAPI.ModBuildConfig/build') diff --git a/src/SMAPI.ModBuildConfig/build/smapi.targets b/src/SMAPI.ModBuildConfig/build/smapi.targets new file mode 100644 index 00000000..a1b6aab3 --- /dev/null +++ b/src/SMAPI.ModBuildConfig/build/smapi.targets @@ -0,0 +1,273 @@ + + + + + + + + + + + + + + + A build task which packs mod files into a conventional release zip. + public class CreateModReleaseZip : Task, ITask + { + /********* + ** Accessors + *********/ + /// The mod files to pack. + public ITaskItem[] Files { get; set; } + + /// The name of the mod. + public string ModName { get; set; } + + /// The absolute or relative path to the folder which should contain the generated zip file. + public string OutputFolderPath { get; set; } + + + /********* + ** Public methods + *********/ + public override bool Execute() + { + try + { + // create output path if needed + Directory.CreateDirectory(OutputFolderPath); + + // 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); + if (File.Exists(zipPath)) + File.Delete(zipPath); + + // create zip file + using (Stream zipStream = new FileStream(zipPath, FileMode.Create, FileAccess.Write)) + using (ZipArchive archive = new ZipArchive(zipStream, ZipArchiveMode.Create)) + { + foreach (ITaskItem file in Files) + { + // get file info + string filePath = file.ItemSpec; + string entryName = ModName + '/' + file.GetMetadata("RecursiveDir") + file.GetMetadata("Filename") + file.GetMetadata("Extension"); + if (new FileInfo(filePath).Directory.Name.Equals("i18n", StringComparison.InvariantCultureIgnoreCase)) + entryName = Path.Combine("i18n", entryName); + + // add to zip + using (Stream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) + using (Stream fileStreamInZip = archive.CreateEntry(entryName).Open()) + { + fileStream.CopyTo(fileStreamInZip); + } + } + } + + return true; + } + catch (Exception ex) + { + Log.LogErrorFromException(ex); + 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); + } + } + ]]> + + + + + + + + + + + + + + + + $(HOME)/GOG Games/Stardew Valley/game + $(HOME)/.local/share/Steam/steamapps/common/Stardew Valley + + + /Applications/Stardew Valley.app/Contents/MacOS + $(HOME)/Library/Application Support/Steam/steamapps/common/Stardew Valley/Contents/MacOS + + + + + C:\Program Files (x86)\GalaxyClient\Games\Stardew Valley + C:\Program Files (x86)\Steam\steamapps\common\Stardew Valley + $([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\GOG.com\Games\1453375253', 'PATH', null, RegistryView.Registry32)) + $([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 413150', 'InstallLocation', null, RegistryView.Registry64, RegistryView.Registry32)) + + + + + + + + + + + + false + + + false + + + false + + + false + + + $(GamePath)\Stardew Valley.exe + false + + + $(GamePath)\StardewModdingAPI.exe + false + + + $(GamePath)\xTile.dll + false + False + + + + + + Program + $(GamePath)\StardewModdingAPI.exe + $(GamePath) + + + + + + + $(GamePath)\MonoGame.Framework.dll + false + False + + + $(GamePath)\StardewValley.exe + false + + + $(GamePath)\StardewModdingAPI.exe + false + + + $(GamePath)\xTile.dll + false + + + + + + + + + + + + + + + + + + + + + + + + $(GamePath)\Mods\$(DeployModFolderName) + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit From ddad601de3610a56a87c3f943d7ecc9c92af15f9 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 8 Oct 2017 01:27:52 -0400 Subject: move create-zip task into project code --- src/SMAPI.ModBuildConfig/build/smapi.targets | 120 +-------------------------- 1 file changed, 2 insertions(+), 118 deletions(-) (limited to 'src/SMAPI.ModBuildConfig/build') diff --git a/src/SMAPI.ModBuildConfig/build/smapi.targets b/src/SMAPI.ModBuildConfig/build/smapi.targets index a1b6aab3..b4bc8d8b 100644 --- a/src/SMAPI.ModBuildConfig/build/smapi.targets +++ b/src/SMAPI.ModBuildConfig/build/smapi.targets @@ -1,124 +1,8 @@ - - - - - - - - - - - - - A build task which packs mod files into a conventional release zip. - public class CreateModReleaseZip : Task, ITask - { - /********* - ** Accessors - *********/ - /// The mod files to pack. - public ITaskItem[] Files { get; set; } - - /// The name of the mod. - public string ModName { get; set; } - - /// The absolute or relative path to the folder which should contain the generated zip file. - public string OutputFolderPath { get; set; } - - - /********* - ** Public methods - *********/ - public override bool Execute() - { - try - { - // create output path if needed - Directory.CreateDirectory(OutputFolderPath); - - // 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); - if (File.Exists(zipPath)) - File.Delete(zipPath); - - // create zip file - using (Stream zipStream = new FileStream(zipPath, FileMode.Create, FileAccess.Write)) - using (ZipArchive archive = new ZipArchive(zipStream, ZipArchiveMode.Create)) - { - foreach (ITaskItem file in Files) - { - // get file info - string filePath = file.ItemSpec; - string entryName = ModName + '/' + file.GetMetadata("RecursiveDir") + file.GetMetadata("Filename") + file.GetMetadata("Extension"); - if (new FileInfo(filePath).Directory.Name.Equals("i18n", StringComparison.InvariantCultureIgnoreCase)) - entryName = Path.Combine("i18n", entryName); - - // add to zip - using (Stream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) - using (Stream fileStreamInZip = archive.CreateEntry(entryName).Open()) - { - fileStream.CopyTo(fileStreamInZip); - } - } - } - - return true; - } - catch (Exception ex) - { - Log.LogErrorFromException(ex); - 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); - } - } - ]]> - - - - + - + - + -- cgit From cd93382c645da3c6d3ce4e532307f42704ba4c76 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 8 Oct 2017 15:03:31 -0400 Subject: move zip logic into method --- src/SMAPI.ModBuildConfig/build/smapi.targets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/SMAPI.ModBuildConfig/build') diff --git a/src/SMAPI.ModBuildConfig/build/smapi.targets b/src/SMAPI.ModBuildConfig/build/smapi.targets index 61bf96ac..46e8428d 100644 --- a/src/SMAPI.ModBuildConfig/build/smapi.targets +++ b/src/SMAPI.ModBuildConfig/build/smapi.targets @@ -152,6 +152,6 @@ - + -- cgit From 475efa12febcb1f1f0976cb6c84e445a263daed9 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 8 Oct 2017 18:05:47 -0400 Subject: rewrite mod build package per new docs --- src/SMAPI.ModBuildConfig/build/smapi.targets | 76 ++++++++++------------------ 1 file changed, 27 insertions(+), 49 deletions(-) (limited to 'src/SMAPI.ModBuildConfig/build') diff --git a/src/SMAPI.ModBuildConfig/build/smapi.targets b/src/SMAPI.ModBuildConfig/build/smapi.targets index 46e8428d..0010d8ff 100644 --- a/src/SMAPI.ModBuildConfig/build/smapi.targets +++ b/src/SMAPI.ModBuildConfig/build/smapi.targets @@ -7,15 +7,24 @@ - + - + + + + $(DeployModFolderName) + $(DeployModZipTo) + + + $(MSBuildProjectName) + $(TargetDir) + True + True + + + @@ -106,52 +115,21 @@ - - - - - - - - - - - - - - - - - $(GamePath)\Mods\$(DeployModFolderName) - - - - - - - - - - - + + - - + EnableModDeploy="$(EnableModDeploy)" + EnableModZip="$(EnableModZip)" - - - - + ProjectDir="$(ProjectDir)" + TargetDir="$(TargetDir)" + GameDir="$(GamePath)" - - - + Platform="$(OS)" + /> -- cgit From 1c0d22e82c4690069754d211179d8aef636a3e7a Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 10 Oct 2017 21:59:05 -0400 Subject: validate build context before build --- src/SMAPI.ModBuildConfig/build/smapi.targets | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/SMAPI.ModBuildConfig/build') diff --git a/src/SMAPI.ModBuildConfig/build/smapi.targets b/src/SMAPI.ModBuildConfig/build/smapi.targets index 0010d8ff..9f3f13f5 100644 --- a/src/SMAPI.ModBuildConfig/build/smapi.targets +++ b/src/SMAPI.ModBuildConfig/build/smapi.targets @@ -3,6 +3,7 @@ ** Import build tasks **********************************************--> + + + + -- cgit From 1c7dfb519dd4238336a9a29d677219563e898dc7 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 10 Oct 2017 22:33:45 -0400 Subject: move validation back into .targets for MonoDevelop compatibility --- src/SMAPI.ModBuildConfig/build/smapi.targets | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/SMAPI.ModBuildConfig/build') diff --git a/src/SMAPI.ModBuildConfig/build/smapi.targets b/src/SMAPI.ModBuildConfig/build/smapi.targets index 9f3f13f5..f7e75e23 100644 --- a/src/SMAPI.ModBuildConfig/build/smapi.targets +++ b/src/SMAPI.ModBuildConfig/build/smapi.targets @@ -118,9 +118,17 @@ + - + + + + + + + + Date: Wed, 11 Oct 2017 15:30:37 -0400 Subject: rm artifact --- src/SMAPI.ModBuildConfig/build/smapi.targets | 1 - 1 file changed, 1 deletion(-) (limited to 'src/SMAPI.ModBuildConfig/build') diff --git a/src/SMAPI.ModBuildConfig/build/smapi.targets b/src/SMAPI.ModBuildConfig/build/smapi.targets index f7e75e23..c0319e22 100644 --- a/src/SMAPI.ModBuildConfig/build/smapi.targets +++ b/src/SMAPI.ModBuildConfig/build/smapi.targets @@ -3,7 +3,6 @@ ** Import build tasks **********************************************--> -