2015-01-11 22:37:53 +01:00
|
|
|
/* Copyright (C) 2015 Wildfire Games.
|
2009-04-18 19:00:33 +02:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
*
|
|
|
|
* 0 A.D. is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2004-06-09 16:58:33 +02:00
|
|
|
#include "precompiled.h"
|
|
|
|
|
2011-04-29 21:10:34 +02:00
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
|
2004-06-09 15:53:32 +02:00
|
|
|
#include "CLogger.h"
|
2014-07-09 21:16:03 +02:00
|
|
|
#include "ConfigDB.h"
|
2007-12-20 21:21:45 +01:00
|
|
|
#include "Filesystem.h"
|
2014-07-09 21:16:03 +02:00
|
|
|
#include "ThreadUtil.h"
|
2011-04-29 21:10:34 +02:00
|
|
|
#include "lib/allocators/shared_ptr.h"
|
2004-06-09 15:53:32 +02:00
|
|
|
|
2014-11-17 02:03:59 +01:00
|
|
|
typedef std::map<CStr, CConfigValueSet> TConfigMap;
|
2004-06-09 15:53:32 +02:00
|
|
|
TConfigMap CConfigDB::m_Map[CFG_LAST];
|
2011-02-16 21:40:15 +01:00
|
|
|
VfsPath CConfigDB::m_ConfigFile[CFG_LAST];
|
2004-06-09 15:53:32 +02:00
|
|
|
|
2013-12-17 20:58:39 +01:00
|
|
|
static pthread_mutex_t cfgdb_mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
2004-07-04 17:36:48 +02:00
|
|
|
CConfigDB::CConfigDB()
|
2013-03-07 14:49:49 +01:00
|
|
|
{
|
2013-12-30 00:56:18 +01:00
|
|
|
// Recursive mutex needed for WriteFile
|
2013-12-17 20:58:39 +01:00
|
|
|
pthread_mutexattr_t attr;
|
|
|
|
int err;
|
|
|
|
err = pthread_mutexattr_init(&attr);
|
|
|
|
ENSURE(err == 0);
|
|
|
|
err = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
|
|
|
|
ENSURE(err == 0);
|
|
|
|
err = pthread_mutex_init(&cfgdb_mutex, &attr);
|
|
|
|
ENSURE(err == 0);
|
|
|
|
err = pthread_mutexattr_destroy(&attr);
|
|
|
|
ENSURE(err == 0);
|
2013-03-07 14:49:49 +01:00
|
|
|
}
|
|
|
|
|
2014-11-17 02:03:59 +01:00
|
|
|
#define CHECK_NS(rval)\
|
|
|
|
do {\
|
|
|
|
if (ns < 0 || ns >= CFG_LAST)\
|
|
|
|
{\
|
|
|
|
debug_warn(L"CConfigDB: Invalid ns value");\
|
|
|
|
return rval;\
|
|
|
|
}\
|
|
|
|
} while (false)
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
template<typename T> void Get(const CStr& value, T& ret)
|
|
|
|
{
|
|
|
|
std::stringstream ss(value);
|
|
|
|
ss >> ret;
|
|
|
|
}
|
|
|
|
template<> void Get<>(const CStr& value, bool& ret)
|
|
|
|
{
|
|
|
|
ret = value == "true";
|
|
|
|
}
|
|
|
|
template<> void Get<>(const CStr& value, std::string& ret)
|
|
|
|
{
|
|
|
|
ret = value;
|
|
|
|
}
|
|
|
|
std::string EscapeString(const CStr& str)
|
|
|
|
{
|
|
|
|
std::string ret;
|
|
|
|
for (size_t i = 0; i < str.length(); ++i)
|
|
|
|
{
|
|
|
|
if (str[i] == '\\')
|
|
|
|
ret += "\\\\";
|
|
|
|
else if (str[i] == '"')
|
|
|
|
ret += "\\\"";
|
|
|
|
else
|
|
|
|
ret += str[i];
|
2013-12-30 00:56:18 +01:00
|
|
|
}
|
2014-11-17 02:03:59 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
#define GETVAL(type)\
|
|
|
|
void CConfigDB::GetValue(EConfigNamespace ns, const CStr& name, type& value)\
|
|
|
|
{\
|
2015-01-11 22:37:53 +01:00
|
|
|
CHECK_NS(;);\
|
2014-11-17 02:03:59 +01:00
|
|
|
CScopeLock s(&cfgdb_mutex);\
|
|
|
|
TConfigMap::iterator it = m_Map[CFG_COMMAND].find(name);\
|
|
|
|
if (it != m_Map[CFG_COMMAND].end())\
|
|
|
|
{\
|
|
|
|
Get(it->second[0], value);\
|
|
|
|
return;\
|
|
|
|
}\
|
|
|
|
for (int search_ns = ns; search_ns >= 0; search_ns--)\
|
|
|
|
{\
|
|
|
|
it = m_Map[search_ns].find(name);\
|
|
|
|
if (it != m_Map[search_ns].end())\
|
|
|
|
{\
|
|
|
|
Get(it->second[0], value);\
|
|
|
|
return;\
|
|
|
|
}\
|
|
|
|
}\
|
|
|
|
}
|
|
|
|
GETVAL(bool)
|
|
|
|
GETVAL(int)
|
|
|
|
GETVAL(float)
|
|
|
|
GETVAL(double)
|
|
|
|
GETVAL(std::string)
|
2013-12-30 00:56:18 +01:00
|
|
|
#undef GETVAL
|
|
|
|
|
|
|
|
void CConfigDB::GetValues(EConfigNamespace ns, const CStr& name, CConfigValueSet& values)
|
2004-07-21 18:34:07 +02:00
|
|
|
{
|
2015-01-11 22:37:53 +01:00
|
|
|
CHECK_NS(;);
|
2004-10-23 16:39:28 +02:00
|
|
|
|
2014-07-09 21:16:03 +02:00
|
|
|
CScopeLock s(&cfgdb_mutex);
|
2010-11-17 00:00:52 +01:00
|
|
|
TConfigMap::iterator it = m_Map[CFG_COMMAND].find(name);
|
|
|
|
if (it != m_Map[CFG_COMMAND].end())
|
2013-12-30 00:56:18 +01:00
|
|
|
{
|
|
|
|
values = it->second;
|
|
|
|
return;
|
|
|
|
}
|
2004-10-23 16:39:28 +02:00
|
|
|
|
2010-11-17 00:00:52 +01:00
|
|
|
for (int search_ns = ns; search_ns >= 0; search_ns--)
|
2004-10-23 16:39:28 +02:00
|
|
|
{
|
2013-12-30 00:56:18 +01:00
|
|
|
it = m_Map[search_ns].find(name);
|
2004-10-23 16:39:28 +02:00
|
|
|
if (it != m_Map[search_ns].end())
|
2013-12-30 00:56:18 +01:00
|
|
|
{
|
|
|
|
values = it->second;
|
|
|
|
return;
|
|
|
|
}
|
2004-10-23 16:39:28 +02:00
|
|
|
}
|
2012-12-25 23:49:18 +01:00
|
|
|
}
|
2004-06-09 15:53:32 +02:00
|
|
|
|
2011-03-03 02:49:49 +01:00
|
|
|
EConfigNamespace CConfigDB::GetValueNamespace(EConfigNamespace ns, const CStr& name)
|
|
|
|
{
|
2014-11-17 02:03:59 +01:00
|
|
|
CHECK_NS(CFG_LAST);
|
2011-03-03 02:49:49 +01:00
|
|
|
|
2014-07-09 21:16:03 +02:00
|
|
|
CScopeLock s(&cfgdb_mutex);
|
2011-03-03 02:49:49 +01:00
|
|
|
TConfigMap::iterator it = m_Map[CFG_COMMAND].find(name);
|
|
|
|
if (it != m_Map[CFG_COMMAND].end())
|
|
|
|
return CFG_COMMAND;
|
|
|
|
|
|
|
|
for (int search_ns = ns; search_ns >= 0; search_ns--)
|
|
|
|
{
|
2013-12-30 00:56:18 +01:00
|
|
|
it = m_Map[search_ns].find(name);
|
2011-03-03 02:49:49 +01:00
|
|
|
if (it != m_Map[search_ns].end())
|
|
|
|
return (EConfigNamespace)search_ns;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CFG_LAST;
|
|
|
|
}
|
|
|
|
|
2012-04-17 15:14:34 +02:00
|
|
|
std::map<CStr, CConfigValueSet> CConfigDB::GetValuesWithPrefix(EConfigNamespace ns, const CStr& prefix)
|
2010-10-23 04:37:00 +02:00
|
|
|
{
|
2014-07-09 21:16:03 +02:00
|
|
|
CScopeLock s(&cfgdb_mutex);
|
2012-04-17 15:14:34 +02:00
|
|
|
std::map<CStr, CConfigValueSet> ret;
|
2010-10-23 04:37:00 +02:00
|
|
|
|
2014-11-17 02:03:59 +01:00
|
|
|
CHECK_NS(ret);
|
2010-10-23 04:37:00 +02:00
|
|
|
|
2012-04-17 15:14:34 +02:00
|
|
|
// Loop upwards so that values in later namespaces can override
|
|
|
|
// values in earlier namespaces
|
|
|
|
for (int search_ns = 0; search_ns <= ns; search_ns++)
|
2010-10-23 04:37:00 +02:00
|
|
|
{
|
|
|
|
for (TConfigMap::iterator it = m_Map[search_ns].begin(); it != m_Map[search_ns].end(); ++it)
|
|
|
|
{
|
|
|
|
if (boost::algorithm::starts_with(it->first, prefix))
|
2012-04-17 15:14:34 +02:00
|
|
|
ret[it->first] = it->second;
|
2010-10-23 04:37:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-30 00:56:18 +01:00
|
|
|
for (TConfigMap::iterator it = m_Map[CFG_COMMAND].begin(); it != m_Map[CFG_COMMAND].end(); ++it)
|
|
|
|
{
|
|
|
|
if (boost::algorithm::starts_with(it->first, prefix))
|
|
|
|
ret[it->first] = it->second;
|
|
|
|
}
|
|
|
|
|
2010-10-23 04:37:00 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-12-30 00:56:18 +01:00
|
|
|
void CConfigDB::SetValueString(EConfigNamespace ns, const CStr& name, const CStr& value)
|
2004-06-09 15:53:32 +02:00
|
|
|
{
|
2015-01-11 22:37:53 +01:00
|
|
|
CHECK_NS(;);
|
2012-12-25 23:49:18 +01:00
|
|
|
|
2014-07-09 21:16:03 +02:00
|
|
|
CScopeLock s(&cfgdb_mutex);
|
2012-12-25 23:49:18 +01:00
|
|
|
TConfigMap::iterator it = m_Map[ns].find(name);
|
2013-12-30 00:56:18 +01:00
|
|
|
if (it == m_Map[ns].end())
|
|
|
|
it = m_Map[ns].insert(m_Map[ns].begin(), make_pair(name, CConfigValueSet(1)));
|
2012-12-25 23:49:18 +01:00
|
|
|
|
2014-11-17 02:03:59 +01:00
|
|
|
it->second[0] = value;
|
2004-06-09 15:53:32 +02:00
|
|
|
}
|
|
|
|
|
2011-02-16 21:40:15 +01:00
|
|
|
void CConfigDB::SetConfigFile(EConfigNamespace ns, const VfsPath& path)
|
2004-06-09 15:53:32 +02:00
|
|
|
{
|
2015-01-11 22:37:53 +01:00
|
|
|
CHECK_NS(;);
|
2012-12-25 23:49:18 +01:00
|
|
|
|
2014-07-09 21:16:03 +02:00
|
|
|
CScopeLock s(&cfgdb_mutex);
|
2014-11-17 02:03:59 +01:00
|
|
|
m_ConfigFile[ns] = path;
|
2004-06-09 15:53:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CConfigDB::Reload(EConfigNamespace ns)
|
|
|
|
{
|
2014-11-17 02:03:59 +01:00
|
|
|
CHECK_NS(false);
|
2011-02-16 21:40:15 +01:00
|
|
|
|
2014-07-09 21:16:03 +02:00
|
|
|
CScopeLock s(&cfgdb_mutex);
|
2013-12-17 20:58:39 +01:00
|
|
|
|
2014-11-17 02:03:59 +01:00
|
|
|
shared_ptr<u8> buffer;
|
|
|
|
size_t buflen;
|
2004-06-09 15:53:32 +02:00
|
|
|
{
|
2009-06-23 19:48:34 +02:00
|
|
|
// Handle missing files quietly
|
2009-08-02 13:07:42 +02:00
|
|
|
if (g_VFS->GetFileInfo(m_ConfigFile[ns], NULL) < 0)
|
2004-06-09 15:53:32 +02:00
|
|
|
{
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGMESSAGE("Cannot find config file \"%s\" - ignoring", m_ConfigFile[ns].string8());
|
2004-06-09 15:53:32 +02:00
|
|
|
return false;
|
|
|
|
}
|
2014-11-17 02:03:59 +01:00
|
|
|
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGMESSAGE("Loading config file \"%s\"", m_ConfigFile[ns].string8());
|
2014-11-17 02:03:59 +01:00
|
|
|
Status ret = g_VFS->LoadFile(m_ConfigFile[ns], buffer, buflen);
|
|
|
|
if (ret != INFO::OK)
|
2009-06-23 19:48:34 +02:00
|
|
|
{
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGERROR("CConfigDB::Reload(): vfs_load for \"%s\" failed: return was %lld", m_ConfigFile[ns].string8(), (long long)ret);
|
2014-11-17 02:03:59 +01:00
|
|
|
return false;
|
2009-06-23 19:48:34 +02:00
|
|
|
}
|
2004-06-09 15:53:32 +02:00
|
|
|
}
|
2015-02-12 18:31:10 +01:00
|
|
|
|
2004-06-09 15:53:32 +02:00
|
|
|
TConfigMap newMap;
|
2014-11-17 02:03:59 +01:00
|
|
|
char *filebuf = (char*)buffer.get();
|
|
|
|
char *filebufend = filebuf+buflen;
|
2015-02-12 18:31:10 +01:00
|
|
|
|
2014-11-17 02:03:59 +01:00
|
|
|
bool quoted = false;
|
2014-11-18 04:57:07 +01:00
|
|
|
CStr header;
|
2014-11-17 02:03:59 +01:00
|
|
|
CStr name;
|
|
|
|
CStr value;
|
|
|
|
int line = 1;
|
|
|
|
std::vector<CStr> values;
|
|
|
|
for (char* pos = filebuf; pos < filebufend; ++pos)
|
2004-06-09 15:53:32 +02:00
|
|
|
{
|
2014-11-17 02:03:59 +01:00
|
|
|
switch (*pos)
|
2004-06-09 15:53:32 +02:00
|
|
|
{
|
2014-11-17 02:03:59 +01:00
|
|
|
case '\n':
|
|
|
|
case ';':
|
|
|
|
break; // We finished parsing this line
|
2004-07-21 18:34:07 +02:00
|
|
|
|
2014-11-17 02:03:59 +01:00
|
|
|
case ' ':
|
|
|
|
case '\r':
|
2015-02-12 18:31:10 +01:00
|
|
|
case '\t':
|
2014-11-17 02:03:59 +01:00
|
|
|
continue; // ignore
|
2004-07-21 18:34:07 +02:00
|
|
|
|
2014-11-18 04:57:07 +01:00
|
|
|
case '[':
|
|
|
|
header.clear();
|
|
|
|
for (++pos; pos < filebufend && *pos != '\n' && *pos != ']'; ++pos)
|
|
|
|
header.push_back(*pos);
|
|
|
|
|
|
|
|
if (pos == filebufend || *pos == '\n')
|
|
|
|
{
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGERROR("Config header with missing close tag encountered on line %d in '%s'", line, m_ConfigFile[ns].string8());
|
2014-11-18 04:57:07 +01:00
|
|
|
header.clear();
|
|
|
|
++line;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGMESSAGE("Found config header '%s'", header.c_str());
|
2014-11-18 04:57:07 +01:00
|
|
|
header.push_back('.');
|
|
|
|
while (++pos < filebufend && *pos != '\n' && *pos != ';')
|
|
|
|
if (*pos != ' ' && *pos != '\r')
|
|
|
|
{
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGERROR("Config settings on the same line as a header on line %d in '%s'", line, m_ConfigFile[ns].string8());
|
2014-11-18 04:57:07 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
while (pos < filebufend && *pos != '\n')
|
|
|
|
++pos;
|
|
|
|
++line;
|
|
|
|
continue;
|
|
|
|
|
2014-11-17 02:03:59 +01:00
|
|
|
case '=':
|
|
|
|
// Parse parameters (comma separated, possibly quoted)
|
|
|
|
for (++pos; pos < filebufend && *pos != '\n' && *pos != ';'; ++pos)
|
2004-07-21 18:34:07 +02:00
|
|
|
{
|
2014-11-17 02:03:59 +01:00
|
|
|
switch (*pos)
|
|
|
|
{
|
|
|
|
case '"':
|
|
|
|
quoted = true;
|
|
|
|
// parse until not quoted anymore
|
|
|
|
for (++pos; pos < filebufend && *pos != '\n' && *pos != '"'; ++pos)
|
|
|
|
{
|
|
|
|
if (*pos == '\\' && ++pos == filebufend)
|
|
|
|
{
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGERROR("Escape character at end of input (line %d in '%s')", line, m_ConfigFile[ns].string8());
|
2014-11-17 02:03:59 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
value.push_back(*pos);
|
|
|
|
}
|
|
|
|
if (pos < filebufend && *pos == '"')
|
|
|
|
quoted = false;
|
|
|
|
else
|
|
|
|
--pos; // We should terminate the outer loop too
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ' ':
|
2015-02-12 18:31:10 +01:00
|
|
|
case '\r':
|
|
|
|
case '\t':
|
2014-11-17 02:03:59 +01:00
|
|
|
break; // ignore
|
|
|
|
|
|
|
|
case ',':
|
|
|
|
if (!value.empty())
|
|
|
|
values.push_back(value);
|
|
|
|
value.clear();
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
value.push_back(*pos);
|
|
|
|
break;
|
|
|
|
}
|
2004-07-21 18:34:07 +02:00
|
|
|
}
|
2014-11-17 02:03:59 +01:00
|
|
|
if (quoted) // We ignore the invalid parameter
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGERROR("Unmatched quote while parsing config file '%s' on line %d", m_ConfigFile[ns].string8(), line);
|
2014-11-17 02:03:59 +01:00
|
|
|
else if (!value.empty())
|
|
|
|
values.push_back(value);
|
|
|
|
value.clear();
|
|
|
|
quoted = false;
|
|
|
|
break; // We are either at the end of the line, or we still have a comment to parse
|
|
|
|
|
|
|
|
default:
|
|
|
|
name.push_back(*pos);
|
|
|
|
continue;
|
2004-06-09 15:53:32 +02:00
|
|
|
}
|
2015-02-12 18:31:10 +01:00
|
|
|
|
2014-11-17 02:03:59 +01:00
|
|
|
// Consume the rest of the line
|
|
|
|
while (pos < filebufend && *pos != '\n')
|
|
|
|
++pos;
|
|
|
|
// Store the setting
|
|
|
|
if (!name.empty() && !values.empty())
|
|
|
|
{
|
2014-11-18 04:57:07 +01:00
|
|
|
CStr key(header + name);
|
|
|
|
newMap[key] = values;
|
|
|
|
if (key == "lobby.password")
|
2015-01-22 21:37:38 +01:00
|
|
|
LOGMESSAGE("Loaded config string \"%s\"", key);
|
2014-11-17 02:03:59 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
std::string vals;
|
2014-11-18 04:57:07 +01:00
|
|
|
for (size_t i = 0; i < newMap[key].size() - 1; ++i)
|
|
|
|
vals += "\"" + EscapeString(newMap[key][i]) + "\", ";
|
|
|
|
vals += "\"" + EscapeString(newMap[key][values.size()-1]) + "\"";
|
2015-01-22 21:37:38 +01:00
|
|
|
LOGMESSAGE("Loaded config string \"%s\" = %s", key, vals);
|
2014-11-17 02:03:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (!name.empty())
|
2015-01-22 21:37:38 +01:00
|
|
|
LOGERROR("Encountered config setting '%s' without value while parsing '%s' on line %d", name, m_ConfigFile[ns].string8(), line);
|
2014-11-17 02:03:59 +01:00
|
|
|
|
|
|
|
name.clear();
|
|
|
|
values.clear();
|
|
|
|
++line;
|
2004-06-09 15:53:32 +02:00
|
|
|
}
|
2014-11-17 02:03:59 +01:00
|
|
|
|
|
|
|
if (!name.empty())
|
2015-01-22 21:37:38 +01:00
|
|
|
LOGERROR("Config file does not have a new line after the last config setting '%s'", name);
|
2014-11-17 02:03:59 +01:00
|
|
|
|
2004-06-09 15:53:32 +02:00
|
|
|
m_Map[ns].swap(newMap);
|
2004-06-09 16:58:33 +02:00
|
|
|
|
|
|
|
return true;
|
2004-06-09 15:53:32 +02:00
|
|
|
}
|
|
|
|
|
2011-02-16 21:40:15 +01:00
|
|
|
bool CConfigDB::WriteFile(EConfigNamespace ns)
|
2004-06-09 15:53:32 +02:00
|
|
|
{
|
2014-11-17 02:03:59 +01:00
|
|
|
CHECK_NS(false);
|
2011-02-16 21:40:15 +01:00
|
|
|
|
2014-07-09 21:16:03 +02:00
|
|
|
CScopeLock s(&cfgdb_mutex);
|
2011-02-16 21:40:15 +01:00
|
|
|
return WriteFile(ns, m_ConfigFile[ns]);
|
|
|
|
}
|
2007-12-20 21:21:45 +01:00
|
|
|
|
2011-02-16 21:40:15 +01:00
|
|
|
bool CConfigDB::WriteFile(EConfigNamespace ns, const VfsPath& path)
|
|
|
|
{
|
2014-11-17 02:03:59 +01:00
|
|
|
CHECK_NS(false);
|
2004-07-07 20:06:02 +02:00
|
|
|
|
2014-07-09 21:16:03 +02:00
|
|
|
CScopeLock s(&cfgdb_mutex);
|
2011-04-29 21:10:34 +02:00
|
|
|
shared_ptr<u8> buf;
|
|
|
|
AllocateAligned(buf, 1*MiB, maxSectorSize);
|
2007-12-20 21:21:45 +01:00
|
|
|
char* pos = (char*)buf.get();
|
2014-11-17 02:03:59 +01:00
|
|
|
TConfigMap &map = m_Map[ns];
|
|
|
|
for (TConfigMap::const_iterator it = map.begin(); it != map.end(); ++it)
|
2004-07-07 20:06:02 +02:00
|
|
|
{
|
2014-11-17 02:03:59 +01:00
|
|
|
size_t i;
|
|
|
|
pos += sprintf(pos, "%s = ", it->first.c_str());
|
|
|
|
for (i = 0; i < it->second.size() - 1; ++i)
|
|
|
|
pos += sprintf(pos, "\"%s\", ", EscapeString(it->second[i]).c_str());
|
|
|
|
pos += sprintf(pos, "\"%s\"\n", EscapeString(it->second[i]).c_str());
|
2004-07-07 20:06:02 +02:00
|
|
|
}
|
2007-12-20 21:21:45 +01:00
|
|
|
const size_t len = pos - (char*)buf.get();
|
2004-07-07 20:06:02 +02:00
|
|
|
|
2011-05-03 14:38:42 +02:00
|
|
|
Status ret = g_VFS->CreateFile(path, buf, len);
|
2014-11-17 02:03:59 +01:00
|
|
|
if (ret < 0)
|
2004-07-07 20:06:02 +02:00
|
|
|
{
|
2015-01-22 21:36:24 +01:00
|
|
|
LOGERROR("CConfigDB::WriteFile(): CreateFile \"%s\" failed (error: %d)", path.string8(), (int)ret);
|
2007-12-20 21:21:45 +01:00
|
|
|
return false;
|
2004-07-07 20:06:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2004-06-09 15:53:32 +02:00
|
|
|
}
|
2014-11-17 02:03:59 +01:00
|
|
|
|
|
|
|
#undef CHECK_NS
|