XNA Creators Club Online
Page 1 of 1 (4 items)
Sort Posts: Previous Next

How to get filename from within ContentProcessor?

Last post 04-23-2008 12:20 PM by mtnPhil. 3 replies.
  • 04-23-2008 4:17 AM

    How to get filename from within ContentProcessor?

    I found this thread which asks the same question

    http://forums.xna.com/thread/15127.aspx

    but the response makes no sense to me.  There is no NodeContent in my Process method.  Was that for XNA 1.0 or something?

    I need to pass a ContentIdentity to an ExternalReference constructor, but I have no idea where to get it.  The only 'context' I have in my processor is ContentProcessorContext, and there doesn't seem to be any property in there that will help me.

  • 04-23-2008 8:54 AM In reply to

    Re: How to get filename from within ContentProcessor?

    You simply create your own ContentIdenty, e.g. ContentIdentity identity = new ContentIdentity("path/to/file", "Phils Content Processor");
    We are boki. The rest is known.
    The not so known part of the rest: It is Björn or Bjoern, but never Bjorn.
    Vote: Allow use of non-ASCII characters in names and titles
  • 04-23-2008 10:51 AM In reply to

    Re: How to get filename from within ContentProcessor?

    All of the standard importers output types that are derived from ContentItem. ContentItem has an Identity property which is of type ContentIdentity. So, if your processor accepts one of these types as input, then you have access to the identity information. If you are using a custom importer, then you should derive the importer's output type from ContentItem and populate the members apporpriately in the importer. Alternatively, if all you need is the filename, you can add that as a property in your importer's output type and populate it in the importer.

    Basically, the only way to get the filename in your processor is for your importer to store that information in the class passed to the processor.

     

  • 04-23-2008 12:20 PM In reply to

    Re: How to get filename from within ContentProcessor?

    Thanks David, that works - I had to write a custom importer which sets the name and just invokes the XmlImporter.

    Now the next hurdle I have is the following:

    I have a Foo class.

    I have an editor application for Foos that writes out Foos into xml using the IntermediateSerializer.

    Up until just now, I was using a Foo object everywhere, but now I have added a corresponding FooContent for the content pipeline, because it became obvious that was the cleaner way to go (my Foo class started being polluted by content pipeline things).  They have mostly the same properties, at least in term of what my editor application puts into the XML file.  But the intermediate serializer puts

    <Asset Type="MyNamespace.Foo">

    in the XML file.

    In my importer, I want to read in a FooContent.

    But I don't want to have to write a tedious function to convert a Foo -> FooContent.  Since they have similar properties, it should be possible to just swap the Asset Type in the XML to FooContent and deserialize that.

    Is there a good way to do that?  i.e. can I override what gets written to the Asset type either

    1) in the XmlImporter in my importer, or

    2) when I serialize with IntermediateSerializer?

    Basically I want my editor application to write out a Foo, and my content pipeline importer to read in a FooContent.

Page 1 of 1 (4 items) Previous Next