Skip to content

Commit

Permalink
remove trophy sets
Browse files Browse the repository at this point in the history
  • Loading branch information
bucanero committed Dec 21, 2024
1 parent bf8efa6 commit cdf06df
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 3 deletions.
1 change: 1 addition & 0 deletions include/saves.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions source/exec_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions source/menu_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
51 changes: 48 additions & 3 deletions source/saves.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit cdf06df

Please sign in to comment.