refactor: Eliminated relative path includes (#1961)
## Summary Relative includes can hide inappropriate dependency relationships. In this case, I found that lib/KOReaderSync/KOReaderCredentialStore.cpp was dependent on src/JsonSettingsIO.h -- a lib -> app dependency, the opposite direction dependencies should flow in this project. This change replaces all relative includes with root-relative includes, and corrects the KOReaderCredentialStore dependency by moving its JSON settings serialization local to the KOReaderSync library. --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? _**PARTIALLY**_
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
#include <Logging.h>
|
||||
#include <Serialization.h>
|
||||
|
||||
#include "../converters/DirectPixelWriter.h"
|
||||
#include "../converters/ImageDecoderFactory.h"
|
||||
#include "Epub/converters/DirectPixelWriter.h"
|
||||
#include "Epub/converters/ImageDecoderFactory.h"
|
||||
|
||||
// Cache file format:
|
||||
// - uint16_t width
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "../SerializedHyphenationTrie.h"
|
||||
#include "Epub/hyphenation/SerializedHyphenationTrie.h"
|
||||
|
||||
// Auto-generated by generate_hyphenation_trie.py. Do not edit manually.
|
||||
alignas(4) constexpr uint8_t de_trie_data[] = {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "../SerializedHyphenationTrie.h"
|
||||
#include "Epub/hyphenation/SerializedHyphenationTrie.h"
|
||||
|
||||
// Auto-generated by generate_hyphenation_trie.py. Do not edit manually.
|
||||
alignas(4) constexpr uint8_t en_trie_data[] = {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "../SerializedHyphenationTrie.h"
|
||||
#include "Epub/hyphenation/SerializedHyphenationTrie.h"
|
||||
|
||||
// Auto-generated by generate_hyphenation_trie.py. Do not edit manually.
|
||||
alignas(4) constexpr uint8_t es_trie_data[] = {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "../SerializedHyphenationTrie.h"
|
||||
#include "Epub/hyphenation/SerializedHyphenationTrie.h"
|
||||
|
||||
// Auto-generated by generate_hyphenation_trie.py. Do not edit manually.
|
||||
alignas(4) constexpr uint8_t fr_trie_data[] = {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "../SerializedHyphenationTrie.h"
|
||||
#include "Epub/hyphenation/SerializedHyphenationTrie.h"
|
||||
|
||||
// Auto-generated by generate_hyphenation_trie.py. Do not edit manually.
|
||||
alignas(4) constexpr uint8_t it_trie_data[] = {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "../SerializedHyphenationTrie.h"
|
||||
#include "Epub/hyphenation/SerializedHyphenationTrie.h"
|
||||
|
||||
// Auto-generated by generate_hyphenation_trie.py. Do not edit manually.
|
||||
alignas(4) constexpr uint8_t ru_trie_data[] = {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "../SerializedHyphenationTrie.h"
|
||||
#include "Epub/hyphenation/SerializedHyphenationTrie.h"
|
||||
|
||||
// Auto-generated by generate_hyphenation_trie.py. Do not edit manually.
|
||||
alignas(4) constexpr uint8_t uk_trie_data[] = {
|
||||
|
||||
@@ -10,11 +10,11 @@
|
||||
|
||||
#include <iterator>
|
||||
|
||||
#include "../../Epub.h"
|
||||
#include "../Page.h"
|
||||
#include "../converters/ImageDecoderFactory.h"
|
||||
#include "../converters/ImageToFramebufferDecoder.h"
|
||||
#include "../htmlEntities.h"
|
||||
#include "Epub.h"
|
||||
#include "Epub/Page.h"
|
||||
#include "Epub/converters/ImageDecoderFactory.h"
|
||||
#include "Epub/converters/ImageToFramebufferDecoder.h"
|
||||
#include "Epub/htmlEntities.h"
|
||||
|
||||
// Minimum file size (in bytes) to show indexing popup - smaller chapters don't benefit from it
|
||||
constexpr size_t MIN_SIZE_FOR_POPUP = 10 * 1024; // 10KB
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "../FootnoteEntry.h"
|
||||
#include "../ParsedText.h"
|
||||
#include "../blocks/ImageBlock.h"
|
||||
#include "../blocks/TextBlock.h"
|
||||
#include "../css/CssParser.h"
|
||||
#include "../css/CssStyle.h"
|
||||
#include "Epub/FootnoteEntry.h"
|
||||
#include "Epub/ParsedText.h"
|
||||
#include "Epub/blocks/ImageBlock.h"
|
||||
#include "Epub/blocks/TextBlock.h"
|
||||
#include "Epub/css/CssParser.h"
|
||||
#include "Epub/css/CssStyle.h"
|
||||
|
||||
class Page;
|
||||
class GfxRenderer;
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <Serialization.h>
|
||||
#include <XmlParserUtils.h>
|
||||
|
||||
#include "../BookMetadataCache.h"
|
||||
#include "Epub/BookMetadataCache.h"
|
||||
|
||||
namespace {
|
||||
constexpr char MEDIA_TYPE_NCX[] = "application/x-dtbncx+xml";
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <Logging.h>
|
||||
#include <XmlParserUtils.h>
|
||||
|
||||
#include "../BookMetadataCache.h"
|
||||
#include "Epub/BookMetadataCache.h"
|
||||
|
||||
bool TocNavParser::setup() {
|
||||
parser = XML_ParserCreate(nullptr);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <Logging.h>
|
||||
#include <XmlParserUtils.h>
|
||||
|
||||
#include "../BookMetadataCache.h"
|
||||
#include "Epub/BookMetadataCache.h"
|
||||
|
||||
bool TocNcxParser::setup() {
|
||||
parser = XML_ParserCreate(nullptr);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <ObfuscationUtils.h>
|
||||
#include <Serialization.h>
|
||||
|
||||
#include "../../src/JsonSettingsIO.h"
|
||||
#include "KOReaderJsonIO.h"
|
||||
|
||||
// Initialize the static instance
|
||||
KOReaderCredentialStore KOReaderCredentialStore::instance;
|
||||
@@ -36,7 +36,7 @@ void legacyDeobfuscate(std::string& data) {
|
||||
|
||||
bool KOReaderCredentialStore::saveToFile() const {
|
||||
Storage.mkdir("/.crosspoint");
|
||||
return JsonSettingsIO::saveKOReader(*this, KOREADER_FILE_JSON);
|
||||
return KOReaderJsonIO::save(*this, KOREADER_FILE_JSON);
|
||||
}
|
||||
|
||||
bool KOReaderCredentialStore::loadFromFile() {
|
||||
@@ -45,7 +45,7 @@ bool KOReaderCredentialStore::loadFromFile() {
|
||||
String json = Storage.readFile(KOREADER_FILE_JSON);
|
||||
if (!json.isEmpty()) {
|
||||
bool resave = false;
|
||||
bool result = JsonSettingsIO::loadKOReader(*this, json.c_str(), &resave);
|
||||
bool result = KOReaderJsonIO::load(*this, json.c_str(), &resave);
|
||||
if (result && resave) {
|
||||
saveToFile();
|
||||
LOG_DBG("KRS", "Resaved KOReader credentials to update format");
|
||||
|
||||
@@ -8,12 +8,6 @@ enum class DocumentMatchMethod : uint8_t {
|
||||
BINARY = 1, // Match by partial MD5 of file content (more accurate, but files must be identical)
|
||||
};
|
||||
|
||||
class KOReaderCredentialStore;
|
||||
namespace JsonSettingsIO {
|
||||
bool saveKOReader(const KOReaderCredentialStore& store, const char* path);
|
||||
bool loadKOReader(KOReaderCredentialStore& store, const char* json, bool* needsResave);
|
||||
} // namespace JsonSettingsIO
|
||||
|
||||
/**
|
||||
* Singleton class for storing KOReader sync credentials on the SD card.
|
||||
* Passwords are XOR-obfuscated with the device's unique hardware MAC address
|
||||
@@ -33,9 +27,6 @@ class KOReaderCredentialStore {
|
||||
|
||||
bool loadFromBinaryFile();
|
||||
|
||||
friend bool JsonSettingsIO::saveKOReader(const KOReaderCredentialStore&, const char*);
|
||||
friend bool JsonSettingsIO::loadKOReader(KOReaderCredentialStore&, const char*, bool*);
|
||||
|
||||
public:
|
||||
// Delete copy constructor and assignment
|
||||
KOReaderCredentialStore(const KOReaderCredentialStore&) = delete;
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
#include "KOReaderJsonIO.h"
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <HalStorage.h>
|
||||
#include <Logging.h>
|
||||
#include <ObfuscationUtils.h>
|
||||
|
||||
#include "KOReaderCredentialStore.h"
|
||||
|
||||
namespace KOReaderJsonIO {
|
||||
|
||||
bool save(const KOReaderCredentialStore& store, const char* path) {
|
||||
JsonDocument doc;
|
||||
doc["username"] = store.getUsername();
|
||||
doc["password_obf"] = obfuscation::obfuscateToBase64(store.getPassword());
|
||||
doc["serverUrl"] = store.getServerUrl();
|
||||
doc["matchMethod"] = static_cast<uint8_t>(store.getMatchMethod());
|
||||
|
||||
String json;
|
||||
serializeJson(doc, json);
|
||||
return Storage.writeFile(path, json);
|
||||
}
|
||||
|
||||
bool load(KOReaderCredentialStore& store, const char* json, bool* needsResave) {
|
||||
if (needsResave) *needsResave = false;
|
||||
JsonDocument doc;
|
||||
auto error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
LOG_ERR("KRS", "JSON parse error: %s", error.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string user = doc["username"] | std::string("");
|
||||
|
||||
bool ok = false;
|
||||
std::string pass = obfuscation::deobfuscateFromBase64(doc["password_obf"] | "", &ok);
|
||||
if (!ok || pass.empty()) {
|
||||
pass = doc["password"] | std::string("");
|
||||
if (!pass.empty() && needsResave) *needsResave = true;
|
||||
}
|
||||
|
||||
store.setCredentials(user, pass);
|
||||
store.setServerUrl(doc["serverUrl"] | std::string(""));
|
||||
|
||||
uint8_t method = doc["matchMethod"] | (uint8_t)0;
|
||||
store.setMatchMethod(static_cast<DocumentMatchMethod>(method));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace KOReaderJsonIO
|
||||
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
class KOReaderCredentialStore;
|
||||
|
||||
namespace KOReaderJsonIO {
|
||||
bool save(const KOReaderCredentialStore& store, const char* path);
|
||||
bool load(KOReaderCredentialStore& store, const char* json, bool* needsResave);
|
||||
} // namespace KOReaderJsonIO
|
||||
@@ -60,7 +60,7 @@ def write_header(path: pathlib.Path, blob: bytes, symbol: str) -> None:
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
#include "../SerializedHyphenationTrie.h"
|
||||
#include "Epub/hyphenation/SerializedHyphenationTrie.h"
|
||||
|
||||
// Auto-generated by generate_hyphenation_trie.py. Do not edit manually.
|
||||
alignas(4) constexpr uint8_t {data_symbol}[] = {{
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
#include "CrossPointSettings.h"
|
||||
#include "CrossPointState.h"
|
||||
#include "KOReaderCredentialStore.h"
|
||||
#include "OpdsServerStore.h"
|
||||
#include "RecentBooksStore.h"
|
||||
#include "SettingsList.h"
|
||||
@@ -251,44 +250,6 @@ bool JsonSettingsIO::loadSettings(CrossPointSettings& s, const char* json, bool*
|
||||
return true;
|
||||
}
|
||||
|
||||
// ---- KOReaderCredentialStore ----
|
||||
|
||||
bool JsonSettingsIO::saveKOReader(const KOReaderCredentialStore& store, const char* path) {
|
||||
JsonDocument doc;
|
||||
doc["username"] = store.getUsername();
|
||||
doc["password_obf"] = obfuscation::obfuscateToBase64(store.getPassword());
|
||||
doc["serverUrl"] = store.getServerUrl();
|
||||
doc["matchMethod"] = static_cast<uint8_t>(store.getMatchMethod());
|
||||
|
||||
String json;
|
||||
serializeJson(doc, json);
|
||||
return Storage.writeFile(path, json);
|
||||
}
|
||||
|
||||
bool JsonSettingsIO::loadKOReader(KOReaderCredentialStore& store, const char* json, bool* needsResave) {
|
||||
if (needsResave) *needsResave = false;
|
||||
JsonDocument doc;
|
||||
auto error = deserializeJson(doc, json);
|
||||
if (error) {
|
||||
LOG_ERR("KRS", "JSON parse error: %s", error.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
store.username = doc["username"] | std::string("");
|
||||
bool ok = false;
|
||||
store.password = obfuscation::deobfuscateFromBase64(doc["password_obf"] | "", &ok);
|
||||
if (!ok || store.password.empty()) {
|
||||
store.password = doc["password"] | std::string("");
|
||||
if (!store.password.empty() && needsResave) *needsResave = true;
|
||||
}
|
||||
store.serverUrl = doc["serverUrl"] | std::string("");
|
||||
uint8_t method = doc["matchMethod"] | (uint8_t)0;
|
||||
store.matchMethod = static_cast<DocumentMatchMethod>(method);
|
||||
|
||||
LOG_DBG("KRS", "Loaded KOReader credentials for user: %s", store.username.c_str());
|
||||
return true;
|
||||
}
|
||||
|
||||
// ---- WifiCredentialStore ----
|
||||
|
||||
bool JsonSettingsIO::saveWifi(const WifiCredentialStore& store, const char* path) {
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
class CrossPointSettings;
|
||||
class CrossPointState;
|
||||
class WifiCredentialStore;
|
||||
class KOReaderCredentialStore;
|
||||
class RecentBooksStore;
|
||||
class OpdsServerStore;
|
||||
|
||||
@@ -21,10 +20,6 @@ bool loadState(CrossPointState& s, const char* json);
|
||||
bool saveWifi(const WifiCredentialStore& store, const char* path);
|
||||
bool loadWifi(WifiCredentialStore& store, const char* json, bool* needsResave = nullptr);
|
||||
|
||||
// KOReaderCredentialStore
|
||||
bool saveKOReader(const KOReaderCredentialStore& store, const char* path);
|
||||
bool loadKOReader(KOReaderCredentialStore& store, const char* json, bool* needsResave = nullptr);
|
||||
|
||||
// RecentBooksStore
|
||||
bool saveRecentBooks(const RecentBooksStore& store, const char* path);
|
||||
bool loadRecentBooks(RecentBooksStore& store, const char* json);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "../Activity.h"
|
||||
#include "activities/Activity.h"
|
||||
|
||||
class BootActivity final : public Activity {
|
||||
public:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "../Activity.h"
|
||||
#include "activities/Activity.h"
|
||||
|
||||
class Bitmap;
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "../Activity.h"
|
||||
#include "OpdsServerStore.h"
|
||||
#include "activities/Activity.h"
|
||||
#include "util/ButtonNavigator.h"
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#pragma once
|
||||
#include "../Activity.h"
|
||||
#include "activities/Activity.h"
|
||||
|
||||
class CrashActivity final : public Activity {
|
||||
std::string panicMessage;
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "../util/ConfirmationActivity.h"
|
||||
#include "CrossPointSettings.h"
|
||||
#include "MappedInputManager.h"
|
||||
#include "activities/util/ConfirmationActivity.h"
|
||||
#include "components/UITheme.h"
|
||||
#include "fontIds.h"
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "../Activity.h"
|
||||
#include "RecentBooksStore.h"
|
||||
#include "activities/Activity.h"
|
||||
#include "util/ButtonNavigator.h"
|
||||
|
||||
class FileBrowserActivity final : public Activity {
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "../Activity.h"
|
||||
#include "./FileBrowserActivity.h"
|
||||
#include "activities/Activity.h"
|
||||
#include "util/ButtonNavigator.h"
|
||||
|
||||
struct RecentBook;
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "../Activity.h"
|
||||
#include "RecentBooksStore.h"
|
||||
#include "activities/Activity.h"
|
||||
#include "util/ButtonNavigator.h"
|
||||
|
||||
class RecentBooksActivity final : public Activity {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "../Activity.h"
|
||||
#include "activities/Activity.h"
|
||||
#include "util/ButtonNavigator.h"
|
||||
|
||||
enum class NetworkMode { JOIN_NETWORK, CONNECT_CALIBRE, CREATE_HOTSPOT };
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "../Activity.h"
|
||||
#include "activities/Activity.h"
|
||||
#include "util/ButtonNavigator.h"
|
||||
|
||||
class EpubReaderChapterSelectionActivity final : public Activity {
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "../Activity.h"
|
||||
#include "activities/Activity.h"
|
||||
#include "util/ButtonNavigator.h"
|
||||
|
||||
class EpubReaderFootnotesActivity final : public Activity {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "../Activity.h"
|
||||
#include "activities/Activity.h"
|
||||
#include "util/ButtonNavigator.h"
|
||||
|
||||
class EpubReaderMenuActivity final : public Activity {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
#include <memory>
|
||||
|
||||
#include "../Activity.h"
|
||||
#include "activities/Activity.h"
|
||||
#include "activities/home/FileBrowserActivity.h"
|
||||
|
||||
class Epub;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "../Activity.h"
|
||||
#include "activities/Activity.h"
|
||||
#include "util/ButtonNavigator.h"
|
||||
|
||||
class XtcReaderChapterSelectionActivity final : public Activity {
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include "../Activity.h"
|
||||
#include "activities/Activity.h"
|
||||
#include "components/UITheme.h"
|
||||
#include "util/ButtonNavigator.h"
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
#include "../Activity.h"
|
||||
#include "MappedInputManager.h"
|
||||
#include "activities/Activity.h"
|
||||
|
||||
class BmpViewerActivity final : public Activity {
|
||||
public:
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
#include <I18n.h>
|
||||
|
||||
#include "../../components/UITheme.h"
|
||||
#include "HalDisplay.h"
|
||||
#include "components/UITheme.h"
|
||||
|
||||
ConfirmationActivity::ConfirmationActivity(GfxRenderer& renderer, MappedInputManager& mappedInput,
|
||||
const std::string& heading, const std::string& body)
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
#include "../../fontIds.h"
|
||||
#include "../Activity.h"
|
||||
#include "activities/Activity.h"
|
||||
#include "fontIds.h"
|
||||
|
||||
class ConfirmationActivity : public Activity {
|
||||
private:
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "../Activity.h"
|
||||
#include "activities/Activity.h"
|
||||
|
||||
class FullScreenMessageActivity final : public Activity {
|
||||
std::string text;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "../Activity.h"
|
||||
#include "activities/Activity.h"
|
||||
#include "util/ButtonNavigator.h"
|
||||
|
||||
struct KeyDef {
|
||||
|
||||
Reference in New Issue
Block a user