From 393510e1b5db6d935088b18ba14e25b3757760cf Mon Sep 17 00:00:00 2001 From: joel16 Date: Fri, 20 Mar 2020 11:37:07 -0400 Subject: [PATCH] Remove all traces of lastdir saving and fix storage bar display for ms0:/ on psp go --- app/include/config.h | 1 - app/source/config.c | 5 +++ app/source/dirbrowse.c | 2 +- app/source/main.c | 16 ++++----- app/source/menus/menu_main.c | 70 ++++-------------------------------- app/source/utils.c | 4 +-- 6 files changed, 23 insertions(+), 75 deletions(-) diff --git a/app/include/config.h b/app/include/config.h index 8922ff96..5f8c40a3 100644 --- a/app/include/config.h +++ b/app/include/config.h @@ -14,4 +14,3 @@ config_t config; int Config_Save(config_t config); int Config_Load(void); -int Config_GetLastDirectory(void); diff --git a/app/source/config.c b/app/source/config.c index 5118e4d9..cabf2e70 100644 --- a/app/source/config.c +++ b/app/source/config.c @@ -49,6 +49,11 @@ int Config_Load(void) { strncpy(root_path, is_psp_go? "ef0:/" : "ms0:/", 6); strncpy(cwd, is_psp_go? "ef0:/" : "ms0:/", 6); + if (is_psp_go) + BROWSE_STATE = BROWSE_STATE_INTERNAL; + else + BROWSE_STATE = BROWSE_STATE_SD; + if (!FS_FileExists("config.json")) { config.sort = 0; config.dark_theme = false; diff --git a/app/source/dirbrowse.c b/app/source/dirbrowse.c index 2c89c16c..dc024856 100644 --- a/app/source/dirbrowse.c +++ b/app/source/dirbrowse.c @@ -133,7 +133,7 @@ void Dirbrowse_DisplayFiles(void) { intraFontSetStyle(font, 0.7f, WHITE, G2D_RGBA(0, 0, 0, 0), 0.f, INTRAFONT_ALIGN_LEFT); intraFontPrint(font, 40, 20 + ((40 - (font->texYSize - 30)) / 2), cwd); - if (is_ms_inserted) { + if ((BROWSE_STATE == BROWSE_STATE_SD) || (BROWSE_STATE == BROWSE_STATE_INTERNAL)) { G2D_DrawRect(40, 52, 400, 3, config.dark_theme? SELECTOR_COLOUR_DARK : G2D_RGBA(10, 73, 163, 255)); G2D_DrawRect(40, 52, (((double)used_storage/(double)total_storage) * 400.0), 3, config.dark_theme? TITLE_COLOUR_DARK : G2D_RGBA(49, 161, 224, 255)); } diff --git a/app/source/main.c b/app/source/main.c index 23e67731..1f27e1e1 100644 --- a/app/source/main.c +++ b/app/source/main.c @@ -62,14 +62,6 @@ static int Init_Services(void) { Utils_InitKernelDrivers(); Log_OpenFileHande(); - Utils_IsMemCardInserted(&is_ms_inserted); - is_psp_go = Utils_IsModelPSPGo(); - - if (R_FAILED(ret = Config_Load())) { - Log_Print("Config_Load failed: 0x%lx\n", ret); - return ret; - } - Textures_Load(); if (R_FAILED(ret = intraFontInit())) { @@ -88,6 +80,14 @@ static int Init_Services(void) { intraFontSetAltFont(chn_font, kor_font); intraFontSetAltFont(kor_font, sym_font); + Utils_IsMemCardInserted(&is_ms_inserted); + is_psp_go = Utils_IsModelPSPGo(); + + if (R_FAILED(ret = Config_Load())) { + Log_Print("Config_Load failed: 0x%lx\n", ret); + return ret; + } + PSP_CTRL_ENTER = Utils_GetEnterButton(); PSP_CTRL_CANCEL = Utils_GetCancelButton(); return 0; diff --git a/app/source/menus/menu_main.c b/app/source/menus/menu_main.c index d242a801..3d20ff56 100644 --- a/app/source/menus/menu_main.c +++ b/app/source/menus/menu_main.c @@ -61,8 +61,6 @@ static void Menu_HandleMultiSelect(void) { } static void Menu_ControlMenubar(int ctrl) { - char *buf = NULL; - if (ctrl & PSP_CTRL_UP) menubar_selection--; else if (ctrl & PSP_CTRL_DOWN) @@ -91,50 +89,12 @@ static void Menu_ControlMenubar(int ctrl) { memset(root_path, 0, strlen(root_path)); if ((is_psp_go && is_ms_inserted) || (!is_psp_go)) { strcpy(root_path, "ms0:/"); - - if (FS_FileExists("lastdir.txt")) { - buf = (char *)calloc(256, sizeof(char)); - if (R_FAILED(FS_ReadFile("lastdir.txt", buf, 256))) { - free(buf); - strcpy(cwd, "ms0:/"); - } - - char temp_path[256], drive[6]; - sscanf(buf, "%[^\n]s", temp_path); - sscanf(drive, "%5s", temp_path); - - if (FS_DirExists(temp_path) && (!strcmp(drive, root_path))) // Incase a directory previously visited had been deleted, set start path to sdmc:/ to avoid errors. - strcpy(cwd, temp_path); - else - strcpy(cwd, "ms0:/"); - - free(buf); - } - + strcpy(cwd, "ms0:/"); BROWSE_STATE = BROWSE_STATE_SD; } else if (is_psp_go && !is_ms_inserted) { strcpy(root_path, "ef0:/"); - - if (FS_FileExists("lastdir.txt")) { - buf = (char *)calloc(256, sizeof(char)); - if (R_FAILED(FS_ReadFile("lastdir.txt", buf, 256))) { - free(buf); - strcpy(cwd, "ef0:/"); - } - - char temp_path[256], drive[6]; - sscanf(buf, "%[^\n]s", temp_path); - sscanf(drive, "%5s", temp_path); - - if (FS_DirExists(temp_path) && (!strcmp(drive, root_path))) // Incase a directory previously visited had been deleted, set start path to sdmc:/ to avoid errors. - strcpy(cwd, temp_path); - else - strcpy(cwd, "ef0:/"); - - free(buf); - } - + strcpy(cwd, "ef0:/"); BROWSE_STATE = BROWSE_STATE_INTERNAL; } @@ -142,6 +102,8 @@ static void Menu_ControlMenubar(int ctrl) { menubar_x = -180; Dirbrowse_PopulateFiles(true); + total_storage = Utils_GetTotalStorage(); + used_storage = Utils_GetUsedStorage(); MENU_STATE = MENU_STATE_HOME; old_menubar_selection = 0; @@ -154,27 +116,7 @@ static void Menu_ControlMenubar(int ctrl) { strcpy(root_path, (is_psp_go && is_ms_inserted)? "ef0:/" : "flash0:/"); strcpy(cwd, (is_psp_go && is_ms_inserted)? "ef0:/" : "flash0:/"); - if (is_psp_go && is_ms_inserted) { - if (FS_FileExists("lastdir.txt")) { - buf = (char *)calloc(256, sizeof(char)); - if (R_FAILED(FS_ReadFile("lastdir.txt", buf, 256))) { - free(buf); - strcpy(cwd, "ef0:/"); - } - - char temp_path[256], drive[7]; - sscanf(buf, "%[^\n]s\n", temp_path); - snprintf(drive, 7, "%.5s", temp_path); - - if (FS_DirExists(temp_path) && (!strcmp(drive, root_path))) // Incase a directory previously visited had been deleted, set start path to sdmc:/ to avoid errors. - strcpy(cwd, temp_path); - else - strcpy(cwd, "ef0:/"); - - free(buf); - } - } - else { + if (!(is_psp_go && is_ms_inserted)) { int ret = 0; if ((R_FAILED(ret = sceIoUnassign("flash0:"))) && (ret != 0x80020321)) Menu_DisplayError("sceIoUnassign(flash0) failed", ret); @@ -189,6 +131,8 @@ static void Menu_ControlMenubar(int ctrl) { menubar_x = -180; Dirbrowse_PopulateFiles(true); + total_storage = Utils_GetTotalStorage(); + used_storage = Utils_GetUsedStorage(); MENU_STATE = MENU_STATE_HOME; old_menubar_selection = 1; diff --git a/app/source/utils.c b/app/source/utils.c index 804a3580..8986d772 100644 --- a/app/source/utils.c +++ b/app/source/utils.c @@ -356,7 +356,7 @@ u64 Utils_GetTotalStorage(void) { SystemDevCommand command; command.pdevinf = &devctl; - if (R_FAILED(ret = sceIoDevctl("ms0:", 0x02425818, &command, sizeof(SystemDevCommand), NULL, 0))) + if (R_FAILED(ret = sceIoDevctl(BROWSE_STATE == BROWSE_STATE_INTERNAL? "ef0": "ms0:", 0x02425818, &command, sizeof(SystemDevCommand), NULL, 0))) return 0; u64 size = (devctl.maxclusters * devctl.sectorcount) * devctl.sectorsize; @@ -370,7 +370,7 @@ static u64 Utils_GetFreeStorage(void) { SystemDevCommand command; command.pdevinf = &devctl; - if (R_FAILED(ret = sceIoDevctl("ms0:", 0x02425818, &command, sizeof(SystemDevCommand), NULL, 0))) + if (R_FAILED(ret = sceIoDevctl(BROWSE_STATE == BROWSE_STATE_INTERNAL? "ef0": "ms0:", 0x02425818, &command, sizeof(SystemDevCommand), NULL, 0))) return 0; u64 size = (devctl.freeclusters * devctl.sectorcount) * devctl.sectorsize;