Support autoloading stuff on startup

This commit is contained in:
Ilari Liusvaara 2013-01-07 21:36:17 +02:00
parent bea1f01c35
commit 1e74f795f6
4 changed files with 37 additions and 0 deletions

View file

@ -4,5 +4,6 @@
#include "library/loadlib.hpp"
void handle_post_loadlibrary();
void autoload_libraries();
#endif

View file

@ -2,8 +2,29 @@
#include "interface/romtype.hpp"
#include "core/command.hpp"
#include "core/dispatch.hpp"
#include "core/misc.hpp"
#include <stdexcept>
#include <sstream>
#include <dirent.h>
namespace
{
std::set<std::string> enumerate_directory(const std::string& dir)
{
std::set<std::string> x;
DIR* d;
dirent* d2;
d = opendir(dir.c_str());
if(!d) {
messages << "Can't read directory '" << dir << "'" << std::endl;
return x;
}
while(d2 = readdir(d))
x.insert(dir + "/" + d2->d_name);
closedir(d);
return x;
}
}
void handle_post_loadlibrary()
{
@ -12,3 +33,15 @@ void handle_post_loadlibrary()
information_dispatch::do_new_core();
}
}
void autoload_libraries()
{
auto libs = enumerate_directory(get_config_path() + "/autoload");
for(auto i : libs)
try {
new loaded_library(i);
messages << "Autoloaded '" << i << "'" << std::endl;
} catch(...) {
}
handle_post_loadlibrary();
}

View file

@ -7,6 +7,7 @@
#include "core/controller.hpp"
#include "core/dispatch.hpp"
#include "core/framerate.hpp"
#include "core/loadlib.hpp"
#include "lua/lua.hpp"
#include "core/mainloop.hpp"
#include "core/misc.hpp"
@ -451,6 +452,7 @@ bool lsnes_app::OnInit()
controls.set_ports(ports);
std::string cfgpath = get_config_path();
autoload_libraries();
messages << "Saving per-user data to: " << get_config_path() << std::endl;
messages << "--- Loading configuration --- " << std::endl;
lsnes_set.set_storage_mode(true);

View file

@ -243,6 +243,7 @@ int main(int argc, char** argv)
messages << std::endl;
std::string cfgpath = get_config_path();
autoload_libraries();
for(auto i : cmdline) {
regex_results r;