@@ -82,28 +82,7 @@ public frmMain(string[] args)
8282 this . Resize += ResizeRecentGames ;
8383 this . FormClosed += ( s , e ) => Application . RemoveMessageFilter ( this ) ;
8484 }
85-
86- public List < string > PreprocessCommandLineArguments ( string [ ] args , bool toLower )
87- {
88- var switches = new List < string > ( ) ;
89- for ( int i = 0 ; i < args . Length ; i ++ ) {
90- if ( args [ i ] != null ) {
91- string arg = args [ i ] . Trim ( ) ;
92- if ( arg . StartsWith ( "--" ) ) {
93- arg = "/" + arg . Substring ( 2 ) ;
94- } else if ( arg . StartsWith ( "-" ) ) {
95- arg = "/" + arg . Substring ( 1 ) ;
96- }
97-
98- if ( toLower ) {
99- arg = arg . ToLowerInvariant ( ) ;
100- }
101- switches . Add ( arg ) ;
102- }
103- }
104- return switches ;
105- }
106-
85+
10786 public void ProcessCommandLineArguments ( List < string > switches , bool forStartup )
10887 {
10988 if ( forStartup ) {
@@ -121,42 +100,13 @@ public void ProcessCommandLineArguments(List<string> switches, bool forStartup)
121100
122101 public void LoadGameFromCommandLine ( List < string > switches )
123102 {
124- Func < string , bool , string > getValidPath = ( string path , bool forLua ) => {
125- path = path . Trim ( ) ;
126- if ( path . ToLower ( ) . EndsWith ( ".lua" ) == forLua ) {
127- try {
128- if ( ! File . Exists ( path ) ) {
129- //Try loading file as a relative path to the folder Mesen was started from
130- path = Path . Combine ( Program . OriginalFolder , path ) ;
131- }
132- if ( File . Exists ( path ) ) {
133- return path ;
134- }
135- } catch { }
136- }
137- return null ;
138- } ;
103+ string romPath ;
104+ CommandLineHelper . GetRomPathFromCommandLine ( switches , out romPath , out _luaScriptsToLoad ) ;
139105
140- //Check if any Lua scripts were specified
141- _luaScriptsToLoad = new List < string > ( ) ;
142- foreach ( string arg in switches ) {
143- string path = getValidPath ( arg , true ) ;
144- if ( path != null ) {
145- _luaScriptsToLoad . Add ( path ) ;
146- }
147- }
148-
149- bool fileLoaded = false ;
150- foreach ( string arg in switches ) {
151- string path = getValidPath ( arg , false ) ;
152- if ( path != null ) {
153- this . LoadFile ( path ) ;
154- fileLoaded = true ;
155- break ;
156- }
157- }
106+ if ( romPath != null ) {
107+ this . LoadFile ( romPath ) ;
108+ } else {
158109
159- if ( ! fileLoaded ) {
160110 if ( _emuThread == null ) {
161111 //When no ROM is loaded, only process Lua scripts if a ROM was specified as a command line param
162112 _luaScriptsToLoad . Clear ( ) ;
@@ -196,7 +146,7 @@ protected override void OnLoad(EventArgs e)
196146
197147 InteropEmu . ScreenSize originalSize = InteropEmu . GetScreenSize ( false ) ;
198148 VideoInfo . ApplyConfig ( ) ;
199- this . ProcessCommandLineArguments ( this . PreprocessCommandLineArguments ( _commandLineArgs , true ) , true ) ;
149+ this . ProcessCommandLineArguments ( CommandLineHelper . PreprocessCommandLineArguments ( _commandLineArgs , true ) , true ) ;
200150 VideoInfo . ApplyConfig ( ) ;
201151 InteropEmu . ScreenSize newSize = InteropEmu . GetScreenSize ( false ) ;
202152 if ( originalSize . Width != newSize . Width || originalSize . Height != newSize . Height ) {
@@ -267,7 +217,7 @@ protected override void OnShown(EventArgs e)
267217 this . Size = ConfigManager . Config . WindowSize . Value ;
268218 }
269219
270- this . LoadGameFromCommandLine ( this . PreprocessCommandLineArguments ( _commandLineArgs , false ) ) ;
220+ this . LoadGameFromCommandLine ( CommandLineHelper . PreprocessCommandLineArguments ( _commandLineArgs , false ) ) ;
271221
272222 this . menuStrip . VisibleChanged += new System . EventHandler ( this . menuStrip_VisibleChanged ) ;
273223 this . UpdateRendererLocation ( ) ;
@@ -281,7 +231,7 @@ protected override void OnShown(EventArgs e)
281231 //This is needed when DPI display settings is not set to 100%
282232 _enableResize = true ;
283233
284- ProcessFullscreenSwitch ( this . PreprocessCommandLineArguments ( _commandLineArgs , true ) ) ;
234+ ProcessFullscreenSwitch ( CommandLineHelper . PreprocessCommandLineArguments ( _commandLineArgs , true ) ) ;
285235 }
286236
287237 protected override void OnClosing ( CancelEventArgs e )
0 commit comments