summaryrefslogtreecommitdiffstatshomepage
path: root/src/frontend/mame/ui/inifile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/frontend/mame/ui/inifile.cpp')
-rw-r--r--src/frontend/mame/ui/inifile.cpp156
1 files changed, 61 insertions, 95 deletions
diff --git a/src/frontend/mame/ui/inifile.cpp b/src/frontend/mame/ui/inifile.cpp
index d9673f13a67..852884fea6a 100644
--- a/src/frontend/mame/ui/inifile.cpp
+++ b/src/frontend/mame/ui/inifile.cpp
@@ -9,134 +9,100 @@
***************************************************************************/
#include "emu.h"
-#include "ui/moptions.h"
#include "ui/inifile.h"
-#include "softlist_dev.h"
+
+#include "ui/moptions.h"
+
#include "drivenum.h"
+#include "softlist_dev.h"
-//-------------------------------------------------
-// GLOBAL VARIABLES
-//-------------------------------------------------
-uint16_t inifile_manager::c_cat = 0;
-uint16_t inifile_manager::c_file = 0;
//-------------------------------------------------
// ctor
//-------------------------------------------------
inifile_manager::inifile_manager(running_machine &machine, ui_options &moptions)
- : m_machine(machine)
- , m_options(moptions)
+ : m_options(moptions)
+ , m_ini_index()
{
- ini_index.clear();
- directory_scan();
+ // scan directories and create index
+ file_enumerator path(m_options.categoryini_path());
+ for (osd::directory::entry const *dir = path.next(); dir; dir = path.next())
+ {
+ std::string name(dir->name);
+ if (core_filename_ends_with(name, ".ini"))
+ {
+ emu_file file(m_options.categoryini_path(), OPEN_FLAG_READ);
+ if (file.open(name) == osd_file::error::NONE)
+ {
+ init_category(std::move(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()); });
}
//-------------------------------------------------
-// scan directories and create index
+// load and indexing ini files
//-------------------------------------------------
-void inifile_manager::directory_scan()
+void inifile_manager::load_ini_category(size_t file, size_t category, std::unordered_set<game_driver const *> &result) const
{
- file_enumerator path(m_options.extraini_path());
- const osd::directory::entry *dir;
+ std::string const &filename(m_ini_index[file].first);
+ emu_file fp(m_options.categoryini_path(), OPEN_FLAG_READ);
+ if (fp.open(filename) != osd_file::error::NONE)
+ {
+ osd_printf_error("Failed to open category file %s for reading\n", filename.c_str());
+ return;
+ }
- while ((dir = path.next()) != nullptr)
- if (core_filename_ends_with(dir->name, ".ini") && parseopen(dir->name))
- {
- init_category(std::string(dir->name));
- parseclose();
- }
+ int64_t const offset(m_ini_index[file].second[category].second);
+ if (fp.seek(offset, SEEK_SET) || (fp.tell() != offset))
+ {
+ fp.close();
+ osd_printf_error("Failed to seek to category offset in file %s\n", filename.c_str());
+ return;
+ }
- // sort
- std::stable_sort(ini_index.begin(), ini_index.end());
+ char rbuf[MAX_CHAR_INFO];
+ while (fp.gets(rbuf, MAX_CHAR_INFO) && rbuf[0] && ('[' != rbuf[0]))
+ {
+ auto const tail(std::find_if(std::begin(rbuf), std::prev(std::end(rbuf)), [] (char ch) { return !ch || ('\r' == ch) || ('\n' == ch); }));
+ *tail = '\0';
+ int const dfind(driver_list::find(rbuf));
+ if (0 <= dfind)
+ result.emplace(&driver_list::driver(dfind));
+ }
+
+ fp.close();
}
//-------------------------------------------------
// initialize category
//-------------------------------------------------
-void inifile_manager::init_category(std::string filename)
+void inifile_manager::init_category(std::string &&filename, emu_file &file)
{
categoryindex index;
char rbuf[MAX_CHAR_INFO];
- std::string readbuf;
- while (fgets(rbuf, MAX_CHAR_INFO, fp) != nullptr)
- if (rbuf[0] == '[')
- {
- readbuf = rbuf;
- auto name = readbuf.substr(1, readbuf.find("]") - 1);
- if (name == "FOLDER_SETTINGS") continue;
- index.emplace_back(name, ftell(fp));
- }
-
- // sort
- std::stable_sort(index.begin(), index.end());
-
- if (!index.empty())
- ini_index.emplace_back(strmakelower(filename), index);
-}
-
-//-------------------------------------------------
-// load and indexing ini files
-//-------------------------------------------------
-
-void inifile_manager::load_ini_category(std::vector<int> &temp_filter)
-{
- if (ini_index.empty())
- return;
-
- auto search_clones = false;
- std::string filename(ini_index[c_file].first);
- auto offset = ini_index[c_file].second[c_cat].second;
-
- if (filename == "category.ini" || filename == "alltime.ini")
- search_clones = true;
-
- if (parseopen(filename.c_str()))
+ std::string name;
+ while (file.gets(rbuf, ARRAY_LENGTH(rbuf)))
{
- fseek(fp, offset, SEEK_SET);
- char rbuf[MAX_CHAR_INFO];
- std::string readbuf;
- while (fgets(rbuf, MAX_CHAR_INFO, fp) != nullptr)
+ if ('[' == rbuf[0])
{
- readbuf = chartrimcarriage(rbuf);
-
- if (readbuf.empty() || readbuf[0] == '[')
- break;
-
- auto dfind = driver_list::find(readbuf.c_str());
- if (dfind != -1)
- {
- temp_filter.push_back(dfind);
- if (search_clones && driver_list::non_bios_clone(dfind) == -1)
- for (int x = 0; x < driver_list::total(); x++)
- if (readbuf == driver_list::driver(x).parent && readbuf != driver_list::driver(x).name)
- temp_filter.push_back(x);
- }
+ auto const head(std::next(std::begin(rbuf)));
+ auto const tail(std::find_if(head, std::end(rbuf), [] (char ch) { return !ch || (']' == ch); }));
+ name.assign(head, tail);
+ if ("FOLDER_SETTINGS" != name)
+ index.emplace_back(std::move(name), file.tell());
}
- parseclose();
}
+ std::stable_sort(index.begin(), index.end(), [] (auto const &x, auto const &y) { return 0 > core_stricmp(x.first.c_str(), y.first.c_str()); });
+ if (!index.empty())
+ m_ini_index.emplace_back(std::move(filename), std::move(index));
}
-//---------------------------------------------------------
-// parseopen - Open up file for reading
-//---------------------------------------------------------
-
-bool inifile_manager::parseopen(const char *filename)
-{
- emu_file file(m_options.extraini_path(), OPEN_FLAG_READ);
- if (file.open(filename) != osd_file::error::NONE)
- return false;
-
- m_fullpath = file.fullpath();
- file.close();
- fp = fopen(m_fullpath.c_str(), "r");
-
- fgetc(fp);
- fseek(fp, 0, SEEK_SET);
- return true;
-}
/**************************************************************************
FAVORITE MANAGER