From 66f7bd6debbb77fad48a3feda7317f1d0c4df5b1 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Wed, 18 Jan 2012 22:53:04 +0200 Subject: [PATCH] True movie slot support --- include/core/moviefile.hpp | 7 ++++++- include/plat-wxwidgets/window_romselect.hpp | 1 + src/core/moviedata.cpp | 12 ++++++++++-- src/core/moviefile.cpp | 19 +++++++++++++++++++ src/plat-sdl/main.cpp | 2 ++ src/plat-wxwidgets/romselect.cpp | 8 +++++++- 6 files changed, 45 insertions(+), 4 deletions(-) diff --git a/include/core/moviefile.hpp b/include/core/moviefile.hpp index ab9cfff0..e301ac72 100644 --- a/include/core/moviefile.hpp +++ b/include/core/moviefile.hpp @@ -160,7 +160,10 @@ struct moviefile * Movie starting RTC subsecond. */ int64_t movie_rtc_subsecond; - +/** + * Movie prefix. + */ + std::string prefix; /** * Get number of frames in movie. * @@ -177,4 +180,6 @@ struct moviefile uint64_t get_movie_length(uint64_t framebias = 0) throw(); }; +std::string sanitize_prefix(const std::string& in) throw(std::bad_alloc); + #endif diff --git a/include/plat-wxwidgets/window_romselect.hpp b/include/plat-wxwidgets/window_romselect.hpp index d7299eb4..31b5aeba 100644 --- a/include/plat-wxwidgets/window_romselect.hpp +++ b/include/plat-wxwidgets/window_romselect.hpp @@ -79,6 +79,7 @@ private: wxComboBox* controller1type; wxComboBox* controller2type; wxTextCtrl* projectname; + wxTextCtrl* prefix; wxTextCtrl* rtc_sec; wxTextCtrl* rtc_subsec; wxTextCtrl* authors; diff --git a/src/core/moviedata.cpp b/src/core/moviedata.cpp index 4a18bd1b..3cd65601 100644 --- a/src/core/moviedata.cpp +++ b/src/core/moviedata.cpp @@ -51,9 +51,9 @@ namespace class projectprefix_setting : public setting { - std::string prefix; - bool _set; public: + bool _set; + std::string prefix; projectprefix_setting() throw(std::bad_alloc) : setting("$project") { @@ -197,6 +197,8 @@ void do_save_state(const std::string& filename) throw(std::bad_alloc, lua_callback_pre_save(filename2, true); try { uint64_t origtime = get_utime(); + if(mprefix._set) + our_movie.prefix = sanitize_prefix(mprefix.prefix); our_movie.is_savestate = true; our_movie.sram = save_sram(); our_movie.savestate = save_core_state(); @@ -224,6 +226,8 @@ void do_save_movie(const std::string& filename) throw(std::bad_alloc, std::runti lua_callback_pre_save(filename2, false); try { uint64_t origtime = get_utime(); + if(mprefix._set) + our_movie.prefix = sanitize_prefix(static_cast(mprefix)); our_movie.is_savestate = false; our_movie.input = movb.get_movie().save(); our_movie.save(filename2, savecompression); @@ -352,6 +356,10 @@ void do_load_state(struct moviefile& _movie, int lmode) our_movie.is_savestate = false; our_movie.host_memory.clear(); } + if(our_movie.prefix != "") { + mprefix.prefix = our_movie.prefix; + mprefix._set = true; + } movb.get_movie() = newmovie; //Paint the screen. { diff --git a/src/core/moviefile.cpp b/src/core/moviefile.cpp index 79963fe4..f2c0a3d5 100644 --- a/src/core/moviefile.cpp +++ b/src/core/moviefile.cpp @@ -356,6 +356,8 @@ moviefile::moviefile(const std::string& movie) throw(std::bad_alloc, std::runtim read_linefile(r, "slotaxml.sha256", slotaxml_sha256, true); read_linefile(r, "slotb.sha256", slotb_sha256, true); read_linefile(r, "slotbxml.sha256", slotbxml_sha256, true); + read_linefile(r, "prefix", prefix, true); + prefix = sanitize_prefix(prefix); movie_rtc_second = DEFAULT_RTC_SECOND; movie_rtc_subsecond = DEFAULT_RTC_SUBSECOND; read_numeric_file(r, "starttime.second", movie_rtc_second, true); @@ -414,6 +416,7 @@ void moviefile::save(const std::string& movie, unsigned compression) throw(std:: write_linefile(w, "slotaxml.sha256", slotaxml_sha256, true); write_linefile(w, "slotb.sha256", slotb_sha256, true); write_linefile(w, "slotbxml.sha256", slotbxml_sha256, true); + write_linefile(w, "prefix", prefix, true); for(auto i : movie_sram) write_raw_file(w, "moviesram." + i.first, i.second); write_numeric_file(w, "starttime.second", movie_rtc_second); @@ -516,3 +519,19 @@ rom_type gametype_romtype(gametype_t type) return ROMTYPE_NONE; }; } + +std::string sanitize_prefix(const std::string& in) throw(std::bad_alloc) +{ + std::ostringstream s; + bool any = false; + for(size_t i = 0; i < in.length(); i++) { + char ch = in[i]; + if(ch < 33 || ch == '$' || ch == ':' || ch == '/' || ch == '\\') + continue; //Always disallowed. + if(ch == '.' && !any) + continue; //Sometimes disallowed. + any = true; + s << ch; + } + return s.str(); +} diff --git a/src/plat-sdl/main.cpp b/src/plat-sdl/main.cpp index d95f027d..e0b30cd8 100644 --- a/src/plat-sdl/main.cpp +++ b/src/plat-sdl/main.cpp @@ -46,6 +46,8 @@ struct moviefile generate_movie_template(std::vector cmdline, loade movie.slotb_sha256 = r.slotb.sha256; movie.slotbxml_sha256 = r.slotb_xml.sha256; movie.movie_sram = load_sram_commandline(cmdline); + if(o.length() >= 9 && o.substr(0, 9) == "--prefix=") + movie.prefix = sanitize_prefix(o.substr(9)); for(auto i = cmdline.begin(); i != cmdline.end(); i++) { std::string o = *i; if(o.length() >= 8 && o.substr(0, 8) == "--port1=") diff --git a/src/plat-wxwidgets/romselect.cpp b/src/plat-wxwidgets/romselect.cpp index bc6cba32..7d74b9c0 100644 --- a/src/plat-wxwidgets/romselect.cpp +++ b/src/plat-wxwidgets/romselect.cpp @@ -646,7 +646,7 @@ wxwin_project::wxwin_project(loaded_rom& rom) toplevel->Add(newp, 0, wxGROW); //Filename/Controllertypes/Gamename/initRTC/SRAMs. - wxFlexGridSizer* mainblock = new wxFlexGridSizer(5 + sram_set.size(), 2, 0, 0); + wxFlexGridSizer* mainblock = new wxFlexGridSizer(6 + sram_set.size(), 2, 0, 0); mainblock->Add(new wxStaticText(this, wxID_ANY, wxT("File to load:")), 0, wxGROW); wxFlexGridSizer* fileblock = new wxFlexGridSizer(1, 2, 0, 0); fileblock->Add(savefile = new wxTextCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(500, -1)), @@ -674,6 +674,9 @@ wxwin_project::wxwin_project(loaded_rom& rom) mainblock->Add(new wxStaticText(this, wxID_ANY, wxT("Game name:")), 0, wxGROW); mainblock->Add(projectname = new wxTextCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(400, -1)), 1, wxGROW); + mainblock->Add(new wxStaticText(this, wxID_ANY, wxT("Save prefix:")), 0, wxGROW); + mainblock->Add(prefix = new wxTextCtrl(this, wxID_ANY, wxT(""), wxDefaultPosition, wxSize(400, -1)), 1, + wxGROW); unsigned idx = 0; for(auto i : sram_set) { mainblock->Add(new wxStaticText(this, wxID_ANY, towxstring("SRAM " + i)), 0, wxGROW); @@ -736,6 +739,7 @@ void wxwin_project::on_file_select(wxCommandEvent& e) rtc_sec->Disable(); rtc_subsec->Disable(); projectname->Disable(); + prefix->Disable(); authors->Disable(); load->SetLabel(wxT("Load")); load_file = true; @@ -755,6 +759,7 @@ void wxwin_project::on_new_select(wxCommandEvent& e) rtc_sec->Enable(); rtc_subsec->Enable(); projectname->Enable(); + prefix->Enable(); authors->Enable(); load->SetLabel(wxT("Start")); on_filename_change(e); @@ -865,6 +870,7 @@ struct moviefile wxwin_project::make_movie() f.port2 = get_controller_type(tostdstring(controller2type->GetValue())); f.coreversion = bsnes_core_version; f.gamename = tostdstring(projectname->GetValue()); + f.prefix = sanitize_prefix(tostdstring(prefix->GetValue())); f.projectid = get_random_hexstring(40); f.rerecords = "0"; f.rom_sha256 = our_rom->rom.sha256; -- 2.11.4.GIT