rendered paste bodyFrom 3e25476d943886879491093ef9e4154717e70357 Mon Sep 17 00:00:00 2001From: Andrei Karas <akaras@inbox.ru>Date: Fri, 15 Oct 2010 22:49:12 +0300Subject: [PATCH] Add portable support for windows version.Add portable option to windows installer.--- 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.xmldiff --git a/packaging/windows/portable.xml b/packaging/windows/portable.xmlnew file mode 100644index 0000000..0059d10--- /dev/null+++ b/packaging/windows/portable.xml@@ -0,0 +1,6 @@+<?xml version="1.0"?>+<configuration>+ <option name="dataDir" value="logs"/>+ <option name="configDir" value="configs"/>+ <option name="screenshotDir" value="screenshots"/>+</configuration>diff --git a/packaging/windows/setup.nsi b/packaging/windows/setup.nsiindex 9c620f3..602fc29 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.cppindex 9bf761a..2898d51 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(); @@ -999,6 +1001,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.@@ -1060,7 +1113,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;@@ -1217,8 +1271,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.hindex 3c52ea3..f44d8bf 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; -- 1.7.2.3