Skip to content

Commit

Permalink
Remove all traces of lastdir saving and fix storage bar display for m…
Browse files Browse the repository at this point in the history
…s0:/ on psp go
  • Loading branch information
joel16 committed Mar 20, 2020
1 parent eaf5202 commit 393510e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 75 deletions.
1 change: 0 additions & 1 deletion app/include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ config_t config;

int Config_Save(config_t config);
int Config_Load(void);
int Config_GetLastDirectory(void);
5 changes: 5 additions & 0 deletions app/source/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion app/source/dirbrowse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
16 changes: 8 additions & 8 deletions app/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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())) {
Expand All @@ -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;
Expand Down
70 changes: 7 additions & 63 deletions app/source/menus/menu_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -91,57 +89,21 @@ 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;
}

menubar_x -= 10.0;
menubar_x = -180;

Dirbrowse_PopulateFiles(true);
total_storage = Utils_GetTotalStorage();
used_storage = Utils_GetUsedStorage();
MENU_STATE = MENU_STATE_HOME;

old_menubar_selection = 0;
Expand All @@ -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);
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions app/source/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 393510e

Please sign in to comment.