예제 #1
0
 private static IProcessor FindDefaultProcessor(IImporter importer)
 {
     if (importer == null)
     {
         return(null);
     }
     return(FindProcessor(importer.GetType().GetCustomAttributes(false).OfType <ContentImporterAttribute>().First().DefaultProcessor));
 }
예제 #2
0
        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;
            }
        }
예제 #3
0
 private static bool ImporterCompatibleWithFile(IImporter importer, string sourceAssetFile)
 {
     return(importer.GetType().GetCustomAttributes(false)
            .OfType <ContentImporterAttribute>().First()
            .FileExtensions.Any(ext => FileExtensionEquals(ext, Path.GetExtension(sourceAssetFile))));
 }