Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
- delete ps3 saves from usb
- online db details
- online db show ps1 icons
- improve sorting
- copy to hdd only when listing usb
  • Loading branch information
bucanero committed Nov 18, 2024
1 parent 3a6f82c commit 80f48ef
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 31 deletions.
4 changes: 2 additions & 2 deletions include/saves.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ enum cmd_code_enum
CMD_CONVERT_TO_PSV,
CMD_IMPORT_DATA_FILE,
CMD_HEX_EDIT_FILE,
CMD_DELETE_VMCSAVE,
CMD_DELETE_SAVE,

// Bulk commands
CMD_RESIGN_SAVES,
Expand Down Expand Up @@ -148,7 +148,7 @@ enum cmd_code_enum
#define SAVE_FLAG_PS1 8
#define SAVE_FLAG_PS2 16
#define SAVE_FLAG_PSP 32
#define SAVE_FLAG_PSV 64
#define SAVE_FLAG_HDD 64
#define SAVE_FLAG_TROPHY 128
#define SAVE_FLAG_ONLINE 256
#define SAVE_FLAG_SELECTED 512
Expand Down
5 changes: 5 additions & 0 deletions source/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ int unlink_secure(const char *path)
return sysLv2FsUnlink(path);
//return remove(path);
}
else if (dir_exists(path)==SUCCESS)
{
sysLv2FsChmod(path, 0777);
return sysLv2FsRmdir(path);
}
return FAILED;
}

Expand Down
32 changes: 25 additions & 7 deletions source/exec_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1518,15 +1518,32 @@ static void downloadLink(const char* path)
show_message("Error! File couldn't be downloaded");
}

static void deleteVmcSave(const save_entry_t* save)
static int deleteSave(const save_entry_t* save)
{
int ret = 0;

if (!show_dialog(DIALOG_TYPE_YESNO, "Do you want to delete %s?", save->dir_name))
return;
return 0;

if ((save->flags & SAVE_FLAG_PS1) ? formatSave(save->dir_name[0]) : vmc_delete_save(save->dir_name))
if (save->flags & SAVE_FLAG_PS1)
ret = formatSave(save->dir_name[0]);

else if (save->flags & SAVE_FLAG_PS2)
ret = vmc_delete_save(save->dir_name);

else if (save->flags & SAVE_FLAG_PS3)
{
// USB saves only
clean_directory(save->path);
ret = (unlink_secure(save->path) == SUCCESS);
}

if (ret)
show_message("Save successfully deleted:\n%s", save->dir_name);
else
show_message("Error! Couldn't delete save:\n%s", save->dir_name);

return ret;
}

static void import_mcr2vmp(const save_entry_t* save, const char* src)
Expand Down Expand Up @@ -1834,10 +1851,11 @@ void execCodeCommand(code_entry_t* code, const char* codecmd)
code->activated = 0;
break;

case CMD_DELETE_VMCSAVE:
deleteVmcSave(selected_entry);
selected_entry->flags |= SAVE_FLAG_UPDATED;
code->activated = 0;
case CMD_DELETE_SAVE:
if (deleteSave(selected_entry))
selected_entry->flags |= SAVE_FLAG_UPDATED;
else
code->activated = 0;
break;

case CMD_IMPORT_DATA_FILE:
Expand Down
2 changes: 1 addition & 1 deletion source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const char * menu_pad_help[TOTAL_MENU_IDS] = { NULL, //Main
"\x10 Select \x13 Back \x12 Details \x11 Refresh", //Trophy list
"\x10 Select \x13 Back \x12 Details \x11 Refresh", //USB list
"\x10 Select \x13 Back \x12 Details \x11 Refresh", //HDD list
"\x10 Select \x13 Back \x11 Refresh", //Online list
"\x10 Select \x13 Back \x12 Details \x11 Refresh", //Online list
"\x10 Select \x13 Back \x11 Refresh", //User backup
"\x10 Select \x13 Back", //Options
"\x13 Back", //About
Expand Down
1 change: 0 additions & 1 deletion source/menu_cheats.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,6 @@ void DrawGameList(int selIndex, list_t * games, u8 alpha)
if (item->flags & SAVE_FLAG_PS3) tmp[0] = CHAR_TAG_PS3;
tmp[1] = (item->flags & SAVE_FLAG_OWNER) ? CHAR_TAG_OWNER : ' ';
tmp[2] = (item->flags & SAVE_FLAG_LOCKED) ? CHAR_TAG_LOCKED : ' ';
if (item->flags & SAVE_FLAG_PSV) tmp[1] = CHAR_TAG_PSV;
if (item->type == FILE_TYPE_VMC) tmp[1] = CHAR_TAG_VMC;

DrawString(800 - (MENU_ICON_OFF * 1), game_y, tmp);
Expand Down
44 changes: 35 additions & 9 deletions source/menu_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,17 @@ static code_entry_t* LoadSaveDetails(const save_entry_t* save)
return(centry);
}

if (save->flags & SAVE_FLAG_ONLINE)
{
asprintf(&centry->codes, "%s\n----- Online Database -----\n"
"Game: %s\n"
"Title ID: %s\n",
save->path,
save->name,
save->title_id);
return(centry);
}

if (!(save->flags & SAVE_FLAG_PS3))
{
asprintf(&centry->codes, "%s\n\nTitle: %s\n", save->path, save->name);
Expand Down Expand Up @@ -260,17 +271,25 @@ static void SetMenu(int id)
break;

case MENU_PATCHES: //Cheat Selection Menu
if (selected_entry->flags & SAVE_FLAG_UPDATED && id == MENU_PS1VMC_SAVES)
if (selected_entry->flags & SAVE_FLAG_UPDATED)
{
selected_entry->flags ^= SAVE_FLAG_UPDATED;
saveMemoryCard(vmc1_saves.path, 0, 0);
ReloadUserSaves(&vmc1_saves);
}
switch (id)
{
case MENU_PS1VMC_SAVES:
saveMemoryCard(vmc1_saves.path, 0, 0);
ReloadUserSaves(&vmc1_saves);
break;

case MENU_PS2VMC_SAVES:
ReloadUserSaves(&vmc2_saves);
break;

case MENU_USB_SAVES:
ReloadUserSaves(&usb_saves);
break;
}

else if (selected_entry->flags & SAVE_FLAG_UPDATED && id == MENU_PS2VMC_SAVES)
{
selected_entry->flags ^= SAVE_FLAG_UPDATED;
ReloadUserSaves(&vmc2_saves);
}
break;

Expand Down Expand Up @@ -380,7 +399,7 @@ static void SetMenu(int id)
snprintf(iconfile, sizeof(iconfile), APOLLO_LOCAL_CACHE "%s.PNG", selected_entry->title_id);

if (file_exists(iconfile) != SUCCESS)
http_download(selected_entry->path, "ICON0.PNG", iconfile, 1);
http_download(selected_entry->path, (selected_entry->flags & SAVE_FLAG_PS3) ? "ICON0.PNG" : "icon0.png", iconfile, 1);
}

if (selected_entry->flags & SAVE_FLAG_VMC && selected_entry->type == FILE_TYPE_PS1)
Expand Down Expand Up @@ -916,6 +935,13 @@ static void doPatchMenu(void)
return;
}

if (selected_centry->codes[0] == CMD_DELETE_SAVE)
{
selected_centry->activated = 0;
SetMenu(last_menu_id[MENU_PATCHES]);
return;
}

if (selected_centry->codes[0] == CMD_VIEW_RAW_PATCH)
{
selected_centry->activated = 0;
Expand Down
30 changes: 19 additions & 11 deletions source/saves.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,15 @@ static void _addBackupCommands(save_entry_t* item)

cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_COPY " Copy save game", CMD_CODE_NULL);
cmd->options_count = 1;
cmd->options = _createOptions(3, "Copy Save to USB", CMD_COPY_SAVE_USB);
asprintf(&cmd->options->name[2], "Copy Save to HDD");
asprintf(&cmd->options->value[2], "%c%c", CMD_COPY_SAVE_HDD, STORAGE_HDD);
cmd->options = _createOptions((item->flags & SAVE_FLAG_HDD) ? 2 : 3, "Copy Save to USB", CMD_COPY_SAVE_USB);
if (!(item->flags & SAVE_FLAG_HDD))
{
asprintf(&cmd->options->name[2], "Copy Save to HDD");
asprintf(&cmd->options->value[2], "%c%c", CMD_COPY_SAVE_HDD, STORAGE_HDD);
list_append(item->codes, cmd);

cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_WARN " Delete save game", CMD_DELETE_SAVE);
}
list_append(item->codes, cmd);

cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_ZIP " Export save game to Zip", CMD_CODE_NULL);
Expand Down Expand Up @@ -728,7 +734,7 @@ int ReadVmc1Codes(save_entry_t * save)
cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_USER " View Save Details", CMD_VIEW_DETAILS);
list_append(save->codes, cmd);

cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_WARN " Delete Save Game", CMD_DELETE_VMCSAVE);
cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_WARN " Delete Save Game", CMD_DELETE_SAVE);
list_append(save->codes, cmd);

cmd = _createCmdCode(PATCH_NULL, "----- " UTF8_CHAR_STAR " Save Game Backup " UTF8_CHAR_STAR " -----", CMD_CODE_NULL);
Expand Down Expand Up @@ -864,7 +870,7 @@ int ReadVmc2Codes(save_entry_t * save)
cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_USER " View Save Details", CMD_VIEW_DETAILS);
list_append(save->codes, cmd);

cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_WARN " Delete Save Game", CMD_DELETE_VMCSAVE);
cmd = _createCmdCode(PATCH_COMMAND, CHAR_ICON_WARN " Delete Save Game", CMD_DELETE_SAVE);
list_append(save->codes, cmd);

cmd = _createCmdCode(PATCH_NULL, "----- " UTF8_CHAR_STAR " Save Game Backup " UTF8_CHAR_STAR " -----", CMD_CODE_NULL);
Expand Down Expand Up @@ -1624,7 +1630,7 @@ int sortSaveList_Compare_Type(const void* a, const void* b)
int tb = ((save_entry_t*) b)->type;

if (ta == tb)
return 0;
return sortSaveList_Compare(a, b);
else if (ta < tb)
return -1;
else
Expand All @@ -1642,7 +1648,9 @@ int sortSaveList_Compare_TitleID(const void* a, const void* b)
if (!tb)
return (1);

return strcasecmp(ta, tb);
int ret = strcasecmp(ta, tb);

return (ret ? ret : sortSaveList_Compare(a, b));
}

static void read_savegames(const char* userPath, const char* folder, list_t *list, uint32_t flag)
Expand Down Expand Up @@ -1791,7 +1799,7 @@ list_t * ReadUserList(const char* userPath)

list = list_alloc();

item = _createSaveEntry(SAVE_FLAG_PS3, CHAR_ICON_COPY " Bulk Save Management");
item = _createSaveEntry(SAVE_FLAG_PS3 | SAVE_FLAG_HDD, CHAR_ICON_COPY " Bulk Save Management");
item->type = FILE_TYPE_MENU;
item->codes = list_alloc();
asprintf(&item->path, "%s%s", userPath, PS3_SAVES_PATH_HDD);
Expand Down Expand Up @@ -1819,9 +1827,9 @@ list_t * ReadUserList(const char* userPath)
list_append(item->codes, cmd);
list_append(list, item);

read_savegames(userPath, PS3_SAVES_PATH_HDD, list, SAVE_FLAG_PS3);
read_savegames(userPath, PS2_SAVES_PATH_HDD, list, SAVE_FLAG_PS2);
read_savegames(userPath, PSP_SAVES_PATH_HDD, list, SAVE_FLAG_PSP);
read_savegames(userPath, PS3_SAVES_PATH_HDD, list, SAVE_FLAG_PS3 | SAVE_FLAG_HDD);
read_savegames(userPath, PS2_SAVES_PATH_HDD, list, SAVE_FLAG_PS2 | SAVE_FLAG_HDD);
read_savegames(userPath, PSP_SAVES_PATH_HDD, list, SAVE_FLAG_PSP | SAVE_FLAG_HDD);

read_vmc1_files(VMC_PS2_PATH_HDD, list);
read_vmc2_files(VMC_PS2_PATH_HDD, list);
Expand Down

0 comments on commit 80f48ef

Please sign in to comment.