From b47ebee363ce510634e3ce93fe7056d8f5b0ce84 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Fri, 13 Jan 2012 21:36:02 +0200 Subject: [PATCH] wxwidgets: Save settings on exit, load settings on startup --- src/plat-wxwidgets/main.cpp | 80 +++++++++++++++++++++++++++++++++++++++ src/plat-wxwidgets/mainwindow.cpp | 1 - 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/src/plat-wxwidgets/main.cpp b/src/plat-wxwidgets/main.cpp index de98a08d..b2538afd 100644 --- a/src/plat-wxwidgets/main.cpp +++ b/src/plat-wxwidgets/main.cpp @@ -5,12 +5,16 @@ #include #include +#include "core/command.hpp" +#include "core/controller.hpp" #include "core/dispatch.hpp" #include "core/framerate.hpp" #include "core/lua.hpp" +#include "core/mainloop.hpp" #include "core/misc.hpp" #include "core/rom.hpp" #include "core/rrdata.hpp" +#include "core/settings.hpp" #include "core/window.hpp" #include "core/zip.hpp" @@ -153,6 +157,74 @@ end: uiserv_event uic(code); wxPostEvent(ui_services, uic); } + + void save_configuration() + { + std::string cfg = get_config_path() + "/lsneswxw.rc"; + std::ofstream cfgfile(cfg.c_str()); + //Jukebox. + for(auto i : get_jukebox_names()) + cfgfile << "add-jukebox-save " << i << std::endl; + //Joystick axis. + for(auto i : keygroup::get_axis_set()) { + keygroup* k = keygroup::lookup_by_name(i); + auto p = k->get_parameters(); + cfgfile << "set-axis " << i << " "; + switch(p.ktype) { + case keygroup::KT_DISABLED: cfgfile << "disabled"; break; + case keygroup::KT_AXIS_PAIR: cfgfile << "axis"; break; + case keygroup::KT_AXIS_PAIR_INVERSE: cfgfile << "axis-inverse"; break; + case keygroup::KT_PRESSURE_M0: cfgfile << "pressure-0"; break; + case keygroup::KT_PRESSURE_MP: cfgfile << "pressure-+"; break; + case keygroup::KT_PRESSURE_0M: cfgfile << "pressure0-"; break; + case keygroup::KT_PRESSURE_0P: cfgfile << "pressure0+"; break; + case keygroup::KT_PRESSURE_PM: cfgfile << "pressure+-"; break; + case keygroup::KT_PRESSURE_P0: cfgfile << "pressure+0"; break; + }; + cfgfile << " minus=" << p.cal_left << " zero=" << p.cal_center << " plus=" << p.cal_right + << " tolerance=" << p.cal_tolerance << std::endl; + } + //Settings. + for(auto i : setting::get_settings_set()) { + if(!setting::is_set(i)) + cfgfile << "unset-setting " << i << std::endl; + else + cfgfile << "set-setting " << i << " " << setting::get(i) << std::endl; + } + //Aliases. + for(auto i : command::get_aliases()) { + std::string old_alias_value = command::get_alias_for(i); + while(old_alias_value != "") { + std::string aliasline; + size_t s = old_alias_value.find_first_of("\n"); + if(s < old_alias_value.length()) { + aliasline = old_alias_value.substr(0, s); + old_alias_value = old_alias_value.substr(s + 1); + } else { + aliasline = old_alias_value; + old_alias_value = ""; + } + cfgfile << "alias-command " << i << " " << aliasline << std::endl; + } + } + //Keybindings. + for(auto i : keymapper::get_bindings()) { + std::string i2 = i; + size_t s = i2.find_first_of("|"); + size_t s2 = i2.find_first_of("/"); + if(s > i2.length() || s2 > s) + continue; + std::string key = i2.substr(s + 1); + std::string mod = i2.substr(0, s2); + std::string modspec = i2.substr(s2 + 1, s - s2 - 1); + std::string old_command_value = keymapper::get_command_for(i); + if(mod != "" || modspec != "") + cfgfile << "bind-key " << mod << "/" << modspec << " " << key << " " + << old_command_value << std::endl; + else + cfgfile << "bind-key " << key << " " << old_command_value << std::endl; + } + } } wxString towxstring(const std::string& str) throw(std::bad_alloc) @@ -196,6 +268,7 @@ void signal_program_exit() void graphics_plugin::init() throw() { + initialize_wx_keyboard(); } void graphics_plugin::quit() throw() @@ -235,8 +308,14 @@ bool lsnes_app::OnInit() messages << "BSNES version: " << bsnes_core_version << std::endl; messages << "lsnes version: lsnes rr" << lsnes_version << std::endl; + controls.set_port(0, PT_NONE, false); + controls.set_port(1, PT_NONE, false); + std::string cfgpath = get_config_path(); messages << "Saving per-user data to: " << get_config_path() << std::endl; + messages << "--- Running lsnesrc --- " << std::endl; + command::invokeC("run-script " + cfgpath + "/lsneswxw.rc"); + messages << "--- End running lsnesrc --- " << std::endl; joystick_thread_handle = &thread::create(joystick_thread, NULL); @@ -256,6 +335,7 @@ int lsnes_app::OnExit() { information_dispatch::do_dump_end(); rrdata::close(); + save_configuration(); joystick_plugin::signal(); delete joystick_thread_handle; platform::quit(); diff --git a/src/plat-wxwidgets/mainwindow.cpp b/src/plat-wxwidgets/mainwindow.cpp index 0bbb4ab0..d0decccc 100644 --- a/src/plat-wxwidgets/mainwindow.cpp +++ b/src/plat-wxwidgets/mainwindow.cpp @@ -608,7 +608,6 @@ void boot_emulator(loaded_rom& rom, moviefile& movie) wxwin_mainwindow::panel::panel(wxWindow* win) : wxPanel(win) { - initialize_wx_keyboard(); this->Connect(wxEVT_PAINT, wxPaintEventHandler(panel::on_paint), NULL, this); this->Connect(wxEVT_ERASE_BACKGROUND, wxEraseEventHandler(panel::on_erase), NULL, this); this->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(panel::on_keyboard_down), NULL, this); -- 2.11.4.GIT