Merge pull request #13489 from jianglong0156/fixwin32textureCacheTest

fix texturecache didn't show correctly in win32
This commit is contained in:
pandamicro 2015-08-20 22:39:01 +08:00
commit c6c1b429c6
2 changed files with 13 additions and 9 deletions

View File

@ -197,18 +197,18 @@ void Downloader::downloadToBuffer(const std::string& srcUrl, const std::string&
CC_ASSERT(_downloaderImpl && "Cannot instanciate more than one instance of DownloaderImpl"); CC_ASSERT(_downloaderImpl && "Cannot instanciate more than one instance of DownloaderImpl");
DownloadUnit unit;
unit.srcUrl = srcUrl;
unit.customId = customId;
unit.fp = buffer;
unit.downloaded = 0;
unit.totalToDownload = 0;
StreamData streamBuffer; StreamData streamBuffer;
streamBuffer.buffer = buffer; streamBuffer.buffer = buffer;
streamBuffer.total = size; streamBuffer.total = size;
streamBuffer.offset = 0; streamBuffer.offset = 0;
DownloadUnit unit;
unit.srcUrl = srcUrl;
unit.customId = customId;
unit.fp = &streamBuffer;
unit.downloaded = 0;
unit.totalToDownload = 0;
int res = _downloaderImpl->performDownload(&unit, int res = _downloaderImpl->performDownload(&unit,
std::bind(&Downloader::bufferWriteFunc, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4), std::bind(&Downloader::bufferWriteFunc, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4),
std::bind(&Downloader::downloadProgressFunc, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3) std::bind(&Downloader::downloadProgressFunc, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)

View File

@ -48,7 +48,10 @@ static size_t _fileWriteFunc(void *ptr, size_t size, size_t nmemb, void* userdat
int ret = this_->getWriterCallback()(ptr, size, nmemb, unit); int ret = this_->getWriterCallback()(ptr, size, nmemb, unit);
return ret; return ret;
} }
static size_t _fileWriteFuncForAdapter(void *ptr, size_t size, size_t nmemb, void* userdata)
{
return nmemb;
}
static int _downloadProgressFunc(void* userdata, double totalToDownload, double nowDownloaded, double totalToUpLoad, double nowUpLoaded) static int _downloadProgressFunc(void* userdata, double totalToDownload, double nowDownloaded, double totalToUpLoad, double nowUpLoaded)
{ {
DownloadUnit *downloadUnit = (DownloadUnit*)userdata; DownloadUnit *downloadUnit = (DownloadUnit*)userdata;
@ -284,7 +287,8 @@ int DownloaderImpl::getHeader(const std::string& url, HeaderInfo* headerInfo)
curl_easy_setopt(curlHandle, CURLOPT_HEADER, 1); curl_easy_setopt(curlHandle, CURLOPT_HEADER, 1);
curl_easy_setopt(curlHandle, CURLOPT_NOBODY, 1); curl_easy_setopt(curlHandle, CURLOPT_NOBODY, 1);
curl_easy_setopt(curlHandle, CURLOPT_NOSIGNAL, 1); curl_easy_setopt(curlHandle, CURLOPT_NOSIGNAL, 1);
// in win32 platform, if not set the writeFunction, it will return CURLE_WRITE_ERROR
curl_easy_setopt(curlHandle, CURLOPT_WRITEFUNCTION, _fileWriteFuncForAdapter);
if ((_lastErrCode=curl_easy_perform(curlHandle)) == CURLE_OK) if ((_lastErrCode=curl_easy_perform(curlHandle)) == CURLE_OK)
{ {
char *effectiveUrl; char *effectiveUrl;