forked from pypt/fervor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fvignoredversions.cpp
63 lines (51 loc) · 1.63 KB
/
fvignoredversions.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "fvignoredversions.h"
#include "fvversioncomparator.h"
#include <QSettings>
#include <string>
// QSettings key for the latest skipped version
#define FV_IGNORED_VERSIONS_LATEST_SKIPPED_VERSION_KEY "FVLatestSkippedVersion"
FVIgnoredVersions::FVIgnoredVersions(QObject *parent) :
QObject(parent)
{
// noop
}
bool FVIgnoredVersions::VersionIsIgnored(QString version)
{
// We assume that variable 'version' contains either:
// 1) The current version of the application (ignore)
// 2) The version that was skipped before and thus stored in QSettings (ignore)
// 3) A newer version (don't ignore)
// 'version' is not likely to contain an older version in any case.
if (version == FV_APP_VERSION) {
return true;
}
QSettings settings;
if (settings.contains(FV_IGNORED_VERSIONS_LATEST_SKIPPED_VERSION_KEY)) {
QString lastSkippedVersion = settings.value(FV_IGNORED_VERSIONS_LATEST_SKIPPED_VERSION_KEY).toString();
if (version == lastSkippedVersion) {
// Implicitly skipped version - skip
return true;
}
}
std::string currentAppVersion = std::string(FV_APP_VERSION);
std::string suggestedVersion = std::string(version.toStdString());
if (FvVersionComparator::CompareVersions(currentAppVersion, suggestedVersion) == FvVersionComparator::kAscending) {
// Newer version - do not skip
return false;
}
// Fallback - skip
return true;
}
void FVIgnoredVersions::IgnoreVersion(QString version)
{
if (version == FV_APP_VERSION) {
// Don't ignore the current version
return;
}
if (version.isEmpty()) {
return;
}
QSettings settings;
settings.setValue(FV_IGNORED_VERSIONS_LATEST_SKIPPED_VERSION_KEY, version);
return;
}