private void btnBuildPack_Click(object sender, EventArgs e) // Build Pack button { FolderBrowserDialog oFolder = new FolderBrowserDialog(); SaveFileDialog sFile = new SaveFileDialog(); if (cbxSetDataOffset.Checked) { try{ int.Parse(tbxDataOffset.Text, System.Globalization.NumberStyles.HexNumber); } //check if it's a hex value (textbox limited to 4 characters) catch { MessageBox.Show("Error:" + "\n\n" + "Fixed Data Offset is not a hex value!"); goto toss; } } oFolder.Description = "Select folder to build into Pack file"; if (tbxFolderRoot.Text != "") { oFolder.SelectedPath = tbxFolderRoot.Text; } if (oFolder.ShowDialog() == DialogResult.Cancel) { goto toss; } int numFiles = Directory.GetFiles(oFolder.SelectedPath, "*", SearchOption.AllDirectories).Length; sFile.Filter = "PACK|*.pack|SARC|*.sarc|SSARC|*.ssarc|RARC|*.rarc|SGENVB|*.sgenvb|SBFARC|*.sbfarc|SBLARC|*.sblarc|SBACTORPACK|*sbactorpack|All Files|*.*"; sFile.InitialDirectory = oFolder.SelectedPath.Remove(oFolder.SelectedPath.LastIndexOf("\\")); //Previous folder, as selected is to build outside of it. sFile.FileName = System.IO.Path.GetFileName(oFolder.SelectedPath); lblProcessStatus.Visible = true; if (sFile.ShowDialog() == DialogResult.Cancel) { goto toss; } if (cbxSetDataOffset.Checked) { uint dataOffset = (uint)int.Parse(tbxDataOffset.Text, System.Globalization.NumberStyles.HexNumber); if (!PACK.Build(oFolder.SelectedPath, sFile.FileName, dataOffset)) { MessageBox.Show("Failed to build!" + "\n\n" + PACK.lerror); goto toss; } } else { if (!PACK.Build(oFolder.SelectedPath, sFile.FileName)) { MessageBox.Show("Failed to build!" + "\n\n" + PACK.lerror); goto toss; } } MessageBox.Show("Building Complete!" + "\n\n" + sFile.FileName); toss: oFolder.Dispose(); sFile.Dispose(); GC.Collect(); lblProcessStatus.Visible = false; }
private void multiPACK_Click(object sender, EventArgs e) { FolderBrowserDialog rFolder = new FolderBrowserDialog(); if (rFolder.ShowDialog() == DialogResult.OK) { string[] directories = Directory.GetDirectories(rFolder.SelectedPath); foreach (string item2 in directories) { PACK.Build(item2, item2.TrimEnd(Path.DirectorySeparatorChar) + extnBX.Text); } } }
private void btnSave_Click(object sender, EventArgs e) { if (tbxFile.Text == "") { MessageBox.Show("Whoops, browse for a file first!"); } else { int nodeCount = PACK.GetFileNodeCount(tbxFile.Text); uint[] currentPaddings = PACK.GetFileNodePaddings(tbxFile.Text); int[] gridPaddings = new int[nodeCount]; bool dataChanged = false; for (int i = 0; i < nodeCount; i++) { gridPaddings[i] = Convert.ToInt32(dgvTable.Rows[i].Cells[1].Value); if (gridPaddings[i] != currentPaddings[i]) //check if paddings need to be changed { PACK.UpdateFilePadding(tbxFile.Text, i, (gridPaddings[i] - (int)(currentPaddings[i]))); dataChanged = true; } } if (dataChanged) { PACK.UpdateFileSize(tbxFile.Text); MessageBox.Show("Save Complete!" + "\n\n" + tbxFile.Text); } else //if no change occured in the data upon saving { MessageBox.Show("No changes were made!" + "\n" + "Data matches current file"); } for (int i = 0; i < dgvTable.Rows.Count; i++) //reset color { dgvTable.Rows[i].Cells[1].Style.BackColor = Color.White; } } }
private void btnCusBrowse_Click(object sender, EventArgs e) { if (rbnCustomFile.Checked) { OpenFileDialog cusFile = new OpenFileDialog(); cusFile.Filter = "PACK File (*.pack *.sarc *.ssarc *.rarc *.sgenvb *.sbfarc *.sblarc *.sbactorpack)|*.pack; *.sarc; *.ssarc; *.rarc; *.sgenvb; *.sbfarc; *.sblarc; *.sbactorpack|All Files|*.*"; if (Properties.Settings.Default.RootFolder != "") { cusFile.InitialDirectory = Properties.Settings.Default.RootFolder; } if (cusFile.ShowDialog() == DialogResult.Cancel) { goto toss; } tbxCustom.Text = cusFile.FileName; dgvCusTable.Rows.Clear(); dgvCusTable.Refresh(); verify: byte[] fileCheck = System.IO.File.ReadAllBytes(tbxCustom.Text); if (fileCheck[0] == 'Y' && fileCheck[1] == 'a' && fileCheck[2] == 'z' && fileCheck[3] == '0') // if Yaz0 encoded, ask if they want to decode it { DialogResult diagResult = MessageBox.Show("This file is encoded!" + "\n\n" + "Do you want to decode?\nIt will create a seperate file automatically", "Yaz0 Encoded file...", MessageBoxButtons.YesNo); if (diagResult == DialogResult.No) { tbxCustom.Text = ""; goto toss; } string outFile = Path.GetDirectoryName(cusFile.FileName) + "\\" + Path.GetFileNameWithoutExtension(cusFile.FileName) + "Decoded" + Path.GetExtension(cusFile.FileName); if (!Yaz0.Decode(cusFile.FileName, outFile)) { MessageBox.Show("Decode error:" + "\n\n" + Yaz0.lerror); tbxCustom.Text = ""; goto toss; } tbxCustom.Text = outFile; goto verify; } if (("" + ((char)fileCheck[0]) + ((char)fileCheck[1]) + ((char)fileCheck[2]) + ((char)fileCheck[3])) != "SARC") { MessageBox.Show("Not a SARC archive! Missing SARC header at 0x00" + "\n" + "( Your file header is: " + ((char)fileCheck[0]) + ((char)fileCheck[1]) + ((char)fileCheck[2]) + ((char)fileCheck[3]) + " )"); tbxCustom.Text = ""; goto toss; } int nodeCount = PACK.GetFileNodeCount(tbxCustom.Text); string[] nodeTypes = PACK.GetFileNodeType(tbxCustom.Text); uint[] nodeSizes = PACK.GetFileNodeSizes(tbxCustom.Text); string[] nodePaths = PACK.GetFileNodePaths(tbxCustom.Text); uint[] nodePaddings = PACK.GetFileNodePaddings(tbxCustom.Text); for (int i = 0; i < nodeCount; i++) { dgvCusTable.Rows.Add(); dgvCusTable.Rows[i].Cells[0].Value = i + 1; dgvCusTable.Rows[i].Cells[1].Value = nodeTypes[i]; dgvCusTable.Rows[i].Cells[2].Value = nodeSizes[i]; dgvCusTable.Rows[i].Cells[3].Value = nodeSizes[i].ToString("X"); dgvCusTable.Rows[i].Cells[4].Value = nodePaths[i]; dgvCusTable.Rows[i].Cells[5].Value = nodePaddings[i]; } toss: cusFile.Dispose(); GC.Collect(); } else if (rbnCustomFolder.Checked) { FolderBrowserDialog cusFolder = new FolderBrowserDialog(); if (Properties.Settings.Default.RootFolder != "") { cusFolder.SelectedPath = Properties.Settings.Default.RootFolder; } cusFolder.Description = "Select Custom Folder"; if (cusFolder.ShowDialog() == DialogResult.Cancel) { goto toss; } tbxCustom.Text = cusFolder.SelectedPath; dgvCusTable.Rows.Clear(); dgvCusTable.Refresh(); string[] cusFolderFiles = System.IO.Directory.GetFiles(cusFolder.SelectedPath == "" ? System.Environment.CurrentDirectory : cusFolder.SelectedPath, "*.*", System.IO.SearchOption.AllDirectories); int nodeCount = cusFolderFiles.Length; if (nodeCount > 1000) { MessageBox.Show("Too many files (1000+)!\n\nI doubt you ment to select this folder...\n" + tbxCustom.Text + "\n\nTry again"); tbxCustom.Text = ""; goto toss; } uint[] nodeSizes = PACK.GetFolderFileSizes(cusFolder.SelectedPath); string[] nodeTypes = PACK.GetFolderFileTypes(cusFolder.SelectedPath); string[] nodePaths = PACK.GetFolderFilePaths(cusFolder.SelectedPath); for (int i = 0; i < nodeCount; i++) { dgvCusTable.Rows.Add(); dgvCusTable.Rows[i].Cells[0].Value = i + 1; dgvCusTable.Rows[i].Cells[1].Value = nodeTypes[i]; dgvCusTable.Rows[i].Cells[2].Value = nodeSizes[i]; dgvCusTable.Rows[i].Cells[3].Value = nodeSizes[i].ToString("X"); dgvCusTable.Rows[i].Cells[4].Value = nodePaths[i]; } toss: cusFolder.Dispose(); GC.Collect(); } }
private void btnOriBrowse_Click(object sender, EventArgs e) { OpenFileDialog oriFile = new OpenFileDialog(); oriFile.Filter = "PACK File (*.pack *.sarc *.ssarc *.rarc *.sgenvb *.sbfarc *.sblarc *.sbactorpack)|*.pack; *.sarc; *.ssarc; *.rarc; *.sgenvb; *.sbfarc; *.sblarc; *.sbactorpack|All Files|*.*"; if (Properties.Settings.Default.RootFolder != "") { oriFile.InitialDirectory = Properties.Settings.Default.RootFolder; } if (oriFile.ShowDialog() == DialogResult.Cancel) { goto toss; } tbxOriFile.Text = oriFile.FileName; dgvOriTable.Rows.Clear(); dgvOriTable.Refresh(); verify: byte[] fileCheck = System.IO.File.ReadAllBytes(tbxOriFile.Text); if (fileCheck[0] == 'Y' && fileCheck[1] == 'a' && fileCheck[2] == 'z' && fileCheck[3] == '0') // if Yaz0 encoded, ask if they want to decode it { DialogResult diagResult = MessageBox.Show("This file is encoded!" + "\n\n" + "Do you want to decode?\nIt will create a seperate file automatically", "Yaz0 Encoded file...", MessageBoxButtons.YesNo); if (diagResult == DialogResult.No) { tbxOriFile.Text = ""; goto toss; } string outFile = Path.GetDirectoryName(oriFile.FileName) + "\\" + Path.GetFileNameWithoutExtension(oriFile.FileName) + "Decoded" + Path.GetExtension(oriFile.FileName); if (!Yaz0.Decode(oriFile.FileName, outFile)) { MessageBox.Show("Decode error:" + "\n\n" + Yaz0.lerror); tbxOriFile.Text = ""; goto toss; } tbxOriFile.Text = outFile; goto verify; } if (("" + ((char)fileCheck[0]) + ((char)fileCheck[1]) + ((char)fileCheck[2]) + ((char)fileCheck[3])) != "SARC") { MessageBox.Show("Not a SARC archive! Missing SARC header at 0x00" + "\n" + "( Your file header is: " + ((char)fileCheck[0]) + ((char)fileCheck[1]) + ((char)fileCheck[2]) + ((char)fileCheck[3]) + " )"); tbxOriFile.Text = ""; goto toss; } int nodeCount = PACK.GetFileNodeCount(tbxOriFile.Text); string[] nodeTypes = PACK.GetFileNodeType(tbxOriFile.Text); uint[] nodeSizes = PACK.GetFileNodeSizes(tbxOriFile.Text); string[] nodePaths = PACK.GetFileNodePaths(tbxOriFile.Text); uint[] nodePaddings = PACK.GetFileNodePaddings(tbxOriFile.Text); for (int i = 0; i < nodeCount; i++) { dgvOriTable.Rows.Add(); dgvOriTable.Rows[i].Cells[0].Value = i + 1; dgvOriTable.Rows[i].Cells[1].Value = nodeTypes[i]; dgvOriTable.Rows[i].Cells[2].Value = nodeSizes[i]; dgvOriTable.Rows[i].Cells[3].Value = nodeSizes[i].ToString("X"); dgvOriTable.Rows[i].Cells[4].Value = nodePaths[i]; dgvOriTable.Rows[i].Cells[5].Value = nodePaddings[i]; } toss: oriFile.Dispose(); GC.Collect(); }
private void btnBuild_Click(object sender, EventArgs e) { FolderBrowserDialog cusFolder = new FolderBrowserDialog(); OpenFileDialog oriFile = new OpenFileDialog(); SaveFileDialog sFile = new SaveFileDialog(); //Verify files and directories if (tbxOriFile.Text == "") { MessageBox.Show("Original file path missing!"); goto toss; } if (tbxCustom.Text == "") { MessageBox.Show("Custom folder path missing!"); goto toss; } if (FileOrDirectoryExists(tbxOriFile.Text)) { oriFile.FileName = tbxOriFile.Text; } else { MessageBox.Show("Original File has an invalid path:\n\n" + tbxOriFile.Text); goto toss; } if (FileOrDirectoryExists(tbxCustom.Text)) { cusFolder.SelectedPath = tbxCustom.Text; } else { MessageBox.Show("Custom Folder has an invalid path:\n\n" + tbxCustom.Text); goto toss; } int oriNodeCount = PACK.GetFileNodeCount(oriFile.FileName); string[] cusFolderFiles = System.IO.Directory.GetFiles(cusFolder.SelectedPath == "" ? System.Environment.CurrentDirectory : cusFolder.SelectedPath, "*.*", System.IO.SearchOption.AllDirectories); if (oriNodeCount != cusFolderFiles.Length) { MessageBox.Show("Number of nodes do not match!\n\n" + "Original file nodes: " + oriNodeCount + "\nCustom Folder nodes: " + cusFolderFiles.Length); goto toss; } int numFiles = Directory.GetFiles(cusFolder.SelectedPath, "*", SearchOption.AllDirectories).Length; //Save file path sFile.Filter = "PACK|*.pack|SARC|*.sarc|SSARC|*.ssarc|RARC|*.rarc|SGENVB|*.sgenvb|SBFARC|*.sbfarc|SBLARC|*.sblarc|SBACTORPACK|*sbactorpack|All Files|*.*"; sFile.InitialDirectory = cusFolder.SelectedPath.Remove(cusFolder.SelectedPath.LastIndexOf("\\")); //Previous folder, as selected is to build outside of it. sFile.FileName = System.IO.Path.GetFileName(cusFolder.SelectedPath); lblProcessStatus.Visible = true; if (sFile.ShowDialog() == DialogResult.Cancel) { goto toss; } if (!PACK.CompareAndBuild(oriFile.FileName, cusFolder.SelectedPath, sFile.FileName, true)) { MessageBox.Show("Failed to build!" + "\n\n" + PACK.lerror); } else { MessageBox.Show("Done!\n\n" + sFile.FileName); } toss: cusFolder.Dispose(); oriFile.Dispose(); sFile.Dispose(); GC.Collect(); lblProcessStatus.Visible = false; }
private void btnBrowse_Click(object sender, EventArgs e) { OpenFileDialog inFile = new OpenFileDialog(); inFile.Filter = "All Files|*.*"; if (inFile.ShowDialog() == DialogResult.Cancel) { goto toss; } tbxFile.Text = inFile.FileName; btnSave.Enabled = true; dgvTable.Rows.Clear(); dgvTable.Refresh(); verify: byte[] fileCheck = System.IO.File.ReadAllBytes(tbxFile.Text); if (fileCheck[0] == 'Y' && fileCheck[1] == 'a' && fileCheck[2] == 'z' && fileCheck[3] == '0') // if Yaz0 encoded, ask if they want to decode it { DialogResult diagResult = MessageBox.Show("This file is encoded!" + "\n\n" + "Do you want to decode?\nIt will create a seperate file automatically", "Yaz0 Encoded file...", MessageBoxButtons.YesNo); if (diagResult == DialogResult.No) { tbxFile.Text = ""; btnSave.Enabled = false; goto toss; } string outFile = Path.GetDirectoryName(inFile.FileName) + "\\" + Path.GetFileNameWithoutExtension(inFile.FileName) + "Decoded" + Path.GetExtension(inFile.FileName); if (!Yaz0.Decode(inFile.FileName, outFile)) { MessageBox.Show("Decode error:" + "\n\n" + Yaz0.lerror); tbxFile.Text = ""; btnSave.Enabled = false; goto toss; } tbxFile.Text = outFile; goto verify; } if (("" + ((char)fileCheck[0]) + ((char)fileCheck[1]) + ((char)fileCheck[2]) + ((char)fileCheck[3])) != "SARC") { MessageBox.Show("Not a SARC archive! Missing SARC header at 0x00" + "\n" + "( Your file header is: " + ((char)fileCheck[0]) + ((char)fileCheck[1]) + ((char)fileCheck[2]) + ((char)fileCheck[3]) + " )"); tbxFile.Text = ""; btnSave.Enabled = false; goto toss; } int nodeCount = PACK.GetFileNodeCount(tbxFile.Text); string[] nodeTypes = PACK.GetFileNodeType(tbxFile.Text); uint[] nodeSizes = PACK.GetFileNodeSizes(tbxFile.Text); string[] nodePaths = PACK.GetFileNodePaths(tbxFile.Text); uint[] nodePaddings = PACK.GetFileNodePaddings(tbxFile.Text); for (int i = 0; i < nodeCount; i++) { dgvTable.Rows.Add(); dgvTable.Rows[i].Cells[0].Value = i + 1; dgvTable.Rows[i].Cells[1].Value = nodePaddings[i]; dgvTable.Rows[i].Cells[2].Value = nodeTypes[i]; dgvTable.Rows[i].Cells[3].Value = nodeSizes[i]; dgvTable.Rows[i].Cells[4].Value = nodeSizes[i].ToString("X"); dgvTable.Rows[i].Cells[5].Value = nodePaths[i]; } fileSize = fileCheck.Length; tbxFileSize.Text = fileSize.ToString(); dataOffset = PACK.GetFileDataOffset(tbxFile.Text); tbxDataOffset.Text = "0x" + dataOffset.ToString("X"); toss: inFile.Dispose(); GC.Collect(); }
private void btnExtractPack_Click(object sender, EventArgs e) //Extract Pack button { OpenFileDialog oFile = new OpenFileDialog(); oFile.Filter = "PACK File (*.pack *.sarc *.ssarc *.rarc *.sgenvb *.sbfarc *.sblarc *.sbactorpack)|*.pack; *.sarc; *.ssarc; *.rarc; *.sgenvb; *.sbfarc; *.sblarc; *.sbactorpack|All Files|*.*"; if (tbxFolderRoot.Text != "") { oFile.InitialDirectory = tbxFolderRoot.Text; } if (oFile.ShowDialog() == DialogResult.Cancel) { goto toss; } String oFolderName = Path.GetFileNameWithoutExtension(oFile.FileName); String oFolderPath = Path.GetDirectoryName(oFile.FileName) + "\\" + oFolderName; // if the output folder exists, prompt user if they want to extract anyway if (Directory.Exists(oFolderPath)) { if (MessageBox.Show(oFolderName + " already exists!" + "\n\n" + "Proceed anyway?", "Overwrite?", MessageBoxButtons.YesNo) == DialogResult.No) { goto xml; } } //SARC lblProcessStatus.Visible = true; bool boolAutoDecode = false; bool boolReplaceFile = false; if (cbxAutoDecode.Checked) //Auto Yaz0 decoding { boolAutoDecode = true; if (cbxReplaceDecodedFile.Checked) //Replace File { boolReplaceFile = true; } } if (!PACK.Extract(oFile.FileName, oFolderPath, boolAutoDecode, boolReplaceFile)) //Extraction { MessageBox.Show("Extraction error:" + "\n\n" + PACK.lerror); goto toss; } else { System.Diagnostics.Process.Start(oFolderPath); } //XML xml: if (cbxWriteXml.Checked) { if (File.Exists(oFolderPath + ".xml")) { if (MessageBox.Show(oFolderName + ".xml already exists!" + "\n\n" + "Proceed anyway?", "Overwrite?", MessageBoxButtons.YesNo) == DialogResult.No) { goto toss; } } if (!XMLWriter.SaveXml(oFile.FileName, (oFolderPath + ".xml"))) { MessageBox.Show("XML file failed to write by unknown reasons"); } } toss: oFile.Dispose(); GC.Collect(); lblProcessStatus.Visible = false; }
private void btnExtractAll_Click(object sender, EventArgs e) { if (!(Directory.Exists(tbxFolderRoot.Text))) { MessageBox.Show("Error: Invalid path" + "\n" + tbxFolderRoot.Text); goto toss; } if (cbxCompileAllInOneFolder.Checked) { if (MessageBox.Show("Extract all SARC data type files from default path?" + "\n" + tbxFolderRoot.Text + "\n\n" + "You are choosing to compile all extracted data to one folder!" + "\n" + "This does not include subfolders", "Are you sure?", MessageBoxButtons.YesNo) == DialogResult.No) { goto toss; } } else { if (MessageBox.Show("Extract all SARC data type files from default path?" + "\n" + tbxFolderRoot.Text + "\n\n" + "This will generate seperate folders of every file it unpacks" + "\n" + "This does not include subfolders", "Are you sure?", MessageBoxButtons.YesNo) == DialogResult.No) { goto toss; } } lblProcessStatus.Visible = true; DirectoryInfo dirFolder = new DirectoryInfo(tbxFolderRoot.Text); String oFolderName, oFolderPath; int sarcFileCount = 0; bool boolAutoDecode = false; bool boolReplaceFile = false; if (cbxAutoDecode.Checked) //Auto Yaz0 decoding { boolAutoDecode = true; if (cbxReplaceDecodedFile.Checked) //Replace File { boolReplaceFile = true; } } if (cbxCompileAllInOneFolder.Checked) //Compile All to New Folder { FolderBrowserDialog oFolder = new FolderBrowserDialog(); if (tbxFolderRoot.Text != "") { oFolder.SelectedPath = tbxFolderRoot.Text; } if (oFolder.ShowDialog() == DialogResult.Cancel) { goto toss; } foreach (FileInfo file in dirFolder.GetFiles()) //Extraction { oFolderName = Path.GetFileNameWithoutExtension(file.FullName); oFolderPath = oFolder.SelectedPath; if (PACK.Extract(file.FullName, oFolderPath, boolAutoDecode, boolReplaceFile)) { sarcFileCount++; } } } else { foreach (FileInfo file in dirFolder.GetFiles()) //Extraction { oFolderName = Path.GetFileNameWithoutExtension(file.FullName); oFolderPath = Path.GetDirectoryName(file.FullName) + "\\" + oFolderName; if (PACK.Extract(file.FullName, oFolderPath, boolAutoDecode, boolReplaceFile)) { sarcFileCount++; } } } MessageBox.Show("Done" + "\n\n" + sarcFileCount + " file(s) extracted!"); toss: GC.Collect(); lblProcessStatus.Visible = false; }