refactor: Drop FsFile alias, use HalFile in downstream code (#2141)

This commit is contained in:
Zach Nelson
2026-05-25 16:26:54 -04:00
committed by GitHub
parent d7797baff2
commit e9120888fa
63 changed files with 201 additions and 205 deletions
+3 -3
View File
@@ -14,7 +14,7 @@
// Initialize the static instance
CrossPointSettings CrossPointSettings::instance;
void readAndValidate(FsFile& file, uint8_t& member, const uint8_t maxValue) {
void readAndValidate(HalFile& file, uint8_t& member, const uint8_t maxValue) {
uint8_t tempValue;
serialization::readPod(file, tempValue);
if (tempValue < maxValue) {
@@ -127,7 +127,7 @@ bool CrossPointSettings::migrateLanguageBinaryFile() {
// frozen enum order from 2f969a9.
if (!Storage.exists(LANG_FILE_BIN)) return false;
FsFile f;
HalFile f;
if (Storage.openFileForRead("CPS", LANG_FILE_BIN, f)) {
uint8_t version;
serialization::readPod(f, version);
@@ -146,7 +146,7 @@ bool CrossPointSettings::migrateLanguageBinaryFile() {
}
bool CrossPointSettings::loadFromBinaryFile() {
FsFile inputFile;
HalFile inputFile;
if (!Storage.openFileForRead("CPS", SETTINGS_FILE_BIN, inputFile)) {
return false;
}
+1 -1
View File
@@ -269,7 +269,7 @@ class CrossPointSettings {
int getReaderFontId() const;
// If count_only is true, returns the number of settings items that would be written.
uint8_t writeSettings(FsFile& file, bool count_only = false) const;
uint8_t writeSettings(HalFile& file, bool count_only = false) const;
bool saveToFile() const;
bool loadFromFile();
+1 -1
View File
@@ -63,7 +63,7 @@ bool CrossPointState::loadFromFile() {
}
bool CrossPointState::loadFromBinaryFile() {
FsFile inputFile;
HalFile inputFile;
if (!Storage.openFileForRead("CPS", STATE_FILE_BIN, inputFile)) {
return false;
}
+1 -1
View File
@@ -81,7 +81,7 @@ bool FontInstaller::ensureFamilyDir(const char* familyName) {
}
bool FontInstaller::validateCpfontFile(const char* path) {
FsFile file;
HalFile file;
if (!Storage.openFileForRead("FONT", path, file)) {
LOG_ERR("FONT", "Cannot open for validation: %s", path);
return false;
+1 -1
View File
@@ -148,7 +148,7 @@ bool RecentBooksStore::loadFromFile() {
}
bool RecentBooksStore::loadFromBinaryFile() {
FsFile inputFile;
HalFile inputFile;
if (!Storage.openFileForRead("RBS", RECENT_BOOKS_FILE_BIN, inputFile)) {
return false;
}
+1 -1
View File
@@ -67,7 +67,7 @@ bool WifiCredentialStore::loadFromFile() {
}
bool WifiCredentialStore::loadFromBinaryFile() {
FsFile file;
HalFile file;
if (!Storage.openFileForRead("WCS", WIFI_FILE_BIN, file)) {
return false;
}
+3 -3
View File
@@ -63,7 +63,7 @@ void SleepActivity::renderCustomSleepScreen() const {
// Look for sleep.bmp on the root of the sd card to determine if we should
// render a custom sleep screen instead of the default.
// This takes priority over the /sleep folder.
FsFile file;
HalFile file;
if (Storage.openFileForRead("SLP", "/sleep.bmp", file)) {
Bitmap bitmap(file, true);
if (bitmap.parseHeaders() == BmpReaderError::Ok) {
@@ -129,7 +129,7 @@ void SleepActivity::renderCustomSleepScreen() const {
APP_STATE.pushRecentSleep(randomFileIndex);
APP_STATE.saveToFile();
const auto filename = std::string(sleepDir) + "/" + files[randomFileIndex];
FsFile randFile;
HalFile randFile;
if (Storage.openFileForRead("SLP", filename, randFile)) {
LOG_DBG("SLP", "Randomly loading: %s/%s", sleepDir, files[randomFileIndex].c_str());
delay(100);
@@ -304,7 +304,7 @@ void SleepActivity::renderCoverSleepScreen() const {
return (this->*renderNoCoverSleepScreen)();
}
FsFile file;
HalFile file;
if (Storage.openFileForRead("SLP", coverBmpPath, file)) {
Bitmap bitmap(file);
if (bitmap.parseHeaders() == BmpReaderError::Ok) {
+1 -1
View File
@@ -123,7 +123,7 @@ void EpubReaderActivity::onEnter() {
epub->setupCacheDir();
FsFile f;
HalFile f;
if (Storage.openFileForRead("ERS", epub->getCachePath() + "/progress.bin", f)) {
uint8_t data[6];
int dataSize = f.read(data, 6);
+1 -1
View File
@@ -13,7 +13,7 @@ inline bool saveProgress(Epub& epub, int spineIndex, int pageNumber, int pageCou
LOG_ERR("ERS", "Progress values out of range: spine=%d page=%d count=%d", spineIndex, pageNumber, pageCount);
return false;
}
FsFile f;
HalFile f;
if (!Storage.openFileForWrite("ERS", epub.getCachePath() + "/progress.bin", f)) {
LOG_ERR("ERS", "Could not open progress file for write!");
return false;
+4 -4
View File
@@ -415,7 +415,7 @@ void TxtReaderActivity::renderStatusBar() const {
}
void TxtReaderActivity::saveProgress() const {
FsFile f;
HalFile f;
if (Storage.openFileForWrite("TRS", txt->getCachePath() + "/progress.bin", f)) {
uint8_t data[4];
data[0] = currentPage & 0xFF;
@@ -427,7 +427,7 @@ void TxtReaderActivity::saveProgress() const {
}
void TxtReaderActivity::loadProgress() {
FsFile f;
HalFile f;
if (Storage.openFileForRead("TRS", txt->getCachePath() + "/progress.bin", f)) {
uint8_t data[4];
if (f.read(data, 4) == 4) {
@@ -457,7 +457,7 @@ bool TxtReaderActivity::loadPageIndexCache() {
// - N * uint32_t: page offsets
std::string cachePath = txt->getCachePath() + "/index.bin";
FsFile f;
HalFile f;
if (!Storage.openFileForRead("TRS", cachePath, f)) {
LOG_DBG("TRS", "No page index cache found");
return false;
@@ -540,7 +540,7 @@ bool TxtReaderActivity::loadPageIndexCache() {
void TxtReaderActivity::savePageIndexCache() const {
std::string cachePath = txt->getCachePath() + "/index.bin";
FsFile f;
HalFile f;
if (!Storage.openFileForWrite("TRS", cachePath, f)) {
LOG_ERR("TRS", "Failed to save page index cache");
return;
+2 -2
View File
@@ -375,7 +375,7 @@ void XtcReaderActivity::renderPage() {
}
void XtcReaderActivity::saveProgress() const {
FsFile f;
HalFile f;
if (Storage.openFileForWrite("XTR", xtc->getCachePath() + "/progress.bin", f)) {
uint8_t data[4];
data[0] = currentPage & 0xFF;
@@ -388,7 +388,7 @@ void XtcReaderActivity::saveProgress() const {
}
void XtcReaderActivity::loadProgress() {
FsFile f;
HalFile f;
if (Storage.openFileForRead("XTR", xtc->getCachePath() + "/progress.bin", f)) {
uint8_t data[4];
if (f.read(data, 4) == 4) {
@@ -82,7 +82,7 @@ bool FontDownloadActivity::fetchAndParseManifest() {
}
// HTTP client is now closed — TLS buffers freed. Parse JSON from file.
FsFile manifestFile;
HalFile manifestFile;
if (!Storage.openFileForRead("FONT", MANIFEST_TMP, manifestFile)) {
LOG_ERR("FONT", "Failed to open temp manifest");
Storage.remove(MANIFEST_TMP);
@@ -149,7 +149,7 @@ bool FontDownloadActivity::fetchAndParseManifest() {
for (const auto& file : family.files) {
char path[128];
FontInstaller::buildFontPath(family.name.c_str(), file.name.c_str(), path, sizeof(path));
FsFile f;
HalFile f;
if (Storage.openFileForRead("FONT", path, f)) {
size_t actual = f.fileSize();
f.close();
@@ -248,7 +248,7 @@ size_t FontDownloadActivity::totalUpdateSize() const {
// Standard CRC32 matching zlib/Python zlib.crc32().
bool FontDownloadActivity::computeFileCrc32(const char* path, uint32_t& outCrc) {
FsFile f;
HalFile f;
if (!Storage.openFileForRead("FONT", path, f)) {
return false;
}
+2 -2
View File
@@ -63,7 +63,7 @@ void BmpViewerActivity::onEnter() {
loadSiblingImages();
}
FsFile file;
HalFile file;
const auto pageWidth = renderer.getScreenWidth();
const auto pageHeight = renderer.getScreenHeight();
@@ -147,7 +147,7 @@ void BmpViewerActivity::doSetSleepCover() {
GUI.drawPopup(renderer, tr(STR_LOADING_POPUP));
bool success = false;
FsFile inFile, outFile;
HalFile inFile, outFile;
if (Storage.openFileForRead("BMP", filePath, inFile)) {
if (Storage.openFileForWrite("BMP", "/sleep.bmp", outFile)) {
char buffer[2048];
+2 -2
View File
@@ -426,7 +426,7 @@ void BaseTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect, const std:
const std::string coverBmpPath =
UITheme::getCoverThumbPath(recentBooks[0].coverBmpPath, BaseMetrics::values.homeCoverHeight);
FsFile file;
HalFile file;
if (Storage.openFileForRead("HOME", coverBmpPath, file)) {
Bitmap bitmap(file);
if (bitmap.parseHeaders() == BmpReaderError::Ok) {
@@ -476,7 +476,7 @@ void BaseTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect, const std:
UITheme::getCoverThumbPath(recentBooks[0].coverBmpPath, BaseMetrics::values.homeCoverHeight);
// First time: load cover from SD and render
FsFile file;
HalFile file;
if (Storage.openFileForRead("HOME", coverBmpPath, file)) {
Bitmap bitmap(file);
if (bitmap.parseHeaders() == BmpReaderError::Ok) {
@@ -42,7 +42,7 @@ void Lyra3CoversTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect, con
UITheme::getCoverThumbPath(coverPath, Lyra3CoversMetrics::values.homeCoverHeight);
// First time: load cover from SD and render
FsFile file;
HalFile file;
if (Storage.openFileForRead("HOME", coverBmpPath, file)) {
Bitmap bitmap(file);
if (bitmap.parseHeaders() == BmpReaderError::Ok) {
+1 -1
View File
@@ -423,7 +423,7 @@ void LyraTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect, const std:
const std::string coverBmpPath = UITheme::getCoverThumbPath(coverPath, LyraMetrics::values.homeCoverHeight);
// First time: load cover from SD and render
FsFile file;
HalFile file;
if (Storage.openFileForRead("HOME", coverBmpPath, file)) {
Bitmap bitmap(file);
if (bitmap.parseHeaders() == BmpReaderError::Ok) {
@@ -140,7 +140,7 @@ void RoundedRaffTheme::drawRecentBookCover(GfxRenderer& renderer, Rect rect, con
UITheme::getCoverThumbPath(coverPath, RoundedRaffMetrics::values.homeCoverHeight);
// First time: load cover from SD and render
FsFile file;
HalFile file;
if (Storage.openFileForRead("HOME", coverBmpPath, file)) {
Bitmap bitmap(file);
if (bitmap.parseHeaders() == BmpReaderError::Ok) {
+2 -2
View File
@@ -237,14 +237,14 @@ void waitForPowerRelease() {
constexpr char SLEEP_FRAME_FILE[] = "/.crosspoint/sleep_frame.bin";
static void saveSleepFrameBuffer() {
FsFile file;
HalFile file;
if (!Storage.openFileForWrite("SLP", SLEEP_FRAME_FILE, file)) return;
file.write(renderer.getFrameBuffer(), renderer.getBufferSize());
file.close();
}
static bool loadSleepFrameBuffer() {
FsFile file;
HalFile file;
if (!Storage.openFileForRead("SLP", SLEEP_FRAME_FILE, file)) return false;
const size_t bufferSize = display.getBufferSize();
const size_t bytesRead = file.read(display.getFrameBuffer(), bufferSize);
+16 -12
View File
@@ -35,7 +35,7 @@ constexpr uint16_t LOCAL_UDP_PORT = 8134;
CrossPointWebServer* wsInstance = nullptr;
// WebSocket upload state
FsFile wsUploadFile;
HalFile wsUploadFile;
String wsUploadFileName;
String wsUploadPath;
size_t wsUploadSize = 0;
@@ -374,7 +374,7 @@ void CrossPointWebServer::handleStatus() const {
}
void CrossPointWebServer::scanFiles(const char* path, const std::function<void(FileInfo)>& callback) const {
FsFile root = Storage.open(path);
HalFile root = Storage.open(path);
if (!root) {
LOG_DBG("WEB", "Failed to open directory: %s", path);
return;
@@ -388,7 +388,7 @@ void CrossPointWebServer::scanFiles(const char* path, const std::function<void(F
LOG_DBG("WEB", "Scanning files in: %s", path);
FsFile file = root.openNextFile();
HalFile file = root.openNextFile();
char name[500];
while (file) {
file.getName(name, sizeof(name));
@@ -519,7 +519,7 @@ void CrossPointWebServer::handleDownload() const {
return;
}
FsFile file = Storage.open(itemPath.c_str());
HalFile file = Storage.open(itemPath.c_str());
if (!file) {
server->send(500, "text/plain", "Failed to open file");
return;
@@ -842,7 +842,7 @@ void CrossPointWebServer::handleRename() const {
return;
}
FsFile file = Storage.open(itemPath.c_str());
HalFile file = Storage.open(itemPath.c_str());
if (!file) {
server->send(500, "text/plain", "Failed to open file");
return;
@@ -918,7 +918,7 @@ void CrossPointWebServer::handleMove() const {
return;
}
FsFile file = Storage.open(itemPath.c_str());
HalFile file = Storage.open(itemPath.c_str());
if (!file) {
server->send(500, "text/plain", "Failed to open file");
return;
@@ -934,7 +934,7 @@ void CrossPointWebServer::handleMove() const {
server->send(404, "text/plain", "Destination not found");
return;
}
FsFile destDir = Storage.open(destPath.c_str());
HalFile destDir = Storage.open(destPath.c_str());
if (!destDir || !destDir.isDirectory()) {
if (destDir) {
destDir.close();
@@ -1064,10 +1064,10 @@ void CrossPointWebServer::handleDelete() const {
// Decide whether it's a directory or file by opening it
bool success = false;
FsFile f = Storage.open(itemPath.c_str());
HalFile f = Storage.open(itemPath.c_str());
if (f && f.isDirectory()) {
// For folders, ensure empty before removing
FsFile entry = f.openNextFile();
HalFile entry = f.openNextFile();
if (entry) {
entry.close();
f.close();
@@ -1741,7 +1741,7 @@ void CrossPointWebServer::handleFontList() const {
fileObj["name"] = name ? name + 1 : file.path.c_str();
// Stat the file for size
FsFile f;
HalFile f;
if (Storage.openFileForRead("WEB", file.path.c_str(), f)) {
fileObj["size"] = static_cast<unsigned long>(f.size());
f.close();
@@ -1848,7 +1848,9 @@ void CrossPointWebServer::handleFontUploadData() {
fontUpload.bytesWritten += fontUpload.bufferPos;
fontUpload.bufferPos = 0;
}
fontUpload.file.close();
if (fontUpload.file) {
fontUpload.file.close();
}
if (!fontUpload.valid && !fontUpload.filePath.empty()) {
Storage.remove(fontUpload.filePath.c_str());
@@ -1859,7 +1861,9 @@ void CrossPointWebServer::handleFontUploadData() {
}
case UPLOAD_FILE_ABORTED: {
fontUpload.file.close();
if (fontUpload.file) {
fontUpload.file.close();
}
if (!fontUpload.filePath.empty()) {
Storage.remove(fontUpload.filePath.c_str());
}
+2 -2
View File
@@ -31,7 +31,7 @@ class CrossPointWebServer {
// Used by POST upload handler
struct UploadState {
FsFile file;
HalFile file;
String fileName;
String path = "/";
size_t size = 0;
@@ -117,7 +117,7 @@ class CrossPointWebServer {
// Font upload state
struct FontUploadState {
FsFile file;
HalFile file;
std::string familyName;
std::string filePath;
bool valid = false;
+1 -1
View File
@@ -179,7 +179,7 @@ HttpDownloader::DownloadError HttpDownloader::downloadToFile(const std::string&
if (Storage.exists(destPath.c_str())) {
Storage.remove(destPath.c_str());
}
FsFile file;
HalFile file;
if (!Storage.openFileForWrite("HTTP", destPath.c_str(), file)) {
LOG_ERR("HTTP", "Failed to open file for writing");
return FILE_ERROR;
+11 -11
View File
@@ -67,7 +67,7 @@ void WebDAVHandler::raw(WebServer& server, const String& uri, HTTPRaw& raw) {
_putExisted = Storage.exists(_putPath.c_str());
if (_putExisted) {
FsFile existing = Storage.open(_putPath.c_str());
HalFile existing = Storage.open(_putPath.c_str());
if (existing && existing.isDirectory()) {
existing.close();
_putOk = false;
@@ -96,7 +96,7 @@ void WebDAVHandler::raw(WebServer& server, const String& uri, HTTPRaw& raw) {
if (_putOk) {
String tempPath = _putPath + ".davtmp";
if (_putExisted) Storage.remove(_putPath.c_str());
FsFile tmp = Storage.open(tempPath.c_str());
HalFile tmp = Storage.open(tempPath.c_str());
if (tmp) {
_putOk = tmp.rename(_putPath.c_str());
tmp.close();
@@ -182,7 +182,7 @@ void WebDAVHandler::handlePropfind(WebServer& s) {
return;
}
FsFile root = Storage.open(path.c_str());
HalFile root = Storage.open(path.c_str());
if (!root) {
if (path == "/") {
// Root should always work — send minimal response
@@ -221,7 +221,7 @@ void WebDAVHandler::handlePropfind(WebServer& s) {
// If depth > 0 and it's a directory, list children
if (depth > 0) {
FsFile file = root.openNextFile();
HalFile file = root.openNextFile();
char name[500];
while (file) {
file.getName(name, sizeof(name));
@@ -311,7 +311,7 @@ void WebDAVHandler::handleGet(WebServer& s) {
return;
}
FsFile file = Storage.open(path.c_str());
HalFile file = Storage.open(path.c_str());
if (!file) {
s.send(500, "text/plain", "Failed to open file");
return;
@@ -348,7 +348,7 @@ void WebDAVHandler::handleHead(WebServer& s) {
return;
}
FsFile file = Storage.open(path.c_str());
HalFile file = Storage.open(path.c_str());
if (!file) {
s.send(500, "text/plain", "");
return;
@@ -411,7 +411,7 @@ void WebDAVHandler::handleDelete(WebServer& s) {
return;
}
FsFile file = Storage.open(path.c_str());
HalFile file = Storage.open(path.c_str());
if (!file) {
s.send(500, "text/plain", "Failed to open");
return;
@@ -419,7 +419,7 @@ void WebDAVHandler::handleDelete(WebServer& s) {
if (file.isDirectory()) {
// Check if directory is empty
FsFile entry = file.openNextFile();
HalFile entry = file.openNextFile();
if (entry) {
entry.close();
file.close();
@@ -537,7 +537,7 @@ void WebDAVHandler::handleMove(WebServer& s) {
Storage.remove(dstPath.c_str());
}
FsFile file = Storage.open(srcPath.c_str());
HalFile file = Storage.open(srcPath.c_str());
if (!file) {
s.send(500, "text/plain", "Failed to open source");
return;
@@ -583,7 +583,7 @@ void WebDAVHandler::handleCopy(WebServer& s) {
return;
}
FsFile srcFile = Storage.open(srcPath.c_str());
HalFile srcFile = Storage.open(srcPath.c_str());
if (!srcFile) {
s.send(500, "text/plain", "Failed to open source");
return;
@@ -617,7 +617,7 @@ void WebDAVHandler::handleCopy(WebServer& s) {
Storage.remove(dstPath.c_str());
}
FsFile dstFile;
HalFile dstFile;
if (!Storage.openFileForWrite("DAV", dstPath, dstFile)) {
srcFile.close();
s.send(500, "text/plain", "Failed to create destination");
+1 -1
View File
@@ -13,7 +13,7 @@ class WebDAVHandler : public RequestHandler {
private:
// PUT streaming state (raw() is called in chunks)
FsFile _putFile;
HalFile _putFile;
String _putPath;
bool _putOk = false;
bool _putExisted = false;
+1 -1
View File
@@ -121,7 +121,7 @@ bool ScreenshotUtil::saveFramebufferAsBmp(const char* filename, const uint8_t* f
}
}
FsFile file;
HalFile file;
if (!Storage.openFileForWrite("SCR", filename, file)) {
LOG_ERR("SCR", "Failed to save screenshot");
return false;