diff options
author | Andrei Karas <akaras@inbox.ru> | 2010-10-15 22:49:12 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2010-10-18 23:52:48 +0300 |
commit | 82183b30b62e3bc9030e30bbfafdde3846ad9856 (patch) | |
tree | f9888551f57adc0aa8c63b438eba46c54eefae64 /src/client.cpp | |
parent | 11c6210b6190111657f7cccf33187ac4d7050a1f (diff) | |
download | mana-82183b30b62e3bc9030e30bbfafdde3846ad9856.tar.gz mana-82183b30b62e3bc9030e30bbfafdde3846ad9856.tar.bz2 mana-82183b30b62e3bc9030e30bbfafdde3846ad9856.tar.xz mana-82183b30b62e3bc9030e30bbfafdde3846ad9856.zip |
Add portable support for windows version.
Add portable option to windows installer.
Reviewed-by: Thorbjorn
Diffstat (limited to 'src/client.cpp')
-rw-r--r-- | src/client.cpp | 60 |
1 files changed, 58 insertions, 2 deletions
diff --git a/src/client.cpp b/src/client.cpp index 0b62a48d..2681a254 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -195,6 +195,7 @@ Client *Client::mInstance = 0; Client::Client(const Options &options): mOptions(options), + mRootDir(""), mCurrentDialog(0), mQuitDialog(0), mDesktop(0), @@ -217,6 +218,7 @@ Client::Client(const Options &options): branding.init(options.brandingPath); } + initRootDir(); initHomeDir(); initConfiguration(); @@ -1001,6 +1003,57 @@ void Client::action(const gcn::ActionEvent &event) } } +void Client::initRootDir() +{ + mRootDir = PHYSFS_getBaseDir(); +#ifdef WIN32 + std::string portableName = mRootDir + "portable.xml"; + struct stat statbuf; + + if (!stat(portableName.c_str(), &statbuf) && S_ISREG(statbuf.st_mode)) + { + std::string dir; + Configuration portable; + portable.init(portableName); + + logger->log("Portable file: %s", portableName.c_str()); + + if (mOptions.localDataDir.empty()) + { + dir = portable.getValue("dataDir", ""); + if (!dir.empty()) + { + mOptions.localDataDir = mRootDir + dir; + logger->log("Portable data dir: %s", + mOptions.localDataDir.c_str()); + } + } + + if (mOptions.configDir.empty()) + { + dir = portable.getValue("configDir", ""); + if (!dir.empty()) + { + mOptions.configDir = mRootDir + dir; + logger->log("Portable config dir: %s", + mOptions.configDir.c_str()); + } + } + + if (mOptions.screenshotDir.empty()) + { + dir = portable.getValue("screenshotDir", ""); + if (!dir.empty()) + { + mOptions.screenshotDir = mRootDir + dir; + logger->log("Portable screenshot dir: %s", + mOptions.screenshotDir.c_str()); + } + } + } +#endif +} + /** * Initializes the home directory. On UNIX and FreeBSD, ~/.mana is used. On * Windows and other systems we use the current working directory. @@ -1062,7 +1115,8 @@ void Client::initHomeDir() { std::string oldConfigFile = std::string(PHYSFS_getUserDir()) + "/.tmw/config.xml"; - if (!stat(oldConfigFile.c_str(), &statbuf) && S_ISREG(statbuf.st_mode)) + if (mRootDir.empty() && !stat(oldConfigFile.c_str(), &statbuf) + && S_ISREG(statbuf.st_mode)) { std::ifstream oldConfig; std::ofstream newConfig; @@ -1220,8 +1274,10 @@ void Client::initUpdatesDir() void Client::initScreenshotDir() { if (!mOptions.screenshotDir.empty()) + { mScreenshotDir = mOptions.screenshotDir; - else + } + else if (mScreenshotDir.empty()) { #ifdef WIN32 mScreenshotDir = getSpecialFolderLocation(CSIDL_MYPICTURES); |