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

View file

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

View file

@ -12,13 +12,13 @@
<icon>Logo.png</icon> <icon>Logo.png</icon>
<version>3.0.6</version> <version>3.0.6</version>
<dependencies> <dependencies>
<group targetFramework="net5.0" /> <group targetFramework="net6.0" />
</dependencies> </dependencies>
</metadata> </metadata>
<files> <files>
<file src="_._" target="lib/net5.0/"/> <file src="_._" target="lib/net6.0/" />
<file src="Contentless.targets" target="build/Contentless.targets" /> <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="../README.md" target="" />
<file src="../Logo.png" target="" /> <file src="../Logo.png" target="" />
</files> </files>

View file

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

View file

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

View file

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

View file

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