From 4cb11db37aeb8052e1fef94965bc48bbc949e7f9 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Wed, 24 Feb 2010 21:51:48 +0100 Subject: Added the possibility to pass a branding file by command line. Reviewed-by: Thorbjørn Lindeijer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 2fb9c112..aaa826cb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,7 +40,7 @@ static void printHelp() using std::endl; std::cout - << _("mana") << endl << endl + << _("mana [mana-file]") << endl << endl << _("Options:") << endl << _(" -C --config-file : Configuration file to use") << endl << _(" -d --data : Directory to load game data from") << endl @@ -147,6 +147,15 @@ static void parseOptions(int argc, char *argv[], Client::Options &options) break; } } + + // when there are still options left use the last + // one as branding file + if (optind < argc) + { + options.brandingPath = argv[optind]; + } + + } #ifdef WIN32 -- cgit v1.2.3-70-g09d2 From 84cf9bcc38028696d02c03cd523b7997906b9f01 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Wed, 24 Feb 2010 22:32:36 +0100 Subject: Removed a bunch of short options from the command line parameters They don't have to be specified, so we can leave them out for rarely used options or those for which a single character is rather unclear. Also gave them a bit nicer order, since alphabetical doesn't make much sense. Reviewed-by: Jared Adams --- src/main.cpp | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index aaa826cb..49122ccf 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -40,26 +40,26 @@ static void printHelp() using std::endl; std::cout - << _("mana [mana-file]") << endl << endl + << _("mana [options] [mana-file]") << endl << endl << _("Options:") << endl - << _(" -C --config-file : Configuration file to use") << endl - << _(" -d --data : Directory to load game data from") << endl - << _(" -D --default : Choose default character server and " - "character") << endl + << _(" -v --version : Display the version") << endl << _(" -h --help : Display this help") << endl - << _(" -S --home-dir : Directory to use as home directory") << endl - << _(" -i --screenshot-dir : Directory to store screenshots") << endl - << _(" -H --update-host : Use this update host") << endl + << _(" -C --config-file : Configuration file to use") << endl + << _(" -U --username : Login with this username") << endl << _(" -P --password : Login with this password") << endl << _(" -c --character : Login with this character") << endl - << _(" -p --port : Login server port") << endl << _(" -s --server : Login server name or IP") << endl + << _(" -p --port : Login server port") << endl + << _(" --update-host : Use this update host") << endl + << _(" -D --default : Choose default character server and " + "character") << endl << _(" -u --skip-update : Skip the update downloads") << endl - << _(" -U --username : Login with this username") << endl + << _(" -d --data : Directory to load game data from") << endl + << _(" --home-dir : Directory to use as home directory") << endl + << _(" --screenshot-dir : Directory to store screenshots") << endl #ifdef USE_OPENGL - << _(" -O --no-opengl : Disable OpenGL for this session") << endl + << _(" --no-opengl : Disable OpenGL for this session") << endl; #endif - << _(" -v --version : Display the version") << endl; } static void printVersion() @@ -69,7 +69,7 @@ static void printVersion() static void parseOptions(int argc, char *argv[], Client::Options &options) { - const char *optstring = "hvud:U:P:Dc:s:p:C:H:S:Oi:"; + const char *optstring = "hvud:U:P:Dc:p:C:S:"; const struct option long_options[] = { { "config-file", required_argument, 0, 'C' }, @@ -108,7 +108,8 @@ static void parseOptions(int argc, char *argv[], Client::Options &options) case 'D': options.chooseDefault = true; break; - default: // Unknown option + case '?': // Unknown option + case ':': // Missing argument case 'h': options.printHelp = true; break; @@ -154,8 +155,6 @@ static void parseOptions(int argc, char *argv[], Client::Options &options) { options.brandingPath = argv[optind]; } - - } #ifdef WIN32 -- cgit v1.2.3-70-g09d2 From df86b2f74a1f42f1dcfa9f0c6c4a75b24fdf81de Mon Sep 17 00:00:00 2001 From: Bernd Wachter Date: Thu, 25 Feb 2010 21:56:31 +0100 Subject: Add support for platform specifig config/data directories #84 Reviewed-by: Jared Adams --- src/client.cpp | 66 +++++++++++++++++++++++++++++++++++++--------------- src/client.h | 14 +++++++---- src/gui/recorder.cpp | 2 +- src/main.cpp | 14 +++++------ 4 files changed, 64 insertions(+), 32 deletions(-) (limited to 'src/main.cpp') 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 +#include "utils/specialfolder.h" #else #include #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(¤tServer, - 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; -- cgit v1.2.3-70-g09d2 From 861b28494e8c0f8701c093f82f152c3bcdbae9fd Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Thu, 25 Feb 2010 22:33:43 +0100 Subject: Unbreak compile without OpenGL --- src/main.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 247cda3d..56019976 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -58,8 +58,9 @@ static void printHelp() << _(" -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; + << _(" --no-opengl : Disable OpenGL for this session") << endl #endif + ; } static void printVersion() -- cgit v1.2.3-70-g09d2