fix: settings persist on font clear, reserve() before push_back, minor (#2519)
This commit is contained in:
@@ -10,7 +10,11 @@ OpdsParser::OpdsParser() {
|
|||||||
if (!parser) {
|
if (!parser) {
|
||||||
errorOccured = true;
|
errorOccured = true;
|
||||||
LOG_DBG("OPDS", "Couldn't allocate memory for parser");
|
LOG_DBG("OPDS", "Couldn't allocate memory for parser");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
XML_SetUserData(parser, this);
|
||||||
|
XML_SetElementHandler(parser, startElement, endElement);
|
||||||
|
XML_SetCharacterDataHandler(parser, characterData);
|
||||||
}
|
}
|
||||||
|
|
||||||
OpdsParser::~OpdsParser() { destroyXmlParser(parser); }
|
OpdsParser::~OpdsParser() { destroyXmlParser(parser); }
|
||||||
@@ -20,10 +24,6 @@ size_t OpdsParser::write(uint8_t c) { return write(&c, 1); }
|
|||||||
size_t OpdsParser::write(const uint8_t* xmlData, const size_t length) {
|
size_t OpdsParser::write(const uint8_t* xmlData, const size_t length) {
|
||||||
if (errorOccured) return length;
|
if (errorOccured) return length;
|
||||||
|
|
||||||
XML_SetUserData(parser, this);
|
|
||||||
XML_SetElementHandler(parser, startElement, endElement);
|
|
||||||
XML_SetCharacterDataHandler(parser, characterData);
|
|
||||||
|
|
||||||
const char* currentPos = reinterpret_cast<const char*>(xmlData);
|
const char* currentPos = reinterpret_cast<const char*>(xmlData);
|
||||||
size_t remaining = length;
|
size_t remaining = length;
|
||||||
constexpr size_t chunkSize = 1024;
|
constexpr size_t chunkSize = 1024;
|
||||||
@@ -54,6 +54,7 @@ size_t OpdsParser::write(const uint8_t* xmlData, const size_t length) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OpdsParser::flush() {
|
void OpdsParser::flush() {
|
||||||
|
if (errorOccured || !parser) return;
|
||||||
if (XML_Parse(parser, nullptr, 0, XML_TRUE) != XML_STATUS_OK) {
|
if (XML_Parse(parser, nullptr, 0, XML_TRUE) != XML_STATUS_OK) {
|
||||||
errorOccured = true;
|
errorOccured = true;
|
||||||
destroyXmlParser(parser);
|
destroyXmlParser(parser);
|
||||||
|
|||||||
+1
-1
@@ -42,7 +42,7 @@ std::string Txt::getTitle() const {
|
|||||||
|
|
||||||
// Remove .txt extension
|
// Remove .txt extension
|
||||||
if (FsHelpers::hasTxtExtension(filename)) {
|
if (FsHelpers::hasTxtExtension(filename)) {
|
||||||
filename = filename.substr(0, filename.length() - 4);
|
filename.resize(filename.length() - 4);
|
||||||
}
|
}
|
||||||
|
|
||||||
return filename;
|
return filename;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <Logging.h>
|
#include <Logging.h>
|
||||||
#include <ObfuscationUtils.h>
|
#include <ObfuscationUtils.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -153,10 +154,6 @@ bool JsonSettingsIO::saveSettings(const CrossPointSettings& s, const char* path)
|
|||||||
// Stored as ISO code string ("EN", "DE", ...) for stability across enum reorders.
|
// Stored as ISO code string ("EN", "DE", ...) for stability across enum reorders.
|
||||||
doc["language"] = (s.language < getLanguageCount()) ? LANGUAGE_CODES[s.language] : "EN";
|
doc["language"] = (s.language < getLanguageCount()) ? LANGUAGE_CODES[s.language] : "EN";
|
||||||
|
|
||||||
// Language -- managed by LanguageSelectActivity, not in SettingsList.
|
|
||||||
// Stored as ISO code string ("EN", "DE", ...) for stability across enum reorders.
|
|
||||||
doc["language"] = (s.language < getLanguageCount()) ? LANGUAGE_CODES[s.language] : "EN";
|
|
||||||
|
|
||||||
String json;
|
String json;
|
||||||
serializeJson(doc, json);
|
serializeJson(doc, json);
|
||||||
return Storage.writeFile(path, json);
|
return Storage.writeFile(path, json);
|
||||||
@@ -345,6 +342,7 @@ bool JsonSettingsIO::loadRecentBooks(RecentBooksStore& store, const char* json)
|
|||||||
|
|
||||||
store.recentBooks.clear();
|
store.recentBooks.clear();
|
||||||
JsonArray arr = doc["books"].as<JsonArray>();
|
JsonArray arr = doc["books"].as<JsonArray>();
|
||||||
|
store.recentBooks.reserve(std::min(arr.size(), (size_t)10));
|
||||||
for (JsonObject obj : arr) {
|
for (JsonObject obj : arr) {
|
||||||
if (store.getCount() >= 10) break;
|
if (store.getCount() >= 10) break;
|
||||||
RecentBook book;
|
RecentBook book;
|
||||||
|
|||||||
@@ -34,10 +34,12 @@ void SdCardFontSystem::begin(GfxRenderer& renderer) {
|
|||||||
} else {
|
} else {
|
||||||
LOG_ERR("SDFS", "Failed to load SD font family: %s (clearing)", SETTINGS.sdFontFamilyName);
|
LOG_ERR("SDFS", "Failed to load SD font family: %s (clearing)", SETTINGS.sdFontFamilyName);
|
||||||
SETTINGS.sdFontFamilyName[0] = '\0';
|
SETTINGS.sdFontFamilyName[0] = '\0';
|
||||||
|
SETTINGS.saveToFile();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG_DBG("SDFS", "SD font family not found on card: %s (clearing)", SETTINGS.sdFontFamilyName);
|
LOG_DBG("SDFS", "SD font family not found on card: %s (clearing)", SETTINGS.sdFontFamilyName);
|
||||||
SETTINGS.sdFontFamilyName[0] = '\0';
|
SETTINGS.sdFontFamilyName[0] = '\0';
|
||||||
|
SETTINGS.saveToFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,6 +78,7 @@ void SdCardFontSystem::ensureLoaded(GfxRenderer& renderer) {
|
|||||||
LOG_DBG("SDFS", "SD font family disappeared: %s (clearing)", wantedFamily);
|
LOG_DBG("SDFS", "SD font family disappeared: %s (clearing)", wantedFamily);
|
||||||
manager_.unloadAll(renderer);
|
manager_.unloadAll(renderer);
|
||||||
SETTINGS.sdFontFamilyName[0] = '\0';
|
SETTINGS.sdFontFamilyName[0] = '\0';
|
||||||
|
SETTINGS.saveToFile();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto* selected = family->findClosestReaderSize(sizeEnum);
|
const auto* selected = family->findClosestReaderSize(sizeEnum);
|
||||||
@@ -96,10 +99,12 @@ void SdCardFontSystem::ensureLoaded(GfxRenderer& renderer) {
|
|||||||
} else {
|
} else {
|
||||||
LOG_ERR("SDFS", "Failed to load SD font family: %s (clearing)", wantedFamily);
|
LOG_ERR("SDFS", "Failed to load SD font family: %s (clearing)", wantedFamily);
|
||||||
SETTINGS.sdFontFamilyName[0] = '\0';
|
SETTINGS.sdFontFamilyName[0] = '\0';
|
||||||
|
SETTINGS.saveToFile();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LOG_DBG("SDFS", "SD font family not found: %s (clearing)", wantedFamily);
|
LOG_DBG("SDFS", "SD font family not found: %s (clearing)", wantedFamily);
|
||||||
SETTINGS.sdFontFamilyName[0] = '\0';
|
SETTINGS.sdFontFamilyName[0] = '\0';
|
||||||
|
SETTINGS.saveToFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
#include <ObfuscationUtils.h>
|
#include <ObfuscationUtils.h>
|
||||||
#include <Serialization.h>
|
#include <Serialization.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
// Initialize the static instance
|
// Initialize the static instance
|
||||||
WifiCredentialStore WifiCredentialStore::instance;
|
WifiCredentialStore WifiCredentialStore::instance;
|
||||||
|
|
||||||
@@ -89,6 +91,7 @@ bool WifiCredentialStore::loadFromBinaryFile() {
|
|||||||
serialization::readPod(file, count);
|
serialization::readPod(file, count);
|
||||||
|
|
||||||
credentials.clear();
|
credentials.clear();
|
||||||
|
credentials.reserve(std::min<size_t>(count, MAX_NETWORKS));
|
||||||
for (uint8_t i = 0; i < count && i < MAX_NETWORKS; i++) {
|
for (uint8_t i = 0; i < count && i < MAX_NETWORKS; i++) {
|
||||||
WifiCredential cred;
|
WifiCredential cred;
|
||||||
serialization::readString(file, cred.ssid);
|
serialization::readString(file, cred.ssid);
|
||||||
|
|||||||
@@ -336,7 +336,7 @@ std::string getFileName(std::string filename) {
|
|||||||
return filename.substr(0, pos);
|
return filename.substr(0, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string getFileExtension(std::string filename) {
|
std::string getFileExtension(const std::string& filename) {
|
||||||
if (filename.back() == '/') {
|
if (filename.back() == '/') {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user