mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-10 01:09:50 +00:00
Changed: Use basic cache expire for web images
--HG-- branch : develop
This commit is contained in:
parent
f23600cd30
commit
72b37450b4
1 changed files with 41 additions and 31 deletions
|
@ -274,6 +274,21 @@ namespace NLGUI
|
|||
return false;
|
||||
}
|
||||
|
||||
// TODO: replace with expire and etag headers
|
||||
if (CFile::fileExists(download.dest))
|
||||
{
|
||||
time_t currentTime;
|
||||
time(¤tTime);
|
||||
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";
|
||||
|
||||
// erase the tmp file if exists
|
||||
|
@ -344,8 +359,6 @@ namespace NLGUI
|
|||
nlwarning("add to download '%s' dest '%s' img %p", finalUrl.c_str(), dest.c_str(), img);
|
||||
#endif
|
||||
|
||||
if (!NLMISC::CFile::fileExists(dest))
|
||||
{
|
||||
Curls.push_back(CDataDownload(finalUrl, dest, ImgType, img, "", "", style));
|
||||
if (Curls.size() < options.curlMaxConnections) {
|
||||
if (!startCurlDownload(Curls.back()))
|
||||
|
@ -364,12 +377,6 @@ namespace NLGUI
|
|||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
setImage(img, dest);
|
||||
setImageSize(img, style);
|
||||
}
|
||||
}
|
||||
|
||||
void CGroupHTML::initImageDownload()
|
||||
{
|
||||
|
@ -607,6 +614,9 @@ namespace NLGUI
|
|||
CBitmap::loadSize(tmpfile, w, h);
|
||||
if (w != 0 && h != 0)
|
||||
{
|
||||
if (CFile::fileExists(it->dest))
|
||||
CFile::deleteFile(it->dest);
|
||||
|
||||
CFile::moveFile(it->dest, tmpfile);
|
||||
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
|
||||
//
|
||||
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
|
||||
try
|
||||
|
@ -4243,15 +4257,11 @@ namespace NLGUI
|
|||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
// 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);
|
||||
|
||||
// no image in cache
|
||||
image = "web_del.tga";
|
||||
addImageDownload(img, newImage, style);
|
||||
}
|
||||
|
||||
addImageDownload(img, newImage, style);
|
||||
}
|
||||
newImage->setTexture (image);
|
||||
newImage->setModulateGlobalColor(globalColor);
|
||||
|
|
Loading…
Reference in a new issue