mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-08-17 23:55:04 +00:00
Fix Setup
This commit is contained in:
parent
e618086590
commit
884a008333
@ -1,7 +1,9 @@
|
|||||||
#include <Tactility/app/setup/Setup.h>
|
#include <Tactility/app/setup/Setup.h>
|
||||||
|
|
||||||
#include <Tactility/StringUtils.h>
|
#include <Tactility/StringUtils.h>
|
||||||
#include <Tactility/app/timezone/TimeZone.h>
|
#include <Tactility/app/timezone/TimeZone.h>
|
||||||
#include <Tactility/app/wifimanage/WifiManage.h>
|
#include <Tactility/app/wifimanage/WifiManage.h>
|
||||||
|
#include <Tactility/file/File.h>
|
||||||
#include <Tactility/service/wifi/Wifi.h>
|
#include <Tactility/service/wifi/Wifi.h>
|
||||||
|
|
||||||
#include <app/event.h>
|
#include <app/event.h>
|
||||||
@ -10,8 +12,8 @@
|
|||||||
|
|
||||||
#include <lvgl_window_manager/window_manager.h>
|
#include <lvgl_window_manager/window_manager.h>
|
||||||
|
|
||||||
|
#include <tactility/log.h>
|
||||||
#include <tactility/paths.h>
|
#include <tactility/paths.h>
|
||||||
#include <tactility/preferences.h>
|
|
||||||
|
|
||||||
#include <lvgl/fonts.h>
|
#include <lvgl/fonts.h>
|
||||||
#include <lvgl/lvgl.h>
|
#include <lvgl/lvgl.h>
|
||||||
@ -32,17 +34,16 @@ namespace tt::app::setup {
|
|||||||
|
|
||||||
extern const ::AppManifest manifest;
|
extern const ::AppManifest manifest;
|
||||||
|
|
||||||
constexpr auto* PREFERENCES_NAMESPACE = "setup";
|
constexpr auto* TAG = "setup";
|
||||||
constexpr auto* PREFERENCES_KEY_COMPLETED = "completed";
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
bool getPreferencesPath(std::string& outPath) {
|
bool getCompletedMarkerPath(std::string& outPath) {
|
||||||
char root[128];
|
char root[128];
|
||||||
if (paths_get_user_data_path(root, sizeof(root)) != ERROR_NONE) {
|
if (paths_get_user_data_path(root, sizeof(root)) != ERROR_NONE) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
outPath = std::string(root) + "/" + PREFERENCES_NAMESPACE + ".properties";
|
outPath = std::string(root) + "/.setup_complete";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -50,32 +51,23 @@ bool getPreferencesPath(std::string& outPath) {
|
|||||||
|
|
||||||
bool isCompleted() {
|
bool isCompleted() {
|
||||||
std::string path;
|
std::string path;
|
||||||
if (!getPreferencesPath(path)) {
|
if (!getCompletedMarkerPath(path)) {
|
||||||
|
LOG_E(TAG, "Setup path not found");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Preferences* preferences = preferences_open(path.c_str());
|
file::FileMutexGuard guard(path);
|
||||||
if (preferences == nullptr) {
|
return file::isFile(path);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
bool completed = false;
|
|
||||||
preferences_opt_bool(preferences, PREFERENCES_KEY_COMPLETED, &completed);
|
|
||||||
preferences_close(preferences);
|
|
||||||
return completed;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void markCompleted() {
|
void markCompleted() {
|
||||||
std::string path;
|
std::string path;
|
||||||
if (!getPreferencesPath(path)) {
|
if (!getCompletedMarkerPath(path)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Preferences* preferences = preferences_open(path.c_str());
|
file::FileMutexGuard guard(path);
|
||||||
if (preferences == nullptr) {
|
file::writeString(path, "");
|
||||||
return;
|
|
||||||
}
|
|
||||||
preferences_put_bool(preferences, PREFERENCES_KEY_COMPLETED, true);
|
|
||||||
preferences_close(preferences);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class Phase {
|
enum class Phase {
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
#include <tactility/preferences.h>
|
#include <tactility/preferences.h>
|
||||||
#include <tactility/properties_file.h>
|
|
||||||
|
#include <tactility/log.h>
|
||||||
#include <tactility/paths.h>
|
#include <tactility/paths.h>
|
||||||
|
#include <tactility/properties_file.h>
|
||||||
|
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
@ -15,6 +17,8 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
constexpr auto* TAG = "preferences";
|
||||||
|
|
||||||
// Escapes '\\' and '\n' so a string value can never break properties_file's one-entry-per-line
|
// Escapes '\\' and '\n' so a string value can never break properties_file's one-entry-per-line
|
||||||
// on-disk format, regardless of its content.
|
// on-disk format, regardless of its content.
|
||||||
std::string escape(const std::string& value) {
|
std::string escape(const std::string& value) {
|
||||||
@ -176,16 +180,19 @@ extern "C" {
|
|||||||
Preferences* preferences_open(const char* path) {
|
Preferences* preferences_open(const char* path) {
|
||||||
std::string directory = parent_directory(path);
|
std::string directory = parent_directory(path);
|
||||||
if (!directory.empty() && !ensure_directory_recursive(directory)) {
|
if (!directory.empty() && !ensure_directory_recursive(directory)) {
|
||||||
|
LOG_E(TAG, "Directory not found: %s", directory.c_str());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
PropertiesFile* file = properties_file_open(path);
|
PropertiesFile* file = properties_file_open(path);
|
||||||
if (file == nullptr) {
|
if (file == nullptr) {
|
||||||
|
LOG_E(TAG, "Failed to open %s", path);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto* preferences = new (std::nothrow) Preferences { file };
|
auto* preferences = new (std::nothrow) Preferences { file };
|
||||||
if (preferences == nullptr) {
|
if (preferences == nullptr) {
|
||||||
|
LOG_E(TAG, "Out of memory");
|
||||||
properties_file_close(file);
|
properties_file_close(file);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user