private void toolStripButton1_Click(object sender, EventArgs e) { string path = ""; OpenFileDialog openROMDialog = new OpenFileDialog(); openROMDialog.Filter = "Any Files|*.*|Narc Files|*.*"; if (openROMDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { path = openROMDialog.FileName; } if (path != "") { a = new FileStream(path, FileMode.Open); DynamicFileByteProvider dynamicFileByteProvider = null; try { dynamicFileByteProvider = new DynamicFileByteProvider(a); } catch { } toolStripLabel1.Text = a.Length + ""; hexBox1.ByteProvider = dynamicFileByteProvider; byte[] bytetemp = new byte[a.Length]; a.Read(bytetemp, 0, (int)a.Length); DynamicFileByteProvider dynamicFileByteProvider2 = null; try { BLZCoder aa = new BLZCoder(); b = new MemoryStream(aa.BLZ_DecodePub(bytetemp, "-d")); dynamicFileByteProvider2 = new DynamicFileByteProvider(b); } catch { b = a; dynamicFileByteProvider2 = new DynamicFileByteProvider(b); } toolStripLabel2.Text = b.Length + ""; hexBox2.ByteProvider = dynamicFileByteProvider2; } }
// Form Load - Used to handle commandline arguments. private async void Form1_Load(object sender, EventArgs e) { var args = Environment.GetCommandLineArgs(); // Remove the control box //if (args.Length > 3) //{ // this.ControlBox = false; //} if (args.Length > 3 && args[1] == "-romfs") { //Build just the romfs, for use with Hans string ROMFS_PATH = args[2].Replace("/", "\\"); string SAVE_PATH = args[3].Replace("/", "\\"); await Task.Run(() => CTR_ROM.buildRomfs(ROMFS_PATH, SAVE_PATH, RTB_Progress, PB_Show)); this.Close(); } else if (args.Length > 4) { //Build the entire 3DS ROM using commandline input. string exefsPath = args[1].Replace("/", "\\"); string romfsPath = args[2].Replace("/", "\\"); string exheaderPath = args[3].Replace("/", "\\"); //romfs TB_Romfs.Text = romfsPath; //exefs string[] files = (new DirectoryInfo(exefsPath).GetFiles().Select(f => Path.GetFileNameWithoutExtension(f.FullName)).ToArray()); if (((files.Contains("code") || files.Contains(".code")) && !(files.Contains(".code") && files.Contains("code"))) && files.Contains("banner") && files.Contains("icon") && files.Length < 10) { FileInfo fi = (new DirectoryInfo(exefsPath)).GetFiles()[Math.Max(Array.IndexOf(files, "code"), Array.IndexOf(files, ".code"))]; if (fi.Name == "code.bin") { string newName = fi.DirectoryName + Path.DirectorySeparatorChar + ".code.bin"; File.Move(fi.FullName, newName); fi = new FileInfo(newName); } if (args.Contains("-compressCode")) { if (fi.Length % 0x200 == 0) { SetPrebuiltBoxes(false); await Task.Run(() => { var blz = new BLZCoder(); blz.CompressCode(new[] { "-en", fi.FullName }, PB_Show); }); SetPrebuiltBoxes(true); } } if (files.Contains("logo")) { File.Delete((new DirectoryInfo(exefsPath)).GetFiles()[Array.IndexOf(files, "logo")].FullName); } TB_Exefs.Text = exefsPath; //Validate_Go(); } else { //Skipping alert because to avoid interacting with the user. //Alert("Your selected ExeFS is missing something essential."); } FileInfo exfi = new FileInfo(exheaderPath); TB_Exheader.Text = exheaderPath; Exheader exh = new Exheader(TB_Exheader.Text); if (RecognizedGames.ContainsKey(exh.TitleID)) { TB_Serial.Text = exh.GetSerial(); } //Replacing / with \ because somewhere in buildROM, / doesn't work, while \ does. TB_SavePath.Text = args[4].Replace("/", "\\"); //Build the ROM await CTR_ROM.buildROM(Card2, LOGO_NAME, exefsPath, romfsPath, exheaderPath, TB_Serial.Text, TB_SavePath.Text, PB_Show, RTB_Progress); //Close the form this.Close(); } }
private async void B_Exefs_Click(object sender, EventArgs e) { if (threads > 0) { Alert("Please wait for all operations to finish first."); return; } if (CHK_PrebuiltExefs.Checked) { OpenFileDialog ofd = new OpenFileDialog(); if (ofd.ShowDialog() != DialogResult.OK) return; TB_Exefs.Text = ofd.FileName; Validate_Go(); } else { FolderBrowserDialog fbd = new FolderBrowserDialog(); if (fbd.ShowDialog() != DialogResult.OK) return; string[] files = (new DirectoryInfo(fbd.SelectedPath)).GetFiles().Select(f => Path.GetFileNameWithoutExtension(f.FullName)).ToArray(); if (((files.Contains("code") || files.Contains(".code")) && !(files.Contains(".code") && files.Contains("code"))) && files.Contains("banner") && files.Contains("icon") && files.Length < 10) { FileInfo fi = (new DirectoryInfo(fbd.SelectedPath)).GetFiles()[Math.Max(Array.IndexOf(files, "code"), Array.IndexOf(files, ".code"))]; if (fi.Name == "code.bin") { Alert("Renaming \"code.bin\" to \".code.bin\""); string newName = fi.DirectoryName + Path.DirectorySeparatorChar + ".code.bin"; File.Move(fi.FullName, newName); fi = new FileInfo(newName); } if (fi.Length % 0x200 == 0) { if (Prompt(MessageBoxButtons.YesNo, "Detected Decompressed code.bin.", "Compress? File will be replaced. Do not build an ExeFS with an uncompressed code.bin if the Exheader doesn't specify it.") == DialogResult.Yes) { await Task.Run(() => { threads++; SetPrebuiltBoxes(false); var blz = new BLZCoder(); blz.CompressCode(new[] { "-en", fi.FullName }, PB_Show); SetPrebuiltBoxes(true); threads--; Alert("Compressed!"); }); } } if (files.Contains("logo")) { Alert("Deleting unneeded exefs logo binary."); File.Delete((new DirectoryInfo(fbd.SelectedPath)).GetFiles()[Array.IndexOf(files, "logo")].FullName); } TB_Exefs.Text = fbd.SelectedPath; Validate_Go(); } else { Alert("Your selected ExeFS is missing something essential."); } } }