public static T Load <T>(this IContentImporter loader, string fileName, IServiceProvider serviceProvider) where T : class
 {
     using (var stream = File.OpenRead(fileName))
     {
         return(loader.Import(stream, serviceProvider) as T);
     }
 }
Esempio n. 2
0
        public ContentItem LoadContentItem(string filename,
                                           IContentImporter importer              = null,
                                           IContentProcessor processor            = null,
                                           Dictionary <string, object> opaqueData = null)
        {
            if (opaqueData == null)
            {
                opaqueData = new Dictionary <string, object>();
            }
            if (importer == null)
            {
                importer = CreateImporter(FindImporterByExtension(Path.GetExtension(filename)), opaqueData);
            }
            if (processor == null)
            {
                processor = CreateProcessor(FindDefaultProcessor(importer.GetType()), opaqueData);
            }

            object item;

            using (FileStream stream = File.OpenRead(filename))
            {
                item = importer.Import(stream, this);
            }
            _processorContext.PushDirectory(Path.GetDirectoryName(filename));
            item = processor.Process(item, _processorContext);
            _processorContext.PopDirectory();

            return((ContentItem)item);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            log4net.Config.BasicConfigurator.Configure(new log4net.Appender.DebugAppender());

            _opaqueData["TextureType"] = TextureType.Texture2D;
            if (!ParseCommandLine(args))
            {
                return;
            }

            if (string.IsNullOrEmpty(_outputName))
            {
                _outputName = string.Format("{0}.meb", Path.GetFileNameWithoutExtension(_imageName));
            }



            //GetTypeWriters();
            ProcessAssemblies();

            string ext = Path.GetExtension(_imageName).ToLower();
            var    imp = _importers.FirstOrDefault(i => i.attribue.FileExtensions.Contains(ext));

            if (imp.type == null)
            {
                Console.WriteLine("file format is not handled by TextureImporter.");
                return;
            }

            ContentManager           manager = new ContentManager(_log);
            ContentTypeWriterManager contentTypeWriterManager = new ContentTypeWriterManager();

            contentTypeWriterManager.RegisterTypeWriter <Texture2DContent>(new Texture2DWriter());

            IContentImporter importer = CreateImporter(imp.type, _opaqueData);

            var content = importer.Import(_imageName, manager);

            IContentProcessor processor = CreateProcessor(FindDefaultProcessor(importer.GetType()), _opaqueData);

            object processedContent = processor.Process(content, new ContentProcessorContext());

            ContentTypeWriter typeWriter = GetTypeWriter(processedContent.GetType());

            using (FileStream stream = new FileStream(_outputName, FileMode.OpenOrCreate))
            {
                ContentWriter writer = manager.CreateWriter(contentTypeWriterManager, stream);
                writer.WriteObject(processedContent, typeWriter);
                writer.Flush();
            }
        }
Esempio n. 4
0
        public override bool Execute()
        {
            Log.LogMessage("Building content:");

            XBuildLogger    logger   = new XBuildLogger(this.Log);
            ContentCompiler compiler = new ContentCompiler(PipelineAssemblies);

            foreach (ITaskItem sourceItem in SourceAssets)
            {
                //foreach (string name in sourceItem.MetadataNames)
                //	Log.LogMessage(name + " : " + sourceItem.GetMetadata(name));
                string assetName = sourceItem.GetMetadata("Name");

                Log.LogMessage("Building " + assetName);

                Stream        outputStream  = new FileStream(OutputDirectory + assetName + ".xnb", FileMode.OpenOrCreate);
                ContentWriter contentWriter = new ContentWriter(outputStream, getTargetPlatform(), CompressContent);

                string importerName  = sourceItem.GetMetadata("Importer");
                string processorName = sourceItem.GetMetadata("Processor");

                IContentImporter importer = getImporterInstance(importerName);
                if (importer == null)
                {
                    Log.LogError("Could not find the importer (" + importerName + ")");
                }

                IContentProcessor processor = getProcessorInstance(processorName);
                if (importer == null)
                {
                    Log.LogError("Could not find the processor (" + processorName + ")");
                }

                Log.LogMessage("Using " + importerName + " and " + processorName);

                ContentImporterContext  importerContext  = new ContentImporterContext(this, IntermediateDirectory, OutputDirectory, logger);
                ContentProcessorContext processorContext = new ContentProcessorContext();

                processor.Process(importer.Import(sourceItem.GetMetadata("Include"), importerContext), processorContext);
            }

            return(true);
        }
 public static T Load <T>(this IContentImporter loader, Stream stream, IServiceProvider serviceProvider) where T : class
 {
     return(loader.Import(stream, serviceProvider) as T);
 }