//------------------------------------------------- // populate_hashpath_from_args_and_inis //------------------------------------------------- public static void populate_hashpath_from_args_and_inis(emu_options options, std.vector <string> args) { // The existence of this function comes from the fact that for softlist options to be properly // evaluated, we need to have the hashpath variable set. The problem is that the hashpath may // be set anywhere on the command line, but also in any of the myriad INI files that we parse, some // of which may be system specific (e.g. - nes.ini) or otherwise influenced by the system (e.g. - vector.ini) // // I think that it is terrible that we have to do a completely independent pass on the command line and every // argument simply because any one of these things might be setting - hashpath.Unless we invest the effort in // building some sort of "late binding" apparatus for options(e.g. - delay evaluation of softlist options until // we've scoured all INIs for hashpath) that can completely straddle the command line and the INI worlds, doing // this is the best that we can do IMO. // parse the command line emu_options temp_options = new emu_options(emu_options.option_support.GENERAL_AND_SYSTEM); // pick up whatever changes the osd did to the default inipath temp_options.set_default_value(emu_options.OPTION_INIPATH, options.ini_path()); try { temp_options.parse_command_line(args, emu_options.OPTION_PRIORITY_CMDLINE, true); } catch (options_exception) { // Something is very long; we have bigger problems than -hashpath possibly // being in never-never land. Punt and let the main code fail return; } // if we have an auxillary verb, hashpath is irrelevant if (!temp_options.command().empty()) { return; } // read INI files if (temp_options.read_config()) { string error_stream; //std::ostringstream error_stream; parse_standard_inis(temp_options, out error_stream); } // and fish out hashpath var entry = temp_options.get_entry(emu_options.OPTION_HASHPATH); if (entry != null) { try { options.set_value(emu_options.OPTION_HASHPATH, entry.value(), entry.priority()); } catch (options_exception) { } } }
// INI parsing helper //------------------------------------------------- // parse_one_ini - parse a single INI file //------------------------------------------------- static void parse_one_ini(emu_options options, string basename, int priority, ref string error_stream) { // don't parse if it has been disabled if (!options.read_config()) { return; } // open the file; if we fail, that's ok emu_file file = new emu_file(options.ini_path(), OPEN_FLAG_READ); osd_printf_verbose("Attempting load of {0}.ini\n", basename); osd_file.error filerr = file.open(basename, ".ini"); if (filerr != osd_file.error.NONE) { return; } // parse the file osd_printf_verbose("Parsing {0}.ini\n", basename); try { options.parse_ini_file(file.core_file_get(), priority, priority < OPTION_PRIORITY_DRIVER_INI, false); } catch (options_exception ex) { if (error_stream != null) { error_stream += string.Format("While parsing {0}:\n{1}\n", file.fullpath(), ex.message()); } return; } finally { file.close(); } }
/*------------------------------------------------- * write_config - emit current option statuses as * INI files * -------------------------------------------------*/ int write_config(emu_options options, string filename, game_driver gamedrv) { string buffer; int retval = 1; if (gamedrv != null) { buffer = string.Format("{0}.ini", gamedrv.name); filename = buffer; } emu_file file = new emu_file(options.ini_path(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE); osd_file.error filerr = file.open(filename); if (filerr == osd_file.error.NONE) { string inistring = options.output_ini(); file.puts(inistring); retval = 0; } file.close(); return(retval); }
/*------------------------------------------------- * write_config - emit current option statuses as * INI files * -------------------------------------------------*/ int write_config(emu_options options, string filename, game_driver gamedrv) { string buffer; int retval = 1; if (gamedrv != null) { sprintf(out buffer, "{0}.ini", gamedrv.name); filename = buffer; } emu_file file = new emu_file(options.ini_path(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE); std.error_condition filerr = file.open(filename); if (!filerr) { string inistring = options.output_ini(); file.puts(inistring); retval = 0; } file.close(); return(retval); }