mirror of
https://github.com/joel16/VitaShell.git
synced 2024-11-23 11:49:40 +00:00
Improved settings
This commit is contained in:
parent
87263b43a9
commit
c220eb19fe
65
config.c
65
config.c
@ -226,4 +226,69 @@ int readConfig(char *path, ConfigEntry *entries, int n_entries) {
|
||||
free(buffer);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int writeEntry(SceUID fd, ConfigEntry *entry) {
|
||||
int result;
|
||||
if ((result = sceIoWrite(fd, entry->name, strlen(entry->name))) < 0)
|
||||
return result;
|
||||
|
||||
if ((result = sceIoWrite(fd, " = ", 3)) < 0)
|
||||
return result;
|
||||
|
||||
char *val;
|
||||
char buffer[33];
|
||||
|
||||
switch (entry->type) {
|
||||
case CONFIG_TYPE_BOOLEAN:
|
||||
val = *(uint32_t*)entry->value != 0 ? "true" : "false";
|
||||
result = sceIoWrite(fd, val, strlen(val));
|
||||
break;
|
||||
|
||||
case CONFIG_TYPE_DECIMAL:
|
||||
itoa(*(int*)entry->value, buffer, 10);
|
||||
result = sceIoWrite(fd, buffer, strlen(buffer));
|
||||
break;
|
||||
|
||||
case CONFIG_TYPE_HEXDECIMAL:
|
||||
itoa(*(int*)entry->value, buffer, 16);
|
||||
result = sceIoWrite(fd, buffer, strlen(buffer));
|
||||
break;
|
||||
|
||||
case CONFIG_TYPE_STRING:
|
||||
val = *(char **)entry->value;
|
||||
sceIoWrite(fd, "\"", 1);
|
||||
result = sceIoWrite(fd, val, strlen(val));
|
||||
sceIoWrite(fd, "\"", 1);
|
||||
break;
|
||||
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (result < 0)
|
||||
return result;
|
||||
|
||||
if ((sceIoWrite(fd, "\n", 1)) < 0)
|
||||
return result;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int writeConfig(char *path, ConfigEntry *entries, int n_entries) {
|
||||
SceUID fd = sceIoOpen(path, SCE_O_WRONLY | SCE_O_CREAT | SCE_O_TRUNC, 0777);
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
int i;
|
||||
for (i = 0; i < n_entries; i++) {
|
||||
int result = writeEntry(fd, entries+i);
|
||||
if (result != 0) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
sceIoClose(fd);
|
||||
|
||||
return 0;
|
||||
}
|
1
config.h
1
config.h
@ -38,5 +38,6 @@ typedef struct {
|
||||
|
||||
int readConfigBuffer(void *buffer, int size, ConfigEntry *entries, int n_entries);
|
||||
int readConfig(char *path, ConfigEntry *entries, int n_entries);
|
||||
int writeConfig(char *path, ConfigEntry *entries, int n_entries);
|
||||
|
||||
#endif
|
@ -22,6 +22,8 @@
|
||||
#define HENKAKU_CONFIG_MAGIC 0x4C434C4D
|
||||
#define HENKAKU_VERSION 7
|
||||
|
||||
#define HENKAKU_DEFAULT_VERSION_STRING "3.61"
|
||||
|
||||
typedef struct {
|
||||
int magic;
|
||||
int version;
|
||||
|
@ -174,6 +174,11 @@ void loadLanguage(int id) {
|
||||
LANGUAGE_ENTRY(HENKAKU_ENABLE_VERSION_SPOOFING),
|
||||
LANGUAGE_ENTRY(HENKAKU_SPOOFED_VERSION),
|
||||
|
||||
// VitaShell settings
|
||||
LANGUAGE_ENTRY(VITASHELL_SETTINGS_MAIN),
|
||||
LANGUAGE_ENTRY(VITASHELL_SETTINGS_LANGUAGE),
|
||||
LANGUAGE_ENTRY(VITASHELL_SETTINGS_THEME),
|
||||
|
||||
// Others
|
||||
LANGUAGE_ENTRY(TOOLBOX),
|
||||
LANGUAGE_ENTRY(SYSINFO_TITLE),
|
||||
|
@ -133,6 +133,11 @@ enum LanguageContainer {
|
||||
HENKAKU_ENABLE_VERSION_SPOOFING,
|
||||
HENKAKU_SPOOFED_VERSION,
|
||||
|
||||
// VitaShell settings
|
||||
VITASHELL_SETTINGS_MAIN,
|
||||
VITASHELL_SETTINGS_LANGUAGE,
|
||||
VITASHELL_SETTINGS_THEME,
|
||||
|
||||
// Others
|
||||
TOOLBOX,
|
||||
SYSINFO_TITLE,
|
||||
|
17
main.c
17
main.c
@ -18,8 +18,6 @@
|
||||
|
||||
/*
|
||||
TODO:
|
||||
- Hide mount points
|
||||
- Inverse sort, sort by date, size
|
||||
- Hex editor byte group size
|
||||
- Duplicate when same location or same name. /lol to /lol - Backup. or overwrite question.
|
||||
- Shortcuts
|
||||
@ -86,6 +84,8 @@ static int dir_level_archive = -1;
|
||||
static char vita_ip[16];
|
||||
static unsigned short int vita_port;
|
||||
|
||||
int is_molecular_shell = 0;
|
||||
|
||||
// Enter and cancel buttons
|
||||
int SCE_CTRL_ENTER = SCE_CTRL_CROSS, SCE_CTRL_CANCEL = SCE_CTRL_CIRCLE;
|
||||
|
||||
@ -1936,8 +1936,17 @@ int main(int argc, const char *argv[]) {
|
||||
// Init VitaShell
|
||||
initVitaShell();
|
||||
|
||||
// Allow writing to ux0:app/VITASHELL
|
||||
sceAppMgrUmount("app0:");
|
||||
// Get titleid
|
||||
char titleid[12];
|
||||
memset(titleid, 0, sizeof(titleid));
|
||||
sceAppMgrAppParamGetString(sceKernelGetProcessId(), 12, titleid, sizeof(titleid));
|
||||
|
||||
if (strcmp(titleid, "MLCL00001") == 0) {
|
||||
is_molecular_shell = 1;
|
||||
} else {
|
||||
// Allow writing to ux0:app/VITASHELL
|
||||
sceAppMgrUmount("app0:");
|
||||
}
|
||||
|
||||
// No custom config, in case they are damaged or unuseable
|
||||
readPad();
|
||||
|
2
main.h
2
main.h
@ -207,6 +207,8 @@ enum DialogSteps {
|
||||
extern vita2d_pgf *font;
|
||||
extern char font_size_cache[256];
|
||||
|
||||
extern int is_molecular_shell;
|
||||
|
||||
extern int SCE_CTRL_ENTER, SCE_CTRL_CANCEL;
|
||||
|
||||
extern volatile int dialog_step;
|
||||
|
@ -113,6 +113,11 @@ HENKAKU_ENABLE_UNSAFE_HOMEBREW = "Enable unsafe homebrew"
|
||||
HENKAKU_ENABLE_VERSION_SPOOFING = "Enable version spoofing"
|
||||
HENKAKU_SPOOFED_VERSION = "Spoofed version"
|
||||
|
||||
# VitaShell settings
|
||||
VITASHELL_SETTINGS_MAIN = "Main settings"
|
||||
VITASHELL_SETTINGS_LANGUAGE = "Language"
|
||||
VITASHELL_SETTINGS_THEME = "Theme"
|
||||
|
||||
# Others
|
||||
PLEASE_WAIT = "Please wait..."
|
||||
SAVE_MODIFICATIONS = "Do you want to save your modifications?"
|
||||
|
160
settings.c
160
settings.c
@ -26,47 +26,57 @@
|
||||
|
||||
#include "henkaku_config.h"
|
||||
|
||||
#define DEFAULT_VERSION_STRING "3.61"
|
||||
/*
|
||||
* HENkaku configuration *
|
||||
- Enable PSN spoofing
|
||||
- Enable unsafe homebrew
|
||||
- Enable version spoofing
|
||||
- Spoofed version
|
||||
|
||||
HENkakuConfig henkaku_config;
|
||||
* Main *
|
||||
- CPU
|
||||
- Language
|
||||
- Theme
|
||||
|
||||
char spoofed_version[8];
|
||||
* FTP *
|
||||
- Auto-start
|
||||
|
||||
typedef struct {
|
||||
int status;
|
||||
float cur_pos;
|
||||
int sel;
|
||||
int n_options;
|
||||
} SettingsMenu;
|
||||
* Status bar *
|
||||
- Display battery percentage
|
||||
*/
|
||||
|
||||
typedef struct {
|
||||
int name;
|
||||
int type;
|
||||
char *string;
|
||||
int size_string;
|
||||
int *value;
|
||||
} SettingsMenuOption;
|
||||
static HENkakuConfig henkaku_config;
|
||||
|
||||
typedef struct {
|
||||
int name;
|
||||
SettingsMenuOption *options;
|
||||
int n_options;
|
||||
} SettingsMenuEntry;
|
||||
static char spoofed_version[8];
|
||||
|
||||
// Dummy
|
||||
static int language, theme;
|
||||
|
||||
static SettingsMenuEntry *settings_menu_entries = NULL;
|
||||
static int n_settings_entries = 0;
|
||||
|
||||
SettingsMenuOption henkaku_configuration[] = {
|
||||
{ HENKAKU_ENABLE_PSN_SPOOFING, SETTINGS_OPTION_TYPE_BOOLEAN, NULL, 0, &henkaku_config.use_psn_spoofing },
|
||||
{ HENKAKU_ENABLE_UNSAFE_HOMEBREW, SETTINGS_OPTION_TYPE_BOOLEAN, NULL, 0, &henkaku_config.allow_unsafe_hb },
|
||||
{ HENKAKU_ENABLE_VERSION_SPOOFING, SETTINGS_OPTION_TYPE_BOOLEAN, NULL, 0, &henkaku_config.use_spoofed_version },
|
||||
{ HENKAKU_SPOOFED_VERSION, SETTINGS_OPTION_TYPE_STRING, spoofed_version, sizeof(spoofed_version), NULL },
|
||||
{ HENKAKU_SPOOFED_VERSION, SETTINGS_OPTION_TYPE_STRING, spoofed_version, 5, NULL },
|
||||
};
|
||||
|
||||
SettingsMenuEntry settings_menu_entries[] = {
|
||||
SettingsMenuOption vitashell_main[] = {
|
||||
{ VITASHELL_SETTINGS_LANGUAGE, SETTINGS_OPTION_TYPE_BOOLEAN, NULL, 0, &language },
|
||||
{ VITASHELL_SETTINGS_THEME, SETTINGS_OPTION_TYPE_BOOLEAN, NULL, 0, &theme },
|
||||
};
|
||||
|
||||
SettingsMenuEntry molecularshell_settings_menu_entries[] = {
|
||||
{ HENKAKU_CONFIGURATION, henkaku_configuration, sizeof(henkaku_configuration) / sizeof(SettingsMenuOption) },
|
||||
{ VITASHELL_SETTINGS_MAIN, vitashell_main, sizeof(vitashell_main) / sizeof(SettingsMenuOption) },
|
||||
};
|
||||
|
||||
#define N_SETTINGS_ENTRIES (sizeof(settings_menu_entries) / sizeof(SettingsMenuEntry))
|
||||
SettingsMenuEntry vitashell_settings_menu_entries[] = {
|
||||
{ VITASHELL_SETTINGS_MAIN, vitashell_main, sizeof(vitashell_main) / sizeof(SettingsMenuOption) },
|
||||
};
|
||||
|
||||
SettingsMenu settings_menu;
|
||||
static SettingsMenu settings_menu;
|
||||
|
||||
static float easeOut(float x0, float x1, float a) {
|
||||
float dx = (x1 - x0);
|
||||
@ -77,57 +87,70 @@ void initSettingsMenu() {
|
||||
memset(&settings_menu, 0, sizeof(SettingsMenu));
|
||||
settings_menu.status = SETTINGS_MENU_CLOSED;
|
||||
|
||||
if (is_molecular_shell) {
|
||||
n_settings_entries = sizeof(molecularshell_settings_menu_entries) / sizeof(SettingsMenuEntry);
|
||||
settings_menu_entries = molecularshell_settings_menu_entries;
|
||||
} else {
|
||||
n_settings_entries = sizeof(vitashell_settings_menu_entries) / sizeof(SettingsMenuEntry);
|
||||
settings_menu_entries = vitashell_settings_menu_entries;
|
||||
}
|
||||
|
||||
int i;
|
||||
for (i = 0; i < N_SETTINGS_ENTRIES; i++)
|
||||
for (i = 0; i < n_settings_entries; i++)
|
||||
settings_menu.n_options += settings_menu_entries[i].n_options;
|
||||
}
|
||||
|
||||
void openSettingsMenu() {
|
||||
settings_menu.status = SETTINGS_MENU_OPENING;
|
||||
settings_menu.sel = 0;
|
||||
settings_menu.entry_sel = 0;
|
||||
settings_menu.option_sel = 0;
|
||||
|
||||
ReadFile("savedata0:config.bin", &henkaku_config, sizeof(HENkakuConfig));
|
||||
if (is_molecular_shell) {
|
||||
ReadFile("savedata0:config.bin", &henkaku_config, sizeof(HENkakuConfig));
|
||||
|
||||
char a = (henkaku_config.spoofed_version >> 28) & 0xF;
|
||||
char b = (henkaku_config.spoofed_version >> 24) & 0xF;
|
||||
char c = (henkaku_config.spoofed_version >> 20) & 0xF;
|
||||
char d = (henkaku_config.spoofed_version >> 16) & 0xF;
|
||||
char a = (henkaku_config.spoofed_version >> 28) & 0xF;
|
||||
char b = (henkaku_config.spoofed_version >> 24) & 0xF;
|
||||
char c = (henkaku_config.spoofed_version >> 20) & 0xF;
|
||||
char d = (henkaku_config.spoofed_version >> 16) & 0xF;
|
||||
|
||||
memset(spoofed_version, 0, sizeof(spoofed_version));
|
||||
memset(spoofed_version, 0, sizeof(spoofed_version));
|
||||
|
||||
if (a || b || c || d) {
|
||||
spoofed_version[0] = '0' + a;
|
||||
spoofed_version[1] = '.';
|
||||
spoofed_version[2] = '0' + b;
|
||||
spoofed_version[3] = '0' + c;
|
||||
spoofed_version[4] = '\0';
|
||||
if (a || b || c || d) {
|
||||
spoofed_version[0] = '0' + a;
|
||||
spoofed_version[1] = '.';
|
||||
spoofed_version[2] = '0' + b;
|
||||
spoofed_version[3] = '0' + c;
|
||||
spoofed_version[4] = '\0';
|
||||
|
||||
if (d) {
|
||||
spoofed_version[4] = '0' + d;
|
||||
spoofed_version[5] = '\0';
|
||||
if (d) {
|
||||
spoofed_version[4] = '0' + d;
|
||||
spoofed_version[5] = '\0';
|
||||
}
|
||||
} else {
|
||||
strcpy(spoofed_version, HENKAKU_DEFAULT_VERSION_STRING);
|
||||
}
|
||||
} else {
|
||||
strcpy(spoofed_version, DEFAULT_VERSION_STRING);
|
||||
}
|
||||
}
|
||||
|
||||
void closeSettingsMenu() {
|
||||
settings_menu.status = SETTINGS_MENU_CLOSING;
|
||||
|
||||
if (IS_DIGIT(spoofed_version[0]) && spoofed_version[1] == '.' && IS_DIGIT(spoofed_version[2]) && IS_DIGIT(spoofed_version[3])) {
|
||||
char a = spoofed_version[0] - '0';
|
||||
char b = spoofed_version[2] - '0';
|
||||
char c = spoofed_version[3] - '0';
|
||||
char d = IS_DIGIT(spoofed_version[4]) ? spoofed_version[4] - '0' : '\0';
|
||||
if (is_molecular_shell) {
|
||||
if (IS_DIGIT(spoofed_version[0]) && spoofed_version[1] == '.' && IS_DIGIT(spoofed_version[2]) && IS_DIGIT(spoofed_version[3])) {
|
||||
char a = spoofed_version[0] - '0';
|
||||
char b = spoofed_version[2] - '0';
|
||||
char c = spoofed_version[3] - '0';
|
||||
char d = IS_DIGIT(spoofed_version[4]) ? spoofed_version[4] - '0' : '\0';
|
||||
|
||||
henkaku_config.spoofed_version = ((a << 28) | (b << 24) | (c << 20) | (d << 16));
|
||||
} else {
|
||||
henkaku_config.spoofed_version = 0;
|
||||
henkaku_config.spoofed_version = ((a << 28) | (b << 24) | (c << 20) | (d << 16));
|
||||
} else {
|
||||
henkaku_config.spoofed_version = 0;
|
||||
}
|
||||
|
||||
henkaku_config.magic = HENKAKU_CONFIG_MAGIC;
|
||||
henkaku_config.version = HENKAKU_VERSION;
|
||||
WriteFile("savedata0:config.bin", &henkaku_config, sizeof(HENkakuConfig));
|
||||
}
|
||||
|
||||
henkaku_config.magic = HENKAKU_CONFIG_MAGIC;
|
||||
henkaku_config.version = HENKAKU_VERSION;
|
||||
WriteFile("savedata0:config.bin", &henkaku_config, sizeof(HENkakuConfig));
|
||||
}
|
||||
|
||||
int getSettingsMenuStatus() {
|
||||
@ -162,7 +185,7 @@ void drawSettingsMenu() {
|
||||
float y = SCREEN_HEIGHT - settings_menu.cur_pos + START_Y;
|
||||
|
||||
int i;
|
||||
for (i = 0; i < N_SETTINGS_ENTRIES; i++) {
|
||||
for (i = 0; i < n_settings_entries; i++) {
|
||||
// Title
|
||||
float x = vita2d_pgf_text_width(font, FONT_SIZE, language_container[settings_menu_entries[i].name]);
|
||||
pgf_draw_text(ALIGN_CENTER(SCREEN_WIDTH, x), y, SETTINGS_MENU_TITLE_COLOR, FONT_SIZE, language_container[settings_menu_entries[i].name]);
|
||||
@ -174,7 +197,7 @@ void drawSettingsMenu() {
|
||||
int j;
|
||||
for (j = 0; j < settings_menu_entries[i].n_options; j++) {
|
||||
// Focus
|
||||
if (settings_menu.sel == j)
|
||||
if (settings_menu.entry_sel == i && settings_menu.option_sel == j)
|
||||
vita2d_draw_rectangle(SHELL_MARGIN_X, y + 3.0f, MARK_WIDTH, FONT_Y_SPACE, SETTINGS_MENU_FOCUS_COLOR);
|
||||
|
||||
// Item
|
||||
@ -203,17 +226,24 @@ void settingsMenuCtrl() {
|
||||
|
||||
// Move
|
||||
if (hold_buttons & SCE_CTRL_UP || hold2_buttons & SCE_CTRL_LEFT_ANALOG_UP) {
|
||||
if (settings_menu.sel > 0)
|
||||
settings_menu.sel--;
|
||||
if (settings_menu.option_sel > 0) {
|
||||
settings_menu.option_sel--;
|
||||
} else if (settings_menu.entry_sel > 0) {
|
||||
settings_menu.entry_sel--;
|
||||
settings_menu.option_sel = settings_menu_entries[settings_menu.entry_sel].n_options - 1;
|
||||
}
|
||||
} else if (hold_buttons & SCE_CTRL_DOWN || hold2_buttons & SCE_CTRL_LEFT_ANALOG_DOWN) {
|
||||
if (settings_menu.sel < settings_menu.n_options - 1)
|
||||
settings_menu.sel++;
|
||||
if (settings_menu.option_sel < settings_menu_entries[settings_menu.entry_sel].n_options - 1) {
|
||||
settings_menu.option_sel++;
|
||||
} else if (settings_menu.entry_sel < n_settings_entries - 1) {
|
||||
settings_menu.entry_sel++;
|
||||
settings_menu.option_sel = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO |
|
||||
SettingsMenuOption *option = &settings_menu_entries[0].options[settings_menu.sel];
|
||||
|
||||
// Change options
|
||||
SettingsMenuOption *option = &settings_menu_entries[settings_menu.entry_sel].options[settings_menu.option_sel];
|
||||
|
||||
if (pressed_buttons & (SCE_CTRL_ENTER | SCE_CTRL_LEFT | SCE_CTRL_RIGHT)) {
|
||||
if (option->type == SETTINGS_OPTION_TYPE_BOOLEAN) {
|
||||
*(option->value) = !*(option->value);
|
||||
|
22
settings.h
22
settings.h
@ -32,6 +32,28 @@ enum SettingsMenuStatus {
|
||||
SETTINGS_MENU_OPENING,
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int status;
|
||||
float cur_pos;
|
||||
int entry_sel;
|
||||
int option_sel;
|
||||
int n_options;
|
||||
} SettingsMenu;
|
||||
|
||||
typedef struct {
|
||||
int name;
|
||||
int type;
|
||||
char *string;
|
||||
int size_string;
|
||||
int *value;
|
||||
} SettingsMenuOption;
|
||||
|
||||
typedef struct {
|
||||
int name;
|
||||
SettingsMenuOption *options;
|
||||
int n_options;
|
||||
} SettingsMenuEntry;
|
||||
|
||||
void initSettingsMenu();
|
||||
void openSettingsMenu();
|
||||
int getSettingsMenuStatus();
|
||||
|
Loading…
Reference in New Issue
Block a user