Skip to content

Commit

Permalink
add export methods
Browse files Browse the repository at this point in the history
  • Loading branch information
bucanero committed Dec 16, 2024
1 parent 48ee918 commit 0029e55
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 15 deletions.
1 change: 1 addition & 0 deletions include/saves.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 18 additions & 11 deletions source/exec_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -351,16 +351,16 @@ 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);
*strrchr(tmp, '/') = 0;

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);
Expand All @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
47 changes: 43 additions & 4 deletions source/saves.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;

Expand All @@ -933,23 +936,49 @@ 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);
asprintf(&trophy->options->name[2], "Save .Zip to HDD");
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);

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0029e55

Please sign in to comment.