diff --git a/Tactility/Include/Tactility/DeprecatedPaths.h b/Tactility/Include/Tactility/DeprecatedPaths.h index 06532f69d..0dd21432c 100644 --- a/Tactility/Include/Tactility/DeprecatedPaths.h +++ b/Tactility/Include/Tactility/DeprecatedPaths.h @@ -15,7 +15,7 @@ FileSystem* findSdcardFileSystem(bool mustBeMounted); std::string getUserDataRootPath(); -std::string getUserDataPath(); +std::string getDataPath(); std::string getTempPath(); diff --git a/Tactility/Source/DeprecatedPaths.cpp b/Tactility/Source/DeprecatedPaths.cpp index 68d2782d3..5aa78fac7 100644 --- a/Tactility/Source/DeprecatedPaths.cpp +++ b/Tactility/Source/DeprecatedPaths.cpp @@ -51,7 +51,7 @@ std::string getUserDataRootPath() { #endif } -std::string getUserDataPath() { +std::string getDataPath() { #ifdef ESP_PLATFORM return getUserDataRootPath() + "/tactility"; #else @@ -60,15 +60,15 @@ std::string getUserDataPath() { } std::string getTempPath() { - return getUserDataPath() + "/tmp"; + return getDataPath() + "/tmp"; } std::string getAppInstallPath() { - return getUserDataPath() + "/app"; + return getDataPath() + "/app"; } std::string getUserHomePath() { - return getUserDataPath() + "/user"; + return getDataPath() + "/user"; } std::string getAppInstallPath(const std::string& appId) { diff --git a/Tactility/Source/Tactility.cpp b/Tactility/Source/Tactility.cpp index d2e239edd..d28d32705 100644 --- a/Tactility/Source/Tactility.cpp +++ b/Tactility/Source/Tactility.cpp @@ -318,7 +318,7 @@ static void registerAndStartServices() { } void createTempDirectory() { - auto data_path = getUserDataPath(); + auto data_path = getDataPath(); auto temp_path = std::format("{}/tmp", data_path); if (!file::isDirectory(temp_path)) { FileMutex mutex; diff --git a/Tactility/Source/bluetooth/BluetoothPairedDevice.cpp b/Tactility/Source/bluetooth/BluetoothPairedDevice.cpp index fccc67022..ad762aed1 100644 --- a/Tactility/Source/bluetooth/BluetoothPairedDevice.cpp +++ b/Tactility/Source/bluetooth/BluetoothPairedDevice.cpp @@ -25,7 +25,7 @@ constexpr auto* KEY_AUTO_CONNECT = "autoConnect"; constexpr auto* KEY_PROFILE_ID = "profileId"; static std::string getSettingsFilePath() { - return getUserDataPath() + "/service/bluetooth"; + return getDataPath() + "/service/bluetooth"; } std::string addrToHex(const std::array& addr) { diff --git a/Tactility/Source/bluetooth/BluetoothSettings.cpp b/Tactility/Source/bluetooth/BluetoothSettings.cpp index d2640a16d..cd599b992 100644 --- a/Tactility/Source/bluetooth/BluetoothSettings.cpp +++ b/Tactility/Source/bluetooth/BluetoothSettings.cpp @@ -11,7 +11,7 @@ namespace tt::bluetooth::settings { constexpr auto* TAG = "BluetoothSettings"; static std::string getSettingsPath() { - return getUserDataPath() + "/settings/bluetooth.settings"; + return getDataPath() + "/settings/bluetooth.properties"; } constexpr auto* KEY_ENABLE_ON_BOOT = "enableOnBoot"; diff --git a/Tactility/Source/network/Ntp.cpp b/Tactility/Source/network/Ntp.cpp index e1ab0dae3..2e81d94c8 100644 --- a/Tactility/Source/network/Ntp.cpp +++ b/Tactility/Source/network/Ntp.cpp @@ -1,5 +1,3 @@ -#include - #include #include @@ -24,11 +22,10 @@ static bool processedSyncEvent = false; static bool getPreferencesPath(std::string& outPath) { char root[128]; - // Not really a service, but this is the best way of organising it for now - if (service_paths_get_user_data_directory("tactility.ntp", root, sizeof(root)) != ERROR_NONE) { + if (paths_get_data_path(root, sizeof(root)) != ERROR_NONE) { return false; } - outPath = std::string(root) + "/time.properties"; + outPath = std::string(root) + "/settings/ntp.properties"; return true; } diff --git a/Tactility/Source/service/webserver/WebServerService.cpp b/Tactility/Source/service/webserver/WebServerService.cpp index f8b21de17..69ab1c778 100644 --- a/Tactility/Source/service/webserver/WebServerService.cpp +++ b/Tactility/Source/service/webserver/WebServerService.cpp @@ -1450,7 +1450,7 @@ esp_err_t WebServerService::handleApiScreenshot(httpd_req_t* request) { #if TT_FEATURE_SCREENSHOT_ENABLED // Determine save location: prefer SD card root if mounted, otherwise /data - std::string save_path = getUserDataPath(); + std::string save_path = getDataPath(); // Find next available filename with incrementing number std::string screenshot_path; diff --git a/Tactility/Source/service/wifi/WifiBootSplashInit.cpp b/Tactility/Source/service/wifi/WifiBootSplashInit.cpp index 36e2f8e00..b279f1a7f 100644 --- a/Tactility/Source/service/wifi/WifiBootSplashInit.cpp +++ b/Tactility/Source/service/wifi/WifiBootSplashInit.cpp @@ -126,7 +126,7 @@ void bootSplashInit() { getMainDispatcher().dispatch([] { LOG_I(TAG, "bootSplashInit dispatch begin"); // Import any provisioning files placed on the system data partition. - const std::string provisioning_path = file::getChildPath(getUserDataPath(), "provisioning"); + const std::string provisioning_path = file::getChildPath(getDataPath(), "provisioning"); if (file::isDirectory(provisioning_path)) { importWifiApSettingsFromDir(provisioning_path); } else { diff --git a/Tactility/Source/settings/AudioSettings.cpp b/Tactility/Source/settings/AudioSettings.cpp index 89277b1b3..60b54f9dc 100644 --- a/Tactility/Source/settings/AudioSettings.cpp +++ b/Tactility/Source/settings/AudioSettings.cpp @@ -1,5 +1,7 @@ #include +#include "tactility/paths.h" + #include #include #include @@ -12,8 +14,14 @@ namespace tt::settings::audio { -static std::string getSettingsFilePath() { - return getUserDataPath() + "/settings/audio.properties"; +static bool getSettingsFilePath(std::string& outPath) { + char root[128]; + // Not really a service, but this is the best way of organising it for now + if (paths_get_data_path(root, sizeof(root)) != ERROR_NONE) { + return false; + } + outPath = std::string(root) + "/settings/audio.properties"; + return true; } constexpr auto* SETTINGS_KEY_INPUT_ENABLED = "inputEnabled"; @@ -56,7 +64,11 @@ static std::string toString(float value) { } bool load(AudioSettings& settings) { - auto settings_path = getSettingsFilePath(); + std::string settings_path; + if (getSettingsFilePath(settings_path)) { + return false; + } + if (!file::isFile(settings_path)) { return false; } @@ -103,10 +115,16 @@ bool save(const AudioSettings& settings) { map[SETTINGS_KEY_OUTPUT_MUTED] = toString(settings.outputMuted); map[SETTINGS_KEY_INPUT_VOLUME] = toString(settings.inputVolume); map[SETTINGS_KEY_OUTPUT_VOLUME] = toString(settings.outputVolume); - auto settings_path = getSettingsFilePath(); + + std::string settings_path; + if (getSettingsFilePath(settings_path)) { + return false; + } + if (!file::findOrCreateParentDirectory(settings_path, 0755)) { return false; } + return file::savePropertiesFile(settings_path, map); } diff --git a/Tactility/Source/settings/BootSettings.cpp b/Tactility/Source/settings/BootSettings.cpp index d6f5549b3..8e3704d5f 100644 --- a/Tactility/Source/settings/BootSettings.cpp +++ b/Tactility/Source/settings/BootSettings.cpp @@ -14,7 +14,7 @@ constexpr auto* PROPERTIES_KEY_LAUNCHER_APP_ID = "launcherAppId"; constexpr auto* PROPERTIES_KEY_AUTO_START_APP_ID = "autoStartAppId"; static std::string getPropertiesFilePath() { - return std::format(PROPERTIES_FILE_FORMAT, getUserDataPath()); + return std::format(PROPERTIES_FILE_FORMAT, getDataPath()); } bool loadBootSettings(BootSettings& properties) { diff --git a/Tactility/Source/settings/KeyboardSettings.cpp b/Tactility/Source/settings/KeyboardSettings.cpp index ef6f9b897..3b15979a9 100644 --- a/Tactility/Source/settings/KeyboardSettings.cpp +++ b/Tactility/Source/settings/KeyboardSettings.cpp @@ -9,7 +9,7 @@ namespace tt::settings::keyboard { static std::string getSettingsFilePath() { - return getUserDataPath() + "/settings/keyboard.properties"; + return getDataPath() + "/settings/keyboard.properties"; } constexpr auto* KEY_BACKLIGHT_ENABLED = "backlightEnabled"; diff --git a/Tactility/Source/settings/SystemSettings.cpp b/Tactility/Source/settings/SystemSettings.cpp index ca797322a..8957738ee 100644 --- a/Tactility/Source/settings/SystemSettings.cpp +++ b/Tactility/Source/settings/SystemSettings.cpp @@ -21,12 +21,12 @@ static bool cached = false; static SystemSettings cachedSettings; static bool hasSystemSettingsFile() { - auto file_path = std::format(FILE_PATH_FORMAT, getUserDataPath()); + auto file_path = std::format(FILE_PATH_FORMAT, getDataPath()); return file::isFile(file_path); } static bool loadSystemSettingsFromFile(SystemSettings& properties) { - auto file_path = std::format(FILE_PATH_FORMAT, getUserDataPath()); + auto file_path = std::format(FILE_PATH_FORMAT, getDataPath()); LOG_I(TAG, "System settings loading from %s", file_path.c_str()); std::map map; if (!file::loadPropertiesFile(file_path, map)) { @@ -75,7 +75,7 @@ bool loadSystemSettings(SystemSettings& properties) { } bool saveSystemSettings(const SystemSettings& properties) { - auto file_path = std::format(FILE_PATH_FORMAT, getUserDataPath()); + auto file_path = std::format(FILE_PATH_FORMAT, getDataPath()); std::map map; map["language"] = toString(properties.language); map["timeFormat24h"] = properties.timeFormat24h ? "true" : "false"; diff --git a/Tactility/Source/settings/TouchCalibrationSettings.cpp b/Tactility/Source/settings/TouchCalibrationSettings.cpp index bc323c008..1c3864baa 100644 --- a/Tactility/Source/settings/TouchCalibrationSettings.cpp +++ b/Tactility/Source/settings/TouchCalibrationSettings.cpp @@ -13,7 +13,7 @@ namespace tt::settings::touch { static std::string getSettingsFilePath() { - return getUserDataPath() + "/settings/touch-calibration.properties"; + return getDataPath() + "/settings/touch-calibration.properties"; } constexpr auto* SETTINGS_KEY_ENABLED = "enabled"; diff --git a/Tactility/Source/settings/time.cpp b/Tactility/Source/settings/time.cpp index 9c6e19518..bccb3d188 100644 --- a/Tactility/Source/settings/time.cpp +++ b/Tactility/Source/settings/time.cpp @@ -13,8 +13,6 @@ namespace tt::settings { -constexpr auto* TIME_SETTINGS_NAMESPACE = "time"; - constexpr auto* TIMEZONE_PREFERENCES_KEY_NAME = "tz_name"; constexpr auto* TIMEZONE_PREFERENCES_KEY_CODE = "tz_code"; constexpr auto* TIMEZONE_PREFERENCES_KEY_TIME24 = "tz_time24"; @@ -26,10 +24,10 @@ namespace { bool getPreferencesPath(std::string& outPath) { char root[128]; // Not really a service, but this is the best way of organising it for now - if (service_paths_get_user_data_directory("tactility.time", root, sizeof(root)) != ERROR_NONE) { + if (paths_get_data_path(root, sizeof(root)) != ERROR_NONE) { return false; } - outPath = std::string(root) + "/" + TIME_SETTINGS_NAMESPACE + ".properties"; + outPath = std::string(root) + "/settings/time.properties"; return true; }