allow subdirectories in Lua-specified paths separated by ":"
This commit is contained in:
parent
66b0bd3da5
commit
2edea049bd
39
Engine.cc
39
Engine.cc
@ -65,6 +65,23 @@ static void normalize(dVector3 vec)
|
||||
}
|
||||
}
|
||||
|
||||
static vector<string> split(const string & str, char delim)
|
||||
{
|
||||
vector<string> ret;
|
||||
ssize_t begin = 0, pos;
|
||||
int len = str.length();
|
||||
while ((pos = str.find(delim)) != string::npos && begin < len)
|
||||
{
|
||||
ret.push_back(string(str, begin, pos - begin));
|
||||
begin = pos + 1;
|
||||
}
|
||||
if (begin < len)
|
||||
{
|
||||
ret.push_back(string(str, begin));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#define DEBUG_GL_ERROR
|
||||
#ifdef DEBUG_GL_ERROR
|
||||
#define checkGLError() checkGLErrorLine(__FUNCTION__, __LINE__)
|
||||
@ -222,6 +239,28 @@ void Engine::checkForAllHandlerFunctions()
|
||||
checkForFunction("mouse_motion_event", mouse_motion);
|
||||
}
|
||||
|
||||
bool Engine::validatePath(string & path)
|
||||
{
|
||||
if (path.find_first_not_of(FILENAME_SAFE_CHARS) != string::npos)
|
||||
return false;
|
||||
if (path[0] == ':')
|
||||
return false;
|
||||
vector<string> parts = split(path, ':');
|
||||
path = "";
|
||||
bool multiple = false;
|
||||
for (int i = 0, sz = parts.size(); i < sz; i++)
|
||||
{
|
||||
if (parts[i].find_first_not_of(".") != string::npos)
|
||||
{
|
||||
if (multiple)
|
||||
path += "/";
|
||||
path += parts[i];
|
||||
multiple = true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Engine::reportErrors(int status)
|
||||
{
|
||||
if (status != 0)
|
||||
|
1
Engine.h
1
Engine.h
@ -274,6 +274,7 @@ class Engine
|
||||
m_av.setCursorVisible(
|
||||
m_engine_cursor_visible || m_script_cursor_visible);
|
||||
}
|
||||
bool validatePath(std::string & path);
|
||||
|
||||
AV & m_av;
|
||||
bool m_engine_cursor_visible;
|
||||
|
Loading…
x
Reference in New Issue
Block a user