-
Notifications
You must be signed in to change notification settings - Fork 60
Plugins
Kuriimu2 utilizes DLLs as plugins to extend its file format support.
Those DLLs are written in C# and loaded at runtime using MEF (Microsoft Extensibility Framework). MEF reduces the code required to load dlls at runtime, making it much easier to load them. Additionally it allows loading metadata for a plugin, instead of initializing it, which makes it faster to get metadata and more memory efficient. To make use of MEFs capabilities in code, one must first reference the System.CompositionModel assembly.
The first type of plugin is the widely used file-based one. It's a plugin that loads a given file and interprets it into a more general and/or readable structure for either the UI or other programs.
Coding a basic file plugin for Kuriimu2 is just combining different interfaces depending on its needs.
----> Do your edits here Icy <-----
---> And erase this block if not needed <--- Optionally one can inherit from ISaveFiles to enable save capability and IIdentifyFiles to enable pre-load identification of a file.
If a file is not identifiable (since it doesn't inherit from IIdentifyFiles), this plugin will be marked as blind. It will later be listed in the event arguments of IdentificationFailed.
To make use of Kuriimu2s UIs you should also inherit from one of the file type interfaces (text, image, archive, etc.)
To expose the used interface types to Kore and therefore Kuriimu2s UIs, one has to "Export" them with the Export attribute given by System.CompositionModel. If one doesn't do that, but the class itself inherits from the interface, it will still be ignored by Kore.
Information about PluginExtensionInfo and PluginInfo can be found here.
Example:
using System.CompositionModel;
[Export(typeof(IIdentifyFiles))] //exporting IIdentifyFiles, so Kore recognizes this plugin as identifiable
[Export(typeof(ILoadFiles))] //exporting ILoadFiles, so Kore recognizes this plugin as loadable
//without exporting IImageAdapter, Kore won't know that this plugin is actually an image plugin
//and therefore Kuriimu2 won't be able to read its images and doesn't load them into the UI
[PluginExtensionInfo("*.ext")]
[PluginInfo("11111-1111-111", "PluginName", "ShortName", "Author", "Website", "Description")]
public class Plugin : IIdentifyFiles, ILoadFiles, IImageAdapter
{
public IList<BitmapInfo> BitmapInfos { get; }
public void Dispose()
{
//every interface from Kontract inherits from IDisposable and therefore each plugin instance is disposable
}
public bool Identify(string filename)
{
//here the file gets read, to identify it and to check if this plugin can handle it
//not inheriting from IIdentifyFiles marks this plugin as blind
}
public void Load(string filename)
{
//here the file gets read and loaded into whatever type interface a dev chose
//Or they do their own thing with own interfaces this plugin inherits from
}
}