-
Notifications
You must be signed in to change notification settings - Fork 60
Kore
Namespace: Kore
Adapter/Plugin: Those are synonymous and refer to the same instance of an object that manages a specific file type.
Kore is a main library for a user interface to manage files and file relevant actions. This way a UI doesn't need to manage loading plugins, file formats and any action not specific to the UI itself.
This library is dependant on Kontract.
There are 2 constructors for Kore. One that just creates an instance of Kore and one that also takes in another plugin directory. By default the plugin directoy is "plugins" in the same folder as the executable.
var kore = new Kore("otherPluginFolder"); //now all plugins get read from the folder "otherPluginFolder"
This returns a list of KoreFileInfos that were opened using LoadFile.
If no file was loaded yet, an empty List is returned.
This returns an already concatted string of all file extensions found in the loaded plugins. It's mainly meant to be used in OpenFileDialogs to populate its filter property.
The returned string can be directly used in the extension filter of OpenFileDialog.
It contains an entry "All Supported Files" to select all files with the extension a plugin is written for.
And the well-known "All Files" entry that just selects every file with .
The syntax of the returned string looks like this, if 2 plugins with ext1 and ext2 were found:
All Supported Files (*.ext1;*.ext2)|*.ext1;*.ext2|Plugin 1 (*.ext1)|*.ext1|Plugin 2 (*.ext2)|*.ext2|All Files (*.*)|*.*
This method takes in a file name, to load the file with a specific plugin. It returns an initialized KoreFileInfo or null, if no plugin could open the file.
It can also optionally take in a boolean to tell Kore that it should track the file. By default it's true and will be used in the future by a feature not finished yet.
For a plugin to load a file, it needs to inherit at least from ILoadFiles.
Notice that there is an event IdentificationFailed which gets executed, if no plugin could distinctly identify the given file. That means if all plugins that inherit from IIdentifyFiles returned false, the event is executed.
This method takes in a KoreFileInfo and optionally a filename to save the file to. If saved successfully, the KoreFileInfo gets updated accordingly.
For a plugin to save a file, it needs to inherit at least from ISaveFiles.
This method takes in a KoreFileInfo. It returns a boolean, indicating if closing the file was successful.
The Adapter of KoreFileInfo will get disposed and the KoreFileInfo itself removed from OpenFiles.
For a plugin to close a file, it needs to inherit at least from ICloseFiles.
This method will return a partly FileFilters, depending on the given interface type.
It has to be an interface type from Kontract.
Optionally it can take in a name for the "All Supported Formats"-filter, and a boolean to determine if the "All Files"-filter should be included.
This method returns a concatted string with the same syntax as in FileFilters.
Example:
var kore = new Kore.Kore();
var loadfilters = kore.FileFiltersByType<ILoadFiles>();
//this will return a concatted string only containing the filters for plugins that are able to load files
This method returns an IEnumerable containing all extensions in the format ".ext", depending on the given interface type.
It has to be an interface type from Kontract.
Example:
var kore = new Kore.Kore();
var loadfilters = kore.FileExtensionsByType<ILoadFiles>();
//this will return an IEnumerable<string> only containing the extensions for plugins that are able to load files
Since Kore inherits from IDisposable, it can be disposed either by calling Dispose manually or by being used in a using directive.
All files tracked by Kore with OpenFiles get closed with CloseFile.
This event is toggled when LoadFile couldn't distinctly identify a given file with the loaded adapters.
A UI can use this event to retrieve a list of adapters that don't inherit from IIdentifyFiles and for example give the user the possibility to choose one of those "blind" adapters on their own behalf.
When toggled, the UI retrieves an object IdentificationFailedEventArgs
, which contains a List<ILoadFiles> representing said blind adapters and a property SelectedAdapter
from type ILoadFiles that ultimately contains the selected adapter by the user.
Example:
static void Main(string[] args)
{
var kore = new Kore.Kore();
kore.IdentificationFailed +=
var kfi = kore.LoadFile("test_file.bin");
}
static void On_IdentificationFailed(object sender, IdentificationFailedEventArgs args)
{
var blinds = args.BlindAdapters;
//do something with those blind adapters
args.SelectedAdapter = blinds.ElementAt(0); //or anything else to set an adapter inheriting from ILoadFiles here
}
This class holds information about one file opened by Kore. It inherits from the System.ComponentModel.INotifyPropertyChanged, which describes an event to notify if a property was changed.
KoreFileInfo contains a plain System.IO.FileInfo without any changes, from the file it's loaded for.
KoreFileInfo contains an adapter with type ILoadFiles which was used to load this file. It can be cast to any other interface from Kontract to access other functionality specific to text, images, archives, etc.
Declares if there are changes made to KoreFileInfo. It has to be set manually and toggles the PropertyChanged event for HasChanges and DisplayName
Gets the filter from the adapter.
Gets the extension from the adapter.
Gets the name of the file and if HasChanges is true, it also has a "*" attached.
static void Main(string[] args)
{
//initialize the Kore object
var kore = new Kore.Kore();
//load the file testfile.bin
var kfi = kore.LoadFile("testfile.bin");
if (kfi == null)
throw new Exception("File couldn't be loaded");
//cast the KoreFileInfo adapter to an image adapter to make image specific changes
var imageAdapter = kfi.Adapter as IImageAdapter;
//add a new image to the image list
imageAdapter.Bitmaps.Add(new Bitmap());
//saves the file opened in kfi to new_testfile.bin
kore.SaveFile(kfi, "new_testfile.bin");
//Closes and disposes the opened file again
kore.CloseFile(kfi);
}