- more ftp tileset bugfixes
This commit is contained in:
parent
7088f60425
commit
8eeb0b550c
|
@ -1674,10 +1674,10 @@ void MenuStateConnectedGame::showFTPMessageBox(const string &text, const string
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName, FTP_Client_ResultType result) {
|
void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName, FTP_Client_CallbackType type, FTP_Client_ResultType result) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
if(ftpMissingDataType == ftpmsg_MissingMap) {
|
if(type == ftp_cct_Map) {
|
||||||
getMissingMapFromFTPServerInProgress = false;
|
getMissingMapFromFTPServerInProgress = false;
|
||||||
printf("Got FTP Callback for [%s] result = %d\n",itemName.c_str(),result);
|
printf("Got FTP Callback for [%s] result = %d\n",itemName.c_str(),result);
|
||||||
|
|
||||||
|
@ -1696,7 +1696,7 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName, FTP_Client
|
||||||
clientInterface->sendTextMessage(szMsg,-1, true);
|
clientInterface->sendTextMessage(szMsg,-1, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(ftpMissingDataType == ftpmsg_MissingTileset) {
|
else if(type == ftp_cct_Tileset) {
|
||||||
getMissingTilesetFromFTPServerInProgress = false;
|
getMissingTilesetFromFTPServerInProgress = false;
|
||||||
printf("Got FTP Callback for [%s] result = %d\n",itemName.c_str(),result);
|
printf("Got FTP Callback for [%s] result = %d\n",itemName.c_str(),result);
|
||||||
|
|
||||||
|
@ -1708,6 +1708,8 @@ void MenuStateConnectedGame::FTPClient_CallbackEvent(string itemName, FTP_Client
|
||||||
char szMsg[1024]="";
|
char szMsg[1024]="";
|
||||||
sprintf(szMsg,"Player: %s SUCCESSFULLY downloaded the tileset: %s",getHumanPlayerName().c_str(),gameSettings->getTileset().c_str());
|
sprintf(szMsg,"Player: %s SUCCESSFULLY downloaded the tileset: %s",getHumanPlayerName().c_str(),gameSettings->getTileset().c_str());
|
||||||
clientInterface->sendTextMessage(szMsg,-1, true);
|
clientInterface->sendTextMessage(szMsg,-1, true);
|
||||||
|
|
||||||
|
findDirs(Config::getInstance().getPathListForType(ptTilesets), tileSets);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
char szMsg[1024]="";
|
char szMsg[1024]="";
|
||||||
|
|
|
@ -181,7 +181,7 @@ private:
|
||||||
void showMessageBox(const string &text, const string &header, bool toggle);
|
void showMessageBox(const string &text, const string &header, bool toggle);
|
||||||
|
|
||||||
void showFTPMessageBox(const string &text, const string &header, bool toggle);
|
void showFTPMessageBox(const string &text, const string &header, bool toggle);
|
||||||
virtual void FTPClient_CallbackEvent(string itemName, FTP_Client_ResultType result);
|
virtual void FTPClient_CallbackEvent(string itemName, FTP_Client_CallbackType type, FTP_Client_ResultType result);
|
||||||
};
|
};
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
|
@ -32,9 +32,14 @@ enum FTP_Client_ResultType {
|
||||||
ftp_crt_ABORTED = 2
|
ftp_crt_ABORTED = 2
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum FTP_Client_CallbackType {
|
||||||
|
ftp_cct_Map = 0,
|
||||||
|
ftp_cct_Tileset = 1
|
||||||
|
};
|
||||||
|
|
||||||
class FTPClientCallbackInterface {
|
class FTPClientCallbackInterface {
|
||||||
public:
|
public:
|
||||||
virtual void FTPClient_CallbackEvent(string mapFilename, FTP_Client_ResultType result) = 0;
|
virtual void FTPClient_CallbackEvent(string itemName, FTP_Client_CallbackType type, FTP_Client_ResultType result) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class FTPClientThread : public BaseThread
|
class FTPClientThread : public BaseThread
|
||||||
|
|
|
@ -408,7 +408,7 @@ int ftpSelect(int poll)
|
||||||
|
|
||||||
if(poll)
|
if(poll)
|
||||||
{
|
{
|
||||||
struct timeval t = {0};
|
struct timeval t = {250};
|
||||||
return select(maxSockNr+1, &signaledSockets, NULL, NULL, &t);
|
return select(maxSockNr+1, &signaledSockets, NULL, NULL, &t);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -33,6 +33,7 @@ namespace Shared { namespace PlatformCommon {
|
||||||
|
|
||||||
struct FtpFile {
|
struct FtpFile {
|
||||||
const char *filename;
|
const char *filename;
|
||||||
|
const char *filepath;
|
||||||
FILE *stream;
|
FILE *stream;
|
||||||
FTPClientThread *ftpServer;
|
FTPClientThread *ftpServer;
|
||||||
};
|
};
|
||||||
|
@ -40,6 +41,14 @@ struct FtpFile {
|
||||||
static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) {
|
static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) {
|
||||||
struct FtpFile *out=(struct FtpFile *)stream;
|
struct FtpFile *out=(struct FtpFile *)stream;
|
||||||
|
|
||||||
|
string fullFilePath = "";
|
||||||
|
if(out != NULL && out->filepath != NULL) {
|
||||||
|
fullFilePath = out->filepath;
|
||||||
|
}
|
||||||
|
if(out != NULL && out->filename != NULL) {
|
||||||
|
fullFilePath += out->filename;
|
||||||
|
}
|
||||||
|
|
||||||
// Abort file xfer and delete partial file
|
// Abort file xfer and delete partial file
|
||||||
if(out && out->ftpServer && out->ftpServer->getQuitStatus() == true) {
|
if(out && out->ftpServer && out->ftpServer->getQuitStatus() == true) {
|
||||||
if(out->stream) {
|
if(out->stream) {
|
||||||
|
@ -47,18 +56,18 @@ static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) {
|
||||||
out->stream = NULL;
|
out->stream = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
unlink(out->filename);
|
unlink(fullFilePath.c_str());
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(out && out->stream == NULL) {
|
if(out && out->stream == NULL) {
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Client thread opening file for writing [%s]\n",out->filename);
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Client thread opening file for writing [%s]\n",fullFilePath.c_str());
|
||||||
|
|
||||||
/* open file for writing */
|
/* open file for writing */
|
||||||
out->stream = fopen(out->filename, "wb");
|
out->stream = fopen(fullFilePath.c_str(), "wb");
|
||||||
if(out->stream == NULL) {
|
if(out->stream == NULL) {
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Client thread FAILED to open file for writing [%s]\n",out->filename);
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Client thread FAILED to open file for writing [%s]\n",fullFilePath.c_str());
|
||||||
|
|
||||||
return -1; /* failure, can't open file to write */
|
return -1; /* failure, can't open file to write */
|
||||||
}
|
}
|
||||||
|
@ -69,11 +78,24 @@ static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) {
|
||||||
|
|
||||||
static long file_is_comming(struct curl_fileinfo *finfo,void *data,int remains)
|
static long file_is_comming(struct curl_fileinfo *finfo,void *data,int remains)
|
||||||
{
|
{
|
||||||
printf("%3d %40s %10luB ", remains, finfo->filename,(unsigned long)finfo->size);
|
struct FtpFile *out=(struct FtpFile *)data;
|
||||||
|
|
||||||
|
string rootFilePath = "";
|
||||||
|
string fullFilePath = "";
|
||||||
|
if(out != NULL && out->filepath != NULL) {
|
||||||
|
rootFilePath = out->filepath;
|
||||||
|
}
|
||||||
|
if(out != NULL && out->filename != NULL) {
|
||||||
|
fullFilePath = rootFilePath + finfo->filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\n===> FTP Client thread file_is_comming: remains: [%3d] filename: [%40s] size: [%10luB] ", remains, finfo->filename,(unsigned long)finfo->size);
|
||||||
|
|
||||||
switch(finfo->filetype) {
|
switch(finfo->filetype) {
|
||||||
case CURLFILETYPE_DIRECTORY:
|
case CURLFILETYPE_DIRECTORY:
|
||||||
printf(" DIR\n");
|
printf("DIR (creating [%s%s])\n",rootFilePath.c_str(),finfo->filename);
|
||||||
|
rootFilePath += finfo->filename;
|
||||||
|
createDirectoryPaths(rootFilePath.c_str());
|
||||||
break;
|
break;
|
||||||
case CURLFILETYPE_FILE:
|
case CURLFILETYPE_FILE:
|
||||||
printf("FILE ");
|
printf("FILE ");
|
||||||
|
@ -90,8 +112,9 @@ static long file_is_comming(struct curl_fileinfo *finfo,void *data,int remains)
|
||||||
// return CURL_CHUNK_BGN_FUNC_SKIP;
|
// return CURL_CHUNK_BGN_FUNC_SKIP;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
struct FtpFile *out=(struct FtpFile *)data;
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf(" opening file [%s] ", fullFilePath.c_str());
|
||||||
out->stream = fopen(finfo->filename, "w");
|
|
||||||
|
out->stream = fopen(fullFilePath.c_str(), "wb");
|
||||||
if(!out->stream) {
|
if(!out->stream) {
|
||||||
return CURL_CHUNK_BGN_FUNC_FAIL;
|
return CURL_CHUNK_BGN_FUNC_FAIL;
|
||||||
}
|
}
|
||||||
|
@ -104,7 +127,7 @@ static long file_is_downloaded(void *data)
|
||||||
{
|
{
|
||||||
struct FtpFile *out=(struct FtpFile *)data;
|
struct FtpFile *out=(struct FtpFile *)data;
|
||||||
if(out->stream) {
|
if(out->stream) {
|
||||||
printf("DOWNLOADED\n");
|
printf("DOWNLOAD COMPLETE!\n");
|
||||||
|
|
||||||
fclose(out->stream);
|
fclose(out->stream);
|
||||||
out->stream = 0x0;
|
out->stream = 0x0;
|
||||||
|
@ -156,6 +179,7 @@ FTP_Client_ResultType FTPClientThread::getMapFromServer(string mapFileName, stri
|
||||||
struct FtpFile ftpfile = {
|
struct FtpFile ftpfile = {
|
||||||
destFile.c_str(), /* name to store the file as if succesful */
|
destFile.c_str(), /* name to store the file as if succesful */
|
||||||
NULL,
|
NULL,
|
||||||
|
NULL,
|
||||||
this
|
this
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -211,7 +235,7 @@ void FTPClientThread::getMapFromServer(string mapFileName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this->pCBObject != NULL) {
|
if(this->pCBObject != NULL) {
|
||||||
this->pCBObject->FTPClient_CallbackEvent(mapFileName,result);
|
this->pCBObject->FTPClient_CallbackEvent(mapFileName,ftp_cct_Map,result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +260,7 @@ void FTPClientThread::getTilesetFromServer(string tileSetName) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this->pCBObject != NULL) {
|
if(this->pCBObject != NULL) {
|
||||||
this->pCBObject->FTPClient_CallbackEvent(tileSetName,result);
|
this->pCBObject->FTPClient_CallbackEvent(tileSetName,ftp_cct_Tileset,result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,6 +271,21 @@ FTP_Client_ResultType FTPClientThread::getTilesetFromServer(string tileSetName,
|
||||||
|
|
||||||
string destFile = this->tilesetsPath.second;
|
string destFile = this->tilesetsPath.second;
|
||||||
|
|
||||||
|
// Root folder for the tileset
|
||||||
|
string destRootFolder = "";
|
||||||
|
if(tileSetNameSubfolder == "") {
|
||||||
|
destRootFolder = this->tilesetsPath.second;
|
||||||
|
if(EndsWith(destRootFolder,"/") == false && EndsWith(destRootFolder,"\\") == false) {
|
||||||
|
destRootFolder += "/";
|
||||||
|
}
|
||||||
|
destRootFolder += tileSetName;
|
||||||
|
if(EndsWith(destRootFolder,"/") == false && EndsWith(destRootFolder,"\\") == false) {
|
||||||
|
destRootFolder += "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
createDirectoryPaths(destRootFolder);
|
||||||
|
}
|
||||||
|
|
||||||
if(EndsWith(destFile,"/") == false && EndsWith(destFile,"\\") == false) {
|
if(EndsWith(destFile,"/") == false && EndsWith(destFile,"\\") == false) {
|
||||||
destFile += "/";
|
destFile += "/";
|
||||||
}
|
}
|
||||||
|
@ -266,7 +305,8 @@ FTP_Client_ResultType FTPClientThread::getTilesetFromServer(string tileSetName,
|
||||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Client thread about to try to RETR into [%s]\n",destFile.c_str());
|
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Client thread about to try to RETR into [%s]\n",destFile.c_str());
|
||||||
|
|
||||||
struct FtpFile ftpfile = {
|
struct FtpFile ftpfile = {
|
||||||
destFile.c_str(), /* name to store the file as if succesful */
|
destFile.c_str(), // name to store the file as if succesful
|
||||||
|
destFile.c_str(),
|
||||||
NULL,
|
NULL,
|
||||||
this
|
this
|
||||||
};
|
};
|
||||||
|
@ -315,6 +355,9 @@ FTP_Client_ResultType FTPClientThread::getTilesetFromServer(string tileSetName,
|
||||||
if(CURLE_OK != res) {
|
if(CURLE_OK != res) {
|
||||||
// we failed
|
// we failed
|
||||||
fprintf(stderr, "curl told us %d\n", res);
|
fprintf(stderr, "curl told us %d\n", res);
|
||||||
|
if(destRootFolder != "") {
|
||||||
|
unlink(destRootFolder.c_str());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
result = ftp_crt_SUCCESS;
|
result = ftp_crt_SUCCESS;
|
||||||
|
@ -333,8 +376,8 @@ FTP_Client_ResultType FTPClientThread::getTilesetFromServer(string tileSetName,
|
||||||
requireMoreFolders = true;
|
requireMoreFolders = true;
|
||||||
}
|
}
|
||||||
else if(tileSetNameSubfolder == "textures") {
|
else if(tileSetNameSubfolder == "textures") {
|
||||||
tileSetNameSubfolder = "textures";
|
tileSetNameSubfolder = "";
|
||||||
requireMoreFolders = true;
|
requireMoreFolders = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(requireMoreFolders == true) {
|
if(requireMoreFolders == true) {
|
||||||
|
|
|
@ -114,7 +114,7 @@ void FTPServerThread::execute() {
|
||||||
ftpStart(portNumber);
|
ftpStart(portNumber);
|
||||||
while(this->getQuitStatus() == false) {
|
while(this->getQuitStatus() == false) {
|
||||||
ftpExecute();
|
ftpExecute();
|
||||||
sleep(25);
|
//sleep(25);
|
||||||
}
|
}
|
||||||
ftpShutdown();
|
ftpShutdown();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue