Merge develop into main (#304)
## 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::notes::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
This commit is contained in:
committed by
GitHub
parent
fbaff8cbac
commit
ee5a5a7181
@@ -0,0 +1,78 @@
|
||||
#include "Tactility/file/ObjectFile.h"
|
||||
#include "Tactility/file/ObjectFilePrivate.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <Tactility/Log.h>
|
||||
|
||||
namespace tt::file {
|
||||
|
||||
constexpr auto* TAG = "ObjectFileReader";
|
||||
|
||||
bool ObjectFileReader::open() {
|
||||
auto opening_file = std::unique_ptr<FILE, FileCloser>(fopen(filePath.c_str(), "r"));
|
||||
if (opening_file == nullptr) {
|
||||
TT_LOG_E(TAG, "Failed to open file %s", filePath.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
FileHeader file_header;
|
||||
if (fread(&file_header, sizeof(FileHeader), 1, opening_file.get()) != 1) {
|
||||
TT_LOG_E(TAG, "Failed to read file header from %s", filePath.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (file_header.identifier != OBJECT_FILE_IDENTIFIER) {
|
||||
TT_LOG_E(TAG, "Invalid file type for %s", filePath.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (file_header.version != OBJECT_FILE_VERSION) {
|
||||
TT_LOG_E(TAG, "Unknown version for %s: %lu", filePath.c_str(), file_header.identifier);
|
||||
return false;
|
||||
}
|
||||
|
||||
ContentHeader content_header;
|
||||
if (fread(&content_header, sizeof(ContentHeader), 1, opening_file.get()) != 1) {
|
||||
TT_LOG_E(TAG, "Failed to read content header from %s", filePath.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (recordSize != content_header.recordSize) {
|
||||
TT_LOG_E(TAG, "Record size mismatch for %s: expected %lu, got %lu", filePath.c_str(), recordSize, content_header.recordSize);
|
||||
return false;
|
||||
}
|
||||
|
||||
recordCount = content_header.recordCount;
|
||||
recordVersion = content_header.recordVersion;
|
||||
|
||||
file = std::move(opening_file);
|
||||
|
||||
TT_LOG_D(TAG, "File version: %lu", file_header.version);
|
||||
TT_LOG_D(TAG, "Content: version = %lu, size = %lu bytes, count = %lu", content_header.recordVersion, content_header.recordSize, content_header.recordCount);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void ObjectFileReader::close() {
|
||||
recordCount = 0;
|
||||
recordVersion = 0;
|
||||
recordsRead = 0;
|
||||
|
||||
file = nullptr;
|
||||
}
|
||||
|
||||
bool ObjectFileReader::readNext(void* output) {
|
||||
if (file == nullptr) {
|
||||
TT_LOG_E(TAG, "File not open");
|
||||
return false;
|
||||
}
|
||||
|
||||
bool result = fread(output, recordSize, 1, file.get()) == 1;
|
||||
if (result) {
|
||||
recordsRead++;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user