private void ImportEntries(EntryListTab[] entries) { foreach (EntryListTab entry in entries.Where(x => x.Path.GetHash() != 0)) { var type = (entry.Type & 0x400000) == 0 ? EntryType.File : EntryType.Dir; if (type == EntryType.Dir) { var node = Nodes[entry.Path.GetHash()]; if (node.NameHash != entry.Name.GetHash() || node.ParentHash != entry.Parent.GetHash()) { Console.WriteLine("Importing hash mismatch"); } node.NextSiblingIndex = entry.NextSiblingIndex == 0xFFFFFF ? -1 : entry.NextSiblingIndex; node.Type = type; EntryNodes.Add(node); } else if (type == EntryType.File) { var node = new FsNode(); node.PathHash = entry.Path.GetHash(); node.ParentHash = entry.Parent.GetHash(); node.NameHash = entry.Name.GetHash(); node.ExtensionHash = entry.Extension.GetHash(); node.NextSiblingIndex = entry.NextSiblingIndex == 0xFFFFFF ? -1 : entry.NextSiblingIndex; node.Type = type; EntryNodes.Add(node); Nodes.Add(node.PathHash, node); } } }
private void PopulateStrings() { foreach (FsNode node in Nodes.Values) { Hash.HashStrings.TryGetValue(node.PathHash, out string pathText); Hash.HashStrings.TryGetValue(node.ParentHash, out string parentText); Hash.HashStrings.TryGetValue(node.NameHash, out string nameText); node.PathText = pathText; node.ParentText = parentText; node.NameText = nameText; if (node.Type == EntryType.File) { Hash.HashStrings.TryGetValue(node.ExtensionHash, out string extensionText); node.ExtensionText = extensionText; } if (node.PathText == "/") { Root = node; // root isn't contained in EntryNodes and must be handled separately node.FirstChild = EntryNodes[node.FirstChildIndex]; } } }
public bool Validate() { if (ExtensionText != null && NameText != null && !NameText.EndsWith(ExtensionText)) { return(false); } if (NameText != null && PathText != null && !PathText.EndsWith(NameText)) { return(false); } if (PathText != null) { FsNode parent = Parent; // Stop before the root node while (parent?.Parent != null) { if (!PathText.StartsWith(parent.PathText)) { return(false); } parent = parent.Parent; } } return(true); }
private void ImportDirectories(DirectoryListTab2[] directories) { foreach (DirectoryListTab2 dir in directories) { var node = new FsNode(); node.PathHash = dir.Path.GetHash(); node.ParentHash = dir.Parent.GetHash(); node.NameHash = dir.Name.GetHash(); node.Type = EntryType.Dir; node.FirstChildIndex = dir.EntryStartIndex; node.ChildCount = dir.EntryCount; node.ChildDirectoryCount = dir.ChildDirCount; node.ChildFileCount = dir.ChildFileCount; DirNodes.Add(node); } Nodes = DirNodes.ToDictionary(x => x.PathHash, x => x); }
public IEnumerable <FsNode> EnumerateEntries() { var stack = new Stack <FsNode>(); stack.Push(Root); while (stack.Count > 0) { FsNode curNode = stack.Pop(); yield return(curNode); if (curNode.NextSibling != null) { stack.Push(curNode.NextSibling); } if (curNode.FirstChild != null) { stack.Push(curNode.FirstChild); } } }