/// <summary>
        /// Builds a directory tree by traversing the list of record headers found in the pack file
        /// </summary>
        /// <param name="recordOffsets">Map of record offsets and headers to create directory tree from</param>
        /// <returns>Root node of directory tree</returns>
        internal static DirectoryTreeNode BuildDirectoryTree(Dictionary <long, BaseRecord> recordOffsets)
        {
            // This offset is a directory, add it as a child of root and process all of it's entries
            GGPKRecord currentDirectory = recordOffsets[0] as GGPKRecord;

            DirectoryTreeNode root = new DirectoryTreeNode()
            {
                Children = new List <DirectoryTreeNode>(),
                Files    = new List <FileRecord>(),
                Name     = "",
                Parent   = null,
                Record   = null
            };

            // First level only contains a empty string name directory record and a free record
            if (currentDirectory == null)
            {
                return(root);
            }
            foreach (var item in from Offset in currentDirectory.RecordOffsets
                     where recordOffsets.ContainsKey(Offset)
                     where recordOffsets[Offset] is DirectoryRecord
                     select recordOffsets[Offset] as DirectoryRecord
                     into firstDirectory
                     from item in firstDirectory.Entries
                     select item)
            {
                BuildDirectoryTree(item, root, recordOffsets);
            }
            return(root);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Builds a linked list of FREE records by traversing FREE records in GGPK file
        /// </summary>
        /// <param name="recordOffsets">Map of record offsets in GGPK file</param>
        /// <returns>Linked list containing list of FREE records</returns>
        internal static LinkedList <FreeRecord> BuildFreeList(Dictionary <long, BaseRecord> recordOffsets)
        {
            LinkedList <FreeRecord> freeList = new LinkedList <FreeRecord>();

            // This offset is a directory, add it as a child of root and process all of it's entries
            GGPKRecord currentDirectory  = recordOffsets[0] as GGPKRecord;
            FreeRecord currentFreeRecord = null;

            foreach (var item in currentDirectory.RecordOffsets)
            {
                if (recordOffsets[item] is FreeRecord)
                {
                    currentFreeRecord = recordOffsets[item] as FreeRecord;
                    break;
                }
            }

            if (currentFreeRecord == null)
            {
                throw new Exception("Failed to find FREE record root in GGPK header");
            }

            while (true)
            {
                freeList.AddLast(currentFreeRecord);
                long nextFreeOFfset = currentFreeRecord.NextFreeOffset;

                if (nextFreeOFfset == 0)
                {
                    break;
                }

                if (!recordOffsets.ContainsKey(nextFreeOFfset))
                {
                    throw new Exception("Failed to find next FREE record in map of record offsets");
                }

                currentFreeRecord = recordOffsets[currentFreeRecord.NextFreeOffset] as FreeRecord;

                if (currentFreeRecord == null)
                {
                    throw new Exception("Found a record that wasn't a FREE record while looking for next FREE record");
                }
            }

            return(freeList);
        }
Ejemplo n.º 3
0
        internal static LinkedList <FreeRecord> BuildFreeList(Dictionary <long, BaseRecord> recordOffsets)
        {
            LinkedList <FreeRecord> linkedList = new LinkedList <FreeRecord>();
            GGPKRecord gGPKRecord = recordOffsets[0L] as GGPKRecord;
            FreeRecord freeRecord = null;

            long[] recordOffsets2 = gGPKRecord.RecordOffsets;
            for (int i = 0; i < recordOffsets2.Length; i++)
            {
                long key = recordOffsets2[i];
                if (recordOffsets[key] is FreeRecord)
                {
                    freeRecord = (recordOffsets[key] as FreeRecord);
                    break;
                }
            }
            if (freeRecord == null)
            {
                throw new Exception("Failed to find FREE record root in GGPK header");
            }
            while (true)
            {
                linkedList.AddLast(freeRecord);
                long nextFreeOffset = freeRecord.NextFreeOffset;
                if (nextFreeOffset == 0L)
                {
                    return(linkedList);
                }
                if (!recordOffsets.ContainsKey(nextFreeOffset))
                {
                    break;
                }
                freeRecord = (recordOffsets[freeRecord.NextFreeOffset] as FreeRecord);
                if (freeRecord == null)
                {
                    goto Block_5;
                }
            }
            throw new Exception("Failed to find next FREE record in map of record offsets");
Block_5:
            throw new Exception("Found a record that wasn't a FREE record while looking for next FREE record");
        }
Ejemplo n.º 4
0
        internal static DirectoryTreeNode BuildDirectoryTree(Dictionary <long, BaseRecord> recordOffsets)
        {
            GGPKRecord        gGPKRecord        = recordOffsets[0L] as GGPKRecord;
            DirectoryTreeNode directoryTreeNode = new DirectoryTreeNode
            {
                Children = new List <DirectoryTreeNode>(),
                Files    = new List <FileRecord>(),
                Name     = "ROOT",
                Parent   = null,
                Record   = null
            };

            long[] recordOffsets2 = gGPKRecord.RecordOffsets;
            for (int i = 0; i < recordOffsets2.Length; i++)
            {
                long fileOffset = recordOffsets2[i];
                DirectoryTreeMaker.BuildDirectoryTree(fileOffset, directoryTreeNode, recordOffsets);
            }
            return(directoryTreeNode);
        }