summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gui/process_detector.cpp15
-rw-r--r--migration/20180102_00-process-detector-separator.cpp48
2 files changed, 60 insertions, 3 deletions
diff --git a/gui/process_detector.cpp b/gui/process_detector.cpp
index b1ad541d..806f0b47 100644
--- a/gui/process_detector.cpp
+++ b/gui/process_detector.cpp
@@ -17,6 +17,9 @@
#include <QPushButton>
#include <QSettings>
+static constexpr inline auto RECORD_SEPARATOR = QChar(char(0x1e)); // RS ^]
+static constexpr inline auto UNIT_SEPARATOR = QChar(char(0x1f)); // US ^_
+
void settings::set_game_list(const QString &game_list)
{
group::with_global_settings_object([&](QSettings& settings) {
@@ -49,12 +52,18 @@ QHash<QString, QString> settings::split_process_names()
{
QHash<QString, QString> ret;
QString str = get_game_list();
- QStringList pairs = str.split('|');
+ QStringList pairs = str.split(RECORD_SEPARATOR, QString::SkipEmptyParts);
for (auto pair : pairs)
{
- QList<QString> tmp = pair.split(':');
+ QList<QString> tmp = pair.split(UNIT_SEPARATOR);
if (tmp.count() != 2)
continue;
+ if (tmp[0].contains(UNIT_SEPARATOR) || tmp[0].contains(RECORD_SEPARATOR))
+ continue;
+ if (tmp[1].contains(UNIT_SEPARATOR) || tmp[1].contains(RECORD_SEPARATOR))
+ continue;
+ if (tmp[0] == QLatin1String("") || tmp[1] == QLatin1String(""))
+ continue;
ret[tmp[0]] = tmp[1];
}
return ret;
@@ -136,7 +145,7 @@ void process_detector::save()
{
auto exe = ui.tableWidget->item(i, 0)->text();
auto profile = reinterpret_cast<QComboBox*>(ui.tableWidget->cellWidget(i, 1))->currentText();
- str += "|" + exe + ":" + profile;
+ str += RECORD_SEPARATOR + exe + UNIT_SEPARATOR + profile;
}
s.set_game_list(str);
diff --git a/migration/20180102_00-process-detector-separator.cpp b/migration/20180102_00-process-detector-separator.cpp
new file mode 100644
index 00000000..c1864adf
--- /dev/null
+++ b/migration/20180102_00-process-detector-separator.cpp
@@ -0,0 +1,48 @@
+#include "migration.hpp"
+#include "options/options.hpp"
+
+using namespace options;
+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 constexpr QLatin1String KEY_NAME = "executable-list"_qstr;
+
+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 group::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 group::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);