AssetsManager

// Remove downloaded files
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
string command = "rm -r ";
// Path may include space.
command += "\"" + pathToSave + "\"";
system(command.c_str());
#else
string command = "rd /s /q ";
// Path may include space.
command += "\"" + pathToSave + "\"";
system(command.c_str());
#endif

bool AssetsManager::downLoad()
{
// Create a file to save package.
string outFileName = _storagePath + TEMP_PACKAGE_FILE_NAME;//下载文件的存放位置
FILE *fp = fopen(outFileName.c_str(), "wb");//新建并打来一个文件 以便下载后写入
if (! fp)
{
sendErrorMessage(kCreateFile);
CCLOG("can not create file %s", outFileName.c_str());
return false;
}

// Download pacakge
CURLcode res;
curl_easy_setopt(_curl, CURLOPT_URL, _packageUrl.c_str());//设定curl的链接
curl_easy_setopt(_curl, CURLOPT_WRITEFUNCTION, downLoadPackage);
curl_easy_setopt(_curl, CURLOPT_WRITEDATA, fp);//设置将data写入到文件流fp中
curl_easy_setopt(_curl, CURLOPT_NOPROGRESS, false);//设为false 下面才能设置进度响应函数
curl_easy_setopt(_curl, CURLOPT_PROGRESSFUNCTION, assetsManagerProgressFunc);//进度响应函数
curl_easy_setopt(_curl, CURLOPT_PROGRESSDATA, this);//数据传输的对象
res = curl_easy_perform(_curl);
curl_easy_cleanup(_curl);
if (res != 0)
{
sendErrorMessage(kNetwork);
CCLOG("error when download package");
fclose(fp);
return false;
}

CCLOG("succeed downloading package %s", _packageUrl.c_str());

fclose(fp);
return true;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值