From f7e292cb0395808e5dfa1dbf4c443350d35a4e5f Mon Sep 17 00:00:00 2001 From: Justin Oros Date: Wed, 22 Apr 2026 17:59:39 -0700 Subject: [PATCH] fix(bookerly): rewrite patch_settings_activity_cpp with correct string escaping --- plugins/bookerly/patch.py | 94 +++++++++++---------------------------- 1 file changed, 27 insertions(+), 67 deletions(-) diff --git a/plugins/bookerly/patch.py b/plugins/bookerly/patch.py index 8f208ab..5cb705b 100644 --- a/plugins/bookerly/patch.py +++ b/plugins/bookerly/patch.py @@ -271,97 +271,57 @@ def patch_settings_activity_cpp(repo_dir): content = content.replace( '#include "fontIds.h"', - '#include "fontIds.h" -#include "BookerlyPlugin.h"' + '#include "fontIds.h"\n#include "BookerlyPlugin.h"' ) - if 'pluginsSettings.push_back' not in content: + if 'SettingAction::BookerlyInstalled' not in content: content = content.replace( - ' readerSettings.push_back(SettingInfo::Action(StrId::STR_CUSTOMISE_STATUS_BAR, SettingAction::CustomiseStatusBar)); -', - ' readerSettings.push_back(SettingInfo::Action(StrId::STR_CUSTOMISE_STATUS_BAR, SettingAction::CustomiseStatusBar)); -' - ' pluginsSettings.push_back(SettingInfo::Action( -' - ' StrId::STR_NONE_OPT, SettingAction::BookerlyInstalled -' - ' )); -' - ) - elif 'BookerlyInstalled' not in content: - content = content.replace( - ' readerSettings.push_back(SettingInfo::Action(StrId::STR_CUSTOMISE_STATUS_BAR, SettingAction::CustomiseStatusBar)); -', - ' readerSettings.push_back(SettingInfo::Action(StrId::STR_CUSTOMISE_STATUS_BAR, SettingAction::CustomiseStatusBar)); -' - ' pluginsSettings.push_back(SettingInfo::Action( -' - ' StrId::STR_NONE_OPT, SettingAction::BookerlyInstalled -' - ' )); -' + ' readerSettings.push_back(SettingInfo::Action(StrId::STR_CUSTOMISE_STATUS_BAR, SettingAction::CustomiseStatusBar));\n', + ' readerSettings.push_back(SettingInfo::Action(StrId::STR_CUSTOMISE_STATUS_BAR, SettingAction::CustomiseStatusBar));\n' + ' pluginsSettings.push_back(SettingInfo::Action(\n' + ' StrId::STR_NONE_OPT, SettingAction::BookerlyInstalled\n' + ' ));\n' ) if '"Bookerly Plugin"' not in content: content = content.replace( ' [&settings](int index) { return std::string(I18N.get(settings[index].nameId)); }, nullptr, nullptr,', - ' [&settings, this](int index) -> std::string { -' - ' if (selectedCategoryIndex == 4) { -' - ' const auto& s = settings[index]; -' - ' if (s.type == SettingType::ACTION && s.action == SettingAction::BookerlyInstalled) return "Bookerly Plugin"; -' - ' } -' - ' return std::string(I18N.get(settings[index].nameId)); -' + ' [&settings, this](int index) -> std::string {\n' + ' if (selectedCategoryIndex == 4) {\n' + ' const auto& s = settings[index];\n' + ' if (s.type == SettingType::ACTION && s.action == SettingAction::BookerlyInstalled) return "Bookerly Plugin";\n' + ' }\n' + ' return std::string(I18N.get(settings[index].nameId));\n' ' }, nullptr, nullptr,' ) if '"Bookerly"' not in content: content = content.replace( - ' const uint8_t value = SETTINGS.*(setting.valuePtr); -' - ' valueText = I18N.get(setting.enumValues[value]); -', - ' const uint8_t value = SETTINGS.*(setting.valuePtr); -' - ' if (setting.key && std::string(setting.key) == "fontFamily" && value == CrossPointSettings::BOOKERLY) { -' - ' valueText = "Bookerly"; -' - ' } else { -' - ' valueText = I18N.get(setting.enumValues[value]); -' - ' } -' + ' const uint8_t value = SETTINGS.*(setting.valuePtr);\n' + ' valueText = I18N.get(setting.enumValues[value]);\n', + ' const uint8_t value = SETTINGS.*(setting.valuePtr);\n' + ' if (setting.key && std::string(setting.key) == "fontFamily" && value == CrossPointSettings::BOOKERLY) {\n' + ' valueText = "Bookerly";\n' + ' } else {\n' + ' valueText = I18N.get(setting.enumValues[value]);\n' + ' }\n' ) if '"Installed"' not in content: content = content.replace( - ' } else if (setting.type == SettingType::VALUE && setting.valuePtr != nullptr) { -' - ' valueText = std::to_string(SETTINGS.*(setting.valuePtr)); -' + ' } else if (setting.type == SettingType::VALUE && setting.valuePtr != nullptr) {\n' + ' valueText = std::to_string(SETTINGS.*(setting.valuePtr));\n' ' }', - ' } else if (setting.type == SettingType::ACTION && setting.action == SettingAction::BookerlyInstalled) { -' - ' valueText = "Installed"; -' - ' } else if (setting.type == SettingType::VALUE && setting.valuePtr != nullptr) { -' - ' valueText = std::to_string(SETTINGS.*(setting.valuePtr)); -' + ' } else if (setting.type == SettingType::ACTION && setting.action == SettingAction::BookerlyInstalled) {\n' + ' valueText = "Installed";\n' + ' } else if (setting.type == SettingType::VALUE && setting.valuePtr != nullptr) {\n' + ' valueText = std::to_string(SETTINGS.*(setting.valuePtr));\n' ' }' ) write_file(path, content) print(" SettingsActivity.cpp patched.") - def patch_web_server(repo_dir): path = find_first("CrossPointWebServer.cpp", repo_dir) content = read_file(path)