mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-23 10:52:16 -07:00
Address comments.
This commit is contained in:
parent
9f0e941476
commit
cbc260646f
3 changed files with 14 additions and 9 deletions
|
|
@ -147,7 +147,7 @@ PictureLoaderWorker::PictureLoaderWorker()
|
||||||
networkManager->setRedirectPolicy(QNetworkRequest::ManualRedirectPolicy);
|
networkManager->setRedirectPolicy(QNetworkRequest::ManualRedirectPolicy);
|
||||||
connect(networkManager, SIGNAL(finished(QNetworkReply *)), this, SLOT(picDownloadFinished(QNetworkReply *)));
|
connect(networkManager, SIGNAL(finished(QNetworkReply *)), this, SLOT(picDownloadFinished(QNetworkReply *)));
|
||||||
|
|
||||||
cacheFilePath = SettingsCache::instance().getRedirectCachePath() + "cacheSettings.ini";
|
cacheFilePath = SettingsCache::instance().getRedirectCachePath() + REDIRECT_CACHE_FILENAME;
|
||||||
loadRedirectCache();
|
loadRedirectCache();
|
||||||
cleanStaleEntries();
|
cleanStaleEntries();
|
||||||
|
|
||||||
|
|
@ -512,9 +512,9 @@ void PictureLoaderWorker::loadRedirectCache()
|
||||||
int size = settings.beginReadArray("redirects");
|
int size = settings.beginReadArray("redirects");
|
||||||
for (int i = 0; i < size; ++i) {
|
for (int i = 0; i < size; ++i) {
|
||||||
settings.setArrayIndex(i);
|
settings.setArrayIndex(i);
|
||||||
QUrl originalUrl = settings.value("original").toUrl();
|
QUrl originalUrl = settings.value(REDIRECT_ORIGINAL_URL).toUrl();
|
||||||
QUrl redirectUrl = settings.value("redirect").toUrl();
|
QUrl redirectUrl = settings.value(REDIRECT_URL).toUrl();
|
||||||
QDateTime timestamp = settings.value("timestamp").toDateTime();
|
QDateTime timestamp = settings.value(REDIRECT_TIMESTAMP).toDateTime();
|
||||||
|
|
||||||
if (originalUrl.isValid() && redirectUrl.isValid()) {
|
if (originalUrl.isValid() && redirectUrl.isValid()) {
|
||||||
redirectCache[originalUrl] = qMakePair(redirectUrl, timestamp);
|
redirectCache[originalUrl] = qMakePair(redirectUrl, timestamp);
|
||||||
|
|
@ -532,9 +532,9 @@ void PictureLoaderWorker::saveRedirectCache() const
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (auto it = redirectCache.cbegin(); it != redirectCache.cend(); ++it) {
|
for (auto it = redirectCache.cbegin(); it != redirectCache.cend(); ++it) {
|
||||||
settings.setArrayIndex(index++);
|
settings.setArrayIndex(index++);
|
||||||
settings.setValue("original", it.key());
|
settings.setValue(REDIRECT_ORIGINAL_URL, it.key());
|
||||||
settings.setValue("redirect", it.value().first);
|
settings.setValue(REDIRECT_URL, it.value().first);
|
||||||
settings.setValue("timestamp", it.value().second);
|
settings.setValue(REDIRECT_TIMESTAMP, it.value().second);
|
||||||
}
|
}
|
||||||
settings.endArray();
|
settings.endArray();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,11 @@ class QNetworkAccessManager;
|
||||||
class QNetworkReply;
|
class QNetworkReply;
|
||||||
class QThread;
|
class QThread;
|
||||||
|
|
||||||
|
#define REDIRECT_ORIGINAL_URL "original"
|
||||||
|
#define REDIRECT_URL "redirect"
|
||||||
|
#define REDIRECT_TIMESTAMP "timestamp"
|
||||||
|
#define REDIRECT_CACHE_FILENAME "cache.ini"
|
||||||
|
|
||||||
class PictureToLoad
|
class PictureToLoad
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
@ -85,7 +90,7 @@ private:
|
||||||
QNetworkAccessManager *networkManager;
|
QNetworkAccessManager *networkManager;
|
||||||
QHash<QUrl, QPair<QUrl, QDateTime>> redirectCache; // Stores redirect and timestamp
|
QHash<QUrl, QPair<QUrl, QDateTime>> redirectCache; // Stores redirect and timestamp
|
||||||
QString cacheFilePath; // Path to persistent storage
|
QString cacheFilePath; // Path to persistent storage
|
||||||
int CacheTTLInDays = 30;
|
static constexpr int CacheTTLInDays = 30;
|
||||||
QList<PictureToLoad> cardsToDownload;
|
QList<PictureToLoad> cardsToDownload;
|
||||||
PictureToLoad cardBeingLoaded;
|
PictureToLoad cardBeingLoaded;
|
||||||
PictureToLoad cardBeingDownloaded;
|
PictureToLoad cardBeingDownloaded;
|
||||||
|
|
|
||||||
|
|
@ -1030,7 +1030,7 @@ void SettingsCache::loadPaths()
|
||||||
replaysPath = getSafeConfigPath("paths/replays", dataPath + "/replays/");
|
replaysPath = getSafeConfigPath("paths/replays", dataPath + "/replays/");
|
||||||
themesPath = getSafeConfigPath("paths/themes", dataPath + "/themes/");
|
themesPath = getSafeConfigPath("paths/themes", dataPath + "/themes/");
|
||||||
picsPath = getSafeConfigPath("paths/pics", dataPath + "/pics/");
|
picsPath = getSafeConfigPath("paths/pics", dataPath + "/pics/");
|
||||||
redirectCachePath = getSafeConfigPath("paths/redirects", dataPath + "/pics/redirects/");
|
redirectCachePath = getSafeConfigPath("paths/redirects", getCachePath() + "/redirects/");
|
||||||
// this has never been exposed as an user-configurable setting
|
// this has never been exposed as an user-configurable setting
|
||||||
if (picsPath.endsWith("/")) {
|
if (picsPath.endsWith("/")) {
|
||||||
customPicsPath = getSafeConfigPath("paths/custompics", picsPath + "CUSTOM/");
|
customPicsPath = getSafeConfigPath("paths/custompics", picsPath + "CUSTOM/");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue