From e0f60f7ba63b6b08355a7eeb078b315d00c82ca3 Mon Sep 17 00:00:00 2001 From: dborth Date: Thu, 9 Apr 2009 07:41:37 +0000 Subject: [PATCH] fix memory card saves --- source/ngc/filebrowser.cpp | 16 ++++++++++++++-- source/ngc/vbasupport.cpp | 31 +++++++++++++------------------ 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/source/ngc/filebrowser.cpp b/source/ngc/filebrowser.cpp index 92f8dec..d4fc08a 100644 --- a/source/ngc/filebrowser.cpp +++ b/source/ngc/filebrowser.cpp @@ -218,8 +218,20 @@ bool MakeFilePath(char filepath[], int type, int method, char * filename, int fi { if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) { - filename[26] = 0; // truncate filename - sprintf(file, "%s%i.%s", filename, filenum, ext); + if(filenum > 9) + { + return false; + } + else if(filenum == -1) + { + filename[27] = 0; // truncate filename + sprintf(file, "%s.%s", filename, ext); + } + else + { + filename[26] = 0; // truncate filename + sprintf(file, "%s%i.%s", filename, filenum, ext); + } } else { diff --git a/source/ngc/vbasupport.cpp b/source/ngc/vbasupport.cpp index eabd862..d2e9fef 100644 --- a/source/ngc/vbasupport.cpp +++ b/source/ngc/vbasupport.cpp @@ -325,27 +325,22 @@ bool LoadBatteryOrStateAuto(int method, int action, bool silent) if (action==FILE_SRAM) { - if (!LoadBatteryOrState(filepath, method, action, SILENT)) - { - if(!MakeFilePath(filepath2, action, method, ROMFilename, -1)) - return false; - if(LoadBatteryOrState(filepath2, method, action, silent)) - { - // rename this file - append Auto - sprintf(fullpath, "%s%s", rootdir, filepath); // add device to path - sprintf(fullpath2, "%s%s", rootdir, filepath2); // add device to path - rename(fullpath2, fullpath); // rename file (to avoid duplicates) - return true; - } - else - { - return false; - } - } - else + if (LoadBatteryOrState(filepath, method, action, SILENT)) + return true; + + // look for file with no number or Auto appended + if(!MakeFilePath(filepath2, action, method, ROMFilename, -1)) + return false; + + if(LoadBatteryOrState(filepath2, method, action, silent)) { + // rename this file - append Auto + sprintf(fullpath, "%s%s", rootdir, filepath); // add device to path + sprintf(fullpath2, "%s%s", rootdir, filepath2); // add device to path + rename(fullpath2, fullpath); // rename file (to avoid duplicates) return true; } + return false; } else {