private void option1ToolStripMenuItem_Click(object sender, EventArgs e) { foreach (ListViewItem item in listView1.SelectedItems) { string name = Path.GetDirectoryName(file) + "\\" + item.SubItems[0].Text; if (item.Tag.GetType().Equals(typeof(TextureArchive))) { TextureArchive texfile = (TextureArchive)item.Tag; efile.ExtractFile(texfile.stream, name); } if (item.Tag.GetType().Equals(typeof(PacFile))) { PacFile pacfile = (PacFile)item.Tag; efile.ExtractFile(pacfile.stream, name); } if (item.Tag.GetType().Equals(typeof(PACHFile))) { PACHFile pachfile = (PACHFile)item.Tag; efile.ExtractFile(pachfile.stream, name); } if (item.Tag.GetType().Equals(typeof(PACH))) { PACH pachcontainer = (PACH)item.Tag; efile.ExtractFile(pachcontainer.PACHFiles[0].stream, name); } } }
PACHFile ReadPACHheader(BinaryReader pachStream) { var pachfile = new PACHFile(); pachfile.id = pachStream.ReadInt32().ToString(); pachfile.offset = (int)pachStream.ReadUInt32(); pachfile.size = (int)pachStream.ReadUInt32(); return(pachfile); }
private void extractAll(TreeNode treeNode, string path) { if (treeNode.Tag.GetType().Equals(typeof(PACHFile))) { PACHFile pfile = (PACHFile)treeNode.Tag; if (pfile.SubContainer != null) { foreach (PACHFile sfile in pfile.SubContainer.PACHFiles) { if (sfile.SubContainer == null && sfile.TexContainer == null) { var filepath = Path.GetDirectoryName(file) + "\\" + path + "\\" + sfile.id; efile.ExtractFile(sfile.stream, filepath); } } } if (pfile.TexContainer != null) { foreach (TextureArchive sfile in pfile.TexContainer) { var name = sfile.alignedstring.Replace("\0", string.Empty).Trim() + "." + sfile.extension.Replace("\0", string.Empty).Trim(); var filepath = Path.GetDirectoryName(file) + "\\" + path + "\\" + name; efile.ExtractFile(sfile.stream, filepath); } } } if (treeNode.Tag.GetType().Equals(typeof(PacFile))) { PacFile pfile = (PacFile)treeNode.Tag; if (pfile.PACHContainer != null) { foreach (PACHFile sfile in pfile.PACHContainer.PACHFiles) { if (sfile.SubContainer == null && sfile.TexContainer == null) { var filepath = Path.GetDirectoryName(file) + "\\" + path + "\\" + sfile.id; efile.ExtractFile(sfile.stream, filepath); } } } } }
PACHFile ReadPACHheader(BinaryReader pachStream) { var pachfile = new PACHFile(); pachfile.id = pachStream.ReadInt32().ToString(); pachfile.offset = (int)pachStream.ReadUInt32(); pachfile.size = (int)pachStream.ReadUInt32(); return pachfile; }
//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); }
private void GetPACHFileDirectories(PACHFile[] subDirs, TreeNode nodeToAddTo) { TreeNode aNode; foreach (PACHFile subDir in subDirs) { if (subDir.SubContainer != null) //More pachs... { aNode = new TreeNode(subDir.id, 0, 0); aNode.Tag = subDir; aNode.ImageKey = "Container"; GetPACHFileDirectories(subDir.SubContainer.PACHFiles, aNode); nodeToAddTo.Nodes.Add(aNode); } else if (subDir.TexContainer != null) //Texture archive { aNode = new TreeNode(subDir.id, 0, 0); aNode.Tag = subDir; aNode.ImageKey = "Container"; nodeToAddTo.Nodes.Add(aNode); } } }