- added new commandline option for inital code to validate a scenario.

This commit is contained in:
Mark Vejvoda 2011-04-06 18:58:48 +00:00
parent a6ccf539e6
commit 896cf7231d
1 changed files with 280 additions and 177 deletions

View File

@ -79,6 +79,7 @@ using namespace Shared::Platform;
using namespace Shared::Util;
using namespace Shared::Graphics;
using namespace Shared::Graphics::Gl;
using namespace Shared::Xml;
namespace Glest{ namespace Game{
@ -104,6 +105,7 @@ const char *GAME_ARGS[] = {
"--curl-info",
"--validate-techtrees",
"--validate-factions",
"--validate-scenario",
"--data-path",
"--ini-path",
"--log-path",
@ -130,6 +132,7 @@ enum GAME_ARG_TYPE {
GAME_ARG_CURL_INFO,
GAME_ARG_VALIDATE_TECHTREES,
GAME_ARG_VALIDATE_FACTIONS,
GAME_ARG_VALIDATE_SCENARIO,
GAME_ARG_DATA_PATH,
GAME_ARG_INI_PATH,
GAME_ARG_LOG_PATH,
@ -950,6 +953,13 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) {
printf("\n \t\t*NOTE: leaving the list empty is the same as running");
printf("\n \t\t%s",GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]);
printf("\n \t\texample: %s %s=tech,egypt",argv0,GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]);
printf("\n%s=x=purgeunused\t\tdisplays a report detailing any known problems related",GAME_ARGS[GAME_ARG_VALIDATE_SCENARIO]);
printf("\n \t\tto your selected scenario game data.");
printf("\n \t\tWhere x is a single scenario to validate.");
printf("\n \t\tWhere purgeunused is an optional parameter telling the validation to delete extra files in the scenario that are not used.");
printf("\n \t\texample: %s %s=stranded",argv0,GAME_ARGS[GAME_ARG_VALIDATE_SCENARIO]);
printf("\n%s=x\t\t\tSets the game data path to x",GAME_ARGS[GAME_ARG_DATA_PATH]);
printf("\n \t\texample: %s %s=/usr/local/game_data/",argv0,GAME_ARGS[GAME_ARG_DATA_PATH]);
printf("\n%s=x\t\t\tSets the game ini path to x",GAME_ARGS[GAME_ARG_INI_PATH]);
@ -1194,94 +1204,10 @@ void setupLogging(Config &config, bool haveSpecialOutputCommandLineOption) {
}
}
void runTechValidationReport(int argc, char** argv) {
//disableBacktrace=true;
printf("====== Started Validation ======\n");
bool purgeUnusedFiles = false;
double purgedMegaBytes=0;
void runTechValidationForPath(string techPath, string techName,
const std::vector<string> filteredFactionList, World &world,
bool purgeUnusedFiles,double &purgedMegaBytes) {
Config &config = Config::getInstance();
// Did the user pass a specific list of factions to validate?
std::vector<string> filteredFactionList;
if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]) + string("=")) == true) {
int foundParamIndIndex = -1;
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]) + string("="),&foundParamIndIndex);
string filterList = argv[foundParamIndIndex];
vector<string> paramPartTokens;
Tokenize(filterList,paramPartTokens,"=");
if(paramPartTokens.size() >= 2) {
string factionList = paramPartTokens[1];
Tokenize(factionList,filteredFactionList,",");
if(filteredFactionList.size() > 0) {
printf("Filtering factions and only looking for the following:\n");
for(int idx = 0; idx < filteredFactionList.size(); ++idx) {
filteredFactionList[idx] = trim(filteredFactionList[idx]);
printf("%s\n",filteredFactionList[idx].c_str());
}
}
if(paramPartTokens.size() >= 3) {
if(paramPartTokens[2] == "purgeunused") {
purgeUnusedFiles = true;
printf("*NOTE All unused faction files will be deleted!\n");
}
}
}
}
vector<string> results;
findDirs(config.getPathListForType(ptTechs), results);
vector<string> techTreeFiles = results;
// Did the user pass a specific list of techtrees to validate?
std::vector<string> filteredTechTreeList;
if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]) + string("=")) == true) {
int foundParamIndIndex = -1;
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]) + string("="),&foundParamIndIndex);
string filterList = argv[foundParamIndIndex];
vector<string> paramPartTokens;
Tokenize(filterList,paramPartTokens,"=");
if(paramPartTokens.size() >= 2) {
string techtreeList = paramPartTokens[1];
Tokenize(techtreeList,filteredTechTreeList,",");
if(filteredTechTreeList.size() > 0) {
printf("Filtering techtrees and only looking for the following:\n");
for(int idx = 0; idx < filteredTechTreeList.size(); ++idx) {
filteredTechTreeList[idx] = trim(filteredTechTreeList[idx]);
printf("%s\n",filteredTechTreeList[idx].c_str());
}
}
if(paramPartTokens.size() >= 3) {
if(paramPartTokens[2] == "purgeunused") {
purgeUnusedFiles = true;
printf("*NOTE All unused techtree files will be deleted!\n");
}
}
}
}
{
printf("\n---------------- Loading factions inside world ----------------");
World world;
vector<string> techPaths = config.getPathListForType(ptTechs);
for(int idx = 0; idx < techPaths.size(); idx++) {
string &techPath = techPaths[idx];
endPathWithSlash(techPath);
//printf("techPath [%s]\n",techPath.c_str());
for(int idx2 = 0; idx2 < techTreeFiles.size(); idx2++) {
string &techName = techTreeFiles[idx2];
if( filteredTechTreeList.size() == 0 ||
std::find(filteredTechTreeList.begin(),filteredTechTreeList.end(),techName) != filteredTechTreeList.end()) {
vector<string> factionsList;
findDirs(techPath + techName + "/factions/", factionsList, false, false);
@ -1308,7 +1234,9 @@ void runTechValidationReport(int argc, char** argv) {
bool techtree_errors = false;
std::map<string,int> loadedFileList;
vector<string> pathList = config.getPathListForType(ptTechs,"");
//vector<string> pathList = config.getPathListForType(ptTechs,"");
vector<string> pathList;
pathList.push_back(techPath);
world.loadTech(pathList, techName, factions, &checksum, loadedFileList);
// Fixup paths with ..
@ -1456,6 +1384,178 @@ void runTechValidationReport(int argc, char** argv) {
}
printf("----------------------------------------------------------------");
}
}
void runTechValidationReport(int argc, char** argv) {
//disableBacktrace=true;
printf("====== Started Validation ======\n");
bool purgeUnusedFiles = false;
double purgedMegaBytes=0;
Config &config = Config::getInstance();
// Did the user pass a specific scenario to validate?
if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_VALIDATE_SCENARIO]) + string("=")) == true) {
int foundParamIndIndex = -1;
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_VALIDATE_SCENARIO]) + string("="),&foundParamIndIndex);
string filterList = argv[foundParamIndIndex];
vector<string> paramPartTokens;
Tokenize(filterList,paramPartTokens,"=");
if(paramPartTokens.size() >= 2) {
vector<string> optionList;
string validateScenarioName = paramPartTokens[1];
printf("Filtering scenario: %s\n",validateScenarioName.c_str());
if(paramPartTokens.size() >= 3) {
if(paramPartTokens[2] == "purgeunused") {
purgeUnusedFiles = true;
printf("*NOTE All unused scenario files will be deleted!\n");
}
}
{
printf("\n---------------- Loading scenario inside world ----------------\n");
World world;
double purgedMegaBytes=0;
std::vector<string> filteredFactionList;
vector<string> scenarioPaths = config.getPathListForType(ptScenarios);
for(int idx = 0; idx < scenarioPaths.size(); idx++) {
string &scenarioPath = scenarioPaths[idx];
endPathWithSlash(scenarioPath);
//printf("techPath [%s]\n",techPath.c_str());
vector<string> scenarioList;
findDirs(scenarioPath, scenarioList, false, false);
for(int idx2 = 0; idx2 < scenarioList.size(); idx2++) {
string &scenarioName = scenarioList[idx2];
//printf("Found Scenario [%s] looking for [%s]\n",scenarioName.c_str(),validateScenarioName.c_str());
if(scenarioName == validateScenarioName) {
string file = scenarioPath + scenarioName + "/" + scenarioName + ".xml";
XmlTree xmlTree;
xmlTree.load(file);
const XmlNode *scenarioNode= xmlTree.getRootNode();
string techName = scenarioNode->getChild("tech-tree")->getAttribute("value")->getValue();
// Self Contained techtree?
string scenarioTechtree = scenarioPath + scenarioName + "/" + techName + "/" + techName + ".xml";
if(fileExists(scenarioTechtree) == true) {
string techPath = scenarioPath + scenarioName + "/";
printf("Found Scenario [%s] with custom techtree [%s] validating...\n",scenarioName.c_str(),techName.c_str());
runTechValidationForPath(techPath, techName, filteredFactionList,
world, purgeUnusedFiles,purgedMegaBytes);
}
//
//
// runTechValidationForPath(techPath, techName, filteredFactionList,
// world, purgeUnusedFiles,purgedMegaBytes);
}
}
}
printf("\n====== Finished Validation ======\n");
}
return;
}
else {
printf("\nInvalid missing scenario specified on commandline [%s] value [%s]\n\n",argv[foundParamIndIndex],(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
//printParameterHelp(argv[0],false);
return;
}
}
// Did the user pass a specific list of factions to validate?
std::vector<string> filteredFactionList;
if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]) + string("=")) == true) {
int foundParamIndIndex = -1;
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]) + string("="),&foundParamIndIndex);
string filterList = argv[foundParamIndIndex];
vector<string> paramPartTokens;
Tokenize(filterList,paramPartTokens,"=");
if(paramPartTokens.size() >= 2) {
string factionList = paramPartTokens[1];
Tokenize(factionList,filteredFactionList,",");
if(filteredFactionList.size() > 0) {
printf("Filtering factions and only looking for the following:\n");
for(int idx = 0; idx < filteredFactionList.size(); ++idx) {
filteredFactionList[idx] = trim(filteredFactionList[idx]);
printf("%s\n",filteredFactionList[idx].c_str());
}
}
if(paramPartTokens.size() >= 3) {
if(paramPartTokens[2] == "purgeunused") {
purgeUnusedFiles = true;
printf("*NOTE All unused faction files will be deleted!\n");
}
}
}
}
vector<string> results;
findDirs(config.getPathListForType(ptTechs), results);
vector<string> techTreeFiles = results;
// Did the user pass a specific list of techtrees to validate?
std::vector<string> filteredTechTreeList;
if(hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]) + string("=")) == true) {
int foundParamIndIndex = -1;
hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]) + string("="),&foundParamIndIndex);
string filterList = argv[foundParamIndIndex];
vector<string> paramPartTokens;
Tokenize(filterList,paramPartTokens,"=");
if(paramPartTokens.size() >= 2) {
string techtreeList = paramPartTokens[1];
Tokenize(techtreeList,filteredTechTreeList,",");
if(filteredTechTreeList.size() > 0) {
printf("Filtering techtrees and only looking for the following:\n");
for(int idx = 0; idx < filteredTechTreeList.size(); ++idx) {
filteredTechTreeList[idx] = trim(filteredTechTreeList[idx]);
printf("%s\n",filteredTechTreeList[idx].c_str());
}
}
if(paramPartTokens.size() >= 3) {
if(paramPartTokens[2] == "purgeunused") {
purgeUnusedFiles = true;
printf("*NOTE All unused techtree files will be deleted!\n");
}
}
}
}
{
printf("\n---------------- Loading factions inside world ----------------");
World world;
vector<string> techPaths = config.getPathListForType(ptTechs);
for(int idx = 0; idx < techPaths.size(); idx++) {
string &techPath = techPaths[idx];
endPathWithSlash(techPath);
//printf("techPath [%s]\n",techPath.c_str());
for(int idx2 = 0; idx2 < techTreeFiles.size(); idx2++) {
string &techName = techTreeFiles[idx2];
if( filteredTechTreeList.size() == 0 ||
std::find(filteredTechTreeList.begin(),filteredTechTreeList.end(),techName) != filteredTechTreeList.end()) {
runTechValidationForPath(techPath, techName, filteredFactionList,
world, purgeUnusedFiles,purgedMegaBytes);
}
}
}
@ -1866,7 +1966,8 @@ int glestMain(int argc, char** argv) {
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) {
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]) == true ||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_SCENARIO]) == true) {
haveSpecialOutputCommandLineOption = true;
}
@ -1908,7 +2009,8 @@ int glestMain(int argc, char** argv) {
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_CURL_INFO]) == true) &&
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_OPENGL_INFO]) == false &&
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]) == false &&
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]) == false) {
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]) == false &&
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_SCENARIO]) == false) {
return -1;
}
@ -2235,7 +2337,8 @@ int glestMain(int argc, char** argv) {
}
if( hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_TECHTREES]) == true ||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]) == true) {
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_FACTIONS]) == true ||
hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_SCENARIO]) == true) {
runTechValidationReport(argc, argv);