private void btnUpdate_Click(object sender, EventArgs e) { string destFilePath = Process.GetCurrentProcess().MainModule.FileName; string srcFilePath = Path.Combine(ConfigManager.DownloadFolder, "Mesen." + lblLatestVersionString.Text + ".exe"); string backupFilePath = Path.Combine(ConfigManager.BackupFolder, "Mesen." + lblCurrentVersionString.Text + ".exe"); string updateHelper = Path.Combine(ConfigManager.HomeFolder, "MesenUpdater.exe"); if (!File.Exists(updateHelper)) { MesenMsgBox.Show("UpdaterNotFound", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.Cancel; } else if (!string.IsNullOrWhiteSpace(srcFilePath)) { frmDownloadProgress frmDownload = new frmDownloadProgress("http://www.mesen.ca/Services/GetLatestVersion.php?a=download&p=win&v=" + InteropEmu.GetMesenVersion(), srcFilePath); if (frmDownload.ShowDialog() == DialogResult.OK) { FileInfo fileInfo = new FileInfo(srcFilePath); if (fileInfo.Length > 0 && GetSha1Hash(srcFilePath) == _fileHash) { Process.Start(updateHelper, string.Format("\"{0}\" \"{1}\" \"{2}\"", srcFilePath, destFilePath, backupFilePath)); } else { //Download failed, mismatching hashes MesenMsgBox.Show("UpdateDownloadFailed", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.Cancel; } } } }
private void LoadRandomGame() { IEnumerable <string> gameFolders = ConfigManager.Config.RecentFiles.Select(recentFile => recentFile.RomFile.Folder.ToLowerInvariant()).Distinct(); List <string> gameRoms = new List <string>(); foreach (string folder in gameFolders) { if (Directory.Exists(folder)) { gameRoms.AddRange(Directory.EnumerateFiles(folder, "*.nes", SearchOption.TopDirectoryOnly)); gameRoms.AddRange(Directory.EnumerateFiles(folder, "*.unf", SearchOption.TopDirectoryOnly)); gameRoms.AddRange(Directory.EnumerateFiles(folder, "*.fds", SearchOption.TopDirectoryOnly)); } } if (gameRoms.Count == 0) { MesenMsgBox.Show("RandomGameNoGameFound", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { Random random = new Random(); string randomGame = gameRoms[random.Next(gameRoms.Count)]; LoadFile(randomGame); } }
private void LoadROM(ResourcePath romFile, bool autoLoadPatches = false, ResourcePath?patchFileToApply = null) { if (romFile.Exists) { if (frmSelectRom.SelectRom(ref romFile)) { _currentRomPath = romFile; if (romFile.Compressed) { Interlocked.Increment(ref _romLoadCounter); ctrlNsfPlayer.Visible = false; ctrlLoading.Visible = true; } ResourcePath?patchFile = patchFileToApply; if (patchFile == null && autoLoadPatches) { string[] extensions = new string[3] { ".ips", ".ups", ".bps" }; foreach (string ext in extensions) { string file = Path.Combine(romFile.Folder, Path.GetFileNameWithoutExtension(romFile.FileName)) + ext; if (File.Exists(file)) { patchFile = file; break; } } } Task loadRomTask = new Task(() => { lock (_loadRomLock) { InteropEmu.LoadROM(romFile, (patchFile.HasValue && patchFile.Value.Exists) ? (string)patchFile.Value : string.Empty); } }); loadRomTask.ContinueWith((Task prevTask) => { this.BeginInvoke((MethodInvoker)(() => { if (romFile.Compressed) { Interlocked.Decrement(ref _romLoadCounter); } ConfigManager.Config.AddRecentFile(romFile, patchFileToApply); UpdateRecentFiles(); })); }); loadRomTask.Start(); } } else { MesenMsgBox.Show("FileNotFound", MessageBoxButtons.OK, MessageBoxIcon.Error, romFile.Path); } }
private void tmrStart_Tick(object sender, EventArgs e) { tmrStart.Stop(); DialogResult result = System.Windows.Forms.DialogResult.None; using (var client = new WebClient()) { client.DownloadProgressChanged += (object s, DownloadProgressChangedEventArgs args) => { progressDownload.Value = args.ProgressPercentage; }; client.DownloadFileCompleted += (object s, AsyncCompletedEventArgs args) => { if (!args.Cancelled && args.Error == null && File.Exists(_filename)) { result = System.Windows.Forms.DialogResult.OK; } else if (args.Error != null) { MesenMsgBox.Show("UnableToDownload", MessageBoxButtons.OK, MessageBoxIcon.Error, args.Error.ToString()); result = System.Windows.Forms.DialogResult.Cancel; } }; Task downloadTask = null; try { downloadTask = client.DownloadFileTaskAsync(_link, _filename); } catch (Exception ex) { MesenMsgBox.Show("UnableToDownload", MessageBoxButtons.OK, MessageBoxIcon.Error, ex.ToString()); result = System.Windows.Forms.DialogResult.Cancel; } if (downloadTask == null) { result = System.Windows.Forms.DialogResult.Cancel; } else { while (!downloadTask.IsCompleted && !_cancel) { System.Threading.Thread.Sleep(200); Application.DoEvents(); } if (_cancel) { client.CancelAsync(); } else if (result == System.Windows.Forms.DialogResult.None) { result = System.Windows.Forms.DialogResult.OK; } } } DialogResult = result; this.Close(); }
protected override void OnShown(EventArgs e) { base.OnShown(e); EmuApi.InitDll(); bool showUpgradeMessage = UpdateHelper.PerformUpgrade(); ConfigManager.Config.Video.ApplyConfig(); EmuApi.InitializeEmu(ConfigManager.HomeFolder, Handle, ctrlRenderer.Handle, false, false, false); ConfigManager.Config.InitializeDefaults(); ConfigManager.Config.ApplyConfig(); _displayManager = new DisplayManager(this, ctrlRenderer, pnlRenderer, mnuMain, ctrlRecentGames); _displayManager.SetScaleBasedOnWindowSize(); _shortcuts = new ShortcutHandler(_displayManager); _notifListener = new NotificationListener(); _notifListener.OnNotification += OnNotificationReceived; _commandLine.LoadGameFromCommandLine(); SaveStateManager.InitializeStateMenu(mnuSaveState, true, _shortcuts); SaveStateManager.InitializeStateMenu(mnuLoadState, false, _shortcuts); BindShortcuts(); Task.Run(() => { Thread.Sleep(25); this.BeginInvoke((Action)(() => { ResizeRecentGames(); ctrlRecentGames.Initialize(); if (!EmuRunner.IsRunning()) { ctrlRecentGames.Visible = true; } })); }); if (showUpgradeMessage) { MesenMsgBox.Show("UpgradeSuccess", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (ConfigManager.Config.Preferences.AutomaticallyCheckForUpdates) { UpdateHelper.CheckForUpdates(true); } InBackgroundHelper.StartBackgroundTimer(); this.Resize += frmMain_Resize; }
private void LoadPatchFile(string patchFile) { string patchFolder = Path.GetDirectoryName(patchFile); HashSet <string> romExtensions = new HashSet <string>() { ".nes", ".fds", ".unf", "*.unif" }; List <string> romsInFolder = new List <string>(); foreach (string filepath in Directory.EnumerateFiles(patchFolder)) { if (romExtensions.Contains(Path.GetExtension(filepath).ToLowerInvariant())) { romsInFolder.Add(filepath); } } if (romsInFolder.Count == 1) { //There is a single rom in the same folder as the IPS/BPS patch, use it automatically LoadROM(romsInFolder[0], true, patchFile); } else { if (_emuThread == null) { //Prompt the user for a rom to load if (MesenMsgBox.Show("SelectRomIps", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { using (OpenFileDialog ofd = new OpenFileDialog()) { ofd.SetFilter(ResourceHelper.GetMessage("FilterRom")); if (ConfigManager.Config.RecentFiles.Count > 0) { ofd.InitialDirectory = ConfigManager.Config.RecentFiles[0].RomFile.Folder; } if (ofd.ShowDialog(this) == DialogResult.OK) { LoadROM(ofd.FileName, true, patchFile); } } } } else if (MesenMsgBox.Show("PatchAndReset", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { //Confirm that the user wants to patch the current rom and reset LoadROM(_currentRomPath.Value, true, patchFile); } } }
private void ExportMovie(UInt32 segStart, UInt32 segEnd) { using (SaveFileDialog sfd = new SaveFileDialog()) { sfd.SetFilter(ResourceHelper.GetMessage("FilterMovie")); sfd.InitialDirectory = ConfigManager.MovieFolder; sfd.FileName = EmuApi.GetRomInfo().GetRomName() + ".mmo"; if (sfd.ShowDialog() == DialogResult.OK) { if (!HistoryViewerApi.HistoryViewerSaveMovie(sfd.FileName, segStart, segEnd)) { MesenMsgBox.Show("MovieSaveError", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void mnuCreateSaveState_Click(object sender, EventArgs e) { using (SaveFileDialog sfd = new SaveFileDialog()) { sfd.SetFilter(ResourceHelper.GetMessage("FilterSavestate")); sfd.InitialDirectory = ConfigManager.SaveStateFolder; sfd.FileName = EmuApi.GetRomInfo().GetRomName() + ".mst"; if (sfd.ShowDialog() == DialogResult.OK) { if (!HistoryViewerApi.HistoryViewerCreateSaveState(sfd.FileName, HistoryViewerApi.HistoryViewerGetPosition())) { MesenMsgBox.Show("FileSaveError", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
private void StartEmuThread() { if (_emuThread == null) { _emuThread = new Thread(() => { try { InteropEmu.HistoryViewerRun(); _emuThread = null; } catch (Exception ex) { MesenMsgBox.Show("UnexpectedError", MessageBoxButtons.OK, MessageBoxIcon.Error, ex.ToString()); _emuThread = null; } }); _emuThread.Start(); } }
protected override void OnDragEnter(DragEventArgs e) { base.OnDragEnter(e); try { if (e.Data != null && e.Data.GetDataPresent(DataFormats.FileDrop)) { e.Effect = DragDropEffects.Copy; } else { EmuApi.DisplayMessage("Error", "Unsupported operation."); } } catch (Exception ex) { MesenMsgBox.Show("UnexpectedError", MessageBoxButtons.OK, MessageBoxIcon.Error, ex.ToString()); } }
private void LoadROM(ResourcePath romFile, bool autoLoadPatches = false, ResourcePath?patchFileToApply = null) { if (romFile.Exists) { if (frmSelectRom.SelectRom(ref romFile)) { _currentRomPath = romFile; if (romFile.Compressed) { Interlocked.Increment(ref _romLoadCounter); ctrlNsfPlayer.Visible = false; ctrlLoading.Visible = true; } ResourcePath?patchFile = patchFileToApply; if (patchFile == null && autoLoadPatches) { patchFile = GetIpsFile(romFile); } Task loadRomTask = new Task(() => { lock (_loadRomLock) { InteropEmu.LoadROM(romFile, (patchFile.HasValue && patchFile.Value.Exists) ? (string)patchFile.Value : string.Empty); } }); loadRomTask.ContinueWith((Task prevTask) => { this.BeginInvoke((MethodInvoker)(() => { if (romFile.Compressed) { Interlocked.Decrement(ref _romLoadCounter); } ConfigManager.Config.AddRecentFile(romFile, patchFileToApply); })); }); loadRomTask.Start(); } } else { MesenMsgBox.Show("FileNotFound", MessageBoxButtons.OK, MessageBoxIcon.Error, romFile.Path); } }
private void btnOk_Click(object sender, EventArgs e) { string targetFolder = radStoragePortable.Checked ? ConfigManager.DefaultPortableFolder : ConfigManager.DefaultDocumentsFolder; string testFile = Path.Combine(targetFolder, "test.txt"); try { if (!Directory.Exists(targetFolder)) { Directory.CreateDirectory(targetFolder); } File.WriteAllText(testFile, "test"); File.Delete(testFile); this.InitializeConfig(); this.Close(); } catch (Exception ex) { MesenMsgBox.Show("CannotWriteToFolder", MessageBoxButtons.OK, MessageBoxIcon.Error, ex.ToString()); } }
private void btnUpdate_Click(object sender, EventArgs e) { #if DISABLEAUTOUPDATE MesenMsgBox.Show("AutoUpdateDisabledMessage", MessageBoxButtons.OK, MessageBoxIcon.Information); this.DialogResult = DialogResult.Cancel; this.Close(); #else string destFilePath = System.Reflection.Assembly.GetEntryAssembly().Location; string srcFilePath = Path.Combine(ConfigManager.DownloadFolder, "Mesen." + lblLatestVersionString.Text + ".exe"); string backupFilePath = Path.Combine(ConfigManager.BackupFolder, "Mesen." + lblCurrentVersionString.Text + ".exe"); string updateHelper = Path.Combine(ConfigManager.HomeFolder, "MesenUpdater.exe"); if (!File.Exists(updateHelper)) { MesenMsgBox.Show("UpdaterNotFound", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.Cancel; } else if (!string.IsNullOrWhiteSpace(srcFilePath)) { frmDownloadProgress frmDownload = new frmDownloadProgress("http://www.mesen.ca/Services/GetLatestVersion.php?a=download&p=win&v=" + InteropEmu.GetMesenVersion(), srcFilePath); if (frmDownload.ShowDialog() == DialogResult.OK) { FileInfo fileInfo = new FileInfo(srcFilePath); if (fileInfo.Length > 0 && ResourceManager.GetSha1Hash(File.ReadAllBytes(srcFilePath)) == _fileHash) { if (Program.IsMono) { Process.Start("mono", string.Format("\"{0}\" \"{1}\" \"{2}\" \"{3}\"", updateHelper, srcFilePath, destFilePath, backupFilePath)); } else { Process.Start(updateHelper, string.Format("\"{0}\" \"{1}\" \"{2}\"", srcFilePath, destFilePath, backupFilePath)); } } else { //Download failed, mismatching hashes MesenMsgBox.Show("UpdateDownloadFailed", MessageBoxButtons.OK, MessageBoxIcon.Error); DialogResult = DialogResult.Cancel; } } } #endif }
protected override void OnDragDrop(DragEventArgs e) { base.OnDragDrop(e); try { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); if (File.Exists(files[0])) { EmuRunner.LoadFile(files[0]); this.Activate(); } else { EmuApi.DisplayMessage("Error", "File not found: " + files[0]); } } catch (Exception ex) { MesenMsgBox.Show("UnexpectedError", MessageBoxButtons.OK, MessageBoxIcon.Error, ex.ToString()); } }
private void fileToolStripMenuItem_DropDownOpening(object sender, EventArgs e) { mnuExportMovie.DropDownItems.Clear(); List <UInt32> segments = new List <UInt32>(InteropEmu.HistoryViewerGetSegments()); UInt32 segmentStart = 0; segments.Add(InteropEmu.HistoryViewerGetHistoryLength() / 30); for (int i = 0; i < segments.Count; i++) { if (segments[i] - segmentStart > 4) { //Only list segments that are at least 2 seconds long UInt32 segStart = segmentStart; UInt32 segEnd = segments[i]; TimeSpan start = new TimeSpan(0, 0, (int)(segmentStart) / 2); TimeSpan end = new TimeSpan(0, 0, (int)(segEnd / 2)); string segmentName = ResourceHelper.GetMessage("MovieSegment", (mnuExportMovie.DropDownItems.Count + 1).ToString()); ToolStripMenuItem item = new ToolStripMenuItem(segmentName + ", " + start.ToString() + " - " + end.ToString()); item.Click += (s, evt) => { SaveFileDialog sfd = new SaveFileDialog(); sfd.SetFilter(ResourceHelper.GetMessage("FilterMovie")); sfd.InitialDirectory = ConfigManager.MovieFolder; sfd.FileName = InteropEmu.GetRomInfo().GetRomName() + ".mmo"; if (sfd.ShowDialog() == DialogResult.OK) { if (!InteropEmu.HistoryViewerSaveMovie(sfd.FileName, segStart, segEnd)) { MesenMsgBox.Show("MovieSaveError", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }; mnuExportMovie.DropDownItems.Add(item); } segmentStart = segments[i] + 1; } mnuImportMovie.Visible = false; mnuExportMovie.Enabled = mnuExportMovie.HasDropDownItems && !_isNsf; }
private void CheckForUpdates(bool displayResult) { Task.Run(() => { try { using (var client = new WebClient()) { XmlDocument xmlDoc = new XmlDocument(); string platform = Program.IsMono ? "linux" : "win"; xmlDoc.LoadXml(client.DownloadString("http://www.mesen.ca/Services/GetLatestVersion.php?v=" + InteropEmu.GetMesenVersion() + "&p=" + platform + "&l=" + ResourceHelper.GetLanguageCode())); Version currentVersion = new Version(InteropEmu.GetMesenVersion()); Version latestVersion = new Version(xmlDoc.SelectSingleNode("VersionInfo/LatestVersion").InnerText); string changeLog = xmlDoc.SelectSingleNode("VersionInfo/ChangeLog").InnerText; string fileHash = xmlDoc.SelectSingleNode("VersionInfo/Sha1Hash").InnerText; string donateText = xmlDoc.SelectSingleNode("VersionInfo/DonateText")?.InnerText; if (latestVersion > currentVersion) { this.BeginInvoke((MethodInvoker)(() => { using (frmUpdatePrompt frmUpdate = new frmUpdatePrompt(currentVersion, latestVersion, changeLog, fileHash, donateText)) { if (frmUpdate.ShowDialog(null, this) == DialogResult.OK) { Application.Exit(); } } })); } else if (displayResult) { MesenMsgBox.Show("MesenUpToDate", MessageBoxButtons.OK, MessageBoxIcon.Information); } } } catch (Exception ex) { if (displayResult) { MesenMsgBox.Show("ErrorWhileCheckingUpdates", MessageBoxButtons.OK, MessageBoxIcon.Error, ex.ToString()); } } }); }
private void tmrStart_Tick(object sender, EventArgs e) { tmrStart.Stop(); DialogResult result = System.Windows.Forms.DialogResult.None; Task.Run(() => { using (var client = new WebClient()) { client.DownloadProgressChanged += (object s, DownloadProgressChangedEventArgs args) => { this.BeginInvoke((Action)(() => { lblFilename.Text = string.Format("{0} ({1:0.00}Mb)", _link, (double)args.TotalBytesToReceive / 1024 / 1024); progressDownload.Value = args.ProgressPercentage; })); }; client.DownloadFileCompleted += (object s, AsyncCompletedEventArgs args) => { if (!args.Cancelled && args.Error == null && File.Exists(_filename)) { result = System.Windows.Forms.DialogResult.OK; } else if (args.Error != null) { MesenMsgBox.Show("UnableToDownload", MessageBoxButtons.OK, MessageBoxIcon.Error, args.Error.ToString()); result = System.Windows.Forms.DialogResult.Cancel; } }; Task downloadTask = null; try { downloadTask = client.DownloadFileTaskAsync(_link, _filename); } catch (Exception ex) { MesenMsgBox.Show("UnableToDownload", MessageBoxButtons.OK, MessageBoxIcon.Error, ex.ToString()); result = System.Windows.Forms.DialogResult.Cancel; } if (downloadTask == null) { result = System.Windows.Forms.DialogResult.Cancel; } else { while (!downloadTask.IsCompleted && !_cancel) { System.Threading.Thread.Sleep(200); } if (_cancel) { client.CancelAsync(); } else if (result == System.Windows.Forms.DialogResult.None) { result = System.Windows.Forms.DialogResult.OK; } } } //Wait a bit for the progress bar to update to 100% (display updates are slower than the .Value updates) System.Threading.Thread.Sleep(500); this.BeginInvoke((Action)(() => { DialogResult = result; this.Close(); })); }); }
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 LoadRandomGame() { IEnumerable <string> gameFolders; SearchOption searchOptions = SearchOption.TopDirectoryOnly; if (ConfigManager.Config.PreferenceInfo.OverrideGameFolder && Directory.Exists(ConfigManager.Config.PreferenceInfo.GameFolder)) { gameFolders = new List <string>() { ConfigManager.Config.PreferenceInfo.GameFolder }; searchOptions = SearchOption.AllDirectories; } else { gameFolders = ConfigManager.Config.RecentFiles.Select(recentFile => recentFile.RomFile.Folder.ToLowerInvariant()).Distinct(); } List <string> gameRoms = new List <string>(); foreach (string folder in gameFolders) { if (Directory.Exists(folder)) { gameRoms.AddRange(Directory.EnumerateFiles(folder, "*.nes", searchOptions)); gameRoms.AddRange(Directory.EnumerateFiles(folder, "*.unf", searchOptions)); gameRoms.AddRange(Directory.EnumerateFiles(folder, "*.fds", searchOptions)); if (searchOptions == SearchOption.AllDirectories) { //When loading from a user-specified folder, assume zip/7z files will likely contain a ROM gameRoms.AddRange(Directory.EnumerateFiles(folder, "*.zip", searchOptions)); gameRoms.AddRange(Directory.EnumerateFiles(folder, "*.7z", searchOptions)); } } } if (gameRoms.Count == 0) { MesenMsgBox.Show("RandomGameNoGameFound", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { int retryCount = 0; Random random = new Random(); do { string randomGame = gameRoms[random.Next(gameRoms.Count)]; if (randomGame.EndsWith(".7z", StringComparison.InvariantCultureIgnoreCase) || randomGame.EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase)) { List <InteropEmu.ArchiveRomEntry> archiveRomList = InteropEmu.GetArchiveRomList(randomGame); if (archiveRomList.Count > 0) { ResourcePath res = new ResourcePath() { InnerFile = archiveRomList[0].Filename, Path = randomGame }; if (!archiveRomList[0].IsUtf8) { res.InnerFileIndex = 1; } LoadROM(res); break; } else { retryCount++; } } else { LoadFile(randomGame); break; } } while(retryCount < 5); } }