From 5dff6ae49327beac3ccab1f1ef9833d17ec7c1dc Mon Sep 17 00:00:00 2001 From: illusion0001 <37698908+illusion0001@users.noreply.github.com> Date: Fri, 17 Jan 2025 16:16:16 -0600 Subject: [PATCH] Export zip decrypted save to current time (#129) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove `get_filename_id` * `zipSave`: Export decrypted save to current time --------- Co-authored-by: Damián Parrino --- source/exec_cmd.c | 46 +++++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/source/exec_cmd.c b/source/exec_cmd.c index 4c4cf30..2c8f5c4 100644 --- a/source/exec_cmd.c +++ b/source/exec_cmd.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -64,26 +65,36 @@ static void downloadSave(const save_entry_t* entry, const char* file, int dst) unlink_secure(APOLLO_LOCAL_CACHE "tmpsave.zip"); } -static uint32_t get_filename_id(const char* dir, const char* title_id) +static struct tm get_local_time(void) { - char path[128]; - uint32_t tid = 0; + int32_t tz_offset = 0; + int32_t tz_dst = 0; + int32_t ret = 0; + + if ((ret = sceSystemServiceParamGetInt(ORBIS_SYSTEM_SERVICE_PARAM_ID_TIME_ZONE, &tz_offset)) < 0) + { + LOG("Failed to obtain ORBIS_SYSTEM_SERVICE_PARAM_ID_TIME_ZONE! Setting timezone offset to 0"); + LOG("sceSystemServiceParamGetInt: 0x%08X", ret); + tz_offset = 0; + } - do + if ((ret = sceSystemServiceParamGetInt(ORBIS_SYSTEM_SERVICE_PARAM_ID_SUMMERTIME, &tz_dst)) < 0) { - tid++; - snprintf(path, sizeof(path), "%s%s-%08d.zip", dir, title_id, tid); + LOG("Failed to obtain ORBIS_SYSTEM_SERVICE_PARAM_ID_SUMMERTIME! Setting timezone daylight time savings to 0"); + LOG("sceSystemServiceParamGetInt: 0x%08X", ret); + tz_dst = 0; } - while (file_exists(path) == SUCCESS); - return tid; + time_t modifiedTime = time(NULL) + ((tz_offset + (tz_dst * 60)) * 60); + return (*gmtime(&modifiedTime)); } static void zipSave(const save_entry_t* entry, const char* exp_path) { char export_file[256]; + char zip_file[256]; + struct tm t = get_local_time(); char* tmp; - uint32_t fid; int ret; if (mkdirs(exp_path) != SUCCESS) @@ -94,14 +105,13 @@ static void zipSave(const save_entry_t* entry, const char* exp_path) init_loading_screen("Exporting save game..."); - fid = get_filename_id(exp_path, entry->title_id); - snprintf(export_file, sizeof(export_file), "%s%s-%08d.zip", exp_path, entry->title_id, fid); + snprintf(zip_file, sizeof(zip_file), "%s%s-%s_%d-%02d-%02d_%02d%02d%02d.zip", exp_path, entry->title_id, entry->dir_name, t.tm_year+1900, t.tm_mon+1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec); tmp = strdup(entry->path); *strrchr(tmp, '/') = 0; *strrchr(tmp, '/') = 0; - ret = zip_directory(tmp, entry->path, export_file); + ret = zip_directory(tmp, entry->path, zip_file); free(tmp); if (ret) @@ -110,11 +120,11 @@ static void zipSave(const save_entry_t* entry, const char* exp_path) FILE* f = fopen(export_file, "a"); if (f) { - fprintf(f, "%s-%08d.zip=%s\n", entry->title_id, fid, entry->name); + fprintf(f, "%s=[%s] %s\n", zip_file, entry->title_id, entry->name); fclose(f); } - sprintf(export_file, "%s%08x.xml", exp_path, apollo_config.user_id); + snprintf(export_file, sizeof(export_file), "%s%08x.xml", exp_path, apollo_config.user_id); save_xml_owner(export_file); } @@ -125,12 +135,12 @@ static void zipSave(const save_entry_t* entry, const char* exp_path) return; } - show_message("Zip file successfully saved to:\n%s%s-%08d.zip", exp_path, entry->title_id, fid); + show_message("Zip file successfully saved to:\n%s", zip_file); } static void copySave(const save_entry_t* save, const char* exp_path) { - char* copy_path; + char copy_path[256]; if (strncmp(save->path, exp_path, strlen(exp_path)) == 0) { @@ -146,13 +156,11 @@ static void copySave(const save_entry_t* save, const char* exp_path) init_loading_screen("Copying files..."); - asprintf(©_path, "%s%08x_%s_%s/", exp_path, apollo_config.user_id, save->title_id, save->dir_name); + snprintf(copy_path, sizeof(copy_path), "%s%08x_%s_%s/", exp_path, apollo_config.user_id, save->title_id, save->dir_name); LOG("Copying <%s> to %s...", save->path, copy_path); copy_directory(save->path, save->path, copy_path); - free(copy_path); - stop_loading_screen(); show_message("Files successfully copied to:\n%s", exp_path); }