mirror of
https://github.com/dborth/snes9xgx.git
synced 2024-12-11 20:04:28 +01:00
file size/type check, remove pngu from source
This commit is contained in:
parent
e053a3d128
commit
95533ef5aa
@ -43,7 +43,7 @@ LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map -Wl,--cref
|
||||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -lpng -lmxml -lbba -ltinysmb -lfat -lz -logc -lm -lfreetype
|
||||
LIBS := -lpngu -lpng -lmxml -lbba -ltinysmb -lfat -lz -logc -lm -lfreetype
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
|
@ -43,7 +43,7 @@ LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map
|
||||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS := -ldi -lpng -lmxml -lfat -lwiiuse -lz -lbte -logc -lm -lfreetype -ltinysmb
|
||||
LIBS := -ldi -lpngu -lpng -lmxml -lfat -lwiiuse -lz -lbte -logc -lm -lfreetype -ltinysmb
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
|
@ -424,53 +424,59 @@ bool SwitchDVDFolder(char origdir[])
|
||||
|
||||
/****************************************************************************
|
||||
* LoadDVDFile
|
||||
* This function will load a file from DVD, in BIN, SMD or ZIP format.
|
||||
* This function will load a file from DVD
|
||||
* The values for offset and length are inherited from dvddir and
|
||||
* dvddirlength.
|
||||
*
|
||||
* The buffer parameter should re-use the initial ROM buffer.
|
||||
* The buffer parameter should re-use the initial ROM buffer
|
||||
***************************************************************************/
|
||||
|
||||
int
|
||||
LoadDVDFile ()
|
||||
LoadDVDFile (unsigned char *buffer, int length)
|
||||
{
|
||||
int offset;
|
||||
int blocks;
|
||||
int i;
|
||||
u64 discoffset;
|
||||
char readbuffer[2048];
|
||||
unsigned char *rbuffer = (unsigned char *) Memory.ROM;
|
||||
|
||||
// How many 2k blocks to read
|
||||
blocks = dvddirlength / 2048;
|
||||
offset = 0;
|
||||
discoffset = dvddir;
|
||||
ShowAction ((char*) "Loading...");
|
||||
dvd_read (readbuffer, 2048, discoffset);
|
||||
|
||||
if (!IsZipFile (readbuffer))
|
||||
if(length > 0)
|
||||
{
|
||||
for (i = 0; i < blocks; i++)
|
||||
{
|
||||
dvd_read (readbuffer, 2048, discoffset);
|
||||
memcpy (rbuffer + offset, readbuffer, 2048);
|
||||
offset += 2048;
|
||||
discoffset += 2048;
|
||||
}
|
||||
dvd_read (buffer, length, discoffset);
|
||||
}
|
||||
else // load whole file
|
||||
{
|
||||
dvd_read (readbuffer, 2048, discoffset);
|
||||
|
||||
/*** And final cleanup ***/
|
||||
if (dvddirlength % 2048)
|
||||
if (!IsZipFile (readbuffer))
|
||||
{
|
||||
i = dvddirlength % 2048;
|
||||
dvd_read (readbuffer, 2048, discoffset);
|
||||
memcpy (rbuffer + offset, readbuffer, i);
|
||||
for (i = 0; i < blocks; i++)
|
||||
{
|
||||
dvd_read (readbuffer, 2048, discoffset);
|
||||
memcpy (buffer + offset, readbuffer, 2048);
|
||||
offset += 2048;
|
||||
discoffset += 2048;
|
||||
}
|
||||
|
||||
/*** And final cleanup ***/
|
||||
if (dvddirlength % 2048)
|
||||
{
|
||||
i = dvddirlength % 2048;
|
||||
dvd_read (readbuffer, 2048, discoffset);
|
||||
memcpy (buffer + offset, readbuffer, i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return UnZipFile (buffer, discoffset); // unzip from dvd
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return UnZipFile (rbuffer, discoffset); // unzip from dvd
|
||||
}
|
||||
|
||||
return dvddirlength;
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
int getpvd ();
|
||||
int ParseDVDdirectory ();
|
||||
int LoadDVDFile ();
|
||||
int LoadDVDFile (unsigned char *buffer, int length);
|
||||
bool TestDVD();
|
||||
int dvd_read (void *dst, unsigned int len, u64 offset);
|
||||
bool SwitchDVDFolder(char dir[]);
|
||||
|
@ -168,12 +168,11 @@ ParseFATdirectory(int method)
|
||||
* LoadFATFile
|
||||
***************************************************************************/
|
||||
int
|
||||
LoadFATFile ()
|
||||
LoadFATFile (char * rbuffer, int length)
|
||||
{
|
||||
char zipbuffer[2048];
|
||||
char filepath[MAXPATHLEN];
|
||||
FILE *handle;
|
||||
unsigned char *rbuffer = (unsigned char *) Memory.ROM;
|
||||
u32 size;
|
||||
|
||||
/* Check filename length */
|
||||
@ -188,20 +187,28 @@ LoadFATFile ()
|
||||
handle = fopen (filepath, "rb");
|
||||
if (handle > 0)
|
||||
{
|
||||
fread (zipbuffer, 1, 2048, handle);
|
||||
|
||||
if (IsZipFile (zipbuffer))
|
||||
if(length > 0) // do a partial read (eg: to check file header)
|
||||
{
|
||||
size = UnZipFile (rbuffer, handle); // unzip from FAT
|
||||
fread (rbuffer, 1, length, handle);
|
||||
size = length;
|
||||
}
|
||||
else
|
||||
else // load whole file
|
||||
{
|
||||
// Just load the file up
|
||||
fseek(handle, 0, SEEK_END);
|
||||
size = ftell(handle); // get filesize
|
||||
fseek(handle, 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, handle);
|
||||
fread (zipbuffer, 1, 2048, handle);
|
||||
|
||||
if (IsZipFile (zipbuffer))
|
||||
{
|
||||
size = UnZipFile ((unsigned char *)rbuffer, handle); // unzip from FAT
|
||||
}
|
||||
else
|
||||
{
|
||||
// Just load the file up
|
||||
fseek(handle, 0, SEEK_END);
|
||||
size = ftell(handle); // get filesize
|
||||
fseek(handle, 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, handle);
|
||||
}
|
||||
}
|
||||
fclose (handle);
|
||||
return size;
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
bool ChangeFATInterface(int method, bool silent);
|
||||
int ParseFATdirectory(int method);
|
||||
int LoadFATFile ();
|
||||
int LoadFATFile (char * fbuffer, int length);
|
||||
int SaveBufferToFAT (char *filepath, int datasize, bool silent);
|
||||
int LoadBufferFromFAT (char *filepath, bool silent);
|
||||
|
||||
|
@ -38,6 +38,7 @@ extern "C" {
|
||||
#include "fileop.h"
|
||||
#include "memcardop.h"
|
||||
#include "input.h"
|
||||
#include "unzip.h"
|
||||
|
||||
int offset;
|
||||
int selection;
|
||||
@ -220,6 +221,55 @@ int FileSortCallback(const void *f1, const void *f2)
|
||||
return stricmp(((FILEENTRIES *)f1)->filename, ((FILEENTRIES *)f2)->filename);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* IsValidROM
|
||||
*
|
||||
* Checks if the specified file is a valid ROM
|
||||
* For now we will just check the file extension and file size
|
||||
* If the file is a zip, we will check the file extension / file size of the
|
||||
* first file inside
|
||||
***************************************************************************/
|
||||
|
||||
bool IsValidROM(int method)
|
||||
{
|
||||
// file size should be between 128K and 8MB
|
||||
if(filelist[selection].length < (1024*128) ||
|
||||
filelist[selection].length > (1024*1024*8))
|
||||
{
|
||||
WaitPrompt((char *)"Invalid file size!");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (strlen(filelist[selection].filename) > 4)
|
||||
{
|
||||
char * p = strrchr(filelist[selection].filename, '.');
|
||||
|
||||
if (p != NULL)
|
||||
{
|
||||
if(stricmp(p, ".zip") == 0)
|
||||
{
|
||||
// we need to check the file extension of the first file in the archive
|
||||
char * zippedFilename = GetFirstZipFilename (method);
|
||||
|
||||
if(strlen(zippedFilename) > 4)
|
||||
p = strrchr(zippedFilename, '.');
|
||||
else
|
||||
p = NULL;
|
||||
}
|
||||
|
||||
if(p != NULL)
|
||||
{
|
||||
if (stricmp(p, ".smc") == 0 || stricmp(p, ".fig") == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
WaitPrompt((char *)"Unknown file type!");
|
||||
return false;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* StripExt
|
||||
*
|
||||
@ -315,17 +365,21 @@ int FileSelector (int method)
|
||||
|
||||
if (!maxfiles)
|
||||
{
|
||||
WaitPrompt ((char*) "Error reading directory !");
|
||||
haverom = 1; // quit menu
|
||||
WaitPrompt ((char*) "Error reading directory!");
|
||||
return 0; // quit menu
|
||||
}
|
||||
}
|
||||
else if (status == -1) // directory name too long
|
||||
{
|
||||
haverom = 1; // quit menu
|
||||
return 0; // quit menu
|
||||
}
|
||||
}
|
||||
else // this is a file
|
||||
{
|
||||
// check that this is a valid ROM
|
||||
if(!IsValidROM(method))
|
||||
return 0;
|
||||
|
||||
// store the filename (w/o ext) - used for sram/freeze naming
|
||||
StripExt(Memory.ROMFilename, filelist[selection].filename);
|
||||
|
||||
@ -335,17 +389,17 @@ int FileSelector (int method)
|
||||
{
|
||||
case METHOD_SD:
|
||||
case METHOD_USB:
|
||||
ARAM_ROMSIZE = LoadFATFile ();
|
||||
ARAM_ROMSIZE = LoadFATFile ((char *)Memory.ROM, 0);
|
||||
break;
|
||||
|
||||
case METHOD_DVD:
|
||||
dvddir = filelist[selection].offset;
|
||||
dvddirlength = filelist[selection].length;
|
||||
ARAM_ROMSIZE = LoadDVDFile ();
|
||||
ARAM_ROMSIZE = LoadDVDFile (Memory.ROM, 0);
|
||||
break;
|
||||
|
||||
case METHOD_SMB:
|
||||
ARAM_ROMSIZE = LoadSMBFile ();
|
||||
ARAM_ROMSIZE = LoadSMBFile ((char *)Memory.ROM, 0);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -380,7 +434,9 @@ int FileSelector (int method)
|
||||
else if ( strcmp(filelist[1].filename,"..") == 0 )
|
||||
{
|
||||
selection = selectit = 1;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
} // End of B
|
||||
|
1132
source/ngc/pngu.c
1132
source/ngc/pngu.c
File diff suppressed because it is too large
Load Diff
@ -214,9 +214,11 @@ ParseSMBdirectory ()
|
||||
|
||||
/****************************************************************************
|
||||
* Load SMB file
|
||||
* rom - pointer to memory where ROM will be stored
|
||||
* length - # bytes to read (0 for all)
|
||||
****************************************************************************/
|
||||
int
|
||||
LoadSMBFile ()
|
||||
LoadSMBFile (char * rom, int length)
|
||||
{
|
||||
char filepath[MAXPATHLEN];
|
||||
|
||||
@ -228,8 +230,7 @@ LoadSMBFile ()
|
||||
WaitPrompt((char*) "Maximum filepath length reached!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return LoadBufferFromSMB((char *)Memory.ROM, SMBPath(filepath), NOTSILENT);
|
||||
return LoadBufferFromSMB(rom, SMBPath(filepath), length, NOTSILENT);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -291,11 +292,11 @@ SaveBufferToSMB (char * sbuffer, char *filepath, int datasize, bool silent)
|
||||
int
|
||||
LoadBufferFromSMB (char *filepath, bool silent)
|
||||
{
|
||||
return LoadBufferFromSMB((char *)savebuffer, filepath, silent);
|
||||
return LoadBufferFromSMB((char *)savebuffer, filepath, 0, silent);
|
||||
}
|
||||
|
||||
int
|
||||
LoadBufferFromSMB (char * sbuffer, char *filepath, bool silent)
|
||||
LoadBufferFromSMB (char * sbuffer, char *filepath, int length, bool silent)
|
||||
{
|
||||
if(!ConnectShare (NOTSILENT))
|
||||
return 0;
|
||||
@ -318,17 +319,24 @@ LoadBufferFromSMB (char * sbuffer, char *filepath, bool silent)
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = SMB_ReadFile (sbuffer, 1024, boffset, smbfile);
|
||||
|
||||
if (IsZipFile (sbuffer))
|
||||
if(length > 0) // do a partial read (eg: to check file header)
|
||||
{
|
||||
boffset = UnZipFile ((unsigned char *)sbuffer, smbfile); // unzip from SMB
|
||||
boffset = SMB_ReadFile (sbuffer, length, 0, smbfile);
|
||||
}
|
||||
else
|
||||
else // load whole file
|
||||
{
|
||||
// Just load the file up
|
||||
while ((ret = SMB_ReadFile (sbuffer + boffset, 1024, boffset, smbfile)) > 0)
|
||||
boffset += ret;
|
||||
ret = SMB_ReadFile (sbuffer, 1024, boffset, smbfile);
|
||||
|
||||
if (IsZipFile (sbuffer))
|
||||
{
|
||||
boffset = UnZipFile ((unsigned char *)sbuffer, smbfile); // unzip from SMB
|
||||
}
|
||||
else
|
||||
{
|
||||
// Just load the file up
|
||||
while ((ret = SMB_ReadFile (sbuffer + boffset, 1024, boffset, smbfile)) > 0)
|
||||
boffset += ret;
|
||||
}
|
||||
}
|
||||
SMB_CloseFile (smbfile);
|
||||
|
||||
|
@ -19,9 +19,9 @@ bool ConnectShare (bool silent);
|
||||
char * SMBPath(char * path);
|
||||
int UpdateSMBdirname();
|
||||
int ParseSMBdirectory ();
|
||||
int LoadSMBFile ();
|
||||
int LoadSMBFile (char * fbuffer, int length);
|
||||
int LoadBufferFromSMB (char *filepath, bool silent);
|
||||
int LoadBufferFromSMB (char * sbuffer, char *filepath, bool silent);
|
||||
int LoadBufferFromSMB (char * sbuffer, char *filepath, int length, bool silent);
|
||||
int SaveBufferToSMB (char *filepath, int datasize, bool silent);
|
||||
int SaveBufferToSMB (char * sbuffer, char *filepath, int datasize, bool silent);
|
||||
#endif
|
||||
|
@ -16,7 +16,10 @@
|
||||
#include <string.h>
|
||||
#include <zlib.h>
|
||||
|
||||
#include "snes9xGX.h"
|
||||
#include "dvd.h"
|
||||
#include "smbop.h"
|
||||
#include "fileop.h"
|
||||
#include "video.h"
|
||||
#include "menudraw.h"
|
||||
#include "unzip.h"
|
||||
@ -228,3 +231,41 @@ UnZipFile (unsigned char *outbuffer, SMBFILE infile)
|
||||
smbfile = infile;
|
||||
return UnZipBuffer(outbuffer, 2);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* 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 testbuffer[ZIPCHUNK];
|
||||
|
||||
// read start of ZIP
|
||||
switch (method)
|
||||
{
|
||||
case METHOD_SD: // SD Card
|
||||
case METHOD_USB: // USB
|
||||
LoadFATFile (testbuffer, ZIPCHUNK);
|
||||
break;
|
||||
|
||||
case METHOD_DVD: // DVD
|
||||
LoadDVDFile ((unsigned char *)testbuffer, ZIPCHUNK);
|
||||
break;
|
||||
|
||||
case METHOD_SMB: // From SMB
|
||||
LoadSMBFile (testbuffer, ZIPCHUNK);
|
||||
break;
|
||||
}
|
||||
|
||||
testbuffer[28] = 0; // truncate - filename length is 2 bytes long (bytes 26-27)
|
||||
int namelength = testbuffer[26]; // filename length starts 26 bytes in
|
||||
|
||||
char * firstFilename = &testbuffer[30]; // first filename of a ZIP starts 31 bytes in
|
||||
firstFilename[namelength] = 0; // truncate at filename length
|
||||
|
||||
return firstFilename;
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include <smb.h>
|
||||
|
||||
extern int IsZipFile (char *buffer);
|
||||
|
||||
char * GetFirstZipFilename(int method);
|
||||
int UnZipFile (unsigned char *outbuffer, FILE* infile); // Reading from FAT
|
||||
int UnZipFile (unsigned char *outbuffer, u64 inoffset); // Reading from DVD
|
||||
int UnZipFile (unsigned char *outbuffer, SMBFILE infile); // Reading from SMB
|
||||
|
Loading…
Reference in New Issue
Block a user