mirror of
https://github.com/edubart/otclient.git
synced 2025-10-19 05:53:26 +02:00
reorganize some stuff
This commit is contained in:
@@ -50,7 +50,7 @@ void Module::discover(const OTMLNodePtr& moduleNode)
|
||||
if(OTMLNodePtr node = moduleNode->get("onLoad")) {
|
||||
g_lua.loadFunction(node->value(), "@" + node->source() + "[" + node->tag() + "]");
|
||||
g_lua.useValue();
|
||||
m_loadCallback = g_lua.polymorphicPop<BooleanCallback>();
|
||||
m_loadCallback = g_lua.polymorphicPop<SimpleCallback>();
|
||||
}
|
||||
|
||||
// set onUnload callback
|
||||
@@ -79,10 +79,8 @@ bool Module::load()
|
||||
}
|
||||
}
|
||||
|
||||
if(m_loadCallback && !m_loadCallback()) {
|
||||
logError("Unable to load module '", m_name, "' because its onLoad event returned false");
|
||||
return false;
|
||||
}
|
||||
if(m_loadCallback)
|
||||
m_loadCallback();
|
||||
|
||||
logInfo("Loaded module '", m_name, "'");
|
||||
m_loaded = true;
|
||||
|
@@ -55,7 +55,7 @@ private:
|
||||
std::string m_author;
|
||||
std::string m_website;
|
||||
std::string m_version;
|
||||
BooleanCallback m_loadCallback;
|
||||
SimpleCallback m_loadCallback;
|
||||
SimpleCallback m_unloadCallback;
|
||||
std::list<std::string> m_dependencies;
|
||||
};
|
||||
|
@@ -67,7 +67,7 @@ bool ResourceManager::addToSearchPath(const std::string& path, bool insertInFron
|
||||
|
||||
void ResourceManager::searchAndAddPackages(const std::string& packagesDir, const std::string& packageExt, bool append)
|
||||
{
|
||||
auto files = listDirectoryFiles(resolvePath(packagesDir));
|
||||
auto files = listDirectoryFiles(checkPath(packagesDir));
|
||||
for(const std::string& file : files) {
|
||||
if(boost::ends_with(file, packageExt))
|
||||
addToSearchPath(packagesDir + "/" + file, !append);
|
||||
@@ -76,17 +76,17 @@ void ResourceManager::searchAndAddPackages(const std::string& packagesDir, const
|
||||
|
||||
bool ResourceManager::fileExists(const std::string& fileName)
|
||||
{
|
||||
return (PHYSFS_exists(resolvePath(fileName).c_str()) && !PHYSFS_isDirectory(resolvePath(fileName).c_str()));
|
||||
return (PHYSFS_exists(checkPath(fileName).c_str()) && !PHYSFS_isDirectory(checkPath(fileName).c_str()));
|
||||
}
|
||||
|
||||
bool ResourceManager::directoryExists(const std::string& directoryName)
|
||||
{
|
||||
return (PHYSFS_isDirectory(resolvePath(directoryName).c_str()));
|
||||
return (PHYSFS_isDirectory(checkPath(directoryName).c_str()));
|
||||
}
|
||||
|
||||
void ResourceManager::loadFile(const std::string& fileName, std::iostream& out)
|
||||
{
|
||||
std::string fullPath = resolvePath(fileName);
|
||||
std::string fullPath = checkPath(fileName);
|
||||
out.clear(std::ios::goodbit);
|
||||
PHYSFS_file* file = PHYSFS_openRead(fullPath.c_str());
|
||||
if(!file) {
|
||||
@@ -114,7 +114,7 @@ std::string ResourceManager::loadFile(const std::string& fileName)
|
||||
|
||||
bool ResourceManager::saveFile(const std::string& fileName, const uchar* data, uint size)
|
||||
{
|
||||
PHYSFS_file* file = PHYSFS_openWrite(resolvePath(fileName).c_str());
|
||||
PHYSFS_file* file = PHYSFS_openWrite(checkPath(fileName).c_str());
|
||||
if(!file)
|
||||
return false;
|
||||
|
||||
@@ -143,13 +143,13 @@ bool ResourceManager::saveFile(const std::string& fileName, const std::string& d
|
||||
|
||||
bool ResourceManager::deleteFile(const std::string& fileName)
|
||||
{
|
||||
return PHYSFS_delete(resolvePath(fileName).c_str()) != 0;
|
||||
return PHYSFS_delete(checkPath(fileName).c_str()) != 0;
|
||||
}
|
||||
|
||||
std::list<std::string> ResourceManager::listDirectoryFiles(const std::string& directoryPath)
|
||||
{
|
||||
std::list<std::string> files;
|
||||
auto rc = PHYSFS_enumerateFiles(resolvePath(directoryPath).c_str());
|
||||
auto rc = PHYSFS_enumerateFiles(checkPath(directoryPath).c_str());
|
||||
|
||||
for(int i = 0; rc[i] != NULL; i++)
|
||||
files.push_back(rc[i]);
|
||||
@@ -158,8 +158,9 @@ std::list<std::string> ResourceManager::listDirectoryFiles(const std::string& di
|
||||
return files;
|
||||
}
|
||||
|
||||
std::string ResourceManager::resolvePath(const std::string& path)
|
||||
std::string ResourceManager::checkPath(const std::string& path)
|
||||
{
|
||||
/*
|
||||
std::string fullPath;
|
||||
if(boost::starts_with(path, "/"))
|
||||
fullPath = path;
|
||||
@@ -169,7 +170,10 @@ std::string ResourceManager::resolvePath(const std::string& path)
|
||||
fullPath += scriptPath + "/";
|
||||
fullPath += path;
|
||||
}
|
||||
return fullPath;
|
||||
*/
|
||||
if(!(boost::starts_with(path, "/")))
|
||||
logTraceWarning("the following file path is not fully resolved: ", path);
|
||||
return path;
|
||||
}
|
||||
|
||||
std::string ResourceManager::getBaseDir()
|
||||
|
@@ -50,7 +50,7 @@ public:
|
||||
|
||||
std::list<std::string> listDirectoryFiles(const std::string& directoryPath = "");
|
||||
|
||||
std::string resolvePath(const std::string& path);
|
||||
std::string checkPath(const std::string& path);
|
||||
std::string getBaseDir();
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user