private void InitializeStateMenu(ToolStripMenuItem menu, bool forSave) { Action <uint> addSaveStateInfo = (i) => { ToolStripMenuItem item = new ToolStripMenuItem(); menu.DropDownItems.Add(item); if (forSave) { BindShortcut(item, (EmulatorShortcut)((int)EmulatorShortcut.SaveStateSlot1 + i - 1)); } else { BindShortcut(item, (EmulatorShortcut)((int)EmulatorShortcut.LoadStateSlot1 + i - 1)); } }; for (uint i = 1; i <= frmMain.NumberOfSaveSlots; i++) { addSaveStateInfo(i); } if (!forSave) { menu.DropDownItems.Add("-"); addSaveStateInfo(NumberOfSaveSlots + 1); menu.DropDownItems.Add("-"); ToolStripMenuItem loadFromFile = new ToolStripMenuItem(ResourceHelper.GetMessage("LoadFromFile"), Resources.FolderOpen); menu.DropDownItems.Add(loadFromFile); BindShortcut(loadFromFile, EmulatorShortcut.LoadStateFromFile); } else { menu.DropDownItems.Add("-"); ToolStripMenuItem saveToFile = new ToolStripMenuItem(ResourceHelper.GetMessage("SaveToFile"), Resources.Floppy); menu.DropDownItems.Add(saveToFile); BindShortcut(saveToFile, EmulatorShortcut.SaveStateToFile); } }
private void UpdateStateMenu(ToolStripMenuItem menu, bool forSave) { if (this.InvokeRequired) { this.BeginInvoke((MethodInvoker)(() => this.UpdateStateMenu(menu, forSave))); } else { for (uint i = 1; i <= frmMain.NumberOfSaveSlots + (forSave ? 0 : 1); i++) { Int64 fileTime = InteropEmu.GetStateInfo(i); string label; bool isAutoSaveSlot = i == NumberOfSaveSlots + 1; string slotName = isAutoSaveSlot ? "Auto" : i.ToString(); if (fileTime == 0) { label = slotName + ". " + ResourceHelper.GetMessage("EmptyState"); } else { DateTime dateTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(fileTime).ToLocalTime(); label = slotName + ". " + dateTime.ToShortDateString() + " " + dateTime.ToShortTimeString(); } if (i == NumberOfSaveSlots + 1) { //Autosave slot (load only) menu.DropDownItems[NumberOfSaveSlots + 1].Text = label; } else { menu.DropDownItems[(int)i - 1].Text = label; } } } }
private void UpdateStateMenu(ToolStripMenuItem menu, bool forSave) { if (this.InvokeRequired) { this.BeginInvoke((MethodInvoker)(() => this.UpdateStateMenu(menu, forSave))); } else { for (uint i = 1; i <= frmMain.NumberOfSaveSlots + (forSave ? 0 : 1); i++) { string statePath = Path.Combine(ConfigManager.SaveStateFolder, InteropEmu.GetRomInfo().GetRomName() + "_" + i + ".mst"); string label; bool isAutoSaveSlot = i == NumberOfSaveSlots + 1; string slotName = isAutoSaveSlot ? "Auto" : i.ToString(); if (!File.Exists(statePath)) { label = slotName + ". " + ResourceHelper.GetMessage("EmptyState"); } else { DateTime dateTime = new FileInfo(statePath).LastWriteTime; label = slotName + ". " + dateTime.ToShortDateString() + " " + dateTime.ToShortTimeString(); } if (i == NumberOfSaveSlots + 1) { //Autosave slot (load only) menu.DropDownItems[NumberOfSaveSlots + 1].Text = label; } else { menu.DropDownItems[(int)i - 1].Text = label; } } } }
protected override void OnLoad(EventArgs e) { base.OnLoad(e); lblExample.Font = new Font(BaseControl.MonospaceFontFamily, BaseControl.DefaultFontSize - 2); txtAudioOptions.Font = new Font(BaseControl.MonospaceFontFamily, BaseControl.DefaultFontSize - 4); txtEmulationOptions.Font = new Font(BaseControl.MonospaceFontFamily, BaseControl.DefaultFontSize - 4); txtVideoOptions.Font = new Font(BaseControl.MonospaceFontFamily, BaseControl.DefaultFontSize - 4); txtGeneralOptions.Font = new Font(BaseControl.MonospaceFontFamily, BaseControl.DefaultFontSize - 4); lblExample.Text = ConvertSlashes(lblExample.Text); StringBuilder sb = new StringBuilder(); DisplayOptions(typeof(VideoInfo), sb); txtVideoOptions.Text = ConvertSlashes(sb.ToString().Trim()); sb.Clear(); DisplayOptions(typeof(AudioInfo), sb); txtAudioOptions.Text = ConvertSlashes(sb.ToString().Trim()); sb.Clear(); DisplayOptions(typeof(EmulationInfo), sb); txtEmulationOptions.Text = ConvertSlashes(sb.ToString().Trim()); sb.Clear(); DisplayOptions(typeof(Configuration), sb); txtGeneralOptions.Text = ConvertSlashes( ResourceHelper.GetMessage("HelpFullscreen") + Environment.NewLine + ResourceHelper.GetMessage("HelpDoNotSaveSettings") + Environment.NewLine + ResourceHelper.GetMessage("HelpRecordMovie") + Environment.NewLine + ResourceHelper.GetMessage("HelpLoadLastSession") + Environment.NewLine + sb.ToString().Trim() ); }
private void InitializeFdsDiskMenu() { if (this.InvokeRequired) { this.BeginInvoke((MethodInvoker)(() => this.InitializeFdsDiskMenu())); } else { UInt32 sideCount = InteropEmu.FdsGetSideCount(); mnuSelectDisk.DropDownItems.Clear(); if (sideCount > 0) { for (UInt32 i = 0; i < sideCount; i++) { UInt32 diskNumber = i; ToolStripItem item = mnuSelectDisk.DropDownItems.Add(ResourceHelper.GetMessage("FdsDiskSide", (diskNumber / 2 + 1).ToString(), (diskNumber % 2 == 0 ? "A" : "B"))); item.Click += (object sender, EventArgs args) => { InteropEmu.FdsInsertDisk(diskNumber); }; } sepFdsDisk.Visible = true; mnuSelectDisk.Visible = true; mnuEjectDisk.Visible = true; mnuSwitchDiskSide.Visible = sideCount > 1; } else { sepFdsDisk.Visible = false; mnuSelectDisk.Visible = false; mnuEjectDisk.Visible = false; mnuSwitchDiskSide.Visible = false; } } }
private void mnuInstallHdPack_Click(object sender, EventArgs e) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.SetFilter(ResourceHelper.GetMessage("FilterZipFiles")); if (ofd.ShowDialog(this) == DialogResult.OK) { try { using (FileStream stream = File.Open(ofd.FileName, FileMode.Open)) { ZipArchive zip = new ZipArchive(stream); //Find the hires.txt file ZipArchiveEntry hiresEntry = null; foreach (ZipArchiveEntry entry in zip.Entries) { if (entry.Name == "hires.txt") { hiresEntry = entry; break; } } if (hiresEntry != null) { using (Stream entryStream = hiresEntry.Open()) { using (StreamReader reader = new StreamReader(entryStream)) { string hiresData = reader.ReadToEnd(); RomInfo romInfo = InteropEmu.GetRomInfo(); //If there's a "supportedRom" tag, check if it matches the current ROM Regex supportedRomRegex = new Regex("<supportedRom>([^\\n]*)"); Match match = supportedRomRegex.Match(hiresData); if (match.Success) { if (!match.Groups[1].Value.ToUpper().Contains(InteropEmu.GetRomInfo().Sha1.ToUpper())) { MesenMsgBox.Show("InstallHdPackWrongRom", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } //Extract HD pack try { string targetFolder = Path.Combine(ConfigManager.HdPackFolder, Path.GetFileNameWithoutExtension(romInfo.GetRomName())); if (Directory.Exists(targetFolder)) { //Warn if the folder already exists if (MesenMsgBox.Show("InstallHdPackConfirmOverwrite", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, targetFolder) != DialogResult.OK) { return; } } else { Directory.CreateDirectory(targetFolder); } string hiresFileFolder = hiresEntry.FullName.Substring(0, hiresEntry.FullName.Length - "hires.txt".Length); foreach (ZipArchiveEntry entry in zip.Entries) { //Extract only the files in the same subfolder as the hires.txt file (and only if they have a name & size > 0) if (!string.IsNullOrWhiteSpace(entry.Name) && entry.Length > 0 && entry.FullName.StartsWith(hiresFileFolder)) { entry.ExtractToFile(Path.Combine(targetFolder, entry.Name), true); } } } catch (Exception ex) { MesenMsgBox.Show("InstallHdPackError", MessageBoxButtons.OK, MessageBoxIcon.Error, ex.ToString()); return; } } //Turn on HD Pack support automatically after installation succeeds ConfigManager.Config.VideoInfo.UseHdPacks = true; ConfigManager.ApplyChanges(); ConfigManager.Config.ApplyConfig(); if (MesenMsgBox.Show("InstallHdPackConfirmReset", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { //Power cycle game if the user agrees InteropEmu.PowerCycle(); } } } else { MesenMsgBox.Show("InstallHdPackInvalidPack", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch { //Invalid file (file missing, not a zip file, etc.) MesenMsgBox.Show("InstallHdPackInvalidZipFile", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void mnuTestRun_Click(object sender, EventArgs e) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.SetFilter(ResourceHelper.GetMessage("FilterTest")); ofd.InitialDirectory = ConfigManager.TestFolder; ofd.Multiselect = true; if (ofd.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) { List <string> passedTests = new List <string>(); List <string> failedTests = new List <string>(); List <int> failedFrameCount = new List <int>(); this.menuStrip.Enabled = false; Task.Run(() => { foreach (string filename in ofd.FileNames) { int result = InteropEmu.RunRecordedTest(filename); if (result == 0) { passedTests.Add(Path.GetFileNameWithoutExtension(filename)); } else { failedTests.Add(Path.GetFileNameWithoutExtension(filename)); failedFrameCount.Add(result); } } this.BeginInvoke((MethodInvoker)(() => { if (failedTests.Count == 0) { MessageBox.Show("All tests passed.", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { StringBuilder message = new StringBuilder(); if (passedTests.Count > 0) { message.AppendLine("Passed tests:"); foreach (string test in passedTests) { message.AppendLine(" -" + test); } message.AppendLine(""); } message.AppendLine("Failed tests:"); for (int i = 0, len = failedTests.Count; i < len; i++) { message.AppendLine(" -" + failedTests[i] + " (" + failedFrameCount[i] + ")"); } MessageBox.Show(message.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.menuStrip.Enabled = true; })); }); } } }