diff options
author | Bertram <bertram@cegetel.net> | 2010-03-03 23:38:18 +0100 |
---|---|---|
committer | Bertram <bertram@cegetel.net> | 2010-03-03 23:38:18 +0100 |
commit | 1e52781e7d425cffcc6a5319b4cb5bf5eebe2ea9 (patch) | |
tree | 596305e9bfd4ad8448efd477a43f86490b1974c5 /src/client.cpp | |
parent | 8cc31b582f372238ce6bd2c86888d312cf1fe5b2 (diff) | |
parent | f5f7a7d5990d1133f714b6cd431aecf6a332fbd5 (diff) | |
download | mana-1e52781e7d425cffcc6a5319b4cb5bf5eebe2ea9.tar.gz mana-1e52781e7d425cffcc6a5319b4cb5bf5eebe2ea9.tar.bz2 mana-1e52781e7d425cffcc6a5319b4cb5bf5eebe2ea9.tar.xz mana-1e52781e7d425cffcc6a5319b4cb5bf5eebe2ea9.zip |
Merge branch 'master' of gitorious.org:mana/mana
Diffstat (limited to 'src/client.cpp')
-rw-r--r-- | src/client.cpp | 427 |
1 files changed, 216 insertions, 211 deletions
diff --git a/src/client.cpp b/src/client.cpp index cd40615b..dfa42034 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -192,13 +192,14 @@ public: Client *Client::mInstance = 0; Client::Client(const Options &options): - options(options), - currentDialog(0), - quitDialog(0), - desktop(0), - setupButton(0), - state(STATE_CHOOSE_SERVER), - oldstate(STATE_START), + mOptions(options), + mCurrentDialog(0), + mQuitDialog(0), + mDesktop(0), + mSetupButton(0), + mState(STATE_CHOOSE_SERVER), + mOldState(STATE_START), + mIcon(0), mLogicCounterId(0), mSecondsCounterId(0), mLimitFps(false) @@ -214,18 +215,17 @@ Client::Client(const Options &options): branding.init(options.brandingPath); } - initHomeDir(options); + initHomeDir(); + initConfiguration(); // Configure logger - logger->setLogFile(localDataDir + std::string("/mana.log")); + logger->setLogFile(mLocalDataDir + std::string("/mana.log")); + logger->setLogToStandardOut(config.getValue("logToStandardOut", 0)); // Log the mana version logger->log("Mana %s", FULL_VERSION); - initConfiguration(options); - initScreenshotDir(options.screenshotDir); - - logger->setLogToStandardOut(config.getValue("logToStandardOut", 0)); + initScreenshotDir(); // Initialize SDL logger->log("Initializing SDL..."); @@ -243,19 +243,12 @@ Client::Client(const Options &options): ResourceManager *resman = ResourceManager::getInstance(); - if (!resman->setWriteDir(localDataDir)) + if (!resman->setWriteDir(mLocalDataDir)) { logger->error(strprintf("%s couldn't be set as home directory! " - "Exiting.", localDataDir.c_str())); + "Exiting.", mLocalDataDir.c_str())); } - // 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()) - resman->addToSearchPath(options.dataPath, true); - resman->addToSearchPath("data", true); #if defined __APPLE__ CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); @@ -267,10 +260,38 @@ Client::Client(const Options &options): } CFRelease(resourcesURL); strncat(path, "/data", PATH_MAX - 1); - resman->addToSearchPath(path, true); + resman->addToSearchPath(path, false); + mPackageDir = path; +#else + resman->addToSearchPath(PKG_DATADIR "data", false); + mPackageDir = PKG_DATADIR "data"; +#endif + + resman->addToSearchPath("data", false); + + // Add branding/data to PhysFS search path + if (!options.brandingPath.empty()) + { + std::string path = options.brandingPath; + + // Strip blah.mana from the path +#ifdef WIN32 + int loc1 = path.find_last_of('/'); + int loc2 = path.find_last_of('\\'); + int loc = std::max(loc1, loc2); #else - resman->addToSearchPath(PKG_DATADIR "data", true); + int loc = path.find_last_of('/'); #endif + if (loc > 0) + resman->addToSearchPath(path.substr(0, loc + 1) + "data", false); + } + + // Add the main data directories to our PhysicsFS search path + if (!options.dataPath.empty()) + resman->addToSearchPath(options.dataPath, false); + + // Add the local data directory to PhysicsFS search path + resman->addToSearchPath(mLocalDataDir, false); #ifdef WIN32 static SDL_SysWMinfo pInfo; @@ -281,17 +302,17 @@ Client::Client(const Options &options): SetClassLong(pInfo.window, GCL_HICON, (LONG) icon); } #else - icon = IMG_Load(resman->getPath( + mIcon = IMG_Load(resman->getPath( branding.getValue("appIcon", "data/icons/mana.png")).c_str()); - if (icon) + if (mIcon) { - SDL_SetAlpha(icon, SDL_SRCALPHA, SDL_ALPHA_OPAQUE); - SDL_WM_SetIcon(icon, NULL); + SDL_SetAlpha(mIcon, SDL_SRCALPHA, SDL_ALPHA_OPAQUE); + SDL_WM_SetIcon(mIcon, NULL); } #endif #ifdef USE_OPENGL - bool useOpenGL = !options.noOpenGL && (config.getValue("opengl", 0) == 1); + bool useOpenGL = !mOptions.noOpenGL && (config.getValue("opengl", 0) == 1); // Setup image loading for the right image format Image::setLoadAsOpenGL(useOpenGL); @@ -319,10 +340,10 @@ Client::Client(const Options &options): // Initialize for drawing graphics->_beginDraw(); - // Initialize the item shortcuts. - itemShortcut = new ItemShortcut; + SkinLoader::prepareThemePath(); - // Initialize the emote shortcuts. + // Initialize the item and emote shortcuts. + itemShortcut = new ItemShortcut; emoteShortcut = new EmoteShortcut; gui = new Gui(graphics); @@ -340,7 +361,7 @@ Client::Client(const Options &options): } catch (const char *err) { - state = STATE_ERROR; + mState = STATE_ERROR; errorMessage = err; logger->log("Warning: %s", err); } @@ -357,28 +378,28 @@ Client::Client(const Options &options): sound.playMusic(branding.getValue("loginMusic", "Magick - Real.ogg")); // Initialize default server - currentServer.hostname = options.serverName; - currentServer.port = options.serverPort; + mCurrentServer.hostname = options.serverName; + mCurrentServer.port = options.serverPort; loginData.username = options.username; loginData.password = options.password; loginData.remember = config.getValue("remember", 0); loginData.registerLogin = false; - if (currentServer.hostname.empty()) + if (mCurrentServer.hostname.empty()) { - currentServer.hostname = branding.getValue("defaultServer", + mCurrentServer.hostname = branding.getValue("defaultServer", "server.themanaworld.org").c_str(); } if (options.serverPort == 0) { - currentServer.port = (short) branding.getValue("defaultPort", + mCurrentServer.port = (short) branding.getValue("defaultPort", DEFAULT_PORT); } if (loginData.username.empty() && loginData.remember) loginData.username = config.getValue("username", ""); - if (state != STATE_ERROR) - state = STATE_CHOOSE_SERVER; + if (mState != STATE_ERROR) + mState = STATE_CHOOSE_SERVER; // Initialize logic and seconds counters tick_time = 0; @@ -400,8 +421,6 @@ Client::~Client() delete itemShortcut; delete emoteShortcut; - config.write(); - delete gui; delete graphics; @@ -421,10 +440,13 @@ Client::~Client() ResourceManager::deleteInstance(); - SDL_FreeSurface(icon); + SDL_FreeSurface(mIcon); logger->log("Quitting"); delete guiPalette; + + config.write(); + delete logger; mInstance = 0; @@ -437,7 +459,7 @@ int Client::exec() Game *game = 0; SDL_Event event; - while (state != STATE_EXIT) + while (mState != STATE_EXIT) { bool handledEvents = false; @@ -456,7 +478,7 @@ int Client::exec() switch (event.type) { case SDL_QUIT: - state = STATE_EXIT; + mState = STATE_EXIT; break; case SDL_KEYDOWN: @@ -499,75 +521,75 @@ int Client::exec() // TODO: Add connect timeouts - if (state == STATE_CONNECT_GAME && + if (mState == STATE_CONNECT_GAME && Net::getGameHandler()->isConnected()) { Net::getLoginHandler()->disconnect(); } - else if (state == STATE_CONNECT_SERVER && oldstate == STATE_CHOOSE_SERVER) + else if (mState == STATE_CONNECT_SERVER && mOldState == STATE_CHOOSE_SERVER) { - Net::connectToServer(currentServer); + Net::connectToServer(mCurrentServer); } - else if (state == STATE_CONNECT_SERVER && - oldstate != STATE_CHOOSE_SERVER && + else if (mState == STATE_CONNECT_SERVER && + mOldState != STATE_CHOOSE_SERVER && Net::getLoginHandler()->isConnected()) { - state = STATE_LOGIN; + mState = STATE_LOGIN; } - else if (state == STATE_WORLD_SELECT && oldstate == STATE_UPDATE) + else if (mState == STATE_WORLD_SELECT && mOldState == STATE_UPDATE) { if (Net::getLoginHandler()->getWorlds().size() < 2) { - state = STATE_LOGIN; + mState = STATE_LOGIN; } } - else if (oldstate == STATE_START || - (oldstate == STATE_GAME && state != STATE_GAME)) + else if (mOldState == STATE_START || + (mOldState == STATE_GAME && mState != STATE_GAME)) { gcn::Container *top = static_cast<gcn::Container*>(gui->getTop()); - desktop = new Desktop; - top->add(desktop); - setupButton = new Button(_("Setup"), "Setup", this); - setupButton->setPosition(top->getWidth() - setupButton->getWidth() + mDesktop = new Desktop; + top->add(mDesktop); + mSetupButton = new Button(_("Setup"), "Setup", this); + mSetupButton->setPosition(top->getWidth() - mSetupButton->getWidth() - 3, 3); - top->add(setupButton); + top->add(mSetupButton); int screenWidth = (int) config.getValue("screenwidth", defaultScreenWidth); int screenHeight = (int) config.getValue("screenheight", defaultScreenHeight); - desktop->setSize(screenWidth, screenHeight); + mDesktop->setSize(screenWidth, screenHeight); } - if (state == STATE_SWITCH_LOGIN && oldstate == STATE_GAME) + if (mState == STATE_SWITCH_LOGIN && mOldState == STATE_GAME) { Net::getGameHandler()->disconnect(); } - if (state != oldstate) + if (mState != mOldState) { - if (oldstate == STATE_GAME) + if (mOldState == STATE_GAME) { delete game; game = 0; } - oldstate = state; + mOldState = mState; // Get rid of the dialog of the previous state - if (currentDialog) + if (mCurrentDialog) { - delete currentDialog; - currentDialog = NULL; + delete mCurrentDialog; + mCurrentDialog = NULL; } // State has changed, while the quitDialog was active, it might // not be correct anymore - if (quitDialog) - quitDialog->scheduleDelete(); + if (mQuitDialog) + mQuitDialog->scheduleDelete(); - switch (state) + switch (mState) { case STATE_CHOOSE_SERVER: logger->log("State: CHOOSE SERVER"); @@ -575,29 +597,29 @@ int Client::exec() // Allow changing this using a server choice dialog // We show the dialog box only if the command-line // options weren't set. - if (options.serverName.empty() && options.serverPort == 0) + if (mOptions.serverName.empty() && mOptions.serverPort == 0) { // Don't allow an alpha opacity // lower than the default value SkinLoader::instance()->setMinimumOpacity(0.8f); - currentDialog = new ServerDialog(¤tServer, - configDir); + mCurrentDialog = new ServerDialog(&mCurrentServer, + mConfigDir); } else { - state = STATE_CONNECT_SERVER; + mState = STATE_CONNECT_SERVER; // Reset options so that cancelling or connect // timeout will show the server dialog. - options.serverName.clear(); - options.serverPort = 0; + mOptions.serverName.clear(); + mOptions.serverPort = 0; } break; case STATE_CONNECT_SERVER: logger->log("State: CONNECT SERVER"); - currentDialog = new ConnectionDialog( + mCurrentDialog = new ConnectionDialog( _("Connecting to server"), STATE_SWITCH_SERVER); break; @@ -607,24 +629,24 @@ int Client::exec() // lower than the default value SkinLoader::instance()->setMinimumOpacity(0.8f); - if (options.username.empty() - || options.password.empty()) + if (mOptions.username.empty() + || mOptions.password.empty()) { - currentDialog = new LoginDialog(&loginData); + mCurrentDialog = new LoginDialog(&loginData); } else { - state = STATE_LOGIN_ATTEMPT; + mState = STATE_LOGIN_ATTEMPT; // Clear the password so that when login fails, the // dialog will show up next time. - options.password.clear(); + mOptions.password.clear(); } break; case STATE_LOGIN_ATTEMPT: logger->log("State: LOGIN ATTEMPT"); accountLogin(&loginData); - currentDialog = new ConnectionDialog( + mCurrentDialog = new ConnectionDialog( _("Logging in"), STATE_SWITCH_SERVER); break; @@ -636,19 +658,19 @@ int Client::exec() if (worlds.size() == 0) { // Trust that the netcode knows what it's doing - state = STATE_UPDATE; + mState = STATE_UPDATE; } else if (worlds.size() == 1) { Net::getLoginHandler()->chooseServer(0); - state = STATE_UPDATE; + mState = STATE_UPDATE; } else { - currentDialog = new WorldSelectDialog(worlds); - if (options.chooseDefault) + mCurrentDialog = new WorldSelectDialog(worlds); + if (mOptions.chooseDefault) { - ((WorldSelectDialog*) currentDialog)->action( + ((WorldSelectDialog*) mCurrentDialog)->action( gcn::ActionEvent(NULL, "ok")); } } @@ -657,27 +679,27 @@ int Client::exec() case STATE_WORLD_SELECT_ATTEMPT: logger->log("State: WORLD SELECT ATTEMPT"); - currentDialog = new ConnectionDialog( + mCurrentDialog = new ConnectionDialog( _("Entering game world"), STATE_WORLD_SELECT); break; case STATE_UPDATE: // Determine which source to use for the update host - if (!options.updateHost.empty()) - updateHost = options.updateHost; + if (!mOptions.updateHost.empty()) + mUpdateHost = mOptions.updateHost; else - updateHost = loginData.updateHost; + mUpdateHost = loginData.updateHost; initUpdatesDir(); - if (options.skipUpdate) + if (mOptions.skipUpdate) { - state = STATE_LOAD_DATA; + mState = STATE_LOAD_DATA; } else { logger->log("State: UPDATE"); - currentDialog = new UpdaterWindow(updateHost, - localDataDir + "/" + updatesDir,options.dataPath.empty()); + mCurrentDialog = new UpdaterWindow(mUpdateHost, + mLocalDataDir + "/" + mUpdatesDir,mOptions.dataPath.empty()); } break; @@ -686,7 +708,7 @@ int Client::exec() // If another data path has been set, // we don't load any other files... - if (options.dataPath.empty()) + if (mOptions.dataPath.empty()) { // Add customdata directory ResourceManager::getInstance()->searchAndAddArchives( @@ -705,15 +727,15 @@ int Client::exec() StatusEffect::load(); Units::loadUnits(); - desktop->reloadWallpaper(); + mDesktop->reloadWallpaper(); - state = STATE_GET_CHARACTERS; + mState = STATE_GET_CHARACTERS; break; case STATE_GET_CHARACTERS: logger->log("State: GET CHARACTERS"); Net::getCharHandler()->requestCharacters(); - currentDialog = new ConnectionDialog( + mCurrentDialog = new ConnectionDialog( _("Requesting characters"), STATE_SWITCH_SERVER); break; @@ -724,14 +746,14 @@ int Client::exec() // lower than the default value SkinLoader::instance()->setMinimumOpacity(0.8f); - currentDialog = new CharSelectDialog(&loginData); + mCurrentDialog = new CharSelectDialog(&loginData); - if (!((CharSelectDialog*) currentDialog)->selectByName( - options.character, CharSelectDialog::Choose)) + if (!((CharSelectDialog*) mCurrentDialog)->selectByName( + mOptions.character, CharSelectDialog::Choose)) { - ((CharSelectDialog*) currentDialog)->selectByName( + ((CharSelectDialog*) mCurrentDialog)->selectByName( config.getValue("lastCharacter", ""), - options.chooseDefault ? + mOptions.chooseDefault ? CharSelectDialog::Choose : CharSelectDialog::Focus); } @@ -742,7 +764,7 @@ int Client::exec() logger->log("State: CONNECT GAME"); Net::getGameHandler()->connect(); - currentDialog = new ConnectionDialog( + mCurrentDialog = new ConnectionDialog( _("Connecting to the game server"), STATE_SWITCH_CHARACTER); break; @@ -761,12 +783,12 @@ int Client::exec() // Allow any alpha opacity SkinLoader::instance()->setMinimumOpacity(-1.0f); - delete setupButton; - delete desktop; - setupButton = NULL; - desktop = NULL; + delete mSetupButton; + delete mDesktop; + mSetupButton = NULL; + mDesktop = NULL; - currentDialog = NULL; + mCurrentDialog = NULL; logger->log("State: GAME"); game = new Game; @@ -774,28 +796,28 @@ int Client::exec() case STATE_LOGIN_ERROR: logger->log("State: LOGIN ERROR"); - currentDialog = new OkDialog(_("Error"), errorMessage); - currentDialog->addActionListener(&loginListener); - currentDialog = NULL; // OkDialog deletes itself + mCurrentDialog = new OkDialog(_("Error"), errorMessage); + mCurrentDialog->addActionListener(&loginListener); + mCurrentDialog = NULL; // OkDialog deletes itself break; case STATE_ACCOUNTCHANGE_ERROR: logger->log("State: ACCOUNT CHANGE ERROR"); - currentDialog = new OkDialog(_("Error"), errorMessage); - currentDialog->addActionListener(&accountListener); - currentDialog = NULL; // OkDialog deletes itself + mCurrentDialog = new OkDialog(_("Error"), errorMessage); + mCurrentDialog->addActionListener(&accountListener); + mCurrentDialog = NULL; // OkDialog deletes itself break; case STATE_REGISTER_PREP: logger->log("State: REGISTER_PREP"); Net::getLoginHandler()->getRegistrationDetails(); - currentDialog = new ConnectionDialog( + mCurrentDialog = new ConnectionDialog( _("Requesting registration details"), STATE_LOGIN); break; case STATE_REGISTER: logger->log("State: REGISTER"); - currentDialog = new RegisterDialog(&loginData); + mCurrentDialog = new RegisterDialog(&loginData); break; case STATE_REGISTER_ATTEMPT: @@ -805,7 +827,7 @@ int Client::exec() case STATE_CHANGEPASSWORD: logger->log("State: CHANGE PASSWORD"); - currentDialog = new ChangePasswordDialog(&loginData); + mCurrentDialog = new ChangePasswordDialog(&loginData); break; case STATE_CHANGEPASSWORD_ATTEMPT: @@ -817,17 +839,17 @@ int Client::exec() case STATE_CHANGEPASSWORD_SUCCESS: logger->log("State: CHANGE PASSWORD SUCCESS"); - currentDialog = new OkDialog(_("Password Change"), + mCurrentDialog = new OkDialog(_("Password Change"), _("Password changed successfully!")); - currentDialog->addActionListener(&accountListener); - currentDialog = NULL; // OkDialog deletes itself + mCurrentDialog->addActionListener(&accountListener); + mCurrentDialog = NULL; // OkDialog deletes itself loginData.password = loginData.newPassword; loginData.newPassword = ""; break; case STATE_CHANGEEMAIL: logger->log("State: CHANGE EMAIL"); - currentDialog = new ChangeEmailDialog(&loginData); + mCurrentDialog = new ChangeEmailDialog(&loginData); break; case STATE_CHANGEEMAIL_ATTEMPT: @@ -837,15 +859,15 @@ int Client::exec() case STATE_CHANGEEMAIL_SUCCESS: logger->log("State: CHANGE EMAIL SUCCESS"); - currentDialog = new OkDialog(_("Email Change"), + mCurrentDialog = new OkDialog(_("Email Change"), _("Email changed successfully!")); - currentDialog->addActionListener(&accountListener); - currentDialog = NULL; // OkDialog deletes itself + mCurrentDialog->addActionListener(&accountListener); + mCurrentDialog = NULL; // OkDialog deletes itself break; case STATE_UNREGISTER: logger->log("State: UNREGISTER"); - currentDialog = new UnRegisterDialog(&loginData); + mCurrentDialog = new UnRegisterDialog(&loginData); break; case STATE_UNREGISTER_ATTEMPT: @@ -858,12 +880,12 @@ int Client::exec() logger->log("State: UNREGISTER SUCCESS"); Net::getLoginHandler()->disconnect(); - currentDialog = new OkDialog(_("Unregister Successful"), + mCurrentDialog = new OkDialog(_("Unregister Successful"), _("Farewell, come back any time...")); loginData.clear(); //The errorlistener sets the state to STATE_CHOOSE_SERVER - currentDialog->addActionListener(&errorListener); - currentDialog = NULL; // OkDialog deletes itself + mCurrentDialog->addActionListener(&errorListener); + mCurrentDialog = NULL; // OkDialog deletes itself break; case STATE_SWITCH_SERVER: @@ -872,7 +894,7 @@ int Client::exec() Net::getLoginHandler()->disconnect(); Net::getGameHandler()->disconnect(); - state = STATE_CHOOSE_SERVER; + mState = STATE_CHOOSE_SERVER; break; case STATE_SWITCH_LOGIN: @@ -880,7 +902,7 @@ int Client::exec() Net::getLoginHandler()->logout(); - state = STATE_LOGIN; + mState = STATE_LOGIN; break; case STATE_SWITCH_CHARACTER: @@ -910,19 +932,19 @@ int Client::exec() logger->log("State: FORCE QUIT"); if (Net::getGeneralHandler()) Net::getGeneralHandler()->unload(); - state = STATE_EXIT; + mState = STATE_EXIT; break; case STATE_ERROR: logger->log("State: ERROR"); - currentDialog = new OkDialog(_("Error"), errorMessage); - currentDialog->addActionListener(&errorListener); - currentDialog = NULL; // OkDialog deletes itself + mCurrentDialog = new OkDialog(_("Error"), errorMessage); + mCurrentDialog->addActionListener(&errorListener); + mCurrentDialog = NULL; // OkDialog deletes itself Net::getGameHandler()->disconnect(); break; default: - state = STATE_FORCE_QUIT; + mState = STATE_FORCE_QUIT; break; } } @@ -958,69 +980,64 @@ void Client::action(const gcn::ActionEvent &event) * Initializes the home directory. On UNIX and FreeBSD, ~/.mana is used. On * Windows and other systems we use the current working directory. */ -void Client::initHomeDir(const Options &options) +void Client::initHomeDir() { - localDataDir = options.localDataDir; + mLocalDataDir = mOptions.localDataDir; - if (localDataDir.empty()) + if (mLocalDataDir.empty()) { #ifdef __APPLE__ // Use Application Directory instead of .mana - localDataDir = std::string(PHYSFS_getUserDir()) + + mLocalDataDir = 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"; + mLocalDataDir = getSpecialFolderLocation(CSIDL_LOCAL_APPDATA); + if (mLocalDataDir.empty()) + mLocalDataDir = std::string(PHYSFS_getUserDir()); + mLocalDataDir += "/Mana"; #else - localDataDir = std::string(PHYSFS_getUserDir()) + + mLocalDataDir = std::string(PHYSFS_getUserDir()) + "/.local/share/mana"; #endif } - if (mkdir_r(localDataDir.c_str())) + if (mkdir_r(mLocalDataDir.c_str())) { logger->error(strprintf(_("%s doesn't exist and can't be created! " - "Exiting."), localDataDir.c_str())); + "Exiting."), mLocalDataDir.c_str())); } - configDir = options.configDir; + mConfigDir = mOptions.configDir; - if (configDir.empty()){ + if (mConfigDir.empty()){ #ifdef __APPLE__ - configDir = localDataDir; + mConfigDir = mLocalDataDir; #elif defined WIN32 - configDir = getSpecialFolderLocation(CSIDL_APPDATA); - if (configDir.empty()) - configDir = localDataDir; + mConfigDir = getSpecialFolderLocation(CSIDL_APPDATA); + if (mConfigDir.empty()) + mConfigDir = mLocalDataDir; else - configDir += "/mana/" + branding.getValue("appName", "Mana"); + mConfigDir += "/mana/" + branding.getValue("appName", "Mana"); #else - configDir = std::string(PHYSFS_getUserDir()) + + mConfigDir = std::string(PHYSFS_getUserDir()) + "/.config/mana/" + branding.getValue("appShort", "mana"); #endif } - if (mkdir_r(configDir.c_str())) + if (mkdir_r(mConfigDir.c_str())) { logger->error(strprintf(_("%s doesn't exist and can't be created! " - "Exiting."), configDir.c_str())); + "Exiting."), mConfigDir.c_str())); } } /** * Initialize configuration. */ -void Client::initConfiguration(const Options &options) +void Client::initConfiguration() { // Fill configuration with defaults - logger->log("Initializing configuration..."); - std::string defaultHost = branding.getValue("defaultServer", - "server.themanaworld.org"); - int defaultPort = (int) branding.getValue("defaultPort", DEFAULT_PORT); - config.setValue("port", defaultPort); config.setValue("hwaccel", false); #if (defined __APPLE__ || defined WIN32) && defined USE_OPENGL config.setValue("opengl", true); @@ -1046,17 +1063,17 @@ void Client::initConfiguration(const Options &options) FILE *configFile = 0; std::string configPath; - configPath = configDir + "/config.xml"; + configPath = mConfigDir + "/config.xml"; configFile = fopen(configPath.c_str(), "r"); // If we can't read it, it doesn't exist ! - if (configFile == NULL) + if (!configFile) { // We reopen the file in write mode and we create it configFile = fopen(configPath.c_str(), "wt"); } - if (configFile == NULL) + if (!configFile) { logger->log("Can't create %s. Using defaults.", configPath.c_str()); } @@ -1076,50 +1093,50 @@ void Client::initUpdatesDir() std::stringstream updates; // If updatesHost is currently empty, fill it from config file - if (updateHost.empty()) + if (mUpdateHost.empty()) { - updateHost = + mUpdateHost = config.getValue("updatehost", "http://updates.themanaworld.org/"); } // Remove any trailing slash at the end of the update host - if (updateHost.at(updateHost.size() - 1) == '/') - updateHost.resize(updateHost.size() - 1); + if (mUpdateHost.at(mUpdateHost.size() - 1) == '/') + mUpdateHost.resize(mUpdateHost.size() - 1); // Parse out any "http://" or "ftp://", and set the updates directory size_t pos; - pos = updateHost.find("://"); - if (pos != updateHost.npos) + pos = mUpdateHost.find("://"); + if (pos != mUpdateHost.npos) { - if (pos + 3 < updateHost.length()) + if (pos + 3 < mUpdateHost.length()) { - updates << "updates/" << updateHost.substr(pos + 3); - updatesDir = updates.str(); + updates << "updates/" << mUpdateHost.substr(pos + 3); + mUpdatesDir = updates.str(); } else { - logger->log("Error: Invalid update host: %s", updateHost.c_str()); + logger->log("Error: Invalid update host: %s", mUpdateHost.c_str()); errorMessage = strprintf(_("Invalid update host: %s"), - updateHost.c_str()); - state = STATE_ERROR; + mUpdateHost.c_str()); + mState = STATE_ERROR; } } else { logger->log("Warning: no protocol was specified for the update host"); - updates << "updates/" << updateHost; - updatesDir = updates.str(); + updates << "updates/" << mUpdateHost; + mUpdatesDir = updates.str(); } ResourceManager *resman = ResourceManager::getInstance(); // Verify that the updates directory exists. Create if necessary. - if (!resman->isDirectory("/" + updatesDir)) + if (!resman->isDirectory("/" + mUpdatesDir)) { - if (!resman->mkdir("/" + updatesDir)) + if (!resman->mkdir("/" + mUpdatesDir)) { #if defined WIN32 - std::string newDir = localDataDir + "\\" + updatesDir; + std::string newDir = mLocalDataDir + "\\" + mUpdatesDir; std::string::size_type loc = newDir.find("/", 0); while (loc != std::string::npos) @@ -1134,43 +1151,39 @@ void Client::initUpdatesDir() logger->log("Error: %s can't be made, but doesn't exist!", newDir.c_str()); errorMessage = _("Error creating updates directory!"); - state = STATE_ERROR; + mState = STATE_ERROR; } #else logger->log("Error: %s/%s can't be made, but doesn't exist!", - localDataDir.c_str(), updatesDir.c_str()); + mLocalDataDir.c_str(), mUpdatesDir.c_str()); errorMessage = _("Error creating updates directory!"); - state = STATE_ERROR; + mState = STATE_ERROR; #endif } } } -void Client::initScreenshotDir(const std::string &dir) +void Client::initScreenshotDir() { - if (!dir.empty()) - screenshotDir = dir; + if (!mOptions.screenshotDir.empty()) + mScreenshotDir = mOptions.screenshotDir; else { std::string configScreenshotDir = config.getValue("screenshotDirectory", ""); if (!configScreenshotDir.empty()) - screenshotDir = configScreenshotDir; + mScreenshotDir = configScreenshotDir; else { #ifdef WIN32 - screenshotDir = getSpecialFolderLocation(CSIDL_MYPICTURES); - if (screenshotDir.empty()) - screenshotDir = getSpecialFolderLocation(CSIDL_DESKTOP); + mScreenshotDir = getSpecialFolderLocation(CSIDL_MYPICTURES); + if (mScreenshotDir.empty()) + mScreenshotDir = 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()); + mScreenshotDir = std::string(PHYSFS_getUserDir()) + "Desktop"; #endif } - config.setValue("screenshotDirectory", screenshotDir); + config.setValue("screenshotDirectory", mScreenshotDir); if (config.getValue("useScreenshotDirectorySuffix", true)) { @@ -1180,20 +1193,12 @@ void Client::initScreenshotDir(const std::string &dir) if (!configScreenshotSuffix.empty()) { - screenshotDir += "/" + configScreenshotSuffix; + mScreenshotDir += "/" + configScreenshotSuffix; config.setValue("screenshotDirectorySuffix", configScreenshotSuffix); } } } - - if (mkdir_r(screenshotDir.c_str())) - { - 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()); - } } void Client::accountLogin(LoginData *loginData) |