static private void ConsoleUnpack(string[] args) { if (args.Length == 2 && File.Exists(args[1])) { if (SARC.Extract(args[1], Path.GetDirectoryName(args[1]) + "\\" + Path.GetFileNameWithoutExtension(args[1]))) { Console.WriteLine("Unpack Successful"); } else { Console.WriteLine("Unpack error: " + SARC.lerror); } } else if (args.Length == 3 && File.Exists(args[1])) { if (SARC.Extract(args[1], args[2])) { Console.WriteLine("Unpack Successful"); } else { Console.WriteLine("Unpack error: " + SARC.lerror); } } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Error: Incorrect use of Unpack command."); Console.WriteLine("/u <Input File> [Output Folder]"); Console.ForegroundColor = ConsoleColor.White; } }
private async void btnYaz0Encode_Click(object sender, EventArgs e) { loadingBar.Visible = true; OpenFileDialog oFile = new OpenFileDialog(); if (tbxFolderRoot.Text != "") { oFile.InitialDirectory = tbxFolderRoot.Text; } if (!(oFile.ShowDialog() == DialogResult.Cancel)) { if (!SARC.IsYaz0File(oFile.FileName)) { string outFile = Yaz0.EncodeOutputFileRename(oFile.FileName); if (File.Exists(outFile)) { if (MessageBox.Show(Path.GetFileName(outFile) + " already exists!" + "\n\n" + "Proceed anyway?", "Overwrite?", MessageBoxButtons.YesNo) == DialogResult.Yes) { await Encode(oFile.FileName, outFile); } } else { await Encode(oFile.FileName, outFile); } } else { MessageBox.Show("Encode error:" + "\n\n" + "File is already Yaz0 encoded!"); } } oFile.Dispose(); loadingBar.Visible = false; }
static private void ConsoleBuildSwitch(string[] args) { if (args.Length == 2 && Directory.Exists(args[1])) { if (SARC.Build(args[1], args[1].Remove(args[1].LastIndexOf("\\")) + "\\" + Path.GetFileName(args[1]) + ".pack", true)) { Console.WriteLine("Build Successful"); } else { Console.WriteLine("Build error: " + SARC.lerror); } } else if (args.Length == 3 && Directory.Exists(args[1])) { if (SARC.Build(args[1], args[2], true)) { Console.WriteLine("Build Successful"); } else { Console.WriteLine("Build error: " + SARC.lerror); } } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Error: Incorrect use of Build command."); Console.WriteLine("/bs <Input Folder> [Output File]"); Console.ForegroundColor = ConsoleColor.White; } }
private void btnBuildPack_Click(object sender, EventArgs e) // Build Pack button { CommonOpenFileDialog oFolder = new CommonOpenFileDialog(); oFolder.IsFolderPicker = true; 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; } } if (tbxFolderRoot.Text != "") { oFolder.InitialDirectory = tbxFolderRoot.Text; } if (oFolder.ShowDialog() == CommonFileDialogResult.Cancel) { goto toss; } int numFiles = Directory.GetFiles(oFolder.FileName, "*", SearchOption.AllDirectories).Length; sFile.Filter = "All Files|*.*"; sFile.InitialDirectory = oFolder.FileName.Remove(oFolder.FileName.LastIndexOf("\\")); //Previous folder, as selected is to build outside of it. sFile.FileName = System.IO.Path.GetFileName(oFolder.FileName); loadingBar.Visible = true; if (sFile.ShowDialog() == DialogResult.Cancel) { goto toss; } if (cbxSetDataOffset.Checked) { uint dataOffset = (uint)int.Parse(tbxDataOffset.Text, System.Globalization.NumberStyles.HexNumber); if (!SARC.Build(oFolder.FileName, sFile.FileName, dataOffset)) { MessageBox.Show("Failed to build!" + "\n\n" + SARC.lerror); goto toss; } } else { if (!SARC.Build(oFolder.FileName, sFile.FileName)) { MessageBox.Show("Failed to build!" + "\n\n" + SARC.lerror); goto toss; } } MessageBox.Show("Building Complete!" + "\n\n" + sFile.FileName); toss: oFolder.Dispose(); sFile.Dispose(); GC.Collect(); loadingBar.Visible = false; }
static public void DragAndDropFile(string arg) { if (SARC.IsSarcFile(arg) && !(Directory.Exists(Path.GetDirectoryName(arg) + "\\" + Path.GetFileNameWithoutExtension(arg)))) //dont overwrite existing folders { ConsoleUnpack(arg); } else if (SARC.IsYaz0File(arg)) { ConsoleDecode(arg); } else if (Yaz0.IsKnownDecodedExtension(arg)) { ConsoleEncode(arg); } }
private void btnSave_Click(object sender, EventArgs e) { if (tbxFile.Text == "") { MessageBox.Show("Whoops, browse for a file first!"); } else { int nodeCount = SARC.GetFileNodeCount(tbxFile.Text); uint[] currentPaddings = SARC.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 { SARC.UpdateFilePadding(tbxFile.Text, i, (gridPaddings[i] - (int)(currentPaddings[i]))); dataChanged = true; } } if (dataChanged) { SARC.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 { ResetTableColor(dgvTable); } tbxFileSize.Text = System.IO.File.ReadAllBytes(tbxFile.Text).Length.ToString(); } }
private void btnExtractPack_Click(object sender, EventArgs e) //Extract Pack button { loadingBar.Visible = true; OpenFileDialog oFile = new OpenFileDialog(); 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 bool boolAutoDecode = false; bool boolNodeDecode = false; if (cbxNodeDecode.Checked) //Node Yaz0 decoding { boolNodeDecode = true; } else //Default, without any checkboxes { if (SARC.IsYaz0File(oFile.FileName)) { if (MessageBox.Show("This file is Yaz0 encoded!" + "\n\n" + "Want to decode it and attempt to extract?", "Decode and Extact?", MessageBoxButtons.YesNo) != DialogResult.No) { boolAutoDecode = true; //Auto decode just this once since we prompted } else { goto toss; //User clicked no } } } if (!SARC.Extract(oFile.FileName, oFolderPath, boolAutoDecode, boolNodeDecode)) //Extraction { MessageBox.Show("Extraction error:" + "\n\n" + SARC.lerror); goto toss; } else { System.Diagnostics.Process.Start(oFolderPath); } //XML xml: if (cbxWriteSarcXml.Checked) { if (File.Exists(oFolderPath + "_SarcDebug.xml")) { if (MessageBox.Show(oFolderName + ".xml already exists!" + "\n\n" + "Proceed anyway?", "Overwrite?", MessageBoxButtons.YesNo) == DialogResult.No) { goto toss; } } if (!DebugWriter.WriteSarcXml(oFile.FileName, (oFolderPath + "_SarcDebug.xml"))) { MessageBox.Show("XML file failed to write by unknown reasons"); } } toss: oFile.Dispose(); GC.Collect(); loadingBar.Visible = false; }
private void btnExtractAll_Click(object sender, EventArgs e) { if (tbxFolderRoot.Text == "") { MessageBox.Show("Browse for a default folder to unpack from first!"); goto toss; } if (!(Directory.Exists(tbxFolderRoot.Text))) { MessageBox.Show("Error: Invalid path" + "\n" + tbxFolderRoot.Text); goto toss; } loadingBar.Visible = true; if (cbxCompileAllInOneFolder.Checked) { if (MessageBox.Show("Extract all SARC data type files from default path?" + "\n" + tbxFolderRoot.Text + "\n" + "*This does not include subfolders" + "\n\n" + "You are choosing to compile all extracted data to ONE folder!" + "\n" + "You'll then select a folder where you want to place them all in.", "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" + "*This does not include subfolders" + "\n\n" + "This will generate SEPERATE folders of every file it unpacks!", "Are you sure?", MessageBoxButtons.YesNo) == DialogResult.No) { goto toss; } } DirectoryInfo dirFolder = new DirectoryInfo(tbxFolderRoot.Text); String oFolderName, oFolderPath; int sarcFileCount = 0; bool boolAutoDecode = false; bool boolNodeDecode = false; if (cbxNodeDecode.Checked) //Auto Yaz0 decoding { boolNodeDecode = true; } if (cbxCompileAllInOneFolder.Checked) //Compile All to New Folder { CommonOpenFileDialog oFolder = new CommonOpenFileDialog(); oFolder.IsFolderPicker = true; if (tbxFolderRoot.Text != "") { oFolder.InitialDirectory = tbxFolderRoot.Text; } if (oFolder.ShowDialog() == CommonFileDialogResult.Cancel) { goto toss; } foreach (FileInfo file in dirFolder.GetFiles()) //Extraction { oFolderName = Path.GetFileNameWithoutExtension(file.FullName); oFolderPath = oFolder.FileName; if (SARC.Extract(file.FullName, oFolderPath, boolAutoDecode, boolNodeDecode)) { sarcFileCount++; } } } else { foreach (FileInfo file in dirFolder.GetFiles()) //Extraction { oFolderName = Path.GetFileNameWithoutExtension(file.FullName); oFolderPath = Path.GetDirectoryName(file.FullName) + "\\" + oFolderName; if (SARC.Extract(file.FullName, oFolderPath, boolAutoDecode, boolNodeDecode)) { sarcFileCount++; } } } MessageBox.Show("Done" + "\n\n" + sarcFileCount + " file(s) extracted!"); toss: GC.Collect(); loadingBar.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 = Yaz0.DecodeOutputFileRename(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 = SARC.GetFileNodeCount(tbxFile.Text); string[] nodeTypes = SARC.GetFileNodeType(tbxFile.Text); uint[] nodeSizes = SARC.GetFileNodeSizes(tbxFile.Text); string[] nodePaths = SARC.GetFileNodePaths(tbxFile.Text); uint[] nodePaddings = SARC.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 = SARC.GetFileDataOffset(tbxFile.Text); tbxDataOffset.Text = "0x" + dataOffset.ToString("X"); toss: inFile.Dispose(); GC.Collect(); }
private void btnOriBrowse_Click(object sender, EventArgs e) { if (rbnOriFile.Checked) { OpenFileDialog oriFile = new OpenFileDialog(); oriFile.Filter = "All Files|*.*"; if (BotwUnpacker.Properties.Settings.Default.RootFolder != "") { oriFile.InitialDirectory = BotwUnpacker.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 = Yaz0.DecodeOutputFileRename(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 = SARC.GetFileNodeCount(tbxOriFile.Text); string[] nodeTypes = SARC.GetFileNodeType(tbxOriFile.Text); uint[] nodeSizes = SARC.GetFileNodeSizes(tbxOriFile.Text); string[] nodePaths = SARC.GetFileNodePaths(tbxOriFile.Text); uint[] nodePaddings = SARC.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(); } else if (rbnOriFolder.Checked) { CommonOpenFileDialog oriFolder = new CommonOpenFileDialog(); oriFolder.IsFolderPicker = true; if (BotwUnpacker.Properties.Settings.Default.RootFolder != "") { oriFolder.InitialDirectory = BotwUnpacker.Properties.Settings.Default.RootFolder; } if (oriFolder.ShowDialog() == CommonFileDialogResult.Cancel) { goto toss; } tbxOriFile.Text = oriFolder.FileName; dgvOriTable.Rows.Clear(); dgvCusTable.Refresh(); string[] oriFolderFiles = System.IO.Directory.GetFiles(oriFolder.FileName == "" ? System.Environment.CurrentDirectory : oriFolder.FileName, "*.*", System.IO.SearchOption.AllDirectories); int nodeCount = oriFolderFiles.Length; if (nodeCount > 1000) { MessageBox.Show("Too many files (1000+)!\n\nI doubt you ment to select this folder...\n" + tbxOriFile.Text + "\n\nTry again"); tbxOriFile.Text = ""; goto toss; } uint[] nodeSizes = SARC.GetFolderFileSizes(oriFolder.FileName); string[] nodeTypes = SARC.GetFolderFileTypes(oriFolder.FileName); string[] nodePaths = SARC.GetFolderFilePaths(oriFolder.FileName); 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]; } toss: oriFolder.Dispose(); GC.Collect(); } }