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 0000000..1910a3f Binary files /dev/null and b/Test/Content/Textures/Exclude.png differ