private static RomFsFileSystemInfo GetRomFsInfo(IFileSystemArchiveReader fsReader, EntryReplaceRule replaceRule) { RomFsFileSystemInfo fsInfo = new RomFsFileSystemInfo(); DirectoryList directories = new DirectoryList(); ArchiveReconstructionUtils.AddEntryToFsInfo addEntryDelegate = (ArchiveReconstructionUtils.AddEntryToFsInfo)(fileInfoList => { foreach (ArchiveReconstructionUtils.BasicFileInfo fileInfo in fileInfoList) { RomFsFileSystemInfo.EntryInfo entryInfo = new RomFsFileSystemInfo.EntryInfo(); entryInfo.type = "source"; entryInfo.name = "/" + fileInfo.Name; entryInfo.size = (ulong)fileInfo.Size; entryInfo.offset = (ulong)fileInfo.Offset; entryInfo.path = (string)null; entryInfo.sourceInterface = fileInfo.Source; fsInfo.entries.Add(entryInfo); ++fsInfo.fileEntryCount; directories.AddAncestors(Path.GetDirectoryName(entryInfo.name)); } }); ArchiveReconstructionUtils.GetFsInfo(fsReader, replaceRule, addEntryDelegate); fsInfo.directoryEntryCount = directories.Count; return(fsInfo); }
public RomFsArchiveSource(RomFsFileSystemInfo fileSystemInfo) { RomFsFileSystemMeta fsFileSystemMeta = new RomFsFileSystemMeta(); List <ConcatenatedSource.Element> elements = new List <ConcatenatedSource.Element>(); RomFsFileSystemInfo fileSystemInfo1 = fileSystemInfo; RomFsFileSystemMetaInfo fileSystemMetaInfo = fsFileSystemMeta.Create(fileSystemInfo1); ConcatenatedSource.Element element1 = new ConcatenatedSource.Element((ISource) new MemorySource(fileSystemMetaInfo.header, 0, fileSystemMetaInfo.header.Length), "meta_header", 0L); elements.Add(element1); long size = element1.Source.Size; foreach (RomFsFileSystemInfo.EntryInfo entry in fileSystemInfo.entries) { if (entry.type == "file") { ConcatenatedSource.Element element2 = new ConcatenatedSource.Element((ISource) new FileSource(entry.path, 0L, (long)entry.size), entry.name, (long)entry.offset + size); elements.Add(element2); } else if (entry.type == "source") { ConcatenatedSource.Element element2 = new ConcatenatedSource.Element((ISource)entry.sourceInterface, entry.name, (long)entry.offset + size); elements.Add(element2); } } RomFsFileSystemInfo.EntryInfo entry1 = fileSystemInfo.entries[fileSystemInfo.entries.Count - 1]; long offset = size + (long)entry1.offset + (long)entry1.size; if (fileSystemMetaInfo.offsetData > offset) { elements.Add(new ConcatenatedSource.Element((ISource) new PaddingSource(fileSystemMetaInfo.offsetData - offset), "romFsMetaBodyPadding", offset)); } ConcatenatedSource.Element element3 = new ConcatenatedSource.Element((ISource) new MemorySource(fileSystemMetaInfo.data, 0, fileSystemMetaInfo.data.Length), "meta_data", fileSystemMetaInfo.offsetData); elements.Add(element3); this.m_source = (ISource) new ConcatenatedSource(elements); this.Size = this.m_source.Size; }
public RomFsFileSystemInfo GetFileSystemInfo() { RomFsFileSystemInfo fsFileSystemInfo = new RomFsFileSystemInfo(); using (StreamReader streamReader = new StreamReader(this.m_adfPath, Encoding.UTF8)) { YamlStream yamlStream = new YamlStream(); yamlStream.Load((TextReader)streamReader); YamlMappingNode rootNode; try { rootNode = (YamlMappingNode)yamlStream.Documents[0].RootNode; if (((YamlScalarNode)rootNode.Children[(YamlNode) new YamlScalarNode("formatType")]).Value != "RomFs") { throw new ArgumentException(); } } catch { throw new ArgumentException("invalid format .adf file."); } YamlSequenceNode child; try { child = (YamlSequenceNode)rootNode.Children[(YamlNode) new YamlScalarNode("entries")]; } catch { throw new ArgumentException("invalid format .adf file. At least one file must be included in the data region."); } DirectoryList directoryList = new DirectoryList(); foreach (YamlMappingNode yamlMappingNode in child) { RomFsFileSystemInfo.EntryInfo entryInfo = new RomFsFileSystemInfo.EntryInfo(); foreach (KeyValuePair <YamlNode, YamlNode> keyValuePair in yamlMappingNode) { string str = ((YamlScalarNode)keyValuePair.Key).Value; if (!(str == "type")) { if (!(str == "name")) { if (!(str == "offset")) { if (!(str == "path")) { throw new ArgumentException("invalid format .adf file. invalid key is specified\n" + yamlMappingNode.ToString()); } entryInfo.path = ((YamlScalarNode)keyValuePair.Value).Value; } else { entryInfo.offset = Convert.ToUInt64(((YamlScalarNode)keyValuePair.Value).Value); } } else { entryInfo.name = "/" + ((YamlScalarNode)keyValuePair.Value).Value; } } else { entryInfo.type = ((YamlScalarNode)keyValuePair.Value).Value; } } if (entryInfo.type == null) { throw new ArgumentException("invalid format .adf file. invalid \"type\"\n" + yamlMappingNode.ToString()); } if (entryInfo.type == "file" && (entryInfo.name == null || entryInfo.path == null)) { throw new ArgumentException("invalid format .adf file. \"type == file\" but \"name\" or \"path\" is not specified.\n" + yamlMappingNode.ToString()); } if (entryInfo.type == "directory" && entryInfo.name == null) { throw new ArgumentException("invalid format .adf file. \"type == directory\" but \"name\" is not specified.\n" + yamlMappingNode.ToString()); } if (entryInfo.type == "file") { FileInfo fileInfo = new FileInfo(entryInfo.path); entryInfo.size = (ulong)fileInfo.Length; fsFileSystemInfo.entries.Add(entryInfo); ++fsFileSystemInfo.fileEntryCount; directoryList.AddAncestors(Path.GetDirectoryName(entryInfo.name)); } else { if (!(entryInfo.type == "directory")) { throw new ArgumentException("invalid format .adf file. \"type\" should be \"directory\" or \"file\".\n" + yamlMappingNode.ToString()); } fsFileSystemInfo.entries.Add(entryInfo); directoryList.AddAncestors(entryInfo.name); } } fsFileSystemInfo.directoryEntryCount = directoryList.Count; } return(fsFileSystemInfo); }