From ca9a26bd0dacaad0eb87573b566870498368ba8e Mon Sep 17 00:00:00 2001 From: joel16 Date: Sat, 6 Jan 2024 11:27:37 -0500 Subject: [PATCH] utils: Use VLF's PspCtrlExtension instead of our own --- app/include/utils.h | 4 -- app/source/gui.c | 4 +- app/source/main.c | 7 +-- app/source/utils.c | 114 -------------------------------------------- 4 files changed, 3 insertions(+), 126 deletions(-) diff --git a/app/include/utils.h b/app/include/utils.h index 8d615d0..49a549f 100644 --- a/app/include/utils.h +++ b/app/include/utils.h @@ -1,6 +1,5 @@ #pragma once -#include #include /// Checks whether a result code indicates success. @@ -8,11 +7,8 @@ /// Checks whether a result code indicates failure. #define R_FAILED(res) ((res) < 0) -extern int PSP_KEY_ENTER, PSP_KEY_CANCEL; extern char g_err_string[1024]; void utilsLogError(const char *error, ...); -int utilsGetEnterButton(void); -int utilsGetCancelButton(void); void utilsGetSizeString(char *string, int size); int utilsSetDevice(const char *dev, const char *dev2, const char *dev3, char *dst); diff --git a/app/source/gui.c b/app/source/gui.c index 9efa42a..c253627 100644 --- a/app/source/gui.c +++ b/app/source/gui.c @@ -534,8 +534,8 @@ static void guiControlFileBrowser(void) { vlfGuiAddEventHandler(PSP_CTRL_LEFT, -1, guiControlFileBrowserStartList, NULL); vlfGuiAddEventHandler(PSP_CTRL_RIGHT, -1, guiControlFileBrowserEndList, NULL); vlfGuiAddEventHandler(PSP_CTRL_TRIANGLE, -1, guiControlContextMenu, NULL); - vlfGuiAddEventHandler(PSP_KEY_ENTER, -1, guiControlFileBrowserEnter, NULL); - vlfGuiAddEventHandler(PSP_KEY_CANCEL, -1, guiControlFileBrowserCancel, NULL); + vlfGuiAddEventHandler(PSP_CTRL_ENTER, -1, guiControlFileBrowserEnter, NULL); + vlfGuiAddEventHandler(PSP_CTRL_CANCEL, -1, guiControlFileBrowserCancel, NULL); } static int guiControlMainMenu(int selection) { diff --git a/app/source/main.c b/app/source/main.c index c6c13ca..2876f77 100755 --- a/app/source/main.c +++ b/app/source/main.c @@ -10,17 +10,12 @@ PSP_MODULE_INFO("VLFFM", PSP_MODULE_USER, VERSION_MAJOR, VERSION_MINOR); PSP_MAIN_THREAD_ATTR(0); -static bool running = true; - int app_main(int argc, char *argv[]) { - PSP_KEY_ENTER = utilsGetEnterButton(); - PSP_KEY_CANCEL = utilsGetCancelButton(); - configLoad(); vlfGuiSystemSetup(1, 1, 1); guiInit(); - while (running) { + while (true) { vlfGuiDrawFrame(); } diff --git a/app/source/utils.c b/app/source/utils.c index de46c88..af53f47 100644 --- a/app/source/utils.c +++ b/app/source/utils.c @@ -1,13 +1,10 @@ #include -#include -#include #include #include #include #include "utils.h" -int PSP_KEY_ENTER, PSP_KEY_CANCEL; char g_err_string[1024]; void utilsLogError(const char *error, ...) { @@ -18,117 +15,6 @@ void utilsLogError(const char *error, ...) { printf(g_err_string); } -static int utilsGetRegistryValue(const char *dir, const char *name, unsigned int *value) { - int ret = 0; - struct RegParam reg_param; - REGHANDLE reg_handle = 0, reg_handle_cat = 0, reg_handle_key = 0; - unsigned int type = 0, size = 0; - - memset(®_param, 0, sizeof(struct RegParam)); - reg_param.regtype = 1; - reg_param.namelen = strlen("/system"); - reg_param.unk2 = 1; - reg_param.unk3 = 1; - strcpy(reg_param.name, "/system"); - - if (R_FAILED(ret = sceRegOpenRegistry(®_param, 2, ®_handle))) { - utilsLogError("sceRegOpenRegistry() failed: 0x%08x\n", ret); - return ret; - } - - if (R_FAILED(ret = sceRegOpenCategory(reg_handle, dir, 2, ®_handle_cat))) { - sceRegCloseRegistry(reg_handle); - utilsLogError("sceRegOpenCategory() failed: 0x%08x\n", ret); - return ret; - } - - if (R_FAILED(ret = sceRegGetKeyInfo(reg_handle_cat, name, ®_handle_key, &type, &size))) { - sceRegCloseCategory(reg_handle_cat); - sceRegCloseRegistry(reg_handle); - utilsLogError("sceRegGetKeyInfo() failed: 0x%08x\n", ret); - return ret; - } - - if (R_FAILED(ret = sceRegGetKeyValue(reg_handle_cat, reg_handle_key, value, 4))) { - sceRegCloseCategory(reg_handle_cat); - sceRegCloseRegistry(reg_handle); - utilsLogError("sceRegGetKeyValue() failed: 0x%08x\n", ret); - return ret; - } - - if (R_FAILED(ret = sceRegFlushCategory(reg_handle_cat))) { - sceRegCloseCategory(reg_handle_cat); - sceRegCloseRegistry(reg_handle); - utilsLogError("sceRegFlushCategory() failed: 0x%08x\n", ret); - return ret; - } - - if (R_FAILED(ret = sceRegCloseCategory(reg_handle_cat))) { - sceRegCloseRegistry(reg_handle); - utilsLogError("sceRegCloseCategory() failed: 0x%08x\n", ret); - return ret; - } - - if (R_FAILED(ret = sceRegFlushRegistry(reg_handle))) { - sceRegCloseRegistry(reg_handle); - utilsLogError("sceRegFlushRegistry() failed: 0x%08x\n", ret); - return ret; - } - - if (R_FAILED(ret = sceRegCloseRegistry(reg_handle))) { - utilsLogError("sceRegFlushRegistry() failed: 0x%08x\n", ret); - return ret; - } - - return 0; -} - -int utilsGetEnterButton(void) { - int ret = 0, button = -1; - - if (R_FAILED(ret = sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_UNKNOWN, &button))) { - utilsLogError("sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_UNKNOWN) failed: 0x%08x\n", ret); - unsigned int reg_button = -1; - - if (R_SUCCEEDED(utilsGetRegistryValue("/CONFIG/SYSTEM/XMB", "button_assign", ®_button))) { - if (reg_button == 0) { - return PSP_CTRL_CIRCLE; - } - - return PSP_CTRL_CROSS; - } - } - - if (button == 0) { - return PSP_CTRL_CIRCLE; - } - - return PSP_CTRL_CROSS; -} - -int utilsGetCancelButton(void) { - int ret = 0, button = -1; - - if (R_FAILED(ret = sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_UNKNOWN, &button))) { - utilsLogError("sceUtilityGetSystemParamInt(PSP_SYSTEMPARAM_ID_INT_UNKNOWN) failed: 0x%08x\n", ret); - unsigned int reg_button = -1; - - if (R_SUCCEEDED(utilsGetRegistryValue("/CONFIG/SYSTEM/XMB", "button_assign", ®_button))) { - if (reg_button == 0) { - return PSP_CTRL_CROSS; - } - - return PSP_CTRL_CIRCLE; - } - } - - if (button == 0) { - return PSP_CTRL_CROSS; - } - - return PSP_CTRL_CIRCLE; -} - void utilsGetSizeString(char *string, int size) { int i = 0; const char *units[] = {"B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"};