Sign in to follow this  
ArgusMagnus

Basic FileType plugin guidance

Recommended Posts

Is there a Basic documentation/how to for writing FileType plugins?

I've tried with the help of examples found online and based on the source of plugins like TinyPNG, but I cannot get PDN to Show me my plugin when I click "Save as...".

 

This is what I have so far, any help would be appreciated. (It's a save-only plugin):

 

public sealed class TestFileType : FileType, IFileTypeFactory
    {
        TestFileType()
            : base("Test", FileTypeFlags.SupportsSaving | FileTypeFlags.SavesWithProgress, new[] { ".test" }) { }

        protected override Document OnLoad(Stream input)
        {
            return null;
        }

        protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface surface, ProgressEventHandler callback)
        {
            // Do save operation...

            base.OnSave(input, output, token, surface, callback);
        }

        FileType[] IFileTypeFactory.GetFileTypeInstances()
        {
            return new[] { new TestFileType() };
        }
    }

 

Edited by ArgusMagnus

Share this post


Link to post
Share on other sites
3 minutes ago, ArgusMagnus said:

public sealed class TestFileType : FileType, IFileTypeFactory

 

I may be mistaken, but I believe your filetype class should not be inheriting from both FileType & IFileTypeFactory. You need to create a class for both of them.

Share this post


Link to post
Share on other sites
15 minutes ago, toe_head2001 said:

I may be mistaken, but I believe your filetype class should not be inheriting from both FileType & IFileTypeFactory. You need to create a class for both of them.

 

Inheriting from both FileType & IFileTypeFactory is fine, my WebP FileType does that for instance.

The problem is that @ArgusMagnus is missing the public modifier on the constructor.

 

public sealed class TestFileType : FileType, IFileTypeFactory
    {
        public TestFileType()
            : base("Test", FileTypeFlags.SupportsSaving | FileTypeFlags.SavesWithProgress, new[] { ".test" }) { }

        protected override Document OnLoad(Stream input)
        {
            return null;
        }

        protected override void OnSave(Document input, Stream output, SaveConfigToken token, Surface surface, ProgressEventHandler callback)
        {
            // Do save operation...

            base.OnSave(input, output, token, surface, callback);
        }

        FileType[] IFileTypeFactory.GetFileTypeInstances()
        {
            return new[] { new TestFileType() };
        }
    }

 

  • Upvote 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this