Merge with develop

--HG--
branch : compatibility-develop
This commit is contained in:
Nimetu 2017-04-20 15:39:29 +03:00
commit b78e8541ef

View file

@ -274,6 +274,21 @@ namespace NLGUI
return false; return false;
} }
// TODO: replace with expire and etag headers
if (CFile::fileExists(download.dest))
{
time_t currentTime;
time(&currentTime);
uint32 mtime = CFile::getFileModificationDate(download.dest);
if (mtime + 3600 > currentTime)
{
#ifdef LOG_DL
nlwarning("Cache for (%s) is not expired (%s, age:%d)", download.url.c_str(), download.dest.c_str(), currentTime - mtime);
#endif
return false;
}
}
string tmpdest = download.dest + ".tmp"; string tmpdest = download.dest + ".tmp";
// erase the tmp file if exists // erase the tmp file if exists
@ -344,30 +359,22 @@ namespace NLGUI
nlwarning("add to download '%s' dest '%s' img %p", finalUrl.c_str(), dest.c_str(), img); nlwarning("add to download '%s' dest '%s' img %p", finalUrl.c_str(), dest.c_str(), img);
#endif #endif
if (!NLMISC::CFile::fileExists(dest)) Curls.push_back(CDataDownload(finalUrl, dest, ImgType, img, "", "", style));
{ if (Curls.size() < options.curlMaxConnections) {
Curls.push_back(CDataDownload(finalUrl, dest, ImgType, img, "", "", style)); if (!startCurlDownload(Curls.back()))
if (Curls.size() < options.curlMaxConnections) {
if (!startCurlDownload(Curls.back()))
{
Curls.pop_back();
return;
}
RunningCurls++;
#ifdef LOG_DL
nlwarning("(%s) adding handle %x, %d curls", _Id.c_str(), Curls.back().curl, Curls.size());
}
else
{ {
nlwarning("(%s) download queued, %d curls", _Id.c_str(), Curls.size()); Curls.pop_back();
#endif return;
} }
RunningCurls++;
#ifdef LOG_DL
nlwarning("(%s) adding handle %x, %d curls", _Id.c_str(), Curls.back().curl, Curls.size());
} }
else else
{ {
setImage(img, dest); nlwarning("(%s) download queued, %d curls", _Id.c_str(), Curls.size());
setImageSize(img, style); #endif
} }
} }
@ -607,6 +614,9 @@ namespace NLGUI
CBitmap::loadSize(tmpfile, w, h); CBitmap::loadSize(tmpfile, w, h);
if (w != 0 && h != 0) if (w != 0 && h != 0)
{ {
if (CFile::fileExists(it->dest))
CFile::deleteFile(it->dest);
CFile::moveFile(it->dest, tmpfile); CFile::moveFile(it->dest, tmpfile);
for(uint i = 0; i < it->imgs.size(); i++) for(uint i = 0; i < it->imgs.size(); i++)
{ {
@ -4225,7 +4235,11 @@ namespace NLGUI
// 2/ if it doesn't work, try to load the image in cache // 2/ if it doesn't work, try to load the image in cache
// //
image = localImageName(img); image = localImageName(img);
if (!reloadImg && lookupLocalFile (finalUrl, image.c_str(), false))
if (reloadImg && CFile::fileExists(image))
CFile::deleteFile(image);
if (lookupLocalFile (finalUrl, image.c_str(), false))
{ {
// don't display image that are not power of 2 // don't display image that are not power of 2
try try
@ -4243,15 +4257,11 @@ namespace NLGUI
} }
else else
{ {
// // no image in cache
// 3/ if it doesn't work, display a placeholder and ask to dl the image into the cache
//
if (reloadImg && CFile::fileExists(image))
CFile::deleteFile(image);
image = "web_del.tga"; image = "web_del.tga";
addImageDownload(img, newImage, style);
} }
addImageDownload(img, newImage, style);
} }
newImage->setTexture (image); newImage->setTexture (image);
newImage->setModulateGlobalColor(globalColor); newImage->setModulateGlobalColor(globalColor);