mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-23 02:42:16 -07:00
Load and store redirects properly.
This commit is contained in:
parent
d22137bb89
commit
eca74114a2
3 changed files with 12 additions and 3 deletions
|
|
@ -145,10 +145,13 @@ 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 = "redirectCache.ini";
|
cacheFilePath = SettingsCache::instance().getRedirectCachePath() + "cacheSettings.ini";
|
||||||
loadRedirectCache();
|
loadRedirectCache();
|
||||||
cleanStaleEntries();
|
cleanStaleEntries();
|
||||||
|
|
||||||
|
connect(QCoreApplication::instance(), &QCoreApplication::aboutToQuit, this,
|
||||||
|
&PictureLoaderWorker::saveRedirectCache);
|
||||||
|
|
||||||
pictureLoaderThread = new QThread;
|
pictureLoaderThread = new QThread;
|
||||||
pictureLoaderThread->start(QThread::LowPriority);
|
pictureLoaderThread->start(QThread::LowPriority);
|
||||||
moveToThread(pictureLoaderThread);
|
moveToThread(pictureLoaderThread);
|
||||||
|
|
@ -156,7 +159,6 @@ PictureLoaderWorker::PictureLoaderWorker()
|
||||||
|
|
||||||
PictureLoaderWorker::~PictureLoaderWorker()
|
PictureLoaderWorker::~PictureLoaderWorker()
|
||||||
{
|
{
|
||||||
saveRedirectCache();
|
|
||||||
pictureLoaderThread->deleteLater();
|
pictureLoaderThread->deleteLater();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -489,6 +491,7 @@ QNetworkReply *PictureLoaderWorker::makeRequest(const QUrl &url)
|
||||||
void PictureLoaderWorker::cacheRedirect(const QUrl &originalUrl, const QUrl &redirectUrl)
|
void PictureLoaderWorker::cacheRedirect(const QUrl &originalUrl, const QUrl &redirectUrl)
|
||||||
{
|
{
|
||||||
redirectCache[originalUrl] = qMakePair(redirectUrl, QDateTime::currentDateTimeUtc());
|
redirectCache[originalUrl] = qMakePair(redirectUrl, QDateTime::currentDateTimeUtc());
|
||||||
|
saveRedirectCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
QUrl PictureLoaderWorker::getCachedRedirect(const QUrl &originalUrl) const
|
QUrl PictureLoaderWorker::getCachedRedirect(const QUrl &originalUrl) const
|
||||||
|
|
@ -520,6 +523,7 @@ void PictureLoaderWorker::loadRedirectCache()
|
||||||
|
|
||||||
void PictureLoaderWorker::saveRedirectCache() const
|
void PictureLoaderWorker::saveRedirectCache() const
|
||||||
{
|
{
|
||||||
|
qDebug() << "Saving redirect cache";
|
||||||
QSettings settings(cacheFilePath, QSettings::IniFormat);
|
QSettings settings(cacheFilePath, QSettings::IniFormat);
|
||||||
|
|
||||||
settings.beginWriteArray("redirects", redirectCache.size());
|
settings.beginWriteArray("redirects", redirectCache.size());
|
||||||
|
|
|
||||||
|
|
@ -1030,6 +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/");
|
||||||
// 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/");
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ private:
|
||||||
QByteArray tokenDialogGeometry;
|
QByteArray tokenDialogGeometry;
|
||||||
QByteArray setsDialogGeometry;
|
QByteArray setsDialogGeometry;
|
||||||
QString lang;
|
QString lang;
|
||||||
QString deckPath, replaysPath, picsPath, customPicsPath, cardDatabasePath, customCardDatabasePath, themesPath,
|
QString deckPath, replaysPath, picsPath, redirectCachePath, customPicsPath, cardDatabasePath, customCardDatabasePath, themesPath,
|
||||||
spoilerDatabasePath, tokenDatabasePath, themeName;
|
spoilerDatabasePath, tokenDatabasePath, themeName;
|
||||||
bool notifyAboutUpdates;
|
bool notifyAboutUpdates;
|
||||||
bool notifyAboutNewVersion;
|
bool notifyAboutNewVersion;
|
||||||
|
|
@ -183,6 +183,10 @@ public:
|
||||||
{
|
{
|
||||||
return picsPath;
|
return picsPath;
|
||||||
}
|
}
|
||||||
|
QString getRedirectCachePath() const
|
||||||
|
{
|
||||||
|
return redirectCachePath;
|
||||||
|
}
|
||||||
QString getCustomPicsPath() const
|
QString getCustomPicsPath() const
|
||||||
{
|
{
|
||||||
return customPicsPath;
|
return customPicsPath;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue