diff --git a/Tactility/Source/bluetooth/BluetoothPairedDevice.cpp b/Tactility/Source/bluetooth/BluetoothPairedDevice.cpp index a6b2c99dc..c425b48aa 100644 --- a/Tactility/Source/bluetooth/BluetoothPairedDevice.cpp +++ b/Tactility/Source/bluetooth/BluetoothPairedDevice.cpp @@ -1,5 +1,7 @@ #include +#include "Tactility/Paths.h" + #include #include #include @@ -16,13 +18,16 @@ namespace tt::bluetooth::settings { constexpr auto* TAG = "BluetoothPairedDevice"; // Use the same directory as the old service for backward compatibility. -constexpr auto* DATA_DIR = "/data/service/bluetooth"; constexpr auto* DEVICE_SETTINGS_FORMAT = "{}/{}.device.properties"; constexpr auto* KEY_NAME = "name"; constexpr auto* KEY_ADDR = "addr"; constexpr auto* KEY_AUTO_CONNECT = "autoConnect"; constexpr auto* KEY_PROFILE_ID = "profileId"; +static std::string getSettingsFilePath() { + return getUserDataPath() + "/service/bluetooth"; +} + std::string addrToHex(const std::array& addr) { std::stringstream stream; stream << std::hex; @@ -52,7 +57,7 @@ static bool hexToAddr(const std::string& hex, std::array& addr) { } static std::string getFilePath(const std::string& addr_hex) { - return std::format(DEVICE_SETTINGS_FORMAT, DATA_DIR, addr_hex); + return std::format(DEVICE_SETTINGS_FORMAT, getSettingsFilePath(), addr_hex); } bool hasFileForDevice(const std::string& addr_hex) { @@ -102,7 +107,10 @@ bool remove(const std::string& addr_hex) { std::vector loadAll() { std::vector entries; - file::scandir(DATA_DIR, entries, [](const dirent* entry) -> int { + if (!file::isDirectory(getSettingsFilePath())) { + return {}; + } + file::scandir(getSettingsFilePath(), entries, [](const dirent* entry) -> int { if (entry->d_type != file::TT_DT_REG && entry->d_type != file::TT_DT_UNKNOWN) return -1; std::string name = entry->d_name; return name.ends_with(".device.properties") ? 0 : -1;