diff --git a/mk/linux/glest.ini b/mk/linux/glest.ini index 1185cb089..08010569f 100644 --- a/mk/linux/glest.ini +++ b/mk/linux/glest.ini @@ -77,6 +77,6 @@ SoundVolumeMusic=90 StencilBits=0 Textures3D=true UnitParticles=true -UserData_Root=mydata/ +UserData_Root=$HOME/.megaglest/ VersionURL=http://master.megaglest.org/files/versions/ Windowed=false diff --git a/source/glest_game/global/config.cpp b/source/glest_game/global/config.cpp index 3098fe5c0..15094e73c 100644 --- a/source/glest_game/global/config.cpp +++ b/source/glest_game/global/config.cpp @@ -99,6 +99,8 @@ Config::Config(std::pair type, std::pair f //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] cfgFile.first = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.first.c_str()); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("-=-=-=-=-=-=-= About to load fileName.first = [%s]\n",fileName.first.c_str()); + if(fileMustExist.first == true || (fileMustExist.first == false && fileExists(fileName.first) == true)) { properties.first.load(fileName.first); @@ -108,9 +110,27 @@ Config::Config(std::pair type, std::pair f } //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] cfgFile.first = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.first.c_str()); - if(properties.first.getString("UserOverrideFile", defaultNotFoundValue.c_str()) != defaultNotFoundValue) { - fileName.second = properties.first.getString("UserOverrideFile"); + string userData = ""; + if(cfgType.first == cfgMainGame) { + if( properties.first.getString("UserData_Root", defaultNotFoundValue.c_str()) != defaultNotFoundValue) { + fileName.second = properties.first.getString("UserData_Root") + fileNameParameter.second; + } + else if(properties.first.getString("UserOverrideFile", defaultNotFoundValue.c_str()) != defaultNotFoundValue) { + fileName.second = properties.first.getString("UserOverrideFile") + fileNameParameter.second; + } + } + else if(cfgType.first == cfgMainKeys) { + Config &mainCfg = Config::getInstance(); + if( mainCfg.getString("UserData_Root", defaultNotFoundValue.c_str()) != defaultNotFoundValue) { + fileName.second = mainCfg.getString("UserData_Root") + fileNameParameter.second; + } + else if(mainCfg.getString("UserOverrideFile", defaultNotFoundValue.c_str()) != defaultNotFoundValue) { + fileName.second = mainCfg.getString("UserOverrideFile") + fileNameParameter.second; + } + } + + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("-=-=-=-=-=-=-= About to load fileName.second = [%s]\n",fileName.second.c_str()); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] cfgFile.second = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.second.c_str()); @@ -183,6 +203,7 @@ void Config::save(const string &path){ if(path != "") { fileName.second = path; } + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] save file [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.second.c_str()); properties.second.save(fileName.second); return; } @@ -190,6 +211,7 @@ void Config::save(const string &path){ if(path != "") { fileName.first = path; } + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] save file [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.first.c_str()); properties.first.save(fileName.first); } @@ -685,13 +707,13 @@ vector Config::getPathListForType(PathType type, string scenarioDir) { if(userData[userData.size()-1] != '/' && userData[userData.size()-1] != '\\') { userData += '/'; } - if(data_path == "") { - userData = data_path + userData; - } - else { - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("extractLastDirectoryFromPath(userData) [%s] from userData [%s]\n",extractLastDirectoryFromPath(userData).c_str(),userData.c_str()); - userData = data_path + extractLastDirectoryFromPath(userData); - } + //if(data_path == "") { + // userData = userData; + //} + //else { + // if(SystemFlags::VERBOSE_MODE_ENABLED) printf("extractLastDirectoryFromPath(userData) [%s] from userData [%s]\n",extractLastDirectoryFromPath(userData).c_str(),userData.c_str()); + // userData = data_path + extractLastDirectoryFromPath(userData); + //} if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] userData path [%s]\n",__FILE__,__FUNCTION__,__LINE__,userData.c_str()); if(isdir(userData.c_str()) == false) { diff --git a/source/glest_game/menu/menu_state_custom_game.cpp b/source/glest_game/menu/menu_state_custom_game.cpp index fad501209..a3b002f31 100644 --- a/source/glest_game/menu/menu_state_custom_game.cpp +++ b/source/glest_game/menu/menu_state_custom_game.cpp @@ -2170,9 +2170,17 @@ void MenuStateCustomGame::loadGameSettings(GameSettings *gameSettings) { void MenuStateCustomGame::saveGameSettingsToFile(std::string fileName) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); - if(getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) != "") { - fileName = getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) + fileName; + //if(getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) != "") { + // fileName = getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) + fileName; + //} + Config &config = Config::getInstance(); + string userData = config.getString("UserData_Root",""); + if(userData != "") { + if(userData != "" && EndsWith(userData, "/") == false && EndsWith(userData, "\\") == false) { + userData += "/"; + } } + fileName = userData + fileName; SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] fileName = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.c_str()); @@ -2230,9 +2238,17 @@ GameSettings MenuStateCustomGame::loadGameSettingsFromFile(std::string fileName) GameSettings gameSettings; - if(getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) != "") { - fileName = getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) + fileName; + //if(getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) != "") { + // fileName = getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) + fileName; + //} + Config &config = Config::getInstance(); + string userData = config.getString("UserData_Root",""); + if(userData != "") { + if(userData != "" && EndsWith(userData, "/") == false && EndsWith(userData, "\\") == false) { + userData += "/"; + } } + fileName = userData + fileName; SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] fileName = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.c_str()); diff --git a/source/glest_game/menu/menu_state_join_game.cpp b/source/glest_game/menu/menu_state_join_game.cpp index 38f22b57e..58f68d7fb 100644 --- a/source/glest_game/menu/menu_state_join_game.cpp +++ b/source/glest_game/menu/menu_state_join_game.cpp @@ -54,11 +54,21 @@ MenuStateJoinGame::MenuStateJoinGame(Program *program, MainMenu *mainMenu, bool networkManager.init(nrClient); serversSavedFile = serverFileName; - if(getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) != "") { - serversSavedFile = getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) + serversSavedFile; + //if(getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) != "") { + // serversSavedFile = getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) + serversSavedFile; + //} + //Config &config = Config::getInstance(); + string userData = config.getString("UserData_Root",""); + if(userData != "") { + if(userData != "" && EndsWith(userData, "/") == false && EndsWith(userData, "\\") == false) { + userData += "/"; + } } + serversSavedFile = userData + serversSavedFile; - servers.load(serversSavedFile); + if(fileExists(serversSavedFile) == true) { + servers.load(serversSavedFile); + } //buttons buttonReturn.registerGraphicComponent(containerName,"buttonReturn"); diff --git a/source/glest_game/menu/menu_state_keysetup.cpp b/source/glest_game/menu/menu_state_keysetup.cpp index 615a55cc3..ab7dd6a29 100644 --- a/source/glest_game/menu/menu_state_keysetup.cpp +++ b/source/glest_game/menu/menu_state_keysetup.cpp @@ -207,14 +207,13 @@ void MenuStateKeysetup::mouseClick(int x, int y, MouseButton mouseButton){ #else int result = unlink(userKeysFile.c_str()); #endif + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] delete file [%s] returned %d\n",__FILE__,__FUNCTION__,__LINE__,userKeysFile.c_str(),result); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] delete file [%s] returned %d\n",__FILE__,__FUNCTION__,__LINE__,userKeysFile.c_str(),result); configKeys.reload(); mainMenu->setState(new MenuStateOptions(program, mainMenu)); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); } - - else if(buttonOk.mouseClick(x, y)){ SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); soundRenderer.playFx(coreData.getClickSoundB()); @@ -222,6 +221,10 @@ void MenuStateKeysetup::mouseClick(int x, int y, MouseButton mouseButton){ if(userProperties.size() > 0) { Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); + string userKeysFile = configKeys.getFileName(true); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] save file [%s] userProperties.size() = %lu\n",__FILE__,__FUNCTION__,__LINE__,userKeysFile.c_str(),userProperties.size()); + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] save file [%s] userProperties.size() = %lu\n",__FILE__,__FUNCTION__,__LINE__,userKeysFile.c_str(),userProperties.size()); + configKeys.setUserProperties(userProperties); configKeys.save(); configKeys.reload(); @@ -323,7 +326,7 @@ void MenuStateKeysetup::showMessageBox(const string &text, const string &header, void MenuStateKeysetup::keyDown(char key) { hotkeyChar = key; - if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] hotkeyChar [%d]\n",__FILE__,__FUNCTION__,__LINE__,hotkeyChar); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] hotkeyChar [%d]\n",__FILE__,__FUNCTION__,__LINE__,hotkeyChar); } void MenuStateKeysetup::keyPress(char c) {