Пример #1
0
        //-------------------------------------------------
        //  save drivers infos to file
        //-------------------------------------------------
        //void init_sorted_list()


        //-------------------------------------------------
        //  load drivers infos from file
        //-------------------------------------------------
        bool load_available_machines()
        {
            // try to load available drivers from file
            emu_file file = new emu_file(ui().options().ui_path(), OPEN_FLAG_READ);

            if (file.open(emulator_info.get_configname() + "_avail.ini"))
            {
                return(false);
            }

            string rbuf;  //char rbuf[MAX_CHAR_INFO];
            string readbuf;

            file.gets(out rbuf, MAX_CHAR_INFO);
            file.gets(out rbuf, MAX_CHAR_INFO);
            readbuf = chartrimcarriage(rbuf);
            string a_rev = string_format("{0}{1}", UI_VERSION_TAG, bare_build_version);

            // version not matching ? exit
            if (a_rev != readbuf)
            {
                file.close();
                return(false);
            }

            // load available list
            std.unordered_set <string> available = new std.unordered_set <string>();
            while (file.gets(out rbuf, MAX_CHAR_INFO) != null)
            {
                readbuf = rbuf.Trim();                      //readbuf = strtrimspace(rbuf);

                if (readbuf.empty() || ('#' == readbuf[0])) // ignore empty lines and line comments
                {
                }
                else if ('[' == readbuf[0]) // throw out the rest of the file if we find a section heading
                {
                    break;
                }
                else
                {
                    available.emplace(readbuf);
                }
            }
            file.close();

            // turn it into the sorted system list we all love
            foreach (ui_system_info info in m_persistent_data.sorted_list())
            {
                var  it    = available.find(info.driver.name);
                bool found = it;
                info.available = found;
                if (found)
                {
                    available.erase(info.driver.name);
                }
            }

            return(true);
        }
Пример #2
0
        // load games from category
        public void load_ini_category(UInt32 file, UInt32 category, std.unordered_set <game_driver> result)
        {
            string   filename = m_ini_index[(int)file].Key;
            emu_file fp       = new emu_file(m_options.categoryini_path(), OPEN_FLAG_READ);

            if (fp.open(filename) != osd_file.error.NONE)
            {
                osd_printf_error("Failed to open category file {0} for reading\n", filename.c_str());
                return;
            }

            Int64 offset = m_ini_index[(int)file].Value[(int)category].Value;

            if (fp.seek(offset, emu_file.SEEK_SET) != 0 || (fp.tell() != (UInt64)offset))
            {
                fp.close();
                osd_printf_error("Failed to seek to category offset in file {0}\n", filename.c_str());
                return;
            }

            string rbuf;  // char rbuf[MAX_CHAR_INFO];

            while (fp.gets(out rbuf, utils_global.MAX_CHAR_INFO) != null && !string.IsNullOrEmpty(rbuf) && ('[' != rbuf[0]))
            {
                //var tail = std::find_if(std::begin(rbuf), std::prev(std::end(rbuf)));//, [] (char ch) { return !ch || ('\r' == ch) || ('\n' == ch); });
                //*tail = '\0';
                var tail = rbuf.IndexOfAny("\r\n".ToCharArray());
                rbuf = rbuf.Substring(tail);
                int dfind = driver_list.find(rbuf);
                if (0 <= dfind)
                {
                    result.emplace(driver_list.driver(dfind));
                }
            }

            fp.close();
        }