mirror of https://github.com/axmolengine/axmol.git
Merge pull request #12184 from pandamicro/v3
Fix issue that __JSDownloaderDelegator::onError get called twice
This commit is contained in:
commit
af756c50dc
|
@ -951,11 +951,7 @@ void __JSDownloaderDelegator::startDownload()
|
|||
|
||||
cocos2d::extension::Downloader::HeaderInfo info = _downloader->getHeader(_url);
|
||||
long contentSize = info.contentSize;
|
||||
if (contentSize == -1 || info.responseCode >= 400) {
|
||||
cocos2d::extension::Downloader::Error err;
|
||||
onError(err);
|
||||
}
|
||||
else {
|
||||
if (contentSize > 0 && info.responseCode < 400) {
|
||||
_size = contentSize / sizeof(unsigned char);
|
||||
_buffer = (unsigned char*)malloc(contentSize);
|
||||
_downloader->downloadToBufferSync(_url, _buffer, _size);
|
||||
|
|
|
@ -288,6 +288,7 @@ Downloader::HeaderInfo Downloader::prepareHeader(const std::string &srcUrl, void
|
|||
curl_easy_setopt(header, CURLOPT_URL, srcUrl.c_str());
|
||||
curl_easy_setopt(header, CURLOPT_HEADER, 1);
|
||||
curl_easy_setopt(header, CURLOPT_NOBODY, 1);
|
||||
curl_easy_setopt(header, CURLOPT_NOSIGNAL, 1);
|
||||
if (curl_easy_perform(header) == CURLE_OK)
|
||||
{
|
||||
char *url;
|
||||
|
@ -296,16 +297,24 @@ Downloader::HeaderInfo Downloader::prepareHeader(const std::string &srcUrl, void
|
|||
curl_easy_getinfo(header, CURLINFO_CONTENT_TYPE, &contentType);
|
||||
curl_easy_getinfo(header, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &info.contentSize);
|
||||
curl_easy_getinfo(header, CURLINFO_RESPONSE_CODE, &info.responseCode);
|
||||
info.url = url;
|
||||
info.contentType = contentType;
|
||||
info.valid = true;
|
||||
|
||||
if (_onHeader)
|
||||
if (contentType == nullptr || info.contentSize == -1 || info.responseCode >= 400)
|
||||
{
|
||||
_onHeader(srcUrl, info);
|
||||
info.valid = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
info.url = url;
|
||||
info.contentType = contentType;
|
||||
info.valid = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (info.valid && _onHeader)
|
||||
{
|
||||
_onHeader(srcUrl, info);
|
||||
}
|
||||
else if (!info.valid)
|
||||
{
|
||||
info.contentSize = -1;
|
||||
std::string msg = StringUtils::format("Can not get content size of file (%s) : Request header failed", srcUrl.c_str());
|
||||
|
|
Loading…
Reference in New Issue