UI: Added load random game shortcut

This commit is contained in:
Sour 2019-10-11 19:21:42 -04:00
parent 9ec6b5f409
commit 8beeecbd8f
9 changed files with 155 additions and 57 deletions

View file

@ -387,6 +387,7 @@ enum class EmulatorShortcut
LoadStateFromFile,
OpenFile,
LoadRandomGame,
ShortcutCount
};

View file

@ -82,6 +82,7 @@ namespace Mesen.GUI.Config.Shortcuts
LoadStateSlotAuto,
LoadStateFromFile,
OpenFile
OpenFile,
LoadRandomGame,
}
}

View file

@ -1,6 +1,7 @@
using Mesen.GUI.Config;
using Mesen.GUI.Config.Shortcuts;
using Mesen.GUI.Forms;
using Mesen.GUI.Utilities;
using System;
using System.Collections.Generic;
using System.IO;
@ -90,6 +91,8 @@ namespace Mesen.GUI.Emulation
case EmulatorShortcut.IncreaseSpeed: IncreaseEmulationSpeed(); break;
case EmulatorShortcut.DecreaseSpeed: DecreaseEmulationSpeed(); break;
case EmulatorShortcut.LoadRandomGame: RandomGameHelper.LoadRandomGame(); break;
case EmulatorShortcut.SetScale1x: _displayManager.SetScale(1, true); break;
case EmulatorShortcut.SetScale2x: _displayManager.SetScale(2, true); break;
case EmulatorShortcut.SetScale3x: _displayManager.SetScale(3, true); break;

View file

@ -77,7 +77,8 @@ namespace Mesen.GUI.Forms.Config
EmulatorShortcut.DecreaseSpeed,
EmulatorShortcut.OpenFile,
EmulatorShortcut.LoadRandomGame,
EmulatorShortcut.MoveToNextStateSlot,
EmulatorShortcut.MoveToPreviousStateSlot,
EmulatorShortcut.SaveState,

View file

@ -97,6 +97,7 @@
this.mnuPrescale8xFilter = new System.Windows.Forms.ToolStripMenuItem();
this.mnuPrescale10xFilter = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem19 = new System.Windows.Forms.ToolStripSeparator();
this.mnuBilinearInterpolation = new System.Windows.Forms.ToolStripMenuItem();
this.mnuBlendHighResolutionModes = new System.Windows.Forms.ToolStripMenuItem();
this.mnuRegion = new System.Windows.Forms.ToolStripMenuItem();
this.mnuRegionAuto = new System.Windows.Forms.ToolStripMenuItem();
@ -130,8 +131,9 @@
this.mnuDebugger = new System.Windows.Forms.ToolStripMenuItem();
this.mnuEventViewer = new System.Windows.Forms.ToolStripMenuItem();
this.mnuMemoryTools = new System.Windows.Forms.ToolStripMenuItem();
this.mnuTraceLogger = new System.Windows.Forms.ToolStripMenuItem();
this.mnuRegisterViewer = new System.Windows.Forms.ToolStripMenuItem();
this.mnuScriptWindow = new System.Windows.Forms.ToolStripMenuItem();
this.mnuTraceLogger = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem12 = new System.Windows.Forms.ToolStripSeparator();
this.mnuTilemapViewer = new System.Windows.Forms.ToolStripMenuItem();
this.mnuTileViewer = new System.Windows.Forms.ToolStripMenuItem();
@ -149,8 +151,7 @@
this.mnuAbout = new System.Windows.Forms.ToolStripMenuItem();
this.pnlRenderer = new System.Windows.Forms.Panel();
this.ctrlRecentGames = new Mesen.GUI.Controls.ctrlRecentGames();
this.mnuBilinearInterpolation = new System.Windows.Forms.ToolStripMenuItem();
this.mnuRegisterViewer = new System.Windows.Forms.ToolStripMenuItem();
this.mnuRandomGame = new System.Windows.Forms.ToolStripMenuItem();
this.mnuMain.SuspendLayout();
this.pnlRenderer.SuspendLayout();
this.SuspendLayout();
@ -199,49 +200,49 @@
//
this.mnuOpen.Image = global::Mesen.GUI.Properties.Resources.Folder;
this.mnuOpen.Name = "mnuOpen";
this.mnuOpen.Size = new System.Drawing.Size(152, 22);
this.mnuOpen.Size = new System.Drawing.Size(136, 22);
this.mnuOpen.Text = "Open";
//
// toolStripMenuItem2
//
this.toolStripMenuItem2.Name = "toolStripMenuItem2";
this.toolStripMenuItem2.Size = new System.Drawing.Size(149, 6);
this.toolStripMenuItem2.Size = new System.Drawing.Size(133, 6);
//
// mnuSaveState
//
this.mnuSaveState.Name = "mnuSaveState";
this.mnuSaveState.Size = new System.Drawing.Size(152, 22);
this.mnuSaveState.Size = new System.Drawing.Size(136, 22);
this.mnuSaveState.Text = "Save State";
this.mnuSaveState.DropDownOpening += new System.EventHandler(this.mnuSaveState_DropDownOpening);
//
// mnuLoadState
//
this.mnuLoadState.Name = "mnuLoadState";
this.mnuLoadState.Size = new System.Drawing.Size(152, 22);
this.mnuLoadState.Size = new System.Drawing.Size(136, 22);
this.mnuLoadState.Text = "Load State";
this.mnuLoadState.DropDownOpening += new System.EventHandler(this.mnuLoadState_DropDownOpening);
//
// toolStripMenuItem10
//
this.toolStripMenuItem10.Name = "toolStripMenuItem10";
this.toolStripMenuItem10.Size = new System.Drawing.Size(149, 6);
this.toolStripMenuItem10.Size = new System.Drawing.Size(133, 6);
//
// mnuRecentFiles
//
this.mnuRecentFiles.Name = "mnuRecentFiles";
this.mnuRecentFiles.Size = new System.Drawing.Size(152, 22);
this.mnuRecentFiles.Size = new System.Drawing.Size(136, 22);
this.mnuRecentFiles.Text = "Recent Files";
//
// toolStripMenuItem6
//
this.toolStripMenuItem6.Name = "toolStripMenuItem6";
this.toolStripMenuItem6.Size = new System.Drawing.Size(149, 6);
this.toolStripMenuItem6.Size = new System.Drawing.Size(133, 6);
//
// mnuExit
//
this.mnuExit.Image = global::Mesen.GUI.Properties.Resources.Exit;
this.mnuExit.Name = "mnuExit";
this.mnuExit.Size = new System.Drawing.Size(152, 22);
this.mnuExit.Size = new System.Drawing.Size(136, 22);
this.mnuExit.Text = "Exit";
//
// mnuGame
@ -263,7 +264,7 @@
this.mnuPause.Enabled = false;
this.mnuPause.Image = global::Mesen.GUI.Properties.Resources.MediaPause;
this.mnuPause.Name = "mnuPause";
this.mnuPause.Size = new System.Drawing.Size(152, 22);
this.mnuPause.Size = new System.Drawing.Size(139, 22);
this.mnuPause.Text = "Pause";
//
// mnuReset
@ -271,7 +272,7 @@
this.mnuReset.Enabled = false;
this.mnuReset.Image = global::Mesen.GUI.Properties.Resources.Refresh;
this.mnuReset.Name = "mnuReset";
this.mnuReset.Size = new System.Drawing.Size(152, 22);
this.mnuReset.Size = new System.Drawing.Size(139, 22);
this.mnuReset.Text = "Reset";
//
// mnuPowerCycle
@ -279,19 +280,19 @@
this.mnuPowerCycle.Enabled = false;
this.mnuPowerCycle.Image = global::Mesen.GUI.Properties.Resources.PowerCycle;
this.mnuPowerCycle.Name = "mnuPowerCycle";
this.mnuPowerCycle.Size = new System.Drawing.Size(152, 22);
this.mnuPowerCycle.Size = new System.Drawing.Size(139, 22);
this.mnuPowerCycle.Text = "Power Cycle";
//
// toolStripMenuItem24
//
this.toolStripMenuItem24.Name = "toolStripMenuItem24";
this.toolStripMenuItem24.Size = new System.Drawing.Size(149, 6);
this.toolStripMenuItem24.Size = new System.Drawing.Size(136, 6);
//
// mnuPowerOff
//
this.mnuPowerOff.Image = global::Mesen.GUI.Properties.Resources.MediaStop;
this.mnuPowerOff.Name = "mnuPowerOff";
this.mnuPowerOff.Size = new System.Drawing.Size(152, 22);
this.mnuPowerOff.Size = new System.Drawing.Size(139, 22);
this.mnuPowerOff.Text = "Power Off";
//
// mnuOptions
@ -331,7 +332,7 @@
this.mnuShowFPS});
this.mnuEmulationSpeed.Image = global::Mesen.GUI.Properties.Resources.Speed;
this.mnuEmulationSpeed.Name = "mnuEmulationSpeed";
this.mnuEmulationSpeed.Size = new System.Drawing.Size(152, 22);
this.mnuEmulationSpeed.Size = new System.Drawing.Size(135, 22);
this.mnuEmulationSpeed.Text = "Speed";
this.mnuEmulationSpeed.DropDownOpening += new System.EventHandler(this.mnuEmulationSpeed_DropDownOpening);
//
@ -418,7 +419,7 @@
this.mnuFullscreen});
this.mnuVideoScale.Image = global::Mesen.GUI.Properties.Resources.Fullscreen;
this.mnuVideoScale.Name = "mnuVideoScale";
this.mnuVideoScale.Size = new System.Drawing.Size(152, 22);
this.mnuVideoScale.Size = new System.Drawing.Size(135, 22);
this.mnuVideoScale.Text = "Video Size";
this.mnuVideoScale.DropDownOpening += new System.EventHandler(this.mnuVideoScale_DropDownOpening);
//
@ -505,7 +506,7 @@
this.mnuBlendHighResolutionModes});
this.mnuVideoFilter.Image = global::Mesen.GUI.Properties.Resources.VideoFilter;
this.mnuVideoFilter.Name = "mnuVideoFilter";
this.mnuVideoFilter.Size = new System.Drawing.Size(152, 22);
this.mnuVideoFilter.Size = new System.Drawing.Size(135, 22);
this.mnuVideoFilter.Text = "Video Filter";
this.mnuVideoFilter.DropDownOpening += new System.EventHandler(this.mnuVideoFilter_DropDownOpening);
//
@ -676,6 +677,13 @@
this.toolStripMenuItem19.Name = "toolStripMenuItem19";
this.toolStripMenuItem19.Size = new System.Drawing.Size(228, 6);
//
// mnuBilinearInterpolation
//
this.mnuBilinearInterpolation.CheckOnClick = true;
this.mnuBilinearInterpolation.Name = "mnuBilinearInterpolation";
this.mnuBilinearInterpolation.Size = new System.Drawing.Size(231, 22);
this.mnuBilinearInterpolation.Text = "Use Bilinear Interpolation";
//
// mnuBlendHighResolutionModes
//
this.mnuBlendHighResolutionModes.CheckOnClick = true;
@ -692,7 +700,7 @@
this.mnuRegionPal});
this.mnuRegion.Image = global::Mesen.GUI.Properties.Resources.WebBrowser;
this.mnuRegion.Name = "mnuRegion";
this.mnuRegion.Size = new System.Drawing.Size(152, 22);
this.mnuRegion.Size = new System.Drawing.Size(135, 22);
this.mnuRegion.Text = "Region";
this.mnuRegion.DropDownOpening += new System.EventHandler(this.mnuRegion_DropDownOpening);
//
@ -722,13 +730,13 @@
// toolStripMenuItem4
//
this.toolStripMenuItem4.Name = "toolStripMenuItem4";
this.toolStripMenuItem4.Size = new System.Drawing.Size(149, 6);
this.toolStripMenuItem4.Size = new System.Drawing.Size(132, 6);
//
// mnuAudioConfig
//
this.mnuAudioConfig.Image = global::Mesen.GUI.Properties.Resources.Audio;
this.mnuAudioConfig.Name = "mnuAudioConfig";
this.mnuAudioConfig.Size = new System.Drawing.Size(152, 22);
this.mnuAudioConfig.Size = new System.Drawing.Size(135, 22);
this.mnuAudioConfig.Text = "Audio";
this.mnuAudioConfig.Click += new System.EventHandler(this.mnuAudioConfig_Click);
//
@ -736,7 +744,7 @@
//
this.mnuInputConfig.Image = global::Mesen.GUI.Properties.Resources.Controller;
this.mnuInputConfig.Name = "mnuInputConfig";
this.mnuInputConfig.Size = new System.Drawing.Size(152, 22);
this.mnuInputConfig.Size = new System.Drawing.Size(135, 22);
this.mnuInputConfig.Text = "Input";
this.mnuInputConfig.Click += new System.EventHandler(this.mnuInputConfig_Click);
//
@ -744,7 +752,7 @@
//
this.mnuVideoConfig.Image = global::Mesen.GUI.Properties.Resources.VideoOptions;
this.mnuVideoConfig.Name = "mnuVideoConfig";
this.mnuVideoConfig.Size = new System.Drawing.Size(152, 22);
this.mnuVideoConfig.Size = new System.Drawing.Size(135, 22);
this.mnuVideoConfig.Text = "Video";
this.mnuVideoConfig.Click += new System.EventHandler(this.mnuVideoConfig_Click);
//
@ -752,20 +760,20 @@
//
this.mnuEmulationConfig.Image = global::Mesen.GUI.Properties.Resources.DipSwitches;
this.mnuEmulationConfig.Name = "mnuEmulationConfig";
this.mnuEmulationConfig.Size = new System.Drawing.Size(152, 22);
this.mnuEmulationConfig.Size = new System.Drawing.Size(135, 22);
this.mnuEmulationConfig.Text = "Emulation";
this.mnuEmulationConfig.Click += new System.EventHandler(this.mnuEmulationConfig_Click);
//
// toolStripMenuItem3
//
this.toolStripMenuItem3.Name = "toolStripMenuItem3";
this.toolStripMenuItem3.Size = new System.Drawing.Size(149, 6);
this.toolStripMenuItem3.Size = new System.Drawing.Size(132, 6);
//
// mnuPreferences
//
this.mnuPreferences.Image = global::Mesen.GUI.Properties.Resources.Settings;
this.mnuPreferences.Name = "mnuPreferences";
this.mnuPreferences.Size = new System.Drawing.Size(152, 22);
this.mnuPreferences.Size = new System.Drawing.Size(135, 22);
this.mnuPreferences.Text = "Preferences";
this.mnuPreferences.Click += new System.EventHandler(this.mnuPreferences_Click);
//
@ -779,6 +787,7 @@
this.toolStripMenuItem11,
this.mnuLogWindow,
this.toolStripMenuItem7,
this.mnuRandomGame,
this.mnuTakeScreenshot});
this.mnuTools.Name = "mnuTools";
this.mnuTools.Size = new System.Drawing.Size(47, 20);
@ -795,14 +804,14 @@
this.mnuStopMovie});
this.mnuMovies.Image = global::Mesen.GUI.Properties.Resources.Movie;
this.mnuMovies.Name = "mnuMovies";
this.mnuMovies.Size = new System.Drawing.Size(159, 22);
this.mnuMovies.Size = new System.Drawing.Size(182, 22);
this.mnuMovies.Text = "Movies";
//
// mnuPlayMovie
//
this.mnuPlayMovie.Image = global::Mesen.GUI.Properties.Resources.MediaPlay;
this.mnuPlayMovie.Name = "mnuPlayMovie";
this.mnuPlayMovie.Size = new System.Drawing.Size(120, 22);
this.mnuPlayMovie.Size = new System.Drawing.Size(152, 22);
this.mnuPlayMovie.Text = "Play...";
this.mnuPlayMovie.Click += new System.EventHandler(this.mnuPlayMovie_Click);
//
@ -810,7 +819,7 @@
//
this.mnuRecordMovie.Image = global::Mesen.GUI.Properties.Resources.Record;
this.mnuRecordMovie.Name = "mnuRecordMovie";
this.mnuRecordMovie.Size = new System.Drawing.Size(120, 22);
this.mnuRecordMovie.Size = new System.Drawing.Size(152, 22);
this.mnuRecordMovie.Text = "Record...";
this.mnuRecordMovie.Click += new System.EventHandler(this.mnuRecordMovie_Click);
//
@ -818,14 +827,14 @@
//
this.mnuStopMovie.Image = global::Mesen.GUI.Properties.Resources.MediaStop;
this.mnuStopMovie.Name = "mnuStopMovie";
this.mnuStopMovie.Size = new System.Drawing.Size(120, 22);
this.mnuStopMovie.Size = new System.Drawing.Size(152, 22);
this.mnuStopMovie.Text = "Stop";
this.mnuStopMovie.Click += new System.EventHandler(this.mnuStopMovie_Click);
//
// toolStripMenuItem25
//
this.toolStripMenuItem25.Name = "toolStripMenuItem25";
this.toolStripMenuItem25.Size = new System.Drawing.Size(156, 6);
this.toolStripMenuItem25.Size = new System.Drawing.Size(179, 6);
//
// mnuSoundRecorder
//
@ -834,7 +843,7 @@
this.mnuWaveStop});
this.mnuSoundRecorder.Image = global::Mesen.GUI.Properties.Resources.Microphone;
this.mnuSoundRecorder.Name = "mnuSoundRecorder";
this.mnuSoundRecorder.Size = new System.Drawing.Size(159, 22);
this.mnuSoundRecorder.Size = new System.Drawing.Size(182, 22);
this.mnuSoundRecorder.Text = "Sound Recorder";
//
// mnuWaveRecord
@ -860,7 +869,7 @@
this.mnuAviStop});
this.mnuVideoRecorder.Image = global::Mesen.GUI.Properties.Resources.VideoRecorder;
this.mnuVideoRecorder.Name = "mnuVideoRecorder";
this.mnuVideoRecorder.Size = new System.Drawing.Size(159, 22);
this.mnuVideoRecorder.Size = new System.Drawing.Size(182, 22);
this.mnuVideoRecorder.Text = "Video Recorder";
//
// mnuAviRecord
@ -882,26 +891,26 @@
// toolStripMenuItem11
//
this.toolStripMenuItem11.Name = "toolStripMenuItem11";
this.toolStripMenuItem11.Size = new System.Drawing.Size(156, 6);
this.toolStripMenuItem11.Size = new System.Drawing.Size(179, 6);
//
// mnuLogWindow
//
this.mnuLogWindow.Image = global::Mesen.GUI.Properties.Resources.LogWindow;
this.mnuLogWindow.Name = "mnuLogWindow";
this.mnuLogWindow.Size = new System.Drawing.Size(159, 22);
this.mnuLogWindow.Size = new System.Drawing.Size(182, 22);
this.mnuLogWindow.Text = "Log Window";
this.mnuLogWindow.Click += new System.EventHandler(this.mnuLogWindow_Click);
//
// toolStripMenuItem7
//
this.toolStripMenuItem7.Name = "toolStripMenuItem7";
this.toolStripMenuItem7.Size = new System.Drawing.Size(156, 6);
this.toolStripMenuItem7.Size = new System.Drawing.Size(179, 6);
//
// mnuTakeScreenshot
//
this.mnuTakeScreenshot.Image = global::Mesen.GUI.Properties.Resources.Camera;
this.mnuTakeScreenshot.Name = "mnuTakeScreenshot";
this.mnuTakeScreenshot.Size = new System.Drawing.Size(159, 22);
this.mnuTakeScreenshot.Size = new System.Drawing.Size(182, 22);
this.mnuTakeScreenshot.Text = "Take Screenshot";
//
// mnuDebug
@ -949,12 +958,12 @@
this.mnuMemoryTools.Size = new System.Drawing.Size(155, 22);
this.mnuMemoryTools.Text = "Memory Tools";
//
// mnuTraceLogger
// mnuRegisterViewer
//
this.mnuTraceLogger.Image = global::Mesen.GUI.Properties.Resources.LogWindow;
this.mnuTraceLogger.Name = "mnuTraceLogger";
this.mnuTraceLogger.Size = new System.Drawing.Size(155, 22);
this.mnuTraceLogger.Text = "Trace Logger";
this.mnuRegisterViewer.Image = global::Mesen.GUI.Properties.Resources.RegisterIcon;
this.mnuRegisterViewer.Name = "mnuRegisterViewer";
this.mnuRegisterViewer.Size = new System.Drawing.Size(155, 22);
this.mnuRegisterViewer.Text = "Register Viewer";
//
// mnuScriptWindow
//
@ -963,6 +972,13 @@
this.mnuScriptWindow.Size = new System.Drawing.Size(155, 22);
this.mnuScriptWindow.Text = "Script Window";
//
// mnuTraceLogger
//
this.mnuTraceLogger.Image = global::Mesen.GUI.Properties.Resources.LogWindow;
this.mnuTraceLogger.Name = "mnuTraceLogger";
this.mnuTraceLogger.Size = new System.Drawing.Size(155, 22);
this.mnuTraceLogger.Text = "Trace Logger";
//
// toolStripMenuItem12
//
this.toolStripMenuItem12.Name = "toolStripMenuItem12";
@ -1090,19 +1106,12 @@
this.ctrlRecentGames.TabIndex = 1;
this.ctrlRecentGames.Visible = false;
//
// mnuBilinearInterpolation
// mnuRandomGame
//
this.mnuBilinearInterpolation.CheckOnClick = true;
this.mnuBilinearInterpolation.Name = "mnuBilinearInterpolation";
this.mnuBilinearInterpolation.Size = new System.Drawing.Size(231, 22);
this.mnuBilinearInterpolation.Text = "Use Bilinear Interpolation";
//
// mnuRegisterViewer
//
this.mnuRegisterViewer.Image = global::Mesen.GUI.Properties.Resources.RegisterIcon;
this.mnuRegisterViewer.Name = "mnuRegisterViewer";
this.mnuRegisterViewer.Size = new System.Drawing.Size(155, 22);
this.mnuRegisterViewer.Text = "Register Viewer";
this.mnuRandomGame.Image = global::Mesen.GUI.Properties.Resources.Dice;
this.mnuRandomGame.Name = "mnuRandomGame";
this.mnuRandomGame.Size = new System.Drawing.Size(182, 22);
this.mnuRandomGame.Text = "Load Random Game";
//
// frmMain
//
@ -1253,5 +1262,6 @@
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem25;
private System.Windows.Forms.ToolStripMenuItem mnuBilinearInterpolation;
private System.Windows.Forms.ToolStripMenuItem mnuRegisterViewer;
private System.Windows.Forms.ToolStripMenuItem mnuRandomGame;
}
}

View file

@ -238,6 +238,7 @@ namespace Mesen.GUI.Forms
_shortcuts.BindShortcut(mnuFullscreen, EmulatorShortcut.ToggleFullscreen);
_shortcuts.BindShortcut(mnuTakeScreenshot, EmulatorShortcut.TakeScreenshot, running);
_shortcuts.BindShortcut(mnuRandomGame, EmulatorShortcut.LoadRandomGame);
mnuDebugger.InitShortcut(this, nameof(DebuggerShortcutsConfig.OpenDebugger));
mnuSpcDebugger.InitShortcut(this, nameof(DebuggerShortcutsConfig.OpenSpcDebugger));

View file

@ -851,6 +851,7 @@
<Compile Include="Utilities\InBackgroundHelper.cs" />
<Compile Include="Utilities\Md5Helper.cs" />
<Compile Include="Updates\UpdateHelper.cs" />
<Compile Include="Utilities\RandomGameHelper.cs" />
<Compile Include="Utilities\XmlColor.cs" />
<None Include="Resources\GsuDebugger.png" />
<None Include="Resources\Sa1Debugger.png" />

View file

@ -12,6 +12,18 @@ namespace Mesen.GUI.Utilities
{
public static class FolderHelper
{
public static bool IsRomFile(string path)
{
string ext = Path.GetExtension(path).ToLower();
return ext == ".sfc" || ext == ".swc" || ext == ".fig" || ext == ".swc";
}
public static bool IsArchiveFile(string path)
{
string ext = Path.GetExtension(path).ToLower();
return ext == ".7z" || ext == ".zip";
}
public static bool CheckFolderPermissions(string folder, bool checkWritePermission = true)
{
if(!Directory.Exists(folder)) {

View file

@ -0,0 +1,68 @@
using Mesen.GUI.Config;
using Mesen.GUI.Emulation;
using Mesen.GUI.Forms;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Mesen.GUI.Utilities
{
public static class RandomGameHelper
{
public static void LoadRandomGame()
{
IEnumerable<string> gameFolders;
SearchOption searchOptions = SearchOption.TopDirectoryOnly;
if(ConfigManager.Config.Preferences.OverrideGameFolder && Directory.Exists(ConfigManager.Config.Preferences.GameFolder)) {
gameFolders = new List<string>() { ConfigManager.Config.Preferences.GameFolder };
searchOptions = SearchOption.AllDirectories;
} else {
gameFolders = ConfigManager.Config.RecentFiles.Items.Select(recentFile => recentFile.RomFile.Folder).Distinct();
}
List<string> gameRoms = new List<string>();
foreach(string folder in gameFolders) {
if(Directory.Exists(folder)) {
foreach(string file in Directory.EnumerateFiles(folder, "*.*", searchOptions)) {
if(FolderHelper.IsRomFile(file) || (searchOptions == SearchOption.AllDirectories && FolderHelper.IsArchiveFile(file))) {
gameRoms.Add(file);
}
}
}
}
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(FolderHelper.IsArchiveFile(randomGame)) {
List<ArchiveRomEntry> archiveRomList = ArchiveHelper.GetArchiveRomList(randomGame);
if(archiveRomList.Count > 0) {
ResourcePath res = new ResourcePath() {
InnerFile = archiveRomList[0].Filename,
Path = randomGame
};
if(!archiveRomList[0].IsUtf8) {
res.InnerFileIndex = 1;
}
EmuRunner.LoadRom(res);
break;
} else {
retryCount++;
}
} else {
EmuRunner.LoadRom(randomGame);
break;
}
} while(retryCount < 5);
}
}
}
}