private void openRomButton_Click(object sender, EventArgs e) { string path = ""; string[] backups = null; if (Properties.Settings.Default.BackupFiles != "" && MessageBox.Show(LanguageManager.Get("StartForm", "OpenBackups"), LanguageManager.Get("StartForm", "OpenBackupsTitle"), MessageBoxButtons.YesNo) == DialogResult.Yes) { backups = Properties.Settings.Default.BackupFiles.Split(';'); path = backups[0]; } else { OpenFileDialog openROMDialog = new OpenFileDialog(); openROMDialog.Filter = LanguageManager.Get("Filters", "rom"); if (Properties.Settings.Default.ROMFolder != "") { openROMDialog.InitialDirectory = Properties.Settings.Default.ROMFolder; } if (openROMDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { path = openROMDialog.FileName; } } if (path == "") { return; } try { NitroROMFilesystem fs = new NitroROMFilesystem(path); Properties.Settings.Default.ROMPath = path; Properties.Settings.Default.Save(); Properties.Settings.Default.ROMFolder = System.IO.Path.GetDirectoryName(path); Properties.Settings.Default.Save(); if (backups != null) { for (int l = 1; l < backups.Length; l++) { ROM.fileBackups.Add(backups[l]); } } run(fs); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void patchExport_Click(object sender, EventArgs e) { //output to show to the user bool differentRomsWarning = false; // tells if we have shown the warning int fileCount = 0; //load the original rom MessageBox.Show(LanguageManager.Get("Patch", "SelectROM"), LanguageManager.Get("Patch", "Export"), MessageBoxButtons.OK, MessageBoxIcon.Information); if (openROMDialog.ShowDialog() == DialogResult.Cancel) { return; } NitroROMFilesystem origROM = new NitroROMFilesystem(openROMDialog.FileName); //open the output patch MessageBox.Show(LanguageManager.Get("Patch", "SelectLocation"), LanguageManager.Get("Patch", "Export"), MessageBoxButtons.OK, MessageBoxIcon.Information); if (savePatchDialog.ShowDialog() == DialogResult.Cancel) { return; } FileStream fs = new FileStream(savePatchDialog.FileName, FileMode.Create, FileAccess.Write, FileShare.None); BinaryWriter bw = new BinaryWriter(fs); bw.Write(patchHeader); //DO THE PATCH!! ProgressWindow progress = new ProgressWindow(LanguageManager.Get("Patch", "ExportProgressTitle")); progress.Show(); progress.SetMax(ROM.FS.allFiles.Count); int progVal = 0; MessageBox.Show(LanguageManager.Get("Patch", "StartingPatch"), LanguageManager.Get("Patch", "Export"), MessageBoxButtons.OK, MessageBoxIcon.Information); foreach (NSMBe5.DSFileSystem.File f in ROM.FS.allFiles) { if (f.isSystemFile) { continue; } Console.Out.WriteLine("Checking " + f.name); progress.SetCurrentAction(string.Format(LanguageManager.Get("Patch", "ComparingFile"), f.name)); NSMBe5.DSFileSystem.File orig = origROM.getFileByName(f.name); //check same version if (orig == null) { new ErrorMSGBox("", "", "In this case it is recommended that you continue.", "This ROM has more files than the original clean ROM or a file was renamed!\n\nPlease make an XDelta patch instead.\n\nExport will end now.").ShowDialog(); bw.Write((byte)0); bw.Close(); origROM.close(); progress.SetCurrentAction(""); progress.WriteLine(string.Format(LanguageManager.Get("Patch", "ExportReady"), fileCount)); return; } else if (!differentRomsWarning && f.id != orig.id) { if (MessageBox.Show(LanguageManager.Get("Patch", "ExportDiffVersions"), LanguageManager.Get("General", "Warning"), MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes) { differentRomsWarning = true; } else { fs.Close(); return; } } byte[] oldFile = orig.getContents(); byte[] newFile = f.getContents(); if (!arrayEqual(oldFile, newFile)) { //include file in patch string fileName = orig.name; Console.Out.WriteLine("Including: " + fileName); progress.WriteLine(string.Format(LanguageManager.Get("Patch", "IncludedFile"), fileName)); fileCount++; bw.Write((byte)1); bw.Write(fileName); bw.Write((ushort)f.id); bw.Write((uint)newFile.Length); bw.Write(newFile, 0, newFile.Length); } progress.setValue(++progVal); } bw.Write((byte)0); bw.Close(); origROM.close(); progress.SetCurrentAction(""); progress.WriteLine(string.Format(LanguageManager.Get("Patch", "ExportReady"), fileCount)); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); string langDir = System.IO.Path.Combine(Application.StartupPath, "Languages"); string langFileName = System.IO.Path.Combine(langDir, Properties.Settings.Default.LanguageFile + ".ini"); if (System.IO.File.Exists(langFileName)) { System.IO.StreamReader rdr = new StreamReader(langFileName); LanguageManager.Load(rdr.ReadToEnd().Split('\n')); rdr.Close(); } else { MessageBox.Show("File " + langFileName + " could not be found, so the language has defaulted to English."); LanguageManager.Load(Properties.Resources.English.Split('\n')); } string[] args = Environment.GetCommandLineArgs(); if (args.Length == 2) { Console.Out.WriteLine("Loading ROM: " + args[1]); NitroROMFilesystem fs = new NitroROMFilesystem(args[1]); ROM.load(fs); SpriteData.Load(); if (Properties.Settings.Default.mdi) { new MdiParentForm().Show(); } else { new LevelChooser().Show(); } } else { new StartForm().Show(); } Application.Run(); //string[] args = Environment.GetCommandLineArgs(); /* * * if(args.Length > 2 && args[2] == "asmpatch") * { * PatchMaker pm = new PatchMaker(ROM.romfile.Directory); * pm.restore(); * pm.generatePatch(); * } * else if(args.Length > 2 && args[2] == "getcodeaddr") * { * PatchMaker pm = new PatchMaker(ROM.romfile.Directory); * pm.restore(); * Console.Out.WriteLine(String.Format("{0:X8}", pm.getCodeAddr())); * }*/ }
private void openRomButton_Click(object sender, EventArgs e) { string path = ""; string[] backups = null; if (Properties.Settings.Default.BackupFiles != "" && MessageBox.Show(LanguageManager.Get("StartForm", "OpenBackups"), LanguageManager.Get("StartForm", "OpenBackupsTitle"), MessageBoxButtons.YesNo) == DialogResult.Yes) { backups = Properties.Settings.Default.BackupFiles.Split(';'); path = backups[0]; } else { OpenFileDialog openROMDialog = new OpenFileDialog(); openROMDialog.Filter = LanguageManager.Get("Filters", "rom"); if (Properties.Settings.Default.ROMFolder != "") { openROMDialog.InitialDirectory = Properties.Settings.Default.ROMFolder; } if (openROMDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { path = openROMDialog.FileName; } } if (path == "") { return; } try { NitroROMFilesystem fs = new NitroROMFilesystem(path); Properties.Settings.Default.ROMPath = path; Properties.Settings.Default.Save(); Properties.Settings.Default.ROMFolder = System.IO.Path.GetDirectoryName(path); Properties.Settings.Default.Save(); if (backups != null) { for (int l = 1; l < backups.Length; l++) { ROM.fileBackups.Add(backups[l]); } } run(fs); //DEBUG PRINT SHIT /*foreach(File file in fs.allFiles) * { * Directory lastDir = file.parentDir; * while (true) * { * if(lastDir != null) * { * Console.Write("/" + lastDir.name); * } * lastDir = lastDir.parentDir; * break; * } * Console.WriteLine("/" + file.name + " = " + (file.id - 131) + ","); * }*/ } catch (Exception ex) { MessageBox.Show(ex.Message); } }