tidy up file code

This commit is contained in:
dborth 2008-11-12 08:40:09 +00:00
parent 5c465f680e
commit a89d6d4d07
16 changed files with 439 additions and 509 deletions

View File

@ -27,6 +27,7 @@
u64 dvddir = 0; // offset of currently selected file or folder u64 dvddir = 0; // offset of currently selected file or folder
int dvddirlength = 0; // length of currently selected file or folder int dvddirlength = 0; // length of currently selected file or folder
u64 dvdrootdir = 0; // offset of DVD root u64 dvdrootdir = 0; // offset of DVD root
int dvdrootlength = 0; // length of DVD root
bool isWii = false; bool isWii = false;
#ifdef HW_DOL #ifdef HW_DOL
@ -258,8 +259,9 @@ getpvd ()
memcpy(&rootdir32, &dvdbuffer[PVDROOT + EXTENT], 4); memcpy(&rootdir32, &dvdbuffer[PVDROOT + EXTENT], 4);
dvddir = (u64)rootdir32; dvddir = (u64)rootdir32;
dvddir <<= 11; dvddir <<= 11;
dvdrootdir = dvddir;
memcpy (&dvddirlength, &dvdbuffer[PVDROOT + FILE_LENGTH], 4); memcpy (&dvddirlength, &dvdbuffer[PVDROOT + FILE_LENGTH], 4);
dvdrootdir = dvddir;
dvdrootlength = dvddirlength;
IsJoliet = 1; IsJoliet = 1;
break; break;
} }
@ -284,8 +286,9 @@ getpvd ()
memcpy (&rootdir32, &dvdbuffer[PVDROOT + EXTENT], 4); memcpy (&rootdir32, &dvdbuffer[PVDROOT + EXTENT], 4);
dvddir = (u64)rootdir32; dvddir = (u64)rootdir32;
dvddir <<= 11; dvddir <<= 11;
dvdrootdir = dvddir;
memcpy (&dvddirlength, &dvdbuffer[PVDROOT + FILE_LENGTH], 4); memcpy (&dvddirlength, &dvdbuffer[PVDROOT + FILE_LENGTH], 4);
dvdrootdir = dvddir;
dvdrootlength = dvddirlength;
IsJoliet = 0; IsJoliet = 0;
break; break;
} }
@ -553,6 +556,11 @@ bool SwitchDVDFolder(char origdir[])
if(dir[strlen(dir)-1] == '/') if(dir[strlen(dir)-1] == '/')
dir[strlen(dir)-1] = 0; dir[strlen(dir)-1] = 0;
// start at root of DVD
dvddir = dvdrootdir;
dvddirlength = dvdrootlength;
ParseDVDdirectory();
return SwitchDVDFolderR(dirptr, 0); return SwitchDVDFolderR(dirptr, 0);
} }
@ -566,7 +574,7 @@ bool SwitchDVDFolder(char origdir[])
***************************************************************************/ ***************************************************************************/
int int
LoadDVDFile (unsigned char *buffer, int length) LoadDVDFileOffset (unsigned char *buffer, int length)
{ {
int offset; int offset;
int blocks; int blocks;
@ -574,16 +582,13 @@ LoadDVDFile (unsigned char *buffer, int length)
u64 discoffset; u64 discoffset;
char readbuffer[2048]; char readbuffer[2048];
dvddir = filelist[selection].offset;
dvddirlength = filelist[selection].length;
// How many 2k blocks to read // How many 2k blocks to read
blocks = dvddirlength / 2048; blocks = dvddirlength / 2048;
offset = 0; offset = 0;
discoffset = dvddir; discoffset = dvddir;
ShowAction ((char*) "Loading..."); 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); dvd_read (buffer, length, discoffset);
} }
@ -617,6 +622,21 @@ LoadDVDFile (unsigned char *buffer, int length)
return dvddirlength; 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 * uselessinquiry
* *

View File

@ -14,7 +14,8 @@
int getpvd (); int getpvd ();
int ParseDVDdirectory (); 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(); bool TestDVD();
int dvd_read (void *dst, unsigned int len, u64 offset); int dvd_read (void *dst, unsigned int len, u64 offset);
int dvd_safe_read (void *dst, unsigned int len, u64 offset); int dvd_safe_read (void *dst, unsigned int len, u64 offset);

View File

@ -17,6 +17,7 @@ void DefaultSettings ();
#define VERSIONNUM "2.0.6" #define VERSIONNUM "2.0.6"
#define VERSIONSTR "FCE Ultra GX 2.0.6" #define VERSIONSTR "FCE Ultra GX 2.0.6"
#define PREF_FILE_NAME "FCEUGX.xml"
#define NOTSILENT 0 #define NOTSILENT 0
#define SILENT 1 #define SILENT 1
@ -31,6 +32,15 @@ enum {
METHOD_MC_SLOTB METHOD_MC_SLOTB
}; };
enum {
FILE_ROM,
FILE_RAM,
FILE_STATE,
FILE_FDSBIOS,
FILE_CHEAT,
FILE_PREF
};
struct SGCSettings{ struct SGCSettings{
int AutoLoad; int AutoLoad;
int AutoSave; int AutoSave;

View File

@ -119,17 +119,9 @@ int GCMemROM(int method, int size)
char filepath[1024]; char filepath[1024];
switch (method) if(MakeFilePath(filepath, FILE_FDSBIOS, method))
{ {
case METHOD_SD: biosSize = LoadFileBuf (tmpbuffer, filepath, 0, method, SILENT);
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;
} }
if(biosSize == 8192) if(biosSize == 8192)

View File

@ -71,6 +71,11 @@ int NGCFCEU_GameSave(CartInfo *LocalHWInfo, int operation)
bool SaveRAM (int method, bool silent) bool SaveRAM (int method, bool silent)
{ {
bool retval = false;
char filepath[1024];
int datasize = 0;
int offset = 0;
if(nesGameType == 4) if(nesGameType == 4)
{ {
if(!silent) if(!silent)
@ -78,15 +83,13 @@ bool SaveRAM (int method, bool silent)
return false; return false;
} }
ShowAction ((char*) "Saving...");
if(method == METHOD_AUTO) if(method == METHOD_AUTO)
method = autoSaveMethod(); method = autoSaveMethod();
bool retval = false; if (!MakeFilePath(filepath, FILE_RAM, method))
char filepath[1024]; return false;
int datasize = 0;
int offset = 0; ShowAction ((char*) "Saving...");
// save game save to savebuffer // save game save to savebuffer
if(nesGameType == 1) if(nesGameType == 1)
@ -94,30 +97,9 @@ bool SaveRAM (int method, bool silent)
else if(nesGameType == 2) else if(nesGameType == 2)
datasize = NGCFCEU_GameSave(&UNIFCart, 0); datasize = NGCFCEU_GameSave(&UNIFCart, 0);
if ( datasize ) if (datasize)
{ {
if(method == METHOD_SD || method == METHOD_USB) offset = SaveFile(filepath, datasize, method, silent);
{
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);
}
if (offset > 0) if (offset > 0)
{ {
@ -136,6 +118,9 @@ bool SaveRAM (int method, bool silent)
bool LoadRAM (int method, bool silent) bool LoadRAM (int method, bool silent)
{ {
char filepath[1024];
int offset = 0;
if(nesGameType == 4) if(nesGameType == 4)
{ {
if(!silent) if(!silent)
@ -143,36 +128,15 @@ bool LoadRAM (int method, bool silent)
return false; return false;
} }
ShowAction ((char*) "Loading...");
if(method == METHOD_AUTO) if(method == METHOD_AUTO)
method = autoSaveMethod(); // we use 'Save' because we need R/W method = autoSaveMethod(); // we use 'Save' because we need R/W
char filepath[1024]; if (!MakeFilePath(filepath, FILE_RAM, method))
int offset = 0; return false;
if(method == METHOD_SD || method == METHOD_USB) ShowAction ((char*) "Loading...");
{
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);
if(method == METHOD_MC_SLOTA) offset = LoadFile(filepath, method, silent);
offset = LoadBufferFromMC (savebuffer, CARD_SLOTA, filepath, silent);
else
offset = LoadBufferFromMC (savebuffer, CARD_SLOTB, filepath, silent);
}
if (offset > 0) if (offset > 0)
{ {
@ -182,12 +146,12 @@ bool LoadRAM (int method, bool silent)
NGCFCEU_GameSave(&UNIFCart, 1); NGCFCEU_GameSave(&UNIFCart, 1);
ResetNES(); ResetNES();
return 1; return true;
} }
// if we reached here, nothing was done! // if we reached here, nothing was done!
if(!silent) if(!silent)
WaitPrompt ((char*) "Save file not found"); WaitPrompt ((char*) "Save file not found");
return 0; return false;
} }

View File

@ -281,42 +281,24 @@ int GCFCEUSS_Save()
bool SaveState (int method, bool silent) bool SaveState (int method, bool silent)
{ {
ShowAction ((char*) "Saving...");
if(method == METHOD_AUTO)
method = autoSaveMethod();
bool retval = false; bool retval = false;
char filepath[1024]; char filepath[1024];
int datasize; int datasize;
int offset = 0; int offset = 0;
if(method == METHOD_AUTO)
method = autoSaveMethod();
if (!MakeFilePath(filepath, FILE_STATE, method))
return false;
ShowAction ((char*) "Saving...");
datasize = GCFCEUSS_Save(); datasize = GCFCEUSS_Save();
if ( datasize ) if (datasize)
{ {
if(method == METHOD_SD || method == METHOD_USB) offset = SaveFile(filepath, datasize, method, silent);
{
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);
}
if (offset > 0) if (offset > 0)
{ {
@ -330,41 +312,18 @@ bool SaveState (int method, bool silent)
bool LoadState (int method, bool silent) bool LoadState (int method, bool silent)
{ {
ShowAction ((char*) "Loading..."); char filepath[1024];
int offset = 0;
if(method == METHOD_AUTO) if(method == METHOD_AUTO)
method = autoSaveMethod(); // we use 'Save' because we need R/W method = autoSaveMethod(); // we use 'Save' because we need R/W
char filepath[1024]; if (!MakeFilePath(filepath, FILE_STATE, method))
int offset = 0; return false;
if(method == METHOD_SD || method == METHOD_USB) ShowAction ((char*) "Loading...");
{
ChangeFATInterface(method, NOTSILENT);
sprintf (filepath, "%s/%s/%s.fcs", ROOTFATDIR, GCSettings.SaveFolder, romFilename);
offset = LoadSaveBufferFromFAT (filepath, silent);
if(offset == 0) // file not found offset = LoadFile(filepath, method, silent);
{
// 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);
}
if (offset > 0) if (offset > 0)
{ {

View File

@ -26,27 +26,6 @@
// FAT file pointer - the only one we should ever use! // FAT file pointer - the only one we should ever use!
FILE * fatfile; 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 * UnmountFAT
* Unmounts the FAT device specified * Unmounts the FAT device specified
@ -71,6 +50,31 @@ void UnmountAllFAT()
UnmountFAT(PI_SDGECKO_B); 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 * ChangeFATInterface
* Unmounts all devices and attempts to mount/configure the device specified * Unmounts all devices and attempts to mount/configure the device specified
@ -79,9 +83,6 @@ bool ChangeFATInterface(int method, bool silent)
{ {
bool mounted = false; bool mounted = false;
// unmount all FAT devices
UnmountAllFAT();
if(method == METHOD_SD) if(method == METHOD_SD)
{ {
#ifdef HW_RVL #ifdef HW_RVL
@ -99,6 +100,7 @@ bool ChangeFATInterface(int method, bool silent)
{ {
#ifdef HW_RVL #ifdef HW_RVL
mounted = MountFAT(PI_USBSTORAGE); mounted = MountFAT(PI_USBSTORAGE);
if(!mounted && !silent) if(!mounted && !silent)
WaitPrompt ((char *)"USB drive not found!"); WaitPrompt ((char *)"USB drive not found!");
#endif #endif
@ -109,7 +111,7 @@ bool ChangeFATInterface(int method, bool silent)
/*************************************************************************** /***************************************************************************
* Browse FAT subdirectories * Browse FAT subdirectories
***************************************************************************/ **************************************************************************/
int int
ParseFATdirectory(int method) ParseFATdirectory(int method)
{ {
@ -155,7 +157,6 @@ ParseFATdirectory(int method)
strncpy(filelist[nbfiles].displayname, filename, MAXDISPLAY+1); // crop name for display strncpy(filelist[nbfiles].displayname, filename, MAXDISPLAY+1); // crop name for display
filelist[nbfiles].length = filestat.st_size; filelist[nbfiles].length = filestat.st_size;
filelist[nbfiles].flags = (filestat.st_mode & _IFDIR) == 0 ? 0 : 1; // flag this as a dir filelist[nbfiles].flags = (filestat.st_mode & _IFDIR) == 0 ? 0 : 1; // flag this as a dir
filelist[nbfiles].offset = 0;
nbfiles++; nbfiles++;
} }
} }
@ -169,60 +170,6 @@ ParseFATdirectory(int method)
return nbfiles; 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 * LoadFATSzFile
* Loads the selected file # from the specified 7z into rbuffer * 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 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 fatfile = fopen (filepath, "rb");
LoadBufferFromFAT (char * sbuffer, char *filepath, bool silent)
{
int size = 0;
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(readsize > 0)
{ {
if ( !silent ) if (IsZipFile (zipbuffer))
{ {
char msg[100]; size = UnZipBuffer ((unsigned char *)rbuffer, METHOD_SD); // unzip from FAT
sprintf(msg, "Couldn't open %s", filepath); }
WaitPrompt (msg); else
} {
return 0; // Just load the file up
} fseek(fatfile, 0, SEEK_END); // go to end of file
size = ftell(fatfile); // get filesize
// Just load the file up fseek(fatfile, 0, SEEK_SET); // go to start of file
fseek(fatfile, 0, SEEK_END); // go to end of file fread (rbuffer, 1, size, fatfile);
size = ftell(fatfile); // get filesize }
fseek(fatfile, 0, SEEK_SET); // go to start of file }
fread (sbuffer, 1, size, fatfile); }
fclose (fatfile); fclose (fatfile);
return size;
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 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"); fatfile = fopen (filepath, "wb");

View File

@ -24,11 +24,9 @@
bool ChangeFATInterface(int method, bool silent); bool ChangeFATInterface(int method, bool silent);
int ParseFATdirectory(int method); int ParseFATdirectory(int method);
int LoadFATFile (char * fbuffer, int length);
int LoadFATSzFile(char * filepath, unsigned char * rbuffer); int LoadFATSzFile(char * filepath, unsigned char * rbuffer);
int SaveBufferToFAT (char *filepath, int datasize, bool silent); int SaveFATFile (char * sbuffer, char *filepath, int length, bool silent);
int LoadSaveBufferFromFAT (char *filepath, bool silent); int LoadFATFile (char * sbuffer, char *filepath, int length, bool silent);
int LoadBufferFromFAT (char * buffer, char *filepath, bool silent);
extern char currFATdir[MAXPATHLEN]; extern char currFATdir[MAXPATHLEN];
extern FILE * fatfile; extern FILE * fatfile;

View File

@ -111,15 +111,14 @@ int autoSaveMethod()
int UpdateDirName(int method) int UpdateDirName(int method)
{ {
int size=0; int size=0;
char *test; char * test;
char temp[1024]; char temp[1024];
// update DVD directory (does not utilize 'currentdir') // update DVD directory
if(method == METHOD_DVD) if(method == METHOD_DVD)
{ {
dvddir = filelist[selection].offset; dvddir = filelist[selection].offset;
dvddirlength = filelist[selection].length; dvddirlength = filelist[selection].length;
return 1;
} }
/* current directory doesn't change */ /* current directory doesn't change */
@ -157,32 +156,133 @@ int UpdateDirName(int method)
} }
else else
{ {
WaitPrompt((char*)"Directory name is too long !"); WaitPrompt((char*)"Directory name is too long!");
return -1; 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]; char temppath[MAXPATHLEN];
// Check filename length if(type == FILE_ROM)
if ((strlen(currentdir)+1+strlen(filelist[selection].filename)) < MAXPATHLEN)
{ {
sprintf(temppath, "%s/%s",currentdir,filelist[selection].filename); // Check path length
if ((strlen(currentdir)+1+strlen(filelist[selection].filename)) >= MAXPATHLEN)
if(method == METHOD_SMB) {
strcpy(filepath, SMBPath(temppath)); WaitPrompt((char*)"Maximum filepath length reached!");
filepath[0] = 0;
return false;
}
else else
strcpy(filepath, temppath); {
return true; sprintf(temppath, "%s/%s",currentdir,filelist[selection].filename);
}
} }
else else
{ {
filepath[0] = 0; switch(type)
return false; {
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()) if(IsSz())
{ {
// we'll store the 7z filepath for extraction later // we'll store the 7z filepath for extraction later
if(!MakeROMPath(szpath, method)) if(!MakeFilePath(szpath, FILE_ROM, method))
{
WaitPrompt((char*) "Maximum filepath length reached!");
return 0; return 0;
}
int szfiles = SzParse(szpath, method); int szfiles = SzParse(szpath, method);
if(szfiles) if(szfiles)
{ {
@ -451,30 +549,32 @@ int FileSelector (int method)
int size = 0; int size = 0;
switch (method) if(!inSz)
{ {
case METHOD_SD: char filepath[1024];
case METHOD_USB:
if(inSz)
size = LoadFATSzFile(szpath, nesrom);
else
size = LoadFATFile((char *)nesrom, 0);
break;
case METHOD_DVD: if(!MakeFilePath(filepath, FILE_ROM, method))
if(inSz) return 0;
size = SzExtractFile(filelist[selection].offset, nesrom);
else
size = LoadDVDFile(nesrom, 0);
break;
case METHOD_SMB: size = LoadFileBuf((char *)nesrom, filepath, filelist[selection].length, method, NOTSILENT);
if(inSz)
size = LoadSMBSzFile(szpath, nesrom);
else
size = LoadSMBFile((char *)nesrom, 0);
break;
} }
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; inSz = false;
if (size > 0) if (size > 0)
@ -627,6 +727,7 @@ OpenDVD (int method)
} }
} }
currentdir[0] = 0;
maxfiles = ParseDVDdirectory(); // load root folder maxfiles = ParseDVDdirectory(); // load root folder
// switch to rom folder // switch to rom folder

View File

@ -39,7 +39,11 @@ extern char romFilename[];
extern int nesGameType; extern int nesGameType;
void ClearSaveBuffer (); 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 OpenROM (int method);
int autoLoadMethod(); int autoLoadMethod();
int autoSaveMethod(); int autoSaveMethod();

View File

@ -96,7 +96,6 @@ UnZipBuffer (unsigned char *outbuffer, int method)
int readoffset = 0; int readoffset = 0;
int have = 0; int have = 0;
char readbuffer[ZIPCHUNK]; char readbuffer[ZIPCHUNK];
char msg[128];
u64 discoffset = 0; u64 discoffset = 0;
// Read Zip Header // Read Zip Header
@ -123,10 +122,6 @@ UnZipBuffer (unsigned char *outbuffer, int method)
pkzip.uncompressedSize = FLIP32 (pkzip.uncompressedSize); pkzip.uncompressedSize = FLIP32 (pkzip.uncompressedSize);
sprintf (msg, "Unzipping %d bytes ... Wait",
pkzip.uncompressedSize);
ShowAction (msg);
/*** Prepare the zip stream ***/ /*** Prepare the zip stream ***/
memset (&zs, 0, sizeof (z_stream)); memset (&zs, 0, sizeof (z_stream));
zs.zalloc = Z_NULL; zs.zalloc = Z_NULL;
@ -213,34 +208,24 @@ UnZipBuffer (unsigned char *outbuffer, int method)
} }
/**************************************************************************** /****************************************************************************
* GetFirstZipFilename * GetFirstZipFilename
* *
* Returns the filename of the first file in the zipped archive * Returns the filename of the first file in the zipped archive
* The idea here is to do the least amount of work required * The idea here is to do the least amount of work required
***************************************************************************/ ***************************************************************************/
char * char *
GetFirstZipFilename (int method) GetFirstZipFilename (int method)
{ {
char * firstFilename = NULL; char * firstFilename = NULL;
char tempbuffer[ZIPCHUNK]; char tempbuffer[ZIPCHUNK];
char filepath[1024];
if(!MakeFilePath(filepath, FILE_ROM, method))
return NULL;
// read start of ZIP // read start of ZIP
switch (method) LoadFileBuf (tempbuffer, filepath, ZIPCHUNK, method, NOTSILENT);
{
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;
}
tempbuffer[28] = 0; // truncate - filename length is 2 bytes long (bytes 26-27) tempbuffer[28] = 0; // truncate - filename length is 2 bytes long (bytes 26-27)
int namelength = tempbuffer[26]; // filename length starts 26 bytes in int namelength = tempbuffer[26]; // filename length starts 26 bytes in
@ -252,26 +237,26 @@ GetFirstZipFilename (int method)
} }
/**************************************************************************** /****************************************************************************
* 7z functions * 7z functions
***************************************************************************/ ***************************************************************************/
typedef struct _SzFileInStream typedef struct _SzFileInStream
{ {
ISzInStream InStream; ISzInStream InStream;
u64 offset; // offset of the file u64 offset; // offset of the file
unsigned int len; // length of the file unsigned int len; // length of the file
u64 pos; // current position of the file pointer u64 pos; // current position of the file pointer
} SzFileInStream; } SzFileInStream;
// 7zip error list // 7zip error list
char szerrormsg[][30] = { char szerrormsg[][30] = {
"7z: Data error", "7z: Data error",
"7z: Out of memory", "7z: Out of memory",
"7z: CRC Error", "7z: CRC Error",
"7z: Not implemented", "7z: Not implemented",
"7z: Fail", "7z: Fail",
"7z: Archive error", "7z: Archive error",
"7z: Dictionary too large", "7z: Dictionary too large",
}; };
SZ_RESULT SzRes; SZ_RESULT SzRes;
@ -290,10 +275,10 @@ char sz_buffer[2048];
int szMethod = 0; int szMethod = 0;
/**************************************************************************** /****************************************************************************
* Is7ZipFile * Is7ZipFile
* *
* Returns 1 when 7z signature is found * Returns 1 when 7z signature is found
****************************************************************************/ ****************************************************************************/
int int
Is7ZipFile (char *buffer) 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 // 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) SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize)
{ {
// the void* object is a SzFileInStream // the void* object is a SzFileInStream
SzFileInStream *s = (SzFileInStream *)object; SzFileInStream *s = (SzFileInStream *) object;
// calculate offset // calculate offset
u64 offset = (u64)(s->offset + s->pos); u64 offset = (u64) (s->offset + s->pos);
if(maxRequiredSize > 2048) if (maxRequiredSize > 2048)
maxRequiredSize = 2048; maxRequiredSize = 2048;
// read data // read data
switch(szMethod) switch (szMethod)
{ {
case METHOD_SD: case METHOD_SD:
case METHOD_USB: case METHOD_USB:
fseek(fatfile, offset, SEEK_SET); fseek(fatfile, offset, SEEK_SET);
fread (sz_buffer, 1, maxRequiredSize, fatfile); fread(sz_buffer, 1, maxRequiredSize, fatfile);
break; break;
case METHOD_DVD: case METHOD_DVD:
dvd_safe_read(sz_buffer, maxRequiredSize, offset); dvd_safe_read(sz_buffer, maxRequiredSize, offset);
@ -345,38 +331,38 @@ SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, siz
break; break;
} }
*buffer = sz_buffer; *buffer = sz_buffer;
*processedSize = maxRequiredSize; *processedSize = maxRequiredSize;
s->pos += *processedSize; s->pos += *processedSize;
return SZ_OK; return SZ_OK;
} }
// function used by the 7zip SDK to change the filepointer // function used by the 7zip SDK to change the filepointer
SZ_RESULT SzFileSeekImp(void *object, CFileSize pos) SZ_RESULT SzFileSeekImp(void *object, CFileSize pos)
{ {
// the void* object is a SzFileInStream // the void* object is a SzFileInStream
SzFileInStream *s = (SzFileInStream *)object; SzFileInStream *s = (SzFileInStream *) object;
// check if the 7z SDK wants to move the pointer to somewhere after the EOF // check if the 7z SDK wants to move the pointer to somewhere after the EOF
if(pos >= s->len) if (pos >= s->len)
{ {
WaitPrompt("7z Error: The 7z SDK wants to start reading somewhere behind the EOF..."); WaitPrompt((char *) "7z: Error - attempt to read after EOF!");
return SZE_FAIL; return SZE_FAIL;
} }
// save new position and return // save new position and return
s->pos = pos; s->pos = pos;
return SZ_OK; return SZ_OK;
} }
/**************************************************************************** /****************************************************************************
* SzParse * SzParse
* *
* Opens a 7z file, and parses it * Opens a 7z file, and parses it
* Right now doesn't parse 7z, since we'll always use the first file * 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 * But it could parse the entire 7z for full browsing capability
***************************************************************************/ ***************************************************************************/
int SzParse(char * filepath, int method) int SzParse(char * filepath, int method)
{ {
@ -495,10 +481,10 @@ int SzParse(char * filepath, int method)
} }
/**************************************************************************** /****************************************************************************
* SzClose * SzClose
* *
* Closes a 7z file * Closes a 7z file
***************************************************************************/ ***************************************************************************/
void SzClose() void SzClose()
{ {
@ -507,45 +493,44 @@ void SzClose()
} }
/**************************************************************************** /****************************************************************************
* SzExtractFile * SzExtractFile
* *
* Extracts the given file # into the buffer specified * Extracts the given file # into the buffer specified
* Must parse the 7z BEFORE running this function * Must parse the 7z BEFORE running this function
***************************************************************************/ ***************************************************************************/
int SzExtractFile(int i, unsigned char *buffer) int SzExtractFile(int i, unsigned char *buffer)
{ {
// prepare some variables // prepare some variables
SzBlockIndex = 0xFFFFFFFF; SzBlockIndex = 0xFFFFFFFF;
SzOffset = 0; SzOffset = 0;
// Unzip the file // Unzip the file
ShowAction("Unzipping file. Please wait...");
SzRes = SzExtract2( SzRes = SzExtract2(
&SzArchiveStream.InStream, &SzArchiveStream.InStream,
&SzDb, &SzDb,
i, // index of file i, // index of file
&SzBlockIndex, // index of solid block &SzBlockIndex, // index of solid block
&buffer, &buffer,
&SzBufferSize, &SzBufferSize,
&SzOffset, // offset of stream for required file in *outBuffer &SzOffset, // offset of stream for required file in *outBuffer
&SzOutSizeProcessed, // size of file in *outBuffer &SzOutSizeProcessed, // size of file in *outBuffer
&SzAllocImp, &SzAllocImp,
&SzAllocTempImp); &SzAllocTempImp);
// close 7Zip archive and free memory // close 7Zip archive and free memory
SzClose(); SzClose();
// check for errors // check for errors
if(SzRes != SZ_OK) if(SzRes != SZ_OK)
{ {
// display error message // display error message
SzDisplayError(SzRes); SzDisplayError(SzRes);
return 0; return 0;
} }
else else
{ {
return SzOutSizeProcessed; return SzOutSizeProcessed;
} }
} }

View File

@ -36,7 +36,7 @@ card_stat CardStatus;
* *
* Wrapper to search through the files on the card. * Wrapper to search through the files on the card.
* Returns TRUE if found. * Returns TRUE if found.
****************************************************************************/ ***************************************************************************/
int int
CardFileExists (char *filename, int slot) CardFileExists (char *filename, int slot)
{ {
@ -58,7 +58,7 @@ CardFileExists (char *filename, int slot)
* TestCard * TestCard
* *
* Checks to see if a card is in the card slot specified * Checks to see if a card is in the card slot specified
****************************************************************************/ ***************************************************************************/
bool TestCard(int slot, bool silent) bool TestCard(int slot, bool silent)
{ {
// Memory Cards do not work in Wii mode - disable // 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. * Mounts the memory card in the given slot.
* Returns the result of the last attempted CARD_Mount command. * Returns the result of the last attempted CARD_Mount command.
****************************************************************************/ ***************************************************************************/
int MountCard(int cslot, bool silent) int MountCard(int cslot, bool silent)
{ {
int ret = -1; int ret = -1;
@ -123,9 +123,9 @@ int MountCard(int cslot, bool silent)
/**************************************************************************** /****************************************************************************
* Verify Memory Card file against buffer * Verify Memory Card file against buffer
****************************************************************************/ ***************************************************************************/
int int
VerifyMCFile (unsigned char *buf, int slot, char *filename, int datasize) VerifyMCFile (char *buf, int slot, char *filename, int datasize)
{ {
int CardError; int CardError;
unsigned int blocks; unsigned int blocks;
@ -201,12 +201,12 @@ VerifyMCFile (unsigned char *buf, int slot, char *filename, int datasize)
return 0; return 0;
} }
/**************************************************************************** /****************************************************************************
* LoadMCFile
* Load savebuffer from Memory Card file * Load savebuffer from Memory Card file
****************************************************************************/ ***************************************************************************/
int int
LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool silent) LoadMCFile (char *buf, int slot, char *filename, bool silent)
{ {
int CardError; int CardError;
unsigned int blocks; unsigned int blocks;
@ -268,10 +268,11 @@ LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool silent)
/**************************************************************************** /****************************************************************************
* SaveMCFile
* Write savebuffer to Memory Card file * Write savebuffer to Memory Card file
****************************************************************************/ ***************************************************************************/
int 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; int CardError;
unsigned int blocks; unsigned int blocks;
@ -405,7 +406,7 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool
} }
else else
if ( !silent ) if ( !silent )
WaitPrompt((char*) "No to data to save!"); WaitPrompt((char*) "This game does not appear to use RAM");
} }
else else
if (slot == CARD_SLOTA) if (slot == CARD_SLOTA)
@ -416,5 +417,3 @@ SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool
return 0; return 0;
} }

View File

@ -12,10 +12,9 @@
#ifndef _MEMCARDOP_H_ #ifndef _MEMCARDOP_H_
#define _MEMCARDOP_H_ #define _MEMCARDOP_H_
int VerifyMCFile (unsigned char *buf, int slot, char *filename, int datasize); int VerifyMCFile (char *buf, int slot, char *filename, int datasize);
int LoadMCFile (char *buf, int slot, char *filename, bool silent);
int LoadBufferFromMC (unsigned char *buf, int slot, char *filename, bool silent); int SaveMCFile (char *buf, int slot, char *filename, int datasize, bool silent);
int SaveBufferToMC (unsigned char *buf, int slot, char *filename, int datasize, bool silent);
int MountCard(int cslot, bool silent); int MountCard(int cslot, bool silent);
bool TestCard(int slot, bool silent); bool TestCard(int slot, bool silent);

View File

@ -33,8 +33,6 @@ extern unsigned int wmpadmap[];
extern unsigned int ccpadmap[]; extern unsigned int ccpadmap[];
extern unsigned int ncpadmap[]; extern unsigned int ncpadmap[];
#define PREFS_FILE_NAME "FCEUGX.xml"
char prefscomment[2][32]; char prefscomment[2][32];
/**************************************************************************** /****************************************************************************
@ -322,41 +320,24 @@ decodePrefsData (int method)
bool bool
SavePrefs (int method, bool silent) 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! // 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) // so instead we'll save using whatever other method is available (eg: SD)
if(method == METHOD_AUTO || method == METHOD_SMB) if(method == METHOD_AUTO || method == METHOD_SMB)
method = autoSaveMethod(); method = autoSaveMethod();
char filepath[1024]; if(!MakeFilePath(filepath, FILE_PREF, method))
int datasize; return false;
int offset = 0;
datasize = preparePrefsData (method);
if (!silent) if (!silent)
ShowAction ((char*) "Saving preferences..."); ShowAction ((char*) "Saving preferences...");
if(method == METHOD_SD || method == METHOD_USB) datasize = preparePrefsData (method);
{
if(ChangeFATInterface(method, NOTSILENT)) offset = SaveFile(filepath, datasize, method, silent);
{
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);
}
if (offset > 0) if (offset > 0)
{ {
@ -378,31 +359,15 @@ LoadPrefsFromMethod (int method)
char filepath[1024]; char filepath[1024];
int offset = 0; int offset = 0;
if(method == METHOD_SD || method == METHOD_USB) if(!MakeFilePath(filepath, FILE_PREF, method))
{ return false;
if(ChangeFATInterface(method, NOTSILENT))
{ offset = LoadFile(filepath, method, SILENT);
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 (offset > 0) if (offset > 0)
{
retval = decodePrefsData (method); retval = decodePrefsData (method);
}
return retval; return retval;
} }

View File

@ -82,8 +82,6 @@ ConnectShare (bool silent)
return false; return false;
#endif #endif
ShowAction ((char*) "Connecting...");
// check that all parameter have been set // check that all parameter have been set
if(strlen(GCSettings.smbuser) == 0 || if(strlen(GCSettings.smbuser) == 0 ||
strlen(GCSettings.smbpwd) == 0 || strlen(GCSettings.smbpwd) == 0 ||
@ -204,7 +202,6 @@ ParseSMBdirectory ()
filelist[filecount].displayname[MAXDISPLAY] = 0; filelist[filecount].displayname[MAXDISPLAY] = 0;
strcpy (filelist[filecount].filename, smbdir.name); strcpy (filelist[filecount].filename, smbdir.name);
filelist[filecount].offset = 0;
filecount++; filecount++;
} }
} while (SMB_FindNext (&smbdir, smbconn) == SMB_SUCCESS); } 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); 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 * LoadSMBSzFile
* Loads the selected file # from the specified 7z into rbuffer * 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 int
SaveBufferToSMB (char *filepath, int datasize, bool silent) SaveSMBFile (char * sbuffer, char *filepath, int datasize, bool silent)
{ {
if(!ConnectShare (NOTSILENT)) if(!ConnectShare (NOTSILENT))
return 0; return 0;
@ -295,10 +275,10 @@ SaveBufferToSMB (char *filepath, int datasize, bool silent)
{ {
if (dsize > 1024) if (dsize > 1024)
wrote = wrote =
SMB_WriteFile ((char *) savebuffer + boffset, 1024, boffset, smbfile); SMB_WriteFile ((char *) sbuffer + boffset, 1024, boffset, smbfile);
else else
wrote = wrote =
SMB_WriteFile ((char *) savebuffer + boffset, dsize, boffset, smbfile); SMB_WriteFile ((char *) sbuffer + boffset, dsize, boffset, smbfile);
boffset += wrote; boffset += wrote;
dsize -= wrote; dsize -= wrote;
@ -312,31 +292,25 @@ SaveBufferToSMB (char *filepath, int datasize, bool silent)
WaitPrompt (msg); WaitPrompt (msg);
} }
ClearSaveBuffer ();
return boffset; return boffset;
} }
/**************************************************************************** /****************************************************************************
* LoadSMBFile
* Load up a buffer from SMB file * 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 int
LoadBufferFromSMB (char * sbuffer, char *filepath, int length, bool silent) LoadSMBFile (char * sbuffer, char *filepath, int length, bool silent)
{ {
if(!ConnectShare (NOTSILENT)) if(!ConnectShare (NOTSILENT))
return 0; return 0;
smbfile = OpenSMBFile(filepath);
int ret; int ret;
int boffset = 0; int boffset = 0;
smbfile = OpenSMBFile(filepath);
if (!smbfile) if (!smbfile)
{ {
if(!silent) if(!silent)
@ -348,13 +322,13 @@ LoadBufferFromSMB (char * sbuffer, char *filepath, int length, bool silent)
return 0; 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); boffset = SMB_ReadFile (sbuffer, length, 0, smbfile);
} }
else // load whole file else // load whole file
{ {
ret = SMB_ReadFile (sbuffer, 1024, boffset, smbfile); ret = SMB_ReadFile (sbuffer, 2048, boffset, smbfile);
if (IsZipFile (sbuffer)) if (IsZipFile (sbuffer))
{ {
@ -363,8 +337,10 @@ LoadBufferFromSMB (char * sbuffer, char *filepath, int length, bool silent)
else else
{ {
// Just load the file up // 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; boffset += ret;
}
} }
} }
SMB_CloseFile (smbfile); SMB_CloseFile (smbfile);

View File

@ -20,11 +20,9 @@ char * SMBPath(char * path);
int UpdateSMBdirname(); int UpdateSMBdirname();
int ParseSMBdirectory (); int ParseSMBdirectory ();
SMBFILE OpenSMBFile(char * filepath); SMBFILE OpenSMBFile(char * filepath);
int LoadSMBFile (char * fbuffer, int length);
int LoadSMBSzFile(char * filepath, unsigned char * rbuffer); int LoadSMBSzFile(char * filepath, unsigned char * rbuffer);
int LoadSaveBufferFromSMB (char *filepath, bool silent); int LoadSMBFile (char * sbuffer, char *filepath, int length, bool silent);
int LoadBufferFromSMB (char * sbuffer, char *filepath, int length, bool silent); int SaveSMBFile (char * sbuffer, char *filepath, int length, bool silent);
int SaveBufferToSMB (char *filepath, int datasize, bool silent);
extern SMBFILE smbfile; extern SMBFILE smbfile;