Use hints for default filename on ROM load request
This commit is contained in:
parent
83dcbee83a
commit
702a4b8c4b
9 changed files with 47 additions and 24 deletions
|
@ -201,4 +201,9 @@ std::vector<char> save_core_state(bool nochecksum = false) throw(std::bad_alloc)
|
|||
*/
|
||||
void load_core_state(const std::vector<char>& buf, bool nochecksum = false) throw(std::runtime_error);
|
||||
|
||||
/**
|
||||
* Does specified file exist?
|
||||
*/
|
||||
bool file_exists(const std::string& name);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -225,7 +225,7 @@ struct graphics_plugin
|
|||
/**
|
||||
* Request filename for ROM load.
|
||||
*/
|
||||
static std::string request_rom(core_type& coretype);
|
||||
static std::string request_rom(core_type& coretype, const std::string& hint);
|
||||
/**
|
||||
* Identification for graphics plugin.
|
||||
*/
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
void menu_check(int id, bool newstate);
|
||||
void menu_separator();
|
||||
void handle_menu_click(wxCommandEvent& e);
|
||||
void request_rom(std::string& filename, core_type& coretype);
|
||||
void request_rom(std::string& filename, core_type& coretype, const std::string& hint);
|
||||
recent_menu* recent_roms;
|
||||
recent_menu* recent_movies;
|
||||
private:
|
||||
|
|
|
@ -183,6 +183,15 @@ namespace
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::string getline(const std::vector<char>& v)
|
||||
{
|
||||
std::string t(v.begin(), v.end());
|
||||
size_t ptr = t.find_first_of("\r\n");
|
||||
if(ptr < t.size())
|
||||
t = t.substr(0, ptr);
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
std::string translate_name_mprefix(std::string original, bool forio)
|
||||
|
@ -376,18 +385,20 @@ void do_load_beginning(bool reload) throw(std::bad_alloc, std::runtime_error)
|
|||
|
||||
void try_request_rom(const std::string& moviefile)
|
||||
{
|
||||
auto sysreg_content = read_file_relative(moviefile + "/gametype", "");
|
||||
std::string sysreg_name(sysreg_content.begin(), sysreg_content.end());
|
||||
size_t ptr = sysreg_name.find_first_of("\r\n");
|
||||
if(ptr < sysreg_name.size())
|
||||
sysreg_name = sysreg_name.substr(0, ptr);
|
||||
std::string sysreg_name = getline(read_file_relative(moviefile + "/gametype", ""));
|
||||
core_sysregion* sysreg;
|
||||
try {
|
||||
sysreg = &core_sysregion::lookup(sysreg_name);
|
||||
} catch(...) {
|
||||
throw std::runtime_error("The movie is for unsupported system type");
|
||||
}
|
||||
std::string rname = graphics_plugin::request_rom(sysreg->get_type());
|
||||
std::string hintfile = (sysreg->get_type().get_biosname() != "") ? "slota.hint" : "rom.hint";
|
||||
std::string hint;
|
||||
try {
|
||||
hint = getline(read_file_relative(moviefile + "/" + hintfile, ""));
|
||||
} catch(...) {
|
||||
}
|
||||
std::string rname = graphics_plugin::request_rom(sysreg->get_type(), hint);
|
||||
if(rname == "")
|
||||
throw std::runtime_error("Canceled loading ROM");
|
||||
loaded_rom newrom(rname);
|
||||
|
|
|
@ -29,20 +29,20 @@
|
|||
#include <boost/iostreams/filtering_stream.hpp>
|
||||
#include <boost/iostreams/device/back_inserter.hpp>
|
||||
|
||||
bool file_exists(const std::string& name)
|
||||
{
|
||||
try {
|
||||
delete &open_file_relative(name, "");
|
||||
return true;
|
||||
} catch(...) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
core_type* current_rom_type = NULL;
|
||||
core_region* current_region = NULL;
|
||||
|
||||
bool file_exists(const std::string& name)
|
||||
{
|
||||
try {
|
||||
delete &open_file_relative(name, "");
|
||||
return true;
|
||||
} catch(...) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
loaded_slot::loaded_slot() throw(std::bad_alloc)
|
||||
|
|
|
@ -49,7 +49,7 @@ void graphics_plugin::fatal_error() throw()
|
|||
std::cerr << "Exiting on fatal error." << std::endl;
|
||||
}
|
||||
|
||||
std::string graphics_plugin::request_rom(core_type& coretype)
|
||||
std::string graphics_plugin::request_rom(core_type& coretype, const std::string& hint)
|
||||
{
|
||||
throw std::runtime_error("Headless does not support ROM preloading");
|
||||
}
|
||||
|
|
|
@ -613,7 +613,7 @@ void graphics_plugin::fatal_error() throw()
|
|||
}
|
||||
}
|
||||
|
||||
std::string graphics_plugin::request_rom(core_type& coretype)
|
||||
std::string graphics_plugin::request_rom(core_type& coretype, const std::string& hint)
|
||||
{
|
||||
throw std::runtime_error("SDL version does not support ROM preloading");
|
||||
}
|
||||
|
|
|
@ -535,19 +535,20 @@ void graphics_plugin::fatal_error() throw()
|
|||
}
|
||||
}
|
||||
|
||||
std::string graphics_plugin::request_rom(core_type& coretype)
|
||||
std::string graphics_plugin::request_rom(core_type& coretype, const std::string& hint)
|
||||
{
|
||||
core_type* ctype = &coretype;
|
||||
std::string outname;
|
||||
std::string _hint = hint;
|
||||
mutex_class lock;
|
||||
cv_class cv;
|
||||
bool done = false;
|
||||
umutex_class h(lock);
|
||||
runuifun([ctype, &outname, &lock, &cv, &done]() -> void {
|
||||
runuifun([ctype, hint, &outname, &lock, &cv, &done]() -> void {
|
||||
if(done)
|
||||
return;
|
||||
try {
|
||||
main_window->request_rom(outname, *ctype);
|
||||
main_window->request_rom(outname, *ctype, hint);
|
||||
} catch(...) {
|
||||
}
|
||||
umutex_class h(lock);
|
||||
|
|
|
@ -1000,12 +1000,16 @@ void wxwin_mainwindow::notify_exit() throw()
|
|||
Destroy();
|
||||
}
|
||||
|
||||
void wxwin_mainwindow::request_rom(std::string& filename, core_type& coretype)
|
||||
void wxwin_mainwindow::request_rom(std::string& filename, core_type& coretype, const std::string& hint)
|
||||
{
|
||||
const std::list<std::string>& exts = coretype.get_extensions();
|
||||
std::string filter = coretype.get_hname() + " ROMs|";
|
||||
bool first = true;
|
||||
std::string defaultname = "";
|
||||
for(auto i : exts) {
|
||||
std::string hinted_file = hint + "." + i;
|
||||
if(file_exists(rom_path() + "/" + hinted_file))
|
||||
defaultname = hinted_file;
|
||||
if(!first)
|
||||
filter = filter + ";";
|
||||
first = false;
|
||||
|
@ -1014,6 +1018,8 @@ void wxwin_mainwindow::request_rom(std::string& filename, core_type& coretype)
|
|||
filter = filter + "|All files|*.*";
|
||||
wxFileDialog* fdiag = new wxFileDialog(this, wxT("Load ROM"), towxstring(rom_path()), wxT(""),
|
||||
towxstring(filter), wxFD_OPEN);
|
||||
if(defaultname != "")
|
||||
fdiag->SetFilename(defaultname);
|
||||
if(fdiag->ShowModal() != wxID_OK) {
|
||||
delete fdiag;
|
||||
return;
|
||||
|
|
Loading…
Add table
Reference in a new issue