Jump to content

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

My batch Image Processor: https://imagenator.codeplex.com

Link to comment
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.

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

bp-sig.png
My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

Link to comment
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

PdnSig.png

Plugin Pack | PSFilterPdn | Content Aware Fill | G'MICPaint Shop Pro Filetype | RAW Filetype | WebP Filetype

The small increase in performance you get coding in C++ over C# is hardly enough to offset the headache of coding in the C++ language. ~BoltBait

 

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...