From e568348086a18acfbf132d07cb6c84b952e0a5fb Mon Sep 17 00:00:00 2001 From: d0k3 Date: Fri, 24 Jul 2020 10:41:02 +0200 Subject: [PATCH] Don't overwrite existing saves when installing thanks @aspargas2 --- arm9/source/utils/gameutil.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/arm9/source/utils/gameutil.c b/arm9/source/utils/gameutil.c index 3bd8578..2460b66 100644 --- a/arm9/source/utils/gameutil.c +++ b/arm9/source/utils/gameutil.c @@ -1436,19 +1436,21 @@ u32 InstallCiaSystemData(CiaStub* cia, const char* drv) { drv, tid_high, tid_low); } - // generate the save file - static const u8 zeroes[0x20] = { 0x00 }; - UINT bw; - FIL save; - fvx_rmkpath(path_save); - if (fvx_open(&save, path_save, FA_WRITE | FA_CREATE_NEW) != FR_OK) - return 1; - if ((fvx_write(&save, zeroes, 0x20, &bw) != FR_OK) || (bw != 0x20)) - bw = 0; - fvx_lseek(&save, exthdr->savedata_size); - fvx_sync(&save); - fvx_close(&save); - if (bw != 0x20) return 1; + // generate the save file, first check if it already exists + if (fvx_qsize(path_save) != exthdr->savedata_size) { + static const u8 zeroes[0x20] = { 0x00 }; + UINT bw; + FIL save; + fvx_rmkpath(path_save); + if (fvx_open(&save, path_save, FA_WRITE | FA_CREATE_ALWAYS) != FR_OK) + return 1; + if ((fvx_write(&save, zeroes, 0x20, &bw) != FR_OK) || (bw != 0x20)) + bw = 0; + fvx_lseek(&save, exthdr->savedata_size); + fvx_sync(&save); + fvx_close(&save); + if (bw != 0x20) return 1; + } } // progress update