internal static void ResolveFilenames(IEnumerable <SaveFsEntry> entries) { var list = new List <string>(); var sb = new StringBuilder(); string delimiter = "/"; foreach (SaveFsEntry file in entries) { list.Add(file.Name); SaveDirectoryEntry dir = file.ParentDir; while (dir != null) { list.Add(delimiter); list.Add(dir.Name); dir = dir.ParentDir; } for (int i = list.Count - 1; i >= 0; i--) { sb.Append(list[i]); } file.FullPath = sb.Length == 0 ? delimiter : sb.ToString(); list.Clear(); sb.Clear(); } }
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 SaveDataDirectory(SaveDataFileSystemCore fs, string path, SaveDirectoryEntry dir, OpenDirectoryMode mode) { ParentFileSystem = fs; Directory = dir; FullPath = path; Mode = mode; }
private SaveDirectoryEntry[] ReadDirEntries(IStorage storage) { var reader = new BinaryReader(storage.AsStream()); int count = reader.ReadInt32(); reader.BaseStream.Position -= 4; var entries = new SaveDirectoryEntry[count]; for (int i = 0; i < count; i++) { entries[i] = new SaveDirectoryEntry(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); }