@@ -33,7 +33,7 @@ using namespace std;
3333
3434static string BaseDirectory;
3535static string FileBase;
36- static string FileExt; /* Includes the . character, as in ".nes" */
36+ static string FileExt; /* Includes the . character, as in ".nes" */
3737static string FileBaseDirectory;
3838
3939
@@ -163,9 +163,9 @@ void MDFN_CheckFIROPSafe(const std::string &path)
163163
164164void MDFN_GetFilePathComponents (const std::string &file_path, std::string *dir_path_out, std::string *file_base_out, std::string *file_ext_out)
165165{
166- size_t final_ds; // in file_path
166+ size_t final_ds; // in file_path
167167 string file_name;
168- size_t fn_final_dot; // in local var file_name
168+ size_t fn_final_dot; // in local var file_name
169169 // Temporary output:
170170 string dir_path, file_base, file_ext;
171171
@@ -346,22 +346,22 @@ std::string MDFN_MakeFName(MakeFName_Type type, int id1, const char *cd1)
346346 {
347347 fmap[' d' ] = FileBaseDirectory;
348348 fmap[' f' ] = FileBase;
349- fmap[' F' ] = FileBase; // If game is a CD, and the CD is recognized as being part of a multi-CD set, then this
350- // will be replaced with MDFNGameInfo->shortname
349+ fmap[' F' ] = FileBase; // If game is a CD, and the CD is recognized as being part of a multi-CD set, then this
350+ // will be replaced with MDFNGameInfo->shortname
351351
352352 fmap[' m' ] = md5_context::asciistr (MDFNGameInfo->MD5 , 0 ); // MD5 hash of the currently loaded game ONLY.
353353
354- fmap[' M' ] = " " ; // One with this empty, if file not found, then fill with MD5 hash of the currently loaded game,
355- // or the MD5 gameset hash for certain CD games, followed by a period and go with that result.
356- // Note: The MD5-less result is skipped if the CD is part of a recognized multi-CD set.
354+ fmap[' M' ] = " " ; // One with this empty, if file not found, then fill with MD5 hash of the currently loaded game,
355+ // or the MD5 gameset hash for certain CD games, followed by a period and go with that result.
356+ // Note: The MD5-less result is skipped if the CD is part of a recognized multi-CD set.
357357 fmap[' e' ] = FileExt;
358358 fmap[' s' ] = MDFNGameInfo->shortname ;
359359
360360 fmap[' p' ] = " " ;
361361
362362
363- fmap[' x' ] = " " ; // Default extension(without period)
364- fmap[' X' ] = " " ; // A merging of x and p
363+ fmap[' x' ] = " " ; // Default extension(without period)
364+ fmap[' X' ] = " " ; // A merging of x and p
365365
366366 if (MDFNGameInfo->GameSetMD5Valid )
367367 {
@@ -381,187 +381,189 @@ std::string MDFN_MakeFName(MakeFName_Type type, int id1, const char *cd1)
381381 case MDFNMKF_STATE:
382382 case MDFNMKF_SAV:
383383 case MDFNMKF_SAVBACK:
384- {
385- std::string dir, fstring, fpath;
386-
387- if (type == MDFNMKF_MOVIE)
388- {
389- dir = MDFN_GetSettingS (" filesys.path_movie" );
390- fstring = MDFN_GetSettingS (" filesys.fname_movie" );
391- fmap[' x' ] = " mcm" ;
392- }
393- else if (type == MDFNMKF_STATE)
394- {
384+ {
385+ std::string dir, fstring, fpath;
386+
387+ if (type == MDFNMKF_MOVIE)
388+ {
389+ // dir = MDFN_GetSettingS("filesys.path_movie");
390+ dir = FileBaseDirectory;
391+ fstring = MDFN_GetSettingS (" filesys.fname_movie" );
392+ fmap[' x' ] = " mcm" ;
393+ }
394+ else if (type == MDFNMKF_STATE)
395+ {
395396 // dir = MDFN_GetSettingS("filesys.path_state");
396397 dir = FileBaseDirectory;
397398 fstring = MDFN_GetSettingS (" filesys.fname_state" );
398- fmap[' x' ] = (cd1 ? cd1 : " mcs" );
399- }
400- else if (type == MDFNMKF_SAV)
401- {
402- dir = MDFN_GetSettingS (" filesys.path_sav" );
403- fstring = MDFN_GetSettingS (" filesys.fname_sav" );
404- fmap[' x' ] = std::string (cd1);
405- }
406- else if (type == MDFNMKF_SAVBACK)
407- {
408- dir = MDFN_GetSettingS (" filesys.path_savbackup" );
409- fstring = MDFN_GetSettingS (" filesys.fname_savbackup" );
410- fmap[' x' ] = std::string (cd1);
411- }
412-
413- fmap[' X' ] = fmap[' x' ];
414-
415- if (type == MDFNMKF_SAVBACK)
416- {
417- if (id1 < 0 )
418- fmap[' p' ] = " C" ;
419- else
420- {
421- trio_snprintf (numtmp, sizeof (numtmp), " %u" , id1);
422- fmap[' p' ] = std::string (numtmp);
423- }
424- }
425- else if (type != MDFNMKF_SAV && !cd1)
426- {
427- trio_snprintf (numtmp, sizeof (numtmp), " %d" , id1);
428- fmap[' p' ] = std::string (numtmp);
429- }
430-
431- if (fmap[' X' ].size () > 1 && fmap[' p' ].size ())
432- fmap[' X' ] = fmap[' X' ].erase (fmap[' X' ].size () - 1 ) + fmap[' p' ];
433-
434- for (int i = 0 ; i < 2 ; i++)
435- {
436- fpath = EvalPathFS (fstring, fmap);
437-
438- if (!IsAbsolutePath (fpath))
439- {
440- if (!IsAbsolutePath (dir))
441- dir = BaseDirectory + std::string (PSS) + dir;
442-
443- fpath = dir + std::string (PSS) + fpath;
444- }
445-
446- if (MDFN_stat (fpath.c_str (), &tmpstat) == -1 )
447- fmap[' M' ] = md5_context::asciistr (MDFNGameInfo->MD5 , 0 ) + std::string (" ." );
448- else
449- break ;
450- }
451-
452- if (type == MDFNMKF_SAVBACK)
453- CreateMissingDirs (fpath);
454-
455- return (fpath);
456- }
399+ fmap[' x' ] = (cd1 ? cd1 : " mcs" );
400+ }
401+ else if (type == MDFNMKF_SAV)
402+ {
403+ // dir = MDFN_GetSettingS("filesys.path_sav");
404+ dir = FileBaseDirectory;
405+ fstring = MDFN_GetSettingS (" filesys.fname_sav" );
406+ fmap[' x' ] = std::string (cd1);
407+ }
408+ else if (type == MDFNMKF_SAVBACK)
409+ {
410+ dir = MDFN_GetSettingS (" filesys.path_savbackup" );
411+ fstring = MDFN_GetSettingS (" filesys.fname_savbackup" );
412+ fmap[' x' ] = std::string (cd1);
413+ }
414+
415+ fmap[' X' ] = fmap[' x' ];
416+
417+ if (type == MDFNMKF_SAVBACK)
418+ {
419+ if (id1 < 0 )
420+ fmap[' p' ] = " C" ;
421+ else
422+ {
423+ trio_snprintf (numtmp, sizeof (numtmp), " %u" , id1);
424+ fmap[' p' ] = std::string (numtmp);
425+ }
426+ }
427+ else if (type != MDFNMKF_SAV && !cd1)
428+ {
429+ trio_snprintf (numtmp, sizeof (numtmp), " %d" , id1);
430+ fmap[' p' ] = std::string (numtmp);
431+ }
432+
433+ if (fmap[' X' ].size () > 1 && fmap[' p' ].size ())
434+ fmap[' X' ] = fmap[' X' ].erase (fmap[' X' ].size () - 1 ) + fmap[' p' ];
435+
436+ for (int i = 0 ; i < 2 ; i++)
437+ {
438+ fpath = EvalPathFS (fstring, fmap);
439+
440+ if (!IsAbsolutePath (fpath))
441+ {
442+ if (!IsAbsolutePath (dir))
443+ dir = BaseDirectory + std::string (PSS) + dir;
444+
445+ fpath = dir + std::string (PSS) + fpath;
446+ }
447+
448+ if (MDFN_stat (fpath.c_str (), &tmpstat) == -1 )
449+ fmap[' M' ] = md5_context::asciistr (MDFNGameInfo->MD5 , 0 ) + std::string (" ." );
450+ else
451+ break ;
452+ }
453+
454+ if (type == MDFNMKF_SAVBACK)
455+ CreateMissingDirs (fpath);
456+
457+ return (fpath);
458+ }
457459
458460 case MDFNMKF_SNAP_DAT:
459461 case MDFNMKF_SNAP:
460- {
461- std::string dir = MDFN_GetSettingS (" filesys.path_snap" );
462- std::string fstring = MDFN_GetSettingS (" filesys.fname_snap" );
463- std::string fpath;
464-
465- trio_snprintf (numtmp, sizeof (numtmp), " %04u" , id1);
466-
467- fmap[' p' ] = std::string (numtmp);
468-
469- if (cd1)
470- fmap[' x' ] = std::string (cd1);
471-
472- if (type == MDFNMKF_SNAP_DAT)
473- {
474- fmap[' p' ] = std::string (" counter" );
475- fmap[' x' ] = std::string (" txt" );
476- }
477- fpath = EvalPathFS (fstring, fmap);
478- if (!IsAbsolutePath (fpath))
479- {
480- if (!IsAbsolutePath (dir))
481- dir = BaseDirectory + std::string (PSS) + dir;
482-
483- fpath = dir + std::string (PSS) + fpath;
484- }
485- return (fpath);
486- }
487- break ;
462+ {
463+ std::string dir = MDFN_GetSettingS (" filesys.path_snap" );
464+ std::string fstring = MDFN_GetSettingS (" filesys.fname_snap" );
465+ std::string fpath;
466+
467+ trio_snprintf (numtmp, sizeof (numtmp), " %04u" , id1);
468+
469+ fmap[' p' ] = std::string (numtmp);
470+
471+ if (cd1)
472+ fmap[' x' ] = std::string (cd1);
473+
474+ if (type == MDFNMKF_SNAP_DAT)
475+ {
476+ fmap[' p' ] = std::string (" counter" );
477+ fmap[' x' ] = std::string (" txt" );
478+ }
479+ fpath = EvalPathFS (fstring, fmap);
480+ if (!IsAbsolutePath (fpath))
481+ {
482+ if (!IsAbsolutePath (dir))
483+ dir = BaseDirectory + std::string (PSS) + dir;
484+
485+ fpath = dir + std::string (PSS) + fpath;
486+ }
487+ return (fpath);
488+ }
489+ break ;
488490
489491 case MDFNMKF_CHEAT_TMP:
490492 case MDFNMKF_CHEAT:
491- {
492- std::string basepath = MDFN_GetSettingS (" filesys.path_cheat" );
493+ {
494+ std::string basepath = MDFN_GetSettingS (" filesys.path_cheat" );
493495
494- if (!IsAbsolutePath (basepath))
495- basepath = BaseDirectory + PSS + basepath;
496+ if (!IsAbsolutePath (basepath))
497+ basepath = BaseDirectory + PSS + basepath;
496498
497- ret = basepath + PSS + MDFNGameInfo->shortname + " ." + ((type == MDFNMKF_CHEAT_TMP) ? " tmpcht" : " cht" );
498- }
499- break ;
499+ ret = basepath + PSS + MDFNGameInfo->shortname + " ." + ((type == MDFNMKF_CHEAT_TMP) ? " tmpcht" : " cht" );
500+ }
501+ break ;
500502
501503 case MDFNMKF_AUX:
502- if (IsAbsolutePath (cd1))
503- ret = cd1;
504- else
505- ret = FileBaseDirectory + PSS + cd1;
506- break ;
504+ if (IsAbsolutePath (cd1))
505+ ret = cd1;
506+ else
507+ ret = FileBaseDirectory + PSS + cd1;
508+ break ;
507509
508510 case MDFNMKF_IPS:
509- ret = FileBaseDirectory + PSS + FileBase + FileExt + " .ips" ;
510- break ;
511+ ret = FileBaseDirectory + PSS + FileBase + FileExt + " .ips" ;
512+ break ;
511513
512514 case MDFNMKF_FIRMWARE:
513- if (IsAbsolutePath (cd1))
514- ret = cd1;
515- else
516- {
517- std::string overpath = MDFN_GetSettingS (" filesys.path_firmware" );
518-
519- if (IsAbsolutePath (overpath))
520- ret = overpath + PSS + cd1;
521- else
522- {
523- ret = BaseDirectory + PSS + overpath + PSS + cd1;
524-
525- // For backwards-compatibility with < 0.9.0
526- if (MDFN_stat (ret.c_str (),&tmpstat) == -1 )
527- ret = BaseDirectory + PSS + cd1;
528- }
529- }
530- break ;
515+ if (IsAbsolutePath (cd1))
516+ ret = cd1;
517+ else
518+ {
519+ std::string overpath = MDFN_GetSettingS (" filesys.path_firmware" );
520+
521+ if (IsAbsolutePath (overpath))
522+ ret = overpath + PSS + cd1;
523+ else
524+ {
525+ ret = BaseDirectory + PSS + overpath + PSS + cd1;
526+
527+ // For backwards-compatibility with < 0.9.0
528+ if (MDFN_stat (ret.c_str (),&tmpstat) == -1 )
529+ ret = BaseDirectory + PSS + cd1;
530+ }
531+ }
532+ break ;
531533
532534 case MDFNMKF_PALETTE:
533- {
534- std::string overpath = MDFN_GetSettingS (" filesys.path_palette" );
535+ {
536+ std::string overpath = MDFN_GetSettingS (" filesys.path_palette" );
535537
536- if (IsAbsolutePath (overpath))
537- eff_dir = overpath;
538- else
539- eff_dir = BaseDirectory + PSS + overpath;
538+ if (IsAbsolutePath (overpath))
539+ eff_dir = overpath;
540+ else
541+ eff_dir = BaseDirectory + PSS + overpath;
540542
541- ret = eff_dir + PSS + FileBase + " .pal" ;
543+ ret = eff_dir + PSS + FileBase + " .pal" ;
542544
543- if (MDFN_stat (ret.c_str (),&tmpstat) == -1 && errno == ENOENT)
544- {
545- ret = eff_dir + PSS + FileBase + " ." + md5_context::asciistr (MDFNGameInfo->MD5 , 0 ) + " .pal" ;
545+ if (MDFN_stat (ret.c_str (),&tmpstat) == -1 && errno == ENOENT)
546+ {
547+ ret = eff_dir + PSS + FileBase + " ." + md5_context::asciistr (MDFNGameInfo->MD5 , 0 ) + " .pal" ;
546548
547- if (MDFN_stat (ret.c_str (), &tmpstat) == -1 && errno == ENOENT)
548- ret = eff_dir + PSS + (cd1 ? cd1 : MDFNGameInfo->shortname ) + " .pal" ;
549- }
550- }
551- break ;
549+ if (MDFN_stat (ret.c_str (), &tmpstat) == -1 && errno == ENOENT)
550+ ret = eff_dir + PSS + (cd1 ? cd1 : MDFNGameInfo->shortname ) + " .pal" ;
551+ }
552+ }
553+ break ;
552554
553555 case MDFNMKF_PGCONFIG:
554- {
555- std::string overpath = MDFN_GetSettingS (" filesys.path_pgconfig" );
556+ {
557+ std::string overpath = MDFN_GetSettingS (" filesys.path_pgconfig" );
556558
557- if (IsAbsolutePath (overpath))
558- eff_dir = overpath;
559- else
560- eff_dir = std::string (BaseDirectory) + std::string (PSS) + overpath;
559+ if (IsAbsolutePath (overpath))
560+ eff_dir = overpath;
561+ else
562+ eff_dir = std::string (BaseDirectory) + std::string (PSS) + overpath;
561563
562- ret = eff_dir + PSS + FileBase + " ." + MDFNGameInfo->shortname + " .cfg" ;
563- }
564- break ;
564+ ret = eff_dir + PSS + FileBase + " ." + MDFNGameInfo->shortname + " .cfg" ;
565+ }
566+ break ;
565567 }
566568
567569 return ret;
0 commit comments