예제 #1
0
 public SaveDataFile(AllocationTableStorage baseStorage, long offset, long size, OpenMode mode)
 {
     Mode        = mode;
     BaseStorage = baseStorage;
     Offset      = offset;
     Size        = size;
 }
예제 #2
0
 public SaveDataFile(AllocationTableStorage baseStorage, string path, HierarchicalSaveFileTable fileTable, long size, OpenMode mode)
 {
     Mode        = mode;
     BaseStorage = baseStorage;
     Path        = path;
     FileTable   = fileTable;
     Size        = size;
 }
예제 #3
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);
        }
예제 #4
0
        public IFile OpenFile(string path, OpenMode mode)
        {
            path = PathTools.Normalize(path);

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

            AllocationTableStorage storage = OpenFatStorage(file.StartBlock);

            return(new SaveDataFile(storage, path, FileTable, file.Length, mode));
        }
예제 #5
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);
        }
예제 #6
0
        public IFile OpenFile(string path, OpenMode mode)
        {
            path = PathTools.Normalize(path);

            if (!FileDictionary.TryGetValue(path, out SaveFileEntry file))
            {
                throw new FileNotFoundException();
            }

            if (file.BlockIndex < 0)
            {
                return(new NullFile());
            }

            AllocationTableStorage storage = OpenFatBlock(file.BlockIndex, file.FileSize);

            return(new SaveDataFile(storage, 0, file.FileSize, mode));
        }
예제 #7
0
        public IFile OpenFile(string path, OpenMode mode)
        {
            path = PathTools.Normalize(path);

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

            if (file.StartBlock < 0)
            {
                return(new NullFile());
            }

            AllocationTableStorage storage = OpenFatBlock(file.StartBlock, file.Length);

            return(new SaveDataFile(storage, 0, file.Length, mode));
        }
예제 #8
0
        private void ReadFileInfo()
        {
            // todo: Query the FAT for the file size when none is given
            AllocationTableStorage dirTableStream  = OpenFatBlock(AllocationTable.Header.DirectoryTableBlock, 1000000);
            AllocationTableStorage fileTableStream = OpenFatBlock(AllocationTable.Header.FileTableBlock, 1000000);

            SaveDirectoryEntry[] dirEntries  = ReadDirEntries(dirTableStream);
            SaveFileEntry[]      fileEntries = ReadFileEntries(fileTableStream);

            foreach (SaveDirectoryEntry dir in dirEntries)
            {
                if (dir.NextSiblingIndex != 0)
                {
                    dir.NextSibling = dirEntries[dir.NextSiblingIndex];
                }
                if (dir.FirstChildIndex != 0)
                {
                    dir.FirstChild = dirEntries[dir.FirstChildIndex];
                }
                if (dir.FirstFileIndex != 0)
                {
                    dir.FirstFile = fileEntries[dir.FirstFileIndex];
                }
                if (dir.NextInChainIndex != 0)
                {
                    dir.NextInChain = dirEntries[dir.NextInChainIndex];
                }
                if (dir.ParentDirIndex != 0 && dir.ParentDirIndex < dirEntries.Length)
                {
                    dir.ParentDir = dirEntries[dir.ParentDirIndex];
                }
            }

            foreach (SaveFileEntry file in fileEntries)
            {
                if (file.NextSiblingIndex != 0)
                {
                    file.NextSibling = fileEntries[file.NextSiblingIndex];
                }
                if (file.NextInChainIndex != 0)
                {
                    file.NextInChain = fileEntries[file.NextInChainIndex];
                }
                if (file.ParentDirIndex != 0 && file.ParentDirIndex < dirEntries.Length)
                {
                    file.ParentDir = dirEntries[file.ParentDirIndex];
                }
            }

            RootDirectory = dirEntries[2];

            SaveFileEntry fileChain = fileEntries[1].NextInChain;
            var           files     = new List <SaveFileEntry>();

            while (fileChain != null)
            {
                files.Add(fileChain);
                fileChain = fileChain.NextInChain;
            }

            SaveDirectoryEntry dirChain = dirEntries[1].NextInChain;
            var dirs = new List <SaveDirectoryEntry>();

            while (dirChain != null)
            {
                dirs.Add(dirChain);
                dirChain = dirChain.NextInChain;
            }

            Files       = files.ToArray();
            Directories = dirs.ToArray();

            SaveFsEntry.ResolveFilenames(Files);
            SaveFsEntry.ResolveFilenames(Directories);
        }