diff options
Diffstat (limited to 'migration')
-rw-r--r-- | migration/20220105_00-pt-grayscale.cpp | 38 | ||||
-rw-r--r-- | migration/20220126_00-camera-name.cpp | 79 | ||||
-rw-r--r-- | migration/CMakeLists.txt | 2 | ||||
-rw-r--r-- | migration/lang/de_DE.ts | 4 | ||||
-rw-r--r-- | migration/lang/zh_CN.ts | 2 | ||||
-rw-r--r-- | migration/migration.cpp | 31 | ||||
-rw-r--r-- | migration/migration.hpp | 3 |
7 files changed, 147 insertions, 12 deletions
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 b2dfac6d..effeddcb 100644 --- a/migration/CMakeLists.txt +++ b/migration/CMakeLists.txt @@ -1,5 +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 index 6401616d..e5ca8aa9 100644 --- a/migration/lang/zh_CN.ts +++ b/migration/lang/zh_CN.ts @@ -1,4 +1,4 @@ <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE TS> -<TS version="2.1"> +<TS version="2.1" language="zh_CN"> </TS> diff --git a/migration/migration.cpp b/migration/migration.cpp index 4ddb2c8c..f4b1739b 100644 --- a/migration/migration.cpp +++ b/migration/migration.cpp @@ -26,14 +26,25 @@ using namespace options::globals; namespace migrations::detail { -static std::vector<mptr> migration_list; -static std::vector<mfun> migration_thunks; + +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; +} + void migrator::register_migration(mptr const& m) { const QString date = m->unique_date(); - for (mptr const& m2 : migration_list) + for (mptr const& m2 : migration_list()) if (m2->unique_date() == date) std::abort(); @@ -65,35 +76,35 @@ void migrator::register_migration(mptr const& m) if (day_ < 1 || day_ > 31) abort(); - migration_list.push_back(m); + migration_list().push_back(m); } void migrator::eval_thunks() { - for (auto& fun : migration_thunks) + for (auto& fun : migration_thunks()) { mptr m = fun(); register_migration(m); } - if (!migration_thunks.empty()) + if (!migration_thunks().empty()) sort_migrations(); - migration_thunks.clear(); + migration_thunks().clear(); } void migrator::add_migration_thunk(mfun& thunk) { - migration_thunks.push_back(thunk); + migration_thunks().push_back(thunk); } std::vector<mptr>& migrator::migrations() { eval_thunks(); - return migration_list; + return migration_list(); } void migrator::sort_migrations() { - std::sort(migration_list.begin(), migration_list.end(), + std::sort(migration_list().begin(), migration_list().end(), [](const mptr x, const mptr y) { return x->unique_date() < y->unique_date(); }); diff --git a/migration/migration.hpp b/migration/migration.hpp index a3035247..7fc18c97 100644 --- a/migration/migration.hpp +++ b/migration/migration.hpp @@ -43,6 +43,9 @@ namespace detail { static void set_last_migration_time(const QString& val); static int to_int(const QString& str, bool& ok); + + static std::vector<mptr>& migration_list(); + static std::vector<mfun>& migration_thunks(); }; template<typename t> |