diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2019-04-18 22:46:00 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2019-09-14 17:14:56 -0400 |
commit | b887ecb30b4c41d58c6211ea00423f8259eebef5 (patch) | |
tree | 272fca4a57fc3f35f924231bfc5c550fe95e4a13 /src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs | |
parent | aa7e4b9c36bf14656493ee0a7ab2dab394a3cf64 (diff) | |
download | SMAPI-b887ecb30b4c41d58c6211ea00423f8259eebef5.tar.gz SMAPI-b887ecb30b4c41d58c6211ea00423f8259eebef5.tar.bz2 SMAPI-b887ecb30b4c41d58c6211ea00423f8259eebef5.zip |
fix <IgnoreModFilePatterns> not applied to files matched by convention, update readme
Diffstat (limited to 'src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs')
-rw-r--r-- | src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs | 97 |
1 files changed, 55 insertions, 42 deletions
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<string, FileInfo> 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."); + } + } + + /// <summary>Get the files in the mod package.</summary> + public IDictionary<string, FileInfo> GetFiles() + { + return new Dictionary<string, FileInfo>(this.Files, StringComparer.InvariantCultureIgnoreCase); + } + + /// <summary>Get a semantic version from the mod manifest.</summary> + /// <exception cref="UserErrorException">The manifest is missing or invalid.</exception> + 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 + *********/ + /// <summary>Get all files to include in the mod folder, not accounting for ignore patterns.</summary> + /// <param name="projectDir">The folder containing the project files.</param> + /// <param name="targetDir">The folder containing the build output.</param> + /// <returns>Returns tuples containing the relative path within the mod folder, and the file to copy to it.</returns> + private IEnumerable<Tuple<string, FileInfo>> 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); } } - /// <summary>Get the files in the mod package.</summary> - public IDictionary<string, FileInfo> GetFiles() - { - return new Dictionary<string, FileInfo>(this.Files, StringComparer.InvariantCultureIgnoreCase); - } - - /// <summary>Get a semantic version from the mod manifest.</summary> - /// <exception cref="UserErrorException">The manifest is missing or invalid.</exception> - 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 - *********/ /// <summary>Get whether a build output file should be ignored.</summary> /// <param name="file">The file to check.</param> /// <param name="relativePath">The file's relative path in the package.</param> |