## New
- Read property files with `PropertiesFile`
- Support `boot.properties` so the user can specify the launcher app and an optional app to start after the launcher finishes. (see `BootProperties.cpp`)
- Create registry for CPU affinity and update code to make use of it
- `AppRegistration` and `ServiceRegistration` now also ensure that the `/data` directories always exist for all apps
- `Notes` is now the default app for opening text files. `TextViewer` is removed entirely. Created `tt::app:🎶:start(path)` function.
- WiFi settings moved from NVS to properties file.
- Specify `*.ap.properties` file on the SD card for automatic WiFi settings import on start-up.
- Added `file::getLock(path)` and `file::withLock(path, function)` to do safe file operations on SD cards
## Improvements
- Update TinyUSB to `1.7.6~1`
- Improved `Boot.cpp` code. General code quality fixes and some restructuring to improve readability.
- `tt::string` functionality improvements
- Rename `AppRegistry` to `AppRegistration`
- Rename `ServiceRegistry` to `ServiceRegistration`
- Cleanup in `Notes.cpp`
- `FileTest.cpp` fix for PC
- Created `TestFile` helper class for tests, which automatically deletes files after the test.
- Renamed `Partitions.h` to `MountPoints.h`
- Created `std::string getMountPoints()` function for easy re-use
- Other code quality improvements
- `SdCardDevice`'s `getState()` and `isMounted()` now have a timeout argument
## Fixes
- ELF loading now has a lock so to avoid a bug when 2 ELF apps are loaded in parallel
75 lines
2.6 KiB
C++
75 lines
2.6 KiB
C++
#include "Tactility/file/PropertiesFile.h"
|
|
|
|
#include <Tactility/StringUtils.h>
|
|
#include <Tactility/file/File.h>
|
|
#include <Tactility/file/FileLock.h>
|
|
|
|
namespace tt::file {
|
|
|
|
static auto TAG = "PropertiesFile";
|
|
|
|
bool getKeyValuePair(const std::string& input, std::string& key, std::string& value) {
|
|
auto index = input.find('=');
|
|
if (index == std::string::npos) {
|
|
return false;
|
|
}
|
|
key = input.substr(0, index);
|
|
value = input.substr(index + 1);
|
|
return true;
|
|
}
|
|
|
|
bool loadPropertiesFile(const std::string& filePath, std::function<void(const std::string& key, const std::string& value)> callback) {
|
|
return file::withLock<bool>(filePath, [&filePath, &callback] {
|
|
TT_LOG_I(TAG, "Reading properties file %s", filePath.c_str());
|
|
const auto input = readString(filePath);
|
|
if (input == nullptr) {
|
|
TT_LOG_E(TAG, "Failed to read file contents of %s", filePath.c_str());
|
|
return false;
|
|
}
|
|
|
|
const auto* input_start = reinterpret_cast<const char*>(input.get());
|
|
const std::string input_string = input_start;
|
|
|
|
uint16_t line_count = 0;
|
|
string::split(input_string, "\n", [&line_count, &filePath, &callback](auto token) {
|
|
line_count++;
|
|
std::string key, value;
|
|
auto trimmed_token = string::trim(token, " \t");
|
|
if (!trimmed_token.starts_with("#")) {
|
|
if (getKeyValuePair(token, key, value)) {
|
|
std::string trimmed_key = string::trim(key, " \t");
|
|
std::string trimmed_value = string::trim(value, " \t");
|
|
callback(trimmed_key, trimmed_value);
|
|
} else { TT_LOG_E(TAG, "Failed to parse line %d of %s", line_count, filePath.c_str()); }
|
|
}
|
|
});
|
|
|
|
return true;
|
|
});
|
|
}
|
|
|
|
bool loadPropertiesFile(const std::string& filePath, std::map<std::string, std::string>& outProperties) {
|
|
return loadPropertiesFile(filePath, [&outProperties](const std::string& key, const std::string& value) {
|
|
outProperties[key] = value;
|
|
});
|
|
}
|
|
|
|
bool savePropertiesFile(const std::string& filePath, const std::map<std::string, std::string>& properties) {
|
|
return file::withLock<bool>(filePath, [filePath, &properties] {
|
|
TT_LOG_I(TAG, "Saving properties file %s", filePath.c_str());
|
|
|
|
FILE* file = fopen(filePath.c_str(), "w");
|
|
if (file == nullptr) {
|
|
TT_LOG_E(TAG, "Failed to open %s", filePath.c_str());
|
|
return false;
|
|
}
|
|
|
|
for (const auto& [key, value]: properties) { fprintf(file, "%s=%s\n", key.c_str(), value.c_str()); }
|
|
|
|
fclose(file);
|
|
return true;
|
|
});
|
|
}
|
|
|
|
}
|