From a2f4ba6dfd7a0df18e05a6a497d6307013188e62 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Mon, 9 Jun 2014 18:39:30 +0300 Subject: [PATCH] Clean up use of project->moviepath/otherpath --- include/core/ui-services.hpp | 8 +++++++ src/core/ui-services.cpp | 18 +++++++++++++++ src/platform/wxwidgets/dumpmenu.cpp | 4 ++-- src/platform/wxwidgets/editor-hexedit.cpp | 5 ++-- src/platform/wxwidgets/editor-macro.cpp | 5 ++-- src/platform/wxwidgets/editor-memorywatch.cpp | 3 ++- src/platform/wxwidgets/editor-movie.cpp | 5 ++-- src/platform/wxwidgets/editor-voicesub.cpp | 17 ++++++++------ src/platform/wxwidgets/mainwindow.cpp | 23 ++++++++++--------- src/platform/wxwidgets/memorysearch.cpp | 7 +++--- src/platform/wxwidgets/messages.cpp | 3 ++- src/platform/wxwidgets/tracelogger.cpp | 13 ++++++----- src/platform/wxwidgets/tracelogmenu.cpp | 3 ++- 13 files changed, 76 insertions(+), 38 deletions(-) diff --git a/include/core/ui-services.hpp b/include/core/ui-services.hpp index 8adae955..8e0c1040 100644 --- a/include/core/ui-services.hpp +++ b/include/core/ui-services.hpp @@ -128,5 +128,13 @@ void UI_save_movie(emulator_instance& inst, std::ostringstream& buffer); * Look up (platform,game) pair. */ std::pair UI_lookup_platform_and_game(emulator_instance& inst); +/** + * Get otherpath of current project. + */ +std::string UI_get_project_otherpath(emulator_instance& inst); +/** + * Get moviepath of current project. + */ +std::string UI_get_project_moviepath(emulator_instance& inst); #endif diff --git a/src/core/ui-services.cpp b/src/core/ui-services.cpp index 82559277..1f955ace 100644 --- a/src/core/ui-services.cpp +++ b/src/core/ui-services.cpp @@ -252,3 +252,21 @@ std::pair UI_lookup_platform_and_game(emulator_instanc }); return std::make_pair(plat, game); } + +std::string UI_get_project_otherpath(emulator_instance& inst) +{ + std::string path; + lsnes_instance.iqueue->run([&inst, &path]() { + path = inst.project->otherpath(); + }); + return path; +} + +std::string UI_get_project_moviepath(emulator_instance& inst) +{ + std::string path; + lsnes_instance.iqueue->run([&inst, &path]() { + path = inst.project->moviepath(); + }); + return path; +} diff --git a/src/platform/wxwidgets/dumpmenu.cpp b/src/platform/wxwidgets/dumpmenu.cpp index 3906093c..565fee10 100644 --- a/src/platform/wxwidgets/dumpmenu.cpp +++ b/src/platform/wxwidgets/dumpmenu.cpp @@ -92,7 +92,7 @@ void dumper_menu::on_select(wxCommandEvent& e) std::string prefix; if((d & dumper_factory_base::target_type_mask) == dumper_factory_base::target_type_file) { wxFileDialog* d = new wxFileDialog(pwin, wxT("Choose file"), - towxstring(inst.project->otherpath()), wxT(""), wxT("*.*"), + towxstring(UI_get_project_otherpath(inst)), wxT(""), wxT("*.*"), wxFD_SAVE); std::string modext = t->mode_extension(mode); d->SetWildcard(towxstring(modext + " files|*." + modext)); @@ -105,7 +105,7 @@ void dumper_menu::on_select(wxCommandEvent& e) } else if((d & dumper_factory_base::target_type_mask) == dumper_factory_base::target_type_prefix) { wxFileDialog* d = new wxFileDialog(pwin, wxT("Choose prefix"), - towxstring(inst.project->otherpath()), wxT(""), wxT("*.*"), + towxstring(UI_get_project_otherpath(inst)), wxT(""), wxT("*.*"), wxFD_SAVE); auto p = inst.project->get(); if(p) diff --git a/src/platform/wxwidgets/editor-hexedit.cpp b/src/platform/wxwidgets/editor-hexedit.cpp index 67f1584d..0ab5f576 100644 --- a/src/platform/wxwidgets/editor-hexedit.cpp +++ b/src/platform/wxwidgets/editor-hexedit.cpp @@ -5,6 +5,7 @@ #include "core/instance-map.hpp" #include "core/project.hpp" #include "core/memorymanip.hpp" +#include "core/ui-services.hpp" #include "library/memorysearch.hpp" #include "library/hex.hpp" @@ -368,7 +369,7 @@ public: { try { std::string filename = choose_file_load(this, "Load bookmarks from file", - inst.project->otherpath(), filetype_hexbookmarks); + UI_get_project_otherpath(inst), filetype_hexbookmarks); auto _in = zip::readrel(filename, ""); std::string in(_in.begin(), _in.end()); JSON::node root(in); @@ -415,7 +416,7 @@ public: std::string doc = root.serialize(); try { std::string filename = choose_file_save(this, "Save bookmarks to file", - inst.project->otherpath(), filetype_hexbookmarks); + UI_get_project_otherpath(inst), filetype_hexbookmarks); std::ofstream out(filename.c_str()); out << doc << std::endl; out.close(); diff --git a/src/platform/wxwidgets/editor-macro.cpp b/src/platform/wxwidgets/editor-macro.cpp index 78304560..52a56baa 100644 --- a/src/platform/wxwidgets/editor-macro.cpp +++ b/src/platform/wxwidgets/editor-macro.cpp @@ -5,6 +5,7 @@ #include "core/mainloop.hpp" #include "core/moviedata.hpp" #include "core/project.hpp" +#include "core/ui-services.hpp" #include "library/zip.hpp" #include "library/minmax.hpp" #include "library/json.hpp" @@ -384,7 +385,7 @@ void wxeditor_macro::on_load(wxCommandEvent& e) std::string mname = pick_text(this, "Name new macro", "Enter name for the new macro:", ""); if(mname == "") return; - std::string file = choose_file_load(this, "Load macro from", inst.project->otherpath(), + std::string file = choose_file_load(this, "Load macro from", UI_get_project_otherpath(inst), filetype_macro); std::vector contents = zip::readrel(file, ""); controller_macro m(JSON::node(std::string(contents.begin(), contents.end()))); @@ -411,7 +412,7 @@ void wxeditor_macro::on_save(wxCommandEvent& e) std::string mdata = _macro->serialize().serialize(); //Okay, have the macro data, now prompt for file and save. try { - std::string tfile = choose_file_save(this, "Save macro to", inst.project->otherpath(), + std::string tfile = choose_file_save(this, "Save macro to", UI_get_project_otherpath(inst), filetype_macro); std::ofstream f(tfile); f << mdata; diff --git a/src/platform/wxwidgets/editor-memorywatch.cpp b/src/platform/wxwidgets/editor-memorywatch.cpp index e3c1cfb8..f7e8f2e0 100644 --- a/src/platform/wxwidgets/editor-memorywatch.cpp +++ b/src/platform/wxwidgets/editor-memorywatch.cpp @@ -2,6 +2,7 @@ #include "core/moviedata.hpp" #include "core/memorywatch.hpp" #include "core/memorymanip.hpp" +#include "core/ui-services.hpp" #include "library/memoryspace.hpp" #include "core/project.hpp" @@ -444,7 +445,7 @@ void wxeditor_memorywatch::on_position_change(wxCommandEvent& e) void wxeditor_memorywatch::on_fontsel(wxCommandEvent& e) { try { - std::string filename = choose_file_load(this, "Choose font file", inst.project->otherpath(), + std::string filename = choose_file_load(this, "Choose font file", UI_get_project_otherpath(inst), filetype_font); font->SetValue(towxstring(filename)); } catch(canceled_exception& e) { diff --git a/src/platform/wxwidgets/editor-movie.cpp b/src/platform/wxwidgets/editor-movie.cpp index d50a2755..2280204b 100644 --- a/src/platform/wxwidgets/editor-movie.cpp +++ b/src/platform/wxwidgets/editor-movie.cpp @@ -4,6 +4,7 @@ #include "core/moviedata.hpp" #include "core/dispatch.hpp" #include "core/window.hpp" +#include "core/ui-services.hpp" #include "interface/controller.hpp" #include "core/mainloop.hpp" @@ -1674,7 +1675,7 @@ void wxeditor_movie::_moviepanel::on_popup_menu(wxCommandEvent& e) std::string filename; std::string branch; std::string dbranch; - auto g = choose_file_load(this, "Choose file to import", inst.project->moviepath(), + auto g = choose_file_load(this, "Choose file to import", UI_get_project_moviepath(inst), exp_imp_type()); filename = g.first; mode = g.second; @@ -1715,7 +1716,7 @@ void wxeditor_movie::_moviepanel::on_popup_menu(wxCommandEvent& e) try { int mode; std::string file; - auto g = choose_file_save(this, "Choose file to export", inst.project->moviepath(), + auto g = choose_file_save(this, "Choose file to export", UI_get_project_moviepath(inst), exp_imp_type()); file = g.first; mode = g.second; diff --git a/src/platform/wxwidgets/editor-voicesub.cpp b/src/platform/wxwidgets/editor-voicesub.cpp index d924596b..67837020 100644 --- a/src/platform/wxwidgets/editor-voicesub.cpp +++ b/src/platform/wxwidgets/editor-voicesub.cpp @@ -2,6 +2,7 @@ #include "core/instance.hpp" #include "core/inthread.hpp" #include "core/project.hpp" +#include "core/ui-services.hpp" #include "library/string.hpp" #include "platform/wxwidgets/platform.hpp" @@ -139,10 +140,12 @@ wxeditor_voicesub::wxeditor_voicesub(wxWindow* parent, emulator_instance& _inst) top_s->SetSizeHints(this); Fit(); - vstreamchange.set(inst.dispatch->voice_stream_change, [this]() { runuifun([this]() -> void { - this->refresh(); }); }); - corechange.set(inst.dispatch->core_change, [this]() { runuifun([this]() -> void { - this->refresh(); }); }); + vstreamchange.set(inst.dispatch->voice_stream_change, [this]() { + runuifun([this]() -> void { this->refresh(); }); + }); + corechange.set(inst.dispatch->core_change, [this]() { + runuifun([this]() -> void { this->refresh(); }); + }); refresh(); } @@ -217,7 +220,7 @@ void wxeditor_voicesub::on_export(wxCommandEvent& e) if(id == NOTHING) return; try { - auto filename = choose_file_save(this, "Select file to epxort", inst.project->otherpath(), + auto filename = choose_file_save(this, "Select file to epxort", UI_get_project_otherpath(inst), filetype_opus_sox); inst.commentary->export_stream(id, filename.first, filename.second); } catch(canceled_exception& e) { @@ -231,7 +234,7 @@ void wxeditor_voicesub::on_export_s(wxCommandEvent& e) try { std::string filename; filename = choose_file_save(this, "Select file to export superstream", - inst.project->otherpath(), filetype_sox); + UI_get_project_otherpath(inst), filetype_sox); inst.commentary->export_superstream(filename); } catch(canceled_exception& e) { } catch(std::exception& e) { @@ -245,7 +248,7 @@ void wxeditor_voicesub::on_import(wxCommandEvent& e) uint64_t ts; ts = inst.commentary->parse_timebase(pick_text(this, "Enter timebase", "Enter position for newly imported stream")); - auto filename = choose_file_save(this, "Select file to import", inst.project->otherpath(), + auto filename = choose_file_save(this, "Select file to import", UI_get_project_otherpath(inst), filetype_opus_sox); inst.commentary->import_stream(ts, filename.first, filename.second); } catch(canceled_exception& e) { diff --git a/src/platform/wxwidgets/mainwindow.cpp b/src/platform/wxwidgets/mainwindow.cpp index fd062edf..ad091f65 100644 --- a/src/platform/wxwidgets/mainwindow.cpp +++ b/src/platform/wxwidgets/mainwindow.cpp @@ -24,6 +24,7 @@ #include "core/framerate.hpp" #include "core/instance.hpp" #include "core/keymapper.hpp" +#include "core/ui-services.hpp" #include "interface/romtype.hpp" #include "core/loadlib.hpp" #include "lua/lua.hpp" @@ -1474,13 +1475,13 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e) inst.iqueue->queue("cancel-saves"); return; case wxID_LOAD_MOVIE: - filename = choose_file_load(this, "Load Movie", inst.project->moviepath(), + filename = choose_file_load(this, "Load Movie", UI_get_project_moviepath(inst), filetype_movie).second; recent_movies->add(filename); inst.iqueue->queue("load-movie " + filename); return; case wxID_LOAD_STATE: - filename2 = choose_file_load(this, "Load State", inst.project->moviepath(), + filename2 = choose_file_load(this, "Load State", UI_get_project_moviepath(inst), filetype_savestate); recent_movies->add(filename2.second); inst.iqueue->queue("load" + filename2.first + " " + filename2.second); @@ -1489,31 +1490,31 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e) inst.iqueue->queue("rewind-movie"); return; case wxID_SAVE_MOVIE: - filename2 = choose_file_save(this, "Save Movie", inst.project->moviepath(), filetype_movie, + filename2 = choose_file_save(this, "Save Movie", UI_get_project_moviepath(inst), filetype_movie, project_prefixname(inst, "lsmv")); recent_movies->add(filename2.second); inst.iqueue->queue("save-movie" + filename2.first + " " + filename2.second); return; case wxID_SAVE_SUBTITLES: inst.iqueue->queue("save-subtitle " + choose_file_save(this, "Save subtitles", - inst.project->moviepath(), filetype_sub, project_prefixname(inst, "sub"))); + UI_get_project_moviepath(inst), filetype_sub, project_prefixname(inst, "sub"))); return; case wxID_SAVE_STATE: - filename2 = choose_file_save(this, "Save State", inst.project->moviepath(), + filename2 = choose_file_save(this, "Save State", UI_get_project_moviepath(inst), filetype_savestate); recent_movies->add(filename2.second); inst.iqueue->queue("save-state" + filename2.first + " " + filename2.second); return; case wxID_SAVE_SCREENSHOT: inst.iqueue->queue("take-screenshot " + choose_file_save(this, "Save Screenshot", - inst.project->moviepath(), filetype_png, get_default_screenshot_name(inst))); + UI_get_project_moviepath(inst), filetype_png, get_default_screenshot_name(inst))); return; case wxID_RUN_SCRIPT: inst.iqueue->queue("run-script " + pick_file_member(this, "Select Script", - inst.project->otherpath())); + UI_get_project_otherpath(inst))); return; case wxID_RUN_LUA: { - std::string f = choose_file_load(this, "Select Lua Script", inst.project->otherpath(), + std::string f = choose_file_load(this, "Select Lua Script", UI_get_project_otherpath(inst), filetype_lua_script); inst.iqueue->queue("run-lua " + f); recent_scripts->add(f); @@ -1563,7 +1564,7 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e) std::set old_watches; inst.iqueue->run([&old_watches]() { old_watches = CORE().mwatch->enumerate(); }); std::string filename = choose_file_save(this, "Save watches to file", - inst.project->otherpath(), filetype_watch); + UI_get_project_otherpath(inst), filetype_watch); std::ofstream out(filename.c_str()); for(auto i : old_watches) { std::string val; @@ -1586,7 +1587,7 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e) inst.iqueue->run([&old_watches]() { old_watches = CORE().mwatch->enumerate(); }); std::map new_watches; std::string filename = choose_file_load(this, "Choose memory watch file", - inst.project->otherpath(), filetype_watch); + UI_get_project_otherpath(inst), filetype_watch); try { std::istream& in = zip::openrel(filename, ""); while(in) { @@ -1719,7 +1720,7 @@ void wxwin_mainwindow::handle_menu_click_cancelable(wxCommandEvent& e) case wxID_LOAD_LIBRARY: { std::string name = std::string("load ") + loadlib::library::name(); with_loaded_library(*new loadlib::module(loadlib::library(choose_file_load(this, name, - inst.project->otherpath(), single_type(loadlib::library::extension(), + UI_get_project_otherpath(inst), single_type(loadlib::library::extension(), loadlib::library::name()))))); handle_post_loadlibrary(); break; diff --git a/src/platform/wxwidgets/memorysearch.cpp b/src/platform/wxwidgets/memorysearch.cpp index 55093310..dfa378e5 100644 --- a/src/platform/wxwidgets/memorysearch.cpp +++ b/src/platform/wxwidgets/memorysearch.cpp @@ -4,6 +4,7 @@ #include "core/memorymanip.hpp" #include "core/memorywatch.hpp" #include "core/project.hpp" +#include "core/ui-services.hpp" #include "library/hex.hpp" #include "library/string.hpp" #include "library/memorysearch.hpp" @@ -824,7 +825,7 @@ void wxwindow_memorysearch::dump_candidates_text() { try { std::string filename = choose_file_save(this, "Dump memory search", - inst.project->otherpath(), filetype_textfile); + UI_get_project_otherpath(inst), filetype_textfile); std::ofstream out(filename); auto ms = msearch; inst.iqueue->run([ms, this, &out]() { @@ -853,7 +854,7 @@ void wxwindow_memorysearch::handle_save(memory_search::savestate_type type) std::vector state; msearch->savestate(state, type); std::string filename = choose_file_save(this, "Save memory search", - inst.project->otherpath(), filetype_memorysearch); + UI_get_project_otherpath(inst), filetype_memorysearch); std::ofstream out(filename, std::ios::binary); out.write(&state[0], state.size()); if(!out) @@ -869,7 +870,7 @@ void wxwindow_memorysearch::handle_load() { try { std::string filename = choose_file_load(this, "Load memory search", - inst.project->otherpath(), filetype_memorysearch); + UI_get_project_otherpath(inst), filetype_memorysearch); std::vector state = zip::readrel(filename, ""); push_undo(); msearch->loadstate(state); diff --git a/src/platform/wxwidgets/messages.cpp b/src/platform/wxwidgets/messages.cpp index 28e4e92f..9507b858 100644 --- a/src/platform/wxwidgets/messages.cpp +++ b/src/platform/wxwidgets/messages.cpp @@ -7,6 +7,7 @@ #include "core/instance.hpp" #include "core/window.hpp" #include "core/project.hpp" +#include "core/ui-services.hpp" #define MAXMESSAGES 20 #define PANELWIDTH 48 @@ -104,7 +105,7 @@ void wxwin_messages::panel::on_menu(wxCommandEvent& e) case wxID_SAVE: try { std::string filename = choose_file_save(this, "Save messages to", - inst.project->otherpath(), filetype_textfile); + UI_get_project_otherpath(inst), filetype_textfile); std::ofstream s(filename, std::ios::app); if(!s) throw std::runtime_error("Error opening output file"); if(lines == 1) str += "\n"; diff --git a/src/platform/wxwidgets/tracelogger.cpp b/src/platform/wxwidgets/tracelogger.cpp index ab588c85..ae5baf77 100644 --- a/src/platform/wxwidgets/tracelogger.cpp +++ b/src/platform/wxwidgets/tracelogger.cpp @@ -8,6 +8,7 @@ #include "core/mainloop.hpp" #include "core/memorymanip.hpp" #include "core/project.hpp" +#include "core/ui-services.hpp" #include "interface/disassembler.hpp" #include "library/minmax.hpp" #include "library/hex.hpp" @@ -882,7 +883,7 @@ namespace } else if(e.GetId() == wxID_SAVE) { try { std::string filename = choose_file_save(this, "Save tracelog to", - inst.project->otherpath(), filetype_trace); + UI_get_project_otherpath(inst), filetype_trace); std::ofstream s(filename, std::ios::app); if(!s) throw std::runtime_error("Error opening output file"); for(auto& i : panel->rows) @@ -1006,7 +1007,7 @@ namespace case wxID_SAVE: try { std::string filename = choose_file_save(this, "Save tracelog fragment to", - inst.project->otherpath(), filetype_trace); + UI_get_project_otherpath(inst), filetype_trace); std::ofstream s(filename, std::ios::app); if(!s) throw std::runtime_error("Error opening output file"); if(lines == 1) str += "\n"; @@ -1045,7 +1046,7 @@ namespace back: try { std::string filename = choose_file_save(this, "Save tracelog to", - inst.project->otherpath(), filetype_trace); + UI_get_project_otherpath(inst), filetype_trace); std::ofstream s(filename, std::ios::app); if(!s) throw std::runtime_error("Error opening output file"); for(auto& i : panel->rows) @@ -1306,7 +1307,7 @@ back: } else if(e.GetId() == wxID_SAVE) { try { std::string filename = choose_file_save(this, "Save disassembly to", - inst.project->otherpath(), filetype_disassembly); + UI_get_project_otherpath(inst), filetype_disassembly); std::ofstream s(filename, std::ios::app); if(!s) throw std::runtime_error("Error opening output file"); for(auto& i : panel->rows) @@ -1472,7 +1473,7 @@ back: case wxID_SAVE: try { std::string filename = choose_file_save(this, "Save disassembly fragment to", - inst.project->otherpath(), filetype_disassembly); + UI_get_project_otherpath(inst), filetype_disassembly); std::ofstream s(filename, std::ios::app); if(!s) throw std::runtime_error("Error opening output file"); if(lines == 1) str += "\n"; @@ -1704,7 +1705,7 @@ back: back: try { std::string filename = choose_file_save(this, "Save disassembly to", - inst.project->otherpath(), filetype_disassembly); + UI_get_project_otherpath(inst), filetype_disassembly); std::ofstream s(filename, std::ios::app); if(!s) throw std::runtime_error("Error opening output file"); for(auto& i : panel->rows) diff --git a/src/platform/wxwidgets/tracelogmenu.cpp b/src/platform/wxwidgets/tracelogmenu.cpp index 449d9627..09e17d93 100644 --- a/src/platform/wxwidgets/tracelogmenu.cpp +++ b/src/platform/wxwidgets/tracelogmenu.cpp @@ -7,6 +7,7 @@ #include "core/project.hpp" #include "core/moviedata.hpp" #include "core/rom.hpp" +#include "core/ui-services.hpp" tracelog_menu::tracelog_menu(wxWindow* win, emulator_instance& _inst, int wxid_low, int wxid_high) @@ -39,7 +40,7 @@ void tracelog_menu::on_select(wxCommandEvent& e) if(ch) { try { std::string filename = choose_file_save(pwin, "Save " + cpunames[rid] + " Trace", - inst.project->moviepath(), filetype_trace, ""); + UI_get_project_moviepath(inst), filetype_trace, ""); inst.dbg->tracelog(rid, filename); } catch(canceled_exception& e) { }