From f6b0bd3fd749f0c5602e45e5c3499807aa8e199a Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 14 Jan 2011 17:57:37 +0000 Subject: [PATCH] - some ftp file transfer bugfixes and moved many strings into language file --- source/glest_game/global/lang.cpp | 14 +++ source/glest_game/global/lang.h | 1 + .../menu/menu_state_connected_game.cpp | 89 ++++++++++++++----- .../sources/platform/posix/miniftpclient.cpp | 44 ++++++--- 4 files changed, 114 insertions(+), 34 deletions(-) diff --git a/source/glest_game/global/lang.cpp b/source/glest_game/global/lang.cpp index 670911f9..0d8efa47 100644 --- a/source/glest_game/global/lang.cpp +++ b/source/glest_game/global/lang.cpp @@ -73,6 +73,20 @@ void Lang::loadScenarioStrings(const string &scenarioDir, const string &scenario } } +bool Lang::hasString(const string &s) { + bool hasString = false; + try { + string result = strings.getString(s); + hasString = true; + } + catch(exception &ex) { + if(strings.getpath() != "") { + SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); + } + } + return hasString; +} + string Lang::get(const string &s) { try{ string result = strings.getString(s); diff --git a/source/glest_game/global/lang.h b/source/glest_game/global/lang.h index 820b3262..dc0c7038 100644 --- a/source/glest_game/global/lang.h +++ b/source/glest_game/global/lang.h @@ -39,6 +39,7 @@ public: void loadStrings(const string &language); void loadScenarioStrings(const string &scenarioDir, const string &scenarioName); string get(const string &s); + bool hasString(const string &s); string getScenarioString(const string &s); }; diff --git a/source/glest_game/menu/menu_state_connected_game.cpp b/source/glest_game/menu/menu_state_connected_game.cpp index 9af7bee0..43e763a2 100644 --- a/source/glest_game/menu/menu_state_connected_game.cpp +++ b/source/glest_game/menu/menu_state_connected_game.cpp @@ -434,6 +434,7 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){ SoundRenderer &soundRenderer= SoundRenderer::getInstance(); NetworkManager &networkManager= NetworkManager::getInstance(); ClientInterface* clientInterface= networkManager.getClientInterface(); + Lang &lang= Lang::getInstance(); if(mainMessageBox.getEnabled()) { int button= 1; @@ -454,7 +455,12 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){ getMissingMapFromFTPServerInProgress = true; char szMsg[1024]=""; - sprintf(szMsg,"Player: %s is attempting to download the map: %s",getHumanPlayerName().c_str(),getMissingMapFromFTPServer.c_str()); + if(lang.hasString("DataMissingMapNowDownloading") == true) { + sprintf(szMsg,lang.get("DataMissingMapNowDownloading").c_str(),getHumanPlayerName().c_str(),getMissingMapFromFTPServer.c_str()); + } + else { + sprintf(szMsg,"Player: %s is attempting to download the map: %s",getHumanPlayerName().c_str(),getMissingMapFromFTPServer.c_str()); + } clientInterface->sendTextMessage(szMsg,-1, true); if(ftpClientThread != NULL) { @@ -467,7 +473,12 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){ getMissingTilesetFromFTPServerInProgress = true; char szMsg[1024]=""; - sprintf(szMsg,"Player: %s is attempting to download the tileset: %s",getHumanPlayerName().c_str(),getMissingTilesetFromFTPServer.c_str()); + if(lang.hasString("DataMissingTilesetNowDownloading") == true) { + sprintf(szMsg,lang.get("DataMissingTilesetNowDownloading").c_str(),getHumanPlayerName().c_str(),getMissingTilesetFromFTPServer.c_str()); + } + else { + sprintf(szMsg,"Player: %s is attempting to download the tileset: %s",getHumanPlayerName().c_str(),getMissingTilesetFromFTPServer.c_str()); + } clientInterface->sendTextMessage(szMsg,-1, true); if(ftpClientThread != NULL) { @@ -485,7 +496,7 @@ void MenuStateConnectedGame::mouseClick(int x, int y, MouseButton mouseButton){ soundRenderer.playFx(coreData.getClickSoundA()); if(clientInterface->getSocket() != NULL) { if(clientInterface->isConnected() == true) { - string sQuitText = "chose to leave the game!"; + string sQuitText = lang.get("QuitGame"); clientInterface->sendTextMessage(sQuitText,-1); sleep(1); } @@ -878,28 +889,29 @@ void MenuStateConnectedGame::update() { int32 mapCRC = checksum.getSum(); safeMutexFTPProgress.ReleaseLock(); - bool dataSynchMismatch = (mapCRC != gameSettings->getMapCRC() || tilesetCRC != gameSettings->getTilesetCRC()); + bool dataSynchMismatch = ((mapCRC != 0 && mapCRC != gameSettings->getMapCRC()) || + (tilesetCRC != 0 && tilesetCRC != gameSettings->getTilesetCRC())); //printf("\nmapCRC [%d] gameSettings->getMapCRC() [%d] tilesetCRC [%d] gameSettings->getTilesetCRC() [%d]\n",mapCRC,gameSettings->getMapCRC(),tilesetCRC,gameSettings->getTilesetCRC()); if(dataSynchMismatch == true) { - string labelSynch = "Game data synch mismatch for:"; + string labelSynch = lang.get("DataNotSynchedTitle"); - if(mapCRC != gameSettings->getMapCRC()) { - labelSynch = labelSynch + " map"; + if(mapCRC != 0 && mapCRC != gameSettings->getMapCRC()) { + labelSynch = labelSynch + " " + lang.get("Map"); if(updateDataSynchDetailText == true && - lastMapDataSynchError != "map CRC mismatch, " + listBoxMap.getSelectedItem()) { - lastMapDataSynchError = "map CRC mismatch, " + listBoxMap.getSelectedItem(); + lastMapDataSynchError != lang.get("DataNotSynchedMap") + " " + listBoxMap.getSelectedItem()) { + lastMapDataSynchError = lang.get("DataNotSynchedMap") + " " + listBoxMap.getSelectedItem(); clientInterface->sendTextMessage(lastMapDataSynchError,-1,true); } } - if(tilesetCRC != gameSettings->getTilesetCRC()) { - labelSynch = labelSynch + " tileset"; + if(tilesetCRC != 0 && tilesetCRC != gameSettings->getTilesetCRC()) { + labelSynch = labelSynch + " " + lang.get("Tileset"); if(updateDataSynchDetailText == true && - lastTileDataSynchError != "tileset CRC mismatch, " + listBoxTileset.getSelectedItem()) { - lastTileDataSynchError = "tileset CRC mismatch, " + listBoxTileset.getSelectedItem(); + lastTileDataSynchError != lang.get("DataNotSynchedTileset") + " " + listBoxTileset.getSelectedItem()) { + lastTileDataSynchError = lang.get("DataNotSynchedTileset") + " " + listBoxTileset.getSelectedItem(); clientInterface->sendTextMessage(lastTileDataSynchError,-1,true); } } @@ -1121,7 +1133,12 @@ void MenuStateConnectedGame::update() { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); char szMsg[1024]=""; - sprintf(szMsg,"Player: %s is missing the tileset: %s",getHumanPlayerName().c_str(),gameSettings->getTileset().c_str()); + if(lang.hasString("DataMissingTileset") == true) { + sprintf(szMsg,lang.get("DataMissingTileset").c_str(),getHumanPlayerName().c_str(),gameSettings->getTileset().c_str()); + } + else { + sprintf(szMsg,"Player: %s is missing the tileset: %s",getHumanPlayerName().c_str(),gameSettings->getTileset().c_str()); + } clientInterface->sendTextMessage(szMsg,-1, true); } } @@ -1408,6 +1425,7 @@ bool MenuStateConnectedGame::loadFactions(const GameSettings *gameSettings, bool bool foundFactions = false; vector results; Config &config = Config::getInstance(); + Lang &lang= Lang::getInstance(); vector techPaths = config.getPathListForType(ptTechs); for(int idx = 0; idx < techPaths.size(); idx++) { @@ -1440,7 +1458,12 @@ bool MenuStateConnectedGame::loadFactions(const GameSettings *gameSettings, bool lastMissingTechtree = gameSettings->getTech(); char szMsg[1024]=""; - sprintf(szMsg,"Player: %s is missing the techtree: %s",getHumanPlayerName().c_str(),gameSettings->getTech().c_str()); + if(lang.hasString("DataMissingTechtree") == true) { + sprintf(szMsg,lang.get("DataMissingTechtree").c_str(),getHumanPlayerName().c_str(),gameSettings->getTech().c_str()); + } + else { + sprintf(szMsg,"Player: %s is missing the techtree: %s",getHumanPlayerName().c_str(),gameSettings->getTech().c_str()); + } clientInterface->sendTextMessage(szMsg,-1, true); } @@ -1752,7 +1775,12 @@ bool MenuStateConnectedGame::loadMapInfo(string file, MapInfo *mapInfo, bool loa lastMissingMap = gameSettings->getMap(); char szMsg[1024]=""; - sprintf(szMsg,"Player: %s is missing the map: %s",getHumanPlayerName().c_str(),gameSettings->getMap().c_str()); + if(lang.hasString("DataMissingMap") == true) { + sprintf(szMsg,lang.get("DataMissingMap").c_str(),getHumanPlayerName().c_str(),gameSettings->getMap().c_str()); + } + else { + sprintf(szMsg,"Player: %s is missing the map: %s",getHumanPlayerName().c_str(),gameSettings->getMap().c_str()); + } clientInterface->sendTextMessage(szMsg,-1, true); } } @@ -1801,6 +1829,7 @@ void MenuStateConnectedGame::showFTPMessageBox(const string &text, const string void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName, FTP_Client_CallbackType type, FTP_Client_ResultType result, void *userdata) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__); + Lang &lang= Lang::getInstance(); if(type == ftp_cct_DownloadProgress) { FTPClientCallbackInterface::FtpProgressStats *stats = (FTPClientCallbackInterface::FtpProgressStats *)userdata; if(stats != NULL) { @@ -1830,14 +1859,24 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName, FTP_Client if(result == ftp_crt_SUCCESS) { char szMsg[1024]=""; - sprintf(szMsg,"Player: %s SUCCESSFULLY downloaded the map: %s",getHumanPlayerName().c_str(),gameSettings->getMap().c_str()); + if(lang.hasString("DataMissingMapSuccessDownload") == true) { + sprintf(szMsg,lang.get("DataMissingMapSuccessDownload").c_str(),getHumanPlayerName().c_str(),gameSettings->getMap().c_str()); + } + else { + sprintf(szMsg,"Player: %s SUCCESSFULLY downloaded the map: %s",getHumanPlayerName().c_str(),gameSettings->getMap().c_str()); + } clientInterface->sendTextMessage(szMsg,-1, true); } else { curl_version_info_data *curlVersion= curl_version_info(CURLVERSION_NOW); char szMsg[1024]=""; - sprintf(szMsg,"Player: %s FAILED to download the map: [%s] using CURL version [%s]",getHumanPlayerName().c_str(),gameSettings->getMap().c_str(),curlVersion->version); + if(lang.hasString("DataMissingMapFailDownload") == true) { + sprintf(szMsg,lang.get("DataMissingMapFailDownload").c_str(),getHumanPlayerName().c_str(),gameSettings->getMap().c_str(),curlVersion->version); + } + else { + sprintf(szMsg,"Player: %s FAILED to download the map: [%s] using CURL version [%s]",getHumanPlayerName().c_str(),gameSettings->getMap().c_str(),curlVersion->version); + } clientInterface->sendTextMessage(szMsg,-1, true); } } @@ -1855,7 +1894,12 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName, FTP_Client if(result == ftp_crt_SUCCESS) { char szMsg[1024]=""; - sprintf(szMsg,"Player: %s SUCCESSFULLY downloaded the tileset: %s",getHumanPlayerName().c_str(),gameSettings->getTileset().c_str()); + if(lang.hasString("DataMissingTilesetSuccessDownload") == true) { + sprintf(szMsg,lang.get("DataMissingTilesetSuccessDownload").c_str(),getHumanPlayerName().c_str(),gameSettings->getTileset().c_str()); + } + else { + sprintf(szMsg,"Player: %s SUCCESSFULLY downloaded the tileset: %s",getHumanPlayerName().c_str(),gameSettings->getTileset().c_str()); + } clientInterface->sendTextMessage(szMsg,-1, true); // START @@ -1906,7 +1950,12 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName, FTP_Client curl_version_info_data *curlVersion= curl_version_info(CURLVERSION_NOW); char szMsg[1024]=""; - sprintf(szMsg,"Player: %s FAILED to download the tileset: [%s] using CURL version [%s]",getHumanPlayerName().c_str(),gameSettings->getTileset().c_str(),curlVersion->version); + if(lang.hasString("DataMissingTilesetFailDownload") == true) { + sprintf(szMsg,lang.get("DataMissingTilesetFailDownload").c_str(),getHumanPlayerName().c_str(),gameSettings->getTileset().c_str(),curlVersion->version); + } + else { + sprintf(szMsg,"Player: %s FAILED to download the tileset: [%s] using CURL version [%s]",getHumanPlayerName().c_str(),gameSettings->getTileset().c_str(),curlVersion->version); + } clientInterface->sendTextMessage(szMsg,-1, true); } } diff --git a/source/shared_lib/sources/platform/posix/miniftpclient.cpp b/source/shared_lib/sources/platform/posix/miniftpclient.cpp index 330dee8b..19eb45a3 100644 --- a/source/shared_lib/sources/platform/posix/miniftpclient.cpp +++ b/source/shared_lib/sources/platform/posix/miniftpclient.cpp @@ -24,6 +24,12 @@ using namespace Shared::PlatformCommon; namespace Shared { namespace PlatformCommon { +const char *FTP_MAPS_CUSTOM_USERNAME = "maps_custom"; +const char *FTP_MAPS_USERNAME = "maps"; +const char *FTP_TILESETS_CUSTOM_USERNAME = "tilesets_custom"; +const char *FTP_TILESETS_USERNAME = "tilesets"; +const char *FTP_COMMON_PASSWORD = "mg_ftp_server"; + /* * This is an example showing how to get a single file from an FTP server. * It delays the actual destination file creation until the first write @@ -133,6 +139,9 @@ static long file_is_comming(struct curl_fileinfo *finfo,void *data,int remains) out->stream = fopen(fullFilePath.c_str(), "wb"); if(out->stream == NULL) { + if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Client thread FAILED to open file for writing [%s]\n",fullFilePath.c_str()); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"===> FTP Client thread FAILED to open file for writing [%s]\n",fullFilePath.c_str()); + return CURL_CHUNK_BGN_FUNC_FAIL; } } @@ -160,6 +169,9 @@ int file_progress(struct FtpFile *out,double download_total, double download_now out->ftpServer != NULL && out->ftpServer->getCallBackObject() != NULL) { if(out->ftpServer->getQuitStatus() == true) { + if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Client thread CANCELLED\n"); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"===> FTP Client thread CANCELLED\n"); + return -1; } FTPClientCallbackInterface::FtpProgressStats stats; @@ -260,24 +272,22 @@ FTP_Client_ResultType FTPClientThread::getMapFromServer(string mapFileName, stri if(ftpfile.stream) { fclose(ftpfile.stream); ftpfile.stream = NULL; - - if(result != ftp_crt_SUCCESS) { - unlink(destFile.c_str()); - } + } + if(result != ftp_crt_SUCCESS) { + unlink(destFile.c_str()); } return result; } - void FTPClientThread::getMapFromServer(string mapFileName) { - FTP_Client_ResultType result = getMapFromServer(mapFileName + ".mgm", "maps_custom", "mg_ftp_server"); + FTP_Client_ResultType result = getMapFromServer(mapFileName + ".mgm", FTP_MAPS_CUSTOM_USERNAME, FTP_COMMON_PASSWORD); if(result != ftp_crt_SUCCESS && this->getQuitStatus() == false) { - result = getMapFromServer(mapFileName + ".gbm", "maps_custom", "mg_ftp_server"); + result = getMapFromServer(mapFileName + ".gbm", FTP_MAPS_CUSTOM_USERNAME, FTP_COMMON_PASSWORD); if(result != ftp_crt_SUCCESS && this->getQuitStatus() == false) { - result = getMapFromServer(mapFileName + ".mgm", "maps", "mg_ftp_server"); + result = getMapFromServer(mapFileName + ".mgm", FTP_MAPS_USERNAME, FTP_COMMON_PASSWORD); if(result != ftp_crt_SUCCESS && this->getQuitStatus() == false) { - result = getMapFromServer(mapFileName + ".gbm", "maps", "mg_ftp_server"); + result = getMapFromServer(mapFileName + ".gbm", FTP_MAPS_USERNAME, FTP_COMMON_PASSWORD); } } } @@ -303,9 +313,9 @@ void FTPClientThread::addTilesetToRequests(string tileSetName) { } void FTPClientThread::getTilesetFromServer(string tileSetName) { - FTP_Client_ResultType result = getTilesetFromServer(tileSetName, "", "tilesets_custom", "mg_ftp_server"); + FTP_Client_ResultType result = getTilesetFromServer(tileSetName, "", FTP_TILESETS_CUSTOM_USERNAME, FTP_COMMON_PASSWORD); if(result != ftp_crt_SUCCESS && this->getQuitStatus() == false) { - result = getTilesetFromServer(tileSetName, "", "tilesets", "mg_ftp_server"); + result = getTilesetFromServer(tileSetName, "", FTP_TILESETS_USERNAME, FTP_COMMON_PASSWORD); } MutexSafeWrapper safeMutex(this->getProgressMutex()); @@ -404,8 +414,8 @@ FTP_Client_ResultType FTPClientThread::getTilesetFromServer(string tileSetName, if(CURLE_OK != res) { // we failed - printf("curl FAILED with: %d [%s]\n", res,curl_easy_strerror(res)); - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"curl FAILED with: %d [%s]\n", res,curl_easy_strerror(res)); + printf("curl FAILED with: %d [%s] attempting to remove folder contents [%s]\n", res,curl_easy_strerror(res),destRootFolder.c_str()); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"curl FAILED with: %d [%s] attempting to remove folder contents [%s]\n", res,curl_easy_strerror(res),destRootFolder.c_str()); if(destRootFolder != "") { //unlink(destRootFolder.c_str()); @@ -434,7 +444,13 @@ FTP_Client_ResultType FTPClientThread::getTilesetFromServer(string tileSetName, } if(requireMoreFolders == true) { - FTP_Client_ResultType result2 = getTilesetFromServer(tileSetName, tileSetNameSubfolder, ftpUser, ftpUserPassword); + result = getTilesetFromServer(tileSetName, tileSetNameSubfolder, ftpUser, ftpUserPassword); + if(result != ftp_crt_SUCCESS) { + if(destRootFolder != "") { + //unlink(destRootFolder.c_str()); + removeFolder(destRootFolder); + } + } } }