From b887ecb30b4c41d58c6211ea00423f8259eebef5 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 18 Apr 2019 22:46:00 -0400 Subject: fix not applied to files matched by convention, update readme --- .../Framework/ModFileManager.cs | 97 ++++++++++++---------- src/SMAPI.ModBuildConfig/package.nuspec | 1 + 2 files changed, 56 insertions(+), 42 deletions(-) (limited to 'src/SMAPI.ModBuildConfig') diff --git a/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs b/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs index 6c11b0fe..e67a18c1 100644 --- a/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs +++ b/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs @@ -41,13 +41,63 @@ namespace StardewModdingAPI.ModBuildConfig.Framework if (!Directory.Exists(targetDir)) throw new UserErrorException("Could not create mod package because no build output was found."); + // collect files + foreach (Tuple entry in this.GetPossibleFiles(projectDir, targetDir)) + { + string relativePath = entry.Item1; + FileInfo file = entry.Item2; + + if (!this.ShouldIgnore(file, relativePath, ignoreFilePatterns)) + this.Files[relativePath] = file; + } + + // check for required files + if (validateRequiredModFiles) + { + // manifest + if (!this.Files.ContainsKey(this.ManifestFileName)) + throw new UserErrorException($"Could not create mod package because no {this.ManifestFileName} was found in the project or build output."); + + // DLL + // ReSharper disable once SimplifyLinqExpression + if (!this.Files.Any(p => !p.Key.EndsWith(".dll"))) + throw new UserErrorException("Could not create mod package because no .dll file was found in the project or build output."); + } + } + + /// Get the files in the mod package. + public IDictionary GetFiles() + { + return new Dictionary(this.Files, StringComparer.InvariantCultureIgnoreCase); + } + + /// Get a semantic version from the mod manifest. + /// The manifest is missing or invalid. + public string GetManifestVersion() + { + if (!this.Files.TryGetValue(this.ManifestFileName, out FileInfo manifestFile) || !new JsonHelper().ReadJsonFileIfExists(manifestFile.FullName, out Manifest manifest)) + throw new InvalidOperationException($"The mod does not have a {this.ManifestFileName} file."); // shouldn't happen since we validate in constructor + + return manifest.Version.ToString(); + } + + + /********* + ** Private methods + *********/ + /// Get all files to include in the mod folder, not accounting for ignore patterns. + /// The folder containing the project files. + /// The folder containing the build output. + /// Returns tuples containing the relative path within the mod folder, and the file to copy to it. + private IEnumerable> GetPossibleFiles(string projectDir, string targetDir) + { // project manifest bool hasProjectManifest = false; { - FileInfo manifest = new FileInfo(Path.Combine(projectDir, "manifest.json")); + FileInfo manifest = new FileInfo(Path.Combine(projectDir, this.ManifestFileName)); if (manifest.Exists) { - this.Files[this.ManifestFileName] = manifest; + yield return Tuple.Create(this.ManifestFileName, manifest); hasProjectManifest = true; } } @@ -58,7 +108,7 @@ namespace StardewModdingAPI.ModBuildConfig.Framework if (translationsFolder.Exists) { foreach (FileInfo file in translationsFolder.EnumerateFiles()) - this.Files[Path.Combine("i18n", file.Name)] = file; + yield return Tuple.Create(Path.Combine("i18n", file.Name), file); hasProjectTranslations = true; } @@ -70,7 +120,7 @@ namespace StardewModdingAPI.ModBuildConfig.Framework foreach (FileInfo file in assetsFolder.EnumerateFiles("*", SearchOption.AllDirectories)) { string relativePath = PathUtilities.GetRelativePath(projectDir, file.FullName); - this.Files[relativePath] = file; + yield return Tuple.Create(relativePath, file); } hasAssetsFolder = true; } @@ -91,48 +141,11 @@ namespace StardewModdingAPI.ModBuildConfig.Framework if (hasAssetsFolder && this.EqualsInvariant(segments[0], "assets")) continue; - // handle ignored files - if (this.ShouldIgnore(file, relativePath, ignoreFilePatterns)) - continue; - // add file - this.Files[relativePath] = file; - } - - // check for required files - if (validateRequiredModFiles) - { - // manifest - if (!this.Files.ContainsKey(this.ManifestFileName)) - throw new UserErrorException($"Could not create mod package because no {this.ManifestFileName} was found in the project or build output."); - - // DLL - // ReSharper disable once SimplifyLinqExpression - if (!this.Files.Any(p => !p.Key.EndsWith(".dll"))) - throw new UserErrorException("Could not create mod package because no .dll file was found in the project or build output."); + yield return Tuple.Create(relativePath, file); } } - /// Get the files in the mod package. - public IDictionary GetFiles() - { - return new Dictionary(this.Files, StringComparer.InvariantCultureIgnoreCase); - } - - /// Get a semantic version from the mod manifest. - /// The manifest is missing or invalid. - public string GetManifestVersion() - { - if (!this.Files.TryGetValue(this.ManifestFileName, out FileInfo manifestFile) || !new JsonHelper().ReadJsonFileIfExists(manifestFile.FullName, out Manifest manifest)) - throw new InvalidOperationException($"The mod does not have a {this.ManifestFileName} file."); // shouldn't happen since we validate in constructor - - return manifest.Version.ToString(); - } - - - /********* - ** Private methods - *********/ /// Get whether a build output file should be ignored. /// The file to check. /// The file's relative path in the package. diff --git a/src/SMAPI.ModBuildConfig/package.nuspec b/src/SMAPI.ModBuildConfig/package.nuspec index b6ef98f0..79a4f008 100644 --- a/src/SMAPI.ModBuildConfig/package.nuspec +++ b/src/SMAPI.ModBuildConfig/package.nuspec @@ -17,6 +17,7 @@ - If the project contains an `assets` folder, its contents are now included in the mod automatically. - Dropped support for very old versions of SMAPI and Visual Studio. - Fixed `Newtonsoft.Json.pdb` included in release zips when Json.NET is referenced directly. + - Fixed `<IgnoreModFilePatterns>` not working for `i18n` files. -- cgit