internal static void ResolveFilenames(IEnumerable <RomfsEntry> entries) { var list = new List <string>(); var sb = new StringBuilder(); const string delimiter = "/"; foreach (RomfsEntry file in entries) { list.Add(file.Name); RomfsDir 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.ToString(); list.Clear(); sb.Clear(); } }
public Romfs(IStorage storage) { BaseStorage = storage; byte[] dirMetaTable; byte[] fileMetaTable; using (var reader = new BinaryReader(BaseStorage.AsStream(), Encoding.Default, true)) { Header = new RomfsHeader(reader); reader.BaseStream.Position = Header.DirMetaTableOffset; dirMetaTable = reader.ReadBytes((int)Header.DirMetaTableSize); reader.BaseStream.Position = Header.FileMetaTableOffset; fileMetaTable = reader.ReadBytes((int)Header.FileMetaTableSize); } using (var reader = new BinaryReader(new MemoryStream(dirMetaTable))) { int position = 0; while (position + 20 < Header.DirMetaTableSize) { var dir = new RomfsDir(reader) { Offset = position }; Directories.Add(dir); if (dir.ParentDirOffset == position) { RootDir = dir; } position = (int)reader.BaseStream.Position; } } using (var reader = new BinaryReader(new MemoryStream(fileMetaTable))) { int position = 0; while (position + 20 < Header.FileMetaTableSize) { var file = new RomfsFile(reader) { Offset = position }; Files.Add(file); position = (int)reader.BaseStream.Position; } } SetReferences(); RomfsEntry.ResolveFilenames(Files); RomfsEntry.ResolveFilenames(Directories); FileDict = Files.ToDictionary(x => x.FullPath, x => x); }