Ejemplo n.º 1
0
        public bool fileExists(string name)
        {
            Framework.Bot.Structs.PK2File.pk2File file = Files.Find(item => item.name.ToLower() == name.ToLower());

            if (file.position != 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        public byte[] getFile(string name)
        {
            if (fileExists(name))
            {
                BinaryReader reader = new BinaryReader(fileStream);
                Framework.Bot.Structs.PK2File.pk2File file = Files.Find(item => item.name.ToLower() == name.ToLower());
                reader.BaseStream.Position = file.position;

                return(reader.ReadBytes((int)file.size));
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 3
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);
            }
        }