Exemple #1
0
        std.vector <KeyValuePair <string, categoryindex> > m_ini_index;  //std::vector<std::pair<std::string, categoryindex> > m_ini_index;


        // construction/destruction
        //-------------------------------------------------
        //  ctor
        //-------------------------------------------------
        public inifile_manager(ui_options moptions)
        {
            m_options   = moptions;
            m_ini_index = new std.vector <KeyValuePair <string, categoryindex> >();


            // scan directories and create index
            file_enumerator path = new file_enumerator(m_options.categoryini_path());

            for (osd.directory.entry dir = path.next(); dir != null; dir = path.next())
            {
                string name = dir.name;
                if (core_filename_ends_with(name, ".ini"))
                {
                    emu_file file = new emu_file(m_options.categoryini_path(), OPEN_FLAG_READ);
                    if (file.open(name) == osd_file.error.NONE)
                    {
                        init_category(name, file);
                        file.close();
                    }
                }
            }

            //std::stable_sort(m_ini_index.begin(), m_ini_index.end());//, [] (auto const &x, auto const &y) { return 0 > core_stricmp(x.first.c_str(), y.first.c_str()); });
            m_ini_index.Sort((x, y) => { return(core_stricmp(x.Key.c_str(), y.Key.c_str())); });
        }
Exemple #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();
        }