updated to .net 6

This commit is contained in:
Ell 2022-09-25 23:29:02 +02:00
parent 0315f996bd
commit d1012c8a28
9 changed files with 529 additions and 535 deletions

View file

@ -1,8 +1,8 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Contentless {
namespace Contentless;
public class Config {
[JsonProperty("exclude")]
@ -12,7 +12,7 @@ namespace Contentless {
public bool LogSkipped = true;
[JsonProperty("overrides")]
public Dictionary<string, Override> Overrides = new Dictionary<string, Override>();
public Dictionary<string, Override> Overrides = new();
}
@ -23,9 +23,8 @@ namespace Contentless {
[JsonProperty("processor")]
public string Processor;
[JsonProperty("processorParams")]
public Dictionary<string, string> ProcessorParams = new Dictionary<string, string>();
public Dictionary<string, string> ProcessorParams = new();
[JsonProperty("copy")]
public bool Copy;
}
}

View file

@ -2,7 +2,8 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RollForward>Major</RollForward>
</PropertyGroup>
<PropertyGroup>

View file

@ -12,13 +12,13 @@
<icon>Logo.png</icon>
<version>3.0.6</version>
<dependencies>
<group targetFramework="net5.0" />
<group targetFramework="net6.0" />
</dependencies>
</metadata>
<files>
<file src="_._" target="lib/net5.0/"/>
<file src="_._" target="lib/net6.0/" />
<file src="Contentless.targets" target="build/Contentless.targets" />
<file src="bin\Debug\net5.0\**\*" target="tools/"/>
<file src="bin\Debug\net6.0\**\*" target="tools/" />
<file src="../README.md" target="" />
<file src="../Logo.png" target="" />
</files>

View file

@ -1,7 +1,8 @@
using System;
using Microsoft.Xna.Framework.Content.Pipeline;
namespace Contentless {
namespace Contentless;
public class ImporterInfo {
public readonly ContentImporterAttribute Importer;
@ -17,4 +18,3 @@ namespace Contentless {
}
}
}

View file

@ -1,6 +1,7 @@
using System.Text.RegularExpressions;
namespace Contentless {
namespace Contentless;
public class OverrideInfo {
public readonly Regex Regex;
@ -12,4 +13,3 @@ namespace Contentless {
}
}
}

View file

@ -6,9 +6,9 @@ using System.Reflection;
using System.Text.RegularExpressions;
using Microsoft.Xna.Framework.Content.Pipeline;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Contentless {
namespace Contentless;
public static class Program {
public static void Main(string[] args) {
@ -24,25 +24,24 @@ namespace Contentless {
}
Console.WriteLine($"Using content file {contentFile}");
var content = ReadContent(contentFile);
var content = Program.ReadContent(contentFile);
// load config
var config = new Config();
var configFile = new FileInfo(Path.Combine(contentFile.DirectoryName, "Contentless.json"));
var configFile = new FileInfo(Path.Combine(contentFile.DirectoryName!, "Contentless.json"));
if (configFile.Exists) {
using (var stream = configFile.OpenText()) {
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 = config.ExcludedFiles.Select(MakeFileRegex).ToArray();
var overrides = GetOverrides(config.Overrides).ToArray();
var excluded = config.ExcludedFiles.Select(Program.MakeFileRegex).ToArray();
var overrides = Program.GetOverrides(config.Overrides).ToArray();
// load any references to be able to include custom content types as well
foreach (var line in content) {
@ -59,7 +58,7 @@ namespace Contentless {
}
// load content importers
var (importers, processors) = GetContentData();
var (importers, processors) = Program.GetContentData();
Console.WriteLine($"Found possible importer types {string.Join(", ", importers)}");
Console.WriteLine($"Found possible processor types {string.Join(", ", processors)}");
@ -68,7 +67,7 @@ namespace Contentless {
// 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("\\", "/");
var relative = Program.GetRelativePath(contentFile.DirectoryName, file.FullName).Replace("\\", "/");
// is the file in an excluded directory?
if (excluded.Any(e => e.IsMatch(relative))) {
@ -78,7 +77,7 @@ namespace Contentless {
}
// is the file already in the content file?
if (HasEntry(content, relative)) {
if (Program.HasEntry(content, relative)) {
if (config.LogSkipped)
Console.WriteLine($"Skipping file {relative} as it is already part of the content file");
continue;
@ -89,13 +88,13 @@ namespace Contentless {
Dictionary<string, string> processorParams = null;
// override importers
var over = GetOverrideFor(relative, overrides);
var over = Program.GetOverrideFor(relative, overrides);
if (over != null) {
processorParams = over.Override.ProcessorParams;
// copy special case
if (over.Override.Copy) {
CopyFile(content, relative);
Program.CopyFile(content, relative);
changed = true;
continue;
}
@ -118,8 +117,7 @@ namespace Contentless {
}
// normal importers
if (importer == null)
importer = GetImporterFor(relative, importers);
importer ??= Program.GetImporterFor(relative, importers);
if (importer != null && processor == null)
processor = processors.Find(p => p == importer.Importer.DefaultProcessor);
@ -129,7 +127,7 @@ namespace Contentless {
continue;
}
AddFile(content, relative, importer.Type.Name, processor, processorParams);
Program.AddFile(content, relative, importer.Type.Name, processor, processorParams);
changed = true;
}
@ -166,7 +164,7 @@ namespace Contentless {
private static IEnumerable<OverrideInfo> GetOverrides(Dictionary<string, Override> config) {
foreach (var entry in config)
yield return new OverrideInfo(MakeFileRegex(entry.Key), entry.Value);
yield return new OverrideInfo(Program.MakeFileRegex(entry.Key), entry.Value);
}
private static OverrideInfo GetOverrideFor(string file, IEnumerable<OverrideInfo> overrides) {
@ -196,16 +194,13 @@ namespace Contentless {
private static List<string> ReadContent(FileInfo file) {
var content = new List<string>();
using (var stream = file.OpenText()) {
string line;
while ((line = stream.ReadLine()) != null) {
using var stream = file.OpenText();
while (stream.ReadLine() is {} line)
content.Add(line);
}
}
return content;
}
private static void AddFile(List<string> content, string relative, string importer, string processor, Dictionary<string, string> processorParams) {
private static void AddFile(ICollection<string> content, string relative, string importer, string processor, Dictionary<string, string> processorParams) {
content.Add($"#begin {relative}");
content.Add($"/importer:{importer}");
content.Add($"/processor:{processor}");
@ -218,7 +213,7 @@ namespace Contentless {
Console.WriteLine($"Adding file {relative} with importer {importer} and processor {processor}");
}
private static void CopyFile(List<string> content, string relative) {
private static void CopyFile(ICollection<string> content, string relative) {
content.Add($"#begin {relative}");
content.Add($"/copy:{relative}");
content.Add("");
@ -236,4 +231,3 @@ namespace Contentless {
}
}
}

View file

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>