コード例 #1
0
        private void CloseInternal(IStateInfo stateInfo)
        {
            ContractAssertions.IsNotNull(stateInfo, nameof(stateInfo));

            // Close children of this state first
            foreach (var child in stateInfo.ArchiveChildren)
            {
                CloseInternal(child);
            }

            // Close indirect children of this state
            // Indirect children occur when a file is loaded by a FileSystem and got a parent attached manually
            IList <IStateInfo> indirectChildren;

            lock (_loadedFilesLock)
            {
                indirectChildren = _loadedFiles.Where(x => x.ParentStateInfo == stateInfo).ToArray();
            }
            foreach (var indirectChild in indirectChildren)
            {
                CloseInternal(indirectChild);
            }

            // Close state itself
            stateInfo.Dispose();

            // Remove from the file tracking of this instance
            lock (_loadedFilesLock)
            {
                _loadedFiles.Remove(stateInfo);
            }
        }
コード例 #2
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);
        }
コード例 #3
0
        /// <summary>
        /// Create a new instance of <see cref="ImageForm"/>.
        /// </summary>
        /// <param name="stateInfo">The loaded state for an image format.</param>
        /// <param name="formCommunicator"><see cref="IFormCommunicator"/> to allow communication with the main form.</param>
        /// <param name="progressContext">The progress context.</param>
        /// <exception cref="T:System.InvalidOperationException">If state is not an image state.</exception>
        public ImageForm(IStateInfo stateInfo, IFormCommunicator formCommunicator, IProgressContext progressContext)
        {
            InitializeComponent();

            if (!(stateInfo.PluginState is IImageState imageState))
            {
                throw new InvalidOperationException($"This state is not an {nameof(IImageState)}.");
            }

            ContractAssertions.IsNotNull(stateInfo, nameof(stateInfo));
            ContractAssertions.IsNotNull(imageState.Images, nameof(imageState.Images));

            // Check integrity of the image state
            CheckIntegrity(imageState);

            _stateInfo        = stateInfo;
            _formCommunicator = formCommunicator;
            _progressContext  = progressContext;

            imbPreview.Image = ImageState.Images.FirstOrDefault()?.GetImage(progressContext);

            // Populate format dropdown
            PopulateFormatDropdown();

            // Populate palette format dropdown
            PopulatePaletteDropdown(imageState.Images[_selectedImageIndex]);

            // Populate border style drop down
            PopulateBorderStyleDropdown();

            // Update form elements
            UpdateFormInternal();
            UpdatePreview();
            UpdateImageList();
        }
コード例 #4
0
        public LoadResult(IStateInfo stateInfo) :
            this(true)
        {
            ContractAssertions.IsNotNull(stateInfo, nameof(stateInfo));

            LoadedState = stateInfo;
        }
コード例 #5
0
        /// <inheritdoc />
        public async Task <SaveResult> SaveFile(IStateInfo stateInfo, UPath saveName)
        {
            lock (_loadedFilesLock)
            {
                ContractAssertions.IsElementContained(_loadedFiles, stateInfo, "loadedFiles", nameof(stateInfo));
            }

            var isRunning = Progress.IsRunning();

            if (!isRunning)
            {
                Progress.StartProgress();
            }

            var saveResult = await _fileSaver.SaveAsync(stateInfo, saveName, new SaveInfo
            {
                Progress      = Progress,
                DialogManager = DialogManager,
                Logger        = Logger
            });

            if (!isRunning)
            {
                Progress.FinishProgress();
            }

            return(saveResult);
        }
コード例 #6
0
        // Constructor
        public TextEditor2ViewModel(PluginManager pluginManager, IStateInfo koreFile)
        {
            _pluginManager = pluginManager;
            KoreFile       = koreFile;

            _state       = KoreFile.PluginState as ITextState;
            GameAdapters = pluginManager.GetGameAdapters().Select(ga => new GameAdapter(ga)).ToList();

            // TODO: Implement game adapter persistence
            SelectedGameAdapter = GameAdapters.FirstOrDefault();
            SelectedZoomLevel   = 1;

            if (Keyboard.IsKeyDown(Key.LeftShift))
            {
                SelectedGameAdapter = GameAdapters.FirstOrDefault(ga => ga.Adapter.PluginId == Guid.Parse("84D2BD62-7AC6-459B-B3BB-3A65855135F6")) ?? GameAdapters.First();
                SelectedZoomLevel   = 2;
            }
            else if (Keyboard.IsKeyDown(Key.LeftAlt))
            {
                SelectedGameAdapter = GameAdapters.FirstOrDefault(ga => ga.Adapter.PluginId == Guid.Parse("B344166C-F1BE-49B2-9ADC-38771D0A15DA")) ?? GameAdapters.First();
                SelectedZoomLevel   = 1;
            }

            SelectedEntry = Entries?.FirstOrDefault();
        }
コード例 #7
0
ファイル: FormInfo.cs プロジェクト: obluda3/Kuriimu2
 public FormInfo(IStateInfo stateInfo, IFormCommunicator formCommunicator, IProgressContext progress, ILogger logger)
 {
     StateInfo        = stateInfo;
     FormCommunicator = formCommunicator;
     Progress         = progress;
     Logger           = logger;
 }
コード例 #8
0
ファイル: VirtualLoadInfo.cs プロジェクト: obluda3/Kuriimu2
        public VirtualLoadInfo(IStateInfo parentStateInfo, IArchiveState archiveState, ArchiveFileInfo afi, IFilePlugin plugin) :
            this(parentStateInfo, archiveState, afi)
        {
            ContractAssertions.IsNotNull(plugin, nameof(plugin));

            Plugin = plugin;
        }
コード例 #9
0
 public ObjectStateInfo(IStateInfo objectStateInfo)
 {
     State      = objectStateInfo.State;
     Date       = objectStateInfo.Date;
     PersonId   = objectStateInfo.PersonId;
     PositionId = objectStateInfo.PositionId;
 }
コード例 #10
0
        private async Task <SaveResult> SaveAndReplaceStateAsync(IStateInfo stateInfo, IFileSystem destinationFileSystem, UPath savePath, SaveInfo saveInfo)
        {
            var saveState = stateInfo.PluginState as ISaveFiles;

            // 1. Save state to a temporary destination
            var temporaryContainer = _streamMonitor.CreateTemporaryFileSystem();
            var saveStateResult    = await TrySaveState(saveState, temporaryContainer, savePath.GetName(), saveInfo);

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

            // TODO: If reload fails then the original files get closed already, which makes future save actions impossible due to disposed streams

            // 2. Dispose of all streams in this state
            _streamMonitor.GetStreamManager(temporaryContainer).ReleaseAll();
            stateInfo.StreamManager.ReleaseAll();

            // 3. Replace files in destination file system
            var moveResult = await MoveFiles(stateInfo, temporaryContainer, destinationFileSystem);

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

            // 4. Release temporary destination
            _streamMonitor.ReleaseTemporaryFileSystem(temporaryContainer);

            return(SaveResult.SuccessfulResult);
        }
コード例 #11
0
        /// <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>();
        }
コード例 #12
0
        public void Close(IStateInfo stateInfo)
        {
            ContractAssertions.IsElementContained(_loadedFiles, stateInfo, "loadedFiles", nameof(stateInfo));

            _parentPluginManager.Close(stateInfo);
            _loadedFiles.Remove(stateInfo);
        }
コード例 #13
0
        public ContextNode Add(IContext parentContext, IStateInfo stateInfo)
        {
            var newNode = new ContextNode(parentContext, this, stateInfo);

            Children.Add(newNode);

            return(newNode);
        }
コード例 #14
0
        public FormCommunicator(IStateInfo stateInfo, IMainForm mainForm)
        {
            ContractAssertions.IsNotNull(stateInfo, nameof(stateInfo));
            ContractAssertions.IsNotNull(mainForm, nameof(mainForm));

            _stateInfo = stateInfo;
            _mainForm  = mainForm;
        }
コード例 #15
0
ファイル: TextContext.cs プロジェクト: cinnature/Kuriimu2
        public TextContext(IStateInfo stateInfo, IContext parentContext)
        {
            ContractAssertions.IsNotNull(stateInfo, nameof(stateInfo));
            ContractAssertions.IsNotNull(parentContext, nameof(parentContext));

            _stateInfo     = stateInfo;
            _parentContext = parentContext;
        }
コード例 #16
0
ファイル: ImageContext.cs プロジェクト: cinnature/Kuriimu2
        public ImageContext(IStateInfo stateInfo, IContext parentContext)
        {
            ContractAssertions.IsNotNull(stateInfo, nameof(stateInfo));
            ContractAssertions.IsNotNull(parentContext, nameof(parentContext));

            _stateInfo     = stateInfo;
            _imageState    = _stateInfo.PluginState as IImageState;
            _parentContext = parentContext;
        }
コード例 #17
0
        /// <summary>
        /// Create a <see cref="AfiFileSystem"/> based on the given <see cref="IStateInfo"/>.
        /// </summary>
        /// <param name="stateInfo"><see cref="IStateInfo"/> to create the file system from.</param>
        /// <param name="path">The path of the virtual file system.</param>
        /// <returns>The created <see cref="IFileSystem"/> for this state.</returns>
        public static IFileSystem CreateAfiFileSystem(IStateInfo stateInfo, UPath path)
        {
            if (!(stateInfo.PluginState is IArchiveState))
            {
                throw new InvalidOperationException("This state is not an archive.");
            }

            return(CreateAfiFileSystem(stateInfo, path, stateInfo.StreamManager));
        }
コード例 #18
0
        public ArchiveContext(ContextNode contextNode, IContext parentContext, IInternalPluginManager pluginManager) : base(pluginManager, contextNode)
        {
            ContractAssertions.IsNotNull(contextNode, nameof(contextNode));
            ContractAssertions.IsNotNull(parentContext, nameof(parentContext));

            _stateInfo         = contextNode.StateInfo;
            _archiveState      = _stateInfo.PluginState as IArchiveState;
            _archiveFileSystem = FileSystemFactory.CreateAfiFileSystem(_stateInfo);
            _parentContext     = parentContext;
        }
コード例 #19
0
        public TState Enter <TState, TPayload>(TPayload payload) where TState : class, TBaseState, IPayloadedState <TPayload>
        {
            ChangeState(out TState state);

            _lastStateInfo    = _currentStateInfo;
            _currentStateInfo = new PayloadedStateInfo <TState, TBaseState, TPayload>(this, state, payload);

            state.Enter(payload);
            return(state);
        }
コード例 #20
0
        public TState Enter <TState>() where TState : class, TBaseState, IState
        {
            ChangeState(out TState state);

            _lastStateInfo    = _currentStateInfo;
            _currentStateInfo = new StateInfo <TState, TBaseState>(this, state);

            state.Enter();
            return(state);
        }
コード例 #21
0
        public CloseResult Close(IStateInfo stateInfo)
        {
            ContractAssertions.IsElementContained(_loadedFiles, stateInfo, "loadedFiles", nameof(stateInfo));

            var closeResult = _parentPluginManager.Close(stateInfo);

            _loadedFiles.Remove(stateInfo);

            return(closeResult);
        }
コード例 #22
0
        private ContextNode(IContext parentContext, ContextNode parentNode, IStateInfo parentState) : this()
        {
            ContractAssertions.IsNotNull(parentContext, nameof(parentContext));
            ContractAssertions.IsNotNull(parentNode, nameof(parentNode));
            ContractAssertions.IsNotNull(parentState, nameof(parentState));

            _parentNode    = parentNode;
            _parentContext = parentContext;
            StateInfo      = parentState;
        }
コード例 #23
0
        public async Task <IList <AnmcNamedImageRessource> > Load(string file)
        {
            if (_archiveStateInfo != null)
            {
                Close();
            }

            // Load archive
            _archiveStateInfo = await LoadArchive(file);

            // Load images
            var archiveFileSystem = FileSystemFactory.CreateAfiFileSystem(ArchiveState, UPath.Root, _archiveStateInfo.StreamManager);

            _imageStateInfos = await LoadImages(archiveFileSystem);

            // Load point mappings
            var mappings = await LoadPvb(archiveFileSystem);

            _pointMappings = await LoadPbis(archiveFileSystem, mappings);

            // Load RES.bin
            var nameIndices = await LoadResBin(archiveFileSystem);

            // Create image providers
            var imageStates    = _imageStateInfos.Select(x => x.State as IImageState).ToArray();
            var imageProviders = new ImageProvider[_imageStateInfos.Count];

            for (var i = 0; i < imageProviders.Length; i++)
            {
                imageProviders[i] = new ImageProvider(new KanvasImage(imageStates[i], imageStates[i].Images[0]));
            }

            // Create final image ressources
            var result = new List <AnmcNamedImageRessource>();

            for (var i = 0; i < Math.Min(_pointMappings.Count, nameIndices.Count); i++)
            {
                var nameIndex     = nameIndices.First(x => x.Value.pbiIndex == i);
                var imageProvider = imageProviders[nameIndex.Value.imageIndex];

                var partIndex       = 0;
                var imageRessources = new List <AnmcImageRessource>();
                for (var mappingIndex = 0; mappingIndex < _pointMappings[i].Count; mappingIndex += 6)
                {
                    var points         = _pointMappings[i].Skip(mappingIndex).Take(6).ToArray();
                    var imageRessource = new AnmcImageRessource(imageProvider, points, $"{nameIndex.Key} Part {partIndex++}");

                    imageRessources.Add(imageRessource);
                }

                result.Add(new AnmcNamedImageRessource(nameIndex.Key, imageRessources));
            }

            return(result);
        }
コード例 #24
0
        /// <summary>
        /// Create a <see cref="AfiFileSystem"/> based on the given <see cref="IArchiveState"/>.
        /// </summary>
        /// <param name="stateInfo"><see cref="IStateInfo"/> to create the file system from.</param>
        /// <param name="path">The path of the virtual file system.</param>
        /// <param name="streamManager">The stream manager for this file system.</param>
        /// <returns>The created <see cref="IFileSystem"/> for this state.</returns>
        public static IFileSystem CreateAfiFileSystem(IStateInfo stateInfo, UPath path, IStreamManager streamManager)
        {
            var fileSystem = (IFileSystem) new AfiFileSystem(stateInfo, streamManager);

            if (path != UPath.Empty && path != UPath.Root)
            {
                fileSystem = new SubFileSystem(fileSystem, path);
            }

            return(fileSystem);
        }
コード例 #25
0
        public void Close()
        {
            _pluginManager.Close(_archiveStateInfo);
            foreach (var imageStateInfo in _imageStateInfos ?? Array.Empty <IStateInfo>())
            {
                _pluginManager.Close(imageStateInfo);
            }

            _archiveStateInfo = null;
            _imageStateInfos  = null;
        }
コード例 #26
0
        public IStateInfo GetHistoryStateFor(string name)
        {
            if (_HistoryStates == null)
            {
                throw new NullReferenceException("No History States are being held by this memento");
            }

            IStateInfo stateInfo = _HistoryStates [name] as IStateInfo;

            return(stateInfo);
        }
コード例 #27
0
ファイル: VirtualLoadInfo.cs プロジェクト: obluda3/Kuriimu2
        public VirtualLoadInfo(IStateInfo parentStateInfo, IArchiveState archiveState, ArchiveFileInfo afi)
        {
            ContractAssertions.IsNotNull(parentStateInfo, nameof(parentStateInfo));
            ContractAssertions.IsNotNull(archiveState, nameof(archiveState));
            ContractAssertions.IsNotNull(afi, nameof(afi));
            ContractAssertions.IsElementContained(archiveState.Files, afi, nameof(archiveState), nameof(afi));

            ParentStateInfo = parentStateInfo;
            ArchiveState    = archiveState;
            Afi             = afi;
        }
コード例 #28
0
        public ArchiveForm(IStateInfo stateInfo, IArchiveFormCommunicator communicator, PluginManager pluginManager, IProgressContext progress)
        {
            InitializeComponent();

            _stateInfo     = stateInfo;
            _communicator  = communicator;
            _pluginManager = pluginManager;
            _progress      = progress;

            _archiveFileSystem = FileSystemFactory.CreateAfiFileSystem(stateInfo);
            _openingFiles      = new List <IArchiveFileInfo>();

            _changedDirectories = new HashSet <UPath>();
            _selectedPath       = UPath.Root;

            _searchTerm              = new SearchTerm(searchTextBox);
            _searchTerm.TextChanged += searchTerm_TextChanged;

            _asyncOperation           = new AsyncOperation();
            _asyncOperation.Started  += asyncOperation_Started;
            _asyncOperation.Finished += asyncOperation_Finished;

            folderView.Expanded            += folderView_Expanded;
            folderView.Collapsed           += folderView_Collapsed;
            folderView.CellFormatting      += folderView_CellFormatting;
            folderView.SelectedItemChanged += folderView_SelectedItemChanged;

            fileView.SelectedItemsChanged += fileView_SelectedItemsChanged;
            fileView.CellDoubleClick      += fileView_CellDoubleClick;
            fileView.CellFormatting       += fileView_CellFormatting;

            searchClearCommand.Executed += searchClearCommand_Executed;
            cancelCommand.Executed      += cancelCommand_Executed;

            saveCommand.Executed   += SaveCommand_Executed;
            saveAsCommand.Executed += SaveAsCommand_Executed;

            openCommand.Executed        += openCommand_Executed;
            extractFileCommand.Executed += extractFileCommand_Executed;
            replaceFileCommand.Executed += replaceFileCommand_Executed;
            renameFileCommand.Executed  += RenameFileCommand_Executed;
            deleteFileCommand.Executed  += DeleteFileCommand_Executed;

            extractDirectoryCommand.Executed += extractDirectoryCommand_Executed;
            replaceDirectoryCommand.Executed += replaceDirectoryCommand_Executed;
            renameDirectoryCommand.Executed  += renameDirectoryCommand_Executed;
            addDirectoryCommand.Executed     += addDirectoryCommand_Executed;
            deleteDirectoryCommand.Executed  += deleteDirectoryCommand_Executed;

            UpdateProperties();
            LoadDirectories();
            UpdateFiles(_selectedPath);
        }
コード例 #29
0
        public void Close(IStateInfo stateInfo)
        {
            lock (_loadedFilesLock)
            {
                ContractAssertions.IsElementContained(_loadedFiles, stateInfo, "loadedFiles", nameof(stateInfo));
            }

            // Remove state from its parent
            stateInfo.ParentStateInfo?.ArchiveChildren.Remove(stateInfo);

            CloseInternal(stateInfo);
        }
コード例 #30
0
        // Constructor
        public TextEditor1ViewModel(IStateInfo koreFile)
        {
            KoreFile = koreFile;

            // TODO: What is display name
            //DisplayName = KoreFile.DisplayName;
            _state = KoreFile.PluginState as ITextState;

            if (_state != null)
            {
                Entries = new ObservableCollection <TextEntry>(_state.Texts);
            }

            SelectedEntry = Entries.First();
        }