From abf0bf769a8f1fb7bc3022aa69d519e261e1d595 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 3 Jan 2018 14:00:44 +0100 Subject: gui/process-detector: change separator characters Prevent common characters from breaking the saved list. Use unprintable characters. Add migration. --- gui/process_detector.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'gui') 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 #include +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 settings::split_process_names() { QHash ret; QString str = get_game_list(); - QStringList pairs = str.split('|'); + QStringList pairs = str.split(RECORD_SEPARATOR, QString::SkipEmptyParts); for (auto pair : pairs) { - QList tmp = pair.split(':'); + QList 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(ui.tableWidget->cellWidget(i, 1))->currentText(); - str += "|" + exe + ":" + profile; + str += RECORD_SEPARATOR + exe + UNIT_SEPARATOR + profile; } s.set_game_list(str); -- cgit v1.2.3