Update AssetsManager.cpp

fix: crash when default constructor params packageUrl, versionFileUrl,.. is NULL
fix: percent
This commit is contained in:
HuaYang Huang 2015-05-16 11:48:34 +08:00
parent e99b99cc79
commit 8212b1398f
1 changed files with 8 additions and 6 deletions

View File

@ -85,10 +85,10 @@ struct ProgressMessage
// Implementation of AssetsManager
AssetsManager::AssetsManager(const char* packageUrl/* =nullptr */, const char* versionFileUrl/* =nullptr */, const char* storagePath/* =nullptr */)
: _storagePath(storagePath)
: _storagePath(storagePath ? storagePath : "")
, _version("")
, _packageUrl(packageUrl)
, _versionFileUrl(versionFileUrl)
, _packageUrl(packageUrl ? packageUrl : "")
, _versionFileUrl(versionFileUrl ? versionFileUrl : "")
, _downloadedVersion("")
, _curl(nullptr)
, _connectionTimeout(0)
@ -180,8 +180,7 @@ bool AssetsManager::checkUpdate()
return false;
}
string recordedVersion = UserDefault::getInstance()->getStringForKey(keyOfVersion().c_str());
if (recordedVersion == _version)
if (getVersion() == _version)
{
Director::getInstance()->getScheduler()->performFunctionInCocosThread([&, this]{
if (this->_delegate)
@ -496,7 +495,10 @@ static size_t downLoadPackage(void *ptr, size_t size, size_t nmemb, void *userda
int assetsManagerProgressFunc(void *ptr, double totalToDownload, double nowDownloaded, double totalToUpLoad, double nowUpLoaded)
{
static int percent = 0;
int tmp = (int)(nowDownloaded / totalToDownload * 100);
int tmp = 0;
if (totalToDownload > 0) {
tmp = (int)(nowDownloaded / totalToDownload * 100);
}
if (percent != tmp)
{