2010-03-13 21:10:45 +00:00
|
|
|
// ==============================================================
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
//
|
2010-06-05 07:52:14 +00:00
|
|
|
// Copyright (C) 2001-2008 Martio Figueroa
|
2010-03-13 21:10:45 +00:00
|
|
|
//
|
|
|
|
// You can redistribute this code and/or modify it under
|
|
|
|
// the terms of the GNU General Public License as published
|
|
|
|
// by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "util.h"
|
2010-03-16 21:44:22 +00:00
|
|
|
#include "game_constants.h"
|
2010-03-20 10:52:55 +00:00
|
|
|
#include "platform_util.h"
|
2010-03-21 23:40:35 +00:00
|
|
|
#include "game_util.h"
|
2010-06-12 18:27:39 +00:00
|
|
|
#include <map>
|
|
|
|
#include "conversion.h"
|
|
|
|
#include "window.h"
|
|
|
|
#include <stdexcept>
|
2010-07-03 07:02:31 +00:00
|
|
|
#include <fstream>
|
2010-03-21 23:40:35 +00:00
|
|
|
#include "leak_dumper.h"
|
2010-03-20 10:52:55 +00:00
|
|
|
|
|
|
|
using namespace Shared::Platform;
|
2010-03-21 23:40:35 +00:00
|
|
|
using namespace Shared::Util;
|
2010-06-12 18:27:39 +00:00
|
|
|
using namespace std;
|
2010-03-13 21:10:45 +00:00
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
2010-12-11 08:00:49 +00:00
|
|
|
int GameConstants::networkFramePeriod = 20;
|
|
|
|
int GameConstants::updateFps = 40;
|
|
|
|
int GameConstants::cameraFps = 100;
|
|
|
|
|
|
|
|
const float GameConstants::normalMultiplier = 1.0f;
|
|
|
|
const float GameConstants::easyMultiplier = 0.8f;
|
|
|
|
const float GameConstants::ultraMultiplier = 3.0f;
|
|
|
|
const float GameConstants::megaMultiplier = 4.0f;
|
2010-03-16 21:44:22 +00:00
|
|
|
|
|
|
|
const char *GameConstants::folder_path_maps = "maps";
|
|
|
|
const char *GameConstants::folder_path_scenarios = "scenarios";
|
|
|
|
const char *GameConstants::folder_path_techs = "techs";
|
|
|
|
const char *GameConstants::folder_path_tilesets = "tilesets";
|
|
|
|
const char *GameConstants::folder_path_tutorials = "tutorials";
|
|
|
|
|
2010-06-29 06:50:35 +00:00
|
|
|
const char *GameConstants::NETWORK_SLOT_UNCONNECTED_SLOTNAME = "???";
|
2010-03-16 21:44:22 +00:00
|
|
|
|
2010-08-02 03:15:11 +00:00
|
|
|
const char *GameConstants::folder_path_screenshots = "screens/";
|
|
|
|
|
2010-09-04 00:32:56 +00:00
|
|
|
const char *GameConstants::OBSERVER_SLOTNAME = "*Observer*";
|
2010-09-11 08:09:33 +00:00
|
|
|
const char *GameConstants::RANDOMFACTION_SLOTNAME = "*Random*";
|
2010-09-04 00:32:56 +00:00
|
|
|
|
2010-11-05 06:46:30 +00:00
|
|
|
const char *GameConstants::playerTextureCacheLookupKey = "playerTextureCache";
|
|
|
|
const char *GameConstants::application_name = "MegaGlest";
|
2010-10-22 07:28:55 +00:00
|
|
|
|
2010-12-09 20:41:11 +00:00
|
|
|
const char *GameConstants::pathCacheLookupKey = "pathCache_";
|
|
|
|
const char *GameConstants::path_data_CacheLookupKey = "data";
|
|
|
|
const char *GameConstants::path_ini_CacheLookupKey = "ini";
|
|
|
|
const char *GameConstants::path_logs_CacheLookupKey = "logs";
|
|
|
|
|
|
|
|
const char *Config::glest_ini_filename = "glest.ini";
|
|
|
|
const char *Config::glestuser_ini_filename = "glestuser.ini";
|
|
|
|
|
|
|
|
|
2010-03-13 21:10:45 +00:00
|
|
|
// =====================================================
|
|
|
|
// class Config
|
|
|
|
// =====================================================
|
|
|
|
|
2010-06-12 18:27:39 +00:00
|
|
|
const string defaultNotFoundValue = "~~NOT FOUND~~";
|
2010-03-21 23:40:35 +00:00
|
|
|
|
2010-06-12 18:27:39 +00:00
|
|
|
map<ConfigType,Config> Config::configList;
|
|
|
|
|
2010-09-09 21:07:39 +00:00
|
|
|
Config::Config() {
|
|
|
|
fileLoaded.first = false;
|
|
|
|
fileLoaded.second = false;
|
|
|
|
cfgType.first = cfgMainGame;
|
|
|
|
cfgType.second = cfgUserGame;
|
|
|
|
fileName.first = "";
|
|
|
|
fileName.second = "";
|
|
|
|
fileLoaded.first = false;
|
|
|
|
fileLoaded.second = false;
|
|
|
|
}
|
|
|
|
|
2010-06-12 18:27:39 +00:00
|
|
|
Config::Config(std::pair<ConfigType,ConfigType> type, std::pair<string,string> file, std::pair<bool,bool> fileMustExist) {
|
|
|
|
fileLoaded.first = false;
|
|
|
|
fileLoaded.second = false;
|
|
|
|
cfgType = type;
|
|
|
|
|
|
|
|
fileName = file;
|
2010-12-09 20:41:11 +00:00
|
|
|
if(getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) != "") {
|
|
|
|
fileName.first = getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) + fileName.first;
|
|
|
|
fileName.second = getGameReadWritePath(GameConstants::path_ini_CacheLookupKey) + fileName.second;
|
2010-06-12 18:27:39 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 06:30:54 +00:00
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] cfgFile.first = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.first.c_str());
|
2010-06-12 18:27:39 +00:00
|
|
|
|
|
|
|
if(fileMustExist.first == true ||
|
|
|
|
(fileMustExist.first == false && fileExists(fileName.first) == true)) {
|
|
|
|
properties.first.load(fileName.first);
|
|
|
|
fileLoaded.first = true;
|
|
|
|
|
2010-07-12 06:30:54 +00:00
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] cfgFile.first = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.first.c_str());
|
2010-06-12 18:27:39 +00:00
|
|
|
}
|
2010-07-12 06:30:54 +00:00
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] cfgFile.first = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.first.c_str());
|
2010-06-12 18:27:39 +00:00
|
|
|
|
|
|
|
if(properties.first.getString("UserOverrideFile", defaultNotFoundValue.c_str()) != defaultNotFoundValue) {
|
|
|
|
fileName.second = properties.first.getString("UserOverrideFile");
|
2010-03-21 23:40:35 +00:00
|
|
|
}
|
|
|
|
|
2010-07-12 06:30:54 +00:00
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] cfgFile.second = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.second.c_str());
|
2010-06-12 18:27:39 +00:00
|
|
|
|
|
|
|
if(fileMustExist.second == true ||
|
|
|
|
(fileMustExist.second == false && fileExists(fileName.second) == true)) {
|
|
|
|
properties.second.load(fileName.second);
|
|
|
|
fileLoaded.second = true;
|
|
|
|
|
2010-07-12 06:30:54 +00:00
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] cfgFile.second = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.second.c_str());
|
2010-06-12 18:27:39 +00:00
|
|
|
}
|
2010-07-03 07:02:31 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
if(fileName.second != "" && fileExists(fileName.second) == false) {
|
2010-12-22 00:31:30 +00:00
|
|
|
if(SystemFlags::VERBOSE_MODE_ENABLED) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] attempting to auto-create cfgFile.second = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.second.c_str());
|
2010-07-03 07:02:31 +00:00
|
|
|
|
|
|
|
std::ofstream userFile;
|
|
|
|
userFile.open(fileName.second.c_str(), ios_base::out | ios_base::trunc);
|
|
|
|
userFile.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(const exception &ex) {
|
2010-10-06 20:22:06 +00:00
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
2010-07-03 07:02:31 +00:00
|
|
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] ERROR trying to auto-create cfgFile.second = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.second.c_str());
|
|
|
|
}
|
|
|
|
|
2010-07-12 06:30:54 +00:00
|
|
|
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] cfgFile.second = [%s]\n",__FILE__,__FUNCTION__,__LINE__,fileName.second.c_str());
|
2010-03-13 21:10:45 +00:00
|
|
|
}
|
|
|
|
|
2010-06-12 18:27:39 +00:00
|
|
|
Config &Config::getInstance(std::pair<ConfigType,ConfigType> type, std::pair<string,string> file, std::pair<bool,bool> fileMustExist) {
|
|
|
|
if(configList.find(type.first) == configList.end()) {
|
2010-12-22 00:31:30 +00:00
|
|
|
if(SystemFlags::VERBOSE_MODE_ENABLED) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-09-09 21:07:39 +00:00
|
|
|
|
2010-06-12 18:27:39 +00:00
|
|
|
Config config(type, file, fileMustExist);
|
2010-09-09 21:07:39 +00:00
|
|
|
|
2010-12-22 00:31:30 +00:00
|
|
|
if(SystemFlags::VERBOSE_MODE_ENABLED) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-09-09 21:07:39 +00:00
|
|
|
|
2010-06-12 18:27:39 +00:00
|
|
|
configList.insert(map<ConfigType,Config>::value_type(type.first,config));
|
2010-09-09 21:07:39 +00:00
|
|
|
|
2010-12-22 00:31:30 +00:00
|
|
|
if(SystemFlags::VERBOSE_MODE_ENABLED) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-06-12 18:27:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return configList.find(type.first)->second;
|
2010-03-13 21:10:45 +00:00
|
|
|
}
|
|
|
|
|
2010-09-09 21:07:39 +00:00
|
|
|
void Config::CopyAll(Config *src, Config *dest) {
|
|
|
|
|
|
|
|
dest->properties = src->properties;
|
|
|
|
dest->cfgType = src->cfgType;
|
|
|
|
dest->fileName = src->fileName;
|
|
|
|
dest->fileLoaded = src->fileLoaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Config::reload() {
|
2010-12-22 00:31:30 +00:00
|
|
|
if(SystemFlags::VERBOSE_MODE_ENABLED) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-09-09 21:07:39 +00:00
|
|
|
|
|
|
|
std::pair<ConfigType,ConfigType> type = std::make_pair(cfgMainGame,cfgUserGame);
|
2010-12-09 20:41:11 +00:00
|
|
|
Config newconfig(type, std::make_pair(glest_ini_filename,glestuser_ini_filename), std::make_pair(true,false));
|
2010-09-09 21:07:39 +00:00
|
|
|
|
2010-12-22 00:31:30 +00:00
|
|
|
if(SystemFlags::VERBOSE_MODE_ENABLED) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-09-09 21:07:39 +00:00
|
|
|
|
|
|
|
Config &oldconfig = configList.find(type.first)->second;
|
|
|
|
CopyAll(&newconfig, &oldconfig);
|
|
|
|
|
2010-12-22 00:31:30 +00:00
|
|
|
if(SystemFlags::VERBOSE_MODE_ENABLED) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
2010-09-09 21:07:39 +00:00
|
|
|
}
|
|
|
|
|
2010-03-13 21:10:45 +00:00
|
|
|
void Config::save(const string &path){
|
2010-06-12 18:27:39 +00:00
|
|
|
if(fileLoaded.second == true) {
|
|
|
|
if(path != "") {
|
|
|
|
fileName.second = path;
|
|
|
|
}
|
|
|
|
properties.second.save(fileName.second);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(path != "") {
|
|
|
|
fileName.first = path;
|
|
|
|
}
|
|
|
|
properties.first.save(fileName.first);
|
2010-03-13 21:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int Config::getInt(const char *key,const char *defaultValueIfNotFound) const {
|
2010-06-12 18:27:39 +00:00
|
|
|
if(fileLoaded.second == true &&
|
|
|
|
properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) {
|
|
|
|
return properties.second.getInt(key,defaultValueIfNotFound);
|
|
|
|
}
|
|
|
|
return properties.first.getInt(key,defaultValueIfNotFound);
|
2010-03-13 21:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Config::getBool(const char *key,const char *defaultValueIfNotFound) const {
|
2010-06-12 18:27:39 +00:00
|
|
|
if(fileLoaded.second == true &&
|
|
|
|
properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) {
|
|
|
|
return properties.second.getBool(key,defaultValueIfNotFound);
|
|
|
|
}
|
|
|
|
|
|
|
|
return properties.first.getBool(key,defaultValueIfNotFound);
|
2010-03-13 21:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float Config::getFloat(const char *key,const char *defaultValueIfNotFound) const {
|
2010-06-12 18:27:39 +00:00
|
|
|
if(fileLoaded.second == true &&
|
|
|
|
properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) {
|
|
|
|
return properties.second.getFloat(key,defaultValueIfNotFound);
|
|
|
|
}
|
|
|
|
|
|
|
|
return properties.first.getFloat(key,defaultValueIfNotFound);
|
2010-03-13 21:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const string Config::getString(const char *key,const char *defaultValueIfNotFound) const {
|
2010-06-12 18:27:39 +00:00
|
|
|
if(fileLoaded.second == true &&
|
|
|
|
properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) {
|
|
|
|
return properties.second.getString(key,defaultValueIfNotFound);
|
|
|
|
}
|
|
|
|
|
|
|
|
return properties.first.getString(key,defaultValueIfNotFound);
|
2010-03-13 21:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int Config::getInt(const string &key,const char *defaultValueIfNotFound) const{
|
2010-06-12 18:27:39 +00:00
|
|
|
if(fileLoaded.second == true &&
|
|
|
|
properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) {
|
|
|
|
return properties.second.getInt(key,defaultValueIfNotFound);
|
|
|
|
}
|
|
|
|
|
|
|
|
return properties.first.getInt(key,defaultValueIfNotFound);
|
2010-03-13 21:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool Config::getBool(const string &key,const char *defaultValueIfNotFound) const{
|
2010-06-12 18:27:39 +00:00
|
|
|
if(fileLoaded.second == true &&
|
|
|
|
properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) {
|
|
|
|
return properties.second.getBool(key,defaultValueIfNotFound);
|
|
|
|
}
|
|
|
|
|
|
|
|
return properties.first.getBool(key,defaultValueIfNotFound);
|
2010-03-13 21:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float Config::getFloat(const string &key,const char *defaultValueIfNotFound) const{
|
2010-06-12 18:27:39 +00:00
|
|
|
if(fileLoaded.second == true &&
|
|
|
|
properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) {
|
|
|
|
return properties.second.getFloat(key,defaultValueIfNotFound);
|
|
|
|
}
|
|
|
|
|
|
|
|
return properties.first.getFloat(key,defaultValueIfNotFound);
|
2010-03-13 21:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const string Config::getString(const string &key,const char *defaultValueIfNotFound) const{
|
2010-06-12 18:27:39 +00:00
|
|
|
if(fileLoaded.second == true &&
|
|
|
|
properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) {
|
|
|
|
return properties.second.getString(key,defaultValueIfNotFound);
|
|
|
|
}
|
|
|
|
|
|
|
|
return properties.first.getString(key,defaultValueIfNotFound);
|
|
|
|
}
|
|
|
|
|
|
|
|
char Config::translateStringToCharKey(const string &value) const {
|
|
|
|
char result = 0;
|
|
|
|
|
|
|
|
if(IsNumeric(value.c_str()) == true) {
|
|
|
|
result = strToInt(value);
|
|
|
|
}
|
|
|
|
else if(value.substr(0,2) == "vk") {
|
|
|
|
if(value == "vkLeft") {
|
|
|
|
result = vkLeft;
|
|
|
|
}
|
|
|
|
else if(value == "vkRight") {
|
|
|
|
result = vkRight;
|
|
|
|
}
|
|
|
|
else if(value == "vkUp") {
|
|
|
|
result = vkUp;
|
|
|
|
}
|
|
|
|
else if(value == "vkDown") {
|
|
|
|
result = vkDown;
|
|
|
|
}
|
|
|
|
else if(value == "vkAdd") {
|
|
|
|
result = vkAdd;
|
|
|
|
}
|
|
|
|
else if(value == "vkSubtract") {
|
|
|
|
result = vkSubtract;
|
|
|
|
}
|
|
|
|
else if(value == "vkEscape") {
|
|
|
|
result = vkEscape;
|
|
|
|
}
|
2010-09-09 21:07:39 +00:00
|
|
|
else if(value == "vkF1") {
|
|
|
|
result = vkF1;
|
|
|
|
}
|
|
|
|
else if(value == "vkF2") {
|
|
|
|
result = vkF2;
|
|
|
|
}
|
|
|
|
else if(value == "vkF3") {
|
|
|
|
result = vkF3;
|
|
|
|
}
|
|
|
|
else if(value == "vkF4") {
|
|
|
|
result = vkF4;
|
|
|
|
}
|
|
|
|
else if(value == "vkF5") {
|
|
|
|
result = vkF5;
|
|
|
|
}
|
|
|
|
else if(value == "vkF6") {
|
|
|
|
result = vkF6;
|
|
|
|
}
|
|
|
|
else if(value == "vkF7") {
|
|
|
|
result = vkF7;
|
|
|
|
}
|
|
|
|
else if(value == "vkF8") {
|
|
|
|
result = vkF8;
|
|
|
|
}
|
|
|
|
else if(value == "vkF9") {
|
|
|
|
result = vkF9;
|
|
|
|
}
|
|
|
|
else if(value == "vkF10") {
|
|
|
|
result = vkF10;
|
|
|
|
}
|
|
|
|
else if(value == "vkF11") {
|
|
|
|
result = vkF11;
|
|
|
|
}
|
|
|
|
else if(value == "vkF12") {
|
|
|
|
result = vkF12;
|
|
|
|
}
|
2010-06-12 18:27:39 +00:00
|
|
|
else {
|
|
|
|
string sError = "Unsupported key translation" + value;
|
|
|
|
throw runtime_error(sError.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(value.length() >= 1) {
|
2010-06-13 17:55:39 +00:00
|
|
|
if(value.length() == 3 && value[0] == '\'' && value[2] == '\'') {
|
|
|
|
result = value[1];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = value[0];
|
|
|
|
}
|
2010-06-12 18:27:39 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
string sError = "Unsupported key translation" + value;
|
|
|
|
throw runtime_error(sError.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
char Config::getCharKey(const char *key) const {
|
|
|
|
if(fileLoaded.second == true &&
|
|
|
|
properties.second.getString(key, defaultNotFoundValue.c_str()) != defaultNotFoundValue) {
|
|
|
|
|
|
|
|
string value = properties.second.getString(key);
|
|
|
|
return translateStringToCharKey(value);
|
|
|
|
}
|
|
|
|
string value = properties.first.getString(key);
|
|
|
|
return translateStringToCharKey(value);
|
2010-03-13 21:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Config::setInt(const string &key, int value){
|
2010-06-12 18:27:39 +00:00
|
|
|
if(fileLoaded.second == true) {
|
|
|
|
properties.second.setInt(key, value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
properties.first.setInt(key, value);
|
2010-03-13 21:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Config::setBool(const string &key, bool value){
|
2010-06-12 18:27:39 +00:00
|
|
|
if(fileLoaded.second == true) {
|
|
|
|
properties.second.setBool(key, value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
properties.first.setBool(key, value);
|
2010-03-13 21:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Config::setFloat(const string &key, float value){
|
2010-06-12 18:27:39 +00:00
|
|
|
if(fileLoaded.second == true) {
|
|
|
|
properties.second.setFloat(key, value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
properties.first.setFloat(key, value);
|
2010-03-13 21:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Config::setString(const string &key, const string &value){
|
2010-06-12 18:27:39 +00:00
|
|
|
if(fileLoaded.second == true) {
|
|
|
|
properties.second.setString(key, value);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
properties.first.setString(key, value);
|
2010-03-13 21:10:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
string Config::toString(){
|
2010-06-12 18:27:39 +00:00
|
|
|
return properties.first.toString();
|
2010-03-13 21:10:45 +00:00
|
|
|
}
|
|
|
|
|
2010-03-21 05:33:13 +00:00
|
|
|
vector<string> Config::getPathListForType(PathType type, string scenarioDir) {
|
2010-03-16 21:44:22 +00:00
|
|
|
vector<string> pathList;
|
|
|
|
|
2010-12-09 20:41:11 +00:00
|
|
|
//#include "game_constants.h"
|
|
|
|
//#include "game_util.h"
|
|
|
|
string data_path = getGameReadWritePath(GameConstants::path_data_CacheLookupKey);
|
|
|
|
|
2010-03-20 00:46:16 +00:00
|
|
|
string userData = getString("UserData_Root","");
|
|
|
|
if(userData != "") {
|
|
|
|
if(userData[userData.size()-1] != '/' && userData[userData.size()-1] != '\\') {
|
|
|
|
userData += '/';
|
|
|
|
}
|
2010-12-09 20:41:11 +00:00
|
|
|
userData=data_path+userData;
|
2010-07-27 18:56:12 +00:00
|
|
|
if(isdir(userData.c_str()) == false) {
|
|
|
|
createDirectoryPaths(userData);
|
|
|
|
}
|
2010-03-20 00:46:16 +00:00
|
|
|
}
|
2010-03-21 05:33:13 +00:00
|
|
|
if(scenarioDir != "") {
|
2010-12-09 20:41:11 +00:00
|
|
|
pathList.push_back(data_path+scenarioDir);
|
2010-03-21 05:33:13 +00:00
|
|
|
}
|
2010-03-20 00:46:16 +00:00
|
|
|
|
2010-03-16 21:44:22 +00:00
|
|
|
switch(type) {
|
|
|
|
case ptMaps:
|
2010-12-09 20:41:11 +00:00
|
|
|
pathList.push_back(data_path+GameConstants::folder_path_maps);
|
2010-03-20 00:46:16 +00:00
|
|
|
if(userData != "") {
|
|
|
|
pathList.push_back(userData + string(GameConstants::folder_path_maps));
|
2010-03-16 21:44:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ptScenarios:
|
2010-12-09 20:41:11 +00:00
|
|
|
pathList.push_back(data_path+GameConstants::folder_path_scenarios);
|
2010-03-20 00:46:16 +00:00
|
|
|
if(userData != "") {
|
|
|
|
pathList.push_back(userData + string(GameConstants::folder_path_scenarios));
|
2010-03-16 21:44:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ptTechs:
|
2010-12-09 20:41:11 +00:00
|
|
|
pathList.push_back(data_path+GameConstants::folder_path_techs);
|
2010-03-20 00:46:16 +00:00
|
|
|
if(userData != "") {
|
|
|
|
pathList.push_back(userData + string(GameConstants::folder_path_techs));
|
2010-03-16 21:44:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ptTilesets:
|
2010-12-09 20:41:11 +00:00
|
|
|
pathList.push_back(data_path+GameConstants::folder_path_tilesets);
|
2010-03-20 00:46:16 +00:00
|
|
|
if(userData != "") {
|
|
|
|
pathList.push_back(userData + string(GameConstants::folder_path_tilesets));
|
2010-03-16 21:44:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ptTutorials:
|
2010-12-09 20:41:11 +00:00
|
|
|
pathList.push_back(data_path+GameConstants::folder_path_tutorials);
|
2010-03-20 00:46:16 +00:00
|
|
|
if(userData != "") {
|
|
|
|
pathList.push_back(userData + string(GameConstants::folder_path_tutorials));
|
2010-03-16 21:44:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return pathList;
|
|
|
|
}
|
|
|
|
|
2010-03-13 21:10:45 +00:00
|
|
|
}}// end namespace
|