diff options
-rw-r--r-- | logic/state.cpp | 3 | ||||
-rw-r--r-- | logic/state.hpp | 1 | ||||
-rw-r--r-- | opentrack/main-window.cpp | 34 | ||||
-rw-r--r-- | opentrack/main-window.hpp | 1 |
4 files changed, 34 insertions, 5 deletions
diff --git a/logic/state.cpp b/logic/state.cpp index 8218e5c3..dc5e5a36 100644 --- a/logic/state.cpp +++ b/logic/state.cpp @@ -22,7 +22,8 @@ std::tuple<dylib_ptr, int> State::module_by_name(const QString& name, dylib_list State::State(const QString& library_path) : modules(library_path), - pose(s.all_axis_opts) + pose(s.all_axis_opts), + library_path{library_path} {} dylib_ptr State::current_tracker() diff --git a/logic/state.hpp b/logic/state.hpp index 809ca458..7fc06a5c 100644 --- a/logic/state.hpp +++ b/logic/state.hpp @@ -35,4 +35,5 @@ struct OTR_LOGIC_EXPORT State module_settings m; Mappings pose; std::shared_ptr<Work> work; + QString library_path; }; diff --git a/opentrack/main-window.cpp b/opentrack/main-window.cpp index ed1db357..38fd1ed7 100644 --- a/opentrack/main-window.cpp +++ b/opentrack/main-window.cpp @@ -320,7 +320,8 @@ void main_window::create_empty_profile() QString name; if (profile_name_from_dialog(name)) { - QFile(ini_combine(name)).open(QFile::ReadWrite); + if (!maybe_profile_from_preset(name)) + (void)QFile(ini_combine(name)).open(QFile::ReadWrite); refresh_profile_list(); if (profile_list.contains(name)) @@ -784,10 +785,11 @@ void main_window::set_profile(const QString& new_name_, bool migrate) QString new_name = new_name_; - if (!profile_list.contains(new_name)) + if (!profile_list.contains(new_name_)) { - new_name = OPENTRACK_DEFAULT_PROFILE; - if (!profile_list.contains(new_name)) + new_name = QStringLiteral(OPENTRACK_DEFAULT_PROFILE); + if ((migrate && !maybe_profile_from_preset(new_name)) && + !profile_list.contains(new_name)) migrate = false; } @@ -1002,6 +1004,30 @@ void main_window::toggle_tracker_() start_tracker_(); } +bool main_window::maybe_profile_from_preset(const QString& name_) +{ + const QString& default_name = QStringLiteral(OPENTRACK_DEFAULT_PROFILE); + const QString* name_ptr = &name_; + if (name_.isEmpty()) + name_ptr = &default_name; + const QString dest = ini_combine(*name_ptr); + if (QFile::exists(dest)) + return false; + + for (const QString& filename : { *name_ptr, default_name }) + { + QString file = (library_path + "/presets/%1").arg(filename); + if (QFile::exists(file)) + { + bool ret = QFile::copy(file, dest); + if (ret) + qDebug() << "create profile" << *name_ptr << "from preset" << file; + return ret; + } + } + return false; +} + #if !defined _WIN32 # include <unistd.h> void main_window::annoy_if_root() diff --git a/opentrack/main-window.hpp b/opentrack/main-window.hpp index 495300c1..e1724a9d 100644 --- a/opentrack/main-window.hpp +++ b/opentrack/main-window.hpp @@ -118,6 +118,7 @@ public: void restart_tracker_(); void toggle_tracker_(); + [[nodiscard]] bool maybe_profile_from_preset(const QString& name); void set_profile(const QString& new_name, bool migrate = true); void set_profile_in_registry(const QString& profile); void refresh_profile_list(); |