public void loadBlueprintsWSD() //Processes the extracted WSD file. { BinaryReader binReader1 = new BinaryReader(fileInput); String versionNumber = System.Text.Encoding.Default.GetString(binReader1.ReadBytes(4)); if (!versionNumber.Equals("AULB")) //Check position in the file, if it's not at the start, skip and check if we have skipped to the correct start position { fileInput.Seek(116, SeekOrigin.Current); versionNumber = System.Text.Encoding.Default.GetString(binReader1.ReadBytes(4)); } if (versionNumber.Equals("AULB")) { fileCount = binReader1.ReadInt32(); //Read how many files will need to be extracted progressBar1.Maximum = fileCount + 4; progressBar1.Visible = true; //for (int i = 0; i < fileCount; i++) //Because the filecount is not always correct.. we have to use a more dynamic way to iterate int i = 0; while (fileInput.Position < fileInput.Length - 1) //While we're not at the end.. { int size = binReader1.ReadInt32(); fileSizes.Add(size); //Add size of file to fileSizes list. String midValues = "" + binReader1.ReadInt64(); int nameLength = binReader1.ReadInt32(); String name = System.Text.Encoding.Default.GetString(binReader1.ReadBytes(nameLength - 1)); binReader1.ReadByte(); fileNames.Add(name, i); //Add name and file number to names hash table fileNamesList.Add(name); int subtypeLength = binReader1.ReadInt32(); string subtype = System.Text.Encoding.Default.GetString(binReader1.ReadBytes(subtypeLength - 1)); //Read in the subtype binReader1.ReadByte(); if (Blueprints.Nodes.ContainsKey(subtype)) //Check if the treeview has this subtype already. { Blueprints.Nodes[subtype].Nodes.Add(name); //Add the file to that subtype } else { Blueprints.Nodes.Add(subtype, subtype); //Create the subtype first Blueprints.Nodes[subtype].Nodes.Add(name); //Add the file to that subtype } byte[] blueprint = null; blueprint = binReader1.ReadBytes((size) - 12 - nameLength - 4 - subtypeLength); //read in file data, ignore header listOfFileArrays.Add(blueprint); //Add extracted file's bytes to list of the data files //MessageBox.Show("Position: " + fileInput.Position + " Size: " + fileInput.Length); //Console.WriteLine("File #: " + i + " Size: " + size + " Int64: " + a + " Name: " + name + "\n"); //Console.Write("\n" + "File #: " + i); //MessageBox.Show(""); //Console.Write(" Size: " + size); //MessageBox.Show(""); //Console.Write(" Int64: " + midValues); //MessageBox.Show(""); //Console.Write(" Subtype: " + subtype); //MessageBox.Show(""); //Console.Write(" Name: " + name); //if (i != fileCount) if (fileInput.Position < fileInput.Length - 1) { while (binReader1.ReadInt32() == 8) { binReader1.ReadInt64(); //Can add line to add current i to List to keep track of every file that has this feature. } fileInput.Seek(fileInput.Position - 4, 0); } extractBlueprintsButton.Visible = true; printListButton.Visible = true; i++; progressBar1.Value++; } progressBar1.Visible = false; progressBar1.Value = 0; //MessageBox.Show(fileNames[fileNames.Count]); Blueprints.Sort(); binReader1.Dispose(); binReader1.Close(); //fileInput.Dispose(); //fileInput.Close(); GC.Collect(); } else { MessageBox.Show("This is not a blueprint archive, valid files are GameTemplates.wsd and Loosefiles_BinPC.pack."); } }
public void loadBlueprintsWSD() //Processes the extracted WSD file. { listOfFileArrays.Clear(); listOfNames.Clear(); fileNames.Clear(); originalStats = null; if (Blueprints.Nodes.Count > 0) { Blueprints.Nodes[0].Remove(); } while (dataGridView1.Rows.Count > 0) { dataGridView1.Rows.RemoveAt(0); } BinaryReader binReader1 = new BinaryReader(fileInput); String versionNumber = System.Text.Encoding.Default.GetString(binReader1.ReadBytes(4)); if (!versionNumber.Equals("AULB")) //Check position in the file, if it's not at the start, skip and check if we have skipped to the correct start position { binReader1.ReadBytes(116); versionNumber = System.Text.Encoding.Default.GetString(binReader1.ReadBytes(4)); } if (versionNumber.Equals("AULB")) { fileCount = binReader1.ReadInt32(); //Read how many files will need to be extracted //for (int i = 0; i < fileCount; i++) //Because the filecount is not always correct.. we have to use a more dynamic way to iterate int i = 0; int wepCount = 0; while (fileInput.Position != fileInput.Length - 1 && fileInput.Position != fileInput.Length) //While we're not at the end.. { int size = binReader1.ReadInt32(); String midValues = "" + binReader1.ReadInt64(); int nameLength = binReader1.ReadInt32(); String name = System.Text.Encoding.Default.GetString(binReader1.ReadBytes(nameLength - 1)); listOfNames.Add(name); binReader1.ReadByte(); int subtypeLength = binReader1.ReadInt32(); string subtype = System.Text.Encoding.Default.GetString(binReader1.ReadBytes(subtypeLength - 1)); //Read in the subtype binReader1.ReadByte(); if (subtype == "Weapon") { fileNames.Add(name, wepCount); //Add name and file number to names hash table wepCount++; if (Blueprints.Nodes.ContainsKey(subtype)) //Check if the treeview has this subtype already. { Blueprints.Nodes[subtype].Nodes.Add(name); //Add the file to that subtype } else { Blueprints.Nodes.Add(subtype, subtype); //Create the subtype first Blueprints.Nodes[subtype].Nodes.Add(name); //Add the file to that subtype } byte[] blueprint = null; blueprint = binReader1.ReadBytes((size) - 12 - nameLength - 4 - subtypeLength); //Read in the header data. listOfFileArrays.Add(blueprint); //Add extracted file's bytes to list of the data files } else { byte[] blueprint = null; blueprint = binReader1.ReadBytes((size) - 12 - nameLength - 4 - subtypeLength); //Read in the header data. } if (fileInput.Position != fileInput.Length - 1 && fileInput.Position != fileInput.Length) { while (binReader1.ReadInt32() == 8) { binReader1.ReadInt64(); //Can add line to add current i to List to keep track of every file that has this feature. } fileInput.Seek(fileInput.Position - 4, 0); } i++; } Blueprints.Sort(); binReader1.Dispose(); binReader1.Close(); GC.Collect(); if (wepCount == 0) { MessageBox.Show("No Will To Fight blueprints were found in this file."); } } else { MessageBox.Show("This is not a blueprint archive, valid files are GameTemplates.wsd and Loosefiles_BinPC.pack."); } }