From 3fa5061f47d1c5eb9545f1644cc6bd08f38f0a17 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 9 Sep 2016 18:33:14 +0200 Subject: migration: add axis sign migration from rc10 --- migration/20160906_1-axis-signs.cpp | 72 +++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) (limited to 'migration') diff --git a/migration/20160906_1-axis-signs.cpp b/migration/20160906_1-axis-signs.cpp index 2146e253..7cf0c719 100644 --- a/migration/20160906_1-axis-signs.cpp +++ b/migration/20160906_1-axis-signs.cpp @@ -1 +1,73 @@ // TODO XXX write migration for axis sign going to mappings bundle + +#include "migration.hpp" +#include "options/options.hpp" +#include "logic/main-settings.hpp" + +#include +#include + +using namespace options; +using namespace migrations; + +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"; + } + + QString name() const override + { + return "asymmetric axis sign to another .ini section"; + } + + bool should_run() const override + { + 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; + } + + void run() override + { + 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(fmt.arg(name)))); + + new_bundle->save(); + } +}; + +const char* axis_signs_split_rc11::axis_names[] = +{ + "yaw", "pitch", "roll", + "x", "y", "z", +}; + +const QString axis_signs_split_rc11::fmt = QStringLiteral("%1-alt-axis-sign"); + +OPENTRACK_MIGRATION(axis_signs_split_rc11); -- cgit v1.2.3