This commit is contained in:
Ellpeck 2019-10-08 12:40:25 +02:00
parent 64016a75c4
commit 0b6e14336f
12 changed files with 251 additions and 0 deletions

6
.gitignore vendored Normal file
View file

@ -0,0 +1,6 @@
.idea
bin
obj
packages
*.user
*.nupkg

3
.gitmodules vendored Normal file
View file

@ -0,0 +1,3 @@
[submodule "MonoGame"]
path = MonoGame
url = https://github.com/MonoGame/MonoGame

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/MonoGame" vcs="Git" />
<mapping directory="$PROJECT_DIR$/MonoGame/ThirdParty/Dependencies" vcs="Git" />
<mapping directory="$PROJECT_DIR$/MonoGame/ThirdParty/NVorbis" vcs="Git" />
<mapping directory="$PROJECT_DIR$/MonoGame/ThirdParty/SDL_GameControllerDB" vcs="Git" />
<mapping directory="$PROJECT_DIR$/MonoGame/ThirdParty/StbImageSharp" vcs="Git" />
<mapping directory="$PROJECT_DIR$/MonoGame/ThirdParty/StbImageWriteSharp" vcs="Git" />
</component>
</project>

28
Contentless.sln Normal file
View file

@ -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

View file

@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\MonoGame\MonoGame.Framework.Content.Pipeline\MonoGame.Framework.Content.Pipeline.Windows.csproj" />
</ItemGroup>
</Project>

123
Contentless/Program.cs Normal file
View file

@ -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<ImporterInfo> 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<string> content, string relativeFile) {
foreach (var line in content) {
if (line.StartsWith($"#begin {relativeFile}"))
return true;
}
return false;
}
private static List<string> ReadContent(FileInfo file) {
var content = new List<string>();
using (var stream = file.OpenText()) {
string line;
while ((line = stream.ReadLine()) != null) {
content.Add(line);
}
}
return content;
}
private static void AddFile(List<string> 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;
}
}
}
}

1
MonoGame Submodule

@ -0,0 +1 @@
Subproject commit 27bdfa92abf597c345c9c40bb4999b0fcd2dcaa2

30
Test/Content/Content.mgcb Normal file
View file

@ -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

View file

@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<XnaContent>
<Asset Type="System.Collections.Generic.Dictionary[System.String, System.String]">
<Item>
<Key>Place</Key>
<Value>Place</Value>
</Item>
<Item>
<Key>Drop</Key>
<Value>Drop</Value>
</Item>
<Item>
<Key>TimeHour</Key>
<Value>h:mm tt</Value>
</Item>
<Item>
<Key>TimeDay</Key>
<Value>dddd d MMM</Value>
</Item>
<Item>
<Key>Inventory</Key>
<Value>Inventory</Value>
</Item>
<Item>
<Key>Tools</Key>
<Value>Tools</Value>
</Item>
</Asset>
</XnaContent>

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

7
Test/Test.csproj Normal file
View file

@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
</Project>