Skip to content

Commit

Permalink
debugging info
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardoquesada committed Aug 7, 2015
1 parent af0dc45 commit 389ed86
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
25 changes: 17 additions & 8 deletions cocos/network/CCDownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ void Downloader::prepareDownload(const std::string& srcUrl, const std::string& s
pData->url = srcUrl;
pData->downloaded = 0;
pData->totalToDownload = 0;
*fp = nullptr;

FILE *localFP = nullptr;

Error err;
err.customId = customId;

Expand All @@ -151,26 +151,31 @@ void Downloader::prepareDownload(const std::string& srcUrl, const std::string& s
{
err.code = ErrorCode::INVALID_URL;
err.message = "Invalid url or filename not exist error: " + srcUrl;
if (this->_onError) this->_onError(err);
if (this->_onError)
this->_onError(err);
*fp = nullptr;
return;
}

// Create a file to save file.
const std::string outFileName = storagePath + TEMP_EXT;
if (_supportResuming && resumeDownload && _fileUtils->isFileExist(outFileName))
{
*fp = fopen(FileUtils::getInstance()->getSuitableFOpen(outFileName).c_str(), "ab");
localFP = fopen(FileUtils::getInstance()->getSuitableFOpen(outFileName).c_str(), "ab");
}
else
{
*fp = fopen(FileUtils::getInstance()->getSuitableFOpen(outFileName).c_str(), "wb");
localFP = fopen(FileUtils::getInstance()->getSuitableFOpen(outFileName).c_str(), "wb");
}
if (! *fp)
if (!localFP)
{
err.code = ErrorCode::CREATE_FILE;
err.message = StringUtils::format("Can not create file %s: errno %d", outFileName.c_str(), errno);
if (this->_onError) this->_onError(err);
if (this->_onError)
this->_onError(err);
}

*fp = localFP;
}

void Downloader::downloadToBufferAsync(const std::string& srcUrl, unsigned char *buffer, long size, const std::string& customId/* = ""*/)
Expand Down Expand Up @@ -472,6 +477,8 @@ void Downloader::reportProgressInProgress(double totalToDownload, double nowDown
// This is only for batchDownload process, will notify file succeed event in progress function
int Downloader::batchDownloadProgressFunc(void *userdata, double totalToDownload, double nowDownloaded)
{
CCLOG("batchDownloadProgressFunc: %d", (int)((nowDownloaded/totalToDownload)*100));

CC_ASSERT(userdata && "Invalid userdata");

ProgressData* ptr = (ProgressData*) userdata;
Expand Down Expand Up @@ -530,6 +537,8 @@ int Downloader::downloadProgressFunc(void *userdata, double totalToDownload, dou
{
CC_ASSERT(userdata && "Invalid userdata");

CCLOG("downloadProgressFunc: %d", (int)((nowDownloaded/totalToDownload)*100));

ProgressData* ptr = (ProgressData*)userdata;
if (ptr->totalToDownload == 0)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/cpp-tests/Classes/DownloaderTest/DownloaderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void DownloaderBaseTest::errorCallback(const cocos2d::network::Downloader::Error

void DownloaderBaseTest::progressCallback(double totalToDownload, double nowDownloaded, const std::string& url, const std::string& customId)
{
cocos2d::log("download progress: %d%% - %s", (int)(nowDownloaded/totalToDownload)*100, url.c_str());
cocos2d::log("download progress: %d%% - %s", (int)((nowDownloaded/totalToDownload)*100), url.c_str());
}

void DownloaderBaseTest::successCallback(const std::string& url, const std::string& path, const std::string& customId)
Expand Down

0 comments on commit 389ed86

Please sign in to comment.