コード例 #1
0
ファイル: RamDiskFileSystem.cs プロジェクト: ishkang/Gorgon
        /// <summary>
        /// Function to open a writable stream to the file.
        /// </summary>
        /// <param name="path">The path to the file.</param>
        /// <returns>A stream to the file.</returns>
        public MemoryStream OpenForWrite(string path)
        {
            MemoryStream stream;

            if (_fileInfos.ContainsKey(path))
            {
                RamDiskFileInfo fileInfo = GetFileInfo(path);

                if (!_fileData.TryGetValue(fileInfo, out stream))
                {
                    throw new FileNotFoundException(string.Format(Resources.GORFS_ERR_FILE_NOT_FOUND, path));
                }

                return(stream);
            }

            // This is a new file, so open it as such.
            var info = new RamDiskFileInfo(path, 0, DateTime.Now, DateTime.Now);

            stream = new MemoryStream();
            _fileInfos.Add(path, info);
            _fileData.Add(info, stream);

            return(stream);
        }
コード例 #2
0
ファイル: RamDiskFileSystem.cs プロジェクト: ishkang/Gorgon
        /// <summary>
        /// Function to open a read only stream to a file.
        /// </summary>
        /// <param name="path">Path to the file.</param>
        /// <returns>The stream to the file.</returns>
        public Stream OpenReadStream(string path)
        {
            RamDiskFileInfo fileInfo = GetFileInfo(path);


            if (!_fileData.TryGetValue(fileInfo, out MemoryStream stream))
            {
                throw new FileNotFoundException(string.Format(Resources.GORFS_ERR_FILE_NOT_FOUND, path));
            }

            return(new GorgonStreamWrapper(stream, 0, stream.Length, false));
        }
コード例 #3
0
ファイル: RamDiskFileSystem.cs プロジェクト: ishkang/Gorgon
        /// <summary>
        /// Function to update the information for a file.
        /// </summary>
        /// <param name="path">Path to the file.</param>
        /// <param name="fileInfo">File information to replace.</param>
        public void UpdateFile(string path, ref RamDiskFileInfo fileInfo)
        {
            if (_fileInfos.TryGetValue(path, out RamDiskFileInfo old))
            {
                _fileInfos.Remove(old.FullPath);
                _fileInfos[path] = fileInfo;
            }
            else
            {
                old = fileInfo;
            }

            if (!_fileData.TryGetValue(old, out MemoryStream oldStream))
            {
                throw new FileNotFoundException(string.Format(Resources.GORFS_ERR_FILE_NOT_FOUND, path));
            }

            _fileData.Remove(old);
            _fileData[fileInfo] = oldStream;
        }