Esempio n. 1
0
        public PK2Class(string pk2FilePath)
        {
            if (File.Exists(pk2FilePath))
            {
                fileStream = new FileStream(pk2FilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
                blowfish.Initialize(bKey);
                BinaryReader reader = new BinaryReader(fileStream);
                header                   = (Framework.Bot.Structs.PK2File.pk2Header)BufferToStruct(reader.ReadBytes(256), typeof(Framework.Bot.Structs.PK2File.pk2Header));
                currentFolder            = new Framework.Bot.Structs.PK2File.pk2Folder();
                currentFolder.name       = pk2FilePath;
                currentFolder.files      = new List <Framework.Bot.Structs.PK2File.pk2File>();
                currentFolder.subfolders = new List <Framework.Bot.Structs.PK2File.pk2Folder>();

                mainFolder = currentFolder;
                read(reader.BaseStream.Position);
            }
        }
Esempio n. 2
0
        public void read(Int64 position)
        {
            BinaryReader reader = new BinaryReader(fileStream);

            reader.BaseStream.Position = position;
            List <Framework.Bot.Structs.PK2File.pk2Folder> tmpFolders = new List <Framework.Bot.Structs.PK2File.pk2Folder>();

            Framework.Bot.Structs.PK2File.pk2EntryBlock entryBlock = (Framework.Bot.Structs.PK2File.pk2EntryBlock)BufferToStruct(blowfish.Decode(reader.ReadBytes(Marshal.SizeOf(typeof(Framework.Bot.Structs.PK2File.pk2EntryBlock)))), typeof(Framework.Bot.Structs.PK2File.pk2EntryBlock));

            for (int i = 0; i < 20; i++)
            {
                Framework.Bot.Structs.PK2File.pk2Entry entry = entryBlock.entries[i];

                switch (entry.type)
                {
                case 0:
                    break;

                case 1:
                    if (entry.name != "." && entry.name != "..")
                    {
                        Framework.Bot.Structs.PK2File.pk2Folder tmpFolder = new Framework.Bot.Structs.PK2File.pk2Folder();
                        tmpFolder.name     = entry.name;
                        tmpFolder.position = BitConverter.ToInt64(entry.position, 0);
                        tmpFolders.Add(tmpFolder);
                        Folders.Add(tmpFolder);

                        if (tmpFolder != null && currentFolder.subfolders == null)
                        {
                            currentFolder.subfolders = new List <Framework.Bot.Structs.PK2File.pk2Folder>();
                        }

                        currentFolder.subfolders.Add(tmpFolder);
                    }
                    break;

                case 2:
                {
                    Framework.Bot.Structs.PK2File.pk2File tmpFile = new Framework.Bot.Structs.PK2File.pk2File();
                    tmpFile.position     = entry.Position;
                    tmpFile.name         = entry.name;
                    tmpFile.size         = entry.Size;
                    tmpFile.parentFolder = currentFolder;
                    Files.Add(tmpFile);

                    currentFolder.files.Add(tmpFile);
                }
                break;
                }
            }

            if (entryBlock.entries[19].nChain != 0)
            {
                read(entryBlock.entries[19].nChain);
            }

            foreach (Framework.Bot.Structs.PK2File.pk2Folder folder in tmpFolders)
            {
                currentFolder = folder;

                if (folder.files == null)
                {
                    folder.files = new List <Framework.Bot.Structs.PK2File.pk2File>();
                }
                else if (folder.subfolders == null)
                {
                    folder.subfolders = new List <Framework.Bot.Structs.PK2File.pk2Folder>();
                }

                read(folder.position);
            }
        }