private TabPage ProcessFile(string fileName, byte[] input = null) { var tab = new TabPage(); if (fileName.EndsWith(".vpk", StringComparison.Ordinal)) { var package = new Package(); if (input != null) { package.SetFileName(fileName); package.Read(new MemoryStream(input)); } else { package.Read(fileName); } // create a TreeView with search capabilities, register its events, and add it to the tab var treeViewWithSearch = new GUI.Controls.TreeViewWithSearchResults(ImageList); treeViewWithSearch.Dock = DockStyle.Fill; treeViewWithSearch.InitializeTreeViewFromPackage("treeViewVpk", package); treeViewWithSearch.TreeNodeMouseDoubleClick += VPK_OpenFile; treeViewWithSearch.TreeNodeMouseClick += VPK_OnClick; treeViewWithSearch.ListViewItemDoubleClick += VPK_OpenFile; treeViewWithSearch.ListViewItemRightClick += VPK_OnClick; tab.Controls.Add(treeViewWithSearch); // since we're in a separate thread, invoke to update the UI this.Invoke((MethodInvoker)delegate { findToolStripButton.Enabled = true; }); } else { var resource = new Resource(); if (input != null) { resource.Read(new MemoryStream(input)); } else { resource.Read(fileName); } var resTabs = new TabControl(); resTabs.Dock = DockStyle.Fill; switch (resource.ResourceType) { case ResourceType.Texture: var tab2 = new TabPage("TEXTURE"); tab2.AutoScroll = true; try { var tex = (Texture)resource.Blocks[BlockType.DATA]; var control = new Forms.Texture(); control.BackColor = Color.Black; control.SetImage(tex.GenerateBitmap(), Path.GetFileNameWithoutExtension(fileName), tex.Width, tex.Height); tab2.Controls.Add(control); } catch (Exception e) { var control = new TextBox { Dock = DockStyle.Fill, Font = new Font(FontFamily.GenericMonospace, 8), Multiline = true, ReadOnly = true, Text = e.ToString() }; tab2.Controls.Add(control); } resTabs.TabPages.Add(tab2); break; case ResourceType.Panorama: if (((Panorama)resource.Blocks[BlockType.DATA]).Names.Count > 0) { var nameTab = new TabPage("PANORAMA NAMES"); var nameControl = new DataGridView(); nameControl.Dock = DockStyle.Fill; nameControl.AutoSize = true; nameControl.ReadOnly = true; nameControl.AllowUserToAddRows = false; nameControl.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; nameControl.DataSource = new BindingSource(new BindingList<Panorama.NameEntry>(((Panorama)resource.Blocks[BlockType.DATA]).Names), null); nameTab.Controls.Add(nameControl); resTabs.TabPages.Add(nameTab); } break; } foreach (var block in resource.Blocks) { if (block.Key == BlockType.RERL) { var externalRefsTab = new TabPage("External Refs"); var externalRefs = new DataGridView(); externalRefs.Dock = DockStyle.Fill; externalRefs.AutoGenerateColumns = true; externalRefs.AutoSize = true; externalRefs.ReadOnly = true; externalRefs.AllowUserToAddRows = false; externalRefs.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; externalRefs.DataSource = new BindingSource(new BindingList<ResourceExtRefList.ResourceReferenceInfo>(resource.ExternalReferences.ResourceRefInfoList), null); externalRefsTab.Controls.Add(externalRefs); resTabs.TabPages.Add(externalRefsTab); continue; } if (block.Key == BlockType.NTRO) { if (((ResourceIntrospectionManifest)block.Value).ReferencedStructs.Count > 0) { var externalRefsTab = new TabPage("Introspection Manifest: Structs"); var externalRefs = new DataGridView(); externalRefs.Dock = DockStyle.Fill; externalRefs.AutoGenerateColumns = true; externalRefs.AutoSize = true; externalRefs.ReadOnly = true; externalRefs.AllowUserToAddRows = false; externalRefs.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; externalRefs.DataSource = new BindingSource(new BindingList<ResourceIntrospectionManifest.ResourceDiskStruct>(((ResourceIntrospectionManifest)block.Value).ReferencedStructs), null); externalRefsTab.Controls.Add(externalRefs); resTabs.TabPages.Add(externalRefsTab); } if (((ResourceIntrospectionManifest)block.Value).ReferencedEnums.Count > 0) { var externalRefsTab = new TabPage("Introspection Manifest: Enums"); var externalRefs2 = new DataGridView(); externalRefs2.Dock = DockStyle.Fill; externalRefs2.AutoGenerateColumns = true; externalRefs2.AutoSize = true; externalRefs2.ReadOnly = true; externalRefs2.AllowUserToAddRows = false; externalRefs2.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; externalRefs2.DataSource = new BindingSource(new BindingList<ResourceIntrospectionManifest.ResourceDiskEnum>(((ResourceIntrospectionManifest)block.Value).ReferencedEnums), null); externalRefsTab.Controls.Add(externalRefs2); resTabs.TabPages.Add(externalRefsTab); } //continue; } var tab2 = new TabPage(block.Key.ToString()); var control = new TextBox(); control.Font = new Font(FontFamily.GenericMonospace, control.Font.Size); try { control.Text = block.Value.ToString().Replace("\r", ""); //Prevent copy+paste with double new line control.Text = block.Value.ToString().Replace("\n", Environment.NewLine); //make sure panorama is new lines } catch (Exception e) { control.Text = e.ToString(); } control.Dock = DockStyle.Fill; control.Multiline = true; control.ReadOnly = true; control.ScrollBars = ScrollBars.Both; tab2.Controls.Add(control); resTabs.TabPages.Add(tab2); } tab.Controls.Add(resTabs); } return tab; }
private TabPage ProcessFile(string fileName, byte[] input = null) { var tab = new TabPage(); if (fileName.EndsWith(".vpk", StringComparison.Ordinal)) { var package = new Package(); if (input != null) { package.SetFileName(fileName); package.Read(new MemoryStream(input)); } else { package.Read(fileName); } // create a TreeView with search capabilities, register its events, and add it to the tab var treeViewWithSearch = new GUI.Controls.TreeViewWithSearchResults(ImageList); treeViewWithSearch.Dock = DockStyle.Fill; treeViewWithSearch.InitializeTreeViewFromPackage("treeViewVpk", package); treeViewWithSearch.TreeNodeMouseDoubleClick += VPK_OpenFile; treeViewWithSearch.TreeNodeMouseClick += VPK_OnClick; treeViewWithSearch.ListViewItemDoubleClick += VPK_OpenFile; treeViewWithSearch.ListViewItemRightClick += VPK_OnClick; tab.Controls.Add(treeViewWithSearch); // since we're in a separate thread, invoke to update the UI this.Invoke((MethodInvoker) delegate { findToolStripButton.Enabled = true; }); } else { var resource = new Resource(); if (input != null) { resource.Read(new MemoryStream(input)); } else { resource.Read(fileName); } var resTabs = new TabControl(); resTabs.Dock = DockStyle.Fill; switch (resource.ResourceType) { case ResourceType.Texture: var tab2 = new TabPage("TEXTURE"); tab2.AutoScroll = true; try { var tex = (Texture)resource.Blocks[BlockType.DATA]; var control = new Forms.Texture(); control.BackColor = Color.Black; control.SetImage(tex.GenerateBitmap(), Path.GetFileNameWithoutExtension(fileName), tex.Width, tex.Height); tab2.Controls.Add(control); } catch (Exception e) { var control = new TextBox { Dock = DockStyle.Fill, Font = new Font(FontFamily.GenericMonospace, 8), Multiline = true, ReadOnly = true, Text = e.ToString() }; tab2.Controls.Add(control); } resTabs.TabPages.Add(tab2); break; case ResourceType.Panorama: if (((Panorama)resource.Blocks[BlockType.DATA]).Names.Count > 0) { var nameTab = new TabPage("PANORAMA NAMES"); var nameControl = new DataGridView(); nameControl.Dock = DockStyle.Fill; nameControl.AutoSize = true; nameControl.ReadOnly = true; nameControl.AllowUserToAddRows = false; nameControl.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; nameControl.DataSource = new BindingSource(new BindingList <Panorama.NameEntry>(((Panorama)resource.Blocks[BlockType.DATA]).Names), null); nameTab.Controls.Add(nameControl); resTabs.TabPages.Add(nameTab); } break; } foreach (var block in resource.Blocks) { if (block.Key == BlockType.RERL) { var externalRefsTab = new TabPage("External Refs"); var externalRefs = new DataGridView(); externalRefs.Dock = DockStyle.Fill; externalRefs.AutoGenerateColumns = true; externalRefs.AutoSize = true; externalRefs.ReadOnly = true; externalRefs.AllowUserToAddRows = false; externalRefs.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; externalRefs.DataSource = new BindingSource(new BindingList <ResourceExtRefList.ResourceReferenceInfo>(resource.ExternalReferences.ResourceRefInfoList), null); externalRefsTab.Controls.Add(externalRefs); resTabs.TabPages.Add(externalRefsTab); continue; } if (block.Key == BlockType.NTRO) { if (((ResourceIntrospectionManifest)block.Value).ReferencedStructs.Count > 0) { var externalRefsTab = new TabPage("Introspection Manifest: Structs"); var externalRefs = new DataGridView(); externalRefs.Dock = DockStyle.Fill; externalRefs.AutoGenerateColumns = true; externalRefs.AutoSize = true; externalRefs.ReadOnly = true; externalRefs.AllowUserToAddRows = false; externalRefs.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; externalRefs.DataSource = new BindingSource(new BindingList <ResourceIntrospectionManifest.ResourceDiskStruct>(((ResourceIntrospectionManifest)block.Value).ReferencedStructs), null); externalRefsTab.Controls.Add(externalRefs); resTabs.TabPages.Add(externalRefsTab); } if (((ResourceIntrospectionManifest)block.Value).ReferencedEnums.Count > 0) { var externalRefsTab = new TabPage("Introspection Manifest: Enums"); var externalRefs2 = new DataGridView(); externalRefs2.Dock = DockStyle.Fill; externalRefs2.AutoGenerateColumns = true; externalRefs2.AutoSize = true; externalRefs2.ReadOnly = true; externalRefs2.AllowUserToAddRows = false; externalRefs2.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; externalRefs2.DataSource = new BindingSource(new BindingList <ResourceIntrospectionManifest.ResourceDiskEnum>(((ResourceIntrospectionManifest)block.Value).ReferencedEnums), null); externalRefsTab.Controls.Add(externalRefs2); resTabs.TabPages.Add(externalRefsTab); } //continue; } var tab2 = new TabPage(block.Key.ToString()); var control = new TextBox(); control.Font = new Font(FontFamily.GenericMonospace, control.Font.Size); try { control.Text = block.Value.ToString(); if (resource.ResourceType == ResourceType.Panorama) { control.Text = control.Text.Replace("\n", Environment.NewLine); //make sure panorama is new lines } } catch (Exception e) { control.Text = e.ToString(); } control.Dock = DockStyle.Fill; control.Multiline = true; control.ReadOnly = true; control.ScrollBars = ScrollBars.Both; tab2.Controls.Add(control); resTabs.TabPages.Add(tab2); } tab.Controls.Add(resTabs); } return(tab); }