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

View File

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

View File

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

View File

@ -1441,7 +1441,7 @@ static int MenuGameSaves(int action)
len = strlen(Memory.ROMFilename); len = strlen(Memory.ROMFilename);
len2 = strlen(browserList[i].filename); 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 len = 26; // memory card filenames are a maximum of 32 chars
// find matching files // find matching files