- added support for better user data customization and default linux path will now be ~/.megaglest/ for user related ini's and data content

This commit is contained in:
Mark Vejvoda 2011-03-10 07:26:43 +00:00
parent 2101a83a5d
commit 242b02c001
5 changed files with 71 additions and 20 deletions

View File

@ -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

View File

@ -99,6 +99,8 @@ Config::Config(std::pair<ConfigType,ConfigType> type, std::pair<string,string> 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<ConfigType,ConfigType> type, std::pair<string,string> 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<string> 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) {

View File

@ -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());

View File

@ -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");

View File

@ -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<ConfigType,ConfigType>(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) {