utils: Use VLF's PspCtrlExtension instead of our own

This commit is contained in:
joel16 2024-01-06 11:27:37 -05:00
parent 953e567c1a
commit ca9a26bd0d
4 changed files with 3 additions and 126 deletions

View File

@ -1,6 +1,5 @@
#pragma once
#include <pspctrl.h>
#include <psptypes.h>
/// 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);

View File

@ -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) {

View File

@ -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();
}

View File

@ -1,13 +1,10 @@
#include <pspkernel.h>
#include <pspreg.h>
#include <psputility_sysparam.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#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(&reg_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(&reg_param, 2, &reg_handle))) {
utilsLogError("sceRegOpenRegistry() failed: 0x%08x\n", ret);
return ret;
}
if (R_FAILED(ret = sceRegOpenCategory(reg_handle, dir, 2, &reg_handle_cat))) {
sceRegCloseRegistry(reg_handle);
utilsLogError("sceRegOpenCategory() failed: 0x%08x\n", ret);
return ret;
}
if (R_FAILED(ret = sceRegGetKeyInfo(reg_handle_cat, name, &reg_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", &reg_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", &reg_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"};