mirror of
https://github.com/daveallie/crosspoint-reader.git
synced 2026-02-04 06:37:38 +03:00
## 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
45 lines
1.0 KiB
C++
45 lines
1.0 KiB
C++
#include "CrossPointState.h"
|
|
|
|
#include <HardwareSerial.h>
|
|
#include <SDCardManager.h>
|
|
#include <Serialization.h>
|
|
|
|
namespace {
|
|
constexpr uint8_t STATE_FILE_VERSION = 1;
|
|
constexpr char STATE_FILE[] = "/.crosspoint/state.bin";
|
|
} // namespace
|
|
|
|
CrossPointState CrossPointState::instance;
|
|
|
|
bool CrossPointState::saveToFile() const {
|
|
FsFile outputFile;
|
|
if (!SdMan.openFileForWrite("CPS", STATE_FILE, outputFile)) {
|
|
return false;
|
|
}
|
|
|
|
serialization::writePod(outputFile, STATE_FILE_VERSION);
|
|
serialization::writeString(outputFile, openEpubPath);
|
|
outputFile.close();
|
|
return true;
|
|
}
|
|
|
|
bool CrossPointState::loadFromFile() {
|
|
FsFile inputFile;
|
|
if (!SdMan.openFileForRead("CPS", STATE_FILE, inputFile)) {
|
|
return false;
|
|
}
|
|
|
|
uint8_t version;
|
|
serialization::readPod(inputFile, version);
|
|
if (version != STATE_FILE_VERSION) {
|
|
Serial.printf("[%lu] [CPS] Deserialization failed: Unknown version %u\n", millis(), version);
|
|
inputFile.close();
|
|
return false;
|
|
}
|
|
|
|
serialization::readString(inputFile, openEpubPath);
|
|
|
|
inputFile.close();
|
|
return true;
|
|
}
|