From 884a008333a1567355db960c3effc72795420b81 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 9 Aug 2026 00:06:06 +0200 Subject: [PATCH] Fix Setup --- Tactility/Source/app/setup/Setup.cpp | 34 ++++++++++---------------- TactilityKernel/source/preferences.cpp | 9 ++++++- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/Tactility/Source/app/setup/Setup.cpp b/Tactility/Source/app/setup/Setup.cpp index 0998163d7..1a0ca97e1 100644 --- a/Tactility/Source/app/setup/Setup.cpp +++ b/Tactility/Source/app/setup/Setup.cpp @@ -1,7 +1,9 @@ #include + #include #include #include +#include #include #include @@ -10,8 +12,8 @@ #include +#include #include -#include #include #include @@ -32,17 +34,16 @@ namespace tt::app::setup { extern const ::AppManifest manifest; -constexpr auto* PREFERENCES_NAMESPACE = "setup"; -constexpr auto* PREFERENCES_KEY_COMPLETED = "completed"; +constexpr auto* TAG = "setup"; namespace { -bool getPreferencesPath(std::string& outPath) { +bool getCompletedMarkerPath(std::string& outPath) { char root[128]; if (paths_get_user_data_path(root, sizeof(root)) != ERROR_NONE) { return false; } - outPath = std::string(root) + "/" + PREFERENCES_NAMESPACE + ".properties"; + outPath = std::string(root) + "/.setup_complete"; return true; } @@ -50,32 +51,23 @@ bool getPreferencesPath(std::string& outPath) { bool isCompleted() { std::string path; - if (!getPreferencesPath(path)) { + if (!getCompletedMarkerPath(path)) { + LOG_E(TAG, "Setup path not found"); return false; } - Preferences* preferences = preferences_open(path.c_str()); - if (preferences == nullptr) { - return false; - } - bool completed = false; - preferences_opt_bool(preferences, PREFERENCES_KEY_COMPLETED, &completed); - preferences_close(preferences); - return completed; + file::FileMutexGuard guard(path); + return file::isFile(path); } namespace { void markCompleted() { std::string path; - if (!getPreferencesPath(path)) { + if (!getCompletedMarkerPath(path)) { return; } - Preferences* preferences = preferences_open(path.c_str()); - if (preferences == nullptr) { - return; - } - preferences_put_bool(preferences, PREFERENCES_KEY_COMPLETED, true); - preferences_close(preferences); + file::FileMutexGuard guard(path); + file::writeString(path, ""); } enum class Phase { diff --git a/TactilityKernel/source/preferences.cpp b/TactilityKernel/source/preferences.cpp index 555b36f78..46af00f2d 100644 --- a/TactilityKernel/source/preferences.cpp +++ b/TactilityKernel/source/preferences.cpp @@ -1,7 +1,9 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include + +#include #include +#include #include #include @@ -15,6 +17,8 @@ namespace { +constexpr auto* TAG = "preferences"; + // Escapes '\\' and '\n' so a string value can never break properties_file's one-entry-per-line // on-disk format, regardless of its content. std::string escape(const std::string& value) { @@ -176,16 +180,19 @@ extern "C" { Preferences* preferences_open(const char* path) { std::string directory = parent_directory(path); if (!directory.empty() && !ensure_directory_recursive(directory)) { + LOG_E(TAG, "Directory not found: %s", directory.c_str()); return nullptr; } PropertiesFile* file = properties_file_open(path); if (file == nullptr) { + LOG_E(TAG, "Failed to open %s", path); return nullptr; } auto* preferences = new (std::nothrow) Preferences { file }; if (preferences == nullptr) { + LOG_E(TAG, "Out of memory"); properties_file_close(file); return nullptr; }