summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-05-29 12:53:30 +0300
committerAndrei Karas <akaras@inbox.ru>2014-05-29 12:56:42 +0300
commit38aea9a883ec792d49bee91bfcec5468c15eff7a (patch)
treeb3315bd1bb7d673ec55be1ed77594ba4a895540e
parent5f048b85f826a85278545ac363d7058793fb3ece (diff)
downloadplus-38aea9a883ec792d49bee91bfcec5468c15eff7a.tar.gz
plus-38aea9a883ec792d49bee91bfcec5468c15eff7a.tar.bz2
plus-38aea9a883ec792d49bee91bfcec5468c15eff7a.tar.xz
plus-38aea9a883ec792d49bee91bfcec5468c15eff7a.zip
Move options into settings.
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/Makefile.am1
-rw-r--r--src/client.cpp141
-rw-r--r--src/client.h62
-rw-r--r--src/main.cpp26
-rw-r--r--src/options.h83
6 files changed, 169 insertions, 145 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 96e74e0b2..dd24d7ae2 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -843,6 +843,7 @@ SET(SRCS
notifications.h
notifymanager.cpp
notifymanager.h
+ options.h
render/graphicsdef.hpp
render/graphics_calcImageRect.hpp
render/graphics_drawImageRect.hpp
diff --git a/src/Makefile.am b/src/Makefile.am
index aa2a69671..072bc6949 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -956,6 +956,7 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
notifications.h \
notifymanager.cpp \
notifymanager.h \
+ options.h \
render/graphicsdef.hpp \
render/graphics_calcImageRect.hpp \
render/graphics_drawImageRect.hpp \
diff --git a/src/client.cpp b/src/client.cpp
index 4688e7306..868d40454 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -207,9 +207,8 @@ namespace
} loginListener;
} // namespace
-Client::Client(const Options &options) :
+Client::Client() :
ActionListener(),
- mOptions(options),
mRootDir(),
mCurrentServer(),
mGame(nullptr),
@@ -251,7 +250,7 @@ Client::Client(const Options &options) :
void Client::testsInit()
{
- if (!mOptions.test.empty() && mOptions.test != "99")
+ if (!settings.options.test.empty() && settings.options.test != "99")
{
gameInit();
}
@@ -269,16 +268,16 @@ void Client::gameInit()
logger = new Logger;
// Load branding information
- if (!mOptions.brandingPath.empty())
- branding.init(mOptions.brandingPath);
+ if (!settings.options.brandingPath.empty())
+ branding.init(settings.options.brandingPath);
branding.setDefaultValues(getBrandingDefaults());
initRootDir();
initHomeDir();
// Configure logger
- if (!mOptions.logFileName.empty())
- settings.logFileName = mOptions.logFileName;
+ if (!settings.options.logFileName.empty())
+ settings.logFileName = settings.options.logFileName;
else
settings.logFileName = settings.localDataDir + "/manaplus.log";
logger->setLogFile(settings.logFileName);
@@ -309,14 +308,14 @@ void Client::gameInit()
initLang();
chatLogger = new ChatLogger;
- if (mOptions.chatLogDir.empty())
+ if (settings.options.chatLogDir.empty())
{
chatLogger->setBaseLogDir(settings.localDataDir
+ std::string("/logs/"));
}
else
{
- chatLogger->setBaseLogDir(mOptions.chatLogDir);
+ chatLogger->setBaseLogDir(settings.options.chatLogDir);
}
logger->setLogToStandardOut(config.getBoolValue("logToStandardOut"));
@@ -360,7 +359,7 @@ void Client::gameInit()
Cpu::detect();
#if defined(USE_OPENGL)
#if !defined(ANDROID) && !defined(__APPLE__) && !defined(__native_client__)
- if (!mOptions.safeMode && mOptions.test.empty()
+ if (!settings.options.safeMode && settings.options.test.empty()
&& !config.getBoolValue("videodetected"))
{
graphicsManager.detectVideoSettings();
@@ -378,8 +377,8 @@ void Client::gameInit()
updateDataPath();
// Add the main data directories to our PhysicsFS search path
- if (!mOptions.dataPath.empty())
- resman->addToSearchPath(mOptions.dataPath, false);
+ if (!settings.options.dataPath.empty())
+ resman->addToSearchPath(settings.options.dataPath, false);
// Add the local data directory to PhysicsFS search path
resman->addToSearchPath(settings.localDataDir, false);
@@ -417,18 +416,18 @@ void Client::gameInit()
joystick->update();
// Initialize default server
- mCurrentServer.hostname = mOptions.serverName;
- mCurrentServer.port = mOptions.serverPort;
+ mCurrentServer.hostname = settings.options.serverName;
+ mCurrentServer.port = settings.options.serverPort;
- loginData.username = mOptions.username;
- loginData.password = mOptions.password;
+ loginData.username = settings.options.username;
+ loginData.password = settings.options.password;
loginData.remember = serverConfig.getValue("remember", 1);
loginData.registerLogin = false;
if (mCurrentServer.hostname.empty())
{
mCurrentServer.hostname = branding.getValue("defaultServer", "");
- mOptions.serverName = mCurrentServer.hostname;
+ settings.options.serverName = mCurrentServer.hostname;
}
if (mCurrentServer.port == 0)
@@ -473,7 +472,7 @@ void Client::gameInit()
Client::~Client()
{
- if (!mOptions.testMode)
+ if (!settings.options.testMode)
gameClear();
else
testsClear();
@@ -541,25 +540,25 @@ void Client::updateEnv()
void Client::updateDataPath()
{
- if (mOptions.dataPath.empty()
+ if (settings.options.dataPath.empty()
&& !branding.getStringValue("dataPath").empty())
{
if (isRealPath(branding.getStringValue("dataPath")))
{
- mOptions.dataPath = branding.getStringValue("dataPath");
+ settings.options.dataPath = branding.getStringValue("dataPath");
}
else
{
- mOptions.dataPath = branding.getDirectory().append(dirSeparator)
+ settings.options.dataPath = branding.getDirectory().append(dirSeparator)
+ branding.getStringValue("dataPath");
}
- mOptions.skipUpdate = true;
+ settings.options.skipUpdate = true;
}
}
void Client::initGraphics()
{
- graphicsManager.initGraphics(mOptions.noOpenGL);
+ graphicsManager.initGraphics(settings.options.noOpenGL);
runCounters = config.getBoolValue("packetcounters");
applyVSync();
@@ -573,7 +572,7 @@ void Client::initGraphics()
void Client::initTitle()
{
- if (mOptions.test.empty())
+ if (settings.options.test.empty())
{
mCaption = strprintf("%s %s",
branding.getStringValue("appName").c_str(),
@@ -679,9 +678,9 @@ void Client::mountDataDir()
#endif
// Add branding/data to PhysFS search path
- if (!mOptions.brandingPath.empty())
+ if (!settings.options.brandingPath.empty())
{
- std::string path = mOptions.brandingPath;
+ std::string path = settings.options.brandingPath;
// Strip blah.manaplus from the path
#ifdef WIN32
@@ -790,7 +789,7 @@ void Client::setEnv(const char *const name, const char *const value)
void Client::testsClear()
{
- if (!mOptions.test.empty())
+ if (!settings.options.test.empty())
gameClear();
else
BeingInfo::clear();
@@ -934,14 +933,14 @@ void Client::gameClear()
int Client::testsExec() const
{
#ifdef USE_OPENGL
- if (mOptions.test.empty())
+ if (settings.options.test.empty())
{
TestMain test;
return test.exec();
}
else
{
- TestLauncher launcher(mOptions.test);
+ TestLauncher launcher(settings.options.test);
return launcher.exec();
}
#else
@@ -1049,7 +1048,7 @@ int Client::gameExec()
settings.supportUrl = mCurrentServer.supportUrl;
settings.updateMirrors = mCurrentServer.updateMirrors;
- if (mOptions.username.empty())
+ if (settings.options.username.empty())
{
if (loginData.remember)
loginData.username = serverConfig.getValue("username", "");
@@ -1058,7 +1057,7 @@ int Client::gameExec()
}
else
{
- loginData.username = mOptions.username;
+ loginData.username = settings.options.username;
}
loginData.remember = serverConfig.getValue("remember", 1);
@@ -1155,11 +1154,11 @@ int Client::gameExec()
Net::getPartyHandler()->clear();
if (chatLogger)
chatLogger->clear();
- if (!mOptions.dataPath.empty())
- UpdaterWindow::unloadMods(mOptions.dataPath);
+ if (!settings.options.dataPath.empty())
+ UpdaterWindow::unloadMods(settings.options.dataPath);
else
UpdaterWindow::unloadMods(settings.oldUpdates);
- if (!mOptions.skipUpdate)
+ if (!settings.options.skipUpdate)
UpdaterWindow::unloadMods(settings.oldUpdates + "/fix/");
}
@@ -1187,7 +1186,7 @@ int Client::gameExec()
settings.supportUrl.clear();
ResourceManager *const resman
= ResourceManager::getInstance();
- if (mOptions.dataPath.empty())
+ if (settings.options.dataPath.empty())
{
// Add customdata directory
resman->searchAndRemoveArchives(
@@ -1201,7 +1200,7 @@ int Client::gameExec()
settings.oldUpdates.clear();
}
- if (!mOptions.skipUpdate)
+ if (!settings.options.skipUpdate)
{
resman->searchAndRemoveArchives(
settings.updatesDir + "/local/",
@@ -1219,7 +1218,7 @@ int Client::gameExec()
// Allow changing this using a server choice dialog
// We show the dialog box only if the command-line
// options weren't set.
- if (mOptions.serverName.empty() && mOptions.serverPort == 0
+ if (settings.options.serverName.empty() && settings.options.serverPort == 0
&& !branding.getValue("onlineServerList", "a").empty())
{
// Don't allow an alpha opacity
@@ -1236,8 +1235,8 @@ int Client::gameExec()
// Reset options so that cancelling or connect
// timeout will show the server dialog.
- mOptions.serverName.clear();
- mOptions.serverPort = 0;
+ settings.options.serverName.clear();
+ settings.options.serverPort = 0;
}
BLOCK_END("Client::gameExec STATE_CHOOSE_SERVER")
break;
@@ -1274,11 +1273,11 @@ int Client::gameExec()
mSearchHash = Net::Download::adlerBuffer(
const_cast<char*>(mCurrentServer.hostname.c_str()),
static_cast<int>(mCurrentServer.hostname.size()));
- if (mOptions.username.empty()
- || mOptions.password.empty())
+ if (settings.options.username.empty()
+ || settings.options.password.empty())
{
mCurrentDialog = new LoginDialog(&loginData,
- mCurrentServer.hostname, &mOptions.updateHost);
+ mCurrentServer.hostname, &settings.options.updateHost);
mCurrentDialog->postInit();
}
else
@@ -1286,7 +1285,7 @@ int Client::gameExec()
mState = STATE_LOGIN_ATTEMPT;
// Clear the password so that when login fails, the
// dialog will show up next time.
- mOptions.password.clear();
+ settings.options.password.clear();
}
BLOCK_END("Client::gameExec STATE_LOGIN")
break;
@@ -1324,7 +1323,7 @@ int Client::gameExec()
{
mCurrentDialog = new WorldSelectDialog(worlds);
mCurrentDialog->postInit();
- if (mOptions.chooseDefault)
+ if (settings.options.chooseDefault)
{
static_cast<WorldSelectDialog*>(mCurrentDialog)
->action(ActionEvent(nullptr, "ok"));
@@ -1348,8 +1347,8 @@ int Client::gameExec()
BLOCK_START("Client::gameExec STATE_UPDATE")
logger->log1("State: UPDATE");
// Determine which source to use for the update host
- if (!mOptions.updateHost.empty())
- settings.updateHost = mOptions.updateHost;
+ if (!settings.options.updateHost.empty())
+ settings.updateHost = settings.options.updateHost;
else
settings.updateHost = loginData.updateHost;
initUpdatesDir();
@@ -1357,11 +1356,11 @@ int Client::gameExec()
if (!settings.oldUpdates.empty())
UpdaterWindow::unloadUpdates(settings.oldUpdates);
- if (mOptions.skipUpdate)
+ if (settings.options.skipUpdate)
{
mState = STATE_LOAD_DATA;
settings.oldUpdates.clear();
- UpdaterWindow::loadDirMods(mOptions.dataPath);
+ UpdaterWindow::loadDirMods(settings.options.dataPath);
}
else if (loginData.updateType & UpdateType::Skip)
{
@@ -1376,7 +1375,7 @@ int Client::gameExec()
+ dirSeparator + settings.updatesDir;
mCurrentDialog = new UpdaterWindow(settings.updateHost,
settings.oldUpdates,
- mOptions.dataPath.empty(),
+ settings.options.dataPath.empty(),
loginData.updateType);
mCurrentDialog->postInit();
}
@@ -1393,7 +1392,7 @@ int Client::gameExec()
// If another data path has been set,
// we don't load any other files...
- if (mOptions.dataPath.empty())
+ if (settings.options.dataPath.empty())
{
// Add customdata directory
resman->searchAndAddArchives(
@@ -1402,7 +1401,7 @@ int Client::gameExec()
false);
}
- if (!mOptions.skipUpdate)
+ if (!settings.options.skipUpdate)
{
resman->searchAndAddArchives(
settings.updatesDir + "/local/",
@@ -1481,20 +1480,20 @@ int Client::gameExec()
mCurrentDialog->postInit();
if (!(static_cast<CharSelectDialog*>(mCurrentDialog))
- ->selectByName(mOptions.character,
+ ->selectByName(settings.options.character,
CharSelectDialog::Choose))
{
(static_cast<CharSelectDialog*>(mCurrentDialog))
->selectByName(
serverConfig.getValue("lastCharacter", ""),
- mOptions.chooseDefault ?
+ settings.options.chooseDefault ?
CharSelectDialog::Choose :
CharSelectDialog::Focus);
}
// Choosing character on the command line should work only
// once, clear it so that 'switch character' works.
- mOptions.character.clear();
+ settings.options.character.clear();
BLOCK_END("Client::gameExec STATE_CHAR_SELECT")
break;
@@ -1889,7 +1888,7 @@ void Client::initRootDir()
Configuration portable;
portable.init(portableName);
- if (mOptions.brandingPath.empty())
+ if (settings.options.brandingPath.empty())
{
branding.init(portableName);
branding.setDefaultValues(getBrandingDefaults());
@@ -1897,36 +1896,36 @@ void Client::initRootDir()
logger->log("Portable file: %s", portableName.c_str());
- if (mOptions.localDataDir.empty())
+ if (settings.options.localDataDir.empty())
{
dir = portable.getValue("dataDir", "");
if (!dir.empty())
{
- mOptions.localDataDir = mRootDir + dir;
+ settings.options.localDataDir = mRootDir + dir;
logger->log("Portable data dir: %s",
- mOptions.localDataDir.c_str());
+ settings.options.localDataDir.c_str());
}
}
- if (mOptions.configDir.empty())
+ if (settings.options.configDir.empty())
{
dir = portable.getValue("configDir", "");
if (!dir.empty())
{
- mOptions.configDir = mRootDir + dir;
+ settings.options.configDir = mRootDir + dir;
logger->log("Portable config dir: %s",
- mOptions.configDir.c_str());
+ settings.options.configDir.c_str());
}
}
- if (mOptions.screenshotDir.empty())
+ if (settings.options.screenshotDir.empty())
{
dir = portable.getValue("screenshotDir", "");
if (!dir.empty())
{
- mOptions.screenshotDir = mRootDir + dir;
+ settings.options.screenshotDir = mRootDir + dir;
logger->log("Portable screenshot dir: %s",
- mOptions.screenshotDir.c_str());
+ settings.options.screenshotDir.c_str());
}
}
}
@@ -1945,7 +1944,7 @@ void Client::initHomeDir()
void Client::initLocalDataDir()
{
- settings.localDataDir = mOptions.localDataDir;
+ settings.localDataDir = settings.options.localDataDir;
if (settings.localDataDir.empty())
{
@@ -1999,7 +1998,7 @@ void Client::initTempDir()
void Client::initConfigDir()
{
- settings.configDir = mOptions.configDir;
+ settings.configDir = settings.options.configDir;
if (settings.configDir.empty())
{
@@ -2131,7 +2130,7 @@ void Client::initConfiguration() const
std::string configPath;
- if (mOptions.test.empty())
+ if (settings.options.test.empty())
configPath = settings.configDir + "/config.xml";
else
configPath = settings.configDir + "/test.xml";
@@ -2273,9 +2272,9 @@ void Client::initUpdatesDir()
void Client::initScreenshotDir()
{
- if (!mOptions.screenshotDir.empty())
+ if (!settings.options.screenshotDir.empty())
{
- settings.screenshotDir = mOptions.screenshotDir;
+ settings.screenshotDir = settings.options.screenshotDir;
if (mkdir_r(settings.screenshotDir.c_str()))
{
// TRANSLATORS: directory creation error
@@ -2371,7 +2370,7 @@ void Client::storeSafeParameters() const
enableMumble = config.getBoolValue("enableMumble");
enableMapReduce = config.getBoolValue("enableMapReduce");
- if (!mOptions.safeMode && !tmpOpengl)
+ if (!settings.options.safeMode && !tmpOpengl)
{
// if video mode configured reset most settings to safe
config.setValue("hwaccel", false);
@@ -2406,7 +2405,7 @@ void Client::storeSafeParameters() const
config.write();
- if (mOptions.safeMode)
+ if (settings.options.safeMode)
{
isSafeMode = true;
return;
diff --git a/src/client.h b/src/client.h
index 06bc1faf0..e2e5a84de 100644
--- a/src/client.h
+++ b/src/client.h
@@ -95,62 +95,7 @@ class Client final : public ConfigListener,
public ActionListener
{
public:
- /**
- * A structure holding the values of various options that can be passed
- * from the command line.
- */
- struct Options
- {
- Options() :
- username(),
- password(),
- character(),
- brandingPath(),
- updateHost(),
- dataPath(),
- homeDir(),
- logFileName(),
- chatLogDir(),
- configDir(),
- localDataDir(),
- screenshotDir(),
- test(),
- serverName(),
- serverPort(0),
- printHelp(false),
- printVersion(false),
- skipUpdate(false),
- chooseDefault(false),
- noOpenGL(false),
- safeMode(false),
- testMode(false)
- {}
-
- std::string username;
- std::string password;
- std::string character;
- std::string brandingPath;
- std::string updateHost;
- std::string dataPath;
- std::string homeDir;
- std::string logFileName;
- std::string chatLogDir;
- std::string configDir;
- std::string localDataDir;
- std::string screenshotDir;
- std::string test;
- std::string serverName;
- uint16_t serverPort;
- bool printHelp;
- bool printVersion;
- bool skipUpdate;
- bool chooseDefault;
- bool noOpenGL;
- bool safeMode;
- bool testMode;
- };
-
- explicit Client(const Options &options);
+ explicit Client();
A_DELETE_COPY(Client)
@@ -189,9 +134,6 @@ public:
void setMouseFocused(const bool n)
{ mMouseFocused = n; }
- const Options &getOptions() const A_WARN_UNUSED
- { return mOptions; }
-
bool isKeyboardVisible() const;
void setGuiAlpha(const float n)
@@ -314,8 +256,6 @@ private:
#endif
#endif
- Options mOptions;
-
std::string mRootDir;
std::string mLogFileName;
diff --git a/src/main.cpp b/src/main.cpp
index 35a5570ea..23ad034fc 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -24,10 +24,7 @@
#include "main.h"
#include "client.h"
-
-#include <getopt.h>
-#include <iostream>
-#include <unistd.h>
+#include "settings.h"
#include "utils/delete2.h"
#include "utils/gettext.h"
@@ -49,6 +46,10 @@
#include <windows.h>
#endif
+#include <getopt.h>
+#include <iostream>
+#include <unistd.h>
+
#include <SDL_image.h>
#include <SDL_mixer.h>
#include <SDL_version.h>
@@ -141,8 +142,7 @@ static void printVersion()
std::cout << strprintf("ManaPlus client %s", FULL_VERSION) << std::endl;
}
-static void parseOptions(const int argc, char *const argv[],
- Client::Options &options)
+static void parseOptions(const int argc, char *const argv[])
{
const char *const optstring = "hvud:U:P:Dc:p:l:L:C:s:t:T:a";
@@ -171,6 +171,8 @@ static void parseOptions(const int argc, char *const argv[],
{ nullptr, 0, nullptr, 0 }
};
+ Options &options = settings.options;
+
while (optind < argc)
{
const int result = getopt_long(argc, argv,
@@ -277,16 +279,14 @@ int main(int argc, char *argv[])
selfName = argv[0];
- // Parse command line options
- Client::Options options;
- parseOptions(argc, argv, options);
+ parseOptions(argc, argv);
- if (options.printHelp)
+ if (settings.options.printHelp)
{
printHelp();
_exit(0);
}
- else if (options.printVersion)
+ else if (settings.options.printVersion)
{
printVersion();
_exit(0);
@@ -309,9 +309,9 @@ int main(int argc, char *argv[])
SetCurrentDirectory(PhysFs::getBaseDir());
#endif
setPriority(true);
- client = new Client(options);
+ client = new Client;
int ret = 0;
- if (!options.testMode)
+ if (!settings.options.testMode)
{
client->gameInit();
ret = client->gameExec();
diff --git a/src/options.h b/src/options.h
new file mode 100644
index 000000000..a36c4bda4
--- /dev/null
+++ b/src/options.h
@@ -0,0 +1,83 @@
+/*
+ * 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 OPTIONS_H
+#define OPTIONS_H
+
+#include <string>
+
+/**
+ * A structure holding the values of various options that can be passed
+ * from the command line.
+ */
+struct Options
+{
+ Options() :
+ username(),
+ password(),
+ character(),
+ brandingPath(),
+ updateHost(),
+ dataPath(),
+ homeDir(),
+ logFileName(),
+ chatLogDir(),
+ configDir(),
+ localDataDir(),
+ screenshotDir(),
+ test(),
+ serverName(),
+ serverPort(0),
+ printHelp(false),
+ printVersion(false),
+ skipUpdate(false),
+ chooseDefault(false),
+ noOpenGL(false),
+ safeMode(false),
+ testMode(false)
+ {}
+
+ std::string username;
+ std::string password;
+ std::string character;
+ std::string brandingPath;
+ std::string updateHost;
+ std::string dataPath;
+ std::string homeDir;
+ std::string logFileName;
+ std::string chatLogDir;
+ std::string configDir;
+ std::string localDataDir;
+ std::string screenshotDir;
+ std::string test;
+ std::string serverName;
+ uint16_t serverPort;
+ bool printHelp;
+ bool printVersion;
+ bool skipUpdate;
+ bool chooseDefault;
+ bool noOpenGL;
+ bool safeMode;
+ bool testMode;
+};
+
+#endif // OPTIONS_H