diff --git a/mk/linux/glest.ini b/mk/linux/glest.ini index 672e955ae..09df49a17 100644 --- a/mk/linux/glest.ini +++ b/mk/linux/glest.ini @@ -35,6 +35,9 @@ FileArchiveExtension=.7z FileArchiveExtractCommand=7z FileArchiveExtractCommandParameters=x -o{outputpath} {archivename} FileArchiveExtractCommandSuccessResult=0 +FileArchiveCompressCommand=7z +FileArchiveCompressCommandParameters=a -r {archivename} {archivefiles} +FileArchiveCompressCommandSuccessResult=0 Filter=Bilinear FilterMaxAnisotropy=1 FirstTime=false diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index d1156881d..95dfe9cb3 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -2142,11 +2142,20 @@ void runTechValidationForPath(string techPath, string techName, replaceAll(file, "//", "/"); replaceAll(file, "\\\\", "\\"); + // ignore loading screen, preview screen and hud if( file.find(GameConstants::LOADING_SCREEN_FILE) != string::npos || file.find(GameConstants::PREVIEW_SCREEN_FILE) != string::npos || file.find(GameConstants::HUD_SCREEN_FILE) != string::npos) { continue; } + + // ignore commondata since we are not loading all factions + if(filteredFactionList.size() > 0) { + if( file.find("/commondata/") != string::npos) { + continue; + } + } + if(file.find("/factions/") != string::npos) { bool includeFaction = false; for ( set::iterator it = factions.begin(); it != factions.end(); ++it ) { @@ -3594,10 +3603,11 @@ int glestMain(int argc, char** argv) { hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_TILESET]) == true || hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_TRANSLATE_TECHTREES]) == true || hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_MAPS]) == true || - hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_TECHTRESS]) == true || - hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_SCENARIOS]) == true || - hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_TILESETS]) == true || - hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_TUTORIALS]) == true) { + hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_TECHTRESS]) == true || + hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_SCENARIOS]) == true || + hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_TILESETS]) == true || + hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_TUTORIALS]) == true || + hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_CREATE_DATA_ARCHIVES]) == true) { haveSpecialOutputCommandLineOption = true; } @@ -3720,10 +3730,11 @@ int glestMain(int argc, char** argv) { hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_VALIDATE_TILESET]) == true || hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_TRANSLATE_TECHTREES]) == true || hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_MAPS]) == true || - hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_TECHTRESS]) == true || - hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_SCENARIOS]) == true || - hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_TILESETS]) == true || - hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_TUTORIALS]) == true) { + hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_TECHTRESS]) == true || + hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_SCENARIOS]) == true || + hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_TILESETS]) == true || + hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_TUTORIALS]) == true || + hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_CREATE_DATA_ARCHIVES]) == true) { VideoPlayer::setDisabled(true); } @@ -3781,7 +3792,8 @@ int glestMain(int argc, char** argv) { hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_TECHTRESS]) == false && hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_SCENARIOS]) == false && hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_TILESETS]) == false && - hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_TUTORIALS]) == false) { + hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_LIST_TUTORIALS]) == false && + hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_CREATE_DATA_ARCHIVES]) == false) { return 0; } @@ -4402,6 +4414,143 @@ int glestMain(int argc, char** argv) { } } + if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_CREATE_DATA_ARCHIVES]) == true) { + int foundParamIndIndex = -1; + hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_CREATE_DATA_ARCHIVES]) + string("="),&foundParamIndIndex); + if(foundParamIndIndex < 0) { + hasCommandArgument(argc, argv,string(GAME_ARGS[GAME_ARG_CREATE_DATA_ARCHIVES]),&foundParamIndIndex); + } + string paramValue = argv[foundParamIndIndex]; + vector paramPartTokens; + Tokenize(paramValue,paramPartTokens,"="); + if(paramPartTokens.size() >= 2 && paramPartTokens[1].length() > 0) { + string compress_item = paramPartTokens[1]; + + string fileArchiveExtension = config.getString("FileArchiveExtension",""); + string fileArchiveCompressCommand = config.getString("FileArchiveCompressCommand",""); + string fileArchiveCompressCommandParameters = config.getString("FileArchiveCompressCommandParameters",""); + int32 fileArchiveCompressCommandSuccessResult = config.getInt("FileArchiveCompressCommandSuccessResult","0"); + + int typesSelected = 0; + if(compress_item == "techtrees" || compress_item == "all") { + typesSelected++; + + vector pathList = config.getPathListForType(ptTechs,""); + vector results; + findDirs(pathList, results); + + printf("Techtrees found:\n===========================================\n"); + for(unsigned int i = 0; i < results.size(); ++i) { + string name = results[i]; + + for(unsigned int j = 0; j < pathList.size(); ++j) { + string techPath = pathList[j]; + if(techPath != "") { + endPathWithSlash(techPath); + } + vector results2; + findDirs(techPath + name + "/factions", results2, false,true); + if(results2.empty() == false) { + string downloadArchive = techPath + name + ".7z"; + + //printf("Test downloadArchive [%s]\n",downloadArchive.c_str()); + + if(fileExists(downloadArchive) == true) { + bool removed = removeFile(downloadArchive); + if(removed == false) { + printf("Error could not remove old file: [%s]\n",downloadArchive.c_str()); + } + } + string compressCmd = getFullFileArchiveCompressCommand( + fileArchiveCompressCommand, + fileArchiveCompressCommandParameters, + downloadArchive,techPath + name ); + + printf("Running compression command: %s\n",compressCmd.c_str()); + + if(executeShellCommand(compressCmd,fileArchiveCompressCommandSuccessResult) == false) { + printf("Error could not create new file: [%s]\n",downloadArchive.c_str()); + } + + if(fileExists(downloadArchive) == true) { + off_t fileSize = getFileSize(downloadArchive); + // convert to MB + double megaBytes = ((double)fileSize / 1048576.0); + printf("%s [download archive %.2fMB]\n",name.c_str(),megaBytes); + } + } + } + } + printf("===========================================\nTotal: " MG_SIZE_T_SPECIFIER "\n",results.size()); + } + if(compress_item == "tilesets" || compress_item == "all") { + typesSelected++; + + vector pathList = config.getPathListForType(ptTilesets,""); + vector results; + findDirs(pathList, results); + + printf("Tilesets found:\n===========================================\n"); + for(unsigned int i = 0; i < results.size(); ++i) { + string name = results[i]; + + for(unsigned int j = 0; j < pathList.size(); ++j) { + string tilesetPath = pathList[j]; + if(tilesetPath != "") { + endPathWithSlash(tilesetPath); + } + if(fileExists(tilesetPath + name + "/" + name + ".xml") == true) { + string downloadArchive = tilesetPath + name + ".7z"; + + //printf("Test downloadArchive [%s]\n",downloadArchive.c_str()); + + if(fileExists(downloadArchive) == true) { + bool removed = removeFile(downloadArchive); + if(removed == false) { + printf("Error could not remove old file: [%s]\n",downloadArchive.c_str()); + } + } + string compressCmd = getFullFileArchiveCompressCommand( + fileArchiveCompressCommand, + fileArchiveCompressCommandParameters, + downloadArchive,tilesetPath + name ); + + printf("Running compression command: %s\n",compressCmd.c_str()); + + if(executeShellCommand(compressCmd,fileArchiveCompressCommandSuccessResult) == false) { + printf("Error could not create new file: [%s]\n",downloadArchive.c_str()); + } + + if(fileExists(downloadArchive) == true) { + off_t fileSize = getFileSize(downloadArchive); + // convert to MB + double megaBytes = ((double)fileSize / 1048576.0); + printf("%s [download archive %.2fMB]\n",name.c_str(),megaBytes); + } + + break; + } + } + } + printf("===========================================\nTotal: " MG_SIZE_T_SPECIFIER "\n",results.size()); + + } + if(typesSelected == 0) { + printf("Compress item [%s] is not valid!\n",compress_item.c_str()); + return 1; + } + + return 0; + } + else { + printf("\nInvalid missing map specified on commandline [%s] value [%s]\n\n",argv[foundParamIndIndex],(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL)); + //printParameterHelp(argv[0],false); + + return 1; + } + } + + SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_SHOW_MAP_CRC]) == true) { diff --git a/source/shared_lib/include/platform/common/platform_common.h b/source/shared_lib/include/platform/common/platform_common.h index 4e7ab6b06..ed34644f8 100644 --- a/source/shared_lib/include/platform/common/platform_common.h +++ b/source/shared_lib/include/platform/common/platform_common.h @@ -291,6 +291,9 @@ inline string trim (const string & s, const string & t = SPACES) { string getFullFileArchiveExtractCommand(string fileArchiveExtractCommand, string fileArchiveExtractCommandParameters, string outputpath, string archivename); +string getFullFileArchiveCompressCommand(string fileArchiveCompressCommand, + string fileArchiveCompressCommandParameters, string archivename, string archivefiles); + bool executeShellCommand(string cmd,int expectedResult=IGNORE_CMD_RESULT_VALUE,ShellCommandOutputCallbackInterface *cb=NULL); string executable_path(string exeName,bool includeExeNameInPath=false); diff --git a/source/shared_lib/include/platform/sdl/platform_main.h b/source/shared_lib/include/platform/sdl/platform_main.h index 2bf79f454..ef93f7265 100644 --- a/source/shared_lib/include/platform/sdl/platform_main.h +++ b/source/shared_lib/include/platform/sdl/platform_main.h @@ -93,6 +93,8 @@ const char *GAME_ARGS[] = { "--debug-network-packets", "--enable-new-protocol", + "--create-data-archives", + "--verbose" }; @@ -171,6 +173,8 @@ enum GAME_ARG_TYPE { GAME_ARG_DEBUG_NETWORK_PACKETS, GAME_ARG_ENABLE_NEW_PROTOCOL, + GAME_ARG_CREATE_DATA_ARCHIVES, + GAME_ARG_VERBOSE_MODE, GAME_ARG_END @@ -477,6 +481,11 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) { printf("\n%s\t\tdisables opengl capability checks (for corrupt or flaky video drivers).",GAME_ARGS[GAME_ARG_DISABLE_OPENGL_CAPS_CHECK]); + printf("\n%s=x\t\t\tcompress selected game data into archives for network sharing.",GAME_ARGS[GAME_ARG_CREATE_DATA_ARCHIVES]); + printf("\n \t\tWhere x is one of the following data items to compress."); + printf("\n \t\ttechtrees, tilesets or all."); + printf("\n \t\texample: %s %s=all",extractFileFromDirectoryPath(argv0).c_str(),GAME_ARGS[GAME_ARG_CREATE_DATA_ARCHIVES]); + printf("\n%s\t\t\tdisplays verbose information in the console.",GAME_ARGS[GAME_ARG_VERBOSE_MODE]); printf("\n\n"); diff --git a/source/shared_lib/sources/platform/common/platform_common.cpp b/source/shared_lib/sources/platform/common/platform_common.cpp index ca07284af..8cd7ac4b6 100644 --- a/source/shared_lib/sources/platform/common/platform_common.cpp +++ b/source/shared_lib/sources/platform/common/platform_common.cpp @@ -2005,6 +2005,30 @@ string getFullFileArchiveExtractCommand(string fileArchiveExtractCommand, return result; } +string getFullFileArchiveCompressCommand(string fileArchiveCompressCommand, + string fileArchiveCompressCommandParameters, + string archivename, string archivefiles) { + string parsedArchivename = archivename; + string parsedArchivefiles = archivefiles; + +// This is required for execution on win32 +#if defined(WIN32) + replaceAll(parsedArchivename, "\\\\", "\\"); + replaceAll(parsedArchivename, "/", "\\"); + replaceAll(parsedArchivefiles, "\\\\", "\\"); + replaceAll(parsedArchivefiles, "/", "\\"); + +#endif + + string result = fileArchiveCompressCommand; + result += " "; + string args = replaceAll(fileArchiveCompressCommandParameters, "{archivename}", parsedArchivename); + args = replaceAll(args, "{archivefiles}", parsedArchivefiles); + result += args; + + return result; +} + bool executeShellCommand(string cmd, int expectedResult, ShellCommandOutputCallbackInterface *cb) { bool result = false; if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"About to run [%s]", cmd.c_str());