summaryrefslogtreecommitdiffhomepage
path: root/migration
diff options
context:
space:
mode:
Diffstat (limited to 'migration')
-rw-r--r--migration/20160906_00-mappings.cpp122
-rw-r--r--migration/20160906_01-axis-signs.cpp78
-rw-r--r--migration/20160906_02-modules.cpp26
-rw-r--r--migration/20160917_00-accela.cpp127
-rw-r--r--migration/20170420_00-udp-naming.cpp54
-rw-r--r--migration/20171013_00-tracker-pt-threshold.cpp52
-rw-r--r--migration/20171020_00-max-pitch-output.cpp70
-rw-r--r--migration/20180102_00-process-detector-separator.cpp50
-rw-r--r--migration/20180118_00-reltrans.cpp44
-rw-r--r--migration/20180428_00-module-names.cpp92
-rw-r--r--migration/20220105_00-pt-grayscale.cpp38
-rw-r--r--migration/20220126_00-camera-name.cpp79
-rw-r--r--migration/CMakeLists.txt5
-rw-r--r--migration/lang/de_DE.ts4
-rw-r--r--migration/lang/zh_CN.ts4
-rw-r--r--migration/migration.cpp165
-rw-r--r--migration/migration.hpp67
17 files changed, 739 insertions, 338 deletions
diff --git a/migration/20160906_00-mappings.cpp b/migration/20160906_00-mappings.cpp
index 58674843..2bc00084 100644
--- a/migration/20160906_00-mappings.cpp
+++ b/migration/20160906_00-mappings.cpp
@@ -18,42 +18,49 @@
#include <QDebug>
+using namespace options;
+using namespace options::globals;
using namespace migrations;
-struct mappings_from_2_3_0_rc11 : migration
+static const char* const old_names[] =
{
- static QList<QList<QPointF>> get_old_splines()
- {
- QList<QList<QPointF>> ret;
+ "tx", "tx_alt",
+ "ty", "ty_alt",
+ "tz", "tz_alt",
+ "rx", "rx_alt",
+ "ry", "ry_alt",
+ "rz", "rz_alt",
+};
- static const char* names[] =
- {
- "tx", "tx_alt",
- "ty", "ty_alt",
- "tz", "tz_alt",
- "rx", "rx_alt",
- "ry", "ry_alt",
- "rz", "rz_alt",
- };
-
- std::shared_ptr<QSettings> settings_ = options::group::ini_file();
- QSettings& settings(*settings_);
-
- for (const char* name : names)
+static const char* const new_names[] = {
+ "spline-X", "alt-spline-X",
+ "spline-Y", "alt-spline-Y",
+ "spline-Z", "alt-spline-Z",
+ "spline-yaw", "alt-spline-yaw",
+ "spline-pitch", "alt-spline-pitch",
+ "spline-roll", "alt-spline-roll",
+};
+
+static QList<QList<QPointF>> get_old_splines()
+{
+ QList<QList<QPointF>> ret;
+
+ return with_settings_object([&](QSettings& settings) {
+ for (const char* name : old_names)
{
+ const int max = settings.value("point-count", 0).toInt();
+
+ if (max < 0 || max > 1 << 16)
+ return ret;
+
QList<QPointF> points;
+ points.reserve(max);
settings.beginGroup(QString("Curves-%1").arg(name));
- const int max = settings.value("point-count", 0).toInt();
-
for (int i = 0; i < max; i++)
- {
- QPointF new_point(settings.value(QString("point-%1-x").arg(i), 0).toDouble(),
- settings.value(QString("point-%1-y").arg(i), 0).toDouble());
-
- points.append(new_point);
- }
+ points.append({ settings.value(QString("point-%1-x").arg(i), 0).toDouble(),
+ settings.value(QString("point-%1-y").arg(i), 0).toDouble() });
settings.endGroup();
@@ -61,52 +68,49 @@ struct mappings_from_2_3_0_rc11 : migration
}
return ret;
- }
+ });
+}
+struct mappings_from_2_3_0_rc11 : migration
+{
QString unique_date() const override { return "20160909_00"; }
QString name() const override { return "mappings to new layout"; }
- static Mappings get_new_mappings()
- {
- main_settings s;
- return Mappings(std::vector<axis_opts*>{&s.a_x, &s.a_y, &s.a_z, &s.a_yaw, &s.a_pitch, &s.a_roll});
- }
-
bool should_run() const override
- {
- Mappings m = get_new_mappings();
-
- // run only if no new splines were set
- for (int i = 0; i < 6; i++)
- if (m(i).spline_main.get_point_count() || m(i).spline_alt.get_point_count())
+ {
+ for (const char* name : new_names)
+ {
+ // run only if no new splines were set
+ auto b = make_bundle(name);
+ if (b->contains("points"))
return false;
- // run only if old splines exist
- for (const QList<QPointF>& points : get_old_splines())
- if (points.size())
- return true;
+ // run only if old splines exist
+ for (const QList<QPointF>& points : get_old_splines())
+ if (!points.empty())
+ return true;
+ }
// no splines exit at all
return false;
}
- void run() override
- {
- const QList<QList<QPointF>> old_mappings = get_old_splines();
- Mappings m = get_new_mappings();
- std::shared_ptr<QSettings> s_ = options::group::ini_file();
- QSettings& s = *s_;
+ void run() override
+ {
+ with_settings_object([](QSettings&) {
+ const QList<QList<QPointF>> old_mappings = get_old_splines();
- for (int i = 0; i < 12; i++)
- {
- spline& spl = (i % 2) == 0 ? m(i / 2).spline_main : m(i / 2).spline_alt;
- spl.clear();
- const QList<QPointF>& points = old_mappings[i];
- for (const QPointF& pt : points)
- spl.add_point(pt);
- spl.save(s);
- }
+ for (int i = 0; i < 12; i++)
+ {
+ auto b = make_bundle(new_names[i]);
+ if (b->contains("points"))
+ continue;
+ value<QList<QPointF>> new_value { b, "points", {} };
+ new_value = old_mappings[i];
+ b->save();
+ }
+ });
}
};
-OPENTRACK_MIGRATION(mappings_from_2_3_0_rc11);
+OPENTRACK_MIGRATION(mappings_from_2_3_0_rc11)
diff --git a/migration/20160906_01-axis-signs.cpp b/migration/20160906_01-axis-signs.cpp
index 0934990d..eeb6963d 100644
--- a/migration/20160906_01-axis-signs.cpp
+++ b/migration/20160906_01-axis-signs.cpp
@@ -8,7 +8,6 @@
#include "migration.hpp"
#include "options/options.hpp"
-#include "logic/main-settings.hpp"
#include <QString>
#include <QVariant>
@@ -16,13 +15,18 @@
using namespace options;
using namespace migrations;
+const char* const axis_names[] =
+{
+ "yaw", "pitch", "roll",
+ "x", "y", "z",
+};
+
+const QString alt_sign_fmt = QStringLiteral("%1-alt-axis-sign");
+
struct axis_signs_split_rc11 : migration
{
axis_signs_split_rc11() = default;
- static const char* axis_names[6];
- static const QString fmt;
-
QString unique_date() const override
{
return "20160909_01";
@@ -33,47 +37,43 @@ struct axis_signs_split_rc11 : migration
return "asymmetric axis option to other section";
}
- bool should_run() const override
+ bool should_run() const override;
+ void run() override;
+};
+
+OPENTRACK_MIGRATION(axis_signs_split_rc11)
+
+bool axis_signs_split_rc11::should_run() const
+{
+ bundle new_bundle = make_bundle("opentrack-mappings");
+ bundle old_bundle = make_bundle("opentrack-ui");
+
+ for (const char* name : axis_names)
{
- bundle new_bundle = make_bundle("opentrack-mappings");
- bundle old_bundle = make_bundle("opentrack-ui");
-
- for (const char* name : axis_names)
- {
- // new present, already applied
- if (new_bundle->contains(fmt.arg(name)))
- return false;
- }
-
- for (const char* name : axis_names)
- {
- // old present
- if (old_bundle->contains(fmt.arg(name)))
- return true;
- }
-
- // nothing to copy
- return false;
+ // new present, already applied
+ if (new_bundle->contains(alt_sign_fmt.arg(name)))
+ return false;
}
- void run() override
+ for (const char* name : axis_names)
{
- bundle new_bundle = make_bundle("opentrack-mappings");
- bundle old_bundle = make_bundle("opentrack-ui");
-
- for (const char* name : axis_names)
- new_bundle->store_kv(fmt.arg(name), QVariant(old_bundle->get<bool>(fmt.arg(name))));
-
- new_bundle->save();
+ // old present
+ if (old_bundle->contains(alt_sign_fmt.arg(name)))
+ return true;
}
-};
-const char* axis_signs_split_rc11::axis_names[] =
+ // nothing to copy
+ return false;
+}
+
+void axis_signs_split_rc11::run()
{
- "yaw", "pitch", "roll",
- "x", "y", "z",
-};
+ bundle new_bundle = make_bundle("opentrack-mappings");
+ bundle old_bundle = make_bundle("opentrack-ui");
-const QString axis_signs_split_rc11::fmt = QStringLiteral("%1-alt-axis-sign");
+ for (const char* name : axis_names)
+ new_bundle->store_kv(alt_sign_fmt.arg(name),
+ old_bundle->get_variant(alt_sign_fmt.arg(name)));
-OPENTRACK_MIGRATION(axis_signs_split_rc11);
+ new_bundle->save();
+}
diff --git a/migration/20160906_02-modules.cpp b/migration/20160906_02-modules.cpp
index 0f0951f1..46745112 100644
--- a/migration/20160906_02-modules.cpp
+++ b/migration/20160906_02-modules.cpp
@@ -15,12 +15,17 @@
using namespace options;
using namespace migrations;
+static const char* const module_names[3] =
+{
+ "tracker-dll",
+ "protocol-dll",
+ "filter-dll",
+};
+
struct split_modules_rc11 : migration
{
split_modules_rc11() = default;
- static const char* names[3];
-
QString unique_date() const override
{
return "20160909_02";
@@ -36,11 +41,11 @@ struct split_modules_rc11 : migration
bundle new_bundle = make_bundle("modules");
bundle old_bundle = make_bundle("opentrack-ui");
- for (const char* name : names)
+ for (const char* name : module_names)
if (new_bundle->contains(name))
return false;
- for (const char* name : names)
+ for (const char* name : module_names)
if (old_bundle->contains(name))
return true;
@@ -52,18 +57,11 @@ struct split_modules_rc11 : migration
bundle new_bundle = make_bundle("modules");
bundle old_bundle = make_bundle("opentrack-ui");
- for (const char* name : names)
- new_bundle->store_kv(name, QVariant(old_bundle->get<QString>(name)));
+ for (const char* name : module_names)
+ new_bundle->store_kv(name, old_bundle->get_variant(name));
new_bundle->save();
}
};
-const char* split_modules_rc11::names[3] =
-{
- "tracker-dll",
- "protocol-dll",
- "filter-dll",
-};
-
-OPENTRACK_MIGRATION(split_modules_rc11);
+OPENTRACK_MIGRATION(split_modules_rc11)
diff --git a/migration/20160917_00-accela.cpp b/migration/20160917_00-accela.cpp
deleted file mode 100644
index 832dcccf..00000000
--- a/migration/20160917_00-accela.cpp
+++ /dev/null
@@ -1,127 +0,0 @@
-/* Copyright (c) 2016, Stanislaw Halik <sthalik@misaki.pl>
-
- * Permission to use, copy, modify, and/or distribute this
- * software for any purpose with or without fee is hereby granted,
- * provided that the above copyright notice and this permission
- * notice appear in all copies.
- */
-
-#include "migration.hpp"
-#include "options/options.hpp"
-#include "compat/util.hpp"
-
-#include "filter-accela/accela-settings.hpp"
-
-using namespace migrations;
-using namespace options;
-
-struct move_accela_to_sliders : migration
-{
- struct map
- {
- const char* old_name;
- double old_max_100;
- double old_min;
- value<slider_value>* new_slider;
- };
-
- static constexpr const char* old_bundle_name = "Accela";
- static constexpr const char* new_bundle_name = "accela-sliders";
- static constexpr const char* slider_name = "rotation-nonlinearity";
-
- using map_ = struct { map s[8]; };
-
- static map_ make_settings(settings_accela& s)
- {
- map_ ret
- {
- {
- { "rotation-threshold", 4, 1, &s.rot_sensitivity },
- { "translation-threshold", 4, 1, &s.pos_sensitivity },
- { "rotation-deadzone", 4, 0, &s.rot_deadzone },
- { "translation-deadzone", 4, 0, &s.pos_deadzone },
- { "ewma", 1.25, 0, &s.ewma },
- { nullptr, 0, 0, nullptr },
- }
- };
- return ret;
- }
-
- move_accela_to_sliders() = default;
-
- QString unique_date() const override { return "20160917_00"; }
- QString name() const override { return "move accela to .ini sliders"; }
-
- bool should_run() const override
- {
- settings_accela s;
- map_ ss = make_settings(s);
- map* settings = ss.s;
-
- const bundle old_b = make_bundle(old_bundle_name);
- const bundle new_b = make_bundle(new_bundle_name);
-
- bool old_found = false;
-
- for (unsigned i = 0; settings[i].old_name; i++)
- {
- const map& cur = settings[i];
- if (new_b->contains(cur.new_slider->name()))
- return false;
- if (old_b->contains(cur.old_name))
- old_found = true;
- }
-
- old_found |= old_b->contains(slider_name);
- old_found &= !new_b->contains(slider_name);
-
- return old_found;
- }
-
- void run() override
- {
- settings_accela s;
- map_ ss = make_settings(s);
- map* settings = ss.s;
-
- bundle old_b = make_bundle(old_bundle_name);
- bundle new_b = make_bundle(new_bundle_name);
-
- for (unsigned i = 0; settings[i].old_name; i++)
- {
- const map& cur = settings[i];
-
- const slider_value val = progn(
- if (old_b->contains(cur.old_name))
- {
- const double old = old_b->get<double>(cur.old_name);
- return slider_value((cur.old_min + old) * cur.old_max_100 / 100.,
- cur.new_slider->default_value().min(),
- cur.new_slider->default_value().max());
- }
- else
- return cur.new_slider->default_value();
- );
-
- value<slider_value> tmp(new_b, cur.new_slider->name(), slider_value(-1e6, val.min(), val.max()));
- tmp = val;
- }
-
- value<slider_value> tmp(new_b, slider_name, slider_value(-1e6, s.rot_nonlinearity().min(), s.rot_nonlinearity().max()));
- tmp = old_b->contains(slider_name)
- ? old_b->get<slider_value>(slider_name)
- : slider_value(1.1, 1, 1.75);
-
- new_b->save();
- }
-};
-
-// odr
-constexpr double settings_accela::rot_gains[16][2];
-constexpr double settings_accela::pos_gains[16][2];
-
-constexpr const char* move_accela_to_sliders::old_bundle_name;
-constexpr const char* move_accela_to_sliders::new_bundle_name;
-constexpr const char* move_accela_to_sliders::slider_name;
-
-OPENTRACK_MIGRATION(move_accela_to_sliders);
diff --git a/migration/20170420_00-udp-naming.cpp b/migration/20170420_00-udp-naming.cpp
new file mode 100644
index 00000000..d8117526
--- /dev/null
+++ b/migration/20170420_00-udp-naming.cpp
@@ -0,0 +1,54 @@
+/* Copyright (c) 2017, Stanislaw Halik <sthalik@misaki.pl>
+
+ * Permission to use, copy, modify, and/or distribute this
+ * software for any purpose with or without fee is hereby granted,
+ * provided that the above copyright notice and this permission
+ * notice appear in all copies.
+ */
+
+#include "migration.hpp"
+#include "options/options.hpp"
+#include "logic/main-settings.hpp"
+
+using namespace migrations;
+using namespace options;
+
+static const char* const old_tracker_name = "UDP sender";
+static const char* const old_proto_name = "UDP Tracker";
+
+static const char* const new_tracker_name = "UDP over network";
+static const char* const new_proto_name = "UDP over network";
+
+struct rename_udp_stuff : migration
+{
+ bool should_run() const override
+ {
+ module_settings s;
+ return s.protocol_dll == old_proto_name || s.tracker_dll == old_tracker_name;
+ }
+
+ void run() override
+ {
+ module_settings s;
+
+ if (s.protocol_dll == old_proto_name)
+ s.protocol_dll = new_proto_name;
+
+ if (s.tracker_dll == old_tracker_name)
+ s.tracker_dll = new_tracker_name;
+
+ s.b->save();
+ }
+
+ QString unique_date() const override
+ {
+ return "20170420_00";
+ }
+
+ QString name() const override
+ {
+ return "rename confusing UDP tracker/proto names";
+ }
+};
+
+OPENTRACK_MIGRATION(rename_udp_stuff)
diff --git a/migration/20171013_00-tracker-pt-threshold.cpp b/migration/20171013_00-tracker-pt-threshold.cpp
new file mode 100644
index 00000000..23f10659
--- /dev/null
+++ b/migration/20171013_00-tracker-pt-threshold.cpp
@@ -0,0 +1,52 @@
+/* Copyright (c) 2017, Stanislaw Halik <sthalik@misaki.pl>
+
+ * Permission to use, copy, modify, and/or distribute this
+ * software for any purpose with or without fee is hereby granted,
+ * provided that the above copyright notice and this permission
+ * notice appear in all copies.
+ */
+
+#include "migration.hpp"
+#include "options/options.hpp"
+//#include "tracker-pt/ftnoir_tracker_pt_settings.h"
+
+using namespace options;
+using namespace migrations;
+
+static const char* const old_name = "threshold-primary";
+static const char* const new_name = "threshold-slider";
+static const char* const bundle_name = "tracker-pt";
+
+struct move_int_to_slider : migration
+{
+ QString unique_date() const override
+ {
+ return "20171013_00";
+ }
+
+ QString name() const override
+ {
+ return "tracker/pt threshold slider (int -> slider_value)";
+ }
+
+ bool should_run() const override
+ {
+ bundle b = make_bundle(bundle_name);
+
+ return b->contains(old_name) && !b->contains(new_name);
+ }
+
+ void run() override
+ {
+ bundle b = make_bundle(bundle_name);
+
+ value<int> old_val(b, old_name, 128);
+ value<slider_value> new_val(b, new_name, { 128, 0, 255 });
+
+ new_val = { *old_val, 0, 255 };
+
+ b->save();
+ }
+};
+
+OPENTRACK_MIGRATION(move_int_to_slider)
diff --git a/migration/20171020_00-max-pitch-output.cpp b/migration/20171020_00-max-pitch-output.cpp
new file mode 100644
index 00000000..868bb5b8
--- /dev/null
+++ b/migration/20171020_00-max-pitch-output.cpp
@@ -0,0 +1,70 @@
+/* Copyright (c) 2017, Stanislaw Halik <sthalik@misaki.pl>
+
+ * Permission to use, copy, modify, and/or distribute this
+ * software for any purpose with or without fee is hereby granted,
+ * provided that the above copyright notice and this permission
+ * notice appear in all copies.
+ */
+
+#include "migration.hpp"
+#include "options/options.hpp"
+#include "logic/mappings.hpp"
+#include "logic/main-settings.hpp"
+
+#include <QString>
+
+using namespace options;
+using namespace migrations;
+
+struct max_pitch_output : migration
+{
+ max_pitch_output() = default;
+
+ QString unique_date() const override
+ {
+ return "20171020_00";
+ }
+
+ QString name() const override
+ {
+ return "max pitch output in mapping window";
+ }
+
+ bool should_run() const override
+ {
+ {
+ constexpr char const* name = "pitch-max-output-value";
+
+ bundle b = make_bundle("opentrack-mappings");
+
+ if (b->contains(name))
+ return false;
+ }
+
+ main_settings s;
+ Mappings m { s.all_axis_opts };
+
+ Map& pitch_map = m(Pitch);
+ spline& pitch_spline_1 = pitch_map.spline_main;
+ spline& pitch_spline_2 = pitch_map.spline_alt;
+
+ for (const spline& spl : { pitch_spline_1, pitch_spline_2 })
+ for (const QPointF& point : spl.get_points())
+ if (point.y() - 1e-2 > 90)
+ return true;
+
+ return false;
+ }
+
+ void run() override
+ {
+ main_settings s;
+ axis_opts& pitch_opts = s.a_pitch;
+
+ pitch_opts.clamp_y_ = axis_opts::o_r180;
+
+ s.b_map->save();
+ }
+};
+
+OPENTRACK_MIGRATION(max_pitch_output)
diff --git a/migration/20180102_00-process-detector-separator.cpp b/migration/20180102_00-process-detector-separator.cpp
new file mode 100644
index 00000000..3656bf73
--- /dev/null
+++ b/migration/20180102_00-process-detector-separator.cpp
@@ -0,0 +1,50 @@
+#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);
+ mark_global_ini_modified();
+ });
+ }
+};
+
+OPENTRACK_MIGRATION(process_detector_record_separator)
diff --git a/migration/20180118_00-reltrans.cpp b/migration/20180118_00-reltrans.cpp
new file mode 100644
index 00000000..09e3847e
--- /dev/null
+++ b/migration/20180118_00-reltrans.cpp
@@ -0,0 +1,44 @@
+#include "migration.hpp"
+#include "options/options.hpp"
+
+using namespace options;
+using namespace migrations;
+
+enum reltrans_state
+{
+ reltrans_disabled = 0,
+ reltrans_enabled = 1,
+ reltrans_non_center = 2,
+};
+
+static const char* old_name = "compensate-translation";
+static const char* new_name = "relative-translation-mode";
+
+struct reltrans_enum : migration
+{
+ QString unique_date() const override
+ {
+ return "20180118_00";
+ }
+
+ QString name() const override
+ {
+ return "reltrans modes";
+ }
+
+ bool should_run() const override
+ {
+ auto b = make_bundle("opentrack-ui");
+ return b->contains(old_name) && !b->contains(new_name);
+ }
+
+ void run() override
+ {
+ auto b = make_bundle("opentrack-ui");
+ bool value = b->get_variant(old_name).value<bool>();
+ b->store_kv(new_name, int(value ? reltrans_enabled : reltrans_disabled));
+ b->save();
+ }
+};
+
+OPENTRACK_MIGRATION(reltrans_enum)
diff --git a/migration/20180428_00-module-names.cpp b/migration/20180428_00-module-names.cpp
new file mode 100644
index 00000000..9558829f
--- /dev/null
+++ b/migration/20180428_00-module-names.cpp
@@ -0,0 +1,92 @@
+#include "migration.hpp"
+#include "options/options.hpp"
+
+using namespace migrations;
+using namespace options;
+
+#include "api/plugin-support.hpp"
+#include "compat/library-path.hpp"
+
+struct module_names : migration
+{
+ using dylib_ptr = Modules::dylib_ptr;
+ using dylib_list = Modules::dylib_list;
+
+ struct module_type {
+ QString name, def;
+ dylib_list const& list;
+ };
+
+ Modules m { OPENTRACK_BASE_PATH + OPENTRACK_LIBRARY_PATH, dylib_load_quiet };
+
+ module_type types[3] {
+ { "tracker-dll", "pt", m.trackers() },
+ { "protocol-dll", "freetrack", m.protocols() },
+ { "filter-dll", "accela", m.filters() },
+ };
+
+ bundle b { make_bundle("modules") };
+
+ QString unique_date() const override
+ {
+ return "20180428_00";
+ }
+
+ QString name() const override
+ {
+ return "module names";
+ }
+
+ bool should_run() const override
+ {
+ for (const module_type& type : types)
+ {
+ if (!b->contains(type.name))
+ continue;
+
+ const QString value = b->get_variant(type.name).value<QString>();
+
+ for (const dylib_ptr& lib : type.list)
+ {
+ if (value == lib->name && value != lib->module_name)
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ void run() override
+ {
+ for (module_type& type : types)
+ {
+ if (!b->contains(type.name))
+ continue;
+
+ const QString value = b->get_variant(type.name).value<QString>();
+
+ bool found = false;
+
+ for (const dylib_ptr& lib : type.list)
+ {
+ if (value == lib->name && value != lib->module_name)
+ {
+ qDebug() << type.name << value << "=>" << lib->module_name;
+ b->store_kv(type.name, lib->module_name);
+ found = true;
+ break;
+ }
+ }
+
+ if (!found)
+ {
+ qDebug() << type.name << value << "not found";
+ b->store_kv(type.name, QVariant());
+ }
+ }
+
+ b->save();
+ }
+};
+
+OPENTRACK_MIGRATION(module_names)
diff --git a/migration/20220105_00-pt-grayscale.cpp b/migration/20220105_00-pt-grayscale.cpp
new file mode 100644
index 00000000..44bdc470
--- /dev/null
+++ b/migration/20220105_00-pt-grayscale.cpp
@@ -0,0 +1,38 @@
+#include "migration.hpp"
+#include "options/options.hpp"
+
+using namespace migrations;
+using namespace options;
+
+#include "api/plugin-support.hpp"
+#include "compat/library-path.hpp"
+
+struct pt_color_grayscale : migration
+{
+ bundle b { make_bundle("tracker-pt") };
+ enum : int { pt_color_average = 5, pt_color_bt709 = 2, };
+
+ QString unique_date() const override
+ {
+ return "20220105_00";
+ }
+
+ QString name() const override
+ {
+ return "pt color enum";
+ }
+
+ bool should_run() const override
+ {
+ auto x = b->get_variant("blob-color").toInt();
+ return x == pt_color_average;
+ }
+
+ void run() override
+ {
+ b->store_kv("blob-color", QVariant::fromValue((int)pt_color_bt709));
+ b->save();
+ }
+};
+
+OPENTRACK_MIGRATION(pt_color_grayscale)
diff --git a/migration/20220126_00-camera-name.cpp b/migration/20220126_00-camera-name.cpp
new file mode 100644
index 00000000..adb6d718
--- /dev/null
+++ b/migration/20220126_00-camera-name.cpp
@@ -0,0 +1,79 @@
+#ifdef _WIN32
+#include "migration.hpp"
+#include "options/options.hpp"
+#include "compat/camera-names.hpp"
+
+using namespace migrations;
+using namespace options;
+
+#include "api/plugin-support.hpp"
+#include "compat/library-path.hpp"
+#include <tuple>
+#include <QString>
+
+static const std::tuple<const char*, const char*> modules[] = {
+ { "tracker-aruco", "camera-name" },
+ { "tracker-easy", "camera-name" },
+ { "neuralnet-tracker", "camera-name" },
+ { "tracker-pt", "camera-name" },
+};
+
+struct win32_camera_name : migration
+{
+ QString unique_date() const override
+ {
+ return "20220126_00";
+ }
+
+ QString name() const override
+ {
+ return "camera name";
+ }
+
+ bool should_run() const override
+ {
+ for (const auto& [name, prop] : modules)
+ {
+ bundle b { make_bundle(name) };
+ QString str = b->get_variant(prop).toString();
+ if (!str.isEmpty() && !str.contains(" ["))
+ return true;
+ }
+ return false;
+ }
+
+ void run() override
+ {
+ auto cameras = get_camera_names();
+
+ for (const auto& [bundle_name, prop] : modules)
+ {
+ bundle b { make_bundle(bundle_name) };
+ QString name = b->get_variant(prop).toString();
+ if (name.isEmpty() || name.contains(" ["))
+ continue;
+ auto full_name_of = [&](const QString& str) {
+ QString ret = str;
+ auto prefix = str + " [";
+ for (const auto& [x, _] : cameras)
+ {
+ if (x == str)
+ return str;
+ if (x.startsWith(prefix))
+ ret = x;
+ }
+ return ret;
+ };
+ auto full_name = full_name_of(name);
+ if (name != full_name)
+ {
+ b->store_kv(prop, full_name);
+ b->save();
+ }
+ }
+ }
+};
+
+OPENTRACK_MIGRATION(win32_camera_name)
+
+#endif
diff --git a/migration/CMakeLists.txt b/migration/CMakeLists.txt
index 9a7f7dc9..effeddcb 100644
--- a/migration/CMakeLists.txt
+++ b/migration/CMakeLists.txt
@@ -1,2 +1,5 @@
otr_module(migration BIN)
-target_link_libraries(opentrack-migration opentrack-logic opentrack-spline)
+target_link_libraries(${self} opentrack-logic opentrack-spline)
+if(CMAKE_COMPILER_IS_CLANGXX)
+ target_compile_options(${self} PRIVATE -Wno-weak-vtables)
+endif()
diff --git a/migration/lang/de_DE.ts b/migration/lang/de_DE.ts
new file mode 100644
index 00000000..1552582e
--- /dev/null
+++ b/migration/lang/de_DE.ts
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.1" language="de_DE">
+</TS>
diff --git a/migration/lang/zh_CN.ts b/migration/lang/zh_CN.ts
new file mode 100644
index 00000000..e5ca8aa9
--- /dev/null
+++ b/migration/lang/zh_CN.ts
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.1" language="zh_CN">
+</TS>
diff --git a/migration/migration.cpp b/migration/migration.cpp
index bb8386fc..f4b1739b 100644
--- a/migration/migration.cpp
+++ b/migration/migration.cpp
@@ -11,7 +11,6 @@
#include "migration.hpp"
#include "options/options.hpp"
-#include "compat/util.hpp"
#include <QString>
#include <QSettings>
@@ -21,17 +20,31 @@
#include <memory>
+using namespace options::globals;
+
// individual migrations are run in the UI thread. they can be interactive if necessary.
-namespace migrations {
+namespace migrations::detail {
+
+
+std::vector<mptr>& migrator::migration_list()
+{
+ static std::vector<mptr> v;
+ return v;
+}
+
+std::vector<mfun>& migrator::migration_thunks()
+{
+ static std::vector<mfun> v;
+ return v;
+}
-namespace detail {
-void migrator::register_migration(migration* m)
+void migrator::register_migration(mptr const& m)
{
const QString date = m->unique_date();
- for (migration* m2 : migrations())
+ for (mptr const& m2 : migration_list())
if (m2->unique_date() == date)
std::abort();
@@ -48,15 +61,13 @@ void migrator::register_migration(migration* m)
bool ok = true;
- if (year < "2016")
- abort();
-
- const int month_ = to_int(month, ok), day_ = to_int(day, ok);
+ const int year_ = to_int(year, ok),
+ month_ = to_int(month, ok),
+ day_ = to_int(day, ok);
- (void) to_int(year, ok);
- (void) to_int(serial, ok);
+ (void)to_int(serial, ok);
- if (!ok)
+ if (!ok || year_ < 1970)
abort();
if (month_ < 1 || month_ > 12)
@@ -65,33 +76,58 @@ void migrator::register_migration(migration* m)
if (day_ < 1 || day_ > 31)
abort();
- migrations().push_back(m);
+ migration_list().push_back(m);
}
-std::vector<migration*>& migrator::migrations()
+void migrator::eval_thunks()
{
- static std::vector<migration*> ret;
- return ret;
+ for (auto& fun : migration_thunks())
+ {
+ mptr m = fun();
+ register_migration(m);
+ }
+ if (!migration_thunks().empty())
+ sort_migrations();
+ migration_thunks().clear();
+}
+
+void migrator::add_migration_thunk(mfun& thunk)
+{
+ migration_thunks().push_back(thunk);
+}
+
+std::vector<mptr>& migrator::migrations()
+{
+ eval_thunks();
+ return migration_list();
+}
+
+void migrator::sort_migrations()
+{
+ std::sort(migration_list().begin(), migration_list().end(),
+ [](const mptr x, const mptr y) {
+ return x->unique_date() < y->unique_date();
+ });
}
QString migrator::last_migration_time()
{
QString ret;
- std::shared_ptr<QSettings> s(options::group::ini_file());
-
- s->beginGroup("migrations");
- ret = s->value("last-migration-at", "19700101_00").toString();
- s->endGroup();
+ with_settings_object([&](QSettings& s) {
+ s.beginGroup("migrations");
+ ret = s.value("last-migration-at", "19700101_00").toString();
+ s.endGroup();
+ });
return ret;
}
QString migrator::time_after_migrations()
{
- const std::vector<migration*> list = sorted_migrations();
+ const std::vector<mptr>& list = migrations();
- if (list.size() == 0u)
+ if (list.empty())
return QStringLiteral("19700101_00");
QString ret = list[list.size() - 1]->unique_date();
@@ -102,21 +138,16 @@ QString migrator::time_after_migrations()
void migrator::set_last_migration_time(const QString& val)
{
- std::shared_ptr<QSettings> s(options::group::ini_file());
-
- s->beginGroup("migrations");
- s->setValue("last-migration-at", val);
- s->endGroup();
-}
-
-std::vector<migration*> migrator::sorted_migrations()
-{
- std::vector<migration*> list(migrations());
-
- using mm = migration*;
-
- std::sort(list.begin(), list.end(), [](const mm x, const mm y) { return x->unique_date() < y->unique_date(); });
- return list;
+ with_settings_object([&](QSettings& s) {
+ s.beginGroup("migrations");
+ const QString old_value = s.value("last-migration-at", "").toString();
+ if (val != old_value)
+ {
+ s.setValue("last-migration-at", val);
+ options::globals::detail::mark_ini_modified();
+ }
+ s.endGroup();
+ });
}
int migrator::to_int(const QString& str, bool& ok)
@@ -129,61 +160,55 @@ int migrator::to_int(const QString& str, bool& ok)
std::vector<QString> migrator::run()
{
- std::vector<migration*> migrations = sorted_migrations();
std::vector<QString> done;
const QString last_migration = last_migration_time();
- for (migration* m_ : migrations)
- {
- migration& m(*m_);
-
- const QString date = m.unique_date();
-
- if (date <= last_migration)
- continue;
-
- if (m.should_run())
+ with_settings_object([&](QSettings&) {
+ for (mptr const& m : migrations())
{
- m.run();
- done.push_back(m.name());
+ const QString date = m->unique_date();
+
+ if (date <= last_migration)
+ continue;
+
+ if (m->should_run())
+ {
+ const QByteArray name = m->name().toUtf8();
+ const QByteArray date = m->unique_date().toUtf8();
+ qDebug() << "migrate:" << date.constData() << name.constData();
+ m->run();
+ done.push_back(m->name());
+ }
}
- }
-
- mark_config_as_not_needing_migration();
-
- if (done.size())
- {
- for (const QString& name : done)
- {
- const QByteArray data = name.toUtf8();
- qDebug() << "migrate:" << data.constData();
- }
- }
+ mark_profile_as_not_needing_migration();
+ });
return done;
}
-}
+} // ns migrations::detail
+
+namespace migrations {
-migration::migration() {}
-migration::~migration() {}
+migration::migration() = default;
+migration::~migration() = default;
-} // ns
+} // ns migrations
std::vector<QString> run_migrations()
{
return migrations::detail::migrator::run();
}
-void mark_config_as_not_needing_migration()
+void mark_profile_as_not_needing_migration()
{
using m = migrations::detail::migrator;
- m::mark_config_as_not_needing_migration();
+ m::mark_profile_as_not_needing_migration();
}
-void migrations::detail::migrator::mark_config_as_not_needing_migration()
+void migrations::detail::migrator::mark_profile_as_not_needing_migration()
{
set_last_migration_time(time_after_migrations());
}
diff --git a/migration/migration.hpp b/migration/migration.hpp
index 5f99de7a..7fc18c97 100644
--- a/migration/migration.hpp
+++ b/migration/migration.hpp
@@ -9,29 +9,43 @@
#pragma once
#include <QString>
-#include <vector>
-
#include "export.hpp"
+#include <memory>
+#include <vector>
+#include <functional>
+
namespace migrations {
-class migration;
+struct migration;
class registrator;
namespace detail {
- class migrator final
+ using mptr = std::shared_ptr<migration>;
+ using mfun = std::function<mptr ()>;
+
+ struct migrator
{
- static std::vector<migration*>& migrations();
+ static std::vector<QString> run();
+ static void add_migration_thunk(std::function<mptr()>& thunk);
+ static void mark_profile_as_not_needing_migration();
+
+ private:
+ static void sort_migrations();
+
+ static void register_migration(const mptr& m);
+ static std::vector<mptr>& migrations();
+
+ static void eval_thunks();
+
static QString last_migration_time();
static QString time_after_migrations();
+
static void set_last_migration_time(const QString& val);
- migrator() = delete;
- static std::vector<migration*> sorted_migrations();
static int to_int(const QString& str, bool& ok);
- public:
- static std::vector<QString> run();
- static void register_migration(migration* m);
- static void mark_config_as_not_needing_migration();
+
+ static std::vector<mptr>& migration_list();
+ static std::vector<mfun>& migration_thunks();
};
template<typename t>
@@ -39,31 +53,28 @@ namespace detail {
{
registrator()
{
- static t m;
- migrator::register_migration(static_cast<migration*>(&m));
+ mfun f { [] { return std::shared_ptr<migration>(new t); } };
+
+ migrator::add_migration_thunk(f);
}
};
}
-#ifndef __COUNTER__
-# error "oops, need __COUNTER__ extension for preprocessor"
-#endif
+#define OPENTRACK_MIGRATION3(type, ctr) \
+ static const char init_##ctr = (::migrations::detail::registrator<type>{}, 0);
-#define OPENTRACK_MIGRATION(type) static ::migrations::detail::registrator<type> opentrack_migration_registrator__ ## __COUNTER__ ## _gensym
+#define OPENTRACK_MIGRATION2(type, ctr) \
+ OPENTRACK_MIGRATION3(type, ctr)
-#ifdef Q_CREATOR_RUN
-# pragma clang diagnostic ignored "-Wweak-vtables"
-#endif
+#define OPENTRACK_MIGRATION(type) \
+ OPENTRACK_MIGRATION2(type, __COUNTER__)
-class migration
+struct migration
{
- migration& operator=(const migration&) = delete;
+ migration();
migration(const migration&) = delete;
- migration& operator=(migration&&) = delete;
- migration(migration&&) = delete;
+ migration& operator=(const migration&) = delete;
-public:
- migration();
virtual ~migration();
virtual QString unique_date() const = 0;
virtual QString name() const = 0;
@@ -71,7 +82,7 @@ public:
virtual void run() = 0;
};
-}
+} // ns migrations
OTR_MIGRATION_EXPORT std::vector<QString> run_migrations();
-OTR_MIGRATION_EXPORT void mark_config_as_not_needing_migration();
+OTR_MIGRATION_EXPORT void mark_profile_as_not_needing_migration();