mirror of
https://github.com/dborth/vbagx.git
synced 2024-12-28 03:31:49 +01:00
improved save file detection algorithm
This commit is contained in:
parent
3e76213c96
commit
ddf1a540d1
@ -1411,6 +1411,47 @@ static int MenuGame()
|
||||
return menu;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* FindGameSaveNum
|
||||
*
|
||||
* Determines the save file number of the given file name
|
||||
* Returns -1 if none is found
|
||||
***************************************************************************/
|
||||
static int FindGameSaveNum(char * savefile, int method)
|
||||
{
|
||||
int n = -1;
|
||||
int romlen = strlen(ROMFilename);
|
||||
int savelen = strlen(savefile);
|
||||
|
||||
if(romlen > 26 && (method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB))
|
||||
romlen = 26; // memory card filenames are a maximum of 32 chars
|
||||
|
||||
int diff = savelen-romlen;
|
||||
|
||||
if(strncmp(savefile, ROMFilename, romlen) != 0)
|
||||
return -1;
|
||||
|
||||
if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
|
||||
{
|
||||
if(diff == 2)
|
||||
n = atoi(&savefile[savelen-2]);
|
||||
else if(diff == 1)
|
||||
n = atoi(&savefile[savelen-1]);
|
||||
}
|
||||
else if(savefile[romlen] == ' ')
|
||||
{
|
||||
if(diff == 5 && strncmp((const char *)savefile[romlen+1], "Auto", 4) == 0)
|
||||
n = 0; // found Auto save
|
||||
else if(diff == 2 || diff == 3)
|
||||
n = atoi(&savefile[romlen+1]);
|
||||
}
|
||||
|
||||
if(n >= 0 && n < MAX_SAVES)
|
||||
return n;
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* MenuGameSaves
|
||||
*
|
||||
@ -1420,12 +1461,12 @@ static int MenuGameSaves(int action)
|
||||
{
|
||||
int menu = MENU_NONE;
|
||||
int ret, result;
|
||||
int i, n, len, len2;
|
||||
int i, n, type, len, len2;
|
||||
int j = 0;
|
||||
SaveList saves;
|
||||
char filepath[1024];
|
||||
char scrfile[1024];
|
||||
char tmp[256];
|
||||
char tmp[MAXJOLIET];
|
||||
struct stat filestat;
|
||||
struct tm * timeinfo;
|
||||
int method = GCSettings.SaveMethod;
|
||||
@ -1514,40 +1555,32 @@ static int MenuGameSaves(int action)
|
||||
ParseDirectory(GCSettings.SaveMethod);
|
||||
}
|
||||
|
||||
for(i=0; i < browser.numEntries; i++)
|
||||
{
|
||||
len = strlen(ROMFilename);
|
||||
len2 = strlen(browserList[i].filename);
|
||||
|
||||
if(len > 26 && (method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB))
|
||||
len = 26; // memory card filenames are a maximum of 32 chars
|
||||
|
||||
// find matching files
|
||||
if(len2 > 5 && strncmp(browserList[i].filename, ROMFilename, len) == 0)
|
||||
for(i=0; i < browser.numEntries; i++)
|
||||
{
|
||||
len2 = strlen(browserList[i].filename);
|
||||
|
||||
if(len2 < 6 || len2-len < 5)
|
||||
continue;
|
||||
|
||||
if(strncmp(&browserList[i].filename[len2-4], ".sav", 4) == 0)
|
||||
saves.type[j] = FILE_SRAM;
|
||||
type = FILE_SRAM;
|
||||
else if(strncmp(&browserList[i].filename[len2-4], ".sgm", 4) == 0)
|
||||
saves.type[j] = FILE_SNAPSHOT;
|
||||
type = FILE_SNAPSHOT;
|
||||
else
|
||||
saves.type[j] = -1;
|
||||
continue;
|
||||
|
||||
if(saves.type[j] != -1)
|
||||
{
|
||||
strncpy(tmp, browserList[i].filename, 255);
|
||||
strncpy(tmp, browserList[i].filename, MAXJOLIET);
|
||||
tmp[len2-4] = 0;
|
||||
n = FindGameSaveNum(tmp, method);
|
||||
|
||||
if(len2 - len == 7)
|
||||
n = atoi(&tmp[len2-5]);
|
||||
else if(len2 - len == 6)
|
||||
n = atoi(&tmp[len2-6]);
|
||||
else
|
||||
n = -1;
|
||||
|
||||
if(n > 0 && n < MAX_SAVES)
|
||||
if(n >= 0)
|
||||
{
|
||||
saves.type[j] = type;
|
||||
saves.files[saves.type[j]][n] = 1;
|
||||
|
||||
strncpy(saves.filename[j], browserList[i].filename, 255);
|
||||
strncpy(saves.filename[j], browserList[i].filename, MAXJOLIET);
|
||||
|
||||
if(method != METHOD_MC_SLOTA && method != METHOD_MC_SLOTB)
|
||||
{
|
||||
@ -1571,7 +1604,6 @@ static int MenuGameSaves(int action)
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
saves.length = j;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user