Skip to content

Commit

Permalink
delete ps1 saves from vmc
Browse files Browse the repository at this point in the history
  • Loading branch information
bucanero committed Jul 24, 2024
1 parent 11bd134 commit 1e08589
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 16 deletions.
2 changes: 1 addition & 1 deletion include/ps1card.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ uint8_t* getSaveBytes(int slotNumber, uint32_t* saveLen);
void toggleDeleteSave(int slotNumber);

//Format save
void formatSave(int slotNumber);
int formatSave(int slotNumber);

//Get Memory Card data
ps1mcData_t* getMemoryCardData(void);
2 changes: 2 additions & 0 deletions include/saves.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ enum cmd_code_enum
CMD_EXP_FINGERPRINT,
CMD_HEX_EDIT_FILE,
CMD_IMPORT_DATA_FILE,
CMD_DELETE_VMCSAVE,

// Bulk commands
CMD_RESIGN_SAVES,
Expand Down Expand Up @@ -131,6 +132,7 @@ enum cmd_code_enum
#define SAVE_FLAG_ONLINE 256
#define SAVE_FLAG_PS1 512
#define SAVE_FLAG_HDD 1024
#define SAVE_FLAG_UPDATED 2048

enum save_type_enum
{
Expand Down
27 changes: 22 additions & 5 deletions source/exec_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ static void exportAllSavesVMC(const save_entry_t* save, int dev, int all)
if (!all && !(item->flags & SAVE_FLAG_SELECTED))
continue;

if (item->type & FILE_TYPE_PS1)
if (item->type == FILE_TYPE_PS1)
(saveSingleSave(outPath, item->blocks, PS1SAVE_PSV) ? done++ : err_count++);
}

Expand Down Expand Up @@ -572,6 +572,17 @@ static void exportVmcSave(const save_entry_t* save, int type, int dst_id)
show_message("Error exporting save:\n%s", save->path);
}

static void deleteVmcSave(const save_entry_t* save)
{
if (!show_dialog(DIALOG_TYPE_YESNO, "Do you want to delete %s?", save->dir_name))
return;

if ((save->flags & SAVE_FLAG_PS1) && formatSave(save->blocks))
show_message("Save successfully deleted:\n%s", save->dir_name);
else
show_message("Error! Couldn't delete save:\n%s", save->dir_name);
}

static void copyKeystone(const save_entry_t* entry, int import)
{
char path_data[256];
Expand Down Expand Up @@ -1237,7 +1248,7 @@ static void import_mcr2vmp(const save_entry_t* save, const char* src)
snprintf(mcrPath, sizeof(mcrPath), PS1_SAVES_PATH_HDD "%s/%s", save->title_id, src);
read_buffer(mcrPath, &data, &size);

if (openMemoryCardStream(data, size, 0) && saveMemoryCard(save->path, 0, 0))
if (openMemoryCardStream(data, size, 0))
show_message("Memory card successfully imported to:\n%s", save->path);
else
show_message("Error importing memory card:\n%s", mcrPath);
Expand Down Expand Up @@ -1407,6 +1418,7 @@ void execCodeCommand(code_entry_t* code, const char* codecmd)

case CMD_IMP_MCR2VMP:
import_mcr2vmp(selected_entry, code->options[0].name[code->options[0].sel]);
selected_entry->flags |= SAVE_FLAG_UPDATED;
code->activated = 0;
break;

Expand Down Expand Up @@ -1463,12 +1475,17 @@ void execCodeCommand(code_entry_t* code, const char* codecmd)

case CMD_IMP_VMCSAVE:
if (openSingleSave(code->file, (int*) host_buf))
{
saveMemoryCard(selected_entry->dir_name, 0, 0);
show_message("Save successfully imported:\n%s", code->file);
}
else
show_message("Error! Couldn't import save:\n%s", code->file);

selected_entry->flags |= SAVE_FLAG_UPDATED;
code->activated = 0;
break;

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

Expand Down
24 changes: 15 additions & 9 deletions source/menu_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ static code_entry_t* LoadRawPatch(void)
return centry;
}

static code_entry_t* LoadSaveDetails(void)
static code_entry_t* LoadSaveDetails(const save_entry_t* save)
{
code_entry_t* centry = calloc(1, sizeof(code_entry_t));
centry->name = strdup(selected_entry->title_id);
centry->name = strdup(save->title_id);

if (!get_save_details(selected_entry, &centry->codes))
asprintf(&centry->codes, "Error getting details (%s)", selected_entry->name);
if (!get_save_details(save, &centry->codes))
asprintf(&centry->codes, "Error getting details (%s)", save->name);

LOG("%s", centry->codes);
return (centry);
Expand All @@ -117,7 +117,6 @@ static void SetMenu(int id)
LOG("Saving VMC changes...");
UnloadGameList(vmc_saves.list);
vmc_saves.list = NULL;
saveMemoryCard(vmc_saves.path, 0, 0);
}

case MENU_MAIN_SCREEN: //Main Menu
Expand All @@ -131,7 +130,15 @@ static void SetMenu(int id)

case MENU_SETTINGS: //Options Menu
case MENU_CREDITS: //About Menu
break;

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

case MENU_SAVE_DETAILS:
Expand Down Expand Up @@ -396,7 +403,7 @@ static void doSaveMenu(save_list_t * save_list)
selected_entry = list_get_item(save_list->list, menu_sel);
if (selected_entry->type != FILE_TYPE_MENU)
{
selected_centry = LoadSaveDetails();
selected_centry = LoadSaveDetails(selected_entry);
SetMenu(MENU_SAVE_DETAILS);
return;
}
Expand Down Expand Up @@ -735,8 +742,7 @@ static void doPatchMenu(void)
list_node_t* node;

for (node = list_head(selected_entry->codes); (code = list_get(node)); node = list_next(node))
if (wildcard_match_icase(code->name, "*(REQUIRED)*"))
// && !strchr(code->file, '*')
if (wildcard_match_icase(code->name, "*(REQUIRED)*") && code->options_count == 0)
code->activated = 1;
}
/*
Expand Down Expand Up @@ -766,7 +772,7 @@ static void doPatchMenu(void)
if (selected_centry->codes[0] == CMD_VIEW_DETAILS)
{
selected_centry->activated = 0;
selected_centry = LoadSaveDetails();
selected_centry = LoadSaveDetails(selected_entry);
SetMenu(MENU_SAVE_DETAILS);
return;
}
Expand Down
6 changes: 5 additions & 1 deletion source/ps1card.c
Original file line number Diff line number Diff line change
Expand Up @@ -568,14 +568,17 @@ static void formatSlot(int slotNumber)
}

//Format save
void formatSave(int slotNumber)
int formatSave(int slotNumber)
{
//Get all linked saves
int saveSlots_Length;
int saveSlots[PS1CARD_MAX_SLOTS];

saveSlots_Length = findSaveLinks(slotNumber, saveSlots);

if (!saveSlots_Length)
return false;

//Cycle through each slot
for (int i = 0; i < saveSlots_Length; i++)
{
Expand All @@ -594,6 +597,7 @@ void formatSave(int slotNumber)

//Set changedFlag to edited
changedFlag = true;
return true;
}

//Find and return continuous free slots
Expand Down
3 changes: 3 additions & 0 deletions source/saves.c
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,9 @@ int ReadVmcCodes(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);
list_append(save->codes, cmd);

cmd = _createCmdCode(PATCH_NULL, "----- " UTF8_CHAR_STAR " Save Backup " UTF8_CHAR_STAR " -----", CMD_CODE_NULL);
list_append(save->codes, cmd);

Expand Down

0 comments on commit 1e08589

Please sign in to comment.