예제 #1
0
        public void AddFileToFST(string fileName, uint size, string inDirectory = "")
        {
            var addDir = rootDirectory;

            if (inDirectory != string.Empty)
            {
                addDir = rootDirectory.SearchForDirectory(inDirectory);
            }

            if (addDir == null)
            {
                return;
            }

            var lastEntry = GetFlattenedFST()
                            .OrderBy(f =>
            {
                return(f is FSTFileEntry fe ? fe.FileDataOffset : 0);
            })
                            .Last() as FSTFileEntry;

            var nameBytes   = new UnicodeString(fileName.ToArray());
            var entryIndex  = addDir.EndEntry + 1;
            var entryOffset = lastEntry.FileDataOffset + lastEntry.Size;
            var newEntry    = new FSTFileEntry(entryIndex, LastNameOffset, entryOffset, size)
            {
                Name = nameBytes
            };

            LastNameOffset += (uint)nameBytes.Count;
        }
예제 #2
0
        void LoadFST(FSTDirectory root, int endEntryIndex, int firstEntryIndex = 1)
        {
            int index = firstEntryIndex;

            while (index < endEntryIndex)
            {
                var entryOffset = index * 12;
                var folder      = ExtractedFile.GetByteAtOffset(entryOffset) == 1;

                FSTEntry fileEntry;
                uint     nameOffset;
                if (folder)
                {
                    nameOffset = (ExtractedFile.GetUIntAtOffset(entryOffset) & 0x00FFFFFF);
                    var parentEntry = ExtractedFile.GetIntAtOffset(entryOffset + 4);
                    var endDirEntry = ExtractedFile.GetIntAtOffset(entryOffset + 8);
                    var directory   = new FSTDirectory(index, nameOffset, parentEntry);

                    LoadFST(directory, endDirEntry, index + 1);
                    fileEntry = directory;
                    index    += endDirEntry - index;
                }
                else
                {
                    nameOffset = ExtractedFile.GetUIntAtOffset(entryOffset);
                    var fileOffset = ExtractedFile.GetUIntAtOffset(entryOffset + 4);
                    var fileSize   = ExtractedFile.GetUIntAtOffset(entryOffset + 8);
                    fileEntry = new FSTFileEntry(index, nameOffset, fileOffset, fileSize);
                    index++;
                    if (fileOffset < StartDataOffset)
                    {
                        StartDataOffset = fileOffset;
                    }
                }

                if (nameOffset > LastNameOffset)
                {
                    LastNameOffset = nameOffset;
                }

                var fileName = ExtractedFile.GetStringAtOffset(nameOffset + TOCFirstStringOffset);
                fileEntry.Name = fileName;
                root.Children.Add(fileEntry);
            }
        }