From 92bba6644221d4becebc9a34892322357f1e7269 Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 7 Sep 2024 11:25:49 +0200 Subject: [PATCH] WIP, revert me --- source/main.cpp | 3 +++ source/plugin/PluginContainer.cpp | 3 ++- source/utils/DrawUtils.cpp | 4 ++-- source/utils/DrawUtils.h | 6 +++--- source/utils/WUPSBackendSettings.cpp | 2 +- source/utils/config/ConfigDefines.h | 6 +++--- source/utils/config/ConfigRenderer.cpp | 19 +++++++++++++------ source/utils/config/ConfigUtils.cpp | 3 +++ source/utils/storage/StorageUtils.cpp | 17 +++++++++++++---- source/utils/utils.cpp | 12 ++++++------ source/utils/utils.h | 10 +++++++++- 11 files changed, 58 insertions(+), 27 deletions(-) diff --git a/source/main.cpp b/source/main.cpp index 1d443a0..bd6e023 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -87,6 +87,9 @@ WUMS_INITIALIZE() { } std::this_thread::sleep_for(16ms); } + DrawUtils::beginDraw(); + DrawUtils::clear(COLOR_BLACK); + DrawUtils::endDraw(); }); DEBUG_FUNCTION_LINE_INFO("Safe Mode activated!"); auto tobeIgnoredFilePath = getNonBaseAromaPluginFilenames(getPluginPath()); diff --git a/source/plugin/PluginContainer.cpp b/source/plugin/PluginContainer.cpp index 26f10f1..f88e154 100644 --- a/source/plugin/PluginContainer.cpp +++ b/source/plugin/PluginContainer.cpp @@ -76,7 +76,8 @@ WUPSStorageError PluginContainer::OpenStorage() { if (storageId.empty()) { return WUPS_STORAGE_ERROR_SUCCESS; } - auto res = StorageUtils::API::Internal::OpenStorage(storageId, mStorageRootItem); + + const auto res = StorageUtils::API::Internal::OpenStorage(storageId, mStorageRootItem); if (res != WUPS_STORAGE_ERROR_SUCCESS) { mStorageRootItem = nullptr; } diff --git a/source/utils/DrawUtils.cpp b/source/utils/DrawUtils.cpp index 955d392..12a9c1f 100644 --- a/source/utils/DrawUtils.cpp +++ b/source/utils/DrawUtils.cpp @@ -436,8 +436,8 @@ uint32_t DrawUtils::getTextWidth(const wchar_t *string) { return width; } -void DrawUtils::RenderScreen(const std::function& callback) { - gOnlyAcceptFromThread = OSGetCurrentThread(); +void DrawUtils::RenderScreen(const std::function &callback) { + gOnlyAcceptFromThread = OSGetCurrentThread(); bool wasHomeButtonMenuEnabled = OSIsHomeButtonMenuEnabled(); // Save copy of DC reg values diff --git a/source/utils/DrawUtils.h b/source/utils/DrawUtils.h index 843e361..22055fb 100644 --- a/source/utils/DrawUtils.h +++ b/source/utils/DrawUtils.h @@ -5,8 +5,8 @@ #include // visible screen sizes -#define SCREEN_WIDTH 854 -#define SCREEN_HEIGHT 480 +#define SCREEN_WIDTH 854 +#define SCREEN_HEIGHT 480 #define COLOR_BACKGROUND Color(238, 238, 238, 255) #define COLOR_BACKGROUND_WARN Color(255, 251, 4, 255) @@ -78,7 +78,7 @@ public: static uint32_t getTextWidth(const wchar_t *string); - static void RenderScreen(const std::function& callback); + static void RenderScreen(const std::function &callback); private: static bool mIsBackBuffer; diff --git a/source/utils/WUPSBackendSettings.cpp b/source/utils/WUPSBackendSettings.cpp index 1d3f483..b3e8b84 100644 --- a/source/utils/WUPSBackendSettings.cpp +++ b/source/utils/WUPSBackendSettings.cpp @@ -19,7 +19,7 @@ namespace WUPSBackendSettings { std::string folderPath = getModulePath() + "/configs/"; std::string filePath = folderPath + "wupsbackend.json"; - if (!ParseJsonFromFile(filePath, j)) { + if (ParseJsonFromFile(filePath, j) != UTILS_IO_ERROR_SUCCESS) { return false; } diff --git a/source/utils/config/ConfigDefines.h b/source/utils/config/ConfigDefines.h index b5f9325..a702632 100644 --- a/source/utils/config/ConfigDefines.h +++ b/source/utils/config/ConfigDefines.h @@ -3,7 +3,7 @@ #include #include -#define MAX_BUTTONS_ON_SCREEN 8 +#define MAX_BUTTONS_ON_SCREEN 8 struct StoredBuffer { void *buffer; @@ -16,6 +16,6 @@ struct StoredBuffer { enum ConfigSubState { SUB_STATE_RUNNING = 0, SUB_STATE_RETURN = 1, - SUB_STATE_RETURN_WITH_PLUGIN_RELOAD = 1, - SUB_STATE_ERROR = 2, + SUB_STATE_RETURN_WITH_PLUGIN_RELOAD = 2, + SUB_STATE_ERROR = 3, }; \ No newline at end of file diff --git a/source/utils/config/ConfigRenderer.cpp b/source/utils/config/ConfigRenderer.cpp index 91720e5..9a23b8e 100644 --- a/source/utils/config/ConfigRenderer.cpp +++ b/source/utils/config/ConfigRenderer.cpp @@ -26,8 +26,9 @@ ConfigSubState ConfigRenderer::Update(Input &input, const WUPSConfigSimplePadDat if (mCategoryRenderer) { auto subResult = mCategoryRenderer->Update(input, simpleInputData, complexInputData); if (subResult != SUB_STATE_RUNNING) { - mNeedRedraw = true; - mState = STATE_MAIN; + mNeedRedraw = true; + mActivePluginsDirty = false; + mState = STATE_MAIN; return SUB_STATE_RUNNING; } return SUB_STATE_RUNNING; @@ -76,7 +77,13 @@ void ConfigRenderer::ResetNeedsRedraw() { ConfigSubState ConfigRenderer::UpdateStateMain(const Input &input) { auto &configs = GetConfigList(); - auto prevSelectedItem = mCursorPos; + const auto prevSelectedItem = mCursorPos; + + const auto& savePendingConfigFn = [&configs, this]() { + for (const auto &element : configs) { + CallOnCloseCallback(element.get().getConfigInformation(), element.get().getConfig()); + } + }; if (input.data.buttons_d & Input::eButtons::BUTTON_DOWN) { mCursorPos++; @@ -86,6 +93,7 @@ ConfigSubState ConfigRenderer::UpdateStateMain(const Input &input) { if (mSetActivePluginsMode) { mNeedRedraw = true; mCategoryRenderer.reset(); + savePendingConfigFn(); return SUB_STATE_RETURN_WITH_PLUGIN_RELOAD; } } else if (input.data.buttons_d & Input::eButtons::BUTTON_X) { @@ -115,15 +123,14 @@ ConfigSubState ConfigRenderer::UpdateStateMain(const Input &input) { for (auto &cur : mConfigs) { cur.resetIsActivePlugin(); } + mActivePluginsDirty = false; mNeedRedraw = true; mSetActivePluginsMode = false; return SUB_STATE_RUNNING; } else { mNeedRedraw = true; mCategoryRenderer.reset(); - for (const auto &element : configs) { - CallOnCloseCallback(element.get().getConfigInformation(), element.get().getConfig()); - } + savePendingConfigFn(); return SUB_STATE_RETURN; } } diff --git a/source/utils/config/ConfigUtils.cpp b/source/utils/config/ConfigUtils.cpp index 9ee5f06..3929c41 100644 --- a/source/utils/config/ConfigUtils.cpp +++ b/source/utils/config/ConfigUtils.cpp @@ -221,6 +221,9 @@ void ConfigUtils::displayMenu() { std::vector newActivePluginsList; + DEBUG_FUNCTION_LINE_ERR("%d", subStateReturnValue); + DEBUG_FUNCTION_LINE_ERR("%d", subStateReturnValue == SUB_STATE_RETURN_WITH_PLUGIN_RELOAD); + if (subStateReturnValue == SUB_STATE_RETURN_WITH_PLUGIN_RELOAD && renderer.GetActivePluginsIfChanged(newActivePluginsList)) { startTime = OSGetTime(); renderBasicScreen("Applying changes, app will now restart..."); diff --git a/source/utils/storage/StorageUtils.cpp b/source/utils/storage/StorageUtils.cpp index d7f7eb1..59b68de 100644 --- a/source/utils/storage/StorageUtils.cpp +++ b/source/utils/storage/StorageUtils.cpp @@ -172,11 +172,20 @@ namespace StorageUtils { return nullptr; } - WUPSStorageError LoadFromFile(std::string_view plugin_id, nlohmann::json &outJson) { - const std::string filePath = getPluginPath() + "/config/" + plugin_id.data() + ".json"; - if (ParseJsonFromFile(filePath, outJson)) { - return WUPS_STORAGE_ERROR_SUCCESS; + WUPSStorageError LoadFromFile(const std::string_view plugin_id, nlohmann::json &outJson) { + switch (const std::string filePath = getPluginPath() + "/config/" + plugin_id.data() + ".json"; ParseJsonFromFile(filePath, outJson)) { + case UTILS_IO_ERROR_SUCCESS: + return WUPS_STORAGE_ERROR_SUCCESS; + case UTILS_IO_ERROR_INVALID_ARGS: + return WUPS_STORAGE_ERROR_INVALID_ARGS; + case UTILS_IO_ERROR_MALLOC_FAILED: + return WUPS_STORAGE_ERROR_MALLOC_FAILED; + case UTILS_IO_ERROR_GENERIC: + return WUPS_STORAGE_ERROR_IO_ERROR; + case UTILS_IO_ERROR_NOT_FOUND: + return WUPS_STORAGE_ERROR_NOT_FOUND; } + return WUPS_STORAGE_ERROR_IO_ERROR; } diff --git a/source/utils/utils.cpp b/source/utils/utils.cpp index 5cd464c..8f3a80b 100644 --- a/source/utils/utils.cpp +++ b/source/utils/utils.cpp @@ -116,22 +116,22 @@ void CustomDynLoadFree(void *addr) { } } -bool ParseJsonFromFile(const std::string &filePath, nlohmann::json &outJson) { +UtilsIOError ParseJsonFromFile(const std::string &filePath, nlohmann::json &outJson) { CFile file(filePath, CFile::ReadOnly); if (!file.isOpen() || file.size() == 0) { - return false; + return UTILS_IO_ERROR_NOT_FOUND; } - auto *json_data = (uint8_t *) memalign(0x40, ROUNDUP(file.size() + 1, 0x40)); + auto *json_data = static_cast(memalign(0x40, ROUNDUP(file.size() + 1, 0x40))); if (!json_data) { - return false; + return UTILS_IO_ERROR_MALLOC_FAILED; } - bool result = true; + auto result = UTILS_IO_ERROR_SUCCESS; uint64_t readRes = file.read(json_data, file.size()); if (readRes == file.size()) { json_data[file.size()] = '\0'; outJson = nlohmann::json::parse(json_data, nullptr, false); } else { - result = false; + result = UTILS_IO_ERROR_GENERIC; } file.close(); free(json_data); diff --git a/source/utils/utils.h b/source/utils/utils.h index 2539d54..dafdd3d 100644 --- a/source/utils/utils.h +++ b/source/utils/utils.h @@ -136,6 +136,14 @@ void append_move_all_values(Container &dest, Container &src) { src.clear(); } +typedef enum { + UTILS_IO_ERROR_SUCCESS = 0, /**< Success. */ + UTILS_IO_ERROR_INVALID_ARGS = -0x01, /**< Invalid arguments passed to the function. */ + UTILS_IO_ERROR_MALLOC_FAILED = -0x02, /**< Memory allocation failed. */ + UTILS_IO_ERROR_GENERIC = -0x03, /**< Generic IO error during saving or loading. */ + UTILS_IO_ERROR_NOT_FOUND = -0x4, /**< Item not found. */ +} UtilsIOError; + std::string getPluginPath(); std::string getModulePath(); @@ -144,7 +152,7 @@ OSDynLoad_Error CustomDynLoadAlloc(int32_t size, int32_t align, void **outAddr); void CustomDynLoadFree(void *addr); -bool ParseJsonFromFile(const std::string &filePath, nlohmann::json &outJson); +UtilsIOError ParseJsonFromFile(const std::string &filePath, nlohmann::json &outJson); std::vector getPluginFilePaths(std::string_view basePath);