added a try-catch around assembly loading

This commit is contained in:
Ellpeck 2019-12-04 16:08:08 +01:00
parent e8e69dc1cc
commit b79601f318
3 changed files with 22 additions and 29 deletions

View file

@ -2,7 +2,7 @@
<package> <package>
<metadata> <metadata>
<id>Contentless</id> <id>Contentless</id>
<version>2.0.4</version> <version>2.0.5</version>
<authors>Ellpeck</authors> <authors>Ellpeck</authors>
<description>A tool for MonoGame that automatically handles adding assets to the Content Pipeline project</description> <description>A tool for MonoGame that automatically handles adding assets to the Content Pipeline project</description>
<tags>monogame mono xna content pipeline mgcb builder tool library</tags> <tags>monogame mono xna content pipeline mgcb builder tool library</tags>

View file

@ -59,10 +59,9 @@ namespace Contentless {
} }
// load content importers // load content importers
var importers = GetContentImporters().ToArray(); var (importers, processors) = GetContentData();
Console.WriteLine($"Found possible importer types {string.Join(", ", importers.AsEnumerable())}"); Console.WriteLine($"Found possible importer types {string.Join(", ", importers)}");
var processors = GetContentProcessors().ToArray(); Console.WriteLine($"Found possible processor types {string.Join(", ", processors)}");
Console.WriteLine($"Found possible processor types {string.Join(", ", processors.AsEnumerable())}");
var changed = false; var changed = false;
foreach (var file in contentFile.Directory.EnumerateFiles("*", SearchOption.AllDirectories)) { foreach (var file in contentFile.Directory.EnumerateFiles("*", SearchOption.AllDirectories)) {
@ -98,14 +97,14 @@ namespace Contentless {
continue; continue;
} }
importer = Array.Find(importers, i => i.Type.Name == over.Importer); importer = importers.Find(i => i.Type.Name == over.Importer);
if (importer == null) { if (importer == null) {
Console.WriteLine($"Override importer {over.Importer} not found for file {relative}"); Console.WriteLine($"Override importer {over.Importer} not found for file {relative}");
continue; continue;
} }
if (over.Processor != null) { if (over.Processor != null) {
processor = Array.Find(processors, p => p == over.Processor); processor = processors.Find(p => p == over.Processor);
if (processor == null) { if (processor == null) {
Console.WriteLine($"Override processor {over.Processor} not found for file {relative}"); Console.WriteLine($"Override processor {over.Processor} not found for file {relative}");
continue; continue;
@ -117,7 +116,7 @@ namespace Contentless {
if (importer == null) if (importer == null)
importer = GetImporterFor(relative, importers); importer = GetImporterFor(relative, importers);
if (importer != null && processor == null) if (importer != null && processor == null)
processor = Array.Find(processors, p => p == importer.Importer.DefaultProcessor); processor = processors.Find(p => p == importer.Importer.DefaultProcessor);
// no importer found :( // no importer found :(
if (importer == null || processor == null) { if (importer == null || processor == null) {
@ -140,24 +139,24 @@ namespace Contentless {
Console.Write("Done"); Console.Write("Done");
} }
private static IEnumerable<ImporterInfo> GetContentImporters() { private static (List<ImporterInfo>, List<string>) GetContentData() {
var importers = new List<ImporterInfo>();
var processors = new List<string>();
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) {
foreach (var type in assembly.GetExportedTypes()) { try {
var importer = (ContentImporterAttribute) type.GetCustomAttribute(typeof(ContentImporterAttribute), true); foreach (var type in assembly.GetExportedTypes()) {
if (importer != null) var importer = (ContentImporterAttribute) type.GetCustomAttribute(typeof(ContentImporterAttribute), true);
yield return new ImporterInfo(importer, type); if (importer != null)
} importers.Add(new ImporterInfo(importer, type));
} var processor = type.GetCustomAttribute(typeof(ContentProcessorAttribute), true);
} if (processor != null)
processors.Add(type.Name);
private static IEnumerable<string> GetContentProcessors() { }
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) { } catch (Exception) {
foreach (var type in assembly.GetExportedTypes()) { // ignored
var processor = type.GetCustomAttribute(typeof(ContentProcessorAttribute), true);
if (processor != null)
yield return type.Name;
} }
} }
return (importers, processors);
} }
private static IEnumerable<OverrideInfo> GetOverrides(Dictionary<string, JToken> config) { private static IEnumerable<OverrideInfo> GetOverrides(Dictionary<string, JToken> config) {
@ -241,5 +240,4 @@ namespace Contentless {
} }
} }
} }

View file

@ -51,8 +51,3 @@
/processor:TiledMapTilesetProcessor /processor:TiledMapTilesetProcessor
/build:Tiled/Tileset.tsx /build:Tiled/Tileset.tsx
#begin Textures/Exclude.png
/importer:TextureImporter
/processor:TextureProcessor
/build:Textures/Exclude.png