summaryrefslogtreecommitdiffhomepage
path: root/migration/20180102_00-process-detector-separator.cpp
blob: 8d0fa280aa7df089eefdb0450a721b43ff2593e1 (plain)
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
#include "migration.hpp"
#include "options/options.hpp"

using namespace options;
using namespace options::globals;
using namespace migrations;

static constexpr auto OLD_RECORD_SEPARATOR  = QChar('|');
static constexpr auto OLD_UNIT_SEPARATOR    = QChar(':');

static constexpr auto NEW_RECORD_SEPARATOR  = QChar(0x1e);
static constexpr auto NEW_UNIT_SEPARATOR    = QChar(0x1f);

static const QString KEY_NAME = "executable-list";

struct process_detector_record_separator : migration
{
    QString unique_date() const override
    {
        return "20180102_00";
    }

    QString name() const override
    {
        return "process detector record separator";
    }

    bool should_run() const override
    {
        return with_global_settings_object([](const QSettings& s)
        {
            const QString old_value = s.value(KEY_NAME).toString();
            return old_value.contains(OLD_RECORD_SEPARATOR);
        });
    }

    void run() override
    {
        return with_global_settings_object([](QSettings& s)
        {
            QString value = s.value(KEY_NAME).toString();
            value.replace(OLD_UNIT_SEPARATOR,   NEW_UNIT_SEPARATOR);
            value.replace(OLD_RECORD_SEPARATOR, NEW_RECORD_SEPARATOR);
            s.setValue(KEY_NAME, value);
        });
    }
};

OPENTRACK_MIGRATION(process_detector_record_separator)