Example #1
0
        /// <inheritdoc />
        public async Task <LoadResult> LoadFile(IFileSystem fileSystem, UPath path, LoadFileContext loadFileContext)
        {
            ContractAssertions.IsNotNull(_stateInfo, "stateInfo");

            // If the same file is passed to another plugin, take the parent of the current state
            var parent    = _stateInfo;
            var statePath = _stateInfo.AbsoluteDirectory / _stateInfo.FilePath.ToRelative();

            if (fileSystem.ConvertPathToInternal(path) == statePath)
            {
                parent = _stateInfo.ParentStateInfo;
            }

            // 1. Load file
            var loadResult = await _parentPluginManager.LoadFile(fileSystem, path, parent, loadFileContext);

            if (!loadResult.IsSuccessful)
            {
                return(loadResult);
            }

            // 2. Add file to loaded files
            _loadedFiles.Add(loadResult.LoadedState);

            return(loadResult);
        }
Example #2
0
        /// <inheritdoc />
        public Task <LoadResult> LoadFile(Stream stream, UPath streamName, LoadFileContext loadFileContext)
        {
            // We don't check for an already loaded file here, since that should never happen

            // 1. Create file system action
            var fileSystemAction = new Func <IStreamManager, IFileSystem>(streamManager =>
                                                                          FileSystemFactory.CreateMemoryFileSystem(stream, streamName, streamManager));

            // 2. Load file
            // A stream has no parent, since it should never occur to be loaded from somewhere deeper in the system
            return(LoadFile(fileSystemAction, streamName, null, loadFileContext));
        }
        /// <inheritdoc />
        public async Task <LoadResult> LoadFile(StreamFile streamFile, LoadFileContext loadFileContext)
        {
            ContractAssertions.IsNotNull(_fileState, "fileState");

            // 1. Load file
            var loadResult = await _parentFileManager.LoadFile(streamFile, loadFileContext);

            if (!loadResult.IsSuccessful)
            {
                return(loadResult);
            }

            // 2. Add file to loaded files
            _loadedFiles.Add(loadResult.LoadedFileState);

            return(loadResult);
        }
Example #4
0
        public Task <LoadResult> LoadFile(string file, Guid pluginId, LoadFileContext loadFileContext)
        {
            // 1. Get UPath
            var path = new UPath(file);

            // If file is already loaded
            if (IsLoaded(path))
            {
                return(Task.FromResult(new LoadResult(GetLoadedFile(path))));
            }

            // 2. Create file system action
            var fileSystemAction = new Func <IStreamManager, IFileSystem>(streamManager =>
                                                                          FileSystemFactory.CreatePhysicalFileSystem(path.GetDirectory(), streamManager));

            // 3. Load file
            // Physical files don't have a parent, if loaded like this
            return(LoadFile(fileSystemAction, path.GetName(), null, pluginId, loadFileContext));
        }
Example #5
0
 /// <inheritdoc />
 public Task <LoadResult> LoadFile(IStateInfo stateInfo, IArchiveFileInfo afi, LoadFileContext loadFileContext)
 {
     return(_parentPluginManager.LoadFile(stateInfo, afi, loadFileContext));
 }
Example #6
0
 /// <inheritdoc />
 public Task <LoadResult> LoadFile(IFileSystem fileSystem, UPath path, LoadFileContext loadFileContext)
 {
     return(LoadFile(fileSystem, path, Guid.Empty, loadFileContext));
 }
Example #7
0
        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);
        }
Example #8
0
 /// <inheritdoc />
 public Task <LoadResult> LoadFile(Stream stream, UPath streamName, LoadFileContext loadFileContext)
 {
     return(LoadFile(stream, streamName, Guid.Empty, loadFileContext));
 }
Example #9
0
        /// <inheritdoc />
        public Task <LoadResult> LoadFile(IFileSystem fileSystem, UPath path, Guid pluginId, IStateInfo parentStateInfo, LoadFileContext loadFileContext)
        {
            // Downside of not having ArchiveChildren is not having the states saved below automatically when opened file is saved

            // If file is loaded
            var absoluteFilePath = UPath.Combine(fileSystem.ConvertPathToInternal(UPath.Root), path.ToRelative());

            if (IsLoaded(absoluteFilePath))
            {
                return(Task.FromResult(new LoadResult(GetLoadedFile(absoluteFilePath))));
            }

            // 1. Create file system action
            var fileSystemAction = new Func <IStreamManager, IFileSystem>(fileSystem.Clone);

            // 2. Load file
            // Only if called by a SubPluginManager the parent state is not null
            // Does not add ArchiveChildren to parent state
            return(LoadFile(fileSystemAction, path, parentStateInfo, pluginId, loadFileContext));
        }
Example #10
0
 /// <inheritdoc />
 public Task <LoadResult> LoadFile(IFileSystem fileSystem, UPath path, Guid pluginId, LoadFileContext loadFileContext)
 {
     return(LoadFile(fileSystem, path, pluginId, null, loadFileContext));
 }
Example #11
0
 /// <inheritdoc />
 public Task <LoadResult> LoadFile(IFileSystem fileSystem, UPath path, IStateInfo parentStateInfo, LoadFileContext loadFileContext)
 {
     return(LoadFile(fileSystem, path, Guid.Empty, parentStateInfo, loadFileContext));
 }
Example #12
0
        /// <inheritdoc />
        public async Task <LoadResult> LoadFile(IStateInfo stateInfo, ArchiveFileInfo afi, Guid pluginId, LoadFileContext loadFileContext)
        {
            // If stateInfo is no archive state
            if (!(stateInfo.PluginState is IArchiveState archiveState))
            {
                throw new InvalidOperationException("The state represents no archive.");
            }

            // If file is already loaded
            var absoluteFilePath = UPath.Combine(stateInfo.AbsoluteDirectory, stateInfo.FilePath.ToRelative(), afi.FilePath.ToRelative());

            if (IsLoaded(absoluteFilePath))
            {
                return(new LoadResult(GetLoadedFile(absoluteFilePath)));
            }

            // 1. Create file system action
            var fileSystemAction = new Func <IStreamManager, IFileSystem>(streamManager =>
                                                                          FileSystemFactory.CreateAfiFileSystem(stateInfo, UPath.Root, streamManager));

            // 2. Load file
            // ArchiveFileInfos have stateInfo as their parent, if loaded like this
            var loadResult = await LoadFile(fileSystemAction, afi.FilePath, stateInfo, pluginId, loadFileContext);

            if (!loadResult.IsSuccessful)
            {
                return(loadResult);
            }

            // 3. Add archive child to parent
            // ArchiveChildren are only added, if a file is loaded like this
            stateInfo.ArchiveChildren.Add(loadResult.LoadedState);

            return(loadResult);
        }
Example #13
0
 /// <inheritdoc />
 public Task <LoadResult> LoadFile(IStateInfo stateInfo, ArchiveFileInfo afi, LoadFileContext loadFileContext)
 {
     return(LoadFile(stateInfo, afi, Guid.Empty, loadFileContext));
 }
Example #14
0
 /// <inheritdoc />
 public Task <LoadResult> LoadFile(string file, LoadFileContext loadFileContext)
 {
     return(LoadFile(file, Guid.Empty, loadFileContext));
 }
Example #15
0
 /// <inheritdoc />
 public Task <LoadResult> LoadFile(IFileState fileState, IArchiveFileInfo afi, LoadFileContext loadFileContext)
 {
     return(_parentFileManager.LoadFile(fileState, afi, loadFileContext));
 }