From 0029e55ffa14e012fed9d3adb27f6ab209c39106 Mon Sep 17 00:00:00 2001 From: bucanero Date: Sun, 15 Dec 2024 21:34:26 -0300 Subject: [PATCH] add export methods --- include/saves.h | 1 + source/exec_cmd.c | 29 ++++++++++++++++++----------- source/saves.c | 47 +++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 62 insertions(+), 15 deletions(-) diff --git a/include/saves.h b/include/saves.h index 1d7b49c..2bd22f3 100644 --- a/include/saves.h +++ b/include/saves.h @@ -76,6 +76,7 @@ enum cmd_code_enum CMD_RESIGN_TROPHY, CMD_EXP_TROPHY_USB, CMD_COPY_TROPHIES_USB, + CMD_COPY_ALL_TROPHIES_USB, CMD_ZIP_TROPHY_USB, // Save commands diff --git a/source/exec_cmd.c b/source/exec_cmd.c index 9f0a11d..5a93dcc 100644 --- a/source/exec_cmd.c +++ b/source/exec_cmd.c @@ -336,8 +336,8 @@ static void exportFingerprint(const save_entry_t* save, int silent) if (!silent) show_message("%s fingerprint successfully saved to:\n%s", save->title_id, fpath); } -/* -void exportTrophiesZip(const char* exp_path) + +static void exportTrophiesZip(const char* exp_path) { char* export_file; char* trp_path; @@ -351,7 +351,7 @@ void exportTrophiesZip(const char* exp_path) init_loading_screen("Exporting Trophies ..."); - asprintf(&export_file, "%s" "trophies_%08d.zip", exp_path, apollo_config.user_id); + asprintf(&export_file, "%s" "trophies_%08x.zip", exp_path, apollo_config.user_id); asprintf(&trp_path, TROPHY_PATH_HDD, apollo_config.user_id); tmp = strdup(trp_path); @@ -359,8 +359,8 @@ void exportTrophiesZip(const char* exp_path) zip_directory(tmp, trp_path, export_file); - sprintf(export_file, "%s" OWNER_XML_FILE, exp_path); - _saveOwnerData(export_file); + sprintf(export_file, "%s%08x.xml", exp_path, apollo_config.user_id); + save_xml_owner(export_file); free(export_file); free(trp_path); @@ -369,7 +369,6 @@ void exportTrophiesZip(const char* exp_path) stop_loading_screen(); show_message("Trophies successfully saved to:\n%strophies_%08d.zip", exp_path, apollo_config.user_id); } -*/ static void dumpAllFingerprints(const save_entry_t* save) { @@ -726,7 +725,9 @@ static void copyAllSavesUSB(const save_entry_t* save, const char* dst_path, int for (node = list_head(list); (item = list_get(node)); node = list_next(node)) { update_progress_bar(progress++, list_count(list), item->name); - if (item->type != FILE_TYPE_PS4 || !(all || item->flags & SAVE_FLAG_SELECTED) || !orbis_SaveMount(item, ORBIS_SAVE_DATA_MOUNT_MODE_RDONLY, mount)) + if (!(item->type == FILE_TYPE_PS4 || item->type == FILE_TYPE_TRP) || + !(all || item->flags & SAVE_FLAG_SELECTED) || + !orbis_SaveMount(item, (item->flags & SAVE_FLAG_TROPHY), mount)) continue; snprintf(save_path, sizeof(save_path), APOLLO_SANDBOX_PATH, mount); @@ -1081,7 +1082,7 @@ static int apply_cheat_patches(const save_entry_t* entry) if (!code->activated || (code->type != PATCH_GAMEGENIE && code->type != PATCH_BSD)) continue; - LOG("Active code: [%s]", code->name); + LOG("Active code: [%s]", code->name); if (strrchr(code->file, '\\')) filename = strrchr(code->file, '\\')+1; @@ -1367,17 +1368,23 @@ void execCodeCommand(code_entry_t* code, const char* codecmd) enableWebServer(dbg_simpleWebServerHandler, NULL, 8080); code->activated = 0; break; -/* + case CMD_ZIP_TROPHY_USB: exportTrophiesZip(codecmd[1] ? EXPORT_PATH_USB1 : EXPORT_PATH_USB0); code->activated = 0; break; case CMD_COPY_TROPHIES_USB: - exportFolder(selected_entry->path, codecmd[1] ? TROPHY_PATH_USB1 : TROPHY_PATH_USB0, "Copying trophies..."); + case CMD_COPY_ALL_TROPHIES_USB: + copyAllSavesUSB(selected_entry, codecmd[1] ? TROPHY_PATH_USB1 : TROPHY_PATH_USB0, codecmd[0] == CMD_COPY_ALL_TROPHIES_USB); + code->activated = 0; + break; + + case CMD_EXP_TROPHY_USB: + copySave(selected_entry, codecmd[1] ? TROPHY_PATH_USB1 : TROPHY_PATH_USB0); code->activated = 0; break; -*/ + case CMD_BROWSER_HISTORY: toggleBrowserHistory(apollo_config.user_id); code->activated = 0; diff --git a/source/saves.c b/source/saves.c index 99634c9..16ef18c 100644 --- a/source/saves.c +++ b/source/saves.c @@ -483,6 +483,7 @@ int orbis_SaveMount(const save_entry_t *save, uint32_t mount_mode, char* mount_p LOG("Saving database to %s", dbpath); sqlite3_memvfs_dump(db, NULL, dbpath); + sqlite3_free(query); sqlite3_close(db); } @@ -925,6 +926,8 @@ int ReadTrophies(save_entry_t * game) int trop_count = 0; code_entry_t * trophy; char query[256]; + char mount[ORBIS_SAVE_DATA_DIRNAME_DATA_MAXSIZE]; + char *tmp; sqlite3 *db; sqlite3_stmt *res; @@ -933,16 +936,25 @@ int ReadTrophies(save_entry_t * game) game->codes = list_alloc(); + if (!orbis_SaveMount(game, (game->flags & SAVE_FLAG_TROPHY), mount)) + { + trophy = _createCmdCode(PATCH_NULL, CHAR_ICON_WARN " --- Error Mounting Trophy Set! --- " CHAR_ICON_WARN, CMD_CODE_NULL); + list_append(game->codes, trophy); + return list_count(game->codes); + } + tmp = game->path; + asprintf(&game->path, APOLLO_SANDBOX_PATH, mount); + // trophy = _createCmdCode(PATCH_COMMAND, CHAR_ICON_SIGN " Apply Changes & Resign Trophy Set", CMD_RESIGN_TROPHY); // list_append(game->codes, trophy); - trophy = _createCmdCode(PATCH_COMMAND, CHAR_ICON_COPY " Backup Trophy Set to USB", CMD_CODE_NULL); + trophy = _createCmdCode(PATCH_COMMAND, CHAR_ICON_COPY " Backup Trophy files to USB", CMD_CODE_NULL); trophy->file = strdup(game->path); trophy->options_count = 1; trophy->options = _createOptions(2, "Copy Trophy to USB", CMD_EXP_TROPHY_USB); list_append(game->codes, trophy); - trophy = _createCmdCode(PATCH_COMMAND, CHAR_ICON_ZIP " Export Trophy Set to Zip", CMD_CODE_NULL); + trophy = _createCmdCode(PATCH_COMMAND, CHAR_ICON_ZIP " Export Trophy files to Zip", CMD_CODE_NULL); trophy->file = strdup(game->path); trophy->options_count = 1; trophy->options = _createOptions(3, "Save .Zip to USB", CMD_EXPORT_ZIP_USB); @@ -950,6 +962,23 @@ 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); + list_append(game->codes, trophy); + + trophy = _createCmdCode(PATCH_COMMAND, CHAR_ICON_COPY " Import decrypted trophy files", CMD_CODE_NULL); + trophy->options_count = 1; + trophy->options = _getFileOptions(game->path, "*", CMD_IMPORT_DATA_FILE); + list_append(game->codes, trophy); + + orbis_SaveUmount(mount); + free(game->path); + game->path = tmp; + trophy = _createCmdCode(PATCH_NULL, "----- " UTF8_CHAR_STAR " Trophies " UTF8_CHAR_STAR " -----", CMD_CODE_NULL); list_append(game->codes, trophy); @@ -2391,11 +2420,21 @@ list_t * ReadTrophyList(const char* userPath) item->type = FILE_TYPE_MENU; item->path = strdup(userPath); item->codes = list_alloc(); - cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_COPY " Backup Trophies to USB", CMD_CODE_NULL); + //bulk management hack + item->dir_name = malloc(sizeof(void**)); + ((void**)item->dir_name)[0] = list; + + cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_COPY " Backup selected Trophies to USB", CMD_CODE_NULL); cmd->options_count = 1; cmd->options = _createOptions(2, "Save Trophies to USB", CMD_COPY_TROPHIES_USB); list_append(item->codes, cmd); - cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_ZIP " Export Trophies to .Zip", CMD_CODE_NULL); + + cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_COPY " Backup all Trophies to USB", CMD_CODE_NULL); + cmd->options_count = 1; + cmd->options = _createOptions(2, "Save Trophies to USB", CMD_COPY_ALL_TROPHIES_USB); + list_append(item->codes, cmd); + + cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_ZIP " Export all encrypted Trophies to .Zip", CMD_CODE_NULL); cmd->options_count = 1; cmd->options = _createOptions(2, "Save .Zip to USB", CMD_ZIP_TROPHY_USB); list_append(item->codes, cmd);