Load script paths from dfhack-config/script-paths.txt

develop
lethosor 2016-03-27 15:56:23 -04:00
parent 2935d8d6be
commit b115fdc73f
1 changed files with 37 additions and 0 deletions

@ -511,6 +511,41 @@ string Core::findScript(string name)
return ""; return "";
} }
bool loadScriptPaths(color_ostream &out, bool silent = false)
{
using namespace std;
string filename("dfhack-config/script-paths.txt");
ifstream file(filename);
if (!file)
{
if (!silent)
out.printerr("Could not load %s\n", filename.c_str());
return false;
}
string raw;
int line = 0;
while (getline(file, raw))
{
++line;
istringstream ss(raw);
char ch;
ss >> skipws;
if (!(ss >> ch) || ch == '#')
continue;
ss >> ws; // discard whitespace
string path;
getline(ss, path);
if (ch == '+' || ch == '-')
{
if (!Core::getInstance().addScriptPath(path, ch == '+') && !silent)
out.printerr("%s:%i: Failed to add path: %s\n", filename.c_str(), line, path.c_str());
}
else if (!silent)
out.printerr("%s:%i: Illegal character: %c\n", filename.c_str(), line, ch);
}
return true;
}
static std::map<std::string, state_change_event> state_change_event_map; static std::map<std::string, state_change_event> state_change_event_map;
static void sc_event_map_init() { static void sc_event_map_init() {
if (!state_change_event_map.size()) if (!state_change_event_map.size())
@ -1505,6 +1540,8 @@ bool Core::Init()
} }
} }
loadScriptPaths(con);
// initialize common lua context // initialize common lua context
if (!Lua::Core::Init(con)) if (!Lua::Core::Init(con))
{ {