Skip to content
realonepiecefreak edited this page Jun 29, 2020 · 6 revisions

Kore

Namespace: Kore

  1. Description
  2. PluginManager
  3. StateInfo

Description

Kore is the main library for a user interface (UI) 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.

PluginManager

The PluginManager is the core component of Kore and any UI. It loads the plugins and uses them to load and save files passed to it in various ways.

Constructors

There is one constructor for the PluginManager. It takes an IProgressOutput and a list of plugin directories relative to the applications location.

var progressOutput = new ConcurrentProgress(new NullProgressOutput());
var pluginManager = new PluginManager(progressOutput, "plugins");

Load Files

The plugin manager can load files from various sources. Be it from a hard drive, another archive plugin, or any other sort of IFileSystem.

The method will first try to automatically identify the plugin to use for the given file. It takes all plugins that implement IIdentifyFiles and call there IdentifyAsync method. The first plugin to return true will be used.

If no plugin can identify the file, the method takes all plugins not implementing IIdentifyFiles and prepare a manual selection for the user to choose from.

It will return a LoadResult, so it can first be checked if the load process was successful. If it was not successful it will contain a human readable message and potentially the exception that was thrown.

If it was successful, a fully loaded IStateInfo is returned as well.

Load a file from a given path to your hard drive:

var loadResult = await pluginManager.LoadFile("path_to_a_file");
if(!loadResult.IsSuccessful)
    ; // Print error message from loadResult.Message or loadResult.Exception

var loadedStateInfo = loadResult.LoadedState;

Load a file from a loaded archive plugin:

IStateInfo loadedArchive;
ArchiveFileInfo fileFromLoadedArchive;

[...]

var loadResult = await pluginManager.LoadFile(loadedArchive, fileFromLoadedArchive);
if(!loadResult.IsSuccessful)
    ; // Print error message from loadResult.Message or loadResult.Exception

var loadedStateInfo = loadResult.LoadedState;

Load a file from any given IFileSystem:

IFileSystem fileSystem;

[...]

var loadResult = await pluginManager.LoadFile(fileSystem, "path_into_file_system");
if(!loadResult.IsSuccessful)
    ; // Print error message from loadResult.Message or loadResult.Exception

var loadedStateInfo = loadResult.LoadedState;

Manual Selection

The plugin manager has the possibility of passing the plugin selection to the user if no plugin could definitely identify the given file. This selection can be disabled by setting AllowManualSelection to false.

To make use of the manual selection you have to add a method to the event OnManualSelection. This event passes an IReadOnlyList<IFilePlugin>, which contains plugins that do not implement IIdentifyFiles. The chosen IFilePlugin may be set into the Result property of the event arguments.

Save Files

The plugin manager can save changes to already loaded files. The changes get saved either to the original location the file was opened from, or to a newly given location.

It only saves a loaded state if it has changes to save. If the loaded state has open states itself (for example, if it is an archive state), those will be saved as well.

After a successful save process, the file will automatically be reloaded into the state by using LoadFiles.

It will return a SaveResult, so it can first be checked if the save process was successful. If it was not successful it will contain a human readable message and potentially the exception that was thrown.

Save a loaded file in its original location:

IStateInfo loadedState;

pluginManager.SaveFile(loadedState);

Save a loaded file in a new location on the hard drive:

IStateInfo loadedState;

pluginManager.SaveFile(loadedState, "new_location");

Save a loaded file into any IFileSystem:

IStateInfo loadedState;
IFileSystem fileSystem;

pluginManager.SaveFile(loadedState, fileSystem, "path_into_file_system");

Close Files

The plugin manager can close already loaded files. This method releases all related ressources and states to this file and the plugin used.

Close a loaded file:

IStateInfo loadedState;

pluginManager.CloseFile(loadedState);

Close all loaded files:

pluginManager.CloseAll();

StateInfo

The StateInfo represents one loaded file in the plugin manager. It contains all necessary instances of objects to properly manage and release ressources regarding the file and its plugin used.

A loaded StateInfo can be retrieved by invoking LoadFiles from the plugin manager.

FilePath and AbsoluteDirectory

Both properties give path information about the loaded file.

FilePath is the relative path of the file in the given IFileSystem. AbsoluteDirectory is the absolute path of the file. It represents the path of the file through every parent state to the root on the hard drive.

PluginManager

Contains an instance of IPluginManager. It represents the portion of loaded files, which are loaded by the plugin itself and not the UI. It has limited access to functionalities of the main plugin manager.

It can only load files from a given IFileSystem and only save them in their original location.

State

This is the loaded State class from the plugin DLL.

This instance is meant to interact with the plugin itself and its capabilities.

FileSystem

The IFileSystem from which the file is loaded. It has all the capabilities described for file systems down below.

StreamManager

An instance of IStreamManager to manage all streams opened by the plugin.

A plugin may generally avoid opening Streams that are not located purely in memory. The plugin manager will open or close all streams for necessary file operations via IStreamManager.

ArchiveChildren

If the loaded state is an IArchiveState, the plugin manager can open the files from this archive as well. If that is the case, the loaded states from those files are added to this property.

If the state is closed, all ArchiveChildren will be closed first.

ParentStateInfo

Contains the StateInfo the current StateInfo was loaded from.

It's only set, if the file was loaded either from an IArchiveState or from within a plugin.

ContentChanged

A boolean property that indicates if any information in the loaded file was changed. The SaveFile operation only executes if this property is set to true.