From 82183b30b62e3bc9030e30bbfafdde3846ad9856 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 15 Oct 2010 22:49:12 +0300 Subject: Add portable support for windows version. Add portable option to windows installer. Reviewed-by: Thorbjorn --- packaging/windows/portable.xml | 6 +++++ packaging/windows/setup.nsi | 6 +++++ src/client.cpp | 60 ++++++++++++++++++++++++++++++++++++++++-- src/client.h | 2 ++ 4 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 packaging/windows/portable.xml diff --git a/packaging/windows/portable.xml b/packaging/windows/portable.xml new file mode 100644 index 00000000..0059d109 --- /dev/null +++ b/packaging/windows/portable.xml @@ -0,0 +1,6 @@ + + + diff --git a/packaging/windows/setup.nsi b/packaging/windows/setup.nsi index 9c620f35..602fc29f 100644 --- a/packaging/windows/setup.nsi +++ b/packaging/windows/setup.nsi @@ -229,6 +229,11 @@ Section /o "Music" SecMusic Delete "$TEMP\tmwmusic-0.2.tar.gz" SectionEnd +Section /o "Portable" SecPortable + SetOutPath "$INSTDIR" + File "portable.xml" +SectionEnd + Section "Translations" SecTrans SetOutPath "$INSTDIR" File /nonfatal /r "${SRCDIR}\translations" @@ -238,6 +243,7 @@ SectionEnd !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN !insertmacro MUI_DESCRIPTION_TEXT ${SecCore} "The core program files." !insertmacro MUI_DESCRIPTION_TEXT ${SecMusic} "Background music. (If selected the music will be downloaded from the internet.)" + !insertmacro MUI_DESCRIPTION_TEXT ${SecPortable} "Portable client. (If selected client will work as portable client.)" !insertmacro MUI_DESCRIPTION_TEXT ${SecTrans} "Translations for the user interface into 23 different languages. Uncheck this component to leave it in English." !insertmacro MUI_FUNCTION_DESCRIPTION_END 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); diff --git a/src/client.h b/src/client.h index 3c52ea37..f44d8bf2 100644 --- a/src/client.h +++ b/src/client.h @@ -182,6 +182,7 @@ public: void action(const gcn::ActionEvent &event); private: + void initRootDir(); void initHomeDir(); void initConfiguration(); void initUpdatesDir(); @@ -199,6 +200,7 @@ private: std::string mUpdateHost; std::string mUpdatesDir; std::string mScreenshotDir; + std::string mRootDir; ServerInfo mCurrentServer; -- cgit v1.2.3-70-g09d2