public int GetEntryCount() { int count = 0; if (Mode.HasFlag(OpenDirectoryMode.Directories)) { SaveDirectoryEntry dirEntry = Directory.FirstChild; while (dirEntry != null) { count++; dirEntry = dirEntry.NextSibling; } } if (Mode.HasFlag(OpenDirectoryMode.Files)) { SaveFileEntry fileEntry = Directory.FirstFile; while (fileEntry != null) { count++; fileEntry = fileEntry.NextSibling; } } return(count); }
public IEnumerable <DirectoryEntry> Read() { if (Mode.HasFlag(OpenDirectoryMode.Directories)) { SaveDirectoryEntry dirEntry = Directory.FirstChild; while (dirEntry != null) { yield return(new DirectoryEntry(dirEntry.Name, FullPath + '/' + dirEntry.Name, DirectoryEntryType.Directory, 0)); dirEntry = dirEntry.NextSibling; } } if (Mode.HasFlag(OpenDirectoryMode.Files)) { SaveFileEntry fileEntry = Directory.FirstFile; while (fileEntry != null) { yield return(new DirectoryEntry(fileEntry.Name, FullPath + '/' + fileEntry.Name, DirectoryEntryType.File, fileEntry.FileSize)); fileEntry = fileEntry.NextSibling; } } }
public IStorage OpenFile(SaveFileEntry file) { if (file.BlockIndex < 0) { return(new NullStorage(0)); } return(OpenFatBlock(file.BlockIndex, file.FileSize)); }
private SaveFileEntry[] ReadFileEntries(IStorage storage) { var reader = new BinaryReader(storage.AsStream()); int count = reader.ReadInt32(); reader.BaseStream.Position -= 4; var entries = new SaveFileEntry[count]; for (int i = 0; i < count; i++) { entries[i] = new SaveFileEntry(reader); } return(entries); }
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); }