コード例 #1
0
        public void CreateFile(string path, long size, CreateFileOptions options)
        {
            path = PathTools.Normalize(path);

            if (size == 0)
            {
                var emptyFileEntry = new SaveFileInfo {
                    StartBlock = int.MinValue, Length = size
                };
                FileTable.AddFile(path, ref emptyFileEntry);

                return;
            }

            int blockCount = (int)Util.DivideByRoundUp(size, AllocationTable.Header.BlockSize);
            int startBlock = AllocationTable.Allocate(blockCount);

            if (startBlock == -1)
            {
                ThrowHelper.ThrowResult(ResultFs.AllocationTableInsufficientFreeBlocks,
                                        "Not enough available space to create file.");
            }

            var fileEntry = new SaveFileInfo {
                StartBlock = startBlock, Length = size
            };

            FileTable.AddFile(path, ref fileEntry);
        }
コード例 #2
0
 public AllocationTableStorage(IStorage data, AllocationTable table, int blockSize, int initialBlock, long length)
 {
     BaseStorage  = data;
     BlockSize    = blockSize;
     Length       = length;
     Fat          = table;
     InitialBlock = initialBlock;
 }
コード例 #3
0
        public AllocationTableIterator(AllocationTable table, int initialBlock)
        {
            Fat = table;

            if (!BeginIteration(initialBlock))
            {
                throw new ArgumentException($"Attempted to start FAT iteration from an invalid block. ({initialBlock})");
            }
        }
コード例 #4
0
ファイル: SaveExtensions.cs プロジェクト: shchmue/LibHac
        public static IEnumerable <(int block, int length)> DumpChain(this AllocationTable table, int startBlock)
        {
            var iterator = new AllocationTableIterator(table, startBlock);

            do
            {
                yield return(iterator.PhysicalBlock, iterator.CurrentSegmentSize);
            } while (iterator.MoveNext());
        }
コード例 #5
0
        public AllocationTableStorage(IStorage data, AllocationTable table, int blockSize, int initialBlock)
        {
            BaseStorage  = data;
            BlockSize    = blockSize;
            Fat          = table;
            InitialBlock = initialBlock;

            _length = initialBlock == -1 ? 0 : table.GetListLength(initialBlock) * blockSize;
        }
コード例 #6
0
        public SaveDataFileSystemCore(IStorage storage, IStorage allocationTable, IStorage header)
        {
            HeaderStorage   = header;
            BaseStorage     = storage;
            AllocationTable = new AllocationTable(allocationTable, header.Slice(0x18, 0x30));

            Header = new SaveHeader(HeaderStorage);

            AllocationTableStorage dirTableStorage  = OpenFatStorage(AllocationTable.Header.DirectoryTableBlock);
            AllocationTableStorage fileTableStorage = OpenFatStorage(AllocationTable.Header.FileTableBlock);

            FileTable = new HierarchicalSaveFileTable(dirTableStorage, fileTableStorage);
        }
コード例 #7
0
        public SaveDataFileSystemCore(IStorage storage, IStorage allocationTable, IStorage header)
        {
            HeaderStorage   = header;
            BaseStorage     = storage;
            AllocationTable = new AllocationTable(allocationTable, header.Slice(0x18, 0x30));

            Header = new SaveHeader(HeaderStorage);

            // todo: Query the FAT for the file size when none is given
            AllocationTableStorage dirTableStorage  = OpenFatBlock(AllocationTable.Header.DirectoryTableBlock, 1000000);
            AllocationTableStorage fileTableStorage = OpenFatBlock(AllocationTable.Header.FileTableBlock, 1000000);

            FileTable = new HierarchicalSaveFileTable(dirTableStorage, fileTableStorage);
        }
コード例 #8
0
        public void DeleteFile(string path)
        {
            path = PathTools.Normalize(path);

            if (!FileTable.TryOpenFile(path, out SaveFileInfo fileInfo))
            {
                ThrowHelper.ThrowResult(ResultFs.PathNotFound);
            }

            if (fileInfo.StartBlock != int.MinValue)
            {
                AllocationTable.Free(fileInfo.StartBlock);
            }

            FileTable.DeleteFile(path);
        }
コード例 #9
0
ファイル: SaveFs.cs プロジェクト: tiliarou/LibHac
        public SaveFs(IStorage storage, IStorage allocationTable, IStorage header)
        {
            HeaderStorage   = header;
            BaseStorage     = storage;
            AllocationTable = new AllocationTable(allocationTable, header.Slice(0x18, 0x30));

            Header = new SaveHeader(HeaderStorage);

            ReadFileInfo();
            var dictionary = new Dictionary <string, FileEntry>();

            foreach (FileEntry entry in Files)
            {
                dictionary[entry.FullPath] = entry;
            }

            FileDictionary = dictionary;
        }
コード例 #10
0
        public SaveDataFileSystemCore(IStorage storage, IStorage allocationTable, IStorage header)
        {
            HeaderStorage   = header;
            BaseStorage     = storage;
            AllocationTable = new AllocationTable(allocationTable, header.Slice(0x18, 0x30));

            Header = new SaveHeader(HeaderStorage);

            ReadFileInfo();

            FileDictionary = new Dictionary <string, SaveFileEntry>();
            foreach (SaveFileEntry entry in Files)
            {
                FileDictionary[entry.FullPath] = entry;
            }

            DirDictionary = new Dictionary <string, SaveDirectoryEntry>();
            foreach (SaveDirectoryEntry entry in Directories)
            {
                DirDictionary[entry.FullPath] = entry;
            }
        }
コード例 #11
0
        public long GetFreeSpaceSize(string path)
        {
            int freeBlockCount = AllocationTable.GetFreeListLength();

            return(Header.BlockSize * freeBlockCount);
        }