Skip to content

Commit

Permalink
Export zip decrypted save to current time (#129)
Browse files Browse the repository at this point in the history
* Remove `get_filename_id`
* `zipSave`: Export decrypted save to current time

---------

Co-authored-by: Damián Parrino <bucanero@users.noreply.github.com>
  • Loading branch information
illusion0001 and bucanero authored Jan 17, 2025
1 parent d23eab0 commit 5dff6ae
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions source/exec_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <time.h>
#include <orbis/NetCtl.h>
#include <orbis/SaveData.h>
#include <orbis/SystemService.h>
#include <orbis/UserService.h>
#include <orbis/SystemService.h>
#include <polarssl/md5.h>
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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);
}

Expand All @@ -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)
{
Expand All @@ -146,13 +156,11 @@ static void copySave(const save_entry_t* save, const char* exp_path)

init_loading_screen("Copying files...");

asprintf(&copy_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);
}
Expand Down

0 comments on commit 5dff6ae

Please sign in to comment.