diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-06-16 01:39:44 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-06-16 02:24:22 +0300 |
commit | 654285675ececa142877d86e6f730d040625fc6e (patch) | |
tree | c57e7d21a3b61acd2e1a179152dcb909ce1ececa | |
parent | 103aa3f43e457ebfcd32fe5ea4624539dd32978d (diff) | |
download | mv-654285675ececa142877d86e6f730d040625fc6e.tar.gz mv-654285675ececa142877d86e6f730d040625fc6e.tar.bz2 mv-654285675ececa142877d86e6f730d040625fc6e.tar.xz mv-654285675ececa142877d86e6f730d040625fc6e.zip |
Add dataPath to branding.
-rw-r--r-- | src/client.cpp | 36 | ||||
-rw-r--r-- | src/configuration.cpp | 13 | ||||
-rw-r--r-- | src/configuration.h | 4 | ||||
-rw-r--r-- | src/defaults.cpp | 1 | ||||
-rw-r--r-- | src/main.cpp | 3 | ||||
-rw-r--r-- | src/utils/stringutils.cpp | 10 | ||||
-rw-r--r-- | src/utils/stringutils.h | 2 |
7 files changed, 55 insertions, 14 deletions
diff --git a/src/client.cpp b/src/client.cpp index bba55a960..be3d20373 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -257,16 +257,16 @@ Client::Client(const Options &options): logger = new Logger; // Load branding information - if (!options.brandingPath.empty()) - branding.init(options.brandingPath); + if (!mOptions.brandingPath.empty()) + branding.init(mOptions.brandingPath); branding.setDefaultValues(getBrandingDefaults()); initRootDir(); initHomeDir(); // Configure logger - if (!options.logFileName.empty()) - logger->setLogFile(options.logFileName); + if (!mOptions.logFileName.empty()) + logger->setLogFile(mOptions.logFileName); else logger->setLogFile(mLocalDataDir + std::string("/manaplus.log")); @@ -276,10 +276,10 @@ Client::Client(const Options &options): storeSafeParameters(); chatLogger = new ChatLogger; - if (options.chatLogDir == "") + if (mOptions.chatLogDir == "") chatLogger->setLogDir(mLocalDataDir + std::string("/logs/")); else - chatLogger->setLogDir(options.chatLogDir); + chatLogger->setLogDir(mOptions.chatLogDir); logger->setLogToStandardOut(config.getBoolValue("logToStandardOut")); @@ -344,9 +344,9 @@ Client::Client(const Options &options): resman->addToSearchPath("data", false); // Add branding/data to PhysFS search path - if (!options.brandingPath.empty()) + if (!mOptions.brandingPath.empty()) { - std::string path = options.brandingPath; + std::string path = mOptions.brandingPath; // Strip blah.mana from the path #ifdef WIN32 @@ -360,9 +360,17 @@ Client::Client(const Options &options): resman->addToSearchPath(path.substr(0, loc + 1) + "data", false); } + if (mOptions.dataPath.empty() + && !branding.getStringValue("dataPath").empty()) + { + mOptions.dataPath = branding.getDirectory() + "/" + + branding.getStringValue("dataPath"); + mOptions.skipUpdate = true; + } + // Add the main data directories to our PhysicsFS search path - if (!options.dataPath.empty()) - resman->addToSearchPath(options.dataPath, false); + if (!mOptions.dataPath.empty()) + resman->addToSearchPath(mOptions.dataPath, false); // Add the local data directory to PhysicsFS search path resman->addToSearchPath(mLocalDataDir, false); @@ -489,11 +497,11 @@ Client::Client(const Options &options): sound.playMusic(branding.getValue("loginMusic", "Magick - Real.ogg")); // Initialize default server - mCurrentServer.hostname = options.serverName; - mCurrentServer.port = options.serverPort; + mCurrentServer.hostname = mOptions.serverName; + mCurrentServer.port = mOptions.serverPort; - loginData.username = options.username; - loginData.password = options.password; + loginData.username = mOptions.username; + loginData.password = mOptions.password; loginData.remember = serverConfig.getValue("remember", 0); loginData.registerLogin = false; diff --git a/src/configuration.cpp b/src/configuration.cpp index abeb4b2af..7969c9341 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -30,6 +30,11 @@ #include <libxml/encoding.h> +#include <stdlib.h> +#ifdef WIN32 +#define realpath(N,R) _fullpath((R),(N),_MAX_PATH) +#endif + #include "debug.h" #ifdef DEBUG_CONFIG @@ -388,9 +393,17 @@ void Configuration::init(const std::string &filename, bool useResManager) XML::Document doc(filename, useResManager); if (useResManager) + { mConfigPath = "PhysFS://" + filename; + mDirectory = ""; + } else + { mConfigPath = filename; + char *realPath = realpath(getFileDir(filename).c_str(), NULL); + mDirectory = realPath; + free(realPath); + } if (!doc.rootNode()) { diff --git a/src/configuration.h b/src/configuration.h index a0a790990..64c60c734 100644 --- a/src/configuration.h +++ b/src/configuration.h @@ -282,6 +282,9 @@ class Configuration : public ConfigurationObject std::string getStringValue(const std::string &key) const; bool getBoolValue(const std::string &key) const; + std::string getDirectory() const + { return mDirectory; } + private: /** * Clean up the default values member. @@ -297,6 +300,7 @@ class Configuration : public ConfigurationObject std::string mConfigPath; /**< Location of config file */ DefaultsData *mDefaultsData; /**< Defaults of value for a given key */ + std::string mDirectory; }; extern Configuration branding; diff --git a/src/defaults.cpp b/src/defaults.cpp index e5a57d9ff..222b73766 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -238,6 +238,7 @@ DefaultsData* getBrandingDefaults() AddDEF(brandingData, "fontsPath", "fonts/"); AddDEF(brandingData, "wallpaperFile", ""); + AddDEF(brandingData, "dataPath", ""); return brandingData; } diff --git a/src/main.cpp b/src/main.cpp index 0f9b0f217..5f565a091 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -265,6 +265,9 @@ int main(int argc, char *argv[]) initXML(); +#ifdef WIN32 + SetCurrentDirectory(PHYSFS_getBaseDir()); +#endif Client client(options); return client.exec(); } diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index dffec3f0c..953cbf58a 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -305,6 +305,16 @@ std::string getFileName(std::string path) return path.substr(pos + 1); } +std::string getFileDir(std::string path) +{ + size_t pos = path.rfind("/"); + if (pos == std::string::npos) + pos = path.rfind("\\"); + if (pos == std::string::npos) + return ""; + return path.substr(0, pos); +} + std::string& replaceAll(std::string& context, const std::string& from, const std::string& to) { diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 796df92c5..140baf944 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -149,6 +149,8 @@ void getSafeUtf8String(std::string text, char *buf); std::string getFileName(std::string path); +std::string getFileDir(std::string path); + std::string& replaceAll(std::string& context, const std::string& from, const std::string& to); |