summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client.cpp66
-rw-r--r--src/client.h14
-rw-r--r--src/gui/recorder.cpp2
-rw-r--r--src/main.cpp14
4 files changed, 64 insertions, 32 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 9ef6bc96..eca63ce4 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -85,6 +85,7 @@
#ifdef WIN32
#include <SDL_syswm.h>
+#include "utils/specialfolder.h"
#else
#include <cerrno>
#endif
@@ -217,7 +218,7 @@ Client::Client(const Options &options):
initScreenshotDir(options.screenshotDir);
// Configure logger
- logger->setLogFile(homeDir + std::string("/mana.log"));
+ logger->setLogFile(localDataDir + std::string("/mana.log"));
// Log the mana version
logger->log("Mana %s", FULL_VERSION);
@@ -241,14 +242,14 @@ Client::Client(const Options &options):
ResourceManager *resman = ResourceManager::getInstance();
- if (!resman->setWriteDir(homeDir))
+ if (!resman->setWriteDir(localDataDir))
{
logger->error(strprintf("%s couldn't be set as home directory! "
- "Exiting.", homeDir.c_str()));
+ "Exiting.", localDataDir.c_str()));
}
- // Add the user's homedir to PhysicsFS search path
- resman->addToSearchPath(homeDir, false);
+ // Add the local data directory to PhysicsFS search path
+ resman->addToSearchPath(localDataDir, false);
// Add the main data directories to our PhysicsFS search path
if (!options.dataPath.empty())
@@ -580,7 +581,7 @@ int Client::exec()
SkinLoader::instance()->setMinimumOpacity(0.8f);
currentDialog = new ServerDialog(&currentServer,
- homeDir);
+ configDir);
}
else
{
@@ -675,7 +676,7 @@ int Client::exec()
{
logger->log("State: UPDATE");
currentDialog = new UpdaterWindow(updateHost,
- homeDir + "/" + updatesDir,options.dataPath.empty());
+ localDataDir + "/" + updatesDir,options.dataPath.empty());
}
break;
@@ -958,25 +959,53 @@ void Client::action(const gcn::ActionEvent &event)
*/
void Client::initHomeDir(const Options &options)
{
- homeDir = options.homeDir;
+ localDataDir = options.localDataDir;
- if (homeDir.empty())
+ if (localDataDir.empty())
{
#ifdef __APPLE__
// Use Application Directory instead of .mana
- homeDir = std::string(PHYSFS_getUserDir()) +
+ localDataDir = std::string(PHYSFS_getUserDir()) +
"/Library/Application Support/" +
branding.getValue("appName", "Mana");
+#elif defined WIN32
+ localDataDir = getSpecialFolderLocation(CSIDL_LOCAL_APPDATA);
+ if (localDataDir.empty())
+ localDataDir = std::string(PHYSFS_getUserDir());
+ localDataDir += "/Mana";
#else
- homeDir = std::string(PHYSFS_getUserDir()) +
- "/." + branding.getValue("appShort", "mana");
+ localDataDir = std::string(PHYSFS_getUserDir()) +
+ "/.local/share/mana";
#endif
}
- if (mkdir_r(homeDir.c_str()))
+ if (mkdir_r(localDataDir.c_str()))
{
logger->error(strprintf(_("%s doesn't exist and can't be created! "
- "Exiting."), homeDir.c_str()));
+ "Exiting."), localDataDir.c_str()));
+ }
+
+ configDir = options.configDir;
+
+ if (configDir.empty()){
+#ifdef __APPLE__
+ configDir = localDataDir;
+#elif defined WIN32
+ configDir = getSpecialFolderLocation(CSIDL_APPDATA);
+ if (configDir.empty())
+ configDir = localDataDir;
+ else
+ configDir += "/mana/" + branding.getValue("appName", "Mana");
+#else
+ configDir = std::string(PHYSFS_getUserDir()) +
+ "/.config/mana/" + branding.getValue("appShort", "mana");
+#endif
+ }
+
+ if (mkdir_r(configDir.c_str()))
+ {
+ logger->error(strprintf(_("%s doesn't exist and can't be created! "
+ "Exiting."), configDir.c_str()));
}
}
@@ -1013,10 +1042,9 @@ void Client::initConfiguration(const Options &options)
// Checking if the configuration file exists... otherwise create it with
// default options.
FILE *configFile = 0;
- std::string configPath = options.configPath;
+ std::string configPath;
- if (configPath.empty())
- configPath = homeDir + "/config.xml";
+ configPath = configDir + "/config.xml";
configFile = fopen(configPath.c_str(), "r");
@@ -1089,7 +1117,7 @@ void Client::initUpdatesDir()
if (!resman->mkdir("/" + updatesDir))
{
#if defined WIN32
- std::string newDir = homeDir + "\\" + updatesDir;
+ std::string newDir = localDataDir + "\\" + updatesDir;
std::string::size_type loc = newDir.find("/", 0);
while (loc != std::string::npos)
@@ -1108,7 +1136,7 @@ void Client::initUpdatesDir()
}
#else
logger->log("Error: %s/%s can't be made, but doesn't exist!",
- homeDir.c_str(), updatesDir.c_str());
+ localDataDir.c_str(), updatesDir.c_str());
errorMessage = _("Error creating updates directory!");
state = STATE_ERROR;
#endif
diff --git a/src/client.h b/src/client.h
index 32b921dc..f0fdd508 100644
--- a/src/client.h
+++ b/src/client.h
@@ -138,11 +138,11 @@ public:
std::string username;
std::string password;
std::string character;
- std::string configPath;
std::string brandingPath;
std::string updateHost;
std::string dataPath;
- std::string homeDir;
+ std::string configDir;
+ std::string localDataDir;
std::string screenshotDir;
std::string serverName;
@@ -165,8 +165,11 @@ public:
static State getState()
{ return instance()->state; }
- static const std::string &getHomeDirectory()
- { return instance()->homeDir; }
+ static const std::string &getConfigDirectory()
+ { return instance()->configDir; }
+
+ static const std::string &getLocalDataDirectory()
+ { return instance()->localDataDir; }
static const std::string &getScreenshotDirectory()
{ return instance()->screenshotDir; }
@@ -186,7 +189,8 @@ private:
Options options;
- std::string homeDir;
+ std::string configDir;
+ std::string localDataDir;
std::string updateHost;
std::string updatesDir;
std::string screenshotDir;
diff --git a/src/gui/recorder.cpp b/src/gui/recorder.cpp
index 7cb6e055..257afd7f 100644
--- a/src/gui/recorder.cpp
+++ b/src/gui/recorder.cpp
@@ -102,7 +102,7 @@ void Recorder::setRecordingFile(const std::string &msg)
* recorded.
*/
localChatTab->chatLog(_("Starting to record..."), BY_SERVER);
- const std::string file = Client::getHomeDirectory() + msgCopy;
+ const std::string file = Client::getLocalDataDirectory() + "/" + msgCopy;
mStream.open(file.c_str(), std::ios_base::trunc);
diff --git a/src/main.cpp b/src/main.cpp
index 49122ccf..247cda3d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -44,7 +44,7 @@ static void printHelp()
<< _("Options:") << endl
<< _(" -v --version : Display the version") << endl
<< _(" -h --help : Display this help") << endl
- << _(" -C --config-file : Configuration file to use") << endl
+ << _(" -C --config-dir : Configuration directory to use") << endl
<< _(" -U --username : Login with this username") << endl
<< _(" -P --password : Login with this password") << endl
<< _(" -c --character : Login with this character") << endl
@@ -55,7 +55,7 @@ static void printHelp()
"character") << endl
<< _(" -u --skip-update : Skip the update downloads") << endl
<< _(" -d --data : Directory to load game data from") << endl
- << _(" --home-dir : Directory to use as home directory") << endl
+ << _(" -L --localdata-dir : Directory to use as local data directory") << endl
<< _(" --screenshot-dir : Directory to store screenshots") << endl
#ifdef USE_OPENGL
<< _(" --no-opengl : Disable OpenGL for this session") << endl;
@@ -69,16 +69,16 @@ static void printVersion()
static void parseOptions(int argc, char *argv[], Client::Options &options)
{
- const char *optstring = "hvud:U:P:Dc:p:C:S:";
+ const char *optstring = "hvud:U:P:Dc:p:C:L:";
const struct option long_options[] = {
- { "config-file", required_argument, 0, 'C' },
+ { "config-dir", required_argument, 0, 'C' },
{ "data", required_argument, 0, 'd' },
{ "default", no_argument, 0, 'D' },
{ "password", required_argument, 0, 'P' },
{ "character", required_argument, 0, 'c' },
{ "help", no_argument, 0, 'h' },
- { "home-dir", required_argument, 0, 'S' },
+ { "localdata-dir", required_argument, 0, 'L' },
{ "update-host", required_argument, 0, 'H' },
{ "port", required_argument, 0, 'p' },
{ "server", required_argument, 0, 's' },
@@ -100,7 +100,7 @@ static void parseOptions(int argc, char *argv[], Client::Options &options)
switch (result)
{
case 'C':
- options.configPath = optarg;
+ options.configDir = optarg;
break;
case 'd':
options.dataPath = optarg;
@@ -138,7 +138,7 @@ static void parseOptions(int argc, char *argv[], Client::Options &options)
options.printVersion = true;
break;
case 'S':
- options.homeDir = optarg;
+ options.localDataDir = optarg;
break;
case 'O':
options.noOpenGL = true;