Jump to content

GuardedStream


Recommended Posts

I was running my File Type plugin on a recent version of Paint.net and it wasn't working because the "ouput" param to OnSave() changed from type FileStream to GuardedStream (declared argument type is just Stream). For most of my code this is just fine, because there were no assumptions about it being a FileStream. But in particular there was one aspect that depended on FileStream.Name. My plugin takes all the layers of the PDN file and outputs them as separate files, while the primary export is a XML index file that contains metadata about those layers. It uses FileStream.Name to make sure that the exported layer files get put in the same place and with the same naming convention that was specified. Without that I don't know what else to do except use fixed paths (which is definitely undesirable and negates a lot of the value of the plugin).

Is there a way to at least get the path that the file is meant to be saved to? I couldn't find any info here on GuardedStream.

Link to comment
Share on other sites

You cannot assume that the Stream will be a FileStream. FileType plugins are only supposed to write data into the provided stream, and never anywhere else. It's not possible to do what you want without cheating and using Reflection, at which point you may not publish your plugin to the forum here. If that's not a concern, and you're just doing this for your own personal use, then use reflection to get at the private "source" field (of type Stream) in GuardedStream.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

Thanks for the fast response!

My plugin is just for personal use, so I'm not above using Reflection to just get unblocked. I'm a huge fan of paint.net, and because of that I've been using it as part of my asset tool chain. My plugin isn't really in its current state generally useful to people (since I imagine the exported xml file and modifications to the layers aren't what most people are looking for). Anyway, grabbing the private field with Reflection works, although it appears the behavior's different in that FileTime.Name is always reporting "[unknown]". Oh well, I can correct this with a script that runs after the plugin export.

Let me know if you have a better idea of how to export PDN layers into individual files. I had always figured a plugin would be more managable than trying to figure out the PDN file format.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...