//------------------------------------------------- // open_next - open the next file that matches // the filename by iterating over paths //------------------------------------------------- osd_file.error open_next() { // if we're open from a previous attempt, close up now if (m_file != null) { close(); } // loop over paths osd_file.error filerr = osd_file.error.NOT_FOUND; while (m_iterator.next(out m_fullpath, m_filename)) { // attempt to open the file directly filerr = util.core_file.open(m_fullpath, m_openflags, out m_file); if (filerr == osd_file.error.NONE) { break; } // if we're opening for read-only we have other options if ((m_openflags & (OPEN_FLAG_READ | OPEN_FLAG_WRITE)) == OPEN_FLAG_READ) { filerr = attempt_zipped(); if (filerr == osd_file.error.NONE) { break; } } } return(filerr); }
//------------------------------------------------- // load_zipped_file - load a ZIPped file //------------------------------------------------- osd_file.error load_zipped_file() { assert(m_file == null); assert(m_zipdata.empty()); assert(m_zipfile != null); // allocate some memory m_zipdata.resize((int)m_ziplength); // read the data into our buffer and return var ziperr = m_zipfile.decompress(m_zipdata, (UInt32)m_zipdata.size()); if (ziperr != util.archive_file.error.NONE) { m_zipdata.clear(); return(osd_file.error.FAILURE); } // convert to RAM file osd_file.error filerr = util.core_file.open_ram(m_zipdata, (UInt32)m_zipdata.size(), m_openflags, out m_file); if (filerr != osd_file.error.NONE) { m_zipdata.clear(); return(osd_file.error.FAILURE); } // close out the ZIP file m_zipfile.Dispose(); m_zipfile = null; return(osd_file.error.NONE); }
public void save_settings() { /* loop over all registrants and call their init function */ foreach (var type in m_typelist) { type.save(config_type.INIT, null); } /* save the defaults file */ emu_file file = new emu_file(machine().options().cfg_directory(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS); osd_file.error filerr = file.open("default.cfg"); if (filerr == osd_file.error.NONE) { save_xml(file, config_type.DEFAULT); } /* finally, save the game-specific file */ filerr = file.open(machine().basename(), ".cfg"); if (filerr == osd_file.error.NONE) { save_xml(file, config_type.GAME); } file.close(); /* loop over all registrants and call their final function */ foreach (var type in m_typelist) { type.save(config_type.FINAL, null); } }
/*------------------------------------------------- * render_load_png - load a PNG file into a * bitmap * -------------------------------------------------*/ public static bool render_load_png(out bitmap_argb32 bitmap, emu_file file, string dirname, string filename, bool load_as_alpha_to_existing = false) { bitmap = new bitmap_argb32(); // deallocate if we're not overlaying alpha if (!load_as_alpha_to_existing) { bitmap.reset(); } // open the file string fname; if (dirname != null) { fname = dirname + global_object.PATH_SEPARATOR + filename; } else { fname = filename; } osd_file.error filerr = file.open(fname); if (filerr != osd_file.error.NONE) { return(false); } throw new emu_unimplemented(); }
//------------------------------------------------- // load_samples - load all the samples in our // attached interface // Returns true when all samples were successfully read, else false //------------------------------------------------- bool load_samples() { bool ok = true; // if the user doesn't want to use samples, bail if (!machine().options().samples()) { return(false); } // iterate over ourself string basename = machine().basename(); samples_iterator iter = new samples_iterator(this); string altbasename = iter.altbasename(); // pre-size the array m_sample.resize(iter.count()); // load the samples int index = 0; for (string samplename = iter.first(); samplename != null; index++, samplename = iter.next()) { // attempt to open as FLAC first emu_file file = new emu_file(machine().options().sample_path(), OPEN_FLAG_READ); osd_file.error filerr = file.open(basename, PATH_SEPARATOR, samplename, ".flac"); if (filerr != osd_file.error.NONE && altbasename != null) { filerr = file.open(altbasename, PATH_SEPARATOR, samplename, ".flac"); } // if not, try as WAV if (filerr != osd_file.error.NONE) { filerr = file.open(basename, PATH_SEPARATOR, samplename, ".wav"); } if (filerr != osd_file.error.NONE && altbasename != null) { filerr = file.open(altbasename, PATH_SEPARATOR, samplename, ".wav"); } // if opened, read it if (filerr == osd_file.error.NONE) { read_sample(file, m_sample[index]); } else if (filerr == osd_file.error.NOT_FOUND) { logerror("{0}: Sample '{1}' NOT FOUND\n", tag(), samplename); ok = false; } file.close(); } return(ok); }
public archive_file.error initialize() { osd_file.error err = osdcore_global.m_osdfile.open(m_filename, OPEN_FLAG_READ, out m_archive_stream.osdfile, out m_archive_stream.length); if (err != osd_file.error.NONE) { return(archive_file.error.FILE_ERROR); } //global.osd_printf_verbose("un7z: opened archive file {0}\n", m_filename.c_str()); #if false CrcGenerateTable(); // FIXME: doesn't belong here - it should be called once statically SzArEx_Init(&m_db); m_inited = true; SRes const res = SzArEx_Open(&m_db, &m_look_stream.s, &m_alloc_imp, &m_alloc_temp_imp); if (res != SZ_OK) { osd_printf_error("un7z: error opening %s as 7z archive (%d)\n", m_filename.c_str(), int(res)); switch (res) { case SZ_ERROR_UNSUPPORTED: return(archive_file.error.UNSUPPORTED); case SZ_ERROR_MEM: return(archive_file.error.OUT_OF_MEMORY); case SZ_ERROR_INPUT_EOF: return(archive_file.error.FILE_TRUNCATED); default: return(archive_file.error.FILE_ERROR); } } return(archive_file::error::NONE); #endif try { m_sharpCompressArchive = SevenZipArchive.Open(m_archive_stream.osdfile.stream); } catch (Exception e) { m_sharpCompressArchive = null; return(archive_file.error.FILE_ERROR); } return(archive_file.error.NONE); }
// 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); }
public void start_luaengine() { if (options().plugins()) { path_iterator iter = new path_iterator(options().plugins_path()); string pluginpath; while (iter.next(out pluginpath)) { m_plugins.parse_json(pluginpath); } string [] include = options().plugin() == null ? new string[0] : options().plugin().Split(','); // split(options().plugin(),','); string [] exclude = options().no_plugin() == null ? new string[0] : options().no_plugin().Split(','); { // parse the file // attempt to open the output file emu_file file = new emu_file(options().ini_path(), OPEN_FLAG_READ); if (file.open("plugin.ini") == osd_file.error.NONE) { try { m_plugins.parse_ini_file(file.core_file_get(), mame_options.OPTION_PRIORITY_MAME_INI, mame_options.OPTION_PRIORITY_MAME_INI < mame_options.OPTION_PRIORITY_DRIVER_INI, false); } catch (options_exception) { osd_printf_error("**Error loading plugin.ini**\n"); } file.close(); } } foreach (var curentry in m_plugins.entries()) { if (curentry.type() != core_options.option_type.HEADER) { if (Array.Exists(include, s => s == curentry.name())) // std::find(include.begin(), include.end(), curentry.name()) != include.end()) { m_plugins.set_value(curentry.name(), "1", emu_options.OPTION_PRIORITY_CMDLINE); } if (Array.Exists(exclude, s => s == curentry.name())) // std::find(exclude.begin(), exclude.end(), curentry.name()) != exclude.end()) { m_plugins.set_value(curentry.name(), "0", emu_options.OPTION_PRIORITY_CMDLINE); } } } } if (options().console()) { m_plugins.set_value("console", "1", emu_options.OPTION_PRIORITY_CMDLINE); if (m_plugins.exists(emu_options.OPTION_CONSOLE)) { m_plugins.set_value(emu_options.OPTION_CONSOLE, "1", emu_options.OPTION_PRIORITY_CMDLINE); } else { fatalerror("Console plugin not found.\n"); } } m_lua.initialize(); { emu_file file = new emu_file(options().plugins_path(), OPEN_FLAG_READ); osd_file.error filerr = file.open("boot.lua"); if (filerr == osd_file.error.NONE) { string exppath; osdcore_global.m_osdcore.osd_subst_env(out exppath, file.fullpath()); m_lua.load_script(file.fullpath()); file.close(); } } }
//------------------------------------------------- // audit_samples - validate the samples for the // currently-enumerated driver //------------------------------------------------- public summary audit_samples() { // start fresh m_record_list.clear(); int required = 0; int found = 0; // iterate over sample entries foreach (samples_device device in new samples_device_iterator(m_enumerator.config().root_device())) { // by default we just search using the driver name string searchpath = m_enumerator.driver().name; // add the alternate path if present samples_iterator samplesiter = new samples_iterator(device); if (samplesiter.altbasename() != null) { searchpath += ";" + samplesiter.altbasename(); } // iterate over samples in this entry for (string samplename = samplesiter.first(); samplename != null; samplename = samplesiter.next()) { required++; // create a new record audit_record record = m_record_list.emplace_back(new audit_record(samplename, audit_record.media_type.MEDIA_SAMPLE)).Value; //audit_record &record = *m_record_list.emplace(m_record_list.end(), samplename, media_type::SAMPLE); // look for the files emu_file file = new emu_file(m_enumerator.options().sample_path(), osdcore_global.OPEN_FLAG_READ | osdcore_global.OPEN_FLAG_NO_PRELOAD); path_iterator path = new path_iterator(searchpath); string curpath; while (path.next(out curpath, samplename)) { // attempt to access the file (.flac) or (.wav) osd_file.error filerr = file.open(curpath, ".flac"); if (filerr != osd_file.error.NONE) { filerr = file.open(curpath, ".wav"); } if (filerr == osd_file.error.NONE) { record.set_status(audit_record.audit_status.STATUS_GOOD, audit_record.audit_substatus.SUBSTATUS_GOOD); found++; } else { record.set_status(audit_record.audit_status.STATUS_NOT_FOUND, audit_record.audit_substatus.SUBSTATUS_NOT_FOUND); } } file.close(); } } if (found == 0 && required > 0) { m_record_list.clear(); return(summary.NOTFOUND); } // return a summary string unused = ""; return(summarize(m_enumerator.driver().name, ref unused)); }
/************************************* * * Settings save/load frontend * *************************************/ public int load_settings() { string controller = machine().options().ctrlr(); int loaded = 0; /* loop over all registrants and call their init function */ foreach (var type in m_typelist) { type.load(config_type.INIT, null); } /* now load the controller file */ if (!string.IsNullOrEmpty(controller)) { /* open the config file */ emu_file file = new emu_file(machine().options().ctrlr_path(), OPEN_FLAG_READ); osd_printf_verbose("Attempting to parse: {0}.cfg\n", controller); osd_file.error filerr = file.open(controller, ".cfg"); if (filerr != osd_file.error.NONE) { throw new emu_fatalerror("Could not load controller file {0}.cfg", controller); } /* load the XML */ if (load_xml(file, config_type.CONTROLLER) == 0) { throw new emu_fatalerror("Could not load controller file {0}.cfg", controller); } file.close(); } { /* next load the defaults file */ emu_file file = new emu_file(machine().options().cfg_directory(), OPEN_FLAG_READ); osd_file.error filerr = file.open("default.cfg"); osd_printf_verbose("Attempting to parse: default.cfg\n"); if (filerr == osd_file.error.NONE) { load_xml(file, config_type.DEFAULT); } /* finally, load the game-specific file */ filerr = file.open(machine().basename(), ".cfg"); osd_printf_verbose("Attempting to parse: {0}.cfg\n", machine().basename()); if (filerr == osd_file.error.NONE) { loaded = load_xml(file, config_type.GAME); } file.close(); } /* loop over all registrants and call their final function */ foreach (var type in m_typelist) { type.load(config_type.FINAL, null); } /* if we didn't find a saved config, return 0 so the main core knows that it */ /* is the first time the game is run and it should display the disclaimer. */ return(loaded); }