MAME related settings are saved on request only (nw)

This commit is contained in:
Miodrag Milanovic 2016-02-06 13:47:21 +01:00
parent 65d9003144
commit f80ff01891
11 changed files with 123 additions and 95 deletions

View File

@ -49,7 +49,7 @@ ui_menu_controller_mapping::~ui_menu_controller_mapping()
if (strcmp(machine().options().value(m_options[d].option),m_device_status[m_options[d].status])!=0)
{
machine().options().set_value(m_options[d].option, m_device_status[m_options[d].status], OPTION_PRIORITY_CMDLINE, error_string);
save_main_option(machine(),m_options[d].option, m_device_status[m_options[d].status]);
machine().options().mark_changed(m_options[d].option);
}
}
}

View File

@ -152,7 +152,7 @@ void ui_menu_add_change_folder::handle()
if (strcmp(machine().options().value(s_folders_entry[m_ref].option), m_current_path.c_str()) != 0)
{
machine().options().set_value(s_folders_entry[m_ref].option, m_current_path.c_str(), OPTION_PRIORITY_CMDLINE, error_string);
save_main_option(machine(), s_folders_entry[m_ref].option, m_current_path.c_str());
machine().options().mark_changed(s_folders_entry[m_ref].option);
}
}
machine().datfile().reset_run();
@ -175,7 +175,7 @@ void ui_menu_add_change_folder::handle()
if (strcmp(machine().options().value(s_folders_entry[m_ref].option), tmppath.c_str()) != 0)
{
machine().options().set_value(s_folders_entry[m_ref].option, tmppath.c_str(), OPTION_PRIORITY_CMDLINE, error_string);
save_main_option(machine(), s_folders_entry[m_ref].option, tmppath.c_str());
machine().options().mark_changed(s_folders_entry[m_ref].option);
}
}
}
@ -627,8 +627,8 @@ void ui_menu_remove_folder::handle()
else {
if (strcmp(machine().options().value(s_folders_entry[m_ref].option),tmppath.c_str())!=0)
{
machine().options().set_value(s_folders_entry[m_ref].option, tmppath.c_str(), OPTION_PRIORITY_CMDLINE, error_string);
save_main_option(machine(), s_folders_entry[m_ref].option, tmppath.c_str());
machine().options().set_value(s_folders_entry[m_ref].option, tmppath.c_str(), OPTION_PRIORITY_CMDLINE, error_string);
machine().options().mark_changed(s_folders_entry[m_ref].option);
}
}

View File

@ -86,13 +86,14 @@ ui_menu_display_options::~ui_menu_display_options()
if (machine().options().int_value(m_options[d].option)!=m_options[d].status)
{
machine().options().set_value(m_options[d].option, m_options[d].status, OPTION_PRIORITY_CMDLINE, error_string);
save_main_option(machine(),m_options[d].option, m_options[d].status);
machine().options().mark_changed(m_options[d].option);
}
}
if (strcmp(machine().options().value(m_options[1].option), m_video[m_options[1].status].option)!=0)
{
machine().options().set_value(m_options[1].option, m_video[m_options[1].status].option, OPTION_PRIORITY_CMDLINE, error_string);
save_main_option(machine(),m_options[1].option, m_video[m_options[1].status].option);
machine().options().mark_changed(m_options[1].option);
}
ui_globals::reset = true;
}

View File

@ -1376,8 +1376,8 @@ void ui_menu::draw_select_game(bool noinput)
container->add_quad(0.0f, 0.0f, 1.0f, 1.0f, ARGB_WHITE, bgrnd_texture, PRIMFLAG_BLENDMODE(BLENDMODE_ALPHA));
hover = item.size() + 1;
visible_items = (is_swlist) ? item.size() - 2 : item.size() - 4;
float extra_height = (is_swlist) ? 2.0f * line_height : 4.0f * line_height;
visible_items = (is_swlist) ? item.size() - 2 : item.size() - 5;
float extra_height = (is_swlist) ? 2.0f * line_height : 5.0f * line_height;
float visible_extra_menu_height = customtop + custombottom + extra_height;
// locate mouse

View File

@ -278,8 +278,4 @@ private:
void draw_icon(int linenum, void *selectedref, float x1, float y1);
};
void save_main_option(running_machine &machine,const char *name, const char *value);
void save_main_option(running_machine &machine,const char *name, int value);
void save_main_option(running_machine &machine,const char *name, float value);
#endif // __UI_MENU_H__

View File

@ -594,7 +594,7 @@ ui_menu_misc_options::~ui_menu_misc_options()
if (machine().options().bool_value(m_options[d].option) != m_options[d].status)
{
machine().options().set_value(m_options[d].option, m_options[d].status, OPTION_PRIORITY_CMDLINE, error_string);
save_main_option(machine(), m_options[d].option, m_options[d].status);
machine().options().mark_changed(m_options[d].option);
}
}
}

View File

@ -340,57 +340,3 @@ void save_ui_options(running_machine &machine)
else
machine.popmessage("**Error to save ui.ini**", emulator_info::get_configname());
}
//-------------------------------------------------
// save main option
//-------------------------------------------------
void save_main_option(running_machine &machine,const char *name, const char *value)
{
// parse the file
std::string error;
emu_options options(machine.options()); // This way we make sure that all OSD parts are in
std::string error_string;
// attempt to open the main ini file
{
emu_file file(machine.options().ini_path(), OPEN_FLAG_READ);
if (file.open(emulator_info::get_configname(), ".ini") == FILERR_NONE)
{
bool result = options.parse_ini_file((core_file&)file, OPTION_PRIORITY_MAME_INI, OPTION_PRIORITY_DRIVER_INI, error);
if (!result)
{
osd_printf_error("**Error to load %s.ini**", emulator_info::get_configname());
return;
}
}
}
options.set_value(name, value, OPTION_PRIORITY_CMDLINE, error_string);
// attempt to open the output file
{
emu_file file(machine.options().ini_path(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
if (file.open(emulator_info::get_configname(), ".ini") == FILERR_NONE)
{
// generate the updated INI
std::string initext = options.output_ini();
file.puts(initext.c_str());
file.close();
}
else
machine.popmessage("**Error to save %s.ini**", emulator_info::get_configname());
}
}
void save_main_option(running_machine &machine,const char *name, int value)
{
std::string tempstr = strformat("%d", value);
save_main_option(machine,name,tempstr.c_str());
}
void save_main_option(running_machine &machine,const char *name, float value)
{
std::string tempstr = strformat("%f", (double)value);
save_main_option(machine,name,tempstr.c_str());
}

View File

@ -101,6 +101,57 @@ bool sort_game_list(const game_driver *x, const game_driver *y)
}
}
//-------------------------------------------------
// save main option
//-------------------------------------------------
void save_main_option(running_machine &machine)
{
// parse the file
std::string error;
emu_options options(machine.options()); // This way we make sure that all OSD parts are in
std::string error_string;
// attempt to open the main ini file
{
emu_file file(machine.options().ini_path(), OPEN_FLAG_READ);
if (file.open(emulator_info::get_configname(), ".ini") == FILERR_NONE)
{
bool result = options.parse_ini_file((core_file&)file, OPTION_PRIORITY_MAME_INI, OPTION_PRIORITY_DRIVER_INI, error);
if (!result)
{
osd_printf_error("**Error to load %s.ini**", emulator_info::get_configname());
return;
}
}
}
for (emu_options::entry *f_entry = machine.options().first(); f_entry != nullptr; f_entry = f_entry->next())
{
if (f_entry->is_changed())
{
options.set_value(f_entry->name(), f_entry->value(), OPTION_PRIORITY_CMDLINE, error_string);
}
}
// attempt to open the output file
{
emu_file file(machine.options().ini_path(), OPEN_FLAG_WRITE | OPEN_FLAG_CREATE | OPEN_FLAG_CREATE_PATHS);
if (file.open(emulator_info::get_configname(), ".ini") == FILERR_NONE)
{
// generate the updated INI
std::string initext = options.output_ini();
file.puts(initext.c_str());
file.close();
}
else {
machine.popmessage("**Error to save %s.ini**", emulator_info::get_configname());
return;
}
}
machine.ui().popup_time(3, "\n Configuration saved \n\n");
}
//-------------------------------------------------
// ctor
//-------------------------------------------------
@ -191,10 +242,10 @@ ui_menu_select_game::~ui_menu_select_game()
else
driver = (selected >= 0 && selected < item.size()) ? (const game_driver *)item[selected].ref : nullptr;
if ((FPTR)driver > 2)
if ((FPTR)driver > 3)
last_driver = driver->name;
if ((FPTR)swinfo > 2)
if ((FPTR)swinfo > 3)
last_driver = swinfo->shortname;
std::string filter(main_filters::text[main_filters::actual]);
@ -330,13 +381,13 @@ void ui_menu_select_game::handle()
if (main_filters::actual != FILTER_FAVORITE_GAME)
{
const game_driver *driver = (const game_driver *)m_event->itemref;
if ((FPTR)driver > 2)
if ((FPTR)driver > 3)
ui_menu::stack_push(global_alloc_clear<ui_menu_dats>(machine(), container, UI_HISTORY_LOAD, driver));
}
else
{
ui_software_info *swinfo = (ui_software_info *)m_event->itemref;
if ((FPTR)swinfo > 2)
if ((FPTR)swinfo > 3)
{
if (swinfo->startempty == 1)
ui_menu::stack_push(global_alloc_clear<ui_menu_dats>(machine(), container, UI_HISTORY_LOAD, swinfo->driver));
@ -352,7 +403,7 @@ void ui_menu_select_game::handle()
if (main_filters::actual != FILTER_FAVORITE_GAME)
{
const game_driver *driver = (const game_driver *)m_event->itemref;
if ((FPTR)driver > 2)
if ((FPTR)driver > 3)
{
if ((driver->flags & MACHINE_TYPE_ARCADE) != 0)
ui_menu::stack_push(global_alloc_clear<ui_menu_dats>(machine(), container, UI_MAMEINFO_LOAD, driver));
@ -363,7 +414,7 @@ void ui_menu_select_game::handle()
else
{
ui_software_info *swinfo = (ui_software_info *)m_event->itemref;
if ((FPTR)swinfo > 2 && swinfo->startempty == 1)
if ((FPTR)swinfo > 3 && swinfo->startempty == 1)
{
if ((swinfo->driver->flags & MACHINE_TYPE_ARCADE) != 0)
ui_menu::stack_push(global_alloc_clear<ui_menu_dats>(machine(), container, UI_MAMEINFO_LOAD, swinfo->driver));
@ -379,13 +430,13 @@ void ui_menu_select_game::handle()
if (main_filters::actual != FILTER_FAVORITE_GAME)
{
const game_driver *driver = (const game_driver *)m_event->itemref;
if ((FPTR)driver > 2)
if ((FPTR)driver > 3)
ui_menu::stack_push(global_alloc_clear<ui_menu_dats>(machine(), container, UI_STORY_LOAD, driver));
}
else
{
ui_software_info *swinfo = (ui_software_info *)m_event->itemref;
if ((FPTR)swinfo > 2 && swinfo->startempty == 1)
if ((FPTR)swinfo > 3 && swinfo->startempty == 1)
ui_menu::stack_push(global_alloc_clear<ui_menu_dats>(machine(), container, UI_STORY_LOAD, swinfo->driver));
}
}
@ -396,13 +447,13 @@ void ui_menu_select_game::handle()
if (main_filters::actual != FILTER_FAVORITE_GAME)
{
const game_driver *driver = (const game_driver *)m_event->itemref;
if ((FPTR)driver > 2)
if ((FPTR)driver > 3)
ui_menu::stack_push(global_alloc_clear<ui_menu_dats>(machine(), container, UI_SYSINFO_LOAD, driver));
}
else
{
ui_software_info *swinfo = (ui_software_info *)m_event->itemref;
if ((FPTR)swinfo > 2 && swinfo->startempty == 1)
if ((FPTR)swinfo > 3 && swinfo->startempty == 1)
ui_menu::stack_push(global_alloc_clear<ui_menu_dats>(machine(), container, UI_SYSINFO_LOAD, swinfo->driver));
}
}
@ -413,13 +464,13 @@ void ui_menu_select_game::handle()
if (main_filters::actual != FILTER_FAVORITE_GAME)
{
const game_driver *driver = (const game_driver *)m_event->itemref;
if ((FPTR)driver > 2)
if ((FPTR)driver > 3)
ui_menu::stack_push(global_alloc_clear<ui_menu_command>(machine(), container, driver));
}
else
{
ui_software_info *swinfo = (ui_software_info *)m_event->itemref;
if ((FPTR)swinfo > 2 && swinfo->startempty == 1)
if ((FPTR)swinfo > 3 && swinfo->startempty == 1)
ui_menu::stack_push(global_alloc_clear<ui_menu_command>(machine(), container, swinfo->driver));
}
}
@ -430,7 +481,7 @@ void ui_menu_select_game::handle()
if (main_filters::actual != FILTER_FAVORITE_GAME)
{
const game_driver *driver = (const game_driver *)m_event->itemref;
if ((FPTR)driver > 2)
if ((FPTR)driver > 3)
{
if (!machine().favorite().isgame_favorite(driver))
{
@ -448,7 +499,7 @@ void ui_menu_select_game::handle()
else
{
ui_software_info *swinfo = (ui_software_info *)m_event->itemref;
if ((FPTR)swinfo > 2)
if ((FPTR)swinfo > 3)
{
machine().popmessage("%s\n removed from favorites list.", swinfo->longname.c_str());
machine().favorite().remove_favorite_game(*swinfo);
@ -657,6 +708,7 @@ void ui_menu_select_game::populate()
item_append(MENU_SEPARATOR_ITEM, nullptr, MENU_FLAG_UI, nullptr);
item_append("Configure Options", nullptr, MENU_FLAG_UI, (void *)(FPTR)1);
item_append("Configure Directories", nullptr, MENU_FLAG_UI, (void *)(FPTR)2);
item_append("Save Configuration", nullptr, MENU_FLAG_UI, (void *)(FPTR)3);
// configure the custom rendering
customtop = 3.0f * machine().ui().get_line_height() + 5.0f * UI_BOX_TB_BORDER;
@ -811,15 +863,15 @@ void ui_menu_select_game::custom_render(void *selectedref, float top, float bott
// determine the text to render below
if (main_filters::actual != FILTER_FAVORITE_GAME)
driver = ((FPTR)selectedref > 2) ? (const game_driver *)selectedref : nullptr;
driver = ((FPTR)selectedref > 3) ? (const game_driver *)selectedref : nullptr;
else
{
swinfo = ((FPTR)selectedref > 2) ? (ui_software_info *)selectedref : nullptr;
swinfo = ((FPTR)selectedref > 3) ? (ui_software_info *)selectedref : nullptr;
if (swinfo && swinfo->startempty == 1)
driver = swinfo->driver;
}
if ((FPTR)driver > 2)
if ((FPTR)driver > 3)
{
isstar = machine().favorite().isgame_favorite(driver);
@ -868,7 +920,7 @@ void ui_menu_select_game::custom_render(void *selectedref, float top, float bott
color = UI_RED_COLOR;
}
else if ((FPTR)swinfo > 2)
else if ((FPTR)swinfo > 3)
{
isstar = machine().favorite().isgame_favorite(*swinfo);
@ -1000,6 +1052,10 @@ void ui_menu_select_game::inkey_select(const ui_menu_event *m_event)
else if ((FPTR)driver == 2)
ui_menu::stack_push(global_alloc_clear<ui_menu_directory>(machine(), container));
// anything else is a driver
else if ((FPTR)driver == 3) {
save_main_option(machine());
}
// anything else is a driver
else
{
// audit the game first to see if we're going to work
@ -1060,7 +1116,10 @@ void ui_menu_select_game::inkey_select_favorite(const ui_menu_event *m_event)
// special case for configure directory
else if ((FPTR)ui_swinfo == 2)
ui_menu::stack_push(global_alloc_clear<ui_menu_directory>(machine(), container));
else if ((FPTR)ui_swinfo == 3)
{
save_main_option(machine());
}
else if (ui_swinfo->startempty == 1)
{
// audit the game first to see if we're going to work
@ -2077,7 +2136,7 @@ void ui_menu_select_game::infos_render(void *selectedref, float origx1, float or
if (is_favorites)
{
soft = ((FPTR)selectedref > 2) ? (ui_software_info *)selectedref : nullptr;
soft = ((FPTR)selectedref > 3) ? (ui_software_info *)selectedref : nullptr;
if (soft && soft->startempty == 1)
{
driver = soft->driver;
@ -2088,7 +2147,7 @@ void ui_menu_select_game::infos_render(void *selectedref, float origx1, float or
}
else
{
driver = ((FPTR)selectedref > 2) ? (const game_driver *)selectedref : nullptr;
driver = ((FPTR)selectedref > 3) ? (const game_driver *)selectedref : nullptr;
oldsoft = nullptr;
}
@ -2393,7 +2452,7 @@ void ui_menu_select_game::arts_render(void *selectedref, float origx1, float ori
if (is_favorites)
{
soft = ((FPTR)selectedref > 2) ? (ui_software_info *)selectedref : nullptr;
soft = ((FPTR)selectedref > 3) ? (ui_software_info *)selectedref : nullptr;
if (soft && soft->startempty == 1)
{
driver = soft->driver;
@ -2404,7 +2463,7 @@ void ui_menu_select_game::arts_render(void *selectedref, float origx1, float ori
}
else
{
driver = ((FPTR)selectedref > 2) ? (const game_driver *)selectedref : nullptr;
driver = ((FPTR)selectedref > 3) ? (const game_driver *)selectedref : nullptr;
oldsoft = nullptr;
}

View File

@ -52,17 +52,17 @@ ui_menu_sound_options::~ui_menu_sound_options()
if (strcmp(moptions.value(OSDOPTION_SOUND),m_sound ? OSDOPTVAL_AUTO : OSDOPTVAL_NONE)!=0)
{
moptions.set_value(OSDOPTION_SOUND, m_sound ? OSDOPTVAL_AUTO : OSDOPTVAL_NONE, OPTION_PRIORITY_CMDLINE, error_string);
save_main_option(machine(),OSDOPTION_SOUND, m_sound ? OSDOPTVAL_AUTO : OSDOPTVAL_NONE);
machine().options().mark_changed(OSDOPTION_SOUND);
}
if (moptions.int_value(OPTION_SAMPLERATE)!=m_sound_rate[m_cur_rates])
{
moptions.set_value(OPTION_SAMPLERATE, m_sound_rate[m_cur_rates], OPTION_PRIORITY_CMDLINE, error_string);
save_main_option(machine(),OPTION_SAMPLERATE, m_sound_rate[m_cur_rates]);
machine().options().mark_changed(OPTION_SAMPLERATE);
}
if (moptions.bool_value(OPTION_SAMPLES)!=m_samples)
{
moptions.set_value(OPTION_SAMPLES, m_samples, OPTION_PRIORITY_CMDLINE, error_string);
save_main_option(machine(),OPTION_SAMPLES, m_samples);
machine().options().mark_changed(OPTION_SAMPLES);
}
}

View File

@ -58,7 +58,8 @@ core_options::entry::entry(const char *name, const char *description, UINT32 fla
m_seqid(0),
m_error_reported(false),
m_priority(OPTION_PRIORITY_DEFAULT),
m_description(description)
m_description(description),
m_changed(false)
{
// copy in the name(s) as appropriate
if (name != nullptr)
@ -614,6 +615,16 @@ bool core_options::exists(const char *name) const
return (m_entrymap.find(name) != m_entrymap.end());
}
//-------------------------------------------------
// is_changed - return if option have been marked
// changed
//-------------------------------------------------
bool core_options::is_changed(const char *name) const
{
auto curentry = m_entrymap.find(name);
return (curentry != m_entrymap.end()) ? curentry->second->is_changed() : false;
}
//-------------------------------------------------
// set_value - set the raw option value
//-------------------------------------------------
@ -656,6 +667,16 @@ void core_options::set_flag(const char *name, UINT32 mask, UINT32 flag)
curentry->second->set_flag(mask, flag);
}
void core_options::mark_changed(const char* name)
{
// find the entry first
auto curentry = m_entrymap.find(name);
if (curentry == m_entrymap.end())
{
return;
}
curentry->second->mark_changed();
}
//-------------------------------------------------
// reset - reset the options state, removing

View File

@ -89,12 +89,14 @@ public:
bool is_internal() const { return m_flags & OPTION_FLAG_INTERNAL; }
bool has_range() const { return (!m_minimum.empty() && !m_maximum.empty()); }
int priority() const { return m_priority; }
bool is_changed() const { return m_changed; }
// setters
void set_value(const char *newvalue, int priority);
void set_default_value(const char *defvalue);
void set_description(const char *description);
void set_flag(UINT32 mask, UINT32 flag);
void mark_changed() { m_changed = true; }
void revert(int priority);
private:
@ -110,6 +112,7 @@ public:
std::string m_defdata; // default data for this item
std::string m_minimum; // minimum value
std::string m_maximum; // maximum value
bool m_changed; // changed flag
};
// construction/destruction
@ -157,6 +160,7 @@ public:
float float_value(const char *name) const { return atof(value(name)); }
UINT32 seqid(const char *name) const;
bool exists(const char *name) const;
bool is_changed(const char *name) const;
// setting
void set_command(const char *command);
@ -164,6 +168,7 @@ public:
bool set_value(const char *name, int value, int priority, std::string &error_string);
bool set_value(const char *name, float value, int priority, std::string &error_string);
void set_flag(const char *name, UINT32 mask, UINT32 flags);
void mark_changed(const char *name);
// misc
static const char *unadorned(int x = 0) { return s_option_unadorned[MIN(x, MAX_UNADORNED_OPTIONS)]; }