diff --git a/plugins/data/data_gameinit.lua b/plugins/data/data_gameinit.lua index 040cfb7745b..13e2489a19d 100644 --- a/plugins/data/data_gameinit.lua +++ b/plugins/data/data_gameinit.lua @@ -20,4 +20,8 @@ function dat.get() return info end +function dat.ver() + return ver +end + return dat diff --git a/plugins/data/data_history.lua b/plugins/data/data_history.lua index 29da2f62fd5..329bccd0b1e 100644 --- a/plugins/data/data_history.lua +++ b/plugins/data/data_history.lua @@ -19,4 +19,8 @@ function dat.get() return info end +function dat.ver() + return ver +end + return dat diff --git a/plugins/data/data_mameinfo.lua b/plugins/data/data_mameinfo.lua index c22175b91e4..6daddc57b45 100644 --- a/plugins/data/data_mameinfo.lua +++ b/plugins/data/data_mameinfo.lua @@ -19,4 +19,8 @@ function dat.get() return info end +function dat.ver() + return ver +end + return dat diff --git a/plugins/data/data_messinfo.lua b/plugins/data/data_messinfo.lua index f616882cb78..5aed9eea8d1 100644 --- a/plugins/data/data_messinfo.lua +++ b/plugins/data/data_messinfo.lua @@ -20,4 +20,8 @@ function dat.get() return info end +function dat.ver() + return ver +end + return dat diff --git a/plugins/data/data_story.lua b/plugins/data/data_story.lua index 398fba2da4f..1a933f0d74b 100644 --- a/plugins/data/data_story.lua +++ b/plugins/data/data_story.lua @@ -25,4 +25,8 @@ function dat.get() return info end +function dat.ver() + return ver +end + return dat diff --git a/plugins/data/data_sysinfo.lua b/plugins/data/data_sysinfo.lua index 2a545cad1d5..9271f7b0a42 100644 --- a/plugins/data/data_sysinfo.lua +++ b/plugins/data/data_sysinfo.lua @@ -19,4 +19,8 @@ function dat.get() return info end +function dat.ver() + return ver +end + return dat diff --git a/plugins/data/init.lua b/plugins/data/init.lua index 9b947cc69f9..83cf194af11 100644 --- a/plugins/data/init.lua +++ b/plugins/data/init.lua @@ -20,7 +20,10 @@ end function data.startplugin() local data_scr = {} local valid_lst = {} + local cur_set + local cur_list emu.register_start(function() + data_scr = {} for file in lfs.dir(data.path) do local name = string.match(file, "^(data_.*).lua$") if name then @@ -32,7 +35,17 @@ function data.startplugin() end end) emu.register_callback(function(set) - local ret = "" + local ret + if set == cur_set then + return cur_list + elseif set == "" then + set = cur_set + else + cur_set = set + end + if not set then + return nil + end valid_lst = {} for num, scr in ipairs(data_scr) do local setname, softname = set:match("^([^,]+),?(.*)$") @@ -41,7 +54,7 @@ function data.startplugin() end local name = scr.check(setname, softname) if name then - if ret == "" then + if not ret then ret = name else ret = ret .. "," .. name @@ -49,12 +62,24 @@ function data.startplugin() valid_lst[#valid_lst + 1] = scr end end + cur_list = ret return ret end, "data_list") emu.register_callback(function(num) return valid_lst[num + 1].get() end, "data") + + emu.register_callback(function(num) + local ver + if valid_lst[num + 1].ver then + ver = valid_lst[num + 1].ver() + end + if ver then + return ver + end + return "" + end, "data_version") end return exports diff --git a/plugins/data/load_dat.lua b/plugins/data/load_dat.lua index a113da7fd63..72956a8becb 100644 --- a/plugins/data/load_dat.lua +++ b/plugins/data/load_dat.lua @@ -19,7 +19,7 @@ function datfile.open(file, vertag) local inblock = false local buffer = fh:read("a") if vertag then - local match = buffer:match("^" .. vertag .. "%s([^%s]+)") + local match = buffer:match(vertag .. "%s*([^%s]+)") if match then ver = match end diff --git a/scripts/src/mame/frontend.lua b/scripts/src/mame/frontend.lua index d1660dc0f22..41d0598cb15 100644 --- a/scripts/src/mame/frontend.lua +++ b/scripts/src/mame/frontend.lua @@ -130,8 +130,6 @@ files { MAME_DIR .. "src/frontend/mame/ui/custmenu.h", MAME_DIR .. "src/frontend/mame/ui/custui.cpp", MAME_DIR .. "src/frontend/mame/ui/custui.h", - MAME_DIR .. "src/frontend/mame/ui/datfile.cpp", - MAME_DIR .. "src/frontend/mame/ui/datfile.h", MAME_DIR .. "src/frontend/mame/ui/datmenu.cpp", MAME_DIR .. "src/frontend/mame/ui/datmenu.h", MAME_DIR .. "src/frontend/mame/ui/defimg.ipp", diff --git a/src/frontend/mame/mame.cpp b/src/frontend/mame/mame.cpp index c6f4824ced4..0a4fc03b3bd 100644 --- a/src/frontend/mame/mame.cpp +++ b/src/frontend/mame/mame.cpp @@ -16,14 +16,12 @@ #include "osdepend.h" #include "validity.h" #include "clifront.h" -#include "drivenum.h" #include "luaengine.h" #include #include "ui/ui.h" #include "ui/selgame.h" #include "ui/simpleselgame.h" #include "cheat.h" -#include "ui/datfile.h" #include "ui/inifile.h" #include "xmlfile.h" @@ -297,9 +295,6 @@ void mame_machine_manager::create_custom(running_machine& machine) // allocate autoboot timer m_autoboot_timer = machine.scheduler().timer_alloc(timer_expired_delegate(FUNC(mame_machine_manager::autoboot_callback), this)); - // start datfile manager - m_datfile = std::make_unique(machine, m_ui->options()); - // start favorite manager m_favorite = std::make_unique(machine, m_ui->options()); diff --git a/src/frontend/mame/mame.h b/src/frontend/mame/mame.h index 859c788e2e9..b6061810245 100644 --- a/src/frontend/mame/mame.h +++ b/src/frontend/mame/mame.h @@ -25,7 +25,6 @@ class favorite_manager; class mame_ui_manager; namespace ui { -class datfile_manager; } // namespace ui // ======================> machine_manager @@ -61,7 +60,6 @@ public: void schedule_new_driver(const game_driver &driver); mame_ui_manager& ui() const { assert(m_ui != nullptr); return *m_ui; } cheat_manager &cheat() const { assert(m_cheat != nullptr); return *m_cheat; } - ui::datfile_manager &datfile() const { assert(m_datfile != nullptr); return *m_datfile; } inifile_manager &inifile() const { assert(m_inifile != nullptr); return *m_inifile; } favorite_manager &favorite() const { assert(m_favorite != nullptr); return *m_favorite; } private: @@ -75,7 +73,6 @@ private: emu_timer *m_autoboot_timer; // autoboot timer std::unique_ptr m_ui; // internal data from ui.cpp std::unique_ptr m_cheat; // internal data from cheat.cpp - std::unique_ptr m_datfile; // internal data from datfile.c std::unique_ptr m_inifile; // internal data from inifile.c for INIs std::unique_ptr m_favorite; // internal data from inifile.c for favorites diff --git a/src/frontend/mame/ui/datfile.cpp b/src/frontend/mame/ui/datfile.cpp deleted file mode 100644 index 17552f34d68..00000000000 --- a/src/frontend/mame/ui/datfile.cpp +++ /dev/null @@ -1,581 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Maurizio Petrarota -/*************************************************************************** - - ui/datfile.cpp - - UI DATs manager. - -***************************************************************************/ - -#include "emu.h" -#include "ui/datfile.h" - -#include "drivenum.h" -#include "ui/moptions.h" -#include "ui/utils.h" - -#include - - -namespace ui { -namespace { -//------------------------------------------------- -// TAGS -//------------------------------------------------- -std::string const DATAFILE_TAG("$"); -std::string const TAG_BIO("$bio"); -std::string const TAG_INFO("$info"); -std::string const TAG_MAME("$mame"); -std::string const TAG_COMMAND("$cmd"); -std::string const TAG_END("$end"); -std::string const TAG_DRIVER("$drv"); -std::string const TAG_STORY("$story"); -std::string const TAG_HISTORY_R("## REVISION:"); -std::string const TAG_MAMEINFO_R("# MAMEINFO.DAT"); -std::string const TAG_MESSINFO_R("# MESSINFO.DAT"); -std::string const TAG_SYSINFO_R("# This file was generated on"); -std::string const TAG_STORY_R("# version"); -std::string const TAG_COMMAND_SEPARATOR("-----------------------------------------------"); -std::string const TAG_GAMEINIT_R("# GAMEINIT.DAT"); - -} // anonymous namespace - -//------------------------------------------------- -// Statics -//------------------------------------------------- -datfile_manager::dataindex datfile_manager::m_histidx; -datfile_manager::dataindex datfile_manager::m_mameidx; -datfile_manager::dataindex datfile_manager::m_messidx; -datfile_manager::dataindex datfile_manager::m_cmdidx; -datfile_manager::dataindex datfile_manager::m_sysidx; -datfile_manager::dataindex datfile_manager::m_storyidx; -datfile_manager::dataindex datfile_manager::m_ginitidx; -datfile_manager::drvindex datfile_manager::m_drvidx; -datfile_manager::drvindex datfile_manager::m_messdrvidx; -datfile_manager::drvindex datfile_manager::m_menuidx; -datfile_manager::swindex datfile_manager::m_swindex; -std::string datfile_manager::m_history_rev; -std::string datfile_manager::m_mame_rev; -std::string datfile_manager::m_mess_rev; -std::string datfile_manager::m_sysinfo_rev; -std::string datfile_manager::m_story_rev; -std::string datfile_manager::m_ginit_rev; -bool datfile_manager::first_run = true; - -#define opendatsfile(f) do { fileptr datfile = parseopen(#f".dat"); if (datfile) init_##f(std::move(datfile)); } while (false) - -//------------------------------------------------- -// ctor -//------------------------------------------------- -datfile_manager::datfile_manager(running_machine &machine, ui_options &moptions) - : m_machine(machine) - , m_options(moptions) -{ - if (m_options.enabled_dats() && first_run) - { - first_run = false; - opendatsfile(mameinfo); - opendatsfile(command); - opendatsfile(story); - opendatsfile(messinfo); - opendatsfile(sysinfo); - opendatsfile(history); - opendatsfile(gameinit); - } -} - -//------------------------------------------------- -// initialize sysinfo.dat index -//------------------------------------------------- -void datfile_manager::init_sysinfo(fileptr &&fp) -{ - int swcount = 0; - auto count = index_datafile(std::move(fp), m_sysidx, swcount, m_sysinfo_rev, TAG_SYSINFO_R, '.'); - osd_printf_verbose("Sysinfo.dat games found = %i\n", count); - osd_printf_verbose("Rev = %s\n", m_sysinfo_rev.c_str()); -} - -//------------------------------------------------- -// initialize story.dat index -//------------------------------------------------- -void datfile_manager::init_story(fileptr &&fp) -{ - int swcount = 0; - auto count = index_datafile(std::move(fp), m_storyidx, swcount, m_story_rev, TAG_STORY_R, 's'); - osd_printf_verbose("Story.dat games found = %i\n", count); -} - -//------------------------------------------------- -// initialize history.dat index -//------------------------------------------------- -void datfile_manager::init_history(fileptr &&fp) -{ - int swcount = 0; - auto count = index_datafile(std::move(fp), m_histidx, swcount, m_history_rev, TAG_HISTORY_R, ' '); - osd_printf_verbose("History.dat systems found = %i\n", count); - osd_printf_verbose("History.dat software packages found = %i\n", swcount); - osd_printf_verbose("Rev = %s\n", m_history_rev.c_str()); -} - -//------------------------------------------------- -// initialize gameinit.dat index -//------------------------------------------------- -void datfile_manager::init_gameinit(fileptr &&fp) -{ - int swcount = 0; - drvindex tmp; - auto count = index_mame_mess_info(std::move(fp), m_ginitidx, tmp, swcount); - osd_printf_verbose("Gameinit.dat games found = %i\n", count); - osd_printf_verbose("Rev = %s\n", m_ginit_rev.c_str()); -} - -//------------------------------------------------- -// initialize mameinfo.dat index -//------------------------------------------------- -void datfile_manager::init_mameinfo(fileptr &&fp) -{ - int drvcount = 0; - auto count = index_mame_mess_info(std::move(fp), m_mameidx, m_drvidx, drvcount); - osd_printf_verbose("Mameinfo.dat games found = %i\n", count); - osd_printf_verbose("Mameinfo.dat drivers found = %d\n", drvcount); - osd_printf_verbose("Rev = %s\n", m_mame_rev.c_str()); -} - -//------------------------------------------------- -// initialize messinfo.dat index -//------------------------------------------------- -void datfile_manager::init_messinfo(fileptr &&fp) -{ - int drvcount = 0; - auto count = index_mame_mess_info(std::move(fp), m_messidx, m_messdrvidx, drvcount); - osd_printf_verbose("Messinfo.dat games found = %i\n", count); - osd_printf_verbose("Messinfo.dat drivers found = %d\n", drvcount); - osd_printf_verbose("Rev = %s\n", m_mess_rev.c_str()); -} - -//------------------------------------------------- -// initialize command.dat index -//------------------------------------------------- -void datfile_manager::init_command(fileptr &&fp) -{ - int swcount = 0; - std::string tmp; - auto count = index_datafile(std::move(fp), m_cmdidx, swcount, tmp, std::string(), 'c'); - osd_printf_verbose("Command.dat games found = %i\n", count); -} - -bool datfile_manager::has_software(std::string const &softlist, std::string const &softname, std::string const &parentname) const -{ - return bool(find_software(softlist, softname, parentname)); -} - -long const *datfile_manager::find_software(std::string const &softlist, std::string const &softname, std::string const &parentname) const -{ - // Find software in software list index - auto const software(m_swindex.find(softlist)); - if (software == m_swindex.end()) - return nullptr; - - auto itemsiter = software->second.find(softname); - if ((itemsiter == software->second.end()) && !parentname.empty()) - itemsiter = software->second.find(parentname); - - return (itemsiter != software->second.end()) ? &itemsiter->second : nullptr; -} - -//------------------------------------------------- -// load software info -//------------------------------------------------- -void datfile_manager::load_software_info(std::string const &softlist, std::string &buffer, std::string const &softname, std::string const &parentname) -{ - if (m_swindex.empty()) - return; - - // Load history text - fileptr const datfile = parseopen("history.dat"); - if (datfile) - { - // Find software in software list index - long const *const s_offset = find_software(softlist, softname, parentname); - if (!s_offset) - return; - - char rbuf[64 * 1024]; - std::fseek(datfile.get(), *s_offset, SEEK_SET); - std::string readbuf; - while (std::fgets(rbuf, 64 * 1024, datfile.get()) != nullptr) - { - readbuf = chartrimcarriage(rbuf); - - // end entry when a end tag is encountered - if (readbuf == TAG_END) - break; - - // add this string to the buffer - buffer.append(readbuf).append("\n"); - } - } -} - -//------------------------------------------------- -// load_data_info -//------------------------------------------------- -void datfile_manager::load_data_info(const game_driver *drv, std::string &buffer, int type) -{ - dataindex const *index_idx = nullptr; - drvindex const *driver_idx = nullptr; - std::string const *tag; - std::string filename; - - switch (type) - { - case UI_HISTORY_LOAD: - filename = "history.dat"; - tag = &TAG_BIO; - index_idx = &m_histidx; - break; - case UI_MAMEINFO_LOAD: - filename = "mameinfo.dat"; - tag = &TAG_MAME; - index_idx = &m_mameidx; - driver_idx = &m_drvidx; - break; - case UI_SYSINFO_LOAD: - filename = "sysinfo.dat"; - tag = &TAG_BIO; - index_idx = &m_sysidx; - break; - case UI_MESSINFO_LOAD: - filename = "messinfo.dat"; - tag = &TAG_MAME; - index_idx = &m_messidx; - driver_idx = &m_messdrvidx; - break; - case UI_STORY_LOAD: - filename = "story.dat"; - tag = &TAG_STORY; - index_idx = &m_storyidx; - break; - case UI_GINIT_LOAD: - filename = "gameinit.dat"; - tag = &TAG_MAME; - index_idx = &m_ginitidx; - break; - default: - assert(false); - return; - } - - fileptr const datfile = parseopen(filename.c_str()); - if (datfile) - { - load_data_text(datfile.get(), drv, buffer, *index_idx, *tag); - - // load driver info - if (driver_idx && !driver_idx->empty()) - load_driver_text(datfile.get(), drv, buffer, *driver_idx, TAG_DRIVER); - - // cleanup mameinfo and sysinfo double line spacing - if (((*tag == TAG_MAME) && (type != UI_GINIT_LOAD)) || (type == UI_SYSINFO_LOAD)) - strreplace(buffer, "\n\n", "\n"); - } -} - -//------------------------------------------------- -// load a game text into the buffer -//------------------------------------------------- -void datfile_manager::load_data_text(FILE *fp, game_driver const *drv, std::string &buffer, dataindex const &idx, std::string const &tag) -{ - auto itemsiter = idx.find(drv); - if (itemsiter == idx.end()) - { - auto cloneof = driver_list::non_bios_clone(*drv); - if (cloneof == -1) - return; - else - { - auto c_drv = &driver_list::driver(cloneof); - itemsiter = idx.find(c_drv); - if (itemsiter == idx.end()) - return; - } - } - - auto s_offset = itemsiter->second; - std::fseek(fp, s_offset, SEEK_SET); - char rbuf[64 * 1024]; - std::string readbuf; - while (std::fgets(rbuf, 64 * 1024, fp) != nullptr) - { - readbuf = chartrimcarriage(rbuf); - - // end entry when a end tag is encountered - if (readbuf == TAG_END) - break; - - // continue if a specific tag is encountered - if (readbuf == tag) - continue; - - // add this string to the buffer - buffer.append(readbuf).append("\n"); - } -} - -//------------------------------------------------- -// load a driver name and offset into an -// indexed array -//------------------------------------------------- -void datfile_manager::load_driver_text(FILE *fp, game_driver const *drv, std::string &buffer, drvindex const &idx, std::string const &tag) -{ - std::string s(core_filename_extract_base(drv->source_file)); - auto index = idx.find(s); - - // if driver not found, return - if (index == idx.end()) - return; - - buffer.append("\n--- DRIVER INFO ---\n").append("Driver: ").append(s).append("\n\n"); - auto s_offset = index->second; - std::fseek(fp, s_offset, SEEK_SET); - char rbuf[64 * 1024]; - std::string readbuf; - while (std::fgets(rbuf, 64 * 1024, fp) != nullptr) - { - readbuf = chartrimcarriage(rbuf); - - // end entry when a end tag is encountered - if (readbuf == TAG_END) - break; - - // continue if a specific tag is encountered - if (readbuf == tag) - continue; - - // add this string to the buffer - buffer.append(readbuf).append("\n"); - } -} - -//------------------------------------------------- -// load a game name and offset into an -// indexed array (mameinfo) -//------------------------------------------------- -int datfile_manager::index_mame_mess_info(fileptr &&fp, dataindex &index, drvindex &index_drv, int &drvcount) -{ - size_t foundtag; - auto t_mame = TAG_MAMEINFO_R.size(); - auto t_mess = TAG_MESSINFO_R.size(); - auto t_ginit = TAG_GAMEINIT_R.size(); - auto t_info = TAG_INFO.size(); - - char rbuf[64 * 1024]; - std::string readbuf, xid, name; - while (std::fgets(rbuf, 64 * 1024, fp.get()) != nullptr) - { - readbuf = chartrimcarriage(rbuf); - if (m_mame_rev.empty() && readbuf.compare(0, t_mame, TAG_MAMEINFO_R) == 0) - { - auto found = readbuf.find(" ", t_mame + 1); - m_mame_rev = readbuf.substr(t_mame + 1, found - t_mame); - } - else if (m_mess_rev.empty() && (foundtag = readbuf.find(TAG_MESSINFO_R)) != std::string::npos) - { - auto found = readbuf.find(" ", foundtag + t_mess + 1); - m_mess_rev = readbuf.substr(foundtag + t_mess + 1, found - t_mess - foundtag); - } - else if (m_ginit_rev.empty() && readbuf.compare(0, t_ginit, TAG_GAMEINIT_R) == 0) - { - auto found = readbuf.find(" ", t_ginit + 1); - m_ginit_rev = readbuf.substr(t_ginit + 1, found - t_ginit); - } - else if (readbuf.compare(0, t_info, TAG_INFO) == 0) - { - // TAG_INFO - std::fgets(rbuf, 64 * 1024, fp.get()); - xid = chartrimcarriage(rbuf); - name = readbuf.substr(t_info + 1); - if (xid == TAG_MAME) - { - // validate driver - auto game_index = driver_list::find(name.c_str()); - if (game_index != -1) - index.emplace(&driver_list::driver(game_index), std::ftell(fp.get())); - } - else if (xid == TAG_DRIVER) - { - index_drv.emplace(name, std::ftell(fp.get())); - drvcount++; - } - } - } - return index.size(); -} - -//------------------------------------------------- -// load a game name and offset into an -// indexed array -//------------------------------------------------- -int datfile_manager::index_datafile(fileptr &&fp, dataindex &index, int &swcount, std::string &rev, std::string const &tag, char sep) -{ - std::string readbuf; - auto const tag_size = tag.size(); - auto const t_info = TAG_INFO.size(); - auto const t_bio = TAG_BIO.size(); - char rbuf[64 * 1024]; - while (std::fgets(rbuf, 64 * 1024, fp.get()) != nullptr) - { - readbuf = chartrimcarriage(rbuf); - - if (!tag.empty()) - { - if (rev.empty() && readbuf.compare(0, tag_size, tag) == 0) - { - if (sep != 's') - rev = readbuf.substr(tag_size + 1, readbuf.find(sep, tag_size + 1) - tag_size); - else - rev = readbuf.substr(tag_size + 1); - } - } - - if (readbuf.compare(0, t_info, TAG_INFO) == 0) - { - // search for game info - auto rd = readbuf.substr(t_info + 1); - std::vector gamelist = tokenize(rd, ','); - for (auto & e : gamelist) - { - auto game_index = driver_list::find(e.c_str()); - if (game_index != -1) - index.emplace(&driver_list::driver(game_index), std::ftell(fp.get())); - } - } - else if (!readbuf.empty() && readbuf[0] == DATAFILE_TAG[0]) - { - // search for software info - std::fgets(rbuf, 64 * 1024, fp.get()); - std::string readbuf_2(chartrimcarriage(rbuf)); - if (readbuf_2.compare(0, t_bio, TAG_BIO) == 0) - { - auto eq_sign = readbuf.find('='); - std::string s_list(readbuf.substr(1, eq_sign - 1)); - std::string s_roms(readbuf.substr(eq_sign + 1)); - std::vector token_list = tokenize(s_list, ','); - std::vector token_roms = tokenize(s_roms, ','); - for (auto & li : token_list) - for (auto & ro : token_roms) - m_swindex[li].emplace(ro, std::ftell(fp.get())); - swcount++; - } - } - } - return index.size(); -} - -//--------------------------------------------------------- -// parseopen - Open up file for reading -//--------------------------------------------------------- -datfile_manager::fileptr datfile_manager::parseopen(const char *filename) -{ - emu_file file(m_options.history_path(), OPEN_FLAG_READ); - if (file.open(filename) != osd_file::error::NONE) - return fileptr(nullptr, &std::fclose); - - std::string const fullpath = file.fullpath(); - file.close(); - fileptr result(std::fopen(fullpath.c_str(), "rb"), &std::fclose); - - fgetc(result.get()); - fseek(result.get(), 0, SEEK_SET); - return result; -} - -//------------------------------------------------- -// create the menu index -//------------------------------------------------- -void datfile_manager::index_menuidx(fileptr &&fp, const game_driver *drv, dataindex const &idx, drvindex &index) -{ - auto itemsiter = idx.find(drv); - if (itemsiter == idx.end()) - { - auto const cloneof = driver_list::non_bios_clone(*drv); - if (cloneof == -1) - return; - - auto const c_drv = &driver_list::driver(cloneof); - if ((itemsiter = idx.find(c_drv)) == idx.end()) - return; - } - - // seek to correct point in datafile - auto const s_offset = itemsiter->second; - std::fseek(fp.get(), s_offset, SEEK_SET); - auto const tinfo = TAG_INFO.size(); - char rbuf[64 * 1024]; - std::string readbuf; - while (std::fgets(rbuf, 64 * 1024, fp.get()) != nullptr) - { - readbuf = chartrimcarriage(rbuf); - - if (!core_strnicmp(TAG_INFO.c_str(), readbuf.c_str(), tinfo)) - break; - - // TAG_COMMAND identifies the driver - if (readbuf == TAG_COMMAND) - { - std::fgets(rbuf, 64 * 1024, fp.get()); - chartrimcarriage(rbuf); - index.emplace(rbuf, std::ftell(fp.get())); - } - } -} - -//------------------------------------------------- -// load command text into the buffer -//------------------------------------------------- -void datfile_manager::load_command_info(std::string &buffer, std::string const &sel) -{ - fileptr const datfile = parseopen("command.dat"); - if (datfile) - { - // open and seek to correct point in datafile - auto const offset = m_menuidx.at(sel); - std::fseek(datfile.get(), offset, SEEK_SET); - char rbuf[64 * 1024]; - std::string readbuf; - while (std::fgets(rbuf, 64 * 1024, datfile.get()) != nullptr) - { - readbuf = chartrimcarriage(rbuf); - - // skip separator lines - if (readbuf == TAG_COMMAND_SEPARATOR) - continue; - - // end entry when a tag is encountered - if (readbuf == TAG_END) - break; - - // add this string to the buffer - buffer.append(readbuf).append("\n");; - } - } -} - -//------------------------------------------------- -// load submenu item for command.dat -//------------------------------------------------- -void datfile_manager::command_sub_menu(const game_driver *drv, std::vector &menuitems) -{ - fileptr datfile = parseopen("command.dat"); - if (datfile) - { - m_menuidx.clear(); - index_menuidx(std::move(datfile), drv, m_cmdidx, m_menuidx); - menuitems.reserve(m_menuidx.size()); - for (auto const &elem : m_menuidx) - menuitems.push_back(elem.first); - } -} - -} // namespace ui diff --git a/src/frontend/mame/ui/datfile.h b/src/frontend/mame/ui/datfile.h deleted file mode 100644 index 93d13527cc9..00000000000 --- a/src/frontend/mame/ui/datfile.h +++ /dev/null @@ -1,106 +0,0 @@ -// license:BSD-3-Clause -// copyright-holders:Maurizio Petrarota -/*************************************************************************** - - ui/datfile.h - - UI DATs manager. - -***************************************************************************/ - -#ifndef MAME_FRONTEND_UI_DATFILE_H -#define MAME_FRONTEND_UI_DATFILE_H - -#pragma once - -#include -#include -#include -#include - - -class ui_options; - -namespace ui { -//------------------------------------------------- -// Datafile Manager -//------------------------------------------------- -class datfile_manager -{ -public: - // construction/destruction - datfile_manager(running_machine &machine, ui_options &moptions); - - // getters - running_machine &machine() const { return m_machine; } - - // actions - void load_data_info(const game_driver *drv, std::string &buffer, int type); - void load_command_info(std::string &buffer, std::string const &sel); - void load_software_info(std::string const &softlist, std::string &buffer, std::string const &softname, std::string const &parentname); - void command_sub_menu(const game_driver *drv, std::vector &menuitems); - void reset_run() { first_run = true; } - - std::string const &rev_history() const { return m_history_rev; } - std::string const &rev_mameinfo() const { return m_mame_rev; } - std::string const &rev_messinfo() const { return m_mess_rev; } - std::string const &rev_sysinfo() const { return m_sysinfo_rev; } - std::string const &rev_storyinfo() const { return m_story_rev; } - std::string const &rev_ginitinfo() const { return m_ginit_rev; } - - bool has_history(game_driver const *driver) const { return m_histidx.find(driver) != m_histidx.end(); } - bool has_mameinfo(game_driver const *driver) const { return m_mameidx.find(driver) != m_mameidx.end(); } - bool has_messinfo(game_driver const *driver) const { return m_messidx.find(driver) != m_messidx.end(); } - bool has_command(game_driver const *driver) const { return m_cmdidx.find(driver) != m_cmdidx.end(); } - bool has_sysinfo(game_driver const *driver) const { return m_sysidx.find(driver) != m_sysidx.end(); } - bool has_story(game_driver const *driver) const { return m_storyidx.find(driver) != m_storyidx.end(); } - bool has_gameinit(game_driver const *driver) const { return m_ginitidx.find(driver) != m_ginitidx.end(); } - bool has_software(std::string const &softlist, std::string const &softname, std::string const &parentname) const; - - bool has_data(game_driver const *a = nullptr) const - { - game_driver const *const d(a ? a : &machine().system()); - return has_history(d) || has_mameinfo(d) || has_messinfo(d) || has_command(d) || has_sysinfo(d) || has_story(d) || has_gameinit(d); - } - -private: - using drvindex = std::unordered_map; - using dataindex = std::unordered_map; - using swindex = std::unordered_map; - using fileptr = std::unique_ptr; - - // global index - static dataindex m_histidx, m_mameidx, m_messidx, m_cmdidx, m_sysidx, m_storyidx, m_ginitidx; - static drvindex m_drvidx, m_messdrvidx, m_menuidx; - static swindex m_swindex; - - // internal helpers - void init_history(fileptr &&fp); - void init_mameinfo(fileptr &&fp); - void init_messinfo(fileptr &&fp); - void init_command(fileptr &&fp); - void init_sysinfo(fileptr &&fp); - void init_story(fileptr &&fp); - void init_gameinit(fileptr &&fp); - - fileptr parseopen(char const *filename); - - int index_mame_mess_info(fileptr &&fp, dataindex &index, drvindex &index_drv, int &drvcount); - int index_datafile(fileptr &&fp, dataindex &index, int &swcount, std::string &rev, std::string const &tag, char sep); - void index_menuidx(fileptr &&fp, game_driver const *drv, dataindex const &idx, drvindex &index); - - long const *find_software(std::string const &softlist, std::string const &softname, std::string const &parentname) const; - - void load_data_text(FILE *fp, game_driver const *drv, std::string &buffer, dataindex const &idx, std::string const &tag); - void load_driver_text(FILE *fp, game_driver const *drv, std::string &buffer, drvindex const &idx, std::string const &tag); - - // internal state - running_machine &m_machine; // reference to our machine - ui_options &m_options; - static std::string m_history_rev, m_mame_rev, m_mess_rev, m_sysinfo_rev, m_story_rev, m_ginit_rev; - static bool first_run; -}; - -} // namespace ui - -#endif // MAME_FRONTEND_UI_DATFILE_H diff --git a/src/frontend/mame/ui/datmenu.cpp b/src/frontend/mame/ui/datmenu.cpp index 99ae6b69bb7..71bc7c9bf09 100644 --- a/src/frontend/mame/ui/datmenu.cpp +++ b/src/frontend/mame/ui/datmenu.cpp @@ -11,7 +11,6 @@ #include "emu.h" #include "ui/ui.h" -#include "ui/datfile.h" #include "ui/datmenu.h" #include "ui/utils.h" @@ -19,6 +18,7 @@ #include "rendfont.h" #include "softlist.h" #include "uiinput.h" +#include "luaengine.h" #include @@ -45,8 +45,19 @@ menu_dats_view::menu_dats_view(mame_ui_manager &mui, render_container &container m_parent = image.software_entry()->parentname(); } } - - init_items(); + const char *lua_list = mame_machine_manager::instance()->lua()->call_plugin(driver->name, "data_list"); + if(lua_list) + { + std::string list(lua_list); + char *token = strtok((char *)list.c_str(), ","); + int count = 0; + while(token) + { + m_items_list.emplace_back(_(token), count, mame_machine_manager::instance()->lua()->call_plugin(util::string_format("%d", count).c_str(), "data_version")); + count++; + token = strtok(nullptr, ","); + } + } } //------------------------------------------------- @@ -65,10 +76,21 @@ menu_dats_view::menu_dats_view(mame_ui_manager &mui, render_container &container , m_issoft(true) { - if (mame_machine_manager::instance()->datfile().has_software(m_list, m_short, m_parent)) - m_items_list.emplace_back(_("Software History"), UI_HISTORY_LOAD, mame_machine_manager::instance()->datfile().rev_history()); if (swinfo != nullptr && !swinfo->usage.empty()) m_items_list.emplace_back(_("Software Usage"), 0, ""); + const char *lua_list = mame_machine_manager::instance()->lua()->call_plugin(std::string(m_short).append(1, ',').append(m_list).c_str(), "data_list"); + if(lua_list) + { + std::string list(lua_list); + char *token = strtok((char *)list.c_str(), ","); + int count = 1; + while(token) + { + m_items_list.emplace_back(_(token), count, mame_machine_manager::instance()->lua()->call_plugin(util::string_format("%d", count - 1).c_str(), "data_version")); + count++; + token = strtok(nullptr, ","); + } + } } //------------------------------------------------- @@ -368,25 +390,8 @@ void menu_dats_view::custom_render(void *selectedref, float top, float bottom, f void menu_dats_view::get_data() { std::vector xstart, xend; - std::string buffer; - if (m_items_list[m_actual].option == UI_COMMAND_LOAD) - { - std::vector m_item; - mame_machine_manager::instance()->datfile().command_sub_menu(m_driver, m_item); - if (!m_item.empty()) - { - for (auto & e : m_item) - { - std::string t_buffer; - buffer.append(e).append("\n"); - mame_machine_manager::instance()->datfile().load_command_info(t_buffer, e); - if (!t_buffer.empty()) buffer.append(t_buffer).append("\n"); - } - convert_command_glyph(buffer); - } - } - else - mame_machine_manager::instance()->datfile().load_data_info(m_driver, buffer, m_items_list[m_actual].option); + std::string buffer(mame_machine_manager::instance()->lua()->call_plugin(util::string_format("%d", m_items_list[m_actual].option).c_str(), "data")); + auto lines = ui().wrap_text(container(), buffer.c_str(), 0.0f, 0.0f, 1.0f - (4.0f * UI_BOX_LR_BORDER), xstart, xend); for (int x = 0; x < lines; ++x) @@ -404,12 +409,7 @@ void menu_dats_view::get_data_sw() if (m_items_list[m_actual].option == 0) buffer = m_swinfo->usage; else - { - if (m_swinfo->startempty == 1) - mame_machine_manager::instance()->datfile().load_data_info(m_swinfo->driver, buffer, UI_HISTORY_LOAD); - else - mame_machine_manager::instance()->datfile().load_software_info(m_swinfo->listname, buffer, m_swinfo->shortname, m_swinfo->parentname); - } + buffer = mame_machine_manager::instance()->lua()->call_plugin(util::string_format("%d", m_items_list[m_actual].option - 1).c_str(), "data"); auto lines = ui().wrap_text(container(), buffer.c_str(), 0.0f, 0.0f, 1.0f - (4.0f * UI_BOX_LR_BORDER), xstart, xend); for (int x = 0; x < lines; ++x) @@ -419,23 +419,4 @@ void menu_dats_view::get_data_sw() } } -void menu_dats_view::init_items() -{ - datfile_manager &datfile = mame_machine_manager::instance()->datfile(); - if (datfile.has_history(m_driver)) - m_items_list.emplace_back(_("History"), UI_HISTORY_LOAD, datfile.rev_history()); - if (datfile.has_mameinfo(m_driver)) - m_items_list.emplace_back(_("Mameinfo"), UI_MAMEINFO_LOAD, datfile.rev_mameinfo()); - if (datfile.has_messinfo(m_driver)) - m_items_list.emplace_back(_("Messinfo"), UI_MESSINFO_LOAD, datfile.rev_messinfo()); - if (datfile.has_sysinfo(m_driver)) - m_items_list.emplace_back(_("Sysinfo"), UI_SYSINFO_LOAD, datfile.rev_sysinfo()); - if (datfile.has_story(m_driver)) - m_items_list.emplace_back(_("Mamescore"), UI_STORY_LOAD, datfile.rev_storyinfo()); - if (datfile.has_gameinit(m_driver)) - m_items_list.emplace_back(_("Gameinit"), UI_GINIT_LOAD, datfile.rev_ginitinfo()); - if (datfile.has_command(m_driver)) - m_items_list.emplace_back(_("Command"), UI_COMMAND_LOAD, ""); -} - } // namespace ui diff --git a/src/frontend/mame/ui/datmenu.h b/src/frontend/mame/ui/datmenu.h index 03299187c97..9c76cc7141f 100644 --- a/src/frontend/mame/ui/datmenu.h +++ b/src/frontend/mame/ui/datmenu.h @@ -51,7 +51,6 @@ private: std::string m_list, m_short, m_long, m_parent; void get_data(); void get_data_sw(); - void init_items(); bool m_issoft; struct list_items { diff --git a/src/frontend/mame/ui/dirmenu.cpp b/src/frontend/mame/ui/dirmenu.cpp index 80b036c5277..3be14a80974 100644 --- a/src/frontend/mame/ui/dirmenu.cpp +++ b/src/frontend/mame/ui/dirmenu.cpp @@ -12,7 +12,6 @@ #include "ui/ui.h" #include "ui/dirmenu.h" -#include "ui/datfile.h" #include "ui/utils.h" #include "ui/optsmenu.h" @@ -79,7 +78,6 @@ menu_directory::~menu_directory() { ui().save_ui_options(); ui_globals::reset = true; - mame_machine_manager::instance()->datfile().reset_run(); } //------------------------------------------------- @@ -369,7 +367,6 @@ void menu_add_change_folder::handle() machine().options().set_value(s_folders[m_ref].option, m_current_path.c_str(), OPTION_PRIORITY_CMDLINE, error_string); machine().options().mark_changed(s_folders[m_ref].option); } - mame_machine_manager::instance()->datfile().reset_run(); } else { diff --git a/src/frontend/mame/ui/mainmenu.cpp b/src/frontend/mame/ui/mainmenu.cpp index 92d7db18d4c..a70ae892387 100644 --- a/src/frontend/mame/ui/mainmenu.cpp +++ b/src/frontend/mame/ui/mainmenu.cpp @@ -12,6 +12,7 @@ #include "crsshair.h" #include "emuopts.h" #include "mame.h" +#include "luaengine.h" #include "ui/menu.h" #include "ui/filemngr.h" #include "ui/barcode.h" @@ -29,7 +30,6 @@ #include "ui/videoopt.h" #include "imagedev/cassette.h" #include "machine/bcreader.h" -#include "ui/datfile.h" #include "ui/inifile.h" #include "ui/datmenu.h" #include "ui/pluginopt.h" @@ -129,7 +129,7 @@ void menu_main::populate() item_append(_("Plugin Options"), "", 0, (void *)PLUGINS); // add dats menu - if (ui().options().enabled_dats() && mame_machine_manager::instance()->datfile().has_data()) + if (ui().options().enabled_dats() && mame_machine_manager::instance()->lua()->call_plugin("", "data_list")) item_append(_("External DAT View"), "", 0, (void *)EXTERNAL_DATS); item_append(menu_item_type::SEPARATOR); diff --git a/src/frontend/mame/ui/selgame.cpp b/src/frontend/mame/ui/selgame.cpp index bcba3239f6a..c025f75e202 100644 --- a/src/frontend/mame/ui/selgame.cpp +++ b/src/frontend/mame/ui/selgame.cpp @@ -14,7 +14,6 @@ #include "ui/ui.h" #include "ui/miscmenu.h" -#include "ui/datfile.h" #include "ui/inifile.h" #include "ui/datmenu.h" #include "ui/optsmenu.h" @@ -33,6 +32,7 @@ #include "rendutil.h" #include "softlist_dev.h" #include "uiinput.h" +#include "luaengine.h" extern const char UI_VERSION_TAG[]; namespace ui { @@ -345,19 +345,18 @@ void menu_select_game::handle() if (!isfavorite()) { const game_driver *driver = (const game_driver *)menu_event->itemref; - if ((FPTR)driver > skip_main_items && mame_machine_manager::instance()->datfile().has_data(driver)) + if ((FPTR)driver > skip_main_items && mame_machine_manager::instance()->lua()->call_plugin(driver->name, "data_list")) menu::stack_push(ui(), container(), driver); } else { ui_software_info *ui_swinfo = (ui_software_info *)menu_event->itemref; - datfile_manager &mdat = mame_machine_manager::instance()->datfile(); if ((FPTR)ui_swinfo > skip_main_items) { - if (ui_swinfo->startempty == 1 && mdat.has_history(ui_swinfo->driver)) + if (ui_swinfo->startempty == 1 && mame_machine_manager::instance()->lua()->call_plugin(ui_swinfo->driver->name, "data_list")) menu::stack_push(ui(), container(), ui_swinfo->driver); - else if (mdat.has_software(ui_swinfo->listname, ui_swinfo->shortname, ui_swinfo->parentname) || !ui_swinfo->usage.empty()) + else if (mame_machine_manager::instance()->lua()->call_plugin(std::string(ui_swinfo->shortname).append(1, ',').append(ui_swinfo->listname).c_str(), "data_list") || !ui_swinfo->usage.empty()) menu::stack_push(ui(), container(), ui_swinfo); } } diff --git a/src/frontend/mame/ui/selmenu.cpp b/src/frontend/mame/ui/selmenu.cpp index 3cf47454317..20f80651307 100644 --- a/src/frontend/mame/ui/selmenu.cpp +++ b/src/frontend/mame/ui/selmenu.cpp @@ -498,7 +498,9 @@ void menu_select_launch::draw_common_arrow(float origx1, float origy1, float ori } // apply arrow - if (current == dmin) + if (dmax == dmin) + return; + else if (current == dmin) draw_arrow(ar_x0, ar_y0, ar_x1, ar_y1, fgcolor_right, ROT90); else if (current == dmax) draw_arrow(al_x0, al_y0, al_x1, al_y1, fgcolor_left, ROT90 ^ ORIENTATION_FLIP_X); diff --git a/src/frontend/mame/ui/selsoft.cpp b/src/frontend/mame/ui/selsoft.cpp index 9902ff3205c..127b6c0ce54 100644 --- a/src/frontend/mame/ui/selsoft.cpp +++ b/src/frontend/mame/ui/selsoft.cpp @@ -14,7 +14,6 @@ #include "ui/ui.h" #include "ui/datmenu.h" -#include "ui/datfile.h" #include "ui/inifile.h" #include "ui/selector.h" @@ -26,6 +25,7 @@ #include "rendutil.h" #include "softlist_dev.h" #include "uiinput.h" +#include "luaengine.h" namespace ui { @@ -246,11 +246,10 @@ void menu_select_software::handle() { // handle UI_DATS ui_software_info *ui_swinfo = (ui_software_info *)menu_event->itemref; - datfile_manager &mdat = mame_machine_manager::instance()->datfile(); - if (ui_swinfo->startempty == 1 && mdat.has_history(ui_swinfo->driver)) + if (ui_swinfo->startempty == 1 && mame_machine_manager::instance()->lua()->call_plugin(ui_swinfo->driver->name, "data_list")) menu::stack_push(ui(), container(), ui_swinfo->driver); - else if (mdat.has_software(ui_swinfo->listname, ui_swinfo->shortname, ui_swinfo->parentname) || !ui_swinfo->usage.empty()) + else if (mame_machine_manager::instance()->lua()->call_plugin(std::string(ui_swinfo->shortname).append(1, ',').append(ui_swinfo->listname).c_str(), "data_list") || !ui_swinfo->usage.empty()) menu::stack_push(ui(), container(), ui_swinfo); } else if (menu_event->iptkey == IPT_UI_LEFT_PANEL) diff --git a/src/frontend/mame/ui/utils.h b/src/frontend/mame/ui/utils.h index 8a2258ec398..b61c230f618 100644 --- a/src/frontend/mame/ui/utils.h +++ b/src/frontend/mame/ui/utils.h @@ -84,20 +84,6 @@ enum HIDE_BOTH }; -enum -{ - UI_FIRST_LOAD = 0, - UI_GENERAL_LOAD = UI_FIRST_LOAD, - UI_HISTORY_LOAD, - UI_MAMEINFO_LOAD, - UI_SYSINFO_LOAD, - UI_MESSINFO_LOAD, - UI_COMMAND_LOAD, - UI_GINIT_LOAD, - UI_STORY_LOAD, - UI_LAST_LOAD = UI_STORY_LOAD -}; - enum : UINT16 { UI_SW_FIRST = 0,