private void OpenFile(string filename) { switch (Path.GetExtension(filename)) { case ".bin": case ".g1t": { currentG1T = new G1T(); currentG1T.Read(filename); foreach (G1Texture tex in currentG1T.Textures) { textureListBox.Items.Add(tex); } } break; case ".dds": { DDS temp = new DDS(); temp.Read(filename); pictureBox1.Image = temp.Texture.GetBitmap(); } break; default: { MessageBox.Show("This file format is not supported yet.", "Unsupported file format"); } break; } }
private void ReplaceG1T_Click(object sender, EventArgs e) { using (var opendialog = new OpenFileDialog()) { opendialog.Filter = "Koei Tecmo texture archive|*.g1t"; if (opendialog.ShowDialog() == DialogResult.OK) { using (var fs = new FileStream(opendialog.FileName, FileMode.Open)) { int fileSize = (int)new FileInfo(opendialog.FileName).Length; byte[] buffer = new byte[fileSize]; fs.Read(buffer, 0, fileSize); var newG1T = new G1T(); newG1T.Read(buffer); treeView1.SelectedNode.Nodes.Clear(); for (int i = 0; i < newG1T.Textures.Count; i++) { treeView1.SelectedNode.Nodes.Add(i.ToString() + ".dds"); } if (FormatIndex == NodeIndexBin && treeView1.Nodes.ContainsKey("BIN")) { BinFileList[treeView1.SelectedNode.Parent.Index][treeView1.SelectedNode.Index] = newG1T; LoadImage(BinFileList[treeView1.SelectedNode.Parent.Index][treeView1.SelectedNode.Index].Textures[treeView1.SelectedNode.FirstNode.Index]); } if (FormatIndex == NodeIndexG1T && treeView1.Nodes.ContainsKey("G1T")) { G1TFileList[treeView1.SelectedNode.Parent.Index] = newG1T; LoadImage(G1TFileList[treeView1.SelectedNode.Index].Textures[treeView1.SelectedNode.FirstNode.Index]); } } } } }
private void OpenFile() { BinFileList = new List <List <G1T> >(); G1TFileList = new List <G1T>(); var imageList = new ImageList(); imageList.ColorDepth = ColorDepth.Depth32Bit; #region BIN for (int i = 0; i < FilePathBinGZList.Count; i++) { imageList.Images.Add(i.ToString(), Icon.ExtractAssociatedIcon(FilePathBinGZList[i])); var node = new TreeNode() { Text = Path.GetFileName(FilePathBinGZList[i]), ImageKey = i.ToString(), SelectedImageKey = i.ToString(), }; treeView1.Nodes[NodeIndexBin].Nodes.Add(node); BinFile = new KTBin(); var binEntries = new List <G1T>(); var dummyEntry = new G1T(); BinFile.Read(FilePathBinGZList[i]); for (int ii = 0; ii < BinFile.FileList.Count; ii++) { if (BinFile.FileList[ii].Length != 0) { #region Compressed Entries try { int magicID = BitConverter.ToInt32(KTGZip.Decompress(BinFile.FileList[ii]), 0x0); switch (magicID) { case (0x47314D5F): // G1M_ { treeView1.Nodes[NodeIndexBin].Nodes[i].Nodes.Add(new TreeNode(ii.ToString() + ".g1m")); binEntries.Add(dummyEntry); } break; case (0x47315447): // G1TG { treeView1.Nodes[NodeIndexBin].Nodes[i].Nodes.Add(new TreeNode(ii.ToString() + ".g1t")); var g1t = new G1T(); g1t.Read(KTGZip.Decompress(BinFile.FileList[ii])); for (int iii = 0; iii < g1t.Textures.Count; iii++) { treeView1.Nodes[NodeIndexBin].Nodes[i].Nodes[ii].Nodes.Add(iii.ToString() + ".dds"); } binEntries.Add(g1t); } break; default: { treeView1.Nodes[NodeIndexBin].Nodes[i].Nodes.Add(new TreeNode(ii.ToString() + ".bin")); binEntries.Add(dummyEntry); } break; } } #endregion // Need a new list to make sure to not compress when saving #region Uncompressed Entries catch (Exception) { int magicID = BitConverter.ToInt32(BinFile.FileList[ii], 0x0); switch (magicID) { case (0x47314D5F): // G1M_ { treeView1.Nodes[NodeIndexBin].Nodes[i].Nodes.Add(new TreeNode(ii.ToString() + ".g1m")); binEntries.Add(dummyEntry); } break; case (0x47315447): // G1TG { var g1tList = new List <List <G1Texture> >(); treeView1.Nodes[NodeIndexBin].Nodes[i].Nodes.Add(new TreeNode(ii.ToString() + ".g1t")); var g1t = new G1T(); g1t.Read(BinFile.FileList[ii]); for (int iii = 0; iii < g1t.Textures.Count; iii++) { treeView1.Nodes[NodeIndexBin].Nodes[i].Nodes[ii].Nodes.Add(iii.ToString() + ".dds"); } binEntries.Add(g1t); } break; default: { treeView1.Nodes[NodeIndexBin].Nodes[i].Nodes.Add(new TreeNode(ii.ToString() + ".bin")); binEntries.Add(dummyEntry); } break; } // New List for bin with uncompressed files if (!FilePathBinList.Contains(FilePathBinGZList[i])) { FilePathBinList.Add(FilePathBinGZList[i]); } } #endregion } #region Dummy Entries else { treeView1.Nodes[NodeIndexBin].Nodes[i].Nodes.Add(new TreeNode(ii.ToString() + ".bin")); binEntries.Add(dummyEntry); } } #endregion BinFileList.Add(binEntries); } // Remove bin with uncompressed files from binGZ for (int i = 0; i < FilePathBinList.Count; i++) { FilePathBinGZList.RemoveAt(FilePathBinGZList.IndexOf(FilePathBinList[i])); } #endregion #region G1T for (int i = 0; i < FilePathG1TList.Count; i++) { imageList.Images.Add(i.ToString(), Icon.ExtractAssociatedIcon(FilePathG1TList[i])); var node = new TreeNode() { Text = Path.GetFileName(FilePathG1TList[i]), ImageKey = i.ToString(), SelectedImageKey = i.ToString(), }; treeView1.Nodes[NodeIndexG1T].Nodes.Add(node); using (var fs = new FileStream(FilePathG1TList[i], FileMode.Open)) { int fileSize = (int)new FileInfo(FilePathG1TList[i]).Length; byte[] buffer = new byte[fileSize]; fs.Read(buffer, 0, fileSize); var g1t = new G1T(); g1t.Read(buffer); for (int ii = 0; ii < g1t.Textures.Count; ii++) { treeView1.Nodes[NodeIndexG1T].Nodes[i].Nodes.Add(new TreeNode(ii.ToString() + ".dds")); } G1TFileList.Add(g1t); } } #endregion /* * switch (Path.GetExtension(openFileDialog.FileNames[i])) * { #region GZ * case ".gz": * { * using (var fs = new FileStream(openFileDialog.FileNames[i], FileMode.Open)) * { * var ktGZip = new KTGZip(); * int fileSize = (int)new FileInfo(openFileDialog.FileNames[i]).Length; * byte[] buffer = new byte[fileSize]; * fs.Read(buffer, 0, fileSize); * * currentG1T = new G1T(); * currentG1T.Read(ktGZip.Decompress(buffer)); * } * var list = new List<string>(); * list.Add(Path.GetFileNameWithoutExtension(openFileDialog.FileNames[i])); * * } * break; #endregion #region DDS * case ".dds": * { * treeView1.Nodes[3].Nodes.Add(node); * * DDS temp = new DDS(); * temp.Read(openFileDialog.FileNames[i]); * pictureBox1.Image = temp.Texture.GetBitmap(); * } * break; * } #endregion */ treeView1.ImageList = imageList; }