From 42a67379603fac5368142bb0adcf06abb65d4d68 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Sat, 9 Apr 2011 22:20:10 +0000 Subject: [PATCH] - proper detection that user does not have 7z installed in their path --- mk/linux/glest.ini | 1 + .../menu/menu_state_connected_game.cpp | 3 ++- source/glest_game/menu/menu_state_mods.cpp | 7 +++++-- .../include/platform/common/platform_common.h | 3 ++- .../include/platform/posix/miniftpclient.h | 4 +++- .../platform/common/platform_common.cpp | 6 +++--- .../sources/platform/posix/miniftpclient.cpp | 20 ++++++++++--------- 7 files changed, 27 insertions(+), 17 deletions(-) diff --git a/mk/linux/glest.ini b/mk/linux/glest.ini index 08010569..3c01f928 100644 --- a/mk/linux/glest.ini +++ b/mk/linux/glest.ini @@ -32,6 +32,7 @@ FastSpeedLoops=2 FileArchiveExtension=.7z FileArchiveExtractCommand=7z FileArchiveExtractCommandParameters=x -o{outputpath} {archivename} +FileArchiveExtractCommandSuccessResult=0 Filter=Bilinear FilterMaxAnisotropy=1 FirstTime=false diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index 1361ba0e..66f4ca36 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -455,11 +455,12 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM string fileArchiveExtension = config.getString("FileArchiveExtension",""); string fileArchiveExtractCommand = config.getString("FileArchiveExtractCommand",""); string fileArchiveExtractCommandParameters = config.getString("FileArchiveExtractCommandParameters",""); + int32 fileArchiveExtractCommandSuccessResult = config.getInt("FileArchiveExtractCommandSuccessResult","0"); ftpClientThread = new FTPClientThread(portNumber,serverUrl, mapsPath,tilesetsPath,techtreesPath,scenariosPath, this,fileArchiveExtension,fileArchiveExtractCommand, - fileArchiveExtractCommandParameters); + fileArchiveExtractCommandParameters,fileArchiveExtractCommandSuccessResult); ftpClientThread->start(); } diff --git a/source/glest_game/menu/menu_state_mods.cpp b/source/glest_game/menu/menu_state_mods.cpp index 7761fefc..1e63d1a8 100644 --- a/source/glest_game/menu/menu_state_mods.cpp +++ b/source/glest_game/menu/menu_state_mods.cpp @@ -245,13 +245,15 @@ MenuStateMods::MenuStateMods(Program *program, MainMenu *mainMenu) : string fileArchiveExtension = config.getString("FileArchiveExtension",""); string fileArchiveExtractCommand = config.getString("FileArchiveExtractCommand",""); string fileArchiveExtractCommandParameters = config.getString("FileArchiveExtractCommandParameters",""); + int32 fileArchiveExtractCommandSuccessResult = config.getInt("FileArchiveExtractCommandSuccessResult","0"); if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); ftpClientThread = new FTPClientThread(-1,"", mapsPath,tilesetsPath,techtreesPath,scenariosPath, this,fileArchiveExtension,fileArchiveExtractCommand, - fileArchiveExtractCommandParameters); + fileArchiveExtractCommandParameters, + fileArchiveExtractCommandSuccessResult); ftpClientThread->start(); @@ -274,7 +276,8 @@ void MenuStateMods::simpleTask(BaseThread *callingThread) { Lang &lang= Lang::getInstance(); Config &config = Config::getInstance(); string fileArchiveExtractCommand = config.getString("FileArchiveExtractCommand",""); - bool findArchive = executeShellCommand(fileArchiveExtractCommand); + int expectedResult = config.getInt("FileArchiveExtractCommandSuccessResult","0"); + bool findArchive = executeShellCommand(fileArchiveExtractCommand,expectedResult); if(findArchive == false) { mainMessageBoxState = ftpmsg_None; mainMessageBox.init(lang.get("Ok")); diff --git a/source/shared_lib/include/platform/common/platform_common.h b/source/shared_lib/include/platform/common/platform_common.h index 8590d310..8a0b66e2 100644 --- a/source/shared_lib/include/platform/common/platform_common.h +++ b/source/shared_lib/include/platform/common/platform_common.h @@ -39,6 +39,7 @@ using Shared::Util::Checksum; namespace Shared { namespace PlatformCommon { +static const int IGNORE_CMD_RESULT_VALUE = -999999; // ===================================================== // class PerformanceTimer // ===================================================== @@ -191,7 +192,7 @@ inline string trim (const string & s, const string & t = SPACES) { string getFullFileArchiveExtractCommand(string fileArchiveExtractCommand, string fileArchiveExtractCommandParameters, string outputpath, string archivename); -bool executeShellCommand(string cmd); +bool executeShellCommand(string cmd,int expectedResult=IGNORE_CMD_RESULT_VALUE); class ValueCheckerVault { diff --git a/source/shared_lib/include/platform/posix/miniftpclient.h b/source/shared_lib/include/platform/posix/miniftpclient.h index b717dcd0..40a511ec 100644 --- a/source/shared_lib/include/platform/posix/miniftpclient.h +++ b/source/shared_lib/include/platform/posix/miniftpclient.h @@ -104,6 +104,7 @@ protected: string fileArchiveExtension; string fileArchiveExtractCommand; string fileArchiveExtractCommandParameters; + int fileArchiveExtractCommandSuccessResult; pair getFileFromServer(FTP_Client_CallbackType downloadType, pair fileNameTitle, @@ -120,7 +121,8 @@ public: FTPClientCallbackInterface *pCBObject, string fileArchiveExtension, string fileArchiveExtractCommand, - string fileArchiveExtractCommandParameters); + string fileArchiveExtractCommandParameters, + int fileArchiveExtractCommandSuccessResult); virtual void execute(); virtual void signalQuit(); virtual bool shutdownAndWait(); diff --git a/source/shared_lib/sources/platform/common/platform_common.cpp b/source/shared_lib/sources/platform/common/platform_common.cpp index 09b040e5..608489fd 100644 --- a/source/shared_lib/sources/platform/common/platform_common.cpp +++ b/source/shared_lib/sources/platform/common/platform_common.cpp @@ -1475,7 +1475,7 @@ string getFullFileArchiveExtractCommand(string fileArchiveExtractCommand, return result; } -bool executeShellCommand(string cmd) { +bool executeShellCommand(string cmd, int expectedResult) { bool result = false; if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\nAbout to run [%s]", cmd.c_str()); @@ -1501,8 +1501,8 @@ bool executeShellCommand(string cmd) { #endif /* Close pipe and print return value. */ - if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\nProcess returned %d", cmdRet); - result = true; + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\nProcess returned %d\n", cmdRet); + result = (expectedResult == IGNORE_CMD_RESULT_VALUE || expectedResult == cmdRet); } return result; } diff --git a/source/shared_lib/sources/platform/posix/miniftpclient.cpp b/source/shared_lib/sources/platform/posix/miniftpclient.cpp index accc7d56..f935063d 100644 --- a/source/shared_lib/sources/platform/posix/miniftpclient.cpp +++ b/source/shared_lib/sources/platform/posix/miniftpclient.cpp @@ -219,7 +219,8 @@ FTPClientThread::FTPClientThread(int portNumber, string serverUrl, FTPClientCallbackInterface *pCBObject, string fileArchiveExtension, string fileArchiveExtractCommand, - string fileArchiveExtractCommandParameters) : BaseThread() { + string fileArchiveExtractCommandParameters, + int fileArchiveExtractCommandSuccessResult) : BaseThread() { this->portNumber = portNumber; this->serverUrl = serverUrl; this->mapsPath = mapsPath; @@ -231,6 +232,7 @@ FTPClientThread::FTPClientThread(int portNumber, string serverUrl, this->fileArchiveExtension = fileArchiveExtension; this->fileArchiveExtractCommand = fileArchiveExtractCommand; this->fileArchiveExtractCommandParameters = fileArchiveExtractCommandParameters; + this->fileArchiveExtractCommandSuccessResult = fileArchiveExtractCommandSuccessResult; if(SystemFlags::getSystemSettingType(SystemFlags::debugNetwork).enabled) SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line %d] Using FTP port #: %d, serverUrl [%s]\n",__FILE__,__FUNCTION__,__LINE__,portNumber,serverUrl.c_str()); } @@ -413,7 +415,7 @@ void FTPClientThread::addFileToRequests(string fileName,string URL) { } void FTPClientThread::getTilesetFromServer(pair tileSetName) { - bool findArchive = executeShellCommand(this->fileArchiveExtractCommand); + bool findArchive = executeShellCommand(this->fileArchiveExtractCommand,this->fileArchiveExtractCommandSuccessResult); pair result = make_pair(ftp_crt_FAIL,""); if(tileSetName.second != "") { @@ -676,7 +678,7 @@ pair FTPClientThread::getTilesetFromServer(pairfileArchiveExtractCommandParameters, destRootArchiveFolder, destRootArchiveFolder + tileSetName.first + this->fileArchiveExtension); - if(executeShellCommand(extractCmd) == false) { + if(executeShellCommand(extractCmd,this->fileArchiveExtractCommandSuccessResult) == false) { result.first = ftp_crt_FAIL; result.second = "failed to extract arhcive!"; } @@ -730,7 +732,7 @@ pair FTPClientThread::getTilesetFromServer(pair techtreeName) { pair result = make_pair(ftp_crt_FAIL,""); - bool findArchive = executeShellCommand(this->fileArchiveExtractCommand); + bool findArchive = executeShellCommand(this->fileArchiveExtractCommand,this->fileArchiveExtractCommandSuccessResult); if(findArchive == true) { if(techtreeName.second != "") { result = getTechtreeFromServer(techtreeName, "", ""); @@ -905,7 +907,7 @@ pair FTPClientThread::getTechtreeFromServer(pair< this->fileArchiveExtractCommandParameters, destRootArchiveFolder, destRootArchiveFolder + techtreeName.first + this->fileArchiveExtension); - if(executeShellCommand(extractCmd) == false) { + if(executeShellCommand(extractCmd,this->fileArchiveExtractCommandSuccessResult) == false) { result.first = ftp_crt_FAIL; result.second = "failed to extract archive!"; } @@ -917,7 +919,7 @@ pair FTPClientThread::getTechtreeFromServer(pair< void FTPClientThread::getScenarioFromServer(pair fileName) { pair result = make_pair(ftp_crt_FAIL,""); - bool findArchive = executeShellCommand(this->fileArchiveExtractCommand); + bool findArchive = executeShellCommand(this->fileArchiveExtractCommand,this->fileArchiveExtractCommandSuccessResult); if(findArchive == true) { result = getScenarioInternalFromServer(fileName); } @@ -956,7 +958,7 @@ pair FTPClientThread::getScenarioInternalFromServ this->fileArchiveExtractCommandParameters, destRootArchiveFolder, destRootArchiveFolder + fileName.first + this->fileArchiveExtension); - if(executeShellCommand(extractCmd) == false) { + if(executeShellCommand(extractCmd,this->fileArchiveExtractCommandSuccessResult) == false) { result.first = ftp_crt_FAIL; result.second = "failed to extract archive!"; } @@ -972,7 +974,7 @@ void FTPClientThread::getFileFromServer(pair fileName) { bool findArchive = true; string ext = extractExtension(fileName.first); if(ext == "7z") { - findArchive = executeShellCommand(this->fileArchiveExtractCommand); + findArchive = executeShellCommand(this->fileArchiveExtractCommand,this->fileArchiveExtractCommandSuccessResult); } if(findArchive == true) { result = getFileInternalFromServer(fileName); @@ -1020,7 +1022,7 @@ pair FTPClientThread::getFileInternalFromServer(p this->fileArchiveExtractCommandParameters, destRootArchiveFolder, destFileSaveAs); - if(executeShellCommand(extractCmd) == false) { + if(executeShellCommand(extractCmd,this->fileArchiveExtractCommandSuccessResult) == false) { result.first = ftp_crt_FAIL; result.second = "failed to extract archive!"; }