/// <summary> /// Represents an open file in the runtime of Kuriimu. /// </summary> /// <param name="filePlugin">The entry class of the plugin for this file.</param> /// <param name="pluginState">The plugin state of this file.</param> /// <param name="parentState">The parent state for this file.</param> /// <param name="fileSystem">The file system around the initially opened file.</param> /// <param name="filePath">The path of the file to be opened in the file system.</param> /// <param name="streamManager">The stream manager used for this opened state.</param> /// <param name="pluginManager">The plugin manager for this state.</param> public StateInfo(IFilePlugin filePlugin, IPluginState pluginState, IStateInfo parentState, IFileSystem fileSystem, UPath filePath, IStreamManager streamManager, IPluginManager pluginManager) { ContractAssertions.IsNotNull(filePlugin, nameof(filePlugin)); ContractAssertions.IsNotNull(pluginState, nameof(pluginState)); ContractAssertions.IsNotNull(fileSystem, nameof(fileSystem)); ContractAssertions.IsNotNull(streamManager, nameof(streamManager)); ContractAssertions.IsNotNull(pluginManager, nameof(pluginManager)); if (filePath == UPath.Empty || filePath.IsDirectory) { throw new InvalidOperationException($"'{filePath}' has to be a path to a file."); } if (!fileSystem.FileExists(filePath)) { throw FileSystemExceptionHelper.NewFileNotFoundException(filePath); } FilePlugin = filePlugin; PluginState = pluginState; FilePath = filePath; FileSystem = fileSystem; StreamManager = streamManager; PluginManager = pluginManager; ParentStateInfo = parentState; ArchiveChildren = new List <IStateInfo>(); }
public PhysicalLoadInfo(UPath filePath, IFilePlugin plugin) : this(filePath) { ContractAssertions.IsNotNull(plugin, nameof(plugin)); Plugin = plugin; }
public VirtualLoadInfo(IFileState parentFileState, IArchiveState archiveState, ArchiveFileInfo afi, IFilePlugin plugin) : this(parentFileState, archiveState, afi) { ContractAssertions.IsNotNull(plugin, nameof(plugin)); Plugin = plugin; }
public PluginLoadInfo(IFileSystem fileSystem, UPath filePath, IFilePlugin plugin) : this(fileSystem, filePath) { ContractAssertions.IsNotNull(plugin, nameof(plugin)); Plugin = plugin; }
private void pluginList_SelectedIndexChanged(object sender, EventArgs e) { if (pluginList.SelectedItems.Count <= 0) { return; } SelectedFilePlugin = (IFilePlugin)pluginList.SelectedItems[0].Tag; okBtn.Enabled = true; }
private async Task <LoadResult> LoadFile(Func <IStreamManager, IFileSystem> fileSystemAction, UPath path, IStateInfo parentStateInfo, Guid pluginId, LoadFileContext loadFileContext) { // 1. Create stream manager var streamManager = _streamMonitor.CreateStreamManager(); // 2. Create file system var fileSystem = fileSystemAction(streamManager); // 3. Find plugin IFilePlugin plugin = null; if (pluginId != Guid.Empty) { plugin = _filePluginLoaders.Select(pl => pl.GetPlugin(pluginId)).First(); } var progress = loadFileContext.Progress ?? _progress; var isRunning = progress.IsRunning(); if (!isRunning) { progress.StartProgress(); } // 4. Load file var loadResult = await _fileLoader.LoadAsync(fileSystem, path, new LoadInfo { ParentStateInfo = parentStateInfo, StreamManager = streamManager, PluginManager = this, Plugin = plugin, Progress = progress, DialogManager = new InternalDialogManager(_dialogManager, loadFileContext.Options), AllowManualSelection = AllowManualSelection }); if (!isRunning) { progress.FinishProgress(); } if (!loadResult.IsSuccessful) { return(loadResult); } // 5. Add file to loaded files lock (_loadedFilesLock) { _loadedFiles.Add(loadResult.LoadedState); } return(loadResult); }
private ListViewItem CreateListItem(IFilePlugin plugin) { var item = new ListViewItem(plugin.Metadata?.Name ?? "<undefined>") { Tag = plugin }; item.SubItems.Add(plugin.PluginType.ToString()); item.SubItems.Add(plugin.PluginId.ToString("D")); return(item); }
// TODO: Rethink creation process public IStateInfo Create(IFilePlugin entryPoint, IPluginManager pluginManager) { // 1. Create new state of the plugin var createdPlugin = entryPoint.CreatePluginState(pluginManager); // 2. Create empty file state if (!TryCreateState(createdPlugin)) { // TODO: Handle errors return(null); } return(null); }
/// <summary> /// Try to create a new plugin state. /// </summary> /// <param name="plugin">The plugin from which to create a new state.</param> /// <param name="pluginManager">The plugin manager to pass to the state creation.</param> /// <param name="pluginState">The created state.</param> /// <returns>If the creation was successful.</returns> private LoadResult TryCreateState(IFilePlugin plugin, IPluginManager pluginManager, out IPluginState pluginState) { pluginState = null; try { pluginState = plugin.CreatePluginState(pluginManager); } catch (Exception e) { return(new LoadResult(e)); } return(new LoadResult(true)); }
/// <summary> /// Try to create a new plugin state. /// </summary> /// <param name="plugin">The plugin from which to create a new state.</param> /// <param name="pluginManager">The plugin manager to pass to the state creation.</param> /// <param name="pluginState">The created state.</param> /// <param name="loadInfo">The load info for this loading operation.</param> /// <returns>If the creation was successful.</returns> private LoadResult TryCreateState(IFilePlugin plugin, IPluginManager pluginManager, LoadInfo loadInfo, out IPluginState pluginState) { pluginState = null; try { pluginState = plugin.CreatePluginState(pluginManager); } catch (Exception e) { loadInfo.Logger?.Fatal(e, "The plugin state for '{0}' could not be initialized.", plugin.PluginId); return(new LoadResult(e)); } return(new LoadResult(true)); }
public ChoosePluginElement(IFilePlugin plugin) { ContractAssertions.IsNotNull(plugin, nameof(plugin)); Plugin = plugin; }
/// <summary> /// Try to load the state for the plugin. /// </summary> /// <param name="pluginState">The plugin state to load.</param> /// <param name="fileSystem">The file system to retrieve further files from.</param> /// <param name="filePath">The path of the identified file.</param> /// <param name="loadContext">The load context.</param> /// <param name="loadInfo">The load info for this loading operation.</param> /// <param name="plugin">The plugin from which the state should be loaded.</param> /// <returns>If the loading was successful.</returns> private async Task <LoadResult> TryLoadStateAsync(IPluginState pluginState, IFileSystem fileSystem, UPath filePath, LoadContext loadContext, LoadInfo loadInfo, IFilePlugin plugin) { // 1. Check if state implements ILoadFile if (!(pluginState is ILoadFiles loadableState)) { return(new LoadResult(false, "The state is not loadable.")); } // 2. Try loading the state try { await Task.Run(async() => await loadableState.Load(fileSystem, filePath, loadContext)); } catch (Exception e) { loadInfo.Logger?.Fatal(e, "The plugin state for '{0}' could not be loaded.", plugin.PluginId); return(new LoadResult(e)); } return(new LoadResult(true)); }
public PluginElement(IFilePlugin plugin) { Plugin = plugin; }