From 80f48ef13f86efab76d0b1d518df0f200b864a25 Mon Sep 17 00:00:00 2001 From: bucanero Date: Mon, 18 Nov 2024 08:34:29 -0300 Subject: [PATCH] improvements - delete ps3 saves from usb - online db details - online db show ps1 icons - improve sorting - copy to hdd only when listing usb --- include/saves.h | 4 ++-- source/common.c | 5 +++++ source/exec_cmd.c | 32 +++++++++++++++++++++++++------- source/main.c | 2 +- source/menu_cheats.c | 1 - source/menu_main.c | 44 +++++++++++++++++++++++++++++++++++--------- source/saves.c | 30 +++++++++++++++++++----------- 7 files changed, 87 insertions(+), 31 deletions(-) diff --git a/include/saves.h b/include/saves.h index aa95e3f..81caca1 100644 --- a/include/saves.h +++ b/include/saves.h @@ -94,7 +94,7 @@ enum cmd_code_enum CMD_CONVERT_TO_PSV, CMD_IMPORT_DATA_FILE, CMD_HEX_EDIT_FILE, - CMD_DELETE_VMCSAVE, + CMD_DELETE_SAVE, // Bulk commands CMD_RESIGN_SAVES, @@ -148,7 +148,7 @@ enum cmd_code_enum #define SAVE_FLAG_PS1 8 #define SAVE_FLAG_PS2 16 #define SAVE_FLAG_PSP 32 -#define SAVE_FLAG_PSV 64 +#define SAVE_FLAG_HDD 64 #define SAVE_FLAG_TROPHY 128 #define SAVE_FLAG_ONLINE 256 #define SAVE_FLAG_SELECTED 512 diff --git a/source/common.c b/source/common.c index 0cf3b22..e393930 100644 --- a/source/common.c +++ b/source/common.c @@ -59,6 +59,11 @@ int unlink_secure(const char *path) return sysLv2FsUnlink(path); //return remove(path); } + else if (dir_exists(path)==SUCCESS) + { + sysLv2FsChmod(path, 0777); + return sysLv2FsRmdir(path); + } return FAILED; } diff --git a/source/exec_cmd.c b/source/exec_cmd.c index 7cdff1b..ac26d17 100644 --- a/source/exec_cmd.c +++ b/source/exec_cmd.c @@ -1518,15 +1518,32 @@ static void downloadLink(const char* path) show_message("Error! File couldn't be downloaded"); } -static void deleteVmcSave(const save_entry_t* save) +static int deleteSave(const save_entry_t* save) { + int ret = 0; + if (!show_dialog(DIALOG_TYPE_YESNO, "Do you want to delete %s?", save->dir_name)) - return; + return 0; - if ((save->flags & SAVE_FLAG_PS1) ? formatSave(save->dir_name[0]) : vmc_delete_save(save->dir_name)) + if (save->flags & SAVE_FLAG_PS1) + ret = formatSave(save->dir_name[0]); + + else if (save->flags & SAVE_FLAG_PS2) + ret = vmc_delete_save(save->dir_name); + + else if (save->flags & SAVE_FLAG_PS3) + { + // USB saves only + clean_directory(save->path); + ret = (unlink_secure(save->path) == SUCCESS); + } + + if (ret) show_message("Save successfully deleted:\n%s", save->dir_name); else show_message("Error! Couldn't delete save:\n%s", save->dir_name); + + return ret; } static void import_mcr2vmp(const save_entry_t* save, const char* src) @@ -1834,10 +1851,11 @@ void execCodeCommand(code_entry_t* code, const char* codecmd) code->activated = 0; break; - case CMD_DELETE_VMCSAVE: - deleteVmcSave(selected_entry); - selected_entry->flags |= SAVE_FLAG_UPDATED; - code->activated = 0; + case CMD_DELETE_SAVE: + if (deleteSave(selected_entry)) + selected_entry->flags |= SAVE_FLAG_UPDATED; + else + code->activated = 0; break; case CMD_IMPORT_DATA_FILE: diff --git a/source/main.c b/source/main.c index 25d06a7..354be2c 100644 --- a/source/main.c +++ b/source/main.c @@ -89,7 +89,7 @@ const char * menu_pad_help[TOTAL_MENU_IDS] = { NULL, //Main "\x10 Select \x13 Back \x12 Details \x11 Refresh", //Trophy list "\x10 Select \x13 Back \x12 Details \x11 Refresh", //USB list "\x10 Select \x13 Back \x12 Details \x11 Refresh", //HDD list - "\x10 Select \x13 Back \x11 Refresh", //Online list + "\x10 Select \x13 Back \x12 Details \x11 Refresh", //Online list "\x10 Select \x13 Back \x11 Refresh", //User backup "\x10 Select \x13 Back", //Options "\x13 Back", //About diff --git a/source/menu_cheats.c b/source/menu_cheats.c index e521e61..5c79155 100644 --- a/source/menu_cheats.c +++ b/source/menu_cheats.c @@ -377,7 +377,6 @@ void DrawGameList(int selIndex, list_t * games, u8 alpha) if (item->flags & SAVE_FLAG_PS3) tmp[0] = CHAR_TAG_PS3; tmp[1] = (item->flags & SAVE_FLAG_OWNER) ? CHAR_TAG_OWNER : ' '; tmp[2] = (item->flags & SAVE_FLAG_LOCKED) ? CHAR_TAG_LOCKED : ' '; - if (item->flags & SAVE_FLAG_PSV) tmp[1] = CHAR_TAG_PSV; if (item->type == FILE_TYPE_VMC) tmp[1] = CHAR_TAG_VMC; DrawString(800 - (MENU_ICON_OFF * 1), game_y, tmp); diff --git a/source/menu_main.c b/source/menu_main.c index 899ca8f..34864d4 100644 --- a/source/menu_main.c +++ b/source/menu_main.c @@ -171,6 +171,17 @@ static code_entry_t* LoadSaveDetails(const save_entry_t* save) return(centry); } + if (save->flags & SAVE_FLAG_ONLINE) + { + asprintf(¢ry->codes, "%s\n----- Online Database -----\n" + "Game: %s\n" + "Title ID: %s\n", + save->path, + save->name, + save->title_id); + return(centry); + } + if (!(save->flags & SAVE_FLAG_PS3)) { asprintf(¢ry->codes, "%s\n\nTitle: %s\n", save->path, save->name); @@ -260,17 +271,25 @@ static void SetMenu(int id) break; case MENU_PATCHES: //Cheat Selection Menu - if (selected_entry->flags & SAVE_FLAG_UPDATED && id == MENU_PS1VMC_SAVES) + if (selected_entry->flags & SAVE_FLAG_UPDATED) { - selected_entry->flags ^= SAVE_FLAG_UPDATED; - saveMemoryCard(vmc1_saves.path, 0, 0); - ReloadUserSaves(&vmc1_saves); - } + switch (id) + { + case MENU_PS1VMC_SAVES: + saveMemoryCard(vmc1_saves.path, 0, 0); + ReloadUserSaves(&vmc1_saves); + break; + + case MENU_PS2VMC_SAVES: + ReloadUserSaves(&vmc2_saves); + break; + + case MENU_USB_SAVES: + ReloadUserSaves(&usb_saves); + break; + } - else if (selected_entry->flags & SAVE_FLAG_UPDATED && id == MENU_PS2VMC_SAVES) - { selected_entry->flags ^= SAVE_FLAG_UPDATED; - ReloadUserSaves(&vmc2_saves); } break; @@ -380,7 +399,7 @@ static void SetMenu(int id) snprintf(iconfile, sizeof(iconfile), APOLLO_LOCAL_CACHE "%s.PNG", selected_entry->title_id); if (file_exists(iconfile) != SUCCESS) - http_download(selected_entry->path, "ICON0.PNG", iconfile, 1); + http_download(selected_entry->path, (selected_entry->flags & SAVE_FLAG_PS3) ? "ICON0.PNG" : "icon0.png", iconfile, 1); } if (selected_entry->flags & SAVE_FLAG_VMC && selected_entry->type == FILE_TYPE_PS1) @@ -916,6 +935,13 @@ static void doPatchMenu(void) return; } + if (selected_centry->codes[0] == CMD_DELETE_SAVE) + { + selected_centry->activated = 0; + SetMenu(last_menu_id[MENU_PATCHES]); + return; + } + if (selected_centry->codes[0] == CMD_VIEW_RAW_PATCH) { selected_centry->activated = 0; diff --git a/source/saves.c b/source/saves.c index d3d6077..e6f4c58 100644 --- a/source/saves.c +++ b/source/saves.c @@ -236,9 +236,15 @@ static void _addBackupCommands(save_entry_t* item) cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_COPY " Copy save game", CMD_CODE_NULL); cmd->options_count = 1; - cmd->options = _createOptions(3, "Copy Save to USB", CMD_COPY_SAVE_USB); - asprintf(&cmd->options->name[2], "Copy Save to HDD"); - asprintf(&cmd->options->value[2], "%c%c", CMD_COPY_SAVE_HDD, STORAGE_HDD); + cmd->options = _createOptions((item->flags & SAVE_FLAG_HDD) ? 2 : 3, "Copy Save to USB", CMD_COPY_SAVE_USB); + if (!(item->flags & SAVE_FLAG_HDD)) + { + asprintf(&cmd->options->name[2], "Copy Save to HDD"); + asprintf(&cmd->options->value[2], "%c%c", CMD_COPY_SAVE_HDD, STORAGE_HDD); + list_append(item->codes, cmd); + + cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_WARN " Delete save game", CMD_DELETE_SAVE); + } list_append(item->codes, cmd); cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_ZIP " Export save game to Zip", CMD_CODE_NULL); @@ -728,7 +734,7 @@ int ReadVmc1Codes(save_entry_t * save) cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_USER " View Save Details", CMD_VIEW_DETAILS); list_append(save->codes, cmd); - cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_WARN " Delete Save Game", CMD_DELETE_VMCSAVE); + cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_WARN " Delete Save Game", CMD_DELETE_SAVE); list_append(save->codes, cmd); cmd = _createCmdCode(PATCH_NULL, "----- " UTF8_CHAR_STAR " Save Game Backup " UTF8_CHAR_STAR " -----", CMD_CODE_NULL); @@ -864,7 +870,7 @@ int ReadVmc2Codes(save_entry_t * save) cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_USER " View Save Details", CMD_VIEW_DETAILS); list_append(save->codes, cmd); - cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_WARN " Delete Save Game", CMD_DELETE_VMCSAVE); + cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_WARN " Delete Save Game", CMD_DELETE_SAVE); list_append(save->codes, cmd); cmd = _createCmdCode(PATCH_NULL, "----- " UTF8_CHAR_STAR " Save Game Backup " UTF8_CHAR_STAR " -----", CMD_CODE_NULL); @@ -1624,7 +1630,7 @@ int sortSaveList_Compare_Type(const void* a, const void* b) int tb = ((save_entry_t*) b)->type; if (ta == tb) - return 0; + return sortSaveList_Compare(a, b); else if (ta < tb) return -1; else @@ -1642,7 +1648,9 @@ int sortSaveList_Compare_TitleID(const void* a, const void* b) if (!tb) return (1); - return strcasecmp(ta, tb); + int ret = strcasecmp(ta, tb); + + return (ret ? ret : sortSaveList_Compare(a, b)); } static void read_savegames(const char* userPath, const char* folder, list_t *list, uint32_t flag) @@ -1791,7 +1799,7 @@ list_t * ReadUserList(const char* userPath) list = list_alloc(); - item = _createSaveEntry(SAVE_FLAG_PS3, CHAR_ICON_COPY " Bulk Save Management"); + item = _createSaveEntry(SAVE_FLAG_PS3 | SAVE_FLAG_HDD, CHAR_ICON_COPY " Bulk Save Management"); item->type = FILE_TYPE_MENU; item->codes = list_alloc(); asprintf(&item->path, "%s%s", userPath, PS3_SAVES_PATH_HDD); @@ -1819,9 +1827,9 @@ list_t * ReadUserList(const char* userPath) list_append(item->codes, cmd); list_append(list, item); - read_savegames(userPath, PS3_SAVES_PATH_HDD, list, SAVE_FLAG_PS3); - read_savegames(userPath, PS2_SAVES_PATH_HDD, list, SAVE_FLAG_PS2); - read_savegames(userPath, PSP_SAVES_PATH_HDD, list, SAVE_FLAG_PSP); + read_savegames(userPath, PS3_SAVES_PATH_HDD, list, SAVE_FLAG_PS3 | SAVE_FLAG_HDD); + read_savegames(userPath, PS2_SAVES_PATH_HDD, list, SAVE_FLAG_PS2 | SAVE_FLAG_HDD); + read_savegames(userPath, PSP_SAVES_PATH_HDD, list, SAVE_FLAG_PSP | SAVE_FLAG_HDD); read_vmc1_files(VMC_PS2_PATH_HDD, list); read_vmc2_files(VMC_PS2_PATH_HDD, list);