- code cleanup

This commit is contained in:
Mark Vejvoda
2011-01-02 10:09:49 +00:00
parent e7ee0b81fe
commit 83ff486e21
2 changed files with 78 additions and 64 deletions

View File

@@ -248,7 +248,7 @@ void findAll(const vector<string> &paths, const string &fileFilter, vector<strin
std::sort(results.begin(),results.end());
}
//finds all filenames like path and stores them in resultys
//finds all filenames like path and stores them in results
void findAll(const string &path, vector<string> &results, bool cutExtension, bool errorOnNotFound) {
results.clear();
@@ -335,6 +335,23 @@ bool isdir(const char *path)
return ret;
}
/*
void removeFolder(const string path) {
path += "*";
vector<string> results;
findAll(path, vector<string> &results, false, false);
for(int i = results.size() -1; i >= 0; --i) {
string item = results[i];
if(isdir(item) == true) {
rmdir(item.c_str());
}
else {
unlink(item.c_str());
}
}
}
*/
bool StartsWith(const std::string &str, const std::string &key) {
return str.find(key) == 0;
}

View File

@@ -56,8 +56,8 @@ static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) {
out->stream = NULL;
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("===> FTP Client thread CANCELLED, deleting file for writing [%s]\n",fullFilePath.c_str());
unlink(fullFilePath.c_str());
return -1;
}
@@ -68,16 +68,13 @@ static size_t my_fwrite(void *buffer, size_t size, size_t nmemb, void *stream) {
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());
return -1; /* failure, can't open file to write */
}
}
return fwrite(buffer, size, nmemb, out->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) {
struct FtpFile *out=(struct FtpFile *)data;
string rootFilePath = "";
@@ -89,7 +86,7 @@ static long file_is_comming(struct curl_fileinfo *finfo,void *data,int remains)
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);
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);
switch(finfo->filetype) {
case CURLFILETYPE_DIRECTORY:
@@ -115,7 +112,7 @@ static long file_is_comming(struct curl_fileinfo *finfo,void *data,int remains)
if(SystemFlags::VERBOSE_MODE_ENABLED) printf(" opening file [%s] ", fullFilePath.c_str());
out->stream = fopen(fullFilePath.c_str(), "wb");
if(!out->stream) {
if(out->stream == NULL) {
return CURL_CHUNK_BGN_FUNC_FAIL;
}
}
@@ -123,14 +120,13 @@ static long file_is_comming(struct curl_fileinfo *finfo,void *data,int remains)
return CURL_CHUNK_BGN_FUNC_OK;
}
static long file_is_downloaded(void *data)
{
static long file_is_downloaded(void *data) {
struct FtpFile *out=(struct FtpFile *)data;
if(out->stream) {
printf("DOWNLOAD COMPLETE!\n");
fclose(out->stream);
out->stream = 0x0;
out->stream = NULL;
}
return CURL_CHUNK_END_FUNC_OK;
}
@@ -157,8 +153,6 @@ bool FTPClientThread::shutdownAndWait() {
FTP_Client_ResultType FTPClientThread::getMapFromServer(string mapFileName, string ftpUser, string ftpUserPassword) {
CURLcode res;
FTP_Client_ResultType result = ftp_crt_FAIL;
string destFileExt = "";
@@ -199,13 +193,12 @@ FTP_Client_ResultType FTPClientThread::getMapFromServer(string mapFileName, stri
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);
/* Switch on full protocol/debug output */
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
res = curl_easy_perform(curl);
if(SystemFlags::VERBOSE_MODE_ENABLED) curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
CURLcode res = curl_easy_perform(curl);
if(CURLE_OK != res) {
// we failed
fprintf(stderr, "curl told us %d\n", res);
printf("curl FAILED with: %d\n", res);
}
else {
result = ftp_crt_SUCCESS;
@@ -217,7 +210,12 @@ 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());
}
}
return result;
}
@@ -265,8 +263,6 @@ void FTPClientThread::getTilesetFromServer(string tileSetName) {
}
FTP_Client_ResultType FTPClientThread::getTilesetFromServer(string tileSetName, string tileSetNameSubfolder, string ftpUser, string ftpUserPassword) {
CURLcode res;
FTP_Client_ResultType result = ftp_crt_FAIL;
string destFile = this->tilesetsPath.second;
@@ -348,13 +344,14 @@ FTP_Client_ResultType FTPClientThread::getTilesetFromServer(string tileSetName,
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &ftpfile);
// Switch on full protocol/debug output
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
if(SystemFlags::VERBOSE_MODE_ENABLED) curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
res = curl_easy_perform(curl);
CURLcode res = curl_easy_perform(curl);
if(CURLE_OK != res) {
// we failed
fprintf(stderr, "curl told us %d\n", res);
printf("curl FAILED with: %d\n", res);
if(destRootFolder != "") {
unlink(destRootFolder.c_str());
}