Don't leave 0 byte files if saving the box art image failed and deal with those that may already exist. Fixes #346

This commit is contained in:
Cameron Gutman 2020-02-20 19:06:19 -08:00
parent f4733dbbe8
commit 9f77f3d968

View File

@ -71,10 +71,10 @@ private:
QUrl BoxArtManager::loadBoxArt(NvComputer* computer, NvApp& app) QUrl BoxArtManager::loadBoxArt(NvComputer* computer, NvApp& app)
{ {
// Try to open the cached file // Try to open the cached file if it exists and contains data
QString cacheFilePath = getFilePathForBoxArt(computer, app.id); QFile cacheFile(getFilePathForBoxArt(computer, app.id));
if (QFile::exists(cacheFilePath)) { if (cacheFile.exists() && cacheFile.size() > 0) {
return QUrl::fromLocalFile(cacheFilePath); return QUrl::fromLocalFile(cacheFile.fileName());
} }
// If we get here, we need to fetch asynchronously. // If we get here, we need to fetch asynchronously.
@ -109,6 +109,10 @@ QUrl BoxArtManager::loadBoxArtFromNetwork(NvComputer* computer, int appId)
if (image.save(cachePath)) { if (image.save(cachePath)) {
return QUrl::fromLocalFile(cachePath); return QUrl::fromLocalFile(cachePath);
} }
else {
// A failed save() may leave a zero byte file. Make sure that's removed.
QFile(cachePath).remove();
}
} }
return QUrl(); return QUrl();