- added a new commandline parameter to display merged ini settings and also to filter on a specific ini setting

This commit is contained in:
Mark Vejvoda 2011-01-03 20:59:18 +00:00
parent 5bb98fa261
commit 21c1da2e18
4 changed files with 130 additions and 7 deletions

View File

@ -389,6 +389,50 @@ void Config::setString(const string &key, const string &value){
properties.first.setString(key, value);
}
vector<pair<string,string> > Config::getPropertiesFromContainer(const Properties &propertiesObj) const {
vector<pair<string,string> > result;
int count = propertiesObj.getPropertyCount();
for(int i = 0; i < count; ++i) {
pair<string,string> property;
property.first = propertiesObj.getKey(i);
property.second = propertiesObj.getString(i);
result.push_back(property);
}
return result;
}
vector<pair<string,string> > Config::getMergedProperties() const {
vector<pair<string,string> > result = getMasterProperties();
vector<pair<string,string> > resultUser = getUserProperties();
for(int i = 0; i < resultUser.size(); ++i) {
const pair<string,string> &propertyUser = resultUser[i];
bool overrideProperty = false;
for(int j = 0; j < result.size(); ++j) {
pair<string,string> &property = result[j];
// Take the user property and override the original value
if(property.first == propertyUser.first) {
property.second = propertyUser.second;
break;
}
}
if(overrideProperty == false) {
result.push_back(propertyUser);
}
}
return result;
}
vector<pair<string,string> > Config::getMasterProperties() const {
return getPropertiesFromContainer(properties.first);
}
vector<pair<string,string> > Config::getUserProperties() const {
return getPropertiesFromContainer(properties.second);
}
string Config::toString(){
return properties.first.toString();
}

View File

@ -53,6 +53,7 @@ protected:
char translateStringToCharKey(const string &value) const;
static void CopyAll(Config *src,Config *dest);
vector<pair<string,string> > getPropertiesFromContainer(const Properties &propertiesObj) const;
public:
static Config &getInstance(std::pair<ConfigType,ConfigType> type = std::make_pair(cfgMainGame,cfgUserGame) ,
@ -79,6 +80,10 @@ public:
vector<string> getPathListForType(PathType type, string scenarioDir = "");
vector<pair<string,string> > getMergedProperties() const;
vector<pair<string,string> > getMasterProperties() const;
vector<pair<string,string> > getUserProperties() const;
string toString();
};

View File

@ -95,6 +95,7 @@ const char *GAME_ARGS[] = {
"--data-path",
"--ini-path",
"--log-path",
"--show-ini-settings",
"--verbose"
};
@ -115,6 +116,7 @@ enum GAME_ARG_TYPE {
GAME_ARG_DATA_PATH,
GAME_ARG_INI_PATH,
GAME_ARG_LOG_PATH,
GAME_ARG_SHOW_INI_SETTINGS,
GAME_ARG_VERBOSE_MODE
};
@ -799,6 +801,9 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) {
printf("\n \t\texample: %s %s=~/game_config/",argv0,GAME_ARGS[GAME_ARG_INI_PATH]);
printf("\n%s=x\t\t\tSets the game logs path to x",GAME_ARGS[GAME_ARG_LOG_PATH]);
printf("\n \t\texample: %s %s=~/game_logs/",argv0,GAME_ARGS[GAME_ARG_LOG_PATH]);
printf("\n%s=x\t\t\tdisplays merged ini settings information.",GAME_ARGS[GAME_ARG_SHOW_INI_SETTINGS]);
printf("\n \t\tWhere x is an optional property name to filter (default shows all).");
printf("\n \t\texample: %s %s=DebugMode",argv0,GAME_ARGS[GAME_ARG_SHOW_INI_SETTINGS]);
printf("\n%s\t\t\tdisplays verbose information in the console.",GAME_ARGS[GAME_ARG_VERBOSE_MODE]);
printf("\n\n");
@ -1151,7 +1156,8 @@ int glestMain(int argc, char** argv) {
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_SDL_INFO]) == true ||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LUA_INFO]) == true ||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_CURL_INFO]) == true ||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VERSION]) == true ||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VERSION]) == true ||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_SHOW_INI_SETTINGS]) == true ||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]) == true ||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]) == true) {
haveSpecialOutputCommandLineOption = true;
@ -1214,9 +1220,6 @@ int glestMain(int argc, char** argv) {
return setupResult;
}
// Setup the file crc thread
std::auto_ptr<FileCRCPreCacheThread> preCacheThread;
// Attempt to read ini files
Config &config = Config::getInstance();
@ -1273,6 +1276,77 @@ int glestMain(int argc, char** argv) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_SHOW_INI_SETTINGS]) == true) {
vector<string> filteredPropertyList;
if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_SHOW_INI_SETTINGS]) + string("=")) == true) {
int foundParamIndIndex = -1;
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_SHOW_INI_SETTINGS]) + string("="),&foundParamIndIndex);
string filterList = argv[foundParamIndIndex];
vector<string> paramPartTokens;
Tokenize(filterList,paramPartTokens,"=");
if(paramPartTokens.size() >= 2) {
string tokenList = paramPartTokens[1];
Tokenize(tokenList,filteredPropertyList,",");
if(filteredPropertyList.size() > 0) {
printf("Filtering techtrees and only looking for the following:\n");
for(int idx = 0; idx < filteredPropertyList.size(); ++idx) {
filteredPropertyList[idx] = trim(filteredPropertyList[idx]);
printf("%s\n",filteredPropertyList[idx].c_str());
}
}
}
}
printf("Main settings report\n");
printf("====================\n");
vector<pair<string,string> > mergedMainSettings = config.getMergedProperties();
for(int i = 0; i < mergedMainSettings.size(); ++i) {
const pair<string,string> &nameValue = mergedMainSettings[i];
bool displayProperty = false;
if(filteredPropertyList.size() > 0) {
if(find(filteredPropertyList.begin(),filteredPropertyList.end(),nameValue.first) != filteredPropertyList.end()) {
displayProperty = true;
}
}
else {
displayProperty = true;
}
if(displayProperty == true) {
printf("Property Name [%s]\t\t\t\tValue[%s]\n",nameValue.first.c_str(),nameValue.second.c_str());
}
}
printf("\n\nMain key binding settings report\n");
printf("====================================\n");
vector<pair<string,string> > mergedKeySettings = configKeys.getMergedProperties();
for(int i = 0; i < mergedKeySettings.size(); ++i) {
const pair<string,string> &nameValue = mergedKeySettings[i];
bool displayProperty = false;
if(filteredPropertyList.size() > 0) {
if(find(filteredPropertyList.begin(),filteredPropertyList.end(),nameValue.first) != filteredPropertyList.end()) {
displayProperty = true;
}
}
else {
displayProperty = true;
}
if(displayProperty == true) {
printf("Property Name [%s]\t\t\t\tValue[%s]\n",nameValue.first.c_str(),nameValue.second.c_str());
}
}
return -1;
}
// Setup the file crc thread
std::auto_ptr<FileCRCPreCacheThread> preCacheThread;
//float pingTime = Socket::getAveragePingMS("soft-haus.com");
//printf("Ping time = %f\n",pingTime);

View File

@ -49,9 +49,9 @@ public:
void load(const string &path);
void save(const string &path);
int getPropertyCount() {return (int)propertyVector.size();}
string getKey(int i) {return propertyVector[i].first;}
string getString(int i) {return propertyVector[i].second;}
int getPropertyCount() const {return (int)propertyVector.size();}
string getKey(int i) const {return propertyVector[i].first;}
string getString(int i) const {return propertyVector[i].second;}
bool getBool(const string &key, const char *defaultValueIfNotFound=NULL) const;
int getInt(const string &key, const char *defaultValueIfNotFound=NULL) const;