コード例 #1
0
        /// <summary>
        /// Recursivly creates a directory tree by traversing PDIR records. Adds FILE records to the current directory
        /// tree node. Recursivly traverses PDIR records and adds them to the current directory tree node's children.
        /// </summary>
        /// <param name="directoryEntry">Directory Entry</param>
        /// <param name="root">Parent node</param>
        private void BuildDirectoryTree(DirectoryRecord.DirectoryEntry directoryEntry, DirectoryTreeNode root)
        {
            if (!RecordOffsets.ContainsKey(directoryEntry.Offset))
            {
                return; // TODO throw error
            }
            if (RecordOffsets[directoryEntry.Offset] is DirectoryRecord)
            {
                // This offset is a directory, add it as a child of root and process all of it's entries
                var currentDirectory = RecordOffsets[directoryEntry.Offset] as DirectoryRecord;
                _directories.Add(currentDirectory);
                var child = new DirectoryTreeNode
                {
                    Name     = currentDirectory.Name,
                    Parent   = root,
                    Children = new List <DirectoryTreeNode>(),
                    Files    = new List <FileRecord>(),
                    Record   = currentDirectory,
                };

                root.Children.Add(child);

                foreach (var entry in currentDirectory.Entries)
                {
                    BuildDirectoryTree(entry, child);
                }
            }
            else if (RecordOffsets[directoryEntry.Offset] is FileRecord)
            {
                var currentFile = RecordOffsets[directoryEntry.Offset] as FileRecord;
                _files.Add(currentFile);
                currentFile.ContainingDirectory = root;
                root.Files.Add(currentFile);
            }
        }
コード例 #2
0
 private static void BuildDirectoryTree(long fileOffset, DirectoryTreeNode root, Dictionary <long, BaseRecord> recordOffsets)
 {
     if (!recordOffsets.ContainsKey(fileOffset))
     {
         return;
     }
     if (recordOffsets[fileOffset] is DirectoryRecord)
     {
         DirectoryRecord   directoryRecord   = recordOffsets[fileOffset] as DirectoryRecord;
         DirectoryTreeNode directoryTreeNode = new DirectoryTreeNode
         {
             Name     = directoryRecord.Name,
             Parent   = root,
             Children = new List <DirectoryTreeNode>(),
             Files    = new List <FileRecord>(),
             Record   = directoryRecord
         };
         root.Children.Add(directoryTreeNode);
         DirectoryRecord.DirectoryEntry[] entries = directoryRecord.Entries;
         for (int i = 0; i < entries.Length; i++)
         {
             DirectoryRecord.DirectoryEntry directoryEntry = entries[i];
             DirectoryTreeMaker.BuildDirectoryTree(directoryEntry.Offset, directoryTreeNode, recordOffsets);
         }
         return;
     }
     if (recordOffsets[fileOffset] is FileRecord)
     {
         FileRecord fileRecord = recordOffsets[fileOffset] as FileRecord;
         fileRecord.ContainingDirectory = root;
         root.Files.Add(fileRecord);
     }
 }
コード例 #3
0
        /// <summary>
        /// Recursivly creates a directory tree by traversing PDIR records. Adds FILE records to the current directory
        /// tree node. Recursivly traverses PDIR records and adds them to the current directory tree node's children.
        /// </summary>
        /// <param name="directoryEntry">Directory Entry</param>
        /// <param name="root">Parent node</param>
        /// <param name="recordOffsets">Map of record offsets and headers to create directory tree from</param>
        private static void BuildDirectoryTree(DirectoryRecord.DirectoryEntry directoryEntry, DirectoryTreeNode root, IReadOnlyDictionary <long, BaseRecord> recordOffsets)
        {
            if (!recordOffsets.ContainsKey(directoryEntry.Offset))
            {
                return;
            }

            var record = recordOffsets[directoryEntry.Offset] as DirectoryRecord;

            if (record != null)
            {
                // This offset is a directory, add it as a child of root and process all of it's entries
                DirectoryRecord   currentDirectory = record;
                DirectoryTreeNode child            = new DirectoryTreeNode
                {
                    Name     = currentDirectory.Name,
                    Parent   = root,
                    Children = new List <DirectoryTreeNode>(),
                    Files    = new List <FileRecord>(),
                    Record   = currentDirectory,
                };

                root.Children.Add(child);

                foreach (var entry in currentDirectory.Entries)
                {
                    BuildDirectoryTree(entry, child, recordOffsets);
                }
            }
            else
            {
                var file = recordOffsets[directoryEntry.Offset] as FileRecord;
                if (file == null)
                {
                    return;
                }
                FileRecord currentFile = file;
                currentFile.ContainingDirectory = root;
                root.Files.Add(currentFile);
            }
        }
コード例 #4
0
ファイル: DirectoryTreeMaker.cs プロジェクト: wongni/libggpk
        /// <summary>
        /// Recursivly creates a directory tree by traversing PDIR records. Adds FILE records to the current directory
        /// tree node. Recursivly traverses PDIR records and adds them to the current directory tree node's children.
        /// </summary>
        /// <param name="directoryEntry">Directory Entry</param>
        /// <param name="root">Parent node</param>
        /// <param name="recordOffsets">Map of record offsets and headers to create directory tree from</param>
        private static void BuildDirectoryTree(DirectoryRecord.DirectoryEntry directoryEntry, DirectoryTreeNode root, Dictionary <long, BaseRecord> recordOffsets)
        {
            if (!recordOffsets.ContainsKey(directoryEntry.Offset))
            {
                return;
            }

            if (recordOffsets[directoryEntry.Offset] is DirectoryRecord)
            {
                // This offset is a directory, add it as a child of root and process all of it's entries
                DirectoryRecord   currentDirectory = recordOffsets[directoryEntry.Offset] as DirectoryRecord;
                DirectoryTreeNode child            = new DirectoryTreeNode()
                {
                    Name     = currentDirectory.Name,
                    Parent   = root,
                    Children = new List <DirectoryTreeNode>(),
                    Files    = new List <FileRecord>(),
                    Record   = currentDirectory,
                };

                root.Children.Add(child);

                foreach (var entry in currentDirectory.Entries)
                {
                    BuildDirectoryTree(entry, child, recordOffsets);
                }
            }
            else if (recordOffsets[directoryEntry.Offset] is FileRecord)
            {
                FileRecord currentFile = recordOffsets[directoryEntry.Offset] as FileRecord;
                // Skip empty .dat Files under Data/
                //if (root.Name.Equals("Data") && currentFile.DataLength == 12)
                //	return;
                currentFile.ContainingDirectory = root;
                root.Files.Add(currentFile);
            }
        }