Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export zip decrypted save to current time #129

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 35 additions & 37 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,27 +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;

do
if ((ret = sceSystemServiceParamGetInt(ORBIS_SYSTEM_SERVICE_PARAM_ID_TIME_ZONE, &tz_offset)) < 0)
{
tid++;
snprintf(path, sizeof(path), "%s%s-%08d.zip", dir, title_id, tid);
LOG("Failed to obtain ORBIS_SYSTEM_SERVICE_PARAM_ID_TIME_ZONE! Setting timezone offset to 0");
LOG("sceSystemServiceParamGetInt: 0x%08X", ret);
tz_offset = 0;
}
while (file_exists(path) == SUCCESS);

return tid;
if ((ret = sceSystemServiceParamGetInt(ORBIS_SYSTEM_SERVICE_PARAM_ID_SUMMERTIME, &tz_dst)) < 0)
{
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;
}

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 export_file[256] = {0};
char zip_file[256] = {0};
struct tm t = get_local_time();
char* tmp;
uint32_t fid;
int ret;

if (mkdirs(exp_path) != SUCCESS)
{
Expand All @@ -94,43 +104,33 @@ 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_%d-%02d-%02d_%02d%02d%02d.zip", exp_path, 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);
free(tmp);
zip_directory(tmp, entry->path, zip_file);

if (ret)
snprintf(export_file, sizeof(export_file), "%s%08x.txt", exp_path, apollo_config.user_id);
FILE* f = fopen(export_file, "a");
if (f)
{
snprintf(export_file, sizeof(export_file), "%s%08x.txt", exp_path, apollo_config.user_id);
FILE* f = fopen(export_file, "a");
if (f)
{
fprintf(f, "%s-%08d.zip=%s\n", entry->title_id, fid, entry->name);
fclose(f);
}

sprintf(export_file, "%s%08x.xml", exp_path, apollo_config.user_id);
save_xml_owner(export_file);
fprintf(f, "%s=[%s] %s\n", zip_file, entry->title_id, entry->name);
fclose(f);
}

stop_loading_screen();
if (!ret)
{
show_message("Error! Can't export save game to:\n%s", exp_path);
return;
}
snprintf(export_file, sizeof(export_file), "%s%08x.xml", exp_path, apollo_config.user_id);
save_xml_owner(export_file);
free(tmp);

show_message("Zip file successfully saved to:\n%s%s-%08d.zip", exp_path, entry->title_id, fid);
stop_loading_screen();
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] = {0};

if (strncmp(save->path, exp_path, strlen(exp_path)) == 0)
{
Expand All @@ -146,13 +146,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