Add exFAT support (#150)

## Summary

* Swap to updated SDCardManager which uses SdFat
* Add exFAT support
  * Swap to using FsFile everywhere
* Use newly exposed `SdMan` macro to get to static instance of
SDCardManager
* Move a bunch of FsHelpers up to SDCardManager
This commit is contained in:
Dave Allie
2025-12-30 15:09:30 +10:00
committed by GitHub
parent d4bd119950
commit fb5fc32c5d
50 changed files with 289 additions and 355 deletions

View File

@@ -9,7 +9,7 @@
#include <FsHelpers.h>
#include <HardwareSerial.h>
#include <SD.h>
#include <SDCardManager.h>
bool Xtc::load() {
Serial.printf("[%lu] [XTC] Loading XTC: %s\n", millis(), filepath.c_str());
@@ -31,12 +31,12 @@ bool Xtc::load() {
}
bool Xtc::clearCache() const {
if (!SD.exists(cachePath.c_str())) {
if (!SdMan.exists(cachePath.c_str())) {
Serial.printf("[%lu] [XTC] Cache does not exist, no action needed\n", millis());
return true;
}
if (!FsHelpers::removeDir(cachePath.c_str())) {
if (!SdMan.removeDir(cachePath.c_str())) {
Serial.printf("[%lu] [XTC] Failed to clear cache\n", millis());
return false;
}
@@ -46,17 +46,17 @@ bool Xtc::clearCache() const {
}
void Xtc::setupCacheDir() const {
if (SD.exists(cachePath.c_str())) {
if (SdMan.exists(cachePath.c_str())) {
return;
}
// Create directories recursively
for (size_t i = 1; i < cachePath.length(); i++) {
if (cachePath[i] == '/') {
SD.mkdir(cachePath.substr(0, i).c_str());
SdMan.mkdir(cachePath.substr(0, i).c_str());
}
}
SD.mkdir(cachePath.c_str());
SdMan.mkdir(cachePath.c_str());
}
std::string Xtc::getTitle() const {
@@ -106,7 +106,7 @@ std::string Xtc::getCoverBmpPath() const { return cachePath + "/cover.bmp"; }
bool Xtc::generateCoverBmp() const {
// Already generated
if (SD.exists(getCoverBmpPath().c_str())) {
if (SdMan.exists(getCoverBmpPath().c_str())) {
return true;
}
@@ -157,8 +157,8 @@ bool Xtc::generateCoverBmp() const {
}
// Create BMP file
File coverBmp;
if (!FsHelpers::openFileForWrite("XTC", getCoverBmpPath(), coverBmp)) {
FsFile coverBmp;
if (!SdMan.openFileForWrite("XTC", getCoverBmpPath(), coverBmp)) {
Serial.printf("[%lu] [XTC] Failed to create cover BMP file\n", millis());
free(pageBuffer);
return false;

View File

@@ -9,6 +9,7 @@
#include <FsHelpers.h>
#include <HardwareSerial.h>
#include <SDCardManager.h>
#include <cstring>
@@ -33,7 +34,7 @@ XtcError XtcParser::open(const char* filepath) {
}
// Open file
if (!FsHelpers::openFileForRead("XTC", filepath, m_file)) {
if (!SdMan.openFileForRead("XTC", filepath, m_file)) {
m_lastError = XtcError::FILE_NOT_FOUND;
return m_lastError;
}
@@ -419,8 +420,8 @@ XtcError XtcParser::loadPageStreaming(uint32_t pageIndex,
}
bool XtcParser::isValidXtcFile(const char* filepath) {
File file = SD.open(filepath, FILE_READ);
if (!file) {
FsFile file;
if (!SdMan.openFileForRead("XTC", filepath, file)) {
return false;
}

View File

@@ -7,7 +7,7 @@
#pragma once
#include <SD.h>
#include <SdFat.h>
#include <functional>
#include <memory>
@@ -80,7 +80,7 @@ class XtcParser {
XtcError getLastError() const { return m_lastError; }
private:
File m_file;
FsFile m_file;
bool m_isOpen;
XtcHeader m_header;
std::vector<PageInfo> m_pageTable;