Exemple #1
0
        public List <PacDir> ReadDir()
        {
            var iOffset   = 16384; //Start of data chunk
            var dirList   = new List <PacDir>();
            var pachParse = new PACHParser();

            pacStream.BaseStream.Seek(2048, SeekOrigin.Begin);

            while (pacStream.BaseStream.Position < (2048 + pacFile.header.listSize))
            {
                var directory = new PacDir();
                directory.id = new string(pacStream.ReadChars(4));
                if (pacFile.header.id == "EPK8")
                {
                    directory.nfiles = (int)pacStream.ReadUInt16() / 4;
                }
                else
                {
                    directory.nfiles = (int)pacStream.ReadUInt16() / 3;
                }
                pacStream.ReadBytes(6);

                directory.PacFiles = new PacFile[directory.nfiles];
                for (int i = 0; i < directory.nfiles; i++)
                {
                    directory.PacFiles[i]        = ReadPacFile();
                    directory.PacFiles[i].offset = iOffset;

                    //Get Pach
                    var pos = pacStream.BaseStream.Position;
                    pacStream.BaseStream.Position = directory.PacFiles[i].offset;

                    directory.PacFiles[i].stream = pacStream.ReadBytes(directory.PacFiles[i].size);

                    directory.PacFiles[i].PACHContainer = pachParse.ReadPACHContainer(directory.PacFiles[i].stream);

                    pacStream.BaseStream.Position = pos;

                    //Need to 2048 byte align these chunks
                    iOffset += directory.PacFiles[i].size + ((2048 - (directory.PacFiles[i].size % 2048)) % 2048);
                }
                dirList.Add(directory);
            }

            return(dirList);
        }
        public List<PacDir> ReadDir()
        {
            var iOffset = 16384; //Start of data chunk
            var dirList = new List<PacDir>();
            var pachParse = new PACHParser();
            pacStream.BaseStream.Seek(2048, SeekOrigin.Begin);

            while (pacStream.BaseStream.Position < (2048 + pacFile.header.listSize))
            {
                var directory = new PacDir();
                directory.id = new string(pacStream.ReadChars(4));
                if (pacFile.header.id == "EPK8")
                {
                    directory.nfiles = (int)pacStream.ReadUInt16() / 4;
                }
                else
                {
                    directory.nfiles = (int)pacStream.ReadUInt16() / 3;
                }
                pacStream.ReadBytes(6);

                directory.PacFiles = new PacFile[directory.nfiles];
                for (int i = 0; i < directory.nfiles; i++)
                {
                    directory.PacFiles[i] = ReadPacFile();
                    directory.PacFiles[i].offset = iOffset;

                    //Get Pach
                    var pos = pacStream.BaseStream.Position;
                    pacStream.BaseStream.Position = directory.PacFiles[i].offset;

                    directory.PacFiles[i].stream = pacStream.ReadBytes(directory.PacFiles[i].size);

                    directory.PacFiles[i].PACHContainer = pachParse.ReadPACHContainer(directory.PacFiles[i].stream);

                    pacStream.BaseStream.Position = pos;

                    //Need to 2048 byte align these chunks
                    iOffset += directory.PacFiles[i].size + ((2048 - (directory.PacFiles[i].size % 2048)) % 2048);
                }
                dirList.Add(directory);
            }

            return dirList;
        }
Exemple #3
0
        //Check the node type and populate the listview based on it.
        void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            TreeNode newSelected = e.Node;

            listView1.Items.Clear();
            ListViewItem item = null;

            ListViewItem.ListViewSubItem[] subItems;


            //right click = extract all menu.
            if (e.Button == MouseButtons.Right)
            {
                if (newSelected.Bounds.Contains(e.Location) == true)
                {
                    contextMenuStrip2.Show(Cursor.Position);
                }
            }

            if (newSelected.Tag != null)
            {
                if (newSelected.Tag.GetType().Equals(typeof(TextureArchive[])))
                {
                    //TextureArchive textures
                    TextureArchive[] textures = (TextureArchive[])newSelected.Tag;
                    foreach (var texture in textures)
                    {
                        var file = texture.alignedstring.Replace("\0", string.Empty).Trim() + "." + texture.extension.Replace("\0", string.Empty).Trim();

                        item     = new ListViewItem(file, 2);
                        item.Tag = texture;
                        subItems = new ListViewItem.ListViewSubItem[]
                        {
                            new ListViewItem.ListViewSubItem(item, texture.extension)
                            , new ListViewItem.ListViewSubItem(item, texture.size.ToString())
                        };
                        item.SubItems.AddRange(subItems);
                        listView1.Items.Add(item);
                    }
                }
                else if (newSelected.Tag.GetType().Equals(typeof(PacDir)))
                {
                    PacDir nodeDirInfo = (PacDir)newSelected.Tag;

                    if (nodeDirInfo.PacFiles != null)
                    {
                        foreach (var file in nodeDirInfo.PacFiles)
                        {
                            item     = new ListViewItem(file.id, 2);
                            item.Tag = file;
                            subItems = new ListViewItem.ListViewSubItem[]
                            {
                                new ListViewItem.ListViewSubItem(item, file.PACHContainer.id.ToString())  //Header of the contained file
                                , new ListViewItem.ListViewSubItem(item, file.size.ToString())
                            };
                            item.SubItems.AddRange(subItems);
                            listView1.Items.Add(item);
                        }
                    }
                }
                else if (newSelected.Tag.GetType().Equals(typeof(PACH)))
                {
                    PACH nodeDirInfo = (PACH)newSelected.Tag;

                    if (nodeDirInfo.PACHFiles != null)
                    {
                        foreach (var file in nodeDirInfo.PACHFiles)
                        {
                            var subFileText = new byte[4];
                            Array.Copy(file.stream, 0, subFileText, 0, 4);
                            var name = System.Text.Encoding.UTF8.GetString(subFileText);

                            item     = new ListViewItem(file.id, 1);
                            item.Tag = file;
                            subItems = new ListViewItem.ListViewSubItem[]
                            {
                                new ListViewItem.ListViewSubItem(item, name) //Type
                                , new ListViewItem.ListViewSubItem(item, file.size.ToString())
                            };
                            item.SubItems.AddRange(subItems);
                            listView1.Items.Add(item);
                        }
                    }
                }
                else if (newSelected.Tag.GetType().Equals(typeof(PACHFile)))
                {
                    PACHFile nodeDirInfo = (PACHFile)newSelected.Tag;
                    if (nodeDirInfo.SubContainer != null) //more pach files...
                    {
                        foreach (PACHFile subFile in nodeDirInfo.SubContainer.PACHFiles)
                        {
                            var subFileText = new byte[4];
                            Array.Copy(subFile.stream, 0, subFileText, 0, 4);
                            var name = System.Text.Encoding.UTF8.GetString(subFileText);

                            item     = new ListViewItem(subFile.id, 1);
                            item.Tag = subFile;
                            subItems = new ListViewItem.ListViewSubItem[]
                            {
                                new ListViewItem.ListViewSubItem(item, name)  //Type
                                , new ListViewItem.ListViewSubItem(item, subFile.size.ToString())
                            };
                            item.SubItems.AddRange(subItems);
                            listView1.Items.Add(item);
                        }
                    }
                    else if (nodeDirInfo.TexContainer != null) // Texture files
                    {
                        foreach (TextureArchive subFile in nodeDirInfo.TexContainer)
                        {
                            var file = subFile.alignedstring.Replace("\0", string.Empty).Trim() + "." + subFile.extension.Replace("\0", string.Empty).Trim();

                            item     = new ListViewItem(file, 2);
                            item.Tag = subFile;
                            subItems = new ListViewItem.ListViewSubItem[]
                            {
                                new ListViewItem.ListViewSubItem(item, subFile.extension)  //Header of the contained file
                                , new ListViewItem.ListViewSubItem(item, subFile.size.ToString())
                            };
                            item.SubItems.AddRange(subItems);
                            listView1.Items.Add(item);
                        }
                    }
                    else //Everything else
                    {
                        var subFileText = new byte[4];
                        Array.Copy(nodeDirInfo.stream, 0, subFileText, 0, 4);
                        var name = System.Text.Encoding.UTF8.GetString(subFileText);

                        item     = new ListViewItem(nodeDirInfo.id, 1);
                        item.Tag = nodeDirInfo;
                        subItems = new ListViewItem.ListViewSubItem[]
                        {
                            new ListViewItem.ListViewSubItem(item, name) //Type
                            , new ListViewItem.ListViewSubItem(item, nodeDirInfo.size.ToString())
                        };
                        item.SubItems.AddRange(subItems);
                        listView1.Items.Add(item);
                    }
                }
                else if (newSelected.Tag.GetType().Equals(typeof(PacFile)))
                {
                    PacFile nodeDirInfo = (PacFile)newSelected.Tag;

                    if (nodeDirInfo.PACHContainer.PACHFiles != null)
                    {
                        foreach (var file in nodeDirInfo.PACHContainer.PACHFiles)
                        {
                            var subFileText = new byte[4];
                            Array.Copy(file.stream, 0, subFileText, 0, 4);
                            var name = System.Text.Encoding.UTF8.GetString(subFileText);

                            item     = new ListViewItem(file.id, 1);
                            item.Tag = file;
                            subItems = new ListViewItem.ListViewSubItem[]
                            {
                                new ListViewItem.ListViewSubItem(item, name) //Type
                                , new ListViewItem.ListViewSubItem(item, file.size.ToString())
                            };
                            item.SubItems.AddRange(subItems);
                            listView1.Items.Add(item);
                        }
                    }
                }
            }
            listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
        }
Exemple #4
0
 private void GetDirectories(PacDir[] subDirs, TreeNode nodeToAddTo)
 {
     TreeNode aNode;
     foreach (PacDir subDir in subDirs)
     {
         aNode = new TreeNode(subDir.id, 0, 0);
         aNode.Tag = subDir;
         aNode.ImageKey = "folder";
         GetPACFileDirectories(subDir.PacFiles, aNode);
         nodeToAddTo.Nodes.Add(aNode);
     }
 }