summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2010-10-15 22:49:12 +0300
committerAndrei Karas <akaras@inbox.ru>2010-10-18 23:52:48 +0300
commit82183b30b62e3bc9030e30bbfafdde3846ad9856 (patch)
treef9888551f57adc0aa8c63b438eba46c54eefae64
parent11c6210b6190111657f7cccf33187ac4d7050a1f (diff)
downloadmana-client-82183b30b62e3bc9030e30bbfafdde3846ad9856.tar.gz
mana-client-82183b30b62e3bc9030e30bbfafdde3846ad9856.tar.bz2
mana-client-82183b30b62e3bc9030e30bbfafdde3846ad9856.tar.xz
mana-client-82183b30b62e3bc9030e30bbfafdde3846ad9856.zip
Add portable support for windows version.
Add portable option to windows installer. Reviewed-by: Thorbjorn
-rw-r--r--packaging/windows/portable.xml6
-rw-r--r--packaging/windows/setup.nsi6
-rw-r--r--src/client.cpp60
-rw-r--r--src/client.h2
4 files changed, 72 insertions, 2 deletions
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 @@
+<?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.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;