Example #1
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>();
        }
Example #2
0
        /// <inheritdoc />
        public void ReplaceFile(UPath srcPath, UPath destPath, UPath destBackupPath, bool ignoreMetadataErrors)
        {
            AssertNotDisposed();
            AssertTrue(CanReplaceFiles, nameof(ReplaceFile));
            srcPath        = ValidatePath(srcPath, nameof(srcPath));
            destPath       = ValidatePath(destPath, nameof(destPath));
            destBackupPath = ValidatePath(destBackupPath, nameof(destBackupPath), true);

            if (!FileExistsImpl(srcPath))
            {
                throw FileSystemExceptionHelper.NewFileNotFoundException(srcPath);
            }

            if (!FileExistsImpl(destPath))
            {
                throw FileSystemExceptionHelper.NewFileNotFoundException(srcPath);
            }

            if (destBackupPath == srcPath)
            {
                throw new IOException($"The source and backup cannot have the same path `{srcPath}`");
            }

            ReplaceFileImpl(srcPath, destPath, destBackupPath, ignoreMetadataErrors);
        }