private static IProcessor FindDefaultProcessor(IImporter importer) { if (importer == null) { return(null); } return(FindProcessor(importer.GetType().GetCustomAttributes(false).OfType <ContentImporterAttribute>().First().DefaultProcessor)); }
public TContent BuildAndLoad <TContent>(string sourceAssetFile, IImporter contentImporter, IProcessor contentProcessor, string fileName) { try { OutputFilename = FindNextValidAssetName(fileName ?? Path.GetFileNameWithoutExtension(sourceAssetFile), ".xnb"); var outputDirectory = Path.GetDirectoryName(OutputFilename); if (!Directory.Exists(outputDirectory)) { Directory.CreateDirectory(outputDirectory); } // Create a dummy file in case a nested build uses the same name File.WriteAllText(OutputFilename, ""); contentImporter = contentImporter ?? FindImporter(null, sourceAssetFile); if (contentImporter == null) { throw new InvalidOperationException(string.Format("Cannot find content importer for {0}", sourceAssetFile)); } contentProcessor = contentProcessor ?? FindDefaultProcessor(contentImporter); Trace.TraceInformation("Building {0} -> {1} with {2} and {3}", sourceAssetFile, OutputFilename, contentImporter != null ? contentImporter.GetType().Name : "<No Importer>", contentProcessor != null ? contentProcessor.GetType().Name : "<No Processor>"); object content = contentImporter.Import(sourceAssetFile, ImporterContext); if (contentProcessor != null) { content = contentProcessor.Process(content, ProcessorContext); } return((TContent)content); } catch (Exception e) { Trace.TraceError("Error importing {0} with asset name {1}", sourceAssetFile, fileName ?? "[Unspecified]"); Trace.WriteLine(e); throw; } }
private static bool ImporterCompatibleWithFile(IImporter importer, string sourceAssetFile) { return(importer.GetType().GetCustomAttributes(false) .OfType <ContentImporterAttribute>().First() .FileExtensions.Any(ext => FileExtensionEquals(ext, Path.GetExtension(sourceAssetFile)))); }