Clean up error reporting on plugin load failure

This commit is contained in:
Ilari Liusvaara 2013-12-29 15:46:01 +02:00
parent c6d744b867
commit e677ebee61
3 changed files with 26 additions and 5 deletions

View file

@ -4,7 +4,7 @@
#include "library/loadlib.hpp"
void handle_post_loadlibrary();
void autoload_libraries(void(*on_error)(const std::string& err) = NULL);
void autoload_libraries(void(*on_error)(const std::string& libname, const std::string& err) = NULL);
void with_loaded_library(const loadlib::module& l);
#endif

View file

@ -10,6 +10,25 @@
#include <sstream>
#include <dirent.h>
namespace
{
std::string get_name(std::string path)
{
#if defined(_WIN32) || defined(_WIN64)
const char* sep = "\\/";
#else
const char* sep = "/";
#endif
size_t p = path.find_last_of(sep);
std::string name;
if(p == std::string::npos)
name = path;
else
name = path.substr(p + 1);
return name;
}
}
void handle_post_loadlibrary()
{
if(new_core_flag) {
@ -29,7 +48,7 @@ void with_loaded_library(const loadlib::module& l)
}
}
void autoload_libraries(void(*on_error)(const std::string& err))
void autoload_libraries(void(*on_error)(const std::string& libname, const std::string& err))
{
try {
std::string extension = loadlib::library::extension();
@ -46,8 +65,9 @@ void autoload_libraries(void(*on_error)(const std::string& err))
with_loaded_library(*new loadlib::module(loadlib::library(i)));
} catch(std::exception& e) {
std::string x = "Can't load '" + i + "': " + e.what();
if(on_error)
on_error(x);
on_error(get_name(i), e.what());
messages << x << std::endl;
}
}

View file

@ -427,8 +427,9 @@ bool lsnes_app::OnInit()
controls.set_ports(ports);
std::string cfgpath = get_config_path();
autoload_libraries([](const std::string& error) {
show_message_ok(NULL, "Error loading plugin", error, wxICON_EXCLAMATION);
autoload_libraries([](const std::string& libname, const std::string& error) {
show_message_ok(NULL, "Error loading plugin " + libname, "Error loading '" + libname + "'\n\n" +
error, wxICON_EXCLAMATION);
});
messages << "Saving per-user data to: " << get_config_path() << std::endl;
messages << "--- Loading configuration --- " << std::endl;