mirror of
https://github.com/Ellpeck/Contentless.git
synced 2024-11-22 15:28:34 +01:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
cd225372e8
14 changed files with 88 additions and 11 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Build/MonoGame.Framework.pdb
Normal file
BIN
Build/MonoGame.Framework.pdb
Normal file
Binary file not shown.
BIN
Build/Newtonsoft.Json.dll
Normal file
BIN
Build/Newtonsoft.Json.dll
Normal file
Binary file not shown.
13
Contentless/Config.cs
Normal file
13
Contentless/Config.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
using Newtonsoft.Json;
|
||||
|
||||
namespace Contentless {
|
||||
public class Config {
|
||||
|
||||
[JsonProperty(PropertyName = "exclude")]
|
||||
public string[] ExcludedFiles = {"bin/", "obj/"};
|
||||
|
||||
[JsonProperty(PropertyName = "logSkipped")]
|
||||
public bool LogSkipped = true;
|
||||
|
||||
}
|
||||
}
|
|
@ -9,4 +9,8 @@
|
|||
<ProjectReference Include="..\MonoGame\MonoGame.Framework.Content.Pipeline\MonoGame.Framework.Content.Pipeline.Windows.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -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<Config>(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,18 +62,21 @@ 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))) {
|
||||
if (config.LogSkipped)
|
||||
Console.WriteLine($"Skipping excluded file {relative}");
|
||||
continue;
|
||||
}
|
||||
|
||||
// is the file already in the content file?
|
||||
if (HasEntry(content, relative)) {
|
||||
if (config.LogSkipped)
|
||||
Console.WriteLine($"Skipping file {relative} as it is already part of the content file");
|
||||
continue;
|
||||
}
|
||||
|
|
21
LICENSE
Normal file
21
LICENSE
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2019 Ellpeck
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
16
README.md
16
README.md
|
@ -10,10 +10,22 @@ Next, add Contentless to your build process by adding the following task to your
|
|||
<Exec Command="..\..\Contentless\Build\Contentless.exe Content/Content.mgcb" />
|
||||
</Target>
|
||||
```
|
||||
Contentless will now automatically add any content files from your `Content` directory and subdirectories (excluding `bin` and `obj`) to your `Content.mgcb` file if they haven't already been added either manually or by Contentless. No existing items' configurations will be overridden, so you can still use the Content Pipeline tool to modify any settings as well.
|
||||
Contentless will now automatically add any content files from your `Content` directory and subdirectories to your `Content.mgcb` file if they haven't already been added either manually or by Contentless. No existing items' configurations will be overridden, so you can still use the Content Pipeline tool to modify any settings as well.
|
||||
|
||||
# Configuring
|
||||
To add a configuration file to Contentless, simply create a file named `Contentless.json` in the same directory as your `Content.mgcb` file. You can use the config to change several options. For reference, here is a configuration file with the default values that are used if no config is supplied:
|
||||
```json
|
||||
{
|
||||
"exclude": [
|
||||
"obj/",
|
||||
"bin/"
|
||||
],
|
||||
"logSkipped": true
|
||||
}
|
||||
```
|
||||
|
||||
# What it does
|
||||
When running Contentless and supplying the location of a MonoGame Content Pipeline project (`Content.mgcb`), it scans all of the files in the project's directory as well as its subdirectories (excluding `bin` and `obj`). For each file, it checks if the `Content.mgcb` file already contains any references to that file. If no references are found, then a new reference to the file is added.
|
||||
When running Contentless and supplying the location of a MonoGame Content Pipeline project (`Content.mgcb`), it scans all of the files in the project's directory as well as its subdirectories. For each file, it checks if the `Content.mgcb` file already contains any references to that file. If no references are found, then a new reference to the file is added.
|
||||
|
||||
Contentless figures out which importer and processor to register for any given file by generating a list of all of the importers and processors that are available, both inside of MonoGame, and inside of References added to the `Content.mgcb` file. This process is similar to what occurs when adding an existing file through MonoGame's Content Pipeline tool. If Contentless sets the wrong importer or processor for any file, the user can simply open `Content.mgcb` in MonoGame's Content Pipeline tool and edit it manually.
|
||||
|
||||
|
|
|
@ -64,4 +64,3 @@
|
|||
/importer:TiledMapTilesetImporter
|
||||
/processor:TiledMapTilesetProcessor
|
||||
/build:Tiled/Tileset.tsx
|
||||
|
||||
|
|
8
Test/Content/Contentless.json
Normal file
8
Test/Content/Contentless.json
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"exclude": [
|
||||
"obj/",
|
||||
"bin/",
|
||||
"Ex*.png"
|
||||
],
|
||||
"logSkipped": false
|
||||
}
|
BIN
Test/Content/Textures/Exclude.png
Normal file
BIN
Test/Content/Textures/Exclude.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.4 KiB |
Loading…
Reference in a new issue