mirror of
https://github.com/glest/glest-source.git
synced 2025-08-15 12:54:01 +02:00
- added an in progress bar when downloading tilesets
- clear the CRC cache after a new file is downloaded
This commit is contained in:
@@ -14,5 +14,9 @@
|
||||
namespace Shared { namespace PlatformCommon {
|
||||
|
||||
Mutex CacheManager::mutexCache;
|
||||
const char *CacheManager::getFolderTreeContentsCheckSumRecursivelyCacheLookupKey1 = "CRC_Cache_FileTree1";
|
||||
const char *CacheManager::getFolderTreeContentsCheckSumRecursivelyCacheLookupKey2 = "CRC_Cache_FileTree2";
|
||||
const char *CacheManager::getFolderTreeContentsCheckSumListRecursivelyCacheLookupKey1 = "CRC_Cache_FileTreeList1";
|
||||
const char *CacheManager::getFolderTreeContentsCheckSumListRecursivelyCacheLookupKey2 = "CRC_Cache_FileTreeList2";
|
||||
|
||||
}}//end namespace
|
||||
|
@@ -369,12 +369,8 @@ bool EndsWith(const string &str, const string& key)
|
||||
|
||||
//finds all filenames like path and gets their checksum of all files combined
|
||||
int32 getFolderTreeContentsCheckSumRecursively(vector<string> paths, string pathSearchString, const string filterFileExt, Checksum *recursiveChecksum) {
|
||||
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
// !!! OLD local CACHE
|
||||
//static std::map<string,int32> crcTreeCache;
|
||||
string cacheLookupId = string(__FILE__) + intToStr(__LINE__);
|
||||
string cacheLookupId = CacheManager::getFolderTreeContentsCheckSumRecursivelyCacheLookupKey1;
|
||||
std::map<string,int32> &crcTreeCache = CacheManager::getCachedItem< std::map<string,int32> >(cacheLookupId);
|
||||
|
||||
string cacheKey = "";
|
||||
@@ -414,10 +410,7 @@ int32 getFolderTreeContentsCheckSumRecursively(vector<string> paths, string path
|
||||
//finds all filenames like path and gets their checksum of all files combined
|
||||
int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string &filterFileExt, Checksum *recursiveChecksum) {
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s] filterFileExt = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),filterFileExt.c_str());
|
||||
|
||||
// !!! OLD local CACHE
|
||||
//static std::map<string,int32> crcTreeCache;
|
||||
string cacheLookupId = string(__FILE__) + intToStr(__LINE__);
|
||||
string cacheLookupId = CacheManager::getFolderTreeContentsCheckSumRecursivelyCacheLookupKey2;
|
||||
std::map<string,int32> &crcTreeCache = CacheManager::getCachedItem< std::map<string,int32> >(cacheLookupId);
|
||||
|
||||
string cacheKey = path + "_" + filterFileExt;
|
||||
@@ -522,10 +515,8 @@ int32 getFolderTreeContentsCheckSumRecursively(const string &path, const string
|
||||
}
|
||||
|
||||
vector<std::pair<string,int32> > getFolderTreeContentsCheckSumListRecursively(vector<string> paths, string pathSearchString, string filterFileExt, vector<std::pair<string,int32> > *recursiveMap) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
//static std::map<string,vector<std::pair<string,int32> > > crcTreeCache;
|
||||
string cacheLookupId = string(__FILE__) + intToStr(__LINE__);
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
string cacheLookupId = CacheManager::getFolderTreeContentsCheckSumListRecursivelyCacheLookupKey1;
|
||||
std::map<string,vector<std::pair<string,int32> > > &crcTreeCache = CacheManager::getCachedItem< std::map<string,vector<std::pair<string,int32> > > >(cacheLookupId);
|
||||
|
||||
string cacheKey = "";
|
||||
@@ -564,9 +555,7 @@ vector<std::pair<string,int32> > getFolderTreeContentsCheckSumListRecursively(ve
|
||||
//finds all filenames like path and gets the checksum of each file
|
||||
vector<std::pair<string,int32> > getFolderTreeContentsCheckSumListRecursively(const string &path, const string &filterFileExt, vector<std::pair<string,int32> > *recursiveMap) {
|
||||
//SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] path = [%s] filterFileExt = [%s]\n",__FILE__,__FUNCTION__,__LINE__,path.c_str(),filterFileExt.c_str());
|
||||
|
||||
//static std::map<string,vector<std::pair<string,int32> > > crcTreeCache;
|
||||
string cacheLookupId = string(__FILE__) + intToStr(__LINE__);
|
||||
string cacheLookupId = CacheManager::getFolderTreeContentsCheckSumListRecursivelyCacheLookupKey2;
|
||||
std::map<string,vector<std::pair<string,int32> > > &crcTreeCache = CacheManager::getCachedItem< std::map<string,vector<std::pair<string,int32> > > >(cacheLookupId);
|
||||
|
||||
string cacheKey = path + "_" + filterFileExt;
|
||||
|
@@ -32,10 +32,12 @@ namespace Shared { namespace PlatformCommon {
|
||||
*/
|
||||
|
||||
struct FtpFile {
|
||||
const char *itemName;
|
||||
const char *filename;
|
||||
const char *filepath;
|
||||
FILE *stream;
|
||||
FTPClientThread *ftpServer;
|
||||
string currentFilename;
|
||||
};
|
||||
|
||||
static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) {
|
||||
@@ -88,6 +90,10 @@ static long file_is_comming(struct curl_fileinfo *finfo,void *data,int remains)
|
||||
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("\n===> FTP Client thread file_is_comming: remains: [%3d] filename: [%s] size: [%10luB] ", remains, finfo->filename,(unsigned long)finfo->size);
|
||||
|
||||
if(out != NULL) {
|
||||
out->currentFilename = finfo->filename;
|
||||
}
|
||||
|
||||
switch(finfo->filetype) {
|
||||
case CURLFILETYPE_DIRECTORY:
|
||||
printf("DIR (creating [%s%s])\n",rootFilePath.c_str(),finfo->filename);
|
||||
@@ -131,6 +137,29 @@ static long file_is_downloaded(void *data) {
|
||||
return CURL_CHUNK_END_FUNC_OK;
|
||||
}
|
||||
|
||||
int file_progress(struct FtpFile *out,double download_total, double download_now, double upload_total,double upload_now) {
|
||||
// printf("%d / %d (%g %%)\n", d, t, d*100.0/t);
|
||||
//gdk_threads_enter();
|
||||
//gtk_progress_set_value(GTK_PROGRESS(bar), d*100.0/t);
|
||||
//gdk_threads_leave();
|
||||
|
||||
if(out != NULL &&
|
||||
out->ftpServer != NULL &&
|
||||
out->ftpServer->getCallBackObject() != NULL) {
|
||||
FTPClientCallbackInterface::FtpProgressStats stats;
|
||||
stats.download_total = download_total;
|
||||
stats.download_now = download_now;
|
||||
stats.upload_total = upload_total;
|
||||
stats.upload_now = upload_now;
|
||||
stats.currentFilename = out->currentFilename;
|
||||
|
||||
MutexSafeWrapper safeMutex(out->ftpServer->getProgressMutex());
|
||||
out->ftpServer->getCallBackObject()->FTPClient_CallbackEvent(out->itemName, ftp_cct_DownloadProgress, ftp_crt_SUCCESS, &stats);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
FTPClientThread::FTPClientThread(int portNumber, string serverUrl, std::pair<string,string> mapsPath, std::pair<string,string> tilesetsPath, FTPClientCallbackInterface *pCBObject) : BaseThread() {
|
||||
this->portNumber = portNumber;
|
||||
this->serverUrl = serverUrl;
|
||||
@@ -171,6 +200,7 @@ FTP_Client_ResultType FTPClientThread::getMapFromServer(string mapFileName, stri
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Client thread about to try to RETR into [%s]\n",destFile.c_str());
|
||||
|
||||
struct FtpFile ftpfile = {
|
||||
NULL,
|
||||
destFile.c_str(), /* name to store the file as if succesful */
|
||||
NULL,
|
||||
NULL,
|
||||
@@ -233,7 +263,7 @@ void FTPClientThread::getMapFromServer(string mapFileName) {
|
||||
}
|
||||
|
||||
if(this->pCBObject != NULL) {
|
||||
this->pCBObject->FTPClient_CallbackEvent(mapFileName,ftp_cct_Map,result);
|
||||
this->pCBObject->FTPClient_CallbackEvent(mapFileName,ftp_cct_Map,result,NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -258,7 +288,7 @@ void FTPClientThread::getTilesetFromServer(string tileSetName) {
|
||||
}
|
||||
|
||||
if(this->pCBObject != NULL) {
|
||||
this->pCBObject->FTPClient_CallbackEvent(tileSetName,ftp_cct_Tileset,result);
|
||||
this->pCBObject->FTPClient_CallbackEvent(tileSetName,ftp_cct_Tileset,result,NULL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -301,6 +331,7 @@ 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());
|
||||
|
||||
struct FtpFile ftpfile = {
|
||||
tileSetName.c_str(),
|
||||
destFile.c_str(), // name to store the file as if succesful
|
||||
destFile.c_str(),
|
||||
NULL,
|
||||
@@ -328,13 +359,9 @@ FTP_Client_ResultType FTPClientThread::getTilesetFromServer(string tileSetName,
|
||||
|
||||
// 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);
|
||||
|
||||
// put transfer data into callbacks
|
||||
// helper data
|
||||
//struct callback_data data = { 0 };
|
||||
curl_easy_setopt(curl, CURLOPT_CHUNK_DATA, &ftpfile);
|
||||
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);
|
||||
|
||||
@@ -343,6 +370,10 @@ FTP_Client_ResultType FTPClientThread::getTilesetFromServer(string tileSetName,
|
||||
// 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);
|
||||
|
||||
// Switch on full protocol/debug output
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
|
||||
|
||||
|
Reference in New Issue
Block a user