mirror of
https://github.com/dborth/fceugx.git
synced 2025-01-05 21:38:17 +01:00
tidy up file code
This commit is contained in:
parent
5c465f680e
commit
a89d6d4d07
@ -27,6 +27,7 @@
|
||||
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
|
||||
@ -258,8 +259,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;
|
||||
}
|
||||
@ -284,8 +286,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 = 0;
|
||||
break;
|
||||
}
|
||||
@ -553,6 +556,11 @@ bool SwitchDVDFolder(char origdir[])
|
||||
if(dir[strlen(dir)-1] == '/')
|
||||
dir[strlen(dir)-1] = 0;
|
||||
|
||||
// start at root of DVD
|
||||
dvddir = dvdrootdir;
|
||||
dvddirlength = dvdrootlength;
|
||||
ParseDVDdirectory();
|
||||
|
||||
return SwitchDVDFolderR(dirptr, 0);
|
||||
}
|
||||
|
||||
@ -566,7 +574,7 @@ bool SwitchDVDFolder(char origdir[])
|
||||
***************************************************************************/
|
||||
|
||||
int
|
||||
LoadDVDFile (unsigned char *buffer, int length)
|
||||
LoadDVDFileOffset (unsigned char *buffer, int length)
|
||||
{
|
||||
int offset;
|
||||
int blocks;
|
||||
@ -574,16 +582,13 @@ 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;
|
||||
discoffset = dvddir;
|
||||
ShowAction ((char*) "Loading...");
|
||||
|
||||
if(length > 0) // do a partial read (eg: to check file header)
|
||||
if(length > 0 && length <= 2048) // do a partial read (eg: to check file header)
|
||||
{
|
||||
dvd_read (buffer, length, discoffset);
|
||||
}
|
||||
@ -617,6 +622,21 @@ LoadDVDFile (unsigned char *buffer, int length)
|
||||
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
|
||||
*
|
||||
|
@ -14,7 +14,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);
|
||||
|
@ -17,6 +17,7 @@ void DefaultSettings ();
|
||||
|
||||
#define VERSIONNUM "2.0.6"
|
||||
#define VERSIONSTR "FCE Ultra GX 2.0.6"
|
||||
#define PREF_FILE_NAME "FCEUGX.xml"
|
||||
|
||||
#define NOTSILENT 0
|
||||
#define SILENT 1
|
||||
@ -31,6 +32,15 @@ enum {
|
||||
METHOD_MC_SLOTB
|
||||
};
|
||||
|
||||
enum {
|
||||
FILE_ROM,
|
||||
FILE_RAM,
|
||||
FILE_STATE,
|
||||
FILE_FDSBIOS,
|
||||
FILE_CHEAT,
|
||||
FILE_PREF
|
||||
};
|
||||
|
||||
struct SGCSettings{
|
||||
int AutoLoad;
|
||||
int AutoSave;
|
||||
|
@ -119,17 +119,9 @@ int GCMemROM(int method, int size)
|
||||
|
||||
char filepath[1024];
|
||||
|
||||
switch (method)
|
||||
if(MakeFilePath(filepath, FILE_FDSBIOS, method))
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
sprintf(filepath, "%s/%s/disksys.rom", ROOTFATDIR, GCSettings.LoadFolder);
|
||||
biosSize = LoadBufferFromFAT(tmpbuffer, filepath, NOTSILENT);
|
||||
break;
|
||||
case METHOD_SMB:
|
||||
sprintf(filepath, "%s/disksys.rom", GCSettings.LoadFolder);
|
||||
biosSize = LoadBufferFromSMB(tmpbuffer, filepath, 0, NOTSILENT);
|
||||
break;
|
||||
biosSize = LoadFileBuf (tmpbuffer, filepath, 0, method, SILENT);
|
||||
}
|
||||
|
||||
if(biosSize == 8192)
|
||||
|
@ -71,6 +71,11 @@ int NGCFCEU_GameSave(CartInfo *LocalHWInfo, int operation)
|
||||
|
||||
bool SaveRAM (int method, bool silent)
|
||||
{
|
||||
bool retval = false;
|
||||
char filepath[1024];
|
||||
int datasize = 0;
|
||||
int offset = 0;
|
||||
|
||||
if(nesGameType == 4)
|
||||
{
|
||||
if(!silent)
|
||||
@ -78,15 +83,13 @@ bool SaveRAM (int method, bool silent)
|
||||
return false;
|
||||
}
|
||||
|
||||
ShowAction ((char*) "Saving...");
|
||||
|
||||
if(method == METHOD_AUTO)
|
||||
method = autoSaveMethod();
|
||||
|
||||
bool retval = false;
|
||||
char filepath[1024];
|
||||
int datasize = 0;
|
||||
int offset = 0;
|
||||
if (!MakeFilePath(filepath, FILE_RAM, method))
|
||||
return false;
|
||||
|
||||
ShowAction ((char*) "Saving...");
|
||||
|
||||
// save game save to savebuffer
|
||||
if(nesGameType == 1)
|
||||
@ -94,30 +97,9 @@ bool SaveRAM (int method, bool silent)
|
||||
else if(nesGameType == 2)
|
||||
datasize = NGCFCEU_GameSave(&UNIFCart, 0);
|
||||
|
||||
if ( datasize )
|
||||
if (datasize)
|
||||
{
|
||||
if(method == METHOD_SD || method == METHOD_USB)
|
||||
{
|
||||
if(ChangeFATInterface(method, NOTSILENT))
|
||||
{
|
||||
sprintf (filepath, "%s/%s/%s.sav", ROOTFATDIR, GCSettings.SaveFolder, romFilename);
|
||||
offset = SaveBufferToFAT (filepath, datasize, silent);
|
||||
}
|
||||
}
|
||||
else if(method == METHOD_SMB)
|
||||
{
|
||||
sprintf (filepath, "%s/%s.sav", GCSettings.SaveFolder, romFilename);
|
||||
offset = SaveBufferToSMB (filepath, datasize, silent);
|
||||
}
|
||||
else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
|
||||
{
|
||||
sprintf (filepath, "%08x.sav", iNESGameCRC32);
|
||||
|
||||
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)
|
||||
{
|
||||
@ -136,6 +118,9 @@ bool SaveRAM (int method, bool silent)
|
||||
|
||||
bool LoadRAM (int method, bool silent)
|
||||
{
|
||||
char filepath[1024];
|
||||
int offset = 0;
|
||||
|
||||
if(nesGameType == 4)
|
||||
{
|
||||
if(!silent)
|
||||
@ -143,36 +128,15 @@ bool LoadRAM (int method, bool silent)
|
||||
return false;
|
||||
}
|
||||
|
||||
ShowAction ((char*) "Loading...");
|
||||
|
||||
if(method == METHOD_AUTO)
|
||||
method = autoSaveMethod(); // we use 'Save' because we need R/W
|
||||
|
||||
char filepath[1024];
|
||||
int offset = 0;
|
||||
if (!MakeFilePath(filepath, FILE_RAM, method))
|
||||
return false;
|
||||
|
||||
if(method == METHOD_SD || method == METHOD_USB)
|
||||
{
|
||||
if(ChangeFATInterface(method, NOTSILENT))
|
||||
{
|
||||
sprintf (filepath, "%s/%s/%s.sav", ROOTFATDIR, GCSettings.SaveFolder, romFilename);
|
||||
offset = LoadSaveBufferFromFAT (filepath, silent);
|
||||
}
|
||||
}
|
||||
else if(method == METHOD_SMB)
|
||||
{
|
||||
sprintf (filepath, "%s/%s.sav", GCSettings.SaveFolder, romFilename);
|
||||
offset = LoadSaveBufferFromSMB (filepath, silent);
|
||||
}
|
||||
else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
|
||||
{
|
||||
sprintf (filepath, "%08x.sav", iNESGameCRC32);
|
||||
ShowAction ((char*) "Loading...");
|
||||
|
||||
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)
|
||||
{
|
||||
@ -182,12 +146,12 @@ bool LoadRAM (int method, bool silent)
|
||||
NGCFCEU_GameSave(&UNIFCart, 1);
|
||||
|
||||
ResetNES();
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
// if we reached here, nothing was done!
|
||||
if(!silent)
|
||||
WaitPrompt ((char*) "Save file not found");
|
||||
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
|
@ -281,42 +281,24 @@ int GCFCEUSS_Save()
|
||||
|
||||
bool SaveState (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_STATE, method))
|
||||
return false;
|
||||
|
||||
ShowAction ((char*) "Saving...");
|
||||
|
||||
datasize = GCFCEUSS_Save();
|
||||
|
||||
if ( datasize )
|
||||
if (datasize)
|
||||
{
|
||||
if(method == METHOD_SD || method == METHOD_USB)
|
||||
{
|
||||
if(ChangeFATInterface(method, NOTSILENT))
|
||||
{
|
||||
sprintf (filepath, "%s/%s/%s.fcs", ROOTFATDIR, GCSettings.SaveFolder, romFilename);
|
||||
offset = SaveBufferToFAT (filepath, datasize, silent);
|
||||
}
|
||||
}
|
||||
else if(method == METHOD_SMB)
|
||||
{
|
||||
sprintf (filepath, "%s/%s.fcs", GCSettings.SaveFolder, romFilename);
|
||||
offset = SaveBufferToSMB (filepath, datasize, silent);
|
||||
}
|
||||
else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
|
||||
{
|
||||
sprintf (filepath, "%08x.fcs", iNESGameCRC32);
|
||||
|
||||
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)
|
||||
{
|
||||
@ -330,41 +312,18 @@ bool SaveState (int method, bool silent)
|
||||
|
||||
bool LoadState (int method, bool silent)
|
||||
{
|
||||
ShowAction ((char*) "Loading...");
|
||||
char filepath[1024];
|
||||
int offset = 0;
|
||||
|
||||
if(method == METHOD_AUTO)
|
||||
method = autoSaveMethod(); // we use 'Save' because we need R/W
|
||||
|
||||
char filepath[1024];
|
||||
int offset = 0;
|
||||
if (!MakeFilePath(filepath, FILE_STATE, method))
|
||||
return false;
|
||||
|
||||
if(method == METHOD_SD || method == METHOD_USB)
|
||||
{
|
||||
ChangeFATInterface(method, NOTSILENT);
|
||||
sprintf (filepath, "%s/%s/%s.fcs", ROOTFATDIR, GCSettings.SaveFolder, romFilename);
|
||||
offset = LoadSaveBufferFromFAT (filepath, silent);
|
||||
ShowAction ((char*) "Loading...");
|
||||
|
||||
if(offset == 0) // file not found
|
||||
{
|
||||
// look for CRC save
|
||||
sprintf (filepath, "%08x.fcs", iNESGameCRC32);
|
||||
offset = LoadSaveBufferFromFAT (filepath, silent);
|
||||
}
|
||||
}
|
||||
else if(method == METHOD_SMB)
|
||||
{
|
||||
sprintf (filepath, "%s/%s.fcs", GCSettings.SaveFolder, romFilename);
|
||||
offset = LoadSaveBufferFromSMB (filepath, silent);
|
||||
}
|
||||
else if(method == METHOD_MC_SLOTA || method == METHOD_MC_SLOTB)
|
||||
{
|
||||
sprintf (filepath, "%08x.fcs", iNESGameCRC32);
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -26,27 +26,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
|
||||
* Unmounts the FAT device specified
|
||||
@ -71,6 +50,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
|
||||
@ -79,9 +83,6 @@ bool ChangeFATInterface(int method, bool silent)
|
||||
{
|
||||
bool mounted = false;
|
||||
|
||||
// unmount all FAT devices
|
||||
UnmountAllFAT();
|
||||
|
||||
if(method == METHOD_SD)
|
||||
{
|
||||
#ifdef HW_RVL
|
||||
@ -99,6 +100,7 @@ bool ChangeFATInterface(int method, bool silent)
|
||||
{
|
||||
#ifdef HW_RVL
|
||||
mounted = MountFAT(PI_USBSTORAGE);
|
||||
|
||||
if(!mounted && !silent)
|
||||
WaitPrompt ((char *)"USB drive not found!");
|
||||
#endif
|
||||
@ -109,7 +111,7 @@ bool ChangeFATInterface(int method, bool silent)
|
||||
|
||||
/***************************************************************************
|
||||
* Browse FAT subdirectories
|
||||
***************************************************************************/
|
||||
**************************************************************************/
|
||||
int
|
||||
ParseFATdirectory(int method)
|
||||
{
|
||||
@ -155,7 +157,6 @@ ParseFATdirectory(int method)
|
||||
strncpy(filelist[nbfiles].displayname, filename, MAXDISPLAY+1); // crop name for display
|
||||
filelist[nbfiles].length = filestat.st_size;
|
||||
filelist[nbfiles].flags = (filestat.st_mode & _IFDIR) == 0 ? 0 : 1; // flag this as a dir
|
||||
filelist[nbfiles].offset = 0;
|
||||
nbfiles++;
|
||||
}
|
||||
}
|
||||
@ -169,60 +170,6 @@ ParseFATdirectory(int method)
|
||||
return nbfiles;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* LoadFATFile
|
||||
* length > 0 - partial file read (starting from start)
|
||||
* length = 0 - full read
|
||||
***************************************************************************/
|
||||
int
|
||||
LoadFATFile (char * rbuffer, int length)
|
||||
{
|
||||
char zipbuffer[2048];
|
||||
char filepath[MAXPATHLEN];
|
||||
u32 size;
|
||||
|
||||
if (!MakeROMPath(filepath, METHOD_SD))
|
||||
{
|
||||
WaitPrompt((char*) "Maximum filepath length reached!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
fatfile = fopen (filepath, "rb");
|
||||
if (fatfile > 0)
|
||||
{
|
||||
if(length > 0) // 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
|
||||
fread (rbuffer + 2048, 1, size - 2048, fatfile);
|
||||
}
|
||||
}
|
||||
fclose (fatfile);
|
||||
return size;
|
||||
}
|
||||
else
|
||||
{
|
||||
WaitPrompt((char*) "Error opening file");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* LoadFATSzFile
|
||||
* Loads the selected file # from the specified 7z into rbuffer
|
||||
@ -247,51 +194,63 @@ LoadFATSzFile(char * filepath, unsigned char * rbuffer)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Load savebuffer from FAT file
|
||||
* LoadFATFile
|
||||
***************************************************************************/
|
||||
|
||||
// no buffer is specified - so use savebuffer
|
||||
int
|
||||
LoadSaveBufferFromFAT (char *filepath, bool silent)
|
||||
LoadFATFile (char * rbuffer, char *filepath, int length, bool silent)
|
||||
{
|
||||
return LoadBufferFromFAT((char *)savebuffer, filepath, silent);
|
||||
}
|
||||
char zipbuffer[2048];
|
||||
int size = 0;
|
||||
int readsize = 0;
|
||||
|
||||
int
|
||||
LoadBufferFromFAT (char * sbuffer, char *filepath, bool silent)
|
||||
{
|
||||
int size = 0;
|
||||
fatfile = fopen (filepath, "rb");
|
||||
|
||||
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
|
||||
{
|
||||
readsize = fread (zipbuffer, 1, 2048, fatfile);
|
||||
|
||||
if (fatfile <= 0)
|
||||
{
|
||||
if ( !silent )
|
||||
{
|
||||
char msg[100];
|
||||
sprintf(msg, "Couldn't open %s", filepath);
|
||||
WaitPrompt (msg);
|
||||
}
|
||||
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 (sbuffer, 1, size, fatfile);
|
||||
fclose (fatfile);
|
||||
|
||||
return size;
|
||||
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); // go to end of file
|
||||
size = ftell(fatfile); // get filesize
|
||||
fseek(fatfile, 0, SEEK_SET); // go to start of file
|
||||
fread (rbuffer, 1, size, fatfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose (fatfile);
|
||||
return size;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!silent)
|
||||
WaitPrompt((char*) "Error opening file!");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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)
|
||||
if (datasize)
|
||||
{
|
||||
fatfile = fopen (filepath, "wb");
|
||||
|
||||
|
@ -24,11 +24,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 LoadSaveBufferFromFAT (char *filepath, bool silent);
|
||||
int LoadBufferFromFAT (char * buffer, 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;
|
||||
|
@ -111,15 +111,14 @@ int autoSaveMethod()
|
||||
int UpdateDirName(int method)
|
||||
{
|
||||
int size=0;
|
||||
char *test;
|
||||
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 */
|
||||
@ -157,32 +156,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));
|
||||
// Check path length
|
||||
if ((strlen(currentdir)+1+strlen(filelist[selection].filename)) >= MAXPATHLEN)
|
||||
{
|
||||
WaitPrompt((char*)"Maximum filepath length reached!");
|
||||
filepath[0] = 0;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
strcpy(filepath, temppath);
|
||||
return true;
|
||||
{
|
||||
sprintf(temppath, "%s/%s",currentdir,filelist[selection].filename);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
filepath[0] = 0;
|
||||
return false;
|
||||
switch(type)
|
||||
{
|
||||
case FILE_RAM:
|
||||
sprintf(folder, GCSettings.SaveFolder);
|
||||
sprintf(file, "%s.sav", romFilename);
|
||||
break;
|
||||
case FILE_STATE:
|
||||
sprintf(folder, GCSettings.SaveFolder);
|
||||
sprintf(file, "%s.fcs", romFilename);
|
||||
break;
|
||||
case FILE_FDSBIOS:
|
||||
sprintf(folder, GCSettings.LoadFolder);
|
||||
sprintf(file, "disksys.rom");
|
||||
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 LoadFileBuf(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 LoadFileBuf((char *)savebuffer, filepath, 0, method, silent);
|
||||
}
|
||||
|
||||
int SaveFileBuf(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 SaveFileBuf((char *)savebuffer, filepath, datasize, method, silent);
|
||||
}
|
||||
|
||||
/***************************************************************************
|
||||
@ -424,11 +524,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)
|
||||
{
|
||||
@ -451,30 +549,32 @@ int FileSelector (int method)
|
||||
|
||||
int size = 0;
|
||||
|
||||
switch (method)
|
||||
if(!inSz)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
if(inSz)
|
||||
size = LoadFATSzFile(szpath, nesrom);
|
||||
else
|
||||
size = LoadFATFile((char *)nesrom, 0);
|
||||
break;
|
||||
char filepath[1024];
|
||||
|
||||
case METHOD_DVD:
|
||||
if(inSz)
|
||||
size = SzExtractFile(filelist[selection].offset, nesrom);
|
||||
else
|
||||
size = LoadDVDFile(nesrom, 0);
|
||||
break;
|
||||
if(!MakeFilePath(filepath, FILE_ROM, method))
|
||||
return 0;
|
||||
|
||||
case METHOD_SMB:
|
||||
if(inSz)
|
||||
size = LoadSMBSzFile(szpath, nesrom);
|
||||
else
|
||||
size = LoadSMBFile((char *)nesrom, 0);
|
||||
break;
|
||||
size = LoadFileBuf((char *)nesrom, filepath, filelist[selection].length, method, NOTSILENT);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (method)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
size = LoadFATSzFile(szpath, nesrom);
|
||||
break;
|
||||
case METHOD_DVD:
|
||||
size = SzExtractFile(filelist[selection].offset, nesrom);
|
||||
break;
|
||||
case METHOD_SMB:
|
||||
size = LoadSMBSzFile(szpath, nesrom);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
inSz = false;
|
||||
|
||||
if (size > 0)
|
||||
@ -627,6 +727,7 @@ OpenDVD (int method)
|
||||
}
|
||||
}
|
||||
|
||||
currentdir[0] = 0;
|
||||
maxfiles = ParseDVDdirectory(); // load root folder
|
||||
|
||||
// switch to rom folder
|
||||
|
@ -39,7 +39,11 @@ extern char romFilename[];
|
||||
extern int nesGameType;
|
||||
|
||||
void ClearSaveBuffer ();
|
||||
bool MakeROMPath(char filepath[], int method);
|
||||
bool MakeFilePath(char filepath[], int type, int method);
|
||||
int LoadFileBuf(char * buffer, char filepath[], int length, int method, bool silent);
|
||||
int LoadFile(char filepath[], int method, bool silent);
|
||||
int SaveFileBuf(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();
|
||||
|
@ -96,7 +96,6 @@ UnZipBuffer (unsigned char *outbuffer, int method)
|
||||
int readoffset = 0;
|
||||
int have = 0;
|
||||
char readbuffer[ZIPCHUNK];
|
||||
char msg[128];
|
||||
u64 discoffset = 0;
|
||||
|
||||
// Read Zip Header
|
||||
@ -123,10 +122,6 @@ UnZipBuffer (unsigned char *outbuffer, int method)
|
||||
|
||||
pkzip.uncompressedSize = FLIP32 (pkzip.uncompressedSize);
|
||||
|
||||
sprintf (msg, "Unzipping %d bytes ... Wait",
|
||||
pkzip.uncompressedSize);
|
||||
ShowAction (msg);
|
||||
|
||||
/*** Prepare the zip stream ***/
|
||||
memset (&zs, 0, sizeof (z_stream));
|
||||
zs.zalloc = Z_NULL;
|
||||
@ -213,34 +208,24 @@ UnZipBuffer (unsigned char *outbuffer, int method)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* GetFirstZipFilename
|
||||
*
|
||||
* Returns the filename of the first file in the zipped archive
|
||||
* The idea here is to do the least amount of work required
|
||||
***************************************************************************/
|
||||
* GetFirstZipFilename
|
||||
*
|
||||
* Returns the filename of the first file in the zipped archive
|
||||
* The idea here is to do the least amount of work required
|
||||
***************************************************************************/
|
||||
|
||||
char *
|
||||
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;
|
||||
}
|
||||
LoadFileBuf (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
|
||||
@ -252,26 +237,26 @@ GetFirstZipFilename (int method)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 7z functions
|
||||
***************************************************************************/
|
||||
* 7z functions
|
||||
***************************************************************************/
|
||||
|
||||
typedef struct _SzFileInStream
|
||||
{
|
||||
ISzInStream InStream;
|
||||
u64 offset; // offset of the file
|
||||
unsigned int len; // length of the file
|
||||
u64 pos; // current position of the file pointer
|
||||
ISzInStream InStream;
|
||||
u64 offset; // offset of the file
|
||||
unsigned int len; // length of the file
|
||||
u64 pos; // current position of the file pointer
|
||||
} SzFileInStream;
|
||||
|
||||
// 7zip error list
|
||||
// 7zip error list
|
||||
char szerrormsg[][30] = {
|
||||
"7z: Data error",
|
||||
"7z: Out of memory",
|
||||
"7z: CRC Error",
|
||||
"7z: Not implemented",
|
||||
"7z: Fail",
|
||||
"7z: Archive error",
|
||||
"7z: Dictionary too large",
|
||||
"7z: Data error",
|
||||
"7z: Out of memory",
|
||||
"7z: CRC Error",
|
||||
"7z: Not implemented",
|
||||
"7z: Fail",
|
||||
"7z: Archive error",
|
||||
"7z: Dictionary too large",
|
||||
};
|
||||
|
||||
SZ_RESULT SzRes;
|
||||
@ -290,10 +275,10 @@ char sz_buffer[2048];
|
||||
int szMethod = 0;
|
||||
|
||||
/****************************************************************************
|
||||
* Is7ZipFile
|
||||
*
|
||||
* Returns 1 when 7z signature is found
|
||||
****************************************************************************/
|
||||
* Is7ZipFile
|
||||
*
|
||||
* Returns 1 when 7z signature is found
|
||||
****************************************************************************/
|
||||
int
|
||||
Is7ZipFile (char *buffer)
|
||||
{
|
||||
@ -318,24 +303,25 @@ void SzDisplayError(SZ_RESULT res)
|
||||
}
|
||||
|
||||
// function used by the 7zip SDK to read data from SD/USB/DVD/SMB
|
||||
|
||||
SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize)
|
||||
{
|
||||
// the void* object is a SzFileInStream
|
||||
SzFileInStream *s = (SzFileInStream *)object;
|
||||
// the void* object is a SzFileInStream
|
||||
SzFileInStream *s = (SzFileInStream *) object;
|
||||
|
||||
// calculate offset
|
||||
u64 offset = (u64)(s->offset + s->pos);
|
||||
// calculate offset
|
||||
u64 offset = (u64) (s->offset + s->pos);
|
||||
|
||||
if(maxRequiredSize > 2048)
|
||||
if (maxRequiredSize > 2048)
|
||||
maxRequiredSize = 2048;
|
||||
|
||||
// read data
|
||||
switch(szMethod)
|
||||
// read data
|
||||
switch (szMethod)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
fseek(fatfile, offset, SEEK_SET);
|
||||
fread (sz_buffer, 1, maxRequiredSize, fatfile);
|
||||
fread(sz_buffer, 1, maxRequiredSize, fatfile);
|
||||
break;
|
||||
case METHOD_DVD:
|
||||
dvd_safe_read(sz_buffer, maxRequiredSize, offset);
|
||||
@ -345,38 +331,38 @@ SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, siz
|
||||
break;
|
||||
}
|
||||
|
||||
*buffer = sz_buffer;
|
||||
*processedSize = maxRequiredSize;
|
||||
s->pos += *processedSize;
|
||||
*buffer = sz_buffer;
|
||||
*processedSize = maxRequiredSize;
|
||||
s->pos += *processedSize;
|
||||
|
||||
return SZ_OK;
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
// function used by the 7zip SDK to change the filepointer
|
||||
SZ_RESULT SzFileSeekImp(void *object, CFileSize pos)
|
||||
{
|
||||
// the void* object is a SzFileInStream
|
||||
SzFileInStream *s = (SzFileInStream *)object;
|
||||
// the void* object is a SzFileInStream
|
||||
SzFileInStream *s = (SzFileInStream *) object;
|
||||
|
||||
// check if the 7z SDK wants to move the pointer to somewhere after the EOF
|
||||
if(pos >= s->len)
|
||||
{
|
||||
WaitPrompt("7z Error: The 7z SDK wants to start reading somewhere behind the EOF...");
|
||||
return SZE_FAIL;
|
||||
}
|
||||
// check if the 7z SDK wants to move the pointer to somewhere after the EOF
|
||||
if (pos >= s->len)
|
||||
{
|
||||
WaitPrompt((char *) "7z: Error - attempt to read after EOF!");
|
||||
return SZE_FAIL;
|
||||
}
|
||||
|
||||
// save new position and return
|
||||
s->pos = pos;
|
||||
return SZ_OK;
|
||||
// save new position and return
|
||||
s->pos = pos;
|
||||
return SZ_OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* SzParse
|
||||
*
|
||||
* Opens a 7z file, and parses it
|
||||
* Right now doesn't parse 7z, since we'll always use the first file
|
||||
* But it could parse the entire 7z for full browsing capability
|
||||
***************************************************************************/
|
||||
* SzParse
|
||||
*
|
||||
* Opens a 7z file, and parses it
|
||||
* Right now doesn't parse 7z, since we'll always use the first file
|
||||
* But it could parse the entire 7z for full browsing capability
|
||||
***************************************************************************/
|
||||
|
||||
int SzParse(char * filepath, int method)
|
||||
{
|
||||
@ -495,10 +481,10 @@ int SzParse(char * filepath, int method)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* SzClose
|
||||
*
|
||||
* Closes a 7z file
|
||||
***************************************************************************/
|
||||
* SzClose
|
||||
*
|
||||
* Closes a 7z file
|
||||
***************************************************************************/
|
||||
|
||||
void SzClose()
|
||||
{
|
||||
@ -507,45 +493,44 @@ void SzClose()
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* SzExtractFile
|
||||
*
|
||||
* Extracts the given file # into the buffer specified
|
||||
* Must parse the 7z BEFORE running this function
|
||||
***************************************************************************/
|
||||
* SzExtractFile
|
||||
*
|
||||
* Extracts the given file # into the buffer specified
|
||||
* Must parse the 7z BEFORE running this function
|
||||
***************************************************************************/
|
||||
|
||||
int SzExtractFile(int i, unsigned char *buffer)
|
||||
{
|
||||
// prepare some variables
|
||||
SzBlockIndex = 0xFFFFFFFF;
|
||||
SzOffset = 0;
|
||||
// prepare some variables
|
||||
SzBlockIndex = 0xFFFFFFFF;
|
||||
SzOffset = 0;
|
||||
|
||||
// Unzip the file
|
||||
ShowAction("Unzipping file. Please wait...");
|
||||
// Unzip the file
|
||||
|
||||
SzRes = SzExtract2(
|
||||
&SzArchiveStream.InStream,
|
||||
&SzDb,
|
||||
i, // index of file
|
||||
&SzBlockIndex, // index of solid block
|
||||
&buffer,
|
||||
&SzBufferSize,
|
||||
&SzOffset, // offset of stream for required file in *outBuffer
|
||||
&SzOutSizeProcessed, // size of file in *outBuffer
|
||||
&SzAllocImp,
|
||||
&SzAllocTempImp);
|
||||
SzRes = SzExtract2(
|
||||
&SzArchiveStream.InStream,
|
||||
&SzDb,
|
||||
i, // index of file
|
||||
&SzBlockIndex, // index of solid block
|
||||
&buffer,
|
||||
&SzBufferSize,
|
||||
&SzOffset, // offset of stream for required file in *outBuffer
|
||||
&SzOutSizeProcessed, // size of file in *outBuffer
|
||||
&SzAllocImp,
|
||||
&SzAllocTempImp);
|
||||
|
||||
// close 7Zip archive and free memory
|
||||
// close 7Zip archive and free memory
|
||||
SzClose();
|
||||
|
||||
// check for errors
|
||||
if(SzRes != SZ_OK)
|
||||
{
|
||||
// display error message
|
||||
SzDisplayError(SzRes);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SzOutSizeProcessed;
|
||||
}
|
||||
// check for errors
|
||||
if(SzRes != SZ_OK)
|
||||
{
|
||||
// display error message
|
||||
SzDisplayError(SzRes);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SzOutSizeProcessed;
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ card_stat CardStatus;
|
||||
*
|
||||
* Wrapper to search through the files on the card.
|
||||
* Returns TRUE if found.
|
||||
****************************************************************************/
|
||||
***************************************************************************/
|
||||
int
|
||||
CardFileExists (char *filename, int slot)
|
||||
{
|
||||
@ -58,7 +58,7 @@ CardFileExists (char *filename, int slot)
|
||||
* TestCard
|
||||
*
|
||||
* Checks to see if a card is in the card slot specified
|
||||
****************************************************************************/
|
||||
***************************************************************************/
|
||||
bool TestCard(int slot, bool silent)
|
||||
{
|
||||
// Memory Cards do not work in Wii mode - disable
|
||||
@ -103,7 +103,7 @@ bool TestCard(int slot, bool silent)
|
||||
*
|
||||
* Mounts the memory card in the given slot.
|
||||
* Returns the result of the last attempted CARD_Mount command.
|
||||
****************************************************************************/
|
||||
***************************************************************************/
|
||||
int MountCard(int cslot, bool silent)
|
||||
{
|
||||
int ret = -1;
|
||||
@ -123,9 +123,9 @@ 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;
|
||||
@ -201,12 +201,12 @@ VerifyMCFile (unsigned char *buf, int slot, char *filename, int datasize)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* LoadMCFile
|
||||
* Load savebuffer from Memory Card file
|
||||
****************************************************************************/
|
||||
***************************************************************************/
|
||||
int
|
||||
LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool silent)
|
||||
LoadMCFile (char *buf, int slot, char *filename, bool silent)
|
||||
{
|
||||
int CardError;
|
||||
unsigned int blocks;
|
||||
@ -268,10 +268,11 @@ LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool silent)
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* SaveMCFile
|
||||
* Write savebuffer to Memory Card file
|
||||
****************************************************************************/
|
||||
***************************************************************************/
|
||||
int
|
||||
SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool silent)
|
||||
SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent)
|
||||
{
|
||||
int CardError;
|
||||
unsigned int blocks;
|
||||
@ -405,7 +406,7 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool
|
||||
}
|
||||
else
|
||||
if ( !silent )
|
||||
WaitPrompt((char*) "No to data to save!");
|
||||
WaitPrompt((char*) "This game does not appear to use RAM");
|
||||
}
|
||||
else
|
||||
if (slot == CARD_SLOTA)
|
||||
@ -416,5 +417,3 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -12,10 +12,9 @@
|
||||
#ifndef _MEMCARDOP_H_
|
||||
#define _MEMCARDOP_H_
|
||||
|
||||
int VerifyMCFile (unsigned char *buf, int slot, char *filename, int datasize);
|
||||
|
||||
int LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool silent);
|
||||
int SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool 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);
|
||||
|
||||
|
@ -33,8 +33,6 @@ extern unsigned int wmpadmap[];
|
||||
extern unsigned int ccpadmap[];
|
||||
extern unsigned int ncpadmap[];
|
||||
|
||||
#define PREFS_FILE_NAME "FCEUGX.xml"
|
||||
|
||||
char prefscomment[2][32];
|
||||
|
||||
/****************************************************************************
|
||||
@ -322,41 +320,24 @@ 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;
|
||||
|
||||
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);
|
||||
}
|
||||
datasize = preparePrefsData (method);
|
||||
|
||||
offset = SaveFile(filepath, datasize, method, silent);
|
||||
|
||||
if (offset > 0)
|
||||
{
|
||||
@ -378,31 +359,15 @@ LoadPrefsFromMethod (int method)
|
||||
char filepath[1024];
|
||||
int offset = 0;
|
||||
|
||||
if(method == METHOD_SD || method == METHOD_USB)
|
||||
{
|
||||
if(ChangeFATInterface(method, NOTSILENT))
|
||||
{
|
||||
sprintf (filepath, "%s/%s/%s", ROOTFATDIR, GCSettings.SaveFolder, PREFS_FILE_NAME);
|
||||
offset = LoadSaveBufferFromFAT (filepath, SILENT);
|
||||
}
|
||||
}
|
||||
else if(method == METHOD_SMB)
|
||||
{
|
||||
sprintf (filepath, "%s/%s", GCSettings.SaveFolder, PREFS_FILE_NAME);
|
||||
offset = LoadSaveBufferFromSMB (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);
|
||||
}
|
||||
if(!MakeFilePath(filepath, FILE_PREF, method))
|
||||
return false;
|
||||
|
||||
offset = LoadFile(filepath, method, SILENT);
|
||||
|
||||
if (offset > 0)
|
||||
{
|
||||
retval = decodePrefsData (method);
|
||||
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
@ -82,8 +82,6 @@ ConnectShare (bool silent)
|
||||
return false;
|
||||
#endif
|
||||
|
||||
ShowAction ((char*) "Connecting...");
|
||||
|
||||
// check that all parameter have been set
|
||||
if(strlen(GCSettings.smbuser) == 0 ||
|
||||
strlen(GCSettings.smbpwd) == 0 ||
|
||||
@ -204,7 +202,6 @@ ParseSMBdirectory ()
|
||||
filelist[filecount].displayname[MAXDISPLAY] = 0;
|
||||
|
||||
strcpy (filelist[filecount].filename, smbdir.name);
|
||||
filelist[filecount].offset = 0;
|
||||
filecount++;
|
||||
}
|
||||
} while (SMB_FindNext (&smbdir, smbconn) == SMB_SUCCESS);
|
||||
@ -227,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
|
||||
@ -273,10 +251,12 @@ LoadSMBSzFile(char * filepath, unsigned char * rbuffer)
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Write savebuffer to SMB file
|
||||
* SaveSMBFile
|
||||
* Write buffer to SMB file
|
||||
****************************************************************************/
|
||||
|
||||
int
|
||||
SaveBufferToSMB (char *filepath, int datasize, bool silent)
|
||||
SaveSMBFile (char * sbuffer, char *filepath, int datasize, bool silent)
|
||||
{
|
||||
if(!ConnectShare (NOTSILENT))
|
||||
return 0;
|
||||
@ -295,10 +275,10 @@ SaveBufferToSMB (char *filepath, int datasize, bool silent)
|
||||
{
|
||||
if (dsize > 1024)
|
||||
wrote =
|
||||
SMB_WriteFile ((char *) savebuffer + boffset, 1024, boffset, smbfile);
|
||||
SMB_WriteFile ((char *) sbuffer + boffset, 1024, boffset, smbfile);
|
||||
else
|
||||
wrote =
|
||||
SMB_WriteFile ((char *) savebuffer + boffset, dsize, boffset, smbfile);
|
||||
SMB_WriteFile ((char *) sbuffer + boffset, dsize, boffset, smbfile);
|
||||
|
||||
boffset += wrote;
|
||||
dsize -= wrote;
|
||||
@ -312,31 +292,25 @@ SaveBufferToSMB (char *filepath, int datasize, bool silent)
|
||||
WaitPrompt (msg);
|
||||
}
|
||||
|
||||
ClearSaveBuffer ();
|
||||
return boffset;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* LoadSMBFile
|
||||
* Load up a buffer from SMB file
|
||||
***************************************************************************/
|
||||
|
||||
// no buffer is specified - so use savebuffer
|
||||
int
|
||||
LoadSaveBufferFromSMB (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;
|
||||
|
||||
smbfile = OpenSMBFile(filepath);
|
||||
int ret;
|
||||
int boffset = 0;
|
||||
|
||||
smbfile = OpenSMBFile(filepath);
|
||||
|
||||
if (!smbfile)
|
||||
{
|
||||
if(!silent)
|
||||
@ -348,13 +322,13 @@ LoadBufferFromSMB (char * sbuffer, char *filepath, int length, bool silent)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if(length > 0) // do a partial read (eg: to check file header)
|
||||
if(length > 0 && length <= 2048) // do a partial read (eg: to check file header)
|
||||
{
|
||||
boffset = SMB_ReadFile (sbuffer, length, 0, smbfile);
|
||||
}
|
||||
else // load whole file
|
||||
{
|
||||
ret = SMB_ReadFile (sbuffer, 1024, boffset, smbfile);
|
||||
ret = SMB_ReadFile (sbuffer, 2048, boffset, smbfile);
|
||||
|
||||
if (IsZipFile (sbuffer))
|
||||
{
|
||||
@ -363,8 +337,10 @@ LoadBufferFromSMB (char * sbuffer, char *filepath, int length, bool silent)
|
||||
else
|
||||
{
|
||||
// Just load the file up
|
||||
while ((ret = SMB_ReadFile (sbuffer + boffset, 1024, boffset, smbfile)) > 0)
|
||||
while ((ret = SMB_ReadFile (sbuffer + boffset, 2048, boffset, smbfile)) > 0)
|
||||
{
|
||||
boffset += ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
SMB_CloseFile (smbfile);
|
||||
|
@ -20,11 +20,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 LoadSaveBufferFromSMB (char *filepath, bool silent);
|
||||
int LoadBufferFromSMB (char * sbuffer, char *filepath, int length, bool silent);
|
||||
int SaveBufferToSMB (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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user