summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSilarn <jrim@rimpo.org>2019-02-05 22:38:46 -0600
committerSilarn <jrim@rimpo.org>2019-02-18 21:31:20 -0600
commit8bc9db23d98ae454899791af9e0fbc0bab4d0b15 (patch)
tree372f10f58879b6726e777ff4e295a7461f880a38 /src
parenteb575e2f92e00e32220e7aa8efaf14ece462c981 (diff)
Add settings option to switch between fixed and dynamic cache timeouts
Diffstat (limited to 'src')
-rw-r--r--src/modinforegular.cpp37
-rw-r--r--src/modlist.cpp8
-rw-r--r--src/settings.cpp19
-rw-r--r--src/settings.h17
-rw-r--r--src/settingsdialog.ui10
5 files changed, 70 insertions, 21 deletions
diff --git a/src/modinforegular.cpp b/src/modinforegular.cpp
index 876ccf3d..10a1317c 100644
--- a/src/modinforegular.cpp
+++ b/src/modinforegular.cpp
@@ -507,22 +507,29 @@ bool ModInfoRegular::canBeUpdated() const
QDateTime ModInfoRegular::getExpires() const
{
- qint64 diff = m_NexusLastModified.msecsTo(QDateTime::currentDateTimeUtc());
- qint64 year = 31536000000;
- qint64 sixMonths = 15768000000;
- qint64 threeMonths = 7884000000;
- qint64 oneMonth = 1314000000;
+ switch (Settings::instance().nexusUpdateStrategy()) {
+ case Settings::NexusUpdateStrategy::Flexible: {
+ qint64 diff = m_NexusLastModified.msecsTo(QDateTime::currentDateTimeUtc());
+ qint64 year = 31536000000;
+ qint64 sixMonths = 15768000000;
+ qint64 threeMonths = 7884000000;
+ qint64 oneMonth = 1314000000;
- if (diff < oneMonth)
- return m_LastNexusUpdate.addSecs(7200);
- else if (diff < threeMonths)
- return m_LastNexusUpdate.addSecs(14400);
- else if (diff < sixMonths)
- return m_LastNexusUpdate.addSecs(21600);
- else if (diff < year)
- return m_LastNexusUpdate.addSecs(43200);
- else
- return m_LastNexusUpdate.addSecs(86400);
+ if (diff < oneMonth)
+ return m_LastNexusUpdate.addSecs(7200);
+ else if (diff < threeMonths)
+ return m_LastNexusUpdate.addSecs(14400);
+ else if (diff < sixMonths)
+ return m_LastNexusUpdate.addSecs(21600);
+ else if (diff < year)
+ return m_LastNexusUpdate.addSecs(43200);
+ else
+ return m_LastNexusUpdate.addSecs(86400);
+ } break;
+ case Settings::NexusUpdateStrategy::Rigid: {
+ return m_LastNexusUpdate.addSecs(86400);
+ } break;
+ }
}
std::vector<ModInfo::EFlag> ModInfoRegular::getFlags() const
diff --git a/src/modlist.cpp b/src/modlist.cpp
index c252d73b..55241492 100644
--- a/src/modlist.cpp
+++ b/src/modlist.cpp
@@ -465,9 +465,13 @@ QVariant ModList::data(const QModelIndex &modelIndex, int role) const
}
if (modInfo->getNexusID() > 0) {
if (!modInfo->canBeUpdated()) {
- text += "<br>" + tr("This mod was last checked on %1. It will be available to check after %2.")
+ qint64 remains = QDateTime::currentDateTimeUtc().secsTo(modInfo->getExpires());
+ qint64 hours = remains / 3600;
+ qint64 minutes = (remains % 3600) / 60;
+ QString remainsStr(tr("%1 hours and %2 minutes").arg(hours).arg(minutes));
+ text += "<br>" + tr("This mod was last checked on %1. It will be available to check in %2.")
.arg(modInfo->getLastNexusUpdate().toLocalTime().toString(Qt::DefaultLocaleShortDate))
- .arg(modInfo->getExpires().toLocalTime().time().toString(Qt::DefaultLocaleShortDate));
+ .arg(remainsStr);
} else {
text += "<br>" + tr("This mod is eligible for an update check.");
text += "<br>" + tr("It was last checked on %1").arg(modInfo->getLastNexusUpdate().toLocalTime().toString(Qt::DefaultLocaleShortDate));
diff --git a/src/settings.cpp b/src/settings.cpp
index cb4520e7..6be5489d 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -81,10 +81,6 @@ private:
int m_SortRole;
};
-
-static const unsigned char Key2[20] = { 0x99, 0xb8, 0x76, 0x42, 0x3e, 0xc1, 0x60, 0xa4, 0x5b, 0x01,
- 0xdb, 0xf8, 0x43, 0x3a, 0xb7, 0xb6, 0x98, 0xd4, 0x7d, 0xa2 };
-
Settings *Settings::s_Instance = nullptr;
@@ -96,6 +92,8 @@ Settings::Settings(const QSettings &settingsSource)
} else {
s_Instance = this;
}
+
+ qRegisterMetaType<Settings::NexusUpdateStrategy>("NexusUpdateStrategy");
}
@@ -418,6 +416,11 @@ int Settings::crashDumpsMax() const
return m_Settings.value("Settings/crash_dumps_max", 5).toInt();
}
+Settings::NexusUpdateStrategy Settings::nexusUpdateStrategy() const
+{
+ return static_cast<NexusUpdateStrategy>(m_Settings.value("Settings/nexus_update_strategy", std::rand() / ((RAND_MAX + 1u) / 2)).toInt());
+}
+
QColor Settings::modlistOverwrittenLooseColor() const
{
return m_Settings.value("Settings/overwrittenLooseFilesColor", QColor(0, 255, 0, 64)).value<QColor>();
@@ -1039,7 +1042,10 @@ Settings::NexusTab::NexusTab(Settings *parent, SettingsDialog &dialog)
, m_preferredServersList(
dialog.findChild<QListWidget *>("preferredServersList"))
, m_endorsementBox(dialog.findChild<QCheckBox *>("endorsementBox"))
+ , m_updateStrategyBox(dialog.findChild<QCheckBox *>("updateStrategy"))
{
+ qRegisterMetaType<Settings::NexusUpdateStrategy>("NexusUpdateStrategy");
+
if (!deObfuscate("APIKEY").isEmpty()) {
m_nexusConnect->setText("Nexus API Key Stored");
m_nexusConnect->setDisabled(true);
@@ -1048,6 +1054,9 @@ Settings::NexusTab::NexusTab(Settings *parent, SettingsDialog &dialog)
m_offlineBox->setChecked(parent->offlineMode());
m_proxyBox->setChecked(parent->useProxy());
m_endorsementBox->setChecked(parent->endorsementIntegration());
+ if (parent->nexusUpdateStrategy() == Settings::NexusUpdateStrategy::Flexible)
+ m_updateStrategyBox->setChecked(true);
+
// display server preferences
m_Settings.beginGroup("Servers");
@@ -1092,6 +1101,8 @@ void Settings::NexusTab::update()
m_Settings.setValue("Settings/offline_mode", m_offlineBox->isChecked());
m_Settings.setValue("Settings/use_proxy", m_proxyBox->isChecked());
m_Settings.setValue("Settings/endorsement_integration", m_endorsementBox->isChecked());
+ m_Settings.setValue("Settings/nexus_update_strategy", m_updateStrategyBox->isChecked()
+ ? Settings::NexusUpdateStrategy::Flexible : Settings::NexusUpdateStrategy::Rigid);
// store server preference
m_Settings.beginGroup("Servers");
diff --git a/src/settings.h b/src/settings.h
index a1dc011d..ddb7cac0 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -31,6 +31,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#include <QString>
#include <QVariant>
#include <QColor>
+#include <QMetaType>
#include <QtGlobal> //for uint
@@ -64,6 +65,14 @@ class Settings : public QObject
{
Q_OBJECT
+ Q_ENUMS(NexusUpdateStrategy)
+
+public:
+
+ enum NexusUpdateStrategy {
+ Rigid,
+ Flexible
+ };
public:
@@ -230,6 +239,11 @@ public:
*/
int crashDumpsMax() const;
+ /**
+ * @return the configured Nexus update strategy
+ */
+ NexusUpdateStrategy nexusUpdateStrategy() const;
+
QColor modlistOverwrittenLooseColor() const;
QColor modlistOverwritingLooseColor() const;
@@ -485,6 +499,7 @@ private:
QListWidget *m_knownServersList;
QListWidget *m_preferredServersList;
QCheckBox *m_endorsementBox;
+ QCheckBox *m_updateStrategyBox;
};
/** Display/store the configuration in the 'steam' tab of the settings dialogue */
@@ -563,4 +578,6 @@ private:
};
+Q_DECLARE_METATYPE(Settings::NexusUpdateStrategy)
+
#endif // SETTINGS_H
diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui
index 127c94c7..cfbcf429 100644
--- a/src/settingsdialog.ui
+++ b/src/settingsdialog.ui
@@ -578,6 +578,16 @@ p, li { white-space: pre-wrap; }
</property>
</widget>
</item>
+ <item row="1" column="1">
+ <widget class="QCheckBox" name="updateStrategy">
+ <property name="toolTip">
+ <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Rather than a global &lt;span style=&quot; font-weight:600;&quot;&gt;1 day&lt;/span&gt; cache, update caches will expire at different rates depending on how recently a mod has been updated on Nexus.&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;Less than a month: &lt;span style=&quot; font-style:italic;&quot;&gt;2 hours&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Less than three months: &lt;span style=&quot; font-style:italic;&quot;&gt;4 hours&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Less than six months: &lt;span style=&quot; font-style:italic;&quot;&gt;6 hours&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Less than one year: &lt;span style=&quot; font-style:italic;&quot;&gt;12 hours&lt;/span&gt;&lt;/p&gt;&lt;p&gt;More than one year: &lt;span style=&quot; font-style:italic;&quot;&gt;1 day&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
+ </property>
+ <property name="text">
+ <string>Use dynamic update timeouts</string>
+ </property>
+ </widget>
+ </item>
</layout>
</item>
<item>