mirror of
https://github.com/glest/glest-source.git
synced 2025-02-25 04:02:30 +01:00
- fixed bug in mod menu where no messages were shown since tit's console class change.
- added new ftp status info and display output from 7z extraction as it happens in game so that the user knows something is happening (and to show errors)
This commit is contained in:
parent
7e581004d6
commit
4bde2882a6
@ -3142,7 +3142,6 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName,
|
||||
FTP_Client_CallbackType type, pair<FTP_Client_ResultType,string> result, void *userdata) {
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__);
|
||||
|
||||
//Lang &lang= Lang::getInstance();
|
||||
if(type == ftp_cct_DownloadProgress) {
|
||||
FTPClientCallbackInterface::FtpProgressStats *stats = (FTPClientCallbackInterface::FtpProgressStats *)userdata;
|
||||
if(stats != NULL) {
|
||||
@ -3177,6 +3176,33 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName,
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(type == ftp_cct_ExtractProgress) {
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Got FTP extract Callback for [%s] result = %d [%s]\n",itemName.c_str(),result.first,result.second.c_str());
|
||||
|
||||
if(userdata == NULL) {
|
||||
NetworkManager &networkManager= NetworkManager::getInstance();
|
||||
ClientInterface* clientInterface= networkManager.getClientInterface();
|
||||
|
||||
Lang &lang= Lang::getInstance();
|
||||
const vector<string> languageList = clientInterface->getGameSettings()->getUniqueNetworkPlayerLanguages();
|
||||
for(unsigned int i = 0; i < languageList.size(); ++i) {
|
||||
char szMsg[1024]="";
|
||||
if(lang.hasString("DataMissingExtractDownload",languageList[i]) == true) {
|
||||
sprintf(szMsg,lang.get("DataMissingExtractDownload",languageList[i]).c_str(),getHumanPlayerName().c_str(),itemName.c_str());
|
||||
}
|
||||
else {
|
||||
sprintf(szMsg,"Please wait, player: %s is extracting: %s",getHumanPlayerName().c_str(),itemName.c_str());
|
||||
}
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] szMsg [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,szMsg);
|
||||
clientInterface->sendTextMessage(szMsg,-1, lang.isLanguageLocal(languageList[i]),languageList[i]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
char *szBuf = (char *)userdata;
|
||||
//printf("%s\n",szBuf);
|
||||
console.addLine(szBuf);
|
||||
}
|
||||
}
|
||||
else if(type == ftp_cct_Map) {
|
||||
getMissingMapFromFTPServerInProgress = false;
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Got FTP Callback for [%s] result = %d [%s]\n",itemName.c_str(),result.first,result.second.c_str());
|
||||
@ -3192,10 +3218,8 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName,
|
||||
if(result.first == ftp_crt_SUCCESS) {
|
||||
// Clear the CRC file Cache
|
||||
Checksum::clearFileCache();
|
||||
//lastCheckedCRCMapValue = -1;
|
||||
Checksum checksum;
|
||||
string file = Map::getMapPath(itemName,"",false);
|
||||
//console.addLine("Checking map CRC [" + file + "]");
|
||||
checksum.addFile(file);
|
||||
lastCheckedCRCMapValue = checksum.getSum();
|
||||
|
||||
@ -3352,11 +3376,10 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName,
|
||||
safeMutexFTPProgress.ReleaseLock();
|
||||
// END
|
||||
|
||||
// Reload tilesets for the UI
|
||||
// Reload techs for the UI
|
||||
string scenarioDir = Scenario::getScenarioDir(dirList, gameSettings->getScenario());
|
||||
findDirs(Config::getInstance().getPathListForType(ptTechs,scenarioDir), techTreeFiles);
|
||||
|
||||
//int initialTechSelection=0;
|
||||
std::vector<string> techsFormatted = techTreeFiles;
|
||||
for(int i= 0; i < techsFormatted.size(); i++){
|
||||
techsFormatted.at(i)= formatString(techsFormatted.at(i));
|
||||
|
@ -302,6 +302,8 @@ MenuStateMods::MenuStateMods(Program *program, MainMenu *mainMenu) :
|
||||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
console.setOnlyChatMessagesInStoredLines(false);
|
||||
|
||||
ftpClientThread = new FTPClientThread(-1,"",
|
||||
mapsPath,tilesetsPath,techtreesPath,scenariosPath,
|
||||
this,fileArchiveExtension,fileArchiveExtractCommand,
|
||||
@ -2557,6 +2559,22 @@ void MenuStateMods::FTPClient_CallbackEvent(string itemName,
|
||||
safeMutexFTPProgress.ReleaseLock();
|
||||
}
|
||||
}
|
||||
else if(type == ftp_cct_ExtractProgress) {
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Got FTP extract Callback for [%s] result = %d [%s]\n",itemName.c_str(),result.first,result.second.c_str());
|
||||
//printf("Got FTP extract Callback for [%s] result = %d [%s]\n",itemName.c_str(),result.first,result.second.c_str());
|
||||
|
||||
if(userdata == NULL) {
|
||||
char szBuf[8096]="";
|
||||
sprintf(szBuf,lang.get("DataMissingExtractDownloadMod").c_str(),itemName.c_str());
|
||||
//printf("%s\n",szBuf);
|
||||
console.addLine(szBuf,true);
|
||||
}
|
||||
else {
|
||||
char *szBuf = (char *)userdata;
|
||||
//printf("%s\n",szBuf);
|
||||
console.addLine(szBuf);
|
||||
}
|
||||
}
|
||||
else if(type == ftp_cct_File) {
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Got FTP Callback for [%s] result = %d [%s]\n",itemName.c_str(),result.first,result.second.c_str());
|
||||
|
||||
|
@ -82,6 +82,14 @@ const char vkDelete = -26;
|
||||
const char vkPrint = -27;
|
||||
const char vkPause = -29;
|
||||
|
||||
class ShellCommandOutputCallbackInterface {
|
||||
public:
|
||||
virtual ~ShellCommandOutputCallbackInterface() {}
|
||||
|
||||
virtual void * getShellCommandOutput_UserData(string cmd) = 0;
|
||||
virtual void ShellCommandOutput_CallbackEvent(string cmd,char *output,void *userdata) = 0;
|
||||
};
|
||||
|
||||
// =====================================================
|
||||
// class PerformanceTimer
|
||||
// =====================================================
|
||||
@ -260,7 +268,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,int expectedResult=IGNORE_CMD_RESULT_VALUE);
|
||||
bool executeShellCommand(string cmd,int expectedResult=IGNORE_CMD_RESULT_VALUE,ShellCommandOutputCallbackInterface *cb=NULL);
|
||||
string executable_path(string exeName,bool includeExeNameInPath=false);
|
||||
|
||||
bool valid_utf8_file(const char* file_name);
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include "base_thread.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "platform_common.h"
|
||||
#include "leak_dumper.h"
|
||||
|
||||
using namespace std;
|
||||
@ -39,7 +39,8 @@ enum FTP_Client_CallbackType {
|
||||
ftp_cct_Techtree = 2,
|
||||
ftp_cct_Scenario = 3,
|
||||
ftp_cct_File = 4,
|
||||
ftp_cct_DownloadProgress = 5
|
||||
ftp_cct_DownloadProgress = 5,
|
||||
ftp_cct_ExtractProgress = 6
|
||||
};
|
||||
|
||||
class FTPClientCallbackInterface {
|
||||
@ -55,10 +56,12 @@ public:
|
||||
};
|
||||
|
||||
virtual void FTPClient_CallbackEvent(string itemName,
|
||||
FTP_Client_CallbackType type, pair<FTP_Client_ResultType,string> result, void *userdata) = 0;
|
||||
FTP_Client_CallbackType type,
|
||||
pair<FTP_Client_ResultType,string> result,
|
||||
void *userdata) = 0;
|
||||
};
|
||||
|
||||
class FTPClientThread : public BaseThread
|
||||
class FTPClientThread : public BaseThread, public ShellCommandOutputCallbackInterface
|
||||
{
|
||||
protected:
|
||||
int portNumber;
|
||||
@ -111,6 +114,10 @@ protected:
|
||||
string remotePath, string destFileSaveAs, string ftpUser,
|
||||
string ftpUserPassword, vector <string> *wantDirListOnly=NULL);
|
||||
|
||||
string shellCommandCallbackUserData;
|
||||
virtual void * getShellCommandOutput_UserData(string cmd);
|
||||
virtual void ShellCommandOutput_CallbackEvent(string cmd,char *output,void *userdata);
|
||||
|
||||
public:
|
||||
|
||||
FTPClientThread(int portNumber,string serverUrl,
|
||||
|
@ -1862,7 +1862,7 @@ string getFullFileArchiveExtractCommand(string fileArchiveExtractCommand,
|
||||
return result;
|
||||
}
|
||||
|
||||
bool executeShellCommand(string cmd, int expectedResult) {
|
||||
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());
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("About to run [%s]", cmd.c_str());
|
||||
@ -1882,6 +1882,10 @@ bool executeShellCommand(string cmd, int expectedResult) {
|
||||
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);
|
||||
|
||||
if(cb != NULL) {
|
||||
cb->ShellCommandOutput_CallbackEvent(cmd,szBuf,cb->getShellCommandOutput_UserData(cmd));
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef WIN32
|
||||
|
@ -218,7 +218,11 @@ int file_progress(struct FtpFile *out,double download_total, double download_now
|
||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||
MutexSafeWrapper safeMutex(out->ftpServer->getProgressMutex(),mutexOwnerId);
|
||||
out->ftpServer->getProgressMutex()->setOwnerId(mutexOwnerId);
|
||||
out->ftpServer->getCallBackObject()->FTPClient_CallbackEvent(out->itemName, ftp_cct_DownloadProgress, make_pair(ftp_crt_SUCCESS,""), &stats);
|
||||
out->ftpServer->getCallBackObject()->FTPClient_CallbackEvent(
|
||||
out->itemName,
|
||||
ftp_cct_DownloadProgress,
|
||||
make_pair(ftp_crt_SUCCESS,""),
|
||||
&stats);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -241,6 +245,7 @@ FTPClientThread::FTPClientThread(int portNumber, string serverUrl,
|
||||
this->techtreesPath = techtreesPath;
|
||||
this->scenariosPath = scenariosPath;
|
||||
this->pCBObject = pCBObject;
|
||||
this->shellCommandCallbackUserData = "";
|
||||
|
||||
this->fileArchiveExtension = fileArchiveExtension;
|
||||
this->fileArchiveExtractCommand = fileArchiveExtractCommand;
|
||||
@ -295,8 +300,6 @@ pair<FTP_Client_ResultType,string> FTPClientThread::getMapFromServer(pair<string
|
||||
ftp_cct_Map
|
||||
};
|
||||
|
||||
//curl_global_init(CURL_GLOBAL_DEFAULT);
|
||||
|
||||
CURL *curl = SystemFlags::initHTTP();
|
||||
if(curl) {
|
||||
ftpfile.stream = NULL;
|
||||
@ -385,7 +388,11 @@ void FTPClientThread::getMapFromServer(pair<string,string> mapFileName) {
|
||||
MutexSafeWrapper safeMutex(this->getProgressMutex(),mutexOwnerId);
|
||||
this->getProgressMutex()->setOwnerId(mutexOwnerId);
|
||||
if(this->pCBObject != NULL) {
|
||||
this->pCBObject->FTPClient_CallbackEvent(mapFileName.first,ftp_cct_Map,result,NULL);
|
||||
this->pCBObject->FTPClient_CallbackEvent(
|
||||
mapFileName.first,
|
||||
ftp_cct_Map,
|
||||
result,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -440,7 +447,9 @@ void FTPClientThread::addFileToRequests(string fileName,string URL) {
|
||||
}
|
||||
|
||||
void FTPClientThread::getTilesetFromServer(pair<string,string> tileSetName) {
|
||||
bool findArchive = executeShellCommand(this->fileArchiveExtractCommand,this->fileArchiveExtractCommandSuccessResult);
|
||||
bool findArchive = executeShellCommand(
|
||||
this->fileArchiveExtractCommand,
|
||||
this->fileArchiveExtractCommandSuccessResult);
|
||||
|
||||
pair<FTP_Client_ResultType,string> result = make_pair(ftp_crt_FAIL,"");
|
||||
if(tileSetName.second != "") {
|
||||
@ -466,180 +475,27 @@ void FTPClientThread::getTilesetFromServer(pair<string,string> tileSetName) {
|
||||
MutexSafeWrapper safeMutex(this->getProgressMutex(),mutexOwnerId);
|
||||
this->getProgressMutex()->setOwnerId(mutexOwnerId);
|
||||
if(this->pCBObject != NULL) {
|
||||
this->pCBObject->FTPClient_CallbackEvent(tileSetName.first,ftp_cct_Tileset,result,NULL);
|
||||
this->pCBObject->FTPClient_CallbackEvent(
|
||||
tileSetName.first,
|
||||
ftp_cct_Tileset,
|
||||
result,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
|
||||
pair<FTP_Client_ResultType,string> FTPClientThread::getTilesetFromServer(pair<string,string> tileSetName,
|
||||
string tileSetNameSubfolder, string ftpUser, string ftpUserPassword,
|
||||
bool findArchive) {
|
||||
|
||||
/*
|
||||
FTP_Client_ResultType result = ftp_crt_FAIL;
|
||||
string destFile = this->tilesetsPath.second;
|
||||
|
||||
// Root folder for the tileset
|
||||
string destRootArchiveFolder = "";
|
||||
string destRootFolder = "";
|
||||
if(tileSetNameSubfolder == "") {
|
||||
destRootFolder = this->tilesetsPath.second;
|
||||
endPathWithSlash(destRootFolder);
|
||||
|
||||
destRootArchiveFolder = destRootFolder;
|
||||
destRootFolder += tileSetName;
|
||||
endPathWithSlash(destRootFolder);
|
||||
|
||||
createDirectoryPaths(destRootFolder);
|
||||
}
|
||||
|
||||
endPathWithSlash(destFile);
|
||||
destFile += tileSetName;
|
||||
endPathWithSlash(destFile);
|
||||
|
||||
if(tileSetNameSubfolder != "") {
|
||||
destFile += tileSetNameSubfolder;
|
||||
endPathWithSlash(destFile);
|
||||
}
|
||||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Client thread about to try to RETR into [%s] findArchive = %d\n",destFile.c_str(),findArchive);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"===> FTP Client thread about to try to RETR into [%s] findArchive = %d\n",destFile.c_str(),findArchive);
|
||||
|
||||
struct FtpFile ftpfile = {
|
||||
tileSetName.c_str(),
|
||||
destFile.c_str(), // name to store the file as if successful
|
||||
destFile.c_str(),
|
||||
NULL,
|
||||
this,
|
||||
"",
|
||||
false
|
||||
};
|
||||
|
||||
if(findArchive == true) {
|
||||
ftpfile.filepath = destRootArchiveFolder.c_str();
|
||||
}
|
||||
|
||||
CURL *curl = SystemFlags::initHTTP();
|
||||
if(curl) {
|
||||
ftpfile.stream = NULL;
|
||||
|
||||
char szBuf[1024]="";
|
||||
if(tileSetNameSubfolder == "") {
|
||||
if(findArchive == true) {
|
||||
sprintf(szBuf,"ftp://%s:%s@%s:%d/%s%s",ftpUser.c_str(),ftpUserPassword.c_str(),serverUrl.c_str(),portNumber,tileSetName.c_str(),this->fileArchiveExtension.c_str());
|
||||
}
|
||||
else {
|
||||
sprintf(szBuf,"ftp://%s:%s@%s:%d/%s/*",ftpUser.c_str(),ftpUserPassword.c_str(),serverUrl.c_str(),portNumber,tileSetName.c_str());
|
||||
}
|
||||
}
|
||||
else {
|
||||
sprintf(szBuf,"ftp://%s:%s@%s:%d/%s/%s/*",ftpUser.c_str(),ftpUserPassword.c_str(),serverUrl.c_str(),portNumber,tileSetName.c_str(),tileSetNameSubfolder.c_str());
|
||||
}
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL,szBuf);
|
||||
curl_easy_setopt(curl, CURLOPT_FTP_USE_EPSV, 0L);
|
||||
|
||||
// turn on wildcard matching
|
||||
curl_easy_setopt(curl, CURLOPT_WILDCARDMATCH, 1L);
|
||||
|
||||
// callback is called before download of concrete file started
|
||||
curl_easy_setopt(curl, CURLOPT_CHUNK_BGN_FUNCTION, file_is_comming);
|
||||
// callback is called after data from the file have been transferred
|
||||
curl_easy_setopt(curl, CURLOPT_CHUNK_END_FUNCTION, file_is_downloaded);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_CHUNK_DATA, &ftpfile);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);
|
||||
|
||||
// Define our callback to get called when there's data to be written
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
|
||||
// Set a pointer to our struct to pass to the callback
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
|
||||
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, file_progress);
|
||||
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &ftpfile);
|
||||
|
||||
// Max 10 minutes to transfer
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 600);
|
||||
|
||||
// Switch on full protocol/debug output
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
||||
|
||||
CURLcode res = curl_easy_perform(curl);
|
||||
|
||||
if(res != CURLE_OK) {
|
||||
// we failed
|
||||
printf("curl FAILED with: %d [%s] attempting to remove folder contents [%s] szBuf [%s] ftpfile.isValidXfer = %d\n", res,curl_easy_strerror(res),destRootFolder.c_str(),szBuf,ftpfile.isValidXfer);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"curl FAILED with: %d [%s] attempting to remove folder contents [%s] szBuf [%s] ftpfile.isValidXfer = %d\n", res,curl_easy_strerror(res),destRootFolder.c_str(),szBuf,ftpfile.isValidXfer);
|
||||
|
||||
if(res == CURLE_PARTIAL_FILE || ftpfile.isValidXfer == true) {
|
||||
result = ftp_crt_PARTIALFAIL;
|
||||
}
|
||||
|
||||
if(destRootFolder != "") {
|
||||
removeFolder(destRootFolder);
|
||||
}
|
||||
}
|
||||
else {
|
||||
result = ftp_crt_SUCCESS;
|
||||
|
||||
bool requireMoreFolders = false;
|
||||
|
||||
if(findArchive == false) {
|
||||
if(tileSetNameSubfolder == "") {
|
||||
tileSetNameSubfolder = "models";
|
||||
requireMoreFolders = true;
|
||||
}
|
||||
else if(tileSetNameSubfolder == "models") {
|
||||
tileSetNameSubfolder = "sounds";
|
||||
requireMoreFolders = true;
|
||||
}
|
||||
else if(tileSetNameSubfolder == "sounds") {
|
||||
tileSetNameSubfolder = "textures";
|
||||
requireMoreFolders = true;
|
||||
}
|
||||
else if(tileSetNameSubfolder == "textures") {
|
||||
tileSetNameSubfolder = "";
|
||||
requireMoreFolders = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(requireMoreFolders == true) {
|
||||
result = getTilesetFromServer(tileSetName, tileSetNameSubfolder, ftpUser, ftpUserPassword, false);
|
||||
if(result != ftp_crt_SUCCESS) {
|
||||
if(destRootFolder != "") {
|
||||
removeFolder(destRootFolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SystemFlags::cleanupHTTP(&curl);
|
||||
}
|
||||
|
||||
if(ftpfile.stream) {
|
||||
fclose(ftpfile.stream);
|
||||
ftpfile.stream = NULL;
|
||||
}
|
||||
|
||||
// Extract the archive
|
||||
if(findArchive == true && result == ftp_crt_SUCCESS) {
|
||||
string extractCmd = getFullFileArchiveExtractCommand(this->fileArchiveExtractCommand,
|
||||
this->fileArchiveExtractCommandParameters, destRootArchiveFolder,
|
||||
destRootArchiveFolder + tileSetName + this->fileArchiveExtension);
|
||||
|
||||
if(executeShellCommand(extractCmd) == false) {
|
||||
result = ftp_crt_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
*/
|
||||
pair<FTP_Client_ResultType,string> FTPClientThread::getTilesetFromServer(
|
||||
pair<string,string> tileSetName,
|
||||
string tileSetNameSubfolder,
|
||||
string ftpUser,
|
||||
string ftpUserPassword,
|
||||
bool findArchive) {
|
||||
|
||||
string destFileSaveAsNewFile = "";
|
||||
string destFileSaveAs = "";
|
||||
string remotePath = "";
|
||||
bool getFolderContents = false;
|
||||
vector<string> wantDirListOnly;
|
||||
|
||||
if(tileSetNameSubfolder == "") {
|
||||
if(findArchive == true) {
|
||||
destFileSaveAs = this->tilesetsPath.second;
|
||||
@ -692,8 +548,14 @@ pair<FTP_Client_ResultType,string> FTPClientThread::getTilesetFromServer(pair<st
|
||||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("FTPClientThread::getTilesetFromServer [%s] remotePath [%s] destFileSaveAs [%s] getFolderContents = %d findArchive = %d\n",tileSetName.first.c_str(),remotePath.c_str(),destFileSaveAs.c_str(),getFolderContents,findArchive);
|
||||
|
||||
pair<FTP_Client_ResultType,string> result = getFileFromServer(ftp_cct_Tileset,
|
||||
tileSetName, remotePath, destFileSaveAs,ftpUser, ftpUserPassword, pWantDirListOnly);
|
||||
pair<FTP_Client_ResultType,string> 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);
|
||||
|
||||
@ -703,13 +565,27 @@ pair<FTP_Client_ResultType,string> FTPClientThread::getTilesetFromServer(pair<st
|
||||
string destRootArchiveFolder = this->tilesetsPath.second;
|
||||
endPathWithSlash(destRootArchiveFolder);
|
||||
|
||||
string extractCmd = getFullFileArchiveExtractCommand(this->fileArchiveExtractCommand,
|
||||
this->fileArchiveExtractCommandParameters, destRootArchiveFolder,
|
||||
string extractCmd = getFullFileArchiveExtractCommand(
|
||||
this->fileArchiveExtractCommand,
|
||||
this->fileArchiveExtractCommandParameters,
|
||||
destRootArchiveFolder,
|
||||
destRootArchiveFolder + tileSetName.first + this->fileArchiveExtension);
|
||||
|
||||
if(executeShellCommand(extractCmd,this->fileArchiveExtractCommandSuccessResult) == false) {
|
||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||
MutexSafeWrapper safeMutex(this->getProgressMutex(),mutexOwnerId);
|
||||
this->getProgressMutex()->setOwnerId(mutexOwnerId);
|
||||
|
||||
if(this->pCBObject != NULL) {
|
||||
this->shellCommandCallbackUserData = tileSetName.first;
|
||||
this->pCBObject->FTPClient_CallbackEvent(
|
||||
tileSetName.first,
|
||||
ftp_cct_ExtractProgress,
|
||||
make_pair(ftp_crt_SUCCESS,"extracting"),NULL);
|
||||
}
|
||||
|
||||
if(executeShellCommand(extractCmd,this->fileArchiveExtractCommandSuccessResult,this) == false) {
|
||||
result.first = ftp_crt_FAIL;
|
||||
result.second = "failed to extract arhcive!";
|
||||
result.second = "failed to extract archive!";
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -761,7 +637,9 @@ pair<FTP_Client_ResultType,string> FTPClientThread::getTilesetFromServer(pair<st
|
||||
|
||||
void FTPClientThread::getTechtreeFromServer(pair<string,string> techtreeName) {
|
||||
pair<FTP_Client_ResultType,string> result = make_pair(ftp_crt_FAIL,"");
|
||||
bool findArchive = executeShellCommand(this->fileArchiveExtractCommand,this->fileArchiveExtractCommandSuccessResult);
|
||||
bool findArchive = executeShellCommand(
|
||||
this->fileArchiveExtractCommand,
|
||||
this->fileArchiveExtractCommandSuccessResult);
|
||||
if(findArchive == true) {
|
||||
if(techtreeName.second != "") {
|
||||
result = getTechtreeFromServer(techtreeName, "", "");
|
||||
@ -778,139 +656,17 @@ void FTPClientThread::getTechtreeFromServer(pair<string,string> techtreeName) {
|
||||
MutexSafeWrapper safeMutex(this->getProgressMutex(),mutexOwnerId);
|
||||
this->getProgressMutex()->setOwnerId(mutexOwnerId);
|
||||
if(this->pCBObject != NULL) {
|
||||
this->pCBObject->FTPClient_CallbackEvent(techtreeName.first,ftp_cct_Techtree,result,NULL);
|
||||
this->pCBObject->FTPClient_CallbackEvent(
|
||||
techtreeName.first,
|
||||
ftp_cct_Techtree,
|
||||
result,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
|
||||
pair<FTP_Client_ResultType,string> FTPClientThread::getTechtreeFromServer(pair<string,string> techtreeName,
|
||||
string ftpUser, string ftpUserPassword) {
|
||||
|
||||
/*
|
||||
FTP_Client_ResultType result = ftp_crt_FAIL;
|
||||
|
||||
string destFile = this->techtreesPath.second;
|
||||
|
||||
// Root folder for the techtree
|
||||
string destRootArchiveFolder = "";
|
||||
string destRootFolder = "";
|
||||
destRootFolder = this->techtreesPath.second;
|
||||
endPathWithSlash(destRootFolder);
|
||||
destRootArchiveFolder = destRootFolder;
|
||||
destRootFolder += techtreeName;
|
||||
endPathWithSlash(destRootFolder);
|
||||
|
||||
createDirectoryPaths(destRootFolder);
|
||||
|
||||
endPathWithSlash(destFile);
|
||||
destFile += techtreeName;
|
||||
string destFileSaveAs = destFile + this->fileArchiveExtension;
|
||||
endPathWithSlash(destFile);
|
||||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Client thread about to try to RETR into [%s]\n",destFileSaveAs.c_str());
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"===> FTP Client thread about to try to RETR into [%s]\n",destFileSaveAs.c_str());
|
||||
|
||||
|
||||
// struct FtpFile ftpfile = {
|
||||
// techtreeName.c_str(),
|
||||
// destFile.c_str(), // name to store the file as if succesful
|
||||
// destFile.c_str(),
|
||||
// NULL,
|
||||
// this,
|
||||
// "",
|
||||
// false
|
||||
// };
|
||||
//
|
||||
// ftpfile.filepath = destRootArchiveFolder.c_str();
|
||||
|
||||
|
||||
struct FtpFile ftpfile = {
|
||||
techtreeName.c_str(),
|
||||
destFileSaveAs.c_str(), // name to store the file as if succesful
|
||||
NULL,
|
||||
NULL,
|
||||
this,
|
||||
"",
|
||||
false
|
||||
};
|
||||
|
||||
CURL *curl = SystemFlags::initHTTP();
|
||||
if(curl) {
|
||||
ftpfile.stream = NULL;
|
||||
|
||||
char szBuf[1024]="";
|
||||
sprintf(szBuf,"ftp://%s:%s@%s:%d/%s%s",ftpUser.c_str(),ftpUserPassword.c_str(),serverUrl.c_str(),portNumber,techtreeName.c_str(),this->fileArchiveExtension.c_str());
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_URL,szBuf);
|
||||
curl_easy_setopt(curl, CURLOPT_FTP_USE_EPSV, 0L);
|
||||
|
||||
// turn on wildcard matching
|
||||
//curl_easy_setopt(curl, CURLOPT_WILDCARDMATCH, 1L);
|
||||
|
||||
// callback is called before download of concrete file started
|
||||
//curl_easy_setopt(curl, CURLOPT_CHUNK_BGN_FUNCTION, file_is_comming);
|
||||
// callback is called after data from the file have been transferred
|
||||
//curl_easy_setopt(curl, CURLOPT_CHUNK_END_FUNCTION, file_is_downloaded);
|
||||
|
||||
//curl_easy_setopt(curl, CURLOPT_CHUNK_DATA, &ftpfile);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);
|
||||
|
||||
// Define our callback to get called when there's data to be written
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, my_fwrite);
|
||||
// Set a pointer to our struct to pass to the callback
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);
|
||||
|
||||
curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L);
|
||||
curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, file_progress);
|
||||
curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &ftpfile);
|
||||
|
||||
// Max 10 minutes to transfer
|
||||
curl_easy_setopt(curl, CURLOPT_TIMEOUT, 600);
|
||||
|
||||
// Switch on full protocol/debug output
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
||||
|
||||
CURLcode res = curl_easy_perform(curl);
|
||||
|
||||
if(res != CURLE_OK) {
|
||||
// we failed
|
||||
printf("curl FAILED with: %d [%s] attempting to remove folder contents [%s] szBuf [%s] ftpfile.isValidXfer = %d\n", res,curl_easy_strerror(res),destRootFolder.c_str(),szBuf,ftpfile.isValidXfer);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugNetwork,"curl FAILED with: %d [%s] attempting to remove folder contents [%s] szBuf [%s] ftpfile.isValidXfer = %d\n", res,curl_easy_strerror(res),destRootFolder.c_str(),szBuf,ftpfile.isValidXfer);
|
||||
|
||||
if(res == CURLE_PARTIAL_FILE || ftpfile.isValidXfer == true) {
|
||||
result = ftp_crt_PARTIALFAIL;
|
||||
}
|
||||
|
||||
if(destRootFolder != "") {
|
||||
removeFolder(destRootFolder);
|
||||
}
|
||||
}
|
||||
else {
|
||||
result = ftp_crt_SUCCESS;
|
||||
}
|
||||
|
||||
SystemFlags::cleanupHTTP(&curl);
|
||||
}
|
||||
|
||||
if(ftpfile.stream) {
|
||||
fclose(ftpfile.stream);
|
||||
ftpfile.stream = NULL;
|
||||
}
|
||||
|
||||
// Extract the archive
|
||||
if(result == ftp_crt_SUCCESS) {
|
||||
string extractCmd = getFullFileArchiveExtractCommand(this->fileArchiveExtractCommand,
|
||||
this->fileArchiveExtractCommandParameters, destRootArchiveFolder,
|
||||
destRootArchiveFolder + techtreeName + this->fileArchiveExtension);
|
||||
|
||||
if(executeShellCommand(extractCmd) == false) {
|
||||
result = ftp_crt_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
*/
|
||||
|
||||
|
||||
// Root folder for the techtree
|
||||
string destRootFolder = this->techtreesPath.second;
|
||||
endPathWithSlash(destRootFolder);
|
||||
@ -934,11 +690,24 @@ pair<FTP_Client_ResultType,string> FTPClientThread::getTechtreeFromServer(pair<
|
||||
|
||||
// Extract the archive
|
||||
if(result.first == ftp_crt_SUCCESS) {
|
||||
string extractCmd = getFullFileArchiveExtractCommand(this->fileArchiveExtractCommand,
|
||||
this->fileArchiveExtractCommandParameters, destRootArchiveFolder,
|
||||
string extractCmd = getFullFileArchiveExtractCommand(
|
||||
this->fileArchiveExtractCommand,
|
||||
this->fileArchiveExtractCommandParameters,
|
||||
destRootArchiveFolder,
|
||||
destRootArchiveFolder + techtreeName.first + this->fileArchiveExtension);
|
||||
|
||||
if(executeShellCommand(extractCmd,this->fileArchiveExtractCommandSuccessResult) == false) {
|
||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||
MutexSafeWrapper safeMutex(this->getProgressMutex(),mutexOwnerId);
|
||||
this->getProgressMutex()->setOwnerId(mutexOwnerId);
|
||||
if(this->pCBObject != NULL) {
|
||||
this->shellCommandCallbackUserData = techtreeName.first;
|
||||
this->pCBObject->FTPClient_CallbackEvent(
|
||||
techtreeName.first,
|
||||
ftp_cct_ExtractProgress,
|
||||
make_pair(ftp_crt_SUCCESS,"extracting"),NULL);
|
||||
}
|
||||
|
||||
if(executeShellCommand(extractCmd,this->fileArchiveExtractCommandSuccessResult,this) == false) {
|
||||
result.first = ftp_crt_FAIL;
|
||||
result.second = "failed to extract archive!";
|
||||
}
|
||||
@ -950,7 +719,9 @@ pair<FTP_Client_ResultType,string> FTPClientThread::getTechtreeFromServer(pair<
|
||||
|
||||
void FTPClientThread::getScenarioFromServer(pair<string,string> fileName) {
|
||||
pair<FTP_Client_ResultType,string> result = make_pair(ftp_crt_FAIL,"");
|
||||
bool findArchive = executeShellCommand(this->fileArchiveExtractCommand,this->fileArchiveExtractCommandSuccessResult);
|
||||
bool findArchive = executeShellCommand(
|
||||
this->fileArchiveExtractCommand,
|
||||
this->fileArchiveExtractCommandSuccessResult);
|
||||
if(findArchive == true) {
|
||||
result = getScenarioInternalFromServer(fileName);
|
||||
}
|
||||
@ -959,7 +730,11 @@ void FTPClientThread::getScenarioFromServer(pair<string,string> fileName) {
|
||||
MutexSafeWrapper safeMutex(this->getProgressMutex(),mutexOwnerId);
|
||||
this->getProgressMutex()->setOwnerId(mutexOwnerId);
|
||||
if(this->pCBObject != NULL) {
|
||||
this->pCBObject->FTPClient_CallbackEvent(fileName.first,ftp_cct_Scenario,result,NULL);
|
||||
this->pCBObject->FTPClient_CallbackEvent(
|
||||
fileName.first,
|
||||
ftp_cct_Scenario,
|
||||
result,
|
||||
NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@ -987,11 +762,24 @@ pair<FTP_Client_ResultType,string> FTPClientThread::getScenarioInternalFromServ
|
||||
|
||||
// Extract the archive
|
||||
if(result.first == ftp_crt_SUCCESS) {
|
||||
string extractCmd = getFullFileArchiveExtractCommand(this->fileArchiveExtractCommand,
|
||||
this->fileArchiveExtractCommandParameters, destRootArchiveFolder,
|
||||
string extractCmd = getFullFileArchiveExtractCommand(
|
||||
this->fileArchiveExtractCommand,
|
||||
this->fileArchiveExtractCommandParameters,
|
||||
destRootArchiveFolder,
|
||||
destRootArchiveFolder + fileName.first + this->fileArchiveExtension);
|
||||
|
||||
if(executeShellCommand(extractCmd,this->fileArchiveExtractCommandSuccessResult) == false) {
|
||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||
MutexSafeWrapper safeMutex(this->getProgressMutex(),mutexOwnerId);
|
||||
this->getProgressMutex()->setOwnerId(mutexOwnerId);
|
||||
if(this->pCBObject != NULL) {
|
||||
this->shellCommandCallbackUserData = fileName.first;
|
||||
this->pCBObject->FTPClient_CallbackEvent(
|
||||
fileName.first,
|
||||
ftp_cct_ExtractProgress,
|
||||
make_pair(ftp_crt_SUCCESS,"extracting"),NULL);
|
||||
}
|
||||
|
||||
if(executeShellCommand(extractCmd,this->fileArchiveExtractCommandSuccessResult,this) == false) {
|
||||
result.first = ftp_crt_FAIL;
|
||||
result.second = "failed to extract archive!";
|
||||
}
|
||||
@ -1007,7 +795,9 @@ void FTPClientThread::getFileFromServer(pair<string,string> fileName) {
|
||||
bool findArchive = true;
|
||||
string ext = extractExtension(fileName.first);
|
||||
if(("." + ext) == this->fileArchiveExtension) {
|
||||
findArchive = executeShellCommand(this->fileArchiveExtractCommand,this->fileArchiveExtractCommandSuccessResult);
|
||||
findArchive = executeShellCommand(
|
||||
this->fileArchiveExtractCommand,
|
||||
this->fileArchiveExtractCommandSuccessResult);
|
||||
}
|
||||
if(findArchive == true) {
|
||||
result = getFileInternalFromServer(fileName);
|
||||
@ -1022,27 +812,9 @@ void FTPClientThread::getFileFromServer(pair<string,string> fileName) {
|
||||
}
|
||||
|
||||
pair<FTP_Client_ResultType,string> FTPClientThread::getFileInternalFromServer(pair<string,string> fileName) {
|
||||
// Root folder for the techtree
|
||||
//string destRootFolder = this->scenariosPath.second;
|
||||
//endPathWithSlash(destRootFolder);
|
||||
//string destRootArchiveFolder = destRootFolder;
|
||||
//destRootFolder += fileName.first;
|
||||
//endPathWithSlash(destRootFolder);
|
||||
|
||||
//string destFile = this->scenariosPath.second;
|
||||
//endPathWithSlash(destFile);
|
||||
//destFile += fileName.first;
|
||||
//string destFileSaveAs = destFile + this->fileArchiveExtension;
|
||||
//endPathWithSlash(destFile);
|
||||
|
||||
string destFile = fileName.first;
|
||||
string destFileSaveAs = fileName.first;
|
||||
|
||||
//string remotePath = fileName.first + this->fileArchiveExtension;
|
||||
//if(fileName.second != "") {
|
||||
// remotePath = fileName.second;
|
||||
//}
|
||||
|
||||
string remotePath = fileName.second;
|
||||
|
||||
pair<FTP_Client_ResultType,string> result = getFileFromServer(ftp_cct_File,
|
||||
@ -1053,8 +825,10 @@ pair<FTP_Client_ResultType,string> FTPClientThread::getFileInternalFromServer(p
|
||||
string ext = extractExtension(destFileSaveAs);
|
||||
if(("." + ext) == fileArchiveExtension) {
|
||||
string destRootArchiveFolder = extractDirectoryPathFromFile(destFileSaveAs);
|
||||
string extractCmd = getFullFileArchiveExtractCommand(this->fileArchiveExtractCommand,
|
||||
this->fileArchiveExtractCommandParameters, destRootArchiveFolder,
|
||||
string extractCmd = getFullFileArchiveExtractCommand(
|
||||
this->fileArchiveExtractCommand,
|
||||
this->fileArchiveExtractCommandParameters,
|
||||
destRootArchiveFolder,
|
||||
destFileSaveAs);
|
||||
|
||||
if(executeShellCommand(extractCmd,this->fileArchiveExtractCommandSuccessResult) == false) {
|
||||
@ -1209,8 +983,6 @@ pair<FTP_Client_ResultType,string> FTPClientThread::getFileFromServer(FTP_Clien
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
FTPClientCallbackInterface * FTPClientThread::getCallBackObject() {
|
||||
static string mutexOwnerId = string(__FILE__) + string("_") + intToStr(__LINE__);
|
||||
MutexSafeWrapper safeMutex(this->getProgressMutex(),mutexOwnerId);
|
||||
@ -1225,6 +997,22 @@ void FTPClientThread::setCallBackObject(FTPClientCallbackInterface *value) {
|
||||
pCBObject = value;
|
||||
}
|
||||
|
||||
void FTPClientThread::ShellCommandOutput_CallbackEvent(string cmd,char *output,void *userdata) {
|
||||
if(this->pCBObject != NULL) {
|
||||
|
||||
string &itemName = *static_cast<string *>(userdata);
|
||||
this->pCBObject->FTPClient_CallbackEvent(
|
||||
itemName,
|
||||
ftp_cct_ExtractProgress,
|
||||
make_pair(ftp_crt_SUCCESS,"extracting"),
|
||||
output);
|
||||
}
|
||||
}
|
||||
|
||||
void * FTPClientThread::getShellCommandOutput_UserData(string cmd) {
|
||||
return &shellCommandCallbackUserData;
|
||||
}
|
||||
|
||||
void FTPClientThread::execute() {
|
||||
{
|
||||
RunningStatusSafeWrapper runningStatus(this);
|
||||
|
Loading…
x
Reference in New Issue
Block a user