mirror of
https://github.com/dborth/snes9xgx.git
synced 2024-11-01 00:15:14 +01:00
tidy up file code
This commit is contained in:
parent
2aa6868725
commit
4d82b68041
@ -12,9 +12,7 @@
|
||||
#include "cheats.h"
|
||||
|
||||
#include "snes9xGX.h"
|
||||
#include "fileop.h"
|
||||
#include "filesel.h"
|
||||
#include "smbop.h"
|
||||
#include "menudraw.h"
|
||||
|
||||
extern SCheatData Cheat;
|
||||
@ -73,21 +71,12 @@ SetupCheats()
|
||||
if(method == METHOD_AUTO)
|
||||
method = autoSaveMethod();
|
||||
|
||||
if(!MakeFilePath(filepath, FILE_CHEAT, method))
|
||||
return;
|
||||
|
||||
AllocSaveBuffer();
|
||||
|
||||
if(method == METHOD_SD || method == METHOD_USB)
|
||||
{
|
||||
if(ChangeFATInterface(method, NOTSILENT))
|
||||
{
|
||||
sprintf (filepath, "%s/%s/%s.cht", ROOTFATDIR, GCSettings.CheatFolder, Memory.ROMFilename);
|
||||
offset = LoadBufferFromFAT (filepath, SILENT);
|
||||
}
|
||||
}
|
||||
else if(method == METHOD_SMB)
|
||||
{
|
||||
sprintf (filepath, "%s/%s.cht", GCSettings.CheatFolder, Memory.ROMFilename);
|
||||
offset = LoadBufferFromSMB (filepath, SILENT);
|
||||
}
|
||||
offset = LoadFile(filepath, method, SILENT);
|
||||
|
||||
// load cheat file if present
|
||||
if(offset > 0)
|
||||
|
@ -32,6 +32,7 @@ extern "C" {
|
||||
u64 dvddir = 0; // offset of currently selected file or folder
|
||||
int dvddirlength = 0; // length of currently selected file or folder
|
||||
u64 dvdrootdir = 0; // offset of DVD root
|
||||
int dvdrootlength = 0; // length of DVD root
|
||||
bool isWii = false;
|
||||
|
||||
#ifdef HW_DOL
|
||||
@ -263,8 +264,9 @@ getpvd ()
|
||||
memcpy(&rootdir32, &dvdbuffer[PVDROOT + EXTENT], 4);
|
||||
dvddir = (u64)rootdir32;
|
||||
dvddir <<= 11;
|
||||
dvdrootdir = dvddir;
|
||||
memcpy (&dvddirlength, &dvdbuffer[PVDROOT + FILE_LENGTH], 4);
|
||||
dvdrootdir = dvddir;
|
||||
dvdrootlength = dvddirlength;
|
||||
IsJoliet = 1;
|
||||
break;
|
||||
}
|
||||
@ -309,7 +311,6 @@ getpvd ()
|
||||
***************************************************************************/
|
||||
bool TestDVD()
|
||||
{
|
||||
|
||||
if (!getpvd())
|
||||
{
|
||||
#ifdef HW_DOL
|
||||
@ -557,6 +558,11 @@ bool SwitchDVDFolder(char origdir[])
|
||||
if(dir[strlen(dir)-1] == '/')
|
||||
dir[strlen(dir)-1] = 0;
|
||||
|
||||
// start searching at root of DVD
|
||||
dvddir = dvdrootdir;
|
||||
dvddirlength = dvdrootlength;
|
||||
ParseDVDdirectory();
|
||||
|
||||
return SwitchDVDFolder(dirptr, 0);
|
||||
}
|
||||
|
||||
@ -570,7 +576,7 @@ bool SwitchDVDFolder(char origdir[])
|
||||
***************************************************************************/
|
||||
|
||||
int
|
||||
LoadDVDFile (unsigned char *buffer, int length)
|
||||
LoadDVDFileOffset (unsigned char *buffer, int length)
|
||||
{
|
||||
int offset;
|
||||
int blocks;
|
||||
@ -578,9 +584,6 @@ LoadDVDFile (unsigned char *buffer, int length)
|
||||
u64 discoffset;
|
||||
char readbuffer[2048];
|
||||
|
||||
dvddir = filelist[selection].offset;
|
||||
dvddirlength = filelist[selection].length;
|
||||
|
||||
// How many 2k blocks to read
|
||||
blocks = dvddirlength / 2048;
|
||||
offset = 0;
|
||||
@ -595,7 +598,11 @@ LoadDVDFile (unsigned char *buffer, int length)
|
||||
{
|
||||
dvd_read (readbuffer, 2048, discoffset);
|
||||
|
||||
if (!IsZipFile (readbuffer))
|
||||
if (IsZipFile (readbuffer))
|
||||
{
|
||||
return UnZipBuffer (buffer, METHOD_DVD); // unzip from dvd
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < blocks; i++)
|
||||
{
|
||||
@ -603,6 +610,7 @@ LoadDVDFile (unsigned char *buffer, int length)
|
||||
memcpy (buffer + offset, readbuffer, 2048);
|
||||
offset += 2048;
|
||||
discoffset += 2048;
|
||||
ShowProgress ((char *)"Loading...", offset, length);
|
||||
}
|
||||
|
||||
/*** And final cleanup ***/
|
||||
@ -613,14 +621,25 @@ LoadDVDFile (unsigned char *buffer, int length)
|
||||
memcpy (buffer + offset, readbuffer, i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return UnZipBuffer (buffer, METHOD_DVD); // unzip from dvd
|
||||
}
|
||||
}
|
||||
return dvddirlength;
|
||||
}
|
||||
|
||||
int
|
||||
LoadDVDFile(char * buffer, char *filepath, int datasize, bool silent)
|
||||
{
|
||||
if(SwitchDVDFolder(filepath))
|
||||
{
|
||||
return LoadDVDFileOffset ((unsigned char *)buffer, datasize);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!silent)
|
||||
WaitPrompt((char *)"Error loading file!");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* uselessinquiry
|
||||
*
|
||||
|
@ -15,7 +15,8 @@
|
||||
|
||||
int getpvd ();
|
||||
int ParseDVDdirectory ();
|
||||
int LoadDVDFile (unsigned char *buffer, int length);
|
||||
int LoadDVDFileOffset(unsigned char *buffer, int length);
|
||||
int LoadDVDFile(char * buffer, char *filepath, int datasize, bool silent);
|
||||
bool TestDVD();
|
||||
int dvd_read (void *dst, unsigned int len, u64 offset);
|
||||
int dvd_safe_read (void *dst, unsigned int len, u64 offset);
|
||||
|
@ -30,26 +30,6 @@
|
||||
// FAT file pointer - the only one we should ever use!
|
||||
FILE * fatfile;
|
||||
|
||||
/****************************************************************************
|
||||
* MountFAT
|
||||
* Attempts to mount the FAT device specified
|
||||
* Sets libfat to use the device by default
|
||||
* Enables read-ahead cache for SD/USB
|
||||
***************************************************************************/
|
||||
bool MountFAT(PARTITION_INTERFACE part)
|
||||
{
|
||||
bool mounted = fatMountNormalInterface(part, 8);
|
||||
|
||||
if(mounted)
|
||||
{
|
||||
fatSetDefaultInterface(part);
|
||||
#ifdef HW_RVL
|
||||
if(part == PI_INTERNAL_SD || part == PI_USBSTORAGE)
|
||||
fatEnableReadAhead (part, 6, 64);
|
||||
#endif
|
||||
}
|
||||
return mounted;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* UnmountFAT
|
||||
@ -75,6 +55,31 @@ void UnmountAllFAT()
|
||||
UnmountFAT(PI_SDGECKO_B);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* MountFAT
|
||||
* Checks if the device needs to be (re)mounted
|
||||
* If so, unmounts the device
|
||||
* Attempts to mount the device specified
|
||||
* Sets libfat to use the device by default
|
||||
* Enables read-ahead cache for SD/USB
|
||||
***************************************************************************/
|
||||
bool MountFAT(PARTITION_INTERFACE part)
|
||||
{
|
||||
UnmountFAT(part);
|
||||
|
||||
bool mounted = fatMountNormalInterface(part, 8);
|
||||
|
||||
if(mounted)
|
||||
{
|
||||
fatSetDefaultInterface(part);
|
||||
#ifdef HW_RVL
|
||||
if(part == PI_INTERNAL_SD || part == PI_USBSTORAGE)
|
||||
fatEnableReadAhead (part, 6, 64);
|
||||
#endif
|
||||
}
|
||||
return mounted;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* ChangeFATInterface
|
||||
* Unmounts all devices and attempts to mount/configure the device specified
|
||||
@ -83,9 +88,6 @@ bool ChangeFATInterface(int method, bool silent)
|
||||
{
|
||||
bool mounted = false;
|
||||
|
||||
// unmount all FAT devices
|
||||
UnmountAllFAT();
|
||||
|
||||
if(method == METHOD_SD)
|
||||
{
|
||||
#ifdef HW_RVL
|
||||
@ -103,6 +105,7 @@ bool ChangeFATInterface(int method, bool silent)
|
||||
{
|
||||
#ifdef HW_RVL
|
||||
mounted = MountFAT(PI_USBSTORAGE);
|
||||
|
||||
if(!mounted && !silent)
|
||||
WaitPrompt ((char *)"USB drive not found!");
|
||||
#endif
|
||||
@ -172,67 +175,6 @@ ParseFATdirectory(int method)
|
||||
return nbfiles;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* LoadFATFile
|
||||
***************************************************************************/
|
||||
int
|
||||
LoadFATFile (char * rbuffer, int length)
|
||||
{
|
||||
char zipbuffer[2048];
|
||||
char filepath[MAXPATHLEN];
|
||||
u32 size;
|
||||
|
||||
/* Check filename length */
|
||||
if (!MakeROMPath(filepath, METHOD_SD))
|
||||
{
|
||||
WaitPrompt((char*) "Maximum filepath length reached!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
fatfile = fopen (filepath, "rb");
|
||||
if (fatfile > 0)
|
||||
{
|
||||
if(length > 0 && length <= 2048) // do a partial read (eg: to check file header)
|
||||
{
|
||||
fread (rbuffer, 1, length, fatfile);
|
||||
size = length;
|
||||
}
|
||||
else // load whole file
|
||||
{
|
||||
fread (zipbuffer, 1, 2048, fatfile);
|
||||
|
||||
if (IsZipFile (zipbuffer))
|
||||
{
|
||||
size = UnZipBuffer ((unsigned char *)rbuffer, METHOD_SD); // unzip from FAT
|
||||
}
|
||||
else
|
||||
{
|
||||
// Just load the file up
|
||||
fseek(fatfile, 0, SEEK_END);
|
||||
size = ftell(fatfile); // get filesize
|
||||
fseek(fatfile, 2048, SEEK_SET); // seek back to point where we left off
|
||||
memcpy (rbuffer, zipbuffer, 2048); // copy what we already read
|
||||
|
||||
ShowProgress ((char *)"Loading...", 2048, size);
|
||||
|
||||
u32 offset = 2048;
|
||||
while(offset < size)
|
||||
{
|
||||
offset += fread (rbuffer + offset, 1, (1024*512), fatfile); // read in 512K chunks
|
||||
ShowProgress ((char *)"Loading...", offset, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose (fatfile);
|
||||
return size;
|
||||
}
|
||||
else
|
||||
{
|
||||
WaitPrompt((char*) "Error opening file");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* LoadFATSzFile
|
||||
* Loads the selected file # from the specified 7z into rbuffer
|
||||
@ -257,41 +199,71 @@ LoadFATSzFile(char * filepath, unsigned char * rbuffer)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Load savebuffer from FAT file
|
||||
* LoadFATFile
|
||||
***************************************************************************/
|
||||
int
|
||||
LoadBufferFromFAT (char *filepath, bool silent)
|
||||
LoadFATFile (char * rbuffer, char *filepath, int length, bool silent)
|
||||
{
|
||||
char zipbuffer[2048];
|
||||
int size = 0;
|
||||
int readsize = 0;
|
||||
|
||||
fatfile = fopen (filepath, "rb");
|
||||
|
||||
if (fatfile <= 0)
|
||||
if (fatfile > 0)
|
||||
{
|
||||
if ( !silent )
|
||||
if(length > 0 && length <= 2048) // do a partial read (eg: to check file header)
|
||||
{
|
||||
char msg[100];
|
||||
sprintf(msg, "Couldn't open %s", filepath);
|
||||
WaitPrompt (msg);
|
||||
fread (rbuffer, 1, length, fatfile);
|
||||
size = length;
|
||||
}
|
||||
else // load whole file
|
||||
{
|
||||
readsize = fread (zipbuffer, 1, 2048, fatfile);
|
||||
|
||||
if(readsize > 0)
|
||||
{
|
||||
if (IsZipFile (zipbuffer))
|
||||
{
|
||||
size = UnZipBuffer ((unsigned char *)rbuffer, METHOD_SD); // unzip from FAT
|
||||
}
|
||||
else
|
||||
{
|
||||
// Just load the file up
|
||||
fseek(fatfile, 0, SEEK_END);
|
||||
size = ftell(fatfile); // get filesize
|
||||
fseek(fatfile, 2048, SEEK_SET); // seek back to point where we left off
|
||||
memcpy (rbuffer, zipbuffer, 2048); // copy what we already read
|
||||
|
||||
ShowProgress ((char *)"Loading...", 2048, length);
|
||||
|
||||
int offset = 2048;
|
||||
while(offset < size && readsize != 0)
|
||||
{
|
||||
readsize = fread (rbuffer + offset, 1, (1024*512), fatfile); // read in 512K chunks
|
||||
offset += readsize;
|
||||
ShowProgress ((char *)"Loading...", offset, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose (fatfile);
|
||||
return size;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!silent)
|
||||
WaitPrompt((char*) "Error opening file!");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Just load the file up
|
||||
fseek(fatfile, 0, SEEK_END); // go to end of file
|
||||
size = ftell(fatfile); // get filesize
|
||||
fseek(fatfile, 0, SEEK_SET); // go to start of file
|
||||
fread (savebuffer, 1, size, fatfile);
|
||||
fclose (fatfile);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Write savebuffer to FAT card file
|
||||
* SaveFATFile
|
||||
* Write buffer to FAT card file
|
||||
***************************************************************************/
|
||||
int
|
||||
SaveBufferToFAT (char *filepath, int datasize, bool silent)
|
||||
SaveFATFile (char * buffer, char *filepath, int datasize, bool silent)
|
||||
{
|
||||
if (datasize)
|
||||
{
|
||||
|
@ -26,10 +26,9 @@
|
||||
|
||||
bool ChangeFATInterface(int method, bool silent);
|
||||
int ParseFATdirectory(int method);
|
||||
int LoadFATFile (char * fbuffer, int length);
|
||||
int LoadFATSzFile(char * filepath, unsigned char * rbuffer);
|
||||
int SaveBufferToFAT (char *filepath, int datasize, bool silent);
|
||||
int LoadBufferFromFAT (char *filepath, bool silent);
|
||||
int SaveFATFile (char * sbuffer, char *filepath, int length, bool silent);
|
||||
int LoadFATFile (char * sbuffer, char *filepath, int length, bool silent);
|
||||
|
||||
extern char currFATdir[MAXPATHLEN];
|
||||
extern FILE * fatfile;
|
||||
|
@ -145,12 +145,11 @@ int UpdateDirName(int method)
|
||||
char * test;
|
||||
char temp[1024];
|
||||
|
||||
// update DVD directory (does not utilize 'currentdir')
|
||||
// update DVD directory
|
||||
if(method == METHOD_DVD)
|
||||
{
|
||||
dvddir = filelist[selection].offset;
|
||||
dvddirlength = filelist[selection].length;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* current directory doesn't change */
|
||||
@ -188,32 +187,133 @@ int UpdateDirName(int method)
|
||||
}
|
||||
else
|
||||
{
|
||||
WaitPrompt((char*)"Directory name is too long !");
|
||||
WaitPrompt((char*)"Directory name is too long!");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool MakeROMPath(char filepath[], int method)
|
||||
bool MakeFilePath(char filepath[], int type, int method)
|
||||
{
|
||||
char file[512];
|
||||
char folder[1024];
|
||||
char temppath[MAXPATHLEN];
|
||||
|
||||
// Check filename length
|
||||
if ((strlen(currentdir)+1+strlen(filelist[selection].filename)) < MAXPATHLEN)
|
||||
if(type == FILE_ROM)
|
||||
{
|
||||
sprintf(temppath, "%s/%s",currentdir,filelist[selection].filename);
|
||||
|
||||
if(method == METHOD_SMB)
|
||||
strcpy(filepath, SMBPath(temppath));
|
||||
else
|
||||
strcpy(filepath, temppath);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
// Check path length
|
||||
if ((strlen(currentdir)+1+strlen(filelist[selection].filename)) >= MAXPATHLEN)
|
||||
{
|
||||
WaitPrompt((char*)"Maximum filepath length reached!");
|
||||
filepath[0] = 0;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(temppath, "%s/%s",currentdir,filelist[selection].filename);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case FILE_SRAM:
|
||||
sprintf(folder, GCSettings.SaveFolder);
|
||||
sprintf(file, "%s.srm", Memory.ROMFilename);
|
||||
break;
|
||||
case FILE_SNAPSHOT:
|
||||
sprintf(folder, GCSettings.SaveFolder);
|
||||
sprintf(file, "%s.frz", Memory.ROMFilename);
|
||||
break;
|
||||
case FILE_CHEAT:
|
||||
sprintf(folder, GCSettings.CheatFolder);
|
||||
sprintf(file, "%s.cht", Memory.ROMFilename);
|
||||
break;
|
||||
case FILE_PREF:
|
||||
sprintf(folder, GCSettings.SaveFolder);
|
||||
sprintf(file, "%s", PREF_FILE_NAME);
|
||||
break;
|
||||
}
|
||||
switch(method)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
sprintf (temppath, "%s/%s/%s", ROOTFATDIR, folder, file);
|
||||
break;
|
||||
case METHOD_DVD:
|
||||
case METHOD_SMB:
|
||||
sprintf (temppath, "%s/%s", folder, file);
|
||||
break;
|
||||
case METHOD_MC_SLOTA:
|
||||
case METHOD_MC_SLOTB:
|
||||
sprintf (temppath, "%s", file);
|
||||
temppath[31] = 0; // truncate filename
|
||||
break;
|
||||
}
|
||||
}
|
||||
strcpy(filepath, temppath);
|
||||
return true;
|
||||
}
|
||||
|
||||
int LoadFile(char * buffer, char filepath[], int length, int method, bool silent)
|
||||
{
|
||||
int offset = 0;
|
||||
|
||||
switch(method)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
if(ChangeFATInterface(method, NOTSILENT))
|
||||
offset = LoadFATFile (buffer, filepath, length, silent);
|
||||
break;
|
||||
case METHOD_SMB:
|
||||
offset = LoadSMBFile (buffer, filepath, length, silent);
|
||||
break;
|
||||
case METHOD_DVD:
|
||||
offset = LoadDVDFile (buffer, filepath, length, silent);
|
||||
break;
|
||||
case METHOD_MC_SLOTA:
|
||||
offset = LoadMCFile (buffer, CARD_SLOTA, filepath, silent);
|
||||
break;
|
||||
case METHOD_MC_SLOTB:
|
||||
offset = LoadMCFile (buffer, CARD_SLOTB, filepath, silent);
|
||||
break;
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
int LoadFile(char filepath[], int method, bool silent)
|
||||
{
|
||||
return LoadFile((char *)savebuffer, filepath, 0, method, silent);
|
||||
}
|
||||
|
||||
int SaveFile(char * buffer, char filepath[], int datasize, int method, bool silent)
|
||||
{
|
||||
int offset = 0;
|
||||
|
||||
switch(method)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
if(ChangeFATInterface(method, NOTSILENT))
|
||||
offset = SaveFATFile (buffer, filepath, datasize, silent);
|
||||
break;
|
||||
case METHOD_SMB:
|
||||
offset = SaveSMBFile (buffer, filepath, datasize, silent);
|
||||
break;
|
||||
case METHOD_MC_SLOTA:
|
||||
offset = SaveMCFile (buffer, CARD_SLOTA, filepath, datasize, silent);
|
||||
break;
|
||||
case METHOD_MC_SLOTB:
|
||||
offset = SaveMCFile (buffer, CARD_SLOTB, filepath, datasize, silent);
|
||||
break;
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
int SaveFile(char filepath[], int datasize, int method, bool silent)
|
||||
{
|
||||
return SaveFile((char *)savebuffer, filepath, datasize, method, silent);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -449,11 +549,9 @@ int FileSelector (int method)
|
||||
if(IsSz())
|
||||
{
|
||||
// we'll store the 7z filepath for extraction later
|
||||
if(!MakeROMPath(szpath, method))
|
||||
{
|
||||
WaitPrompt((char*) "Maximum filepath length reached!");
|
||||
if(!MakeFilePath(szpath, FILE_ROM, method))
|
||||
return 0;
|
||||
}
|
||||
|
||||
int szfiles = SzParse(szpath, method);
|
||||
if(szfiles)
|
||||
{
|
||||
@ -476,30 +574,31 @@ int FileSelector (int method)
|
||||
|
||||
SNESROMSize = 0;
|
||||
|
||||
if(!inSz)
|
||||
{
|
||||
char filepath[1024];
|
||||
|
||||
if(!MakeFilePath(filepath, FILE_ROM, method))
|
||||
return 0;
|
||||
|
||||
SNESROMSize = LoadFile ((char *)Memory.ROM, filepath, filelist[selection].length, method, NOTSILENT);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (method)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
if(inSz)
|
||||
SNESROMSize = LoadFATSzFile(szpath, (unsigned char *)Memory.ROM);
|
||||
else
|
||||
SNESROMSize = LoadFATFile ((char *)Memory.ROM, filelist[selection].length);
|
||||
break;
|
||||
|
||||
case METHOD_DVD:
|
||||
if(inSz)
|
||||
SNESROMSize = SzExtractFile(filelist[selection].offset, (unsigned char *)Memory.ROM);
|
||||
else
|
||||
SNESROMSize = LoadDVDFile (Memory.ROM, filelist[selection].length);
|
||||
break;
|
||||
|
||||
case METHOD_SMB:
|
||||
if(inSz)
|
||||
SNESROMSize = LoadSMBSzFile(szpath, (unsigned char *)Memory.ROM);
|
||||
else
|
||||
SNESROMSize = LoadSMBFile ((char *)Memory.ROM, filelist[selection].length);
|
||||
break;
|
||||
}
|
||||
}
|
||||
inSz = false;
|
||||
|
||||
if (SNESROMSize > 0)
|
||||
@ -645,6 +744,7 @@ OpenDVD (int method)
|
||||
}
|
||||
}
|
||||
|
||||
currentdir[0] = 0;
|
||||
maxfiles = ParseDVDdirectory(); // load root folder
|
||||
|
||||
// switch to rom folder
|
||||
|
@ -40,7 +40,11 @@ extern unsigned long SNESROMSize;
|
||||
|
||||
void AllocSaveBuffer();
|
||||
void FreeSaveBuffer();
|
||||
bool MakeROMPath(char filepath[], int method);
|
||||
bool MakeFilePath(char filepath[], int type, int method);
|
||||
int LoadFile(char * buffer, char filepath[], int length, int method, bool silent);
|
||||
int LoadFile(char filepath[], int method, bool silent);
|
||||
int SaveFile(char * buffer, char filepath[], int datasize, int method, bool silent);
|
||||
int SaveFile(char filepath[], int datasize, int method, bool silent);
|
||||
int OpenROM (int method);
|
||||
int autoLoadMethod();
|
||||
int autoSaveMethod();
|
||||
|
@ -33,9 +33,6 @@
|
||||
#include "freeze.h"
|
||||
#include "filesel.h"
|
||||
#include "menudraw.h"
|
||||
#include "smbop.h"
|
||||
#include "fileop.h"
|
||||
#include "memcardop.h"
|
||||
|
||||
extern void S9xSRTCPreSaveState ();
|
||||
extern void NGCFreezeStruct ();
|
||||
@ -126,43 +123,33 @@ NGCFreezeMemBuffer ()
|
||||
int
|
||||
NGCFreezeGame (int method, bool8 silent)
|
||||
{
|
||||
char filepath[1024];
|
||||
int offset = 0; // bytes written (actual)
|
||||
int woffset = 0; // bytes written (expected)
|
||||
char msg[100];
|
||||
|
||||
ShowAction ((char*) "Saving...");
|
||||
|
||||
if(method == METHOD_AUTO)
|
||||
method = autoSaveMethod();
|
||||
|
||||
char filename[1024];
|
||||
int offset = 0;
|
||||
char msg[100];
|
||||
if(!MakeFilePath(filepath, FILE_SNAPSHOT, method))
|
||||
return 0;
|
||||
|
||||
S9xSetSoundMute (TRUE);
|
||||
S9xPrepareSoundForSnapshotSave (FALSE);
|
||||
|
||||
AllocSaveBuffer ();
|
||||
NGCFreezeMemBuffer (); // copy freeze mem into savebuffer
|
||||
woffset = bufoffset;
|
||||
|
||||
S9xPrepareSoundForSnapshotSave (TRUE);
|
||||
S9xSetSoundMute (FALSE);
|
||||
|
||||
if (method == METHOD_SD || method == METHOD_USB) // FAT devices
|
||||
if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) // MC Slot A or B
|
||||
{
|
||||
if(ChangeFATInterface(method, NOTSILENT))
|
||||
{
|
||||
sprintf (filename, "%s/%s/%s.frz", ROOTFATDIR, GCSettings.SaveFolder, Memory.ROMFilename);
|
||||
offset = SaveBufferToFAT (filename, bufoffset, silent);
|
||||
}
|
||||
}
|
||||
else if (method == METHOD_SMB) // SMB
|
||||
{
|
||||
sprintf (filename, "%s/%s.frz", GCSettings.SaveFolder, Memory.ROMFilename);
|
||||
offset = SaveBufferToSMB (filename, bufoffset, silent);
|
||||
}
|
||||
else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) // MC Slot A or B
|
||||
{
|
||||
sprintf (filename, "%s.snz", Memory.ROMName);
|
||||
|
||||
// Copy in save icon
|
||||
int woffset = sizeof (saveicon);
|
||||
woffset = sizeof (saveicon);
|
||||
memcpy (savebuffer, saveicon, woffset);
|
||||
|
||||
// And the freezecomment
|
||||
@ -191,13 +178,10 @@ NGCFreezeGame (int method, bool8 silent)
|
||||
woffset += 4;
|
||||
|
||||
woffset += zippedsize;
|
||||
|
||||
if(method == METHOD_MC_SLOTA)
|
||||
offset = SaveBufferToMC ( savebuffer, CARD_SLOTA, filename, woffset, SILENT );
|
||||
else
|
||||
offset = SaveBufferToMC ( savebuffer, CARD_SLOTB, filename, woffset, SILENT );
|
||||
}
|
||||
|
||||
offset = SaveFile(filepath, woffset, method, silent);
|
||||
|
||||
FreeSaveBuffer ();
|
||||
|
||||
if(offset > 0) // save successful!
|
||||
@ -253,43 +237,28 @@ NGCUnFreezeBlock (char *name, uint8 * block, int size)
|
||||
int
|
||||
NGCUnfreezeGame (int method, bool8 silent)
|
||||
{
|
||||
ShowAction ((char*) "Loading...");
|
||||
char filename[1024];
|
||||
char filepath[1024];
|
||||
int offset = 0;
|
||||
int result = 0;
|
||||
char msg[80];
|
||||
|
||||
bufoffset = 0;
|
||||
|
||||
ShowAction ((char*) "Loading...");
|
||||
|
||||
if(method == METHOD_AUTO)
|
||||
method = autoSaveMethod(); // we use 'Save' because snapshot needs R/W
|
||||
|
||||
if(!MakeFilePath(filepath, FILE_SNAPSHOT, method))
|
||||
return 0;
|
||||
|
||||
AllocSaveBuffer ();
|
||||
|
||||
if (method == METHOD_SD || method == METHOD_USB) // SD & USB
|
||||
{
|
||||
if(ChangeFATInterface(method, NOTSILENT))
|
||||
{
|
||||
sprintf (filename, "%s/%s/%s.frz", ROOTFATDIR, GCSettings.SaveFolder, Memory.ROMFilename);
|
||||
offset = LoadBufferFromFAT (filename, silent);
|
||||
}
|
||||
}
|
||||
else if (method == METHOD_SMB) // Network (SMB)
|
||||
{
|
||||
sprintf (filename, "%s/%s.frz", GCSettings.SaveFolder, Memory.ROMFilename);
|
||||
offset = LoadBufferFromSMB (filename, silent);
|
||||
}
|
||||
else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) // MC in slot A or slot B
|
||||
{
|
||||
sprintf (filename, "%s.snz", Memory.ROMName);
|
||||
offset = LoadFile(filepath, method, silent);
|
||||
|
||||
int ret = 0;
|
||||
|
||||
if(method == METHOD_MC_SLOTA)
|
||||
ret = LoadBufferFromMC ( savebuffer, CARD_SLOTA, filename, silent );
|
||||
else
|
||||
ret = LoadBufferFromMC ( savebuffer, CARD_SLOTB, filename, silent );
|
||||
|
||||
if (ret)
|
||||
if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB) // MC in slot A or slot B
|
||||
{
|
||||
if (offset)
|
||||
{
|
||||
char * zipbuffer = (char *)malloc(SAVEBUFFERSIZE);
|
||||
memset (zipbuffer, 0, SAVEBUFFERSIZE);
|
||||
@ -323,15 +292,9 @@ NGCUnfreezeGame (int method, bool8 silent)
|
||||
memcpy (savebuffer, zipbuffer, SAVEBUFFERSIZE);
|
||||
}
|
||||
free(zipbuffer);
|
||||
zipbuffer = NULL;
|
||||
|
||||
if(offset == 0)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int result = 0;
|
||||
|
||||
if(offset > 0)
|
||||
{
|
||||
if (S9xUnfreezeGame ("AGAME") == SUCCESS)
|
||||
|
@ -130,7 +130,7 @@ int MountCard(int cslot, bool silent)
|
||||
* Verify Memory Card file against buffer
|
||||
***************************************************************************/
|
||||
int
|
||||
VerifyMCFile (unsigned char *buf, int slot, char *filename, int datasize)
|
||||
VerifyMCFile (char *buf, int slot, char *filename, int datasize)
|
||||
{
|
||||
int CardError;
|
||||
unsigned int blocks;
|
||||
@ -207,10 +207,11 @@ VerifyMCFile (unsigned char *buf, int slot, char *filename, int datasize)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* LoadMCFile
|
||||
* Load savebuffer from Memory Card file
|
||||
***************************************************************************/
|
||||
int
|
||||
LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool8 silent)
|
||||
LoadMCFile (char *buf, int slot, char *filename, bool silent)
|
||||
{
|
||||
int CardError;
|
||||
unsigned int blocks;
|
||||
@ -272,10 +273,11 @@ LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool8 silent)
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* SaveMCFile
|
||||
* Write savebuffer to Memory Card file
|
||||
***************************************************************************/
|
||||
int
|
||||
SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool8 silent)
|
||||
SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
|
||||
{
|
||||
int CardError;
|
||||
unsigned int blocks;
|
||||
|
@ -13,10 +13,9 @@
|
||||
#ifndef _NGCMCSAVE_
|
||||
#define _NGCMCSAVE_
|
||||
|
||||
int VerifyMCFile (unsigned char *buf, int slot, char *filename, int datasize);
|
||||
|
||||
int LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool8 silent);
|
||||
int SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool8 silent);
|
||||
int VerifyMCFile (char *buf, int slot, char *filename, int datasize);
|
||||
int LoadMCFile (char *buf, int slot, char *filename, bool silent);
|
||||
int SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent);
|
||||
int MountCard(int cslot, bool silent);
|
||||
bool TestCard(int slot, bool silent);
|
||||
|
||||
|
@ -14,9 +14,6 @@
|
||||
|
||||
#include "snes9xGX.h"
|
||||
#include "menudraw.h"
|
||||
#include "fileop.h"
|
||||
#include "dvd.h"
|
||||
#include "smbop.h"
|
||||
#include "memfile.h"
|
||||
#include "filesel.h"
|
||||
|
||||
@ -411,46 +408,25 @@ bool patchApplyPPF(MFILE *f, u8 **rom, int *size)
|
||||
void LoadPatch(int method)
|
||||
{
|
||||
int patchsize = 0;
|
||||
int patchtype = -1;
|
||||
int patchtype;
|
||||
char patchpath[3][512];
|
||||
|
||||
ShowAction((char *)"Loading patch...");
|
||||
|
||||
AllocSaveBuffer ();
|
||||
|
||||
char patchpath[3][512];
|
||||
memset(patchpath, 0, sizeof(patchpath));
|
||||
sprintf(patchpath[0], "%s/%s.ips", currentdir, Memory.ROMFilename);
|
||||
sprintf(patchpath[1], "%s/%s.ups", currentdir, Memory.ROMFilename);
|
||||
sprintf(patchpath[2], "%s/%s.ppf", currentdir, Memory.ROMFilename);
|
||||
|
||||
ShowAction((char *)"Loading patch...");
|
||||
|
||||
switch (method)
|
||||
for(patchtype=0; patchtype<3; patchtype++)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
for(int i=0; i<3; i++)
|
||||
{
|
||||
patchsize = LoadBufferFromFAT (patchpath[i], SILENT);
|
||||
patchsize = LoadFile(patchpath[patchtype], method, SILENT);
|
||||
|
||||
if(patchsize)
|
||||
{
|
||||
patchtype = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case METHOD_SMB:
|
||||
for(int i=0; i<3; i++)
|
||||
{
|
||||
patchsize = LoadBufferFromSMB (patchpath[i], SILENT);
|
||||
|
||||
if(patchsize)
|
||||
{
|
||||
patchtype = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(patchsize > 0)
|
||||
{
|
||||
|
@ -25,8 +25,6 @@
|
||||
|
||||
extern int currconfig[4];
|
||||
|
||||
#define PREFS_FILE_NAME "SNES9xGX.xml"
|
||||
|
||||
char prefscomment[2][32];
|
||||
|
||||
/****************************************************************************
|
||||
@ -316,42 +314,25 @@ decodePrefsData (int method)
|
||||
bool
|
||||
SavePrefs (int method, bool silent)
|
||||
{
|
||||
char filepath[1024];
|
||||
int datasize;
|
||||
int offset = 0;
|
||||
|
||||
// there's no point in saving SMB settings TO SMB, because then we'll have no way to load them the next time!
|
||||
// so instead we'll save using whatever other method is available (eg: SD)
|
||||
if(method == METHOD_AUTO || method == METHOD_SMB)
|
||||
method = autoSaveMethod();
|
||||
|
||||
char filepath[1024];
|
||||
int datasize;
|
||||
int offset = 0;
|
||||
|
||||
AllocSaveBuffer ();
|
||||
datasize = preparePrefsData (method);
|
||||
if(!MakeFilePath(filepath, FILE_PREF, method))
|
||||
return false;
|
||||
|
||||
if (!silent)
|
||||
ShowAction ((char*) "Saving preferences...");
|
||||
|
||||
if(method == METHOD_SD || method == METHOD_USB)
|
||||
{
|
||||
if(ChangeFATInterface(method, NOTSILENT))
|
||||
{
|
||||
sprintf (filepath, "%s/%s/%s", ROOTFATDIR, GCSettings.SaveFolder, PREFS_FILE_NAME);
|
||||
offset = SaveBufferToFAT (filepath, datasize, silent);
|
||||
}
|
||||
}
|
||||
else if(method == METHOD_SMB)
|
||||
{
|
||||
sprintf (filepath, "%s/%s", GCSettings.SaveFolder, PREFS_FILE_NAME);
|
||||
offset = SaveBufferToSMB (filepath, datasize, silent);
|
||||
}
|
||||
else if(method == METHOD_MC_SLOTA)
|
||||
{
|
||||
offset = SaveBufferToMC (savebuffer, CARD_SLOTA, (char *)PREFS_FILE_NAME, datasize, silent);
|
||||
}
|
||||
else if(method == METHOD_MC_SLOTB)
|
||||
{
|
||||
offset = SaveBufferToMC (savebuffer, CARD_SLOTB, (char *)PREFS_FILE_NAME, datasize, silent);
|
||||
}
|
||||
AllocSaveBuffer ();
|
||||
datasize = preparePrefsData (method);
|
||||
|
||||
offset = SaveFile(filepath, datasize, method, silent);
|
||||
|
||||
FreeSaveBuffer ();
|
||||
|
||||
@ -374,29 +355,12 @@ LoadPrefsFromMethod (int method)
|
||||
char filepath[1024];
|
||||
int offset = 0;
|
||||
|
||||
if(!MakeFilePath(filepath, FILE_PREF, method))
|
||||
return false;
|
||||
|
||||
AllocSaveBuffer ();
|
||||
|
||||
if(method == METHOD_SD || method == METHOD_USB)
|
||||
{
|
||||
if(ChangeFATInterface(method, NOTSILENT))
|
||||
{
|
||||
sprintf (filepath, "%s/%s/%s", ROOTFATDIR, GCSettings.SaveFolder, PREFS_FILE_NAME);
|
||||
offset = LoadBufferFromFAT (filepath, SILENT);
|
||||
}
|
||||
}
|
||||
else if(method == METHOD_SMB)
|
||||
{
|
||||
sprintf (filepath, "%s/%s", GCSettings.SaveFolder, PREFS_FILE_NAME);
|
||||
offset = LoadBufferFromSMB (filepath, SILENT);
|
||||
}
|
||||
else if(method == METHOD_MC_SLOTA)
|
||||
{
|
||||
offset = LoadBufferFromMC (savebuffer, CARD_SLOTA, (char *)PREFS_FILE_NAME, SILENT);
|
||||
}
|
||||
else if(method == METHOD_MC_SLOTB)
|
||||
{
|
||||
offset = LoadBufferFromMC (savebuffer, CARD_SLOTB, (char *)PREFS_FILE_NAME, SILENT);
|
||||
}
|
||||
offset = LoadFile(filepath, method, SILENT);
|
||||
|
||||
if (offset > 0)
|
||||
retval = decodePrefsData (method);
|
||||
|
@ -224,25 +224,6 @@ SMBFILE OpenSMBFile(char * filepath)
|
||||
return SMB_OpenFile (SMBPath(filepath), SMB_OPEN_READING, SMB_OF_OPEN, smbconn);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Load SMB file
|
||||
* rom - pointer to memory where ROM will be stored
|
||||
* length - # bytes to read (0 for all)
|
||||
****************************************************************************/
|
||||
int
|
||||
LoadSMBFile (char * rom, int length)
|
||||
{
|
||||
char filepath[MAXPATHLEN];
|
||||
|
||||
/* Check filename length */
|
||||
if (!MakeROMPath(filepath, METHOD_SMB))
|
||||
{
|
||||
WaitPrompt((char*) "Maximum filepath length reached!");
|
||||
return -1;
|
||||
}
|
||||
return LoadBufferFromSMB(rom, filepath, length, NOTSILENT);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* LoadSMBSzFile
|
||||
* Loads the selected file # from the specified 7z into rbuffer
|
||||
@ -270,17 +251,12 @@ LoadSMBSzFile(char * filepath, unsigned char * rbuffer)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Write savebuffer to SMB file
|
||||
* SaveSMBFile
|
||||
* Write buffer to SMB file
|
||||
****************************************************************************/
|
||||
// no buffer specified, use savebuffer
|
||||
int
|
||||
SaveBufferToSMB (char *filepath, int datasize, bool silent)
|
||||
{
|
||||
return SaveBufferToSMB((char *)savebuffer, filepath, datasize, silent);
|
||||
}
|
||||
|
||||
int
|
||||
SaveBufferToSMB (char * sbuffer, char *filepath, int datasize, bool silent)
|
||||
SaveSMBFile (char * sbuffer, char *filepath, int datasize, bool silent)
|
||||
{
|
||||
if(!ConnectShare (NOTSILENT))
|
||||
return 0;
|
||||
@ -320,18 +296,12 @@ SaveBufferToSMB (char * sbuffer, char *filepath, int datasize, bool silent)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* LoadSMBFile
|
||||
* Load up a buffer from SMB file
|
||||
****************************************************************************/
|
||||
|
||||
// no buffer is specified - so use savebuffer
|
||||
int
|
||||
LoadBufferFromSMB (char *filepath, bool silent)
|
||||
{
|
||||
return LoadBufferFromSMB((char *)savebuffer, filepath, 0, silent);
|
||||
}
|
||||
|
||||
int
|
||||
LoadBufferFromSMB (char * sbuffer, char *filepath, int length, bool silent)
|
||||
LoadSMBFile (char * sbuffer, char *filepath, int length, bool silent)
|
||||
{
|
||||
if(!ConnectShare (NOTSILENT))
|
||||
return 0;
|
||||
|
@ -22,12 +22,9 @@ char * SMBPath(char * path);
|
||||
int UpdateSMBdirname();
|
||||
int ParseSMBdirectory ();
|
||||
SMBFILE OpenSMBFile(char * filepath);
|
||||
int LoadSMBFile (char * fbuffer, int length);
|
||||
int LoadSMBSzFile(char * filepath, unsigned char * rbuffer);
|
||||
int LoadBufferFromSMB (char *filepath, bool silent);
|
||||
int LoadBufferFromSMB (char * sbuffer, char *filepath, int length, bool silent);
|
||||
int SaveBufferToSMB (char *filepath, int datasize, bool silent);
|
||||
int SaveBufferToSMB (char * sbuffer, char *filepath, int datasize, bool silent);
|
||||
int LoadSMBFile (char * sbuffer, char *filepath, int length, bool silent);
|
||||
int SaveSMBFile (char * sbuffer, char *filepath, int length, bool silent);
|
||||
|
||||
extern SMBFILE smbfile;
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#define VERSIONNUM "006"
|
||||
#define VERSIONSTR "Snes9x GX 006"
|
||||
#define PREF_FILE_NAME "SNES9xGX.xml"
|
||||
|
||||
#define NOTSILENT 0
|
||||
#define SILENT 1
|
||||
@ -33,6 +34,14 @@ enum {
|
||||
METHOD_MC_SLOTB
|
||||
};
|
||||
|
||||
enum {
|
||||
FILE_ROM,
|
||||
FILE_SRAM,
|
||||
FILE_SNAPSHOT,
|
||||
FILE_CHEAT,
|
||||
FILE_PREF
|
||||
};
|
||||
|
||||
struct SGCSettings{
|
||||
int AutoLoad;
|
||||
int AutoSave;
|
||||
|
@ -22,9 +22,6 @@
|
||||
#include "snes9xGX.h"
|
||||
#include "images/saveicon.h"
|
||||
#include "menudraw.h"
|
||||
#include "memcardop.h"
|
||||
#include "fileop.h"
|
||||
#include "smbop.h"
|
||||
#include "filesel.h"
|
||||
|
||||
extern int padcal;
|
||||
@ -144,53 +141,32 @@ decodesavedata (int method, int readsize)
|
||||
int
|
||||
LoadSRAM (int method, bool silent)
|
||||
{
|
||||
ShowAction ((char*) "Loading...");
|
||||
char filepath[1024];
|
||||
int offset = 0;
|
||||
|
||||
if(method == METHOD_AUTO)
|
||||
method = autoSaveMethod(); // we use 'Save' because SRAM needs R/W
|
||||
|
||||
char filepath[1024];
|
||||
int offset = 0;
|
||||
if(!MakeFilePath(filepath, FILE_SRAM, method))
|
||||
return 0;
|
||||
|
||||
ShowAction ((char*) "Loading...");
|
||||
|
||||
AllocSaveBuffer();
|
||||
|
||||
if(method == METHOD_SD || method == METHOD_USB)
|
||||
{
|
||||
if(ChangeFATInterface(method, NOTSILENT))
|
||||
{
|
||||
sprintf (filepath, "%s/%s/%s.srm", ROOTFATDIR, GCSettings.SaveFolder, Memory.ROMFilename);
|
||||
offset = LoadBufferFromFAT (filepath, silent);
|
||||
}
|
||||
}
|
||||
else if(method == METHOD_SMB)
|
||||
{
|
||||
sprintf (filepath, "%s/%s.srm", GCSettings.SaveFolder, Memory.ROMFilename);
|
||||
offset = LoadBufferFromSMB (filepath, silent);
|
||||
}
|
||||
else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
|
||||
{
|
||||
sprintf (filepath, "%s.srm", Memory.ROMName);
|
||||
|
||||
if(method == METHOD_MC_SLOTA)
|
||||
offset = LoadBufferFromMC (savebuffer, CARD_SLOTA, filepath, silent);
|
||||
else
|
||||
offset = LoadBufferFromMC (savebuffer, CARD_SLOTB, filepath, silent);
|
||||
}
|
||||
offset = LoadFile(filepath, method, silent);
|
||||
|
||||
if (offset > 0)
|
||||
{
|
||||
decodesavedata (method, offset);
|
||||
S9xSoftReset();
|
||||
}
|
||||
|
||||
FreeSaveBuffer ();
|
||||
|
||||
if(offset > 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
FreeSaveBuffer ();
|
||||
|
||||
// if we reached here, nothing was done!
|
||||
if(!silent)
|
||||
WaitPrompt ((char*) "SRAM file not found");
|
||||
@ -205,44 +181,26 @@ LoadSRAM (int method, bool silent)
|
||||
bool
|
||||
SaveSRAM (int method, bool silent)
|
||||
{
|
||||
ShowAction ((char*) "Saving...");
|
||||
|
||||
if(method == METHOD_AUTO)
|
||||
method = autoSaveMethod();
|
||||
|
||||
bool retval = false;
|
||||
char filepath[1024];
|
||||
int datasize;
|
||||
int offset = 0;
|
||||
|
||||
if(method == METHOD_AUTO)
|
||||
method = autoSaveMethod();
|
||||
|
||||
if(!MakeFilePath(filepath, FILE_SRAM, method))
|
||||
return false;
|
||||
|
||||
ShowAction ((char*) "Saving...");
|
||||
|
||||
AllocSaveBuffer ();
|
||||
|
||||
datasize = preparesavedata (method);
|
||||
|
||||
if ( datasize )
|
||||
if (datasize)
|
||||
{
|
||||
if(method == METHOD_SD || method == METHOD_USB)
|
||||
{
|
||||
if(ChangeFATInterface(method, NOTSILENT))
|
||||
{
|
||||
sprintf (filepath, "%s/%s/%s.srm", ROOTFATDIR, GCSettings.SaveFolder, Memory.ROMFilename);
|
||||
offset = SaveBufferToFAT (filepath, datasize, silent);
|
||||
}
|
||||
}
|
||||
else if(method == METHOD_SMB)
|
||||
{
|
||||
sprintf (filepath, "%s/%s.srm", GCSettings.SaveFolder, Memory.ROMFilename);
|
||||
offset = SaveBufferToSMB (filepath, datasize, silent);
|
||||
}
|
||||
else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
|
||||
{
|
||||
sprintf (filepath, "%s.srm", Memory.ROMName);
|
||||
|
||||
if(method == METHOD_MC_SLOTA)
|
||||
offset = SaveBufferToMC (savebuffer, CARD_SLOTA, filepath, datasize, silent);
|
||||
else
|
||||
offset = SaveBufferToMC (savebuffer, CARD_SLOTB, filepath, datasize, silent);
|
||||
}
|
||||
offset = SaveFile(filepath, datasize, method, silent);
|
||||
|
||||
if (offset > 0)
|
||||
{
|
||||
|
@ -228,23 +228,13 @@ GetFirstZipFilename (int method)
|
||||
{
|
||||
char * firstFilename = NULL;
|
||||
char tempbuffer[ZIPCHUNK];
|
||||
char filepath[1024];
|
||||
|
||||
if(!MakeFilePath(filepath, FILE_ROM, method))
|
||||
return NULL;
|
||||
|
||||
// read start of ZIP
|
||||
switch (method)
|
||||
{
|
||||
case METHOD_SD: // SD Card
|
||||
case METHOD_USB: // USB
|
||||
LoadFATFile (tempbuffer, ZIPCHUNK);
|
||||
break;
|
||||
|
||||
case METHOD_DVD: // DVD
|
||||
LoadDVDFile ((unsigned char *)tempbuffer, ZIPCHUNK);
|
||||
break;
|
||||
|
||||
case METHOD_SMB: // From SMB
|
||||
LoadSMBFile (tempbuffer, ZIPCHUNK);
|
||||
break;
|
||||
}
|
||||
LoadFile (tempbuffer, filepath, ZIPCHUNK, method, NOTSILENT);
|
||||
|
||||
tempbuffer[28] = 0; // truncate - filename length is 2 bytes long (bytes 26-27)
|
||||
int namelength = tempbuffer[26]; // filename length starts 26 bytes in
|
||||
|
Loading…
Reference in New Issue
Block a user