From cdf06dfa16b4a9a36af2b70ec4a5af676af1f3ee Mon Sep 17 00:00:00 2001 From: bucanero Date: Sat, 21 Dec 2024 08:36:15 -0300 Subject: [PATCH] remove trophy sets --- include/saves.h | 1 + source/exec_cmd.c | 3 +++ source/menu_main.c | 4 ++++ source/saves.c | 51 +++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/include/saves.h b/include/saves.h index 31c75c6..c49d948 100644 --- a/include/saves.h +++ b/include/saves.h @@ -317,6 +317,7 @@ int orbis_UpdateSaveParams(const save_entry_t* save, const char* title, const ch int trophy_lock(const save_entry_t* game, int trp_id, int grp_id, int type); int trophy_unlock(const save_entry_t* game, int trp_id, int grp_id, int type); +int trophySet_delete(const save_entry_t* game); int vmc_export_psv(const char* save, const char* out_path); int vmc_export_psu(const char* path, const char* output); diff --git a/source/exec_cmd.c b/source/exec_cmd.c index 93287b6..4c4cf30 100644 --- a/source/exec_cmd.c +++ b/source/exec_cmd.c @@ -945,6 +945,9 @@ static int deleteSave(const save_entry_t* save) else if (save->flags & SAVE_FLAG_PS2) ret = vmc_delete_save(save->dir_name); + else if (save->flags & SAVE_FLAG_TROPHY) + ret = trophySet_delete(save); + else if (save->flags & SAVE_FLAG_PS4) { if (save->flags & SAVE_FLAG_HDD) diff --git a/source/menu_main.c b/source/menu_main.c index a8df4b7..c6825e2 100644 --- a/source/menu_main.c +++ b/source/menu_main.c @@ -181,6 +181,10 @@ static void SetMenu(int id) case MENU_USB_SAVES: ReloadUserSaves(&usb_saves); break; + + case MENU_TROPHIES: + ReloadUserSaves(&trophies); + break; } selected_entry->flags ^= SAVE_FLAG_UPDATED; diff --git a/source/saves.c b/source/saves.c index 19eab8e..090c095 100644 --- a/source/saves.c +++ b/source/saves.c @@ -483,6 +483,45 @@ int trophy_lock(const save_entry_t* game, int trp_id, int grp_id, int type) return 1; } +int trophySet_delete(const save_entry_t* game) +{ + char dbpath[256]; + sqlite3 *db; + + snprintf(dbpath, sizeof(dbpath), TROPHY_DB_PATH, apollo_config.user_id); + if ((db = open_sqlite_db(dbpath)) == NULL) + return 0; + + char* query = sqlite3_mprintf("DELETE FROM tbl_trophy_title WHERE (id=%d);\n" + "DELETE FROM tbl_trophy_title_entry WHERE (id=%d);\n" + "DELETE FROM tbl_trophy_flag WHERE (title_id=%d);", + game->blocks, game->blocks, game->blocks); + + if (sqlite3_exec(db, query, NULL, NULL, NULL) != SQLITE_OK) + { + LOG("Error updating '%s': %s", game->title_id, sqlite3_errmsg(db)); + sqlite3_free(query); + sqlite3_close(db); + return 0; + } + + LOG("Saving database to %s", dbpath); + sqlite3_memvfs_dump(db, NULL, dbpath); + sqlite3_free(query); + sqlite3_close(db); + + snprintf(dbpath, sizeof(dbpath), TROPHY_PATH_HDD "%s/sealedkey", apollo_config.user_id, game->title_id); + unlink_secure(dbpath); + + snprintf(dbpath, sizeof(dbpath), TROPHY_PATH_HDD "%s/trophy.img", apollo_config.user_id, game->title_id); + unlink_secure(dbpath); + + *strrchr(dbpath, '/') = 0; + rmdir(dbpath); + + return 1; +} + int orbis_SaveDelete(const save_entry_t *save) { OrbisSaveDataDelete del; @@ -1060,6 +1099,15 @@ int ReadTrophies(save_entry_t * game) trophy = _createCmdCode(PATCH_COMMAND, CHAR_ICON_SIGN " Apply Changes to Trophy Set", CMD_UPDATE_TROPHY); list_append(game->codes, trophy); + trophy = _createCmdCode(PATCH_COMMAND, CHAR_ICON_USER " View Trophy Set Details", CMD_VIEW_DETAILS); + list_append(game->codes, trophy); + + trophy = _createCmdCode(PATCH_COMMAND, CHAR_ICON_WARN " Delete Trophy Set", CMD_DELETE_SAVE); + list_append(game->codes, trophy); + + trophy = _createCmdCode(PATCH_NULL, "----- " UTF8_CHAR_STAR " File Backup " UTF8_CHAR_STAR " -----", CMD_CODE_NULL); + list_append(game->codes, trophy); + trophy = _createCmdCode(PATCH_COMMAND, CHAR_ICON_COPY " Backup Trophy files to USB", CMD_CODE_NULL); trophy->file = strdup(game->path); trophy->options_count = 1; @@ -1074,9 +1122,6 @@ int ReadTrophies(save_entry_t * game) asprintf(&trophy->options->value[2], "%c", CMD_EXPORT_ZIP_HDD); list_append(game->codes, trophy); - trophy = _createCmdCode(PATCH_NULL, "----- " UTF8_CHAR_STAR " File Backup " UTF8_CHAR_STAR " -----", CMD_CODE_NULL); - list_append(game->codes, trophy); - trophy = _createCmdCode(PATCH_COMMAND, CHAR_ICON_COPY " Export decrypted trophy files", CMD_CODE_NULL); trophy->options_count = 1; trophy->options = _getFileOptions(game->path, "*", CMD_DECRYPT_FILE);