-
Notifications
You must be signed in to change notification settings - Fork 73
/
fvignoredversions.cpp
86 lines (72 loc) · 2.29 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include "fvignoredversions.h"
#include "fvversioncomparator.h"
#include <QSettings>
#include <QApplication>
#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;
}
#ifdef Q_WS_MAC
QSettings settings(QSettings::NativeFormat,
QSettings::UserScope,
QApplication::organizationDomain(),
QApplication::applicationName());
#else
QSettings settings(QSettings::NativeFormat,
QSettings::UserScope,
QApplication::organizationName(),
QApplication::applicationName());
#endif
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;
}
#ifdef Q_WS_MAC
QSettings settings(QSettings::NativeFormat,
QSettings::UserScope,
QApplication::organizationDomain(),
QApplication::applicationName());
#else
QSettings settings(QSettings::NativeFormat,
QSettings::UserScope,
QApplication::organizationName(),
QApplication::applicationName());
#endif
settings.setValue(FV_IGNORED_VERSIONS_LATEST_SKIPPED_VERSION_KEY, version);
return;
}