summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-05-29 15:54:49 +0300
committerAndrei Karas <akaras@inbox.ru>2014-05-29 15:54:49 +0300
commit88f71d6a8673932d178408e7632a6eea08623294 (patch)
tree0cc0c1d9bc663abaec614441164db86e88f878fe /src
parent13dc76b540a0fa9bd62e3e996dd707b610e792e5 (diff)
downloadmanaplus-88f71d6a8673932d178408e7632a6eea08623294.tar.gz
manaplus-88f71d6a8673932d178408e7632a6eea08623294.tar.bz2
manaplus-88f71d6a8673932d178408e7632a6eea08623294.tar.xz
manaplus-88f71d6a8673932d178408e7632a6eea08623294.zip
Move config related functions from client into configmanager.
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/client.cpp333
-rw-r--r--src/client.h14
-rw-r--r--src/configmanager.cpp322
-rw-r--r--src/configmanager.h45
6 files changed, 395 insertions, 323 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index c617842c5..929a1042a 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -735,6 +735,8 @@ SET(SRCS
commandhandler.h
commands.cpp
commands.h
+ configmanager.cpp
+ configmanager.h
being/compounditem.h
being/compoundsprite.cpp
being/compoundsprite.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 6bb9951f9..0104db56a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -850,6 +850,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
commandhandler.h \
commands.cpp \
commands.h \
+ configmanager.cpp \
+ configmanager.h \
being/compounditem.h \
being/compoundsprite.cpp \
being/compoundsprite.h \
diff --git a/src/client.cpp b/src/client.cpp
index 1d3051372..081fe3996 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -26,6 +26,7 @@
#include "auctionmanager.h"
#include "chatlogger.h"
+#include "configmanager.h"
#include "configuration.h"
#include "dirs.h"
#include "dropshortcut.h"
@@ -160,10 +161,6 @@
#include "debug.h"
-#if defined __native_client__
-#define _nacl_dir std::string("/persistent/manaplus")
-#endif
-
#ifdef ANDROID
#ifdef USE_SDL2
int loadingProgressCounter = 1;
@@ -184,10 +181,6 @@ unsigned int mLastHost = 0;
unsigned long mSearchHash = 0;
int textures_count = 0;
-#ifdef WIN32
-extern "C" char const *_nl_locale_name_default(void);
-#endif
-
namespace
{
class AccountListener final : public ActionListener
@@ -285,8 +278,8 @@ void Client::gameInit()
#ifdef USE_FUZZER
Fuzzer::init();
#endif
- backupConfig();
- initConfiguration();
+ ConfigManager::backupConfig("config.xml");
+ ConfigManager::initConfiguration();
paths.setDefaultValues(getPathsDefaults());
initFeatures();
logger->log("init 4");
@@ -295,7 +288,7 @@ void Client::gameInit()
config.incValue("runcount");
#ifndef ANDROID
- storeSafeParameters();
+ ConfigManager::storeSafeParameters();
#endif
const ResourceManager *const resman = ResourceManager::getInstance();
@@ -354,7 +347,7 @@ void Client::gameInit()
#endif
setIcon();
- checkConfigVersion();
+ ConfigManager::checkConfigVersion();
logVars();
Cpu::detect();
#if defined(USE_OPENGL)
@@ -859,7 +852,25 @@ int Client::gameExec()
mOldState == STATE_CHOOSE_SERVER)
{
settings.serverName = mCurrentServer.hostname;
- initServerConfig(mCurrentServer.hostname);
+ ConfigManager::initServerConfig(mCurrentServer.hostname);
+ initPacketLimiter();
+ initTradeFilter();
+ Dirs::initUsersDir();
+ player_relations.init();
+
+ // Initialize the item and emote shortcuts.
+ for (unsigned f = 0; f < SHORTCUT_TABS; f ++)
+ {
+ delete itemShortcut[f];
+ itemShortcut[f] = new ItemShortcut(f);
+ }
+ delete emoteShortcut;
+ emoteShortcut = new EmoteShortcut;
+
+ // Initialize the drop shortcuts.
+ delete dropShortcut;
+ dropShortcut = new DropShortcut;
+
initFeatures();
PlayerInfo::loadData();
loginData.registerUrl = mCurrentServer.registerUrl;
@@ -1699,258 +1710,12 @@ void Client::action(const ActionEvent &event)
}
}
-/**
- * Initializes the home directory. On UNIX and FreeBSD, ~/.mana is used. On
- * Windows and other systems we use the current working directory.
- */
-void Client::initServerConfig(const std::string &serverName)
-{
- settings.serverConfigDir = settings.configDir + dirSeparator + serverName;
-
- if (mkdir_r(settings.serverConfigDir.c_str()))
- {
- // TRANSLATORS: directory creation error
- logger->error(strprintf(_("%s doesn't exist and can't be created! "
- "Exiting."), settings.serverConfigDir.c_str()));
- }
- const std::string configPath = settings.serverConfigDir + "/config.xml";
- FILE *configFile = fopen(configPath.c_str(), "r");
- if (!configFile)
- {
- configFile = fopen(configPath.c_str(), "wt");
- logger->log("Creating new server config: " + configPath);
- }
- if (configFile)
- {
- fclose(configFile);
- serverConfig.init(configPath);
- serverConfig.setDefaultValues(getConfigDefaults());
- logger->log("serverConfigPath: " + configPath);
- }
- initPacketLimiter();
- initTradeFilter();
- Dirs::initUsersDir();
- player_relations.init();
-
- // Initialize the item and emote shortcuts.
- for (unsigned f = 0; f < SHORTCUT_TABS; f ++)
- {
- delete itemShortcut[f];
- itemShortcut[f] = new ItemShortcut(f);
- }
- delete emoteShortcut;
- emoteShortcut = new EmoteShortcut;
-
- // Initialize the drop shortcuts.
- delete dropShortcut;
- dropShortcut = new DropShortcut;
-}
-
void Client::initFeatures()
{
features.init(paths.getStringValue("featuresFile"), true);
features.setDefaultValues(getFeaturesDefaults());
}
-void Client::initConfiguration() const
-{
-#ifdef DEBUG_CONFIG
- config.setIsMain(true);
-#endif
-
- // Fill configuration with defaults
- config.setValue("hwaccel", false);
-#ifdef USE_OPENGL
-#if (defined __APPLE__)
- config.setValue("opengl", static_cast<int>(RENDER_NORMAL_OPENGL));
-#elif (defined ANDROID)
- config.setValue("opengl", static_cast<int>(RENDER_GLES_OPENGL));
-#elif (defined WIN32)
- config.setValue("opengl", static_cast<int>(RENDER_SAFE_OPENGL));
-#else
- config.setValue("opengl", static_cast<int>(RENDER_SOFTWARE));
-#endif
-#else
- config.setValue("opengl", static_cast<int>(RENDER_SOFTWARE));
-#endif
- config.setValue("screen", false);
- config.setValue("sound", true);
- config.setValue("guialpha", 0.8F);
-// config.setValue("remember", true);
- config.setValue("sfxVolume", 100);
- config.setValue("musicVolume", 60);
- config.setValue("fpslimit", 60);
- std::string defaultUpdateHost = branding.getValue("defaultUpdateHost", "");
- if (!checkPath(defaultUpdateHost))
- defaultUpdateHost.clear();
- config.setValue("updatehost", defaultUpdateHost);
- config.setValue("useScreenshotDirectorySuffix", true);
- config.setValue("ChatLogLength", 128);
-
- std::string configPath;
-
- if (settings.options.test.empty())
- configPath = settings.configDir + "/config.xml";
- else
- configPath = settings.configDir + "/test.xml";
-
- FILE *configFile = fopen(configPath.c_str(), "r");
- if (!configFile)
- {
- configFile = fopen(configPath.c_str(), "wt");
- logger->log1("Creating new config");
- }
- if (!configFile)
- {
- logger->log("Can't create %s. Using defaults.", configPath.c_str());
- }
- else
- {
- fclose(configFile);
- config.init(configPath);
- logger->log1("init 3");
- config.setDefaultValues(getConfigDefaults());
- logger->log("configPath: " + configPath);
- }
-}
-
-void Client::backupConfig() const
-{
- const std::string confName = settings.configDir + "/config.xml.bak";
- const int maxFileIndex = 5;
- ::remove((confName + toString(maxFileIndex)).c_str());
- for (int f = maxFileIndex; f > 1; f --)
- {
- const std::string fileName1 = confName + toString(f - 1);
- const std::string fileName2 = confName + toString(f);
- Files::renameFile(fileName1, fileName2);
- }
- const std::string fileName3 = settings.configDir + "/config.xml";
- const std::string fileName4 = confName + toString(1);
- Files::copyFile(fileName3, fileName4);
-}
-
-#ifndef ANDROID
-void Client::storeSafeParameters() const
-{
- bool tmpHwaccel;
- RenderType tmpOpengl;
- int tmpFpslimit;
- int tmpAltFpslimit;
- bool tmpSound;
- int width;
- int height;
- std::string font;
- std::string bFont;
- std::string particleFont;
- std::string helpFont;
- std::string secureFont;
- std::string npcFont;
- std::string japanFont;
- std::string chinaFont;
- bool showBackground;
- bool enableMumble;
- bool enableMapReduce;
-
- isSafeMode = config.getBoolValue("safemode");
- if (isSafeMode)
- logger->log1("Run in safe mode");
-
- tmpOpengl = intToRenderType(config.getIntValue("opengl"));
-
- width = config.getIntValue("screenwidth");
- height = config.getIntValue("screenheight");
- tmpHwaccel = config.getBoolValue("hwaccel");
-
- tmpFpslimit = config.getIntValue("fpslimit");
- tmpAltFpslimit = config.getIntValue("altfpslimit");
- tmpSound = config.getBoolValue("sound");
-
- font = config.getStringValue("font");
- bFont = config.getStringValue("boldFont");
- particleFont = config.getStringValue("particleFont");
- helpFont = config.getStringValue("helpFont");
- secureFont = config.getStringValue("secureFont");
- npcFont = config.getStringValue("npcFont");
- japanFont = config.getStringValue("japanFont");
- chinaFont = config.getStringValue("chinaFont");
-
- showBackground = config.getBoolValue("showBackground");
- enableMumble = config.getBoolValue("enableMumble");
- enableMapReduce = config.getBoolValue("enableMapReduce");
-
- if (!settings.options.safeMode && !tmpOpengl)
- {
- // if video mode configured reset most settings to safe
- config.setValue("hwaccel", false);
- config.setValue("altfpslimit", 3);
- config.setValue("sound", false);
- config.setValue("safemode", true);
- config.setValue("screenwidth", 640);
- config.setValue("screenheight", 480);
- config.setValue("font", "fonts/dejavusans.ttf");
- config.setValue("boldFont", "fonts/dejavusans-bold.ttf");
- config.setValue("particleFont", "fonts/dejavusans.ttf");
- config.setValue("helpFont", "fonts/dejavusansmono.ttf");
- config.setValue("secureFont", "fonts/dejavusansmono.ttf");
- config.setValue("npcFont", "fonts/dejavusans.ttf");
- config.setValue("japanFont", "fonts/mplus-1p-regular.ttf");
- config.setValue("chinaFont", "fonts/wqy-microhei.ttf");
- config.setValue("showBackground", false);
- config.setValue("enableMumble", false);
- config.setValue("enableMapReduce", false);
- }
- else
- {
- // if video mode not configured reset only video mode to safe
- config.setValue("screenwidth", 640);
- config.setValue("screenheight", 480);
- }
-#if defined(__APPLE__)
- config.setValue("opengl", static_cast<int>(RENDER_NORMAL_OPENGL));
-#else
- config.setValue("opengl", static_cast<int>(RENDER_SOFTWARE));
-#endif
-
- config.write();
-
- if (settings.options.safeMode)
- {
- isSafeMode = true;
- return;
- }
-
- config.setValue("safemode", false);
- if (!tmpOpengl)
- {
- config.setValue("hwaccel", tmpHwaccel);
- config.setValue("opengl", static_cast<int>(tmpOpengl));
- config.setValue("fpslimit", tmpFpslimit);
- config.setValue("altfpslimit", tmpAltFpslimit);
- config.setValue("sound", tmpSound);
- config.setValue("screenwidth", width);
- config.setValue("screenheight", height);
- config.setValue("font", font);
- config.setValue("boldFont", bFont);
- config.setValue("particleFont", particleFont);
- config.setValue("helpFont", helpFont);
- config.setValue("secureFont", secureFont);
- config.setValue("npcFont", npcFont);
- config.setValue("japanFont", japanFont);
- config.setValue("chinaFont", chinaFont);
- config.setValue("showBackground", showBackground);
- config.setValue("enableMumble", enableMumble);
- config.setValue("enableMapReduce", enableMapReduce);
- }
- else
- {
- config.setValue("opengl", static_cast<int>(tmpOpengl));
- config.setValue("screenwidth", width);
- config.setValue("screenheight", height);
- }
-}
-#endif
-
void Client::initTradeFilter() const
{
const std::string tradeListName =
@@ -2383,56 +2148,6 @@ void Client::windowRemoved(const Window *const window)
mCurrentDialog = nullptr;
}
-void Client::checkConfigVersion()
-{
- const int version = config.getIntValue("cfgver");
- if (version < 1)
- {
- if (config.getIntValue("fontSize") == 11)
- config.deleteKey("fontSize");
- if (config.getIntValue("npcfontSize") == 13)
- config.deleteKey("npcfontSize");
- }
- if (version < 2)
- {
- if (config.getIntValue("screenButtonsSize") == 1)
- config.deleteKey("screenButtonsSize");
- if (config.getIntValue("screenJoystickSize") == 1)
- config.deleteKey("screenJoystickSize");
- }
- if (version < 3)
- {
- config.setValue("audioFrequency", 44100);
-#ifdef ANDROID
- config.setValue("customcursor", false);
-#endif
- }
- if (version < 4)
- {
-#ifdef ANDROID
- config.setValue("showDidYouKnow", false);
-#endif
- }
- if (version < 5)
- {
- if (config.getIntValue("speech") == BeingSpeech::TEXT_OVERHEAD)
- {
- config.setValue("speech", static_cast<int>(
- BeingSpeech::NO_NAME_IN_BUBBLE));
- }
- }
- if (version < 6)
- config.setValue("blur", false);
-
- if (version < 7)
- config.setValue("download-music", true);
-
- if (version < 8)
- config.deleteKey("videodetected");
-
- config.setValue("cfgver", 8);
-}
-
void Client::setIcon()
{
std::string iconFile = branding.getValue("appIcon", "icons/manaplus");
diff --git a/src/client.h b/src/client.h
index b83c069e4..28dc27e75 100644
--- a/src/client.h
+++ b/src/client.h
@@ -198,30 +198,16 @@ private:
void initTitle();
- void initConfiguration() const;
-
- void initServerConfig(const std::string &serverName);
-
static void initFeatures();
-#ifndef ANDROID
- void storeSafeParameters() const;
-#endif
-
- void backupConfig() const;
-
void gameClear();
void testsClear();
static void logVars();
- static void checkConfigVersion();
-
void setIcon();
- static Client *mInstance;
-
static void setEnv(const char *const name, const char *const value);
#ifdef ANDROID
diff --git a/src/configmanager.cpp b/src/configmanager.cpp
new file mode 100644
index 000000000..745ef195a
--- /dev/null
+++ b/src/configmanager.cpp
@@ -0,0 +1,322 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program 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
+ * any later version.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "configmanager.h"
+
+#include "client.h"
+#include "configuration.h"
+#include "logger.h"
+#include "settings.h"
+
+#include "being/beingspeech.h"
+#include "being/playerrelations.h"
+
+#include "utils/files.h"
+#include "utils/gettext.h"
+#include "utils/mkdir.h"
+#include "utils/paths.h"
+#include "utils/physfstools.h"
+
+#include "render/renderers.h"
+
+#include "debug.h"
+
+/**
+ * Initializes the home directory. On UNIX and FreeBSD, ~/.mana is used. On
+ * Windows and other systems we use the current working directory.
+ */
+void ConfigManager::initServerConfig(const std::string &serverName)
+{
+ settings.serverConfigDir = settings.configDir + dirSeparator + serverName;
+
+ if (mkdir_r(settings.serverConfigDir.c_str()))
+ {
+ // TRANSLATORS: directory creation error
+ logger->error(strprintf(_("%s doesn't exist and can't be created! "
+ "Exiting."), settings.serverConfigDir.c_str()));
+ }
+ const std::string configPath = settings.serverConfigDir + "/config.xml";
+ FILE *configFile = fopen(configPath.c_str(), "r");
+ if (!configFile)
+ {
+ configFile = fopen(configPath.c_str(), "wt");
+ logger->log("Creating new server config: " + configPath);
+ }
+ if (configFile)
+ {
+ fclose(configFile);
+ serverConfig.init(configPath);
+ serverConfig.setDefaultValues(getConfigDefaults());
+ logger->log("serverConfigPath: " + configPath);
+ }
+}
+
+void ConfigManager::initConfiguration()
+{
+#ifdef DEBUG_CONFIG
+ config.setIsMain(true);
+#endif
+
+ // Fill configuration with defaults
+ config.setValue("hwaccel", false);
+#ifdef USE_OPENGL
+#if (defined __APPLE__)
+ config.setValue("opengl", static_cast<int>(RENDER_NORMAL_OPENGL));
+#elif (defined ANDROID)
+ config.setValue("opengl", static_cast<int>(RENDER_GLES_OPENGL));
+#elif (defined WIN32)
+ config.setValue("opengl", static_cast<int>(RENDER_SAFE_OPENGL));
+#else
+ config.setValue("opengl", static_cast<int>(RENDER_SOFTWARE));
+#endif
+#else
+ config.setValue("opengl", static_cast<int>(RENDER_SOFTWARE));
+#endif
+ config.setValue("screen", false);
+ config.setValue("sound", true);
+ config.setValue("guialpha", 0.8F);
+// config.setValue("remember", true);
+ config.setValue("sfxVolume", 100);
+ config.setValue("musicVolume", 60);
+ config.setValue("fpslimit", 60);
+ std::string defaultUpdateHost = branding.getValue("defaultUpdateHost", "");
+ if (!checkPath(defaultUpdateHost))
+ defaultUpdateHost.clear();
+ config.setValue("updatehost", defaultUpdateHost);
+ config.setValue("useScreenshotDirectorySuffix", true);
+ config.setValue("ChatLogLength", 128);
+
+ std::string configPath;
+
+ if (settings.options.test.empty())
+ configPath = settings.configDir + "/config.xml";
+ else
+ configPath = settings.configDir + "/test.xml";
+
+ FILE *configFile = fopen(configPath.c_str(), "r");
+ if (!configFile)
+ {
+ configFile = fopen(configPath.c_str(), "wt");
+ logger->log1("Creating new config");
+ }
+ if (!configFile)
+ {
+ logger->log("Can't create %s. Using defaults.", configPath.c_str());
+ }
+ else
+ {
+ fclose(configFile);
+ config.init(configPath);
+ logger->log1("init 3");
+ config.setDefaultValues(getConfigDefaults());
+ logger->log("configPath: " + configPath);
+ }
+}
+
+void ConfigManager::backupConfig(const std::string &name)
+{
+ const std::string confName = std::string(settings.configDir).append(
+ "/").append(name).append(".bak");
+ const int maxFileIndex = 5;
+ ::remove((confName + toString(maxFileIndex)).c_str());
+ for (int f = maxFileIndex; f > 1; f --)
+ {
+ const std::string fileName1 = confName + toString(f - 1);
+ const std::string fileName2 = confName + toString(f);
+ Files::renameFile(fileName1, fileName2);
+ }
+ const std::string fileName3 = std::string(settings.configDir).append(
+ "/").append(name);
+ const std::string fileName4 = confName + toString(1);
+ Files::copyFile(fileName3, fileName4);
+}
+
+#ifndef ANDROID
+void ConfigManager::storeSafeParameters()
+{
+ bool tmpHwaccel;
+ RenderType tmpOpengl;
+ int tmpFpslimit;
+ int tmpAltFpslimit;
+ bool tmpSound;
+ int width;
+ int height;
+ std::string font;
+ std::string bFont;
+ std::string particleFont;
+ std::string helpFont;
+ std::string secureFont;
+ std::string npcFont;
+ std::string japanFont;
+ std::string chinaFont;
+ bool showBackground;
+ bool enableMumble;
+ bool enableMapReduce;
+
+ isSafeMode = config.getBoolValue("safemode");
+ if (isSafeMode)
+ logger->log1("Run in safe mode");
+
+ tmpOpengl = intToRenderType(config.getIntValue("opengl"));
+
+ width = config.getIntValue("screenwidth");
+ height = config.getIntValue("screenheight");
+ tmpHwaccel = config.getBoolValue("hwaccel");
+
+ tmpFpslimit = config.getIntValue("fpslimit");
+ tmpAltFpslimit = config.getIntValue("altfpslimit");
+ tmpSound = config.getBoolValue("sound");
+
+ font = config.getStringValue("font");
+ bFont = config.getStringValue("boldFont");
+ particleFont = config.getStringValue("particleFont");
+ helpFont = config.getStringValue("helpFont");
+ secureFont = config.getStringValue("secureFont");
+ npcFont = config.getStringValue("npcFont");
+ japanFont = config.getStringValue("japanFont");
+ chinaFont = config.getStringValue("chinaFont");
+
+ showBackground = config.getBoolValue("showBackground");
+ enableMumble = config.getBoolValue("enableMumble");
+ enableMapReduce = config.getBoolValue("enableMapReduce");
+
+ if (!settings.options.safeMode && !tmpOpengl)
+ {
+ // if video mode configured reset most settings to safe
+ config.setValue("hwaccel", false);
+ config.setValue("altfpslimit", 3);
+ config.setValue("sound", false);
+ config.setValue("safemode", true);
+ config.setValue("screenwidth", 640);
+ config.setValue("screenheight", 480);
+ config.setValue("font", "fonts/dejavusans.ttf");
+ config.setValue("boldFont", "fonts/dejavusans-bold.ttf");
+ config.setValue("particleFont", "fonts/dejavusans.ttf");
+ config.setValue("helpFont", "fonts/dejavusansmono.ttf");
+ config.setValue("secureFont", "fonts/dejavusansmono.ttf");
+ config.setValue("npcFont", "fonts/dejavusans.ttf");
+ config.setValue("japanFont", "fonts/mplus-1p-regular.ttf");
+ config.setValue("chinaFont", "fonts/wqy-microhei.ttf");
+ config.setValue("showBackground", false);
+ config.setValue("enableMumble", false);
+ config.setValue("enableMapReduce", false);
+ }
+ else
+ {
+ // if video mode not configured reset only video mode to safe
+ config.setValue("screenwidth", 640);
+ config.setValue("screenheight", 480);
+ }
+#if defined(__APPLE__)
+ config.setValue("opengl", static_cast<int>(RENDER_NORMAL_OPENGL));
+#else
+ config.setValue("opengl", static_cast<int>(RENDER_SOFTWARE));
+#endif
+
+ config.write();
+
+ if (settings.options.safeMode)
+ {
+ isSafeMode = true;
+ return;
+ }
+
+ config.setValue("safemode", false);
+ if (!tmpOpengl)
+ {
+ config.setValue("hwaccel", tmpHwaccel);
+ config.setValue("opengl", static_cast<int>(tmpOpengl));
+ config.setValue("fpslimit", tmpFpslimit);
+ config.setValue("altfpslimit", tmpAltFpslimit);
+ config.setValue("sound", tmpSound);
+ config.setValue("screenwidth", width);
+ config.setValue("screenheight", height);
+ config.setValue("font", font);
+ config.setValue("boldFont", bFont);
+ config.setValue("particleFont", particleFont);
+ config.setValue("helpFont", helpFont);
+ config.setValue("secureFont", secureFont);
+ config.setValue("npcFont", npcFont);
+ config.setValue("japanFont", japanFont);
+ config.setValue("chinaFont", chinaFont);
+ config.setValue("showBackground", showBackground);
+ config.setValue("enableMumble", enableMumble);
+ config.setValue("enableMapReduce", enableMapReduce);
+ }
+ else
+ {
+ config.setValue("opengl", static_cast<int>(tmpOpengl));
+ config.setValue("screenwidth", width);
+ config.setValue("screenheight", height);
+ }
+}
+#endif
+
+void ConfigManager::checkConfigVersion()
+{
+ const int version = config.getIntValue("cfgver");
+ if (version < 1)
+ {
+ if (config.getIntValue("fontSize") == 11)
+ config.deleteKey("fontSize");
+ if (config.getIntValue("npcfontSize") == 13)
+ config.deleteKey("npcfontSize");
+ }
+ if (version < 2)
+ {
+ if (config.getIntValue("screenButtonsSize") == 1)
+ config.deleteKey("screenButtonsSize");
+ if (config.getIntValue("screenJoystickSize") == 1)
+ config.deleteKey("screenJoystickSize");
+ }
+ if (version < 3)
+ {
+ config.setValue("audioFrequency", 44100);
+#ifdef ANDROID
+ config.setValue("customcursor", false);
+#endif
+ }
+ if (version < 4)
+ {
+#ifdef ANDROID
+ config.setValue("showDidYouKnow", false);
+#endif
+ }
+ if (version < 5)
+ {
+ if (config.getIntValue("speech") == BeingSpeech::TEXT_OVERHEAD)
+ {
+ config.setValue("speech", static_cast<int>(
+ BeingSpeech::NO_NAME_IN_BUBBLE));
+ }
+ }
+ if (version < 6)
+ config.setValue("blur", false);
+
+ if (version < 7)
+ config.setValue("download-music", true);
+
+ if (version < 8)
+ config.deleteKey("videodetected");
+
+ config.setValue("cfgver", 8);
+}
diff --git a/src/configmanager.h b/src/configmanager.h
new file mode 100644
index 000000000..87ed939a6
--- /dev/null
+++ b/src/configmanager.h
@@ -0,0 +1,45 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2004-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2014 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program 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
+ * any later version.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef CONFIGMANAGER_H
+#define CONFIGMANAGER_H
+
+#include <string>
+
+#include "localconsts.h"
+
+class ConfigManager final
+{
+ public:
+ static void initConfiguration();
+
+ static void initServerConfig(const std::string &serverName);
+
+#ifndef ANDROID
+ static void storeSafeParameters();
+#endif
+ static void backupConfig(const std::string &name);
+
+ static void checkConfigVersion();
+};
+
+#endif // CONFIGMANAGER_H