Library: look for cfg files in more paths, include exepath even if CFGDIR is used.

This commit is contained in:
Daniel Marjamäki 2016-08-01 12:58:33 +02:00
parent 15c1942a64
commit 095b2f73f7
1 changed files with 14 additions and 7 deletions

View File

@ -74,21 +74,28 @@ Library::Error Library::load(const char exename[], const char path[])
absolute_path = Path::getAbsoluteFilePath(fullfilename); absolute_path = Path::getAbsoluteFilePath(fullfilename);
} }
if (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND) { std::list<std::string> cfgfolders;
// Try to locate the library configuration in the installation folder..
#ifdef CFGDIR #ifdef CFGDIR
const std::string cfgfolder(CFGDIR); cfgfolders.push_back(CFGDIR);
#else
if (!exename)
return Error(FILE_NOT_FOUND);
const std::string cfgfolder(Path::fromNativeSeparators(Path::getPathFromFilename(exename)) + "cfg");
#endif #endif
if (exename) {
const std::string exepath(Path::fromNativeSeparators(Path::getPathFromFilename(exename)));
cfgfolders.push_back(exepath + "cfg");
cfgfolders.push_back(exepath);
}
while (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND && !cfgfolders.empty()) {
const std::string cfgfolder(cfgfolders.front());
cfgfolders.pop_front();
const char *sep = (!cfgfolder.empty() && cfgfolder[cfgfolder.size()-1U]=='/' ? "" : "/"); const char *sep = (!cfgfolder.empty() && cfgfolder[cfgfolder.size()-1U]=='/' ? "" : "/");
const std::string filename(cfgfolder + sep + fullfilename); const std::string filename(cfgfolder + sep + fullfilename);
error = doc.LoadFile(filename.c_str()); error = doc.LoadFile(filename.c_str());
if (error != tinyxml2::XML_ERROR_FILE_NOT_FOUND) if (error != tinyxml2::XML_ERROR_FILE_NOT_FOUND)
absolute_path = Path::getAbsoluteFilePath(filename); absolute_path = Path::getAbsoluteFilePath(filename);
} }
if (error == tinyxml2::XML_ERROR_FILE_NOT_FOUND)
return Error(FILE_NOT_FOUND);
} else } else
absolute_path = Path::getAbsoluteFilePath(path); absolute_path = Path::getAbsoluteFilePath(path);