Exemple #1
0
        public override void SetSize(long size)
        {
            if (size < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(size));
            }
            if (Size == size)
            {
                return;
            }

            BaseStorage.SetSize(size);

            if (!FileTable.TryOpenFile(Path, out SaveFileInfo fileInfo))
            {
                throw new FileNotFoundException();
            }

            fileInfo.StartBlock = BaseStorage.InitialBlock;
            fileInfo.Length     = size;

            FileTable.AddFile(Path, ref fileInfo);

            Size = size;
        }
        protected override Result SetSizeImpl(long size)
        {
            if (size < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(size));
            }
            if (Size == size)
            {
                return(Result.Success);
            }

            Result rc = BaseStorage.SetSize(size);

            if (rc.IsFailure())
            {
                return(rc);
            }

            if (!FileTable.TryOpenFile(Path, out SaveFileInfo fileInfo))
            {
                throw new FileNotFoundException();
            }

            fileInfo.StartBlock = BaseStorage.InitialBlock;
            fileInfo.Length     = size;

            FileTable.AddFile(Path, ref fileInfo);

            Size = size;

            return(Result.Success);
        }
Exemple #3
0
        /// <summary>
        /// Adds a file to the RomFS.
        /// </summary>
        /// <param name="path">The full path in the RomFS</param>
        /// <param name="file">An <see cref="IFile"/> of the file data to add.</param>
        public void AddFile(string path, IFile file)
        {
            var  fileInfo = new RomFileInfo();
            long fileSize = file.GetSize();

            fileInfo.Offset = CurrentOffset;
            fileInfo.Length = fileSize;

            IStorage fileStorage = file.AsStorage();

            Sources.Add(fileStorage);

            long newOffset = CurrentOffset + fileSize;

            CurrentOffset = Util.AlignUp(newOffset, FileAlignment);

            var padding = new NullStorage(CurrentOffset - newOffset);

            Sources.Add(padding);

            FileTable.AddFile(path, ref fileInfo);
        }