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/client.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/client.cpp') diff --git a/src/client.cpp b/src/client.cpp index cf1a6496..5651f968 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -205,7 +205,10 @@ Client::Client(const Options &options): mInstance = this; // Load branding information - branding.init("data/branding.xml"); + if (!options.brandingPath.empty()) + { + branding.init(options.brandingPath); + } initHomeDir(options); initScreenshotDir(options.screenshotDir); -- cgit v1.2.3-70-g09d2 From 2ebd55fdcd7e177be150f9c5bdd1cbff9b110ad3 Mon Sep 17 00:00:00 2001 From: Bernd Wachter Date: Thu, 25 Feb 2010 14:50:23 +0100 Subject: Use recursive mkdir for config directories, fix log initialization Logger now logs to stdout by default, and allows logging without having a log file open. This allows using logger for error logging in early startup functions. Reviewed-by: Jared Adams --- mana.cbp | 2 ++ mana.files | 2 ++ src/CMakeLists.txt | 2 ++ src/Makefile.am | 2 ++ src/client.cpp | 14 +++++--------- src/log.cpp | 12 +++++------- 6 files changed, 18 insertions(+), 16 deletions(-) (limited to 'src/client.cpp') diff --git a/mana.cbp b/mana.cbp index 8282351c..82c08cc1 100644 --- a/mana.cbp +++ b/mana.cbp @@ -575,6 +575,8 @@ + + diff --git a/mana.files b/mana.files index 9551ae31..ed1605b0 100644 --- a/mana.files +++ b/mana.files @@ -517,6 +517,8 @@ ./src/utils/dtor.h ./src/utils/gettext.h ./src/utils/mathutils.h +./src/utils/mkdir.cpp +./src/utils/mkdir.h ./src/utils/mutex.h ./src/utils/sha256.cpp ./src/utils/sha256.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5cfbd1f0..ed579993 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -386,6 +386,8 @@ SET(SRCS utils/stringutils.cpp utils/stringutils.h utils/mutex.h + utils/mkdir.cpp + utils/mkdir.h utils/xml.cpp utils/xml.h animatedsprite.cpp diff --git a/src/Makefile.am b/src/Makefile.am index e7dc3685..a9ac7dff 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -286,6 +286,8 @@ mana_SOURCES = gui/widgets/avatarlistbox.cpp \ utils/dtor.h \ utils/gettext.h \ utils/mathutils.h \ + utils/mkdir.cpp \ + utils/mkdir.h \ utils/sha256.cpp \ utils/sha256.h \ utils/stringutils.cpp \ diff --git a/src/client.cpp b/src/client.cpp index 5651f968..9ef6bc96 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -73,6 +73,7 @@ #include "resources/resourcemanager.h" #include "utils/gettext.h" +#include "utils/mkdir.h" #include "utils/stringutils.h" #ifdef __APPLE__ @@ -204,6 +205,8 @@ Client::Client(const Options &options): assert(!mInstance); mInstance = this; + logger = new Logger; + // Load branding information if (!options.brandingPath.empty()) { @@ -214,7 +217,6 @@ Client::Client(const Options &options): initScreenshotDir(options.screenshotDir); // Configure logger - logger = new Logger; logger->setLogFile(homeDir + std::string("/mana.log")); // Log the mana version @@ -970,14 +972,8 @@ void Client::initHomeDir(const Options &options) "/." + branding.getValue("appShort", "mana"); #endif } -#if defined WIN32 - if (!CreateDirectory(homeDir.c_str(), 0) && - GetLastError() != ERROR_ALREADY_EXISTS) -#else - // Create home directory if it doesn't exist already - if ((mkdir(homeDir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) && - (errno != EEXIST)) -#endif + + if (mkdir_r(homeDir.c_str())) { logger->error(strprintf(_("%s doesn't exist and can't be created! " "Exiting."), homeDir.c_str())); diff --git a/src/log.cpp b/src/log.cpp index 432d1b04..ba1610fd 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -35,7 +35,7 @@ #include Logger::Logger(): - mLogToStandardOut(false), + mLogToStandardOut(true), mChatWindow(NULL) { } @@ -61,11 +61,6 @@ void Logger::setLogFile(const std::string &logFilename) void Logger::log(const char *log_text, ...) { - if (!mLogFile.is_open()) - { - return; - } - char* buf = new char[1024]; va_list ap; @@ -94,7 +89,10 @@ void Logger::log(const char *log_text, ...) << (int)((tv.tv_usec / 10000) % 100) << "] "; - mLogFile << timeStr.str() << buf << std::endl; + if (mLogFile.is_open()) + { + mLogFile << timeStr.str() << buf << std::endl; + } if (mLogToStandardOut) { -- 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/client.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 81c9926450abe3635ffc9c976571415c8c1873ef Mon Sep 17 00:00:00 2001 From: Bernd Wachter Date: Fri, 26 Feb 2010 01:11:03 +0100 Subject: Use MYPICTURES on windows, add config parameter for screenshot directory Under Windows try to place the screenshots in the `My Pictures' directory, and use Desktop as a fallback. On all platforms, add a Suffix to the screenshot directory path to avoid cluttering the Desktop/... Usage of suffix/suffix content/path are configurable. Create the screenshot directory if it does not exist, and fall back to saving screenshots in the users home directory if it could not be created. Reviewed-by: Jared Adams --- src/client.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 47 insertions(+), 9 deletions(-) (limited to 'src/client.cpp') diff --git a/src/client.cpp b/src/client.cpp index eca63ce4..cd40615b 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -215,7 +215,6 @@ Client::Client(const Options &options): } initHomeDir(options); - initScreenshotDir(options.screenshotDir); // Configure logger logger->setLogFile(localDataDir + std::string("/mana.log")); @@ -224,6 +223,8 @@ Client::Client(const Options &options): logger->log("Mana %s", FULL_VERSION); initConfiguration(options); + initScreenshotDir(options.screenshotDir); + logger->setLogToStandardOut(config.getValue("logToStandardOut", 0)); // Initialize SDL @@ -1037,6 +1038,7 @@ void Client::initConfiguration(const Options &options) "http://updates.themanaworld.org"); config.setValue("updatehost", defaultUpdateHost); config.setValue("customcursor", true); + config.setValue("useScreenshotDirectorySuffix", true); config.setValue("ChatLogLength", 128); // Checking if the configuration file exists... otherwise create it with @@ -1146,16 +1148,52 @@ void Client::initUpdatesDir() void Client::initScreenshotDir(const std::string &dir) { - if (dir.empty()) + if (!dir.empty()) + screenshotDir = dir; + else + { + std::string configScreenshotDir = + config.getValue("screenshotDirectory", ""); + if (!configScreenshotDir.empty()) + screenshotDir = configScreenshotDir; + else + { +#ifdef WIN32 + screenshotDir = getSpecialFolderLocation(CSIDL_MYPICTURES); + if (screenshotDir.empty()) + screenshotDir = getSpecialFolderLocation(CSIDL_DESKTOP); +#else + screenshotDir = std::string(PHYSFS_getUserDir()) + "Desktop"; + // If ~/Desktop does not exist, we save screenshots in the user's home. + struct stat statbuf; + if (stat(screenshotDir.c_str(), &statbuf)) + screenshotDir = std::string(PHYSFS_getUserDir()); +#endif + } + config.setValue("screenshotDirectory", screenshotDir); + + if (config.getValue("useScreenshotDirectorySuffix", true)) + { + std::string configScreenshotSuffix = + config.getValue("screenshotDirectorySuffix", + branding.getValue("appShort", "Mana")); + + if (!configScreenshotSuffix.empty()) + { + screenshotDir += "/" + configScreenshotSuffix; + config.setValue("screenshotDirectorySuffix", + configScreenshotSuffix); + } + } + } + + if (mkdir_r(screenshotDir.c_str())) { - screenshotDir = std::string(PHYSFS_getUserDir()) + "Desktop"; - // If ~/Desktop does not exist, we save screenshots in the user's home. - struct stat statbuf; - if (stat(screenshotDir.c_str(), &statbuf)) - screenshotDir = std::string(PHYSFS_getUserDir()); + logger->log("Directory %s doesn't exist and can't be created! " + "Setting screenshot directory to home.", + screenshotDir.c_str()); + screenshotDir = std::string(PHYSFS_getUserDir()); } - else - screenshotDir = dir; } void Client::accountLogin(LoginData *loginData) -- cgit v1.2.3-70-g09d2