void HttpDownload::onProgress(double percent, void *delegate, string filefullPath){ // 下载进度
    
    if (_stopDownload) {
        CurlDown * cd = (CurlDown *)delegate;
        cd->setStopDown();
        _stopDownload = false;
    }
    //进入Cocos主线程然后分发
    auto scheduler = Director::getInstance()->getScheduler();
    scheduler->performFunctionInCocosThread([this,percent,delegate,filefullPath]
                                            {
                                                //TODO:分发给LUA
                                                
                                                CURLDOWNLOG("Download Progress %.2f%%",percent);
                                                if (_delegate)
                                                {
                                                    _delegate->onProgress(percent,delegate,filefullPath);
                                                    
                                                }
                                            });
}
Esempio n. 2
0
void Download::onProgress(double percent, void *delegate, string filefullPath){ // 下载进度
	if (clsCurDown->isStop) {
		CurlDown * cd = (CurlDown *)delegate;
		//        pthread_mutex_lock(&g_downloadMutex);
		cd->setStopDown();
		//        pthread_mutex_unlock(&g_downloadMutex);
	}
	if(clsCurDown->isPause){
		CurlDown * cd = (CurlDown *)delegate;
		//        pthread_mutex_lock(&g_downloadMutex);
		cd->setPauseDown();
		//        pthread_mutex_unlock(&g_downloadMutex);
	}
	jindu = percent;
	//CCLog("current:%.2f",percent);
	//pthread_mutex_lock(&g_downloadMutex);
	
	//const char * per = CCString::createWithFormat("donw progress:%.2f%%", percent)->getCString();
	//updateStr = per;
	//downFilePath = filefullPath;
	//pthread_mutex_unlock(&g_downloadMutex);
}
long HttpDownload::getLocalFileLength(std::string filePath)const
{
    CurlDown *curl = new CurlDown();
    curl->_FilePath = filePath;
    return curl->getLocalFileLength();
}
long HttpDownload::getDownloadFileSize(std::string url)const
{
    CurlDown *curl = new CurlDown();
    curl->mDownloadUrl = url;
    return curl->getDownloadFileLenth();
}