From d14b13e285b04dee161f2fe993a15c95f1751f95 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 15 Apr 2011 00:09:38 +0000 Subject: [PATCH] - added a new cancel button for connected menu to cancel all current and queued file transfers --- .../menu/menu_state_connected_game.cpp | 79 ++++++++++++++++++- .../menu/menu_state_connected_game.h | 1 + .../platform/common/platform_common.cpp | 4 + .../sources/platform/posix/miniftpclient.cpp | 8 +- 4 files changed, 88 insertions(+), 4 deletions(-) diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index cd967e42..acfdd363 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -141,8 +141,9 @@ MenuStateConnectedGame::MenuStateConnectedGame(Program *program, MainMenu *mainM buttonDisconnect.registerGraphicComponent(containerName,"buttonDisconnect"); buttonDisconnect.init(350, 180, 125); - - + buttonCancelDownloads.registerGraphicComponent(containerName,"buttonCancelDownloads"); + buttonCancelDownloads.init(10, 150, 125); + buttonCancelDownloads.setText(lang.get("CancelDownloads")); xoffset=170; // fog - o - war @@ -580,6 +581,76 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){ } } } + else if(buttonCancelDownloads.mouseClick(x,y)) { + if(ftpClientThread != NULL && fileFTPProgressList.size() > 0) { + ftpClientThread->setCallBackObject(NULL); + if(ftpClientThread->shutdownAndWait() == true) { + delete ftpClientThread; + } + + fileFTPProgressList.clear(); + getMissingMapFromFTPServerInProgress = false; + getMissingTilesetFromFTPServerInProgress = false; + getMissingTechtreeFromFTPServerInProgress = false; + getMissingMapFromFTPServer = ""; + getMissingTilesetFromFTPServer = ""; + getMissingTechtreeFromFTPServer = ""; + + ClientInterface *clientInterface = networkManager.getClientInterface(); + string serverUrl = clientInterface->getServerIpAddress(); + //int portNumber = config.getInt("FTPServerPort",intToStr(ServerSocket::getFTPServerPort()).c_str()); + int portNumber = clientInterface->getServerFTPPort(); + + if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] Using FTP port #: %d\n",__FILE__,__FUNCTION__,__LINE__,portNumber); + + Config &config = Config::getInstance(); + vector mapPathList = config.getPathListForType(ptMaps); + std::pair mapsPath; + if(mapPathList.size() > 0) { + mapsPath.first = mapPathList[0]; + } + if(mapPathList.size() > 1) { + mapsPath.second = mapPathList[1]; + } + std::pair tilesetsPath; + vector tilesetsList = Config::getInstance().getPathListForType(ptTilesets); + if(tilesetsList.size() > 0) { + tilesetsPath.first = tilesetsList[0]; + if(tilesetsList.size() > 1) { + tilesetsPath.second = tilesetsList[1]; + } + } + + std::pair techtreesPath; + vector techtreesList = Config::getInstance().getPathListForType(ptTechs); + if(techtreesList.size() > 0) { + techtreesPath.first = techtreesList[0]; + if(techtreesList.size() > 1) { + techtreesPath.second = techtreesList[1]; + } + } + + std::pair scenariosPath; + vector scenariosList = Config::getInstance().getPathListForType(ptScenarios); + if(scenariosList.size() > 0) { + scenariosPath.first = scenariosList[0]; + if(scenariosList.size() > 1) { + scenariosPath.second = scenariosList[1]; + } + } + + 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,fileArchiveExtractCommandSuccessResult); + ftpClientThread->start(); + } + } else if(buttonDisconnect.mouseClick(x,y)){ if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -759,6 +830,7 @@ void MenuStateConnectedGame::mouseMove(int x, int y, const MouseState *ms) { ftpMessageBox.mouseMove(x, y); } + buttonCancelDownloads.mouseMove(x, y); buttonDisconnect.mouseMove(x, y); bool editingPlayerName = false; @@ -925,7 +997,8 @@ void MenuStateConnectedGame::render() { MutexSafeWrapper safeMutexFTPProgress((ftpClientThread != NULL ? ftpClientThread->getProgressMutex() : NULL),string(__FILE__) + "_" + intToStr(__LINE__)); if(fileFTPProgressList.size() > 0) { Lang &lang= Lang::getInstance(); - int yLocation = buttonDisconnect.getY(); + renderer.renderButton(&buttonCancelDownloads); + int yLocation = buttonCancelDownloads.getY() - 20; for(std::map >::iterator iterMap = fileFTPProgressList.begin(); iterMap != fileFTPProgressList.end(); ++iterMap) { string progressLabelPrefix = lang.get("ModDownloading") + " " + iterMap->first + " "; diff --git a/source/glest_game/menu/menu_state_connected_game.h b/source/glest_game/menu/menu_state_connected_game.h index c21001a1..4e40b2f6 100644 --- a/source/glest_game/menu/menu_state_connected_game.h +++ b/source/glest_game/menu/menu_state_connected_game.h @@ -167,6 +167,7 @@ private: vector > factionCRCList; std::map > fileFTPProgressList; + GraphicButton buttonCancelDownloads; public: diff --git a/source/shared_lib/sources/platform/common/platform_common.cpp b/source/shared_lib/sources/platform/common/platform_common.cpp index f430bc00..da11a3ea 100644 --- a/source/shared_lib/sources/platform/common/platform_common.cpp +++ b/source/shared_lib/sources/platform/common/platform_common.cpp @@ -1513,6 +1513,7 @@ string getFullFileArchiveExtractCommand(string fileArchiveExtractCommand, bool executeShellCommand(string cmd, int expectedResult) { bool result = false; if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"About to run [%s]", cmd.c_str()); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("About to run [%s]", cmd.c_str()); #ifdef WIN32 FILE *file = _popen(cmd.c_str(),"r"); @@ -1521,12 +1522,14 @@ bool executeShellCommand(string cmd, int expectedResult) { #endif if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"file = [%p]", file); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("file = [%p]", file); if(file != NULL) { char szBuf[4096]=""; while(feof(file) == false) { if(fgets( szBuf, 4095, file) != NULL) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"%s",szBuf); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("%s",szBuf); } } #ifdef WIN32 @@ -1537,6 +1540,7 @@ bool executeShellCommand(string cmd, int expectedResult) { /* Close pipe and print return value. */ if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"Process returned %d\n", cmdRet); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Process 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 1dfde73a..711c0e4c 100644 --- a/source/shared_lib/sources/platform/posix/miniftpclient.cpp +++ b/source/shared_lib/sources/platform/posix/miniftpclient.cpp @@ -679,11 +679,13 @@ pair FTPClientThread::getTilesetFromServer(pair result = getFileFromServer(ftp_cct_Tileset, tileSetName, remotePath, destFileSaveAs,ftpUser, ftpUserPassword, pWantDirListOnly); + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("FTPClientThread::getTilesetFromServer [%s] remotePath [%s] destFileSaveAs [%s] getFolderContents = %d result.first = %d [%s] findArchive = %d\n",tileSetName.first.c_str(),remotePath.c_str(),destFileSaveAs.c_str(),getFolderContents,result.first,result.second.c_str(),findArchive); + // Extract the archive if(result.first == ftp_crt_SUCCESS) { if(findArchive == true) { @@ -1154,6 +1156,8 @@ pair FTPClientThread::getFileFromServer(FTP_Clien else { result.first = ftp_crt_SUCCESS; + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] result.first = %d wantDirListOnly = %p\n",__FILE__,__FUNCTION__,__LINE__,result.first,wantDirListOnly); + if(wantDirListOnly) { if(ftpfile.stream) { fclose(ftpfile.stream); @@ -1185,6 +1189,8 @@ pair FTPClientThread::getFileFromServer(FTP_Clien ftpfile.stream = NULL; } + if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d] result.first = %d\n",__FILE__,__FUNCTION__,__LINE__,result.first); + return result; }