Change Encyclo button name and macros icon
[ryzomcore.git] / nel / src / pipeline / database_config.cpp
blob57e3b88d8053678ffe3776dc4007be4e2b47cf1a
1 // NeL - MMORPG Framework <https://wiki.ryzom.dev/>
2 // Copyright (C) 2015 Winch Gate Property Limited
3 //
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2016 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
6 //
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
20 // Author: Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
22 #include <nel/misc/types_nl.h>
23 #include "nel/pipeline/database_config.h"
25 #include <nel/misc/debug.h>
26 #include <nel/misc/path.h>
27 #include <nel/misc/config_file.h>
29 using namespace std;
30 using namespace NLMISC;
32 namespace NLPIPELINE {
34 TPathString CDatabaseConfig::s_RootPath;
35 NLMISC::CConfigFile *CDatabaseConfig::s_ConfigFile = NULL;
36 CDatabaseConfig CDatabaseConfig::s_Instance;
37 uint32 CDatabaseConfig::s_ConfigFileModification;
39 static std::set<TPathString> s_SearchPaths;
41 void CDatabaseConfig::cleanup()
43 delete CDatabaseConfig::s_ConfigFile;
44 CDatabaseConfig::s_ConfigFile = NULL;
47 CDatabaseConfig::~CDatabaseConfig()
49 cleanup();
52 bool CDatabaseConfig::init(const std::string &asset)
54 // release();
56 TPathString rootPath = NLMISC::CPath::standardizePath(asset, false);
57 TPathString configPath = rootPath + "/database.cfg";
58 while (!CFile::fileExists(configPath))
60 std::string::size_type sep = CFile::getLastSeparator(rootPath);
61 if (sep == string::npos)
62 return false;
64 rootPath = rootPath.substr(0, sep);
65 if (rootPath.empty())
66 return false;
68 configPath = rootPath + "/database.cfg";
71 rootPath += "/";
72 uint32 configFileModification = CFile::getFileModificationDate(configPath);
73 if (rootPath == s_RootPath && s_ConfigFileModification == configFileModification)
74 return true; // Do not reload
76 nldebug("Initializing database config '%s'", configPath.c_str());
77 release();
79 s_RootPath = rootPath;
80 s_ConfigFileModification = configFileModification;
82 s_ConfigFile = new CConfigFile();
83 s_ConfigFile->load(configPath);
84 return true;
87 void CDatabaseConfig::initTextureSearchDirectories()
89 searchDirectories("TextureSearchDirectories");
92 void CDatabaseConfig::searchDirectories(const char *var)
94 CConfigFile::CVar &paths = s_ConfigFile->getVar(var);
95 for (uint i = 0; i < paths.size(); i++)
97 TPathString path = paths.asString(i);
98 if (s_SearchPaths.find(path) == s_SearchPaths.end())
100 CPath::addSearchPath(s_RootPath + path);
101 s_SearchPaths.insert(path);
106 void CDatabaseConfig::release()
108 s_SearchPaths.clear();
109 CPath::clearMap();
110 cleanup();
113 } /* namespace NLPIPELINE */
115 /* end of file */