diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..38f4e9e --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.idea +bin +obj +packages +*.user +*.nupkg \ No newline at end of file diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..4a70de7 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "MonoGame"] + path = MonoGame + url = https://github.com/MonoGame/MonoGame diff --git a/.idea/.idea.Contentless/.idea/vcs.xml b/.idea/.idea.Contentless/.idea/vcs.xml new file mode 100644 index 0000000..0e97cfa --- /dev/null +++ b/.idea/.idea.Contentless/.idea/vcs.xml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Contentless.sln b/Contentless.sln new file mode 100644 index 0000000..e07d337 --- /dev/null +++ b/Contentless.sln @@ -0,0 +1,28 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Contentless", "Contentless\Contentless.csproj", "{A5C68D51-B404-44C9-8DD8-BAD4FD62A82D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MonoGame.Framework.Content.Pipeline.Windows", "MonoGame\MonoGame.Framework.Content.Pipeline\MonoGame.Framework.Content.Pipeline.Windows.csproj", "{B950DE10-AC5D-4BD9-B817-51247C4A732D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{58716AA9-5BCE-42C5-A0E7-D8B23C0488BA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A5C68D51-B404-44C9-8DD8-BAD4FD62A82D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A5C68D51-B404-44C9-8DD8-BAD4FD62A82D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A5C68D51-B404-44C9-8DD8-BAD4FD62A82D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A5C68D51-B404-44C9-8DD8-BAD4FD62A82D}.Release|Any CPU.Build.0 = Release|Any CPU + {B950DE10-AC5D-4BD9-B817-51247C4A732D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B950DE10-AC5D-4BD9-B817-51247C4A732D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B950DE10-AC5D-4BD9-B817-51247C4A732D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B950DE10-AC5D-4BD9-B817-51247C4A732D}.Release|Any CPU.Build.0 = Release|Any CPU + {58716AA9-5BCE-42C5-A0E7-D8B23C0488BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {58716AA9-5BCE-42C5-A0E7-D8B23C0488BA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {58716AA9-5BCE-42C5-A0E7-D8B23C0488BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {58716AA9-5BCE-42C5-A0E7-D8B23C0488BA}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/Contentless/Contentless.csproj b/Contentless/Contentless.csproj new file mode 100644 index 0000000..42dfd03 --- /dev/null +++ b/Contentless/Contentless.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp2.2 + + + + + + + diff --git a/Contentless/Program.cs b/Contentless/Program.cs new file mode 100644 index 0000000..6943b35 --- /dev/null +++ b/Contentless/Program.cs @@ -0,0 +1,123 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using Microsoft.Xna.Framework.Content.Pipeline; + +namespace Contentless { + public static class Program { + + private static readonly ImporterInfo[] Importers = GetContentImporters().ToArray(); + private static readonly string[] ExcludedFolders = {"bin", "obj"}; + + public static void Main(string[] args) { + var contentFile = new FileInfo(Path.Combine(Environment.CurrentDirectory, args[0])); + if (!contentFile.Exists) { + Console.WriteLine($"Unable to find content file {contentFile}"); + return; + } + var content = ReadContent(contentFile); + + var changed = false; + foreach (var file in contentFile.Directory.EnumerateFiles("*", SearchOption.AllDirectories)) { + // is the file the content file? + if (file.Name == contentFile.Name) + continue; + var relative = Path.GetRelativePath(contentFile.Directory.FullName, file.FullName).Replace("\\", "/"); + + // is the file in an excluded directory? + var dirName = file.DirectoryName.Replace("\\", "/"); + if (ExcludedFolders.Any(e => dirName.Contains(e))) { + continue; + } + + // is the file already in the content file? + if (HasEntry(content, relative)) { + Console.WriteLine($"Skipping file {relative} as it is already part of the content file"); + continue; + } + + var importer = GetImporterFor(relative); + if (importer == null) { + Console.WriteLine($"No importer found for file {relative}, please add the file manually"); + continue; + } + + AddFile(content, relative, importer); + changed = true; + } + + if (changed) { + contentFile.Delete(); + using (var stream = contentFile.CreateText()) { + foreach (var line in content) + stream.WriteLine(line); + } + Console.WriteLine("Wrote changes to content file"); + } + Console.Write("Done"); + } + + private static IEnumerable GetContentImporters() { + foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { + foreach (var type in assembly.GetTypes()) { + var importer = (ContentImporterAttribute) type.GetCustomAttribute(typeof(ContentImporterAttribute), true); + if (importer != null) + yield return new ImporterInfo(importer, type); + } + } + } + + private static ImporterInfo GetImporterFor(string file) { + var extension = Path.GetExtension(file); + foreach (var importer in Importers) { + if (importer.Importer.FileExtensions.Contains(extension)) + return importer; + } + return null; + } + + private static bool HasEntry(IEnumerable content, string relativeFile) { + foreach (var line in content) { + if (line.StartsWith($"#begin {relativeFile}")) + return true; + } + return false; + } + + private static List ReadContent(FileInfo file) { + var content = new List(); + using (var stream = file.OpenText()) { + string line; + while ((line = stream.ReadLine()) != null) { + content.Add(line); + } + } + return content; + } + + private static void AddFile(List content, string relative, ImporterInfo importer) { + content.Add($"#begin {relative}"); + content.Add($"/importer:{importer.Type.Name}"); + content.Add($"/processor:{importer.Importer.DefaultProcessor}"); + content.Add($"/build:{relative}"); + content.Add(""); + + Console.WriteLine($"Adding file {relative} with importer {importer.Type.Name} and processor {importer.Importer.DefaultProcessor}"); + } + + private class ImporterInfo { + + public readonly ContentImporterAttribute Importer; + public readonly Type Type; + + public ImporterInfo(ContentImporterAttribute importer, Type type) { + this.Importer = importer; + this.Type = type; + } + + } + + } +} \ No newline at end of file diff --git a/MonoGame b/MonoGame new file mode 160000 index 0000000..27bdfa9 --- /dev/null +++ b/MonoGame @@ -0,0 +1 @@ +Subproject commit 27bdfa92abf597c345c9c40bb4999b0fcd2dcaa2 diff --git a/Test/Content/Content.mgcb b/Test/Content/Content.mgcb new file mode 100644 index 0000000..d78753e --- /dev/null +++ b/Test/Content/Content.mgcb @@ -0,0 +1,30 @@ + +#----------------------------- Global Properties ----------------------------# + +/outputDir:bin +/intermediateDir:obj +/platform:DesktopGL +/config: +/profile:Reach +/compress:False + +#-------------------------------- References --------------------------------# + + +#---------------------------------- Content ---------------------------------# + +#begin Textures/Inside.png +/importer:TextureImporter +/processor:TextureProcessor +/build:Textures/Inside.png + +#begin Locale/Interface.xml +/importer:XmlImporter +/processor:PassThroughProcessor +/build:Locale/Interface.xml + +#begin Textures/Icons.png +/importer:TextureImporter +/processor:TextureProcessor +/build:Textures/Icons.png + diff --git a/Test/Content/Locale/Interface.xml b/Test/Content/Locale/Interface.xml new file mode 100644 index 0000000..d4c4f76 --- /dev/null +++ b/Test/Content/Locale/Interface.xml @@ -0,0 +1,29 @@ + + + + + Place + Place + + + Drop + Drop + + + TimeHour + h:mm tt + + + TimeDay + dddd d MMM + + + Inventory + Inventory + + + Tools + Tools + + + \ No newline at end of file diff --git a/Test/Content/Textures/Icons.png b/Test/Content/Textures/Icons.png new file mode 100644 index 0000000..1910a3f Binary files /dev/null and b/Test/Content/Textures/Icons.png differ diff --git a/Test/Content/Textures/Inside.png b/Test/Content/Textures/Inside.png new file mode 100644 index 0000000..28c556b Binary files /dev/null and b/Test/Content/Textures/Inside.png differ diff --git a/Test/Test.csproj b/Test/Test.csproj new file mode 100644 index 0000000..ec0b0b9 --- /dev/null +++ b/Test/Test.csproj @@ -0,0 +1,7 @@ + + + + netcoreapp2.2 + + +