From f64baaeb6a0583f4b50dd06d850620c885048e8f Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Tue, 8 Oct 2019 19:20:35 +0200 Subject: [PATCH] added a config --- Contentless/Contentless.csproj | 4 ++++ Contentless/Program.cs | 32 +++++++++++++++++++++++------- Test/Content/Content.mgcb | 5 +++++ Test/Content/Contentless.json | 7 +++++++ Test/Content/Textures/Exclude.png | Bin 0 -> 7530 bytes 5 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 Test/Content/Contentless.json create mode 100644 Test/Content/Textures/Exclude.png diff --git a/Contentless/Contentless.csproj b/Contentless/Contentless.csproj index 4aa6ccd..2fe1e8a 100644 --- a/Contentless/Contentless.csproj +++ b/Contentless/Contentless.csproj @@ -9,4 +9,8 @@ + + + + diff --git a/Contentless/Program.cs b/Contentless/Program.cs index 553440c..2f9d991 100644 --- a/Contentless/Program.cs +++ b/Contentless/Program.cs @@ -3,13 +3,13 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Reflection; +using System.Text.RegularExpressions; using Microsoft.Xna.Framework.Content.Pipeline; +using Newtonsoft.Json; namespace Contentless { public static class Program { - private static readonly string[] ExcludedFolders = {"bin/", "obj/"}; - public static void Main(string[] args) { if (args.Length != 1) { Console.WriteLine("Please specify the location of the content file you want to use"); @@ -25,6 +25,23 @@ namespace Contentless { Console.WriteLine($"Using content file {contentFile}"); var content = ReadContent(contentFile); + // load config + var config = new Config(); + var configFile = new FileInfo(Path.Combine(contentFile.DirectoryName, "Contentless.json")); + if (configFile.Exists) { + using (var stream = configFile.OpenText()) { + try { + config = JsonConvert.DeserializeObject(stream.ReadToEnd()); + Console.WriteLine($"Using config from {configFile}"); + } catch (Exception e) { + Console.WriteLine($"Error loading config from {configFile}: {e}"); + } + } + } else { + Console.WriteLine("Using default config"); + } + var excluded = Array.ConvertAll(config.ExcludedFiles, s => new Regex(s.Replace(".", "[.]").Replace("*", ".*").Replace("?", "."))); + // load any references to be able to include custom content types as well foreach (var line in content) { if (!line.StartsWith("/reference:")) @@ -34,8 +51,8 @@ namespace Contentless { try { Assembly.LoadFrom(refPath); Console.WriteLine($"Using reference {refPath}"); - } catch (Exception) { - Console.WriteLine($"Couldn't load reference {refPath}, file types that require this reference won't be added automatically"); + } catch (Exception e) { + Console.WriteLine($"Error loading reference {refPath}: {e}"); } } @@ -45,13 +62,14 @@ namespace Contentless { var changed = false; foreach (var file in contentFile.Directory.EnumerateFiles("*", SearchOption.AllDirectories)) { - // is the file the content file? - if (file.Name == contentFile.Name) + // is the file the content or config file? + if (file.Name == contentFile.Name || file.Name == configFile.Name) continue; var relative = GetRelativePath(contentFile.DirectoryName, file.FullName).Replace("\\", "/"); // is the file in an excluded directory? - if (ExcludedFolders.Any(e => relative.Contains(e))) { + if (excluded.Any(e => e.IsMatch(relative))) { + Console.WriteLine($"Skipping excluded file {relative}"); continue; } diff --git a/Test/Content/Content.mgcb b/Test/Content/Content.mgcb index 3a18093..e34014a 100644 --- a/Test/Content/Content.mgcb +++ b/Test/Content/Content.mgcb @@ -65,3 +65,8 @@ /processor:TiledMapTilesetProcessor /build:Tiled/Tileset.tsx +#begin Contentless.json +/importer:TexturePackerJsonImporter +/processor:TexturePackerProcessor +/build:Contentless.json + diff --git a/Test/Content/Contentless.json b/Test/Content/Contentless.json new file mode 100644 index 0000000..00b87f0 --- /dev/null +++ b/Test/Content/Contentless.json @@ -0,0 +1,7 @@ +{ + "exclude": [ + "obj/", + "bin/", + "Ex*.png" + ] +} \ No newline at end of file diff --git a/Test/Content/Textures/Exclude.png b/Test/Content/Textures/Exclude.png new file mode 100644 index 0000000000000000000000000000000000000000..1910a3f9669e644621d9a03493e0624bae27e668 GIT binary patch literal 7530 zcmeHMdrVVj6#r_mih{^=u?n@IF6vxBP+}EmLBZ!HzJ@Lel`wHz4dqcO@@Ok;G#arw zXJi2}6QeS;K$uW`&@zNNH>>ynwbTN2fWuOdQu?^G#L_}{(6&-zX!NLrJs>XX%UGIM>>irOQZFB`rPG4GxCwxJ z$GVW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