fix memcard file browsing

This commit is contained in:
dborth 2009-03-19 16:51:36 +00:00
parent 0aabe352af
commit 565aafb30f
4 changed files with 23 additions and 33 deletions

View File

@ -194,6 +194,7 @@ bool MakeFilePath(char filepath[], int type, int method, char * filename, int fi
{
char file[512];
char folder[1024];
char ext[4];
char temppath[MAXPATHLEN];
if(type == FILE_ROM)
@ -215,44 +216,25 @@ bool MakeFilePath(char filepath[], int type, int method, char * filename, int fi
switch(type)
{
case FILE_SRAM:
sprintf(folder, GCSettings.SaveFolder);
if(filenum >= 0)
{
if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
{
filename[26] = 0; // truncate filename
sprintf(file, "%s%i.srm", filename, filenum);
}
else
{
if(filenum == 0)
sprintf(file, "%s Auto.srm", filename);
else
sprintf(file, "%s %i.srm", filename, filenum);
}
}
else
{
sprintf(file, "%s", filename);
}
break;
case FILE_SNAPSHOT:
sprintf(folder, GCSettings.SaveFolder);
if(type == FILE_SRAM) sprintf(ext, "srm");
else sprintf(ext, "frz");
if(filenum >= 0)
{
if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
{
filename[26] = 0; // truncate filename
sprintf(file, "%s%i.frz", filename, filenum);
sprintf(file, "%s%i.%", filename, filenum, ext);
}
else
{
if(filenum == 0)
sprintf(file, "%s Auto.frz", filename);
sprintf(file, "%s Auto.%", filename, ext);
else
sprintf(file, "%s %i.frz", filename, filenum);
sprintf(file, "%s %i.%", filename, filenum, ext);
}
}
else
@ -269,7 +251,7 @@ bool MakeFilePath(char filepath[], int type, int method, char * filename, int fi
sprintf(file, "%s", PREF_FILE_NAME);
break;
case FILE_SCREEN:
sprintf(folder, GCSettings.SaveFolder); // screenshot dir?
sprintf(folder, GCSettings.SaveFolder);
sprintf(file, "%s.png", Memory.ROMFilename);
break;
}

View File

@ -155,7 +155,7 @@ NGCFreezeGame (char * filepath, int method, bool silent)
char freezecomment[2][32];
memset(freezecomment, 0, 64);
sprintf (freezecomment[0], "%s Freeze", APPVERSION);
sprintf (freezecomment[0], "%s Snapshot", APPNAME);
sprintf (freezecomment[1], Memory.ROMName);
memcpy (savebuffer + woffset, freezecomment, 64);
woffset += 64;

View File

@ -98,6 +98,7 @@ ParseMCDirectory (int slot)
card_dir CardDir;
int CardError;
int entryNum = 0;
char tmpname[MAXPATHLEN];
// Try to mount the card
CardError = MountMC(slot, NOTSILENT);
@ -123,6 +124,8 @@ ParseMCDirectory (int slot)
memset(&(browserList[entryNum]), 0, sizeof(BROWSERENTRY)); // clear the new entry
strncpy(browserList[entryNum].filename, (char *)CardDir.filename, MAXJOLIET);
StripExt(tmpname, (char *)CardDir.filename); // hide file extension
strncpy(browserList[entryNum].displayname, tmpname, MAXDISPLAY); // crop name for display
browserList[entryNum].length = CardDir.filelen;
entryNum++;
@ -132,6 +135,12 @@ ParseMCDirectory (int slot)
CARD_Unmount(slot);
}
// Sort the file list
qsort(browserList, entryNum, sizeof(BROWSERENTRY), FileSortCallback);
CancelAction();
browser.numEntries = entryNum;
return entryNum;
}
@ -148,7 +157,6 @@ VerifyMCFile (char *buf, int slot, char *filename, int datasize)
unsigned int SectorSize;
int bytesleft = 0;
int bytesread = 0;
int ret = 0;
memset (verifybuffer, 0, 65536);
@ -179,22 +187,22 @@ VerifyMCFile (char *buf, int slot, char *filename, int datasize)
bytesread = 0;
while (bytesleft > 0)
{
CARD_Read (&CardFile, verifybuffer, SectorSize, bytesread);
if ( memcmp (buf + bytesread, verifybuffer, (unsigned int)bytesleft < SectorSize ? bytesleft : SectorSize) )
CardError = CARD_Read (&CardFile, verifybuffer, SectorSize, bytesread);
if (CardError || memcmp (buf + bytesread, verifybuffer, (unsigned int)bytesleft < SectorSize ? bytesleft : SectorSize) )
{
bytesread = 0;
ErrorPrompt("File integrity could not be verified!");
break;
}
bytesleft -= SectorSize;
bytesread += SectorSize;
ShowProgress ("Verifying...", bytesread, blocks);
}
CARD_Close (&CardFile);
CancelAction();
}
return ret;
return bytesread;
}
/****************************************************************************

View File

@ -1441,7 +1441,7 @@ static int MenuGameSaves(int action)
len = strlen(Memory.ROMFilename);
len2 = strlen(browserList[i].filename);
if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
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