Beispiel #1
0
        private void CreateFileTree()
        {
            this.root           = new PboFsRealFolder(null, writeableDirectory, null);
            this.fileTreeLookup = new HashSet <IPboFsNode>();
            this.fileTreeLookup.Add(this.root);
            var hasCfgConvert = PboFS.HasCfgConvert();

            foreach (string filePath in this.archiveManager.FilePathToFileEntry.Keys)
            {
                if (excludePrefix != null && filePath.StartsWith(excludePrefix))
                {
                    continue;
                }
                FileEntry file = this.archiveManager.FilePathToFileEntry[filePath];

                PboFsFolder currentFolder = root;
                var         currentPath   = "\\";
                var         splitPath     = filePath.Split('\\');

                // Create inputFolder for all sub paths
                for (int i = 1; i < splitPath.Length - 1; i++)
                {
                    var folderName = splitPath[i];
                    currentPath += folderName;

                    PboFsFolder folder = null;
                    if (!this.fileTreeLookup.Contains(new PboFsLookupDummy(currentPath)))
                    {
                        folder = new PboFsFolder(folderName, currentFolder);
                        this.fileTreeLookup.Add(folder);
                    }
                    else
                    {
                        fileTreeLookup.TryGetValue(new PboFsLookupDummy(currentPath), out var node);
                        folder = node as PboFsFolder;
                    }

                    if (!currentFolder.Children.ContainsKey(folderName))
                    {
                        currentFolder.Children[folderName] = currentFolder = folder;
                    }
                    else
                    {
                        currentFolder = (PboFsFolder)currentFolder.Children[folderName];
                    }

                    currentPath += "\\";
                }

                var fileName = splitPath[splitPath.Length - 1];
                var fileNode = new PboFsFile(fileName, file, currentFolder);
                currentFolder.Children[fileName] = fileNode;
                this.fileTreeLookup.Add(fileNode);
                if (hasCfgConvert && fileName == "config.bin")
                {
                    var derapNode = new PboFsDebinarizedFile("config.cpp", file, currentFolder);
                    currentFolder.Children["config.cpp"] = derapNode;
                    this.fileTreeLookup.Add(derapNode);
                }
            }

            //Interweave writeableDirectory
            LinkRealDirectory(new System.IO.DirectoryInfo(writeableDirectory), "", this.root, true);
        }
Beispiel #2
0
        private void CreateFileTree()
        {
            this.root           = new PboFsRealFolder(null, writeableDirectory, null);
            this.fileTreeLookup = new HashSet <IPboFsNode>();
            this.fileTreeLookup.Add(this.root);
            var hasCfgConvert = PboFS.HasCfgConvert();


            foreach (var(filePath, file) in this.archiveManager.Enumerator)
            {
                if (excludePrefix != null && filePath.StartsWith(excludePrefix))
                {
                    continue;
                }
                this.archiveManager.TotalBytes += (long)file.DataSize;

                PboFsFolder currentFolder = root;
                var         currentPath   = "\\";
                var         splitPath     = filePath.Split(PboFsLookupDummy.PathChars, StringSplitOptions.RemoveEmptyEntries);

                // Make sure the files directory path exists
                for (int i = 0; i < splitPath.Length - 1; i++)
                {
                    var folderName = splitPath[i];
                    currentPath += folderName;

                    //A part of the path might already exist, walking the tree directly via this shortcut saves alot of time
                    currentFolder.Children.TryGetValue(folderName, out var subFolderNode);
                    if (subFolderNode is PboFsFolder subFolder)
                    {
                        currentFolder = subFolder;
                        currentPath  += "\\";
                        continue;
                    }
                    var lookup = new PboFsLookupDummy(currentPath);

                    PboFsFolder folder = null;
                    if (!this.fileTreeLookup.Contains(lookup))
                    {
                        folder = new PboFsFolder(folderName, currentFolder);
                        this.fileTreeLookup.Add(folder);
                    }
                    else
                    {
                        fileTreeLookup.TryGetValue(lookup, out var node);
                        folder = node as PboFsFolder;
                    }

                    if (!currentFolder.Children.ContainsKey(folderName))
                    {
                        currentFolder.Children[folderName] = currentFolder = folder;
                    }
                    else
                    {
                        currentFolder = (PboFsFolder)currentFolder.Children[folderName];
                    }

                    currentPath += "\\";
                }

                var fileName = splitPath[splitPath.Length - 1];
                var fileNode = new PboFsFile(fileName, file, currentFolder);

                if (hasCfgConvert && fileName.EndsWith("rvmat"))
                {
                    byte[] buffer = new byte[4];
                    fileNode.ReadFile(buffer, out var length, 0);
                    if (buffer[0] == 0 && buffer[1] == 'r' && buffer[2] == 'a' && buffer[3] == 'P')
                    {
                        var derapNode = new PboFsDebinarizedFile(fileName, file, currentFolder);
                        currentFolder.Children[fileName] = derapNode;
                        this.fileTreeLookup.Add(derapNode);
                        continue;
                    }
                }

                currentFolder.Children[fileName] = fileNode;
                this.fileTreeLookup.Add(fileNode);

                if (hasCfgConvert && fileName == "config.bin")
                {
                    var derapNode = new PboFsDebinarizedFile("config.cpp", file, currentFolder);
                    currentFolder.Children["config.cpp"] = derapNode;
                    this.fileTreeLookup.Add(derapNode);
                }
            }

            //Interweave writeableDirectory
            LinkRealDirectory(new System.IO.DirectoryInfo(writeableDirectory), "", this.root, true);
        }