WIP, revert me

This commit is contained in:
Maschell 2024-09-07 11:25:49 +02:00
parent 9052ecb2b2
commit 92bba66442
11 changed files with 58 additions and 27 deletions

View File

@ -87,6 +87,9 @@ WUMS_INITIALIZE() {
} }
std::this_thread::sleep_for(16ms); std::this_thread::sleep_for(16ms);
} }
DrawUtils::beginDraw();
DrawUtils::clear(COLOR_BLACK);
DrawUtils::endDraw();
}); });
DEBUG_FUNCTION_LINE_INFO("Safe Mode activated!"); DEBUG_FUNCTION_LINE_INFO("Safe Mode activated!");
auto tobeIgnoredFilePath = getNonBaseAromaPluginFilenames(getPluginPath()); auto tobeIgnoredFilePath = getNonBaseAromaPluginFilenames(getPluginPath());

View File

@ -76,7 +76,8 @@ WUPSStorageError PluginContainer::OpenStorage() {
if (storageId.empty()) { if (storageId.empty()) {
return WUPS_STORAGE_ERROR_SUCCESS; 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) { if (res != WUPS_STORAGE_ERROR_SUCCESS) {
mStorageRootItem = nullptr; mStorageRootItem = nullptr;
} }

View File

@ -436,7 +436,7 @@ uint32_t DrawUtils::getTextWidth(const wchar_t *string) {
return width; return width;
} }
void DrawUtils::RenderScreen(const std::function<void()>& callback) { void DrawUtils::RenderScreen(const std::function<void()> &callback) {
gOnlyAcceptFromThread = OSGetCurrentThread(); gOnlyAcceptFromThread = OSGetCurrentThread();
bool wasHomeButtonMenuEnabled = OSIsHomeButtonMenuEnabled(); bool wasHomeButtonMenuEnabled = OSIsHomeButtonMenuEnabled();

View File

@ -78,7 +78,7 @@ public:
static uint32_t getTextWidth(const wchar_t *string); static uint32_t getTextWidth(const wchar_t *string);
static void RenderScreen(const std::function<void()>& callback); static void RenderScreen(const std::function<void()> &callback);
private: private:
static bool mIsBackBuffer; static bool mIsBackBuffer;

View File

@ -19,7 +19,7 @@ namespace WUPSBackendSettings {
std::string folderPath = getModulePath() + "/configs/"; std::string folderPath = getModulePath() + "/configs/";
std::string filePath = folderPath + "wupsbackend.json"; std::string filePath = folderPath + "wupsbackend.json";
if (!ParseJsonFromFile(filePath, j)) { if (ParseJsonFromFile(filePath, j) != UTILS_IO_ERROR_SUCCESS) {
return false; return false;
} }

View File

@ -16,6 +16,6 @@ struct StoredBuffer {
enum ConfigSubState { enum ConfigSubState {
SUB_STATE_RUNNING = 0, SUB_STATE_RUNNING = 0,
SUB_STATE_RETURN = 1, SUB_STATE_RETURN = 1,
SUB_STATE_RETURN_WITH_PLUGIN_RELOAD = 1, SUB_STATE_RETURN_WITH_PLUGIN_RELOAD = 2,
SUB_STATE_ERROR = 2, SUB_STATE_ERROR = 3,
}; };

View File

@ -27,6 +27,7 @@ ConfigSubState ConfigRenderer::Update(Input &input, const WUPSConfigSimplePadDat
auto subResult = mCategoryRenderer->Update(input, simpleInputData, complexInputData); auto subResult = mCategoryRenderer->Update(input, simpleInputData, complexInputData);
if (subResult != SUB_STATE_RUNNING) { if (subResult != SUB_STATE_RUNNING) {
mNeedRedraw = true; mNeedRedraw = true;
mActivePluginsDirty = false;
mState = STATE_MAIN; mState = STATE_MAIN;
return SUB_STATE_RUNNING; return SUB_STATE_RUNNING;
} }
@ -76,7 +77,13 @@ void ConfigRenderer::ResetNeedsRedraw() {
ConfigSubState ConfigRenderer::UpdateStateMain(const Input &input) { ConfigSubState ConfigRenderer::UpdateStateMain(const Input &input) {
auto &configs = GetConfigList(); 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) { if (input.data.buttons_d & Input::eButtons::BUTTON_DOWN) {
mCursorPos++; mCursorPos++;
@ -86,6 +93,7 @@ ConfigSubState ConfigRenderer::UpdateStateMain(const Input &input) {
if (mSetActivePluginsMode) { if (mSetActivePluginsMode) {
mNeedRedraw = true; mNeedRedraw = true;
mCategoryRenderer.reset(); mCategoryRenderer.reset();
savePendingConfigFn();
return SUB_STATE_RETURN_WITH_PLUGIN_RELOAD; return SUB_STATE_RETURN_WITH_PLUGIN_RELOAD;
} }
} else if (input.data.buttons_d & Input::eButtons::BUTTON_X) { } else if (input.data.buttons_d & Input::eButtons::BUTTON_X) {
@ -115,15 +123,14 @@ ConfigSubState ConfigRenderer::UpdateStateMain(const Input &input) {
for (auto &cur : mConfigs) { for (auto &cur : mConfigs) {
cur.resetIsActivePlugin(); cur.resetIsActivePlugin();
} }
mActivePluginsDirty = false;
mNeedRedraw = true; mNeedRedraw = true;
mSetActivePluginsMode = false; mSetActivePluginsMode = false;
return SUB_STATE_RUNNING; return SUB_STATE_RUNNING;
} else { } else {
mNeedRedraw = true; mNeedRedraw = true;
mCategoryRenderer.reset(); mCategoryRenderer.reset();
for (const auto &element : configs) { savePendingConfigFn();
CallOnCloseCallback(element.get().getConfigInformation(), element.get().getConfig());
}
return SUB_STATE_RETURN; return SUB_STATE_RETURN;
} }
} }

View File

@ -221,6 +221,9 @@ void ConfigUtils::displayMenu() {
std::vector<PluginLoadWrapper> newActivePluginsList; std::vector<PluginLoadWrapper> 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)) { if (subStateReturnValue == SUB_STATE_RETURN_WITH_PLUGIN_RELOAD && renderer.GetActivePluginsIfChanged(newActivePluginsList)) {
startTime = OSGetTime(); startTime = OSGetTime();
renderBasicScreen("Applying changes, app will now restart..."); renderBasicScreen("Applying changes, app will now restart...");

View File

@ -172,11 +172,20 @@ namespace StorageUtils {
return nullptr; return nullptr;
} }
WUPSStorageError LoadFromFile(std::string_view plugin_id, nlohmann::json &outJson) { WUPSStorageError LoadFromFile(const std::string_view plugin_id, nlohmann::json &outJson) {
const std::string filePath = getPluginPath() + "/config/" + plugin_id.data() + ".json"; switch (const std::string filePath = getPluginPath() + "/config/" + plugin_id.data() + ".json"; ParseJsonFromFile(filePath, outJson)) {
if (ParseJsonFromFile(filePath, outJson)) { case UTILS_IO_ERROR_SUCCESS:
return WUPS_STORAGE_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; return WUPS_STORAGE_ERROR_IO_ERROR;
} }

View File

@ -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); CFile file(filePath, CFile::ReadOnly);
if (!file.isOpen() || file.size() == 0) { 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<uint8_t *>(memalign(0x40, ROUNDUP(file.size() + 1, 0x40)));
if (!json_data) { 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()); uint64_t readRes = file.read(json_data, file.size());
if (readRes == file.size()) { if (readRes == file.size()) {
json_data[file.size()] = '\0'; json_data[file.size()] = '\0';
outJson = nlohmann::json::parse(json_data, nullptr, false); outJson = nlohmann::json::parse(json_data, nullptr, false);
} else { } else {
result = false; result = UTILS_IO_ERROR_GENERIC;
} }
file.close(); file.close();
free(json_data); free(json_data);

View File

@ -136,6 +136,14 @@ void append_move_all_values(Container &dest, Container &src) {
src.clear(); 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 getPluginPath();
std::string getModulePath(); std::string getModulePath();
@ -144,7 +152,7 @@ OSDynLoad_Error CustomDynLoadAlloc(int32_t size, int32_t align, void **outAddr);
void CustomDynLoadFree(void *addr); void CustomDynLoadFree(void *addr);
bool ParseJsonFromFile(const std::string &filePath, nlohmann::json &outJson); UtilsIOError ParseJsonFromFile(const std::string &filePath, nlohmann::json &outJson);
std::vector<std::string> getPluginFilePaths(std::string_view basePath); std::vector<std::string> getPluginFilePaths(std::string_view basePath);