mirror of
https://github.com/dborth/snes9xgx.git
synced 2024-11-01 00:15:14 +01:00
add loading progress bars
This commit is contained in:
parent
d9f13b8203
commit
e222775a1a
@ -578,7 +578,7 @@ LoadDVDFile (unsigned char *buffer, int length)
|
|||||||
discoffset = dvddir;
|
discoffset = dvddir;
|
||||||
ShowAction ((char*) "Loading...");
|
ShowAction ((char*) "Loading...");
|
||||||
|
|
||||||
if(length > 0)
|
if(length > 0 && length <= 2048)
|
||||||
{
|
{
|
||||||
dvd_read (buffer, length, discoffset);
|
dvd_read (buffer, length, discoffset);
|
||||||
}
|
}
|
||||||
|
@ -185,7 +185,7 @@ LoadFATFile (char * rbuffer, int length)
|
|||||||
fatfile = fopen (filepath, "rb");
|
fatfile = fopen (filepath, "rb");
|
||||||
if (fatfile > 0)
|
if (fatfile > 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)
|
||||||
{
|
{
|
||||||
fread (rbuffer, 1, length, fatfile);
|
fread (rbuffer, 1, length, fatfile);
|
||||||
size = length;
|
size = length;
|
||||||
@ -205,7 +205,13 @@ LoadFATFile (char * rbuffer, int length)
|
|||||||
size = ftell(fatfile); // get filesize
|
size = ftell(fatfile); // get filesize
|
||||||
fseek(fatfile, 2048, SEEK_SET); // seek back to point where we left off
|
fseek(fatfile, 2048, SEEK_SET); // seek back to point where we left off
|
||||||
memcpy (rbuffer, zipbuffer, 2048); // copy what we already read
|
memcpy (rbuffer, zipbuffer, 2048); // copy what we already read
|
||||||
fread (rbuffer + 2048, 1, size - 2048, fatfile);
|
|
||||||
|
u32 offset = 2048;
|
||||||
|
while(offset < size)
|
||||||
|
{
|
||||||
|
offset += fread (rbuffer + offset, 1, (1024*512), fatfile); // read in 512K chunks
|
||||||
|
ShowProgress ((char *)"Loading...", offset, size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose (fatfile);
|
fclose (fatfile);
|
||||||
|
@ -451,6 +451,8 @@ int FileSelector (int method)
|
|||||||
maxfiles = szfiles;
|
maxfiles = szfiles;
|
||||||
inSz = true;
|
inSz = true;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
WaitPrompt((char*) "Error opening archive!");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -472,21 +474,21 @@ int FileSelector (int method)
|
|||||||
if(inSz)
|
if(inSz)
|
||||||
SNESROMSize = LoadFATSzFile(szpath, (unsigned char *)Memory.ROM);
|
SNESROMSize = LoadFATSzFile(szpath, (unsigned char *)Memory.ROM);
|
||||||
else
|
else
|
||||||
SNESROMSize = LoadFATFile ((char *)Memory.ROM, 0);
|
SNESROMSize = LoadFATFile ((char *)Memory.ROM, filelist[selection].length);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case METHOD_DVD:
|
case METHOD_DVD:
|
||||||
if(inSz)
|
if(inSz)
|
||||||
SNESROMSize = SzExtractFile(filelist[selection].offset, (unsigned char *)Memory.ROM);
|
SNESROMSize = SzExtractFile(filelist[selection].offset, (unsigned char *)Memory.ROM);
|
||||||
else
|
else
|
||||||
SNESROMSize = LoadDVDFile (Memory.ROM, 0);
|
SNESROMSize = LoadDVDFile (Memory.ROM, filelist[selection].length);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case METHOD_SMB:
|
case METHOD_SMB:
|
||||||
if(inSz)
|
if(inSz)
|
||||||
SNESROMSize = LoadSMBSzFile(szpath, (unsigned char *)Memory.ROM);
|
SNESROMSize = LoadSMBSzFile(szpath, (unsigned char *)Memory.ROM);
|
||||||
else
|
else
|
||||||
SNESROMSize = LoadSMBFile ((char *)Memory.ROM, 0);
|
SNESROMSize = LoadSMBFile ((char *)Memory.ROM, filelist[selection].length);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
inSz = false;
|
inSz = false;
|
||||||
|
@ -920,33 +920,37 @@ DrawLine (int x1, int y1, int x2, int y2, u8 r, u8 g, u8 b)
|
|||||||
*
|
*
|
||||||
* Show the user what's happening
|
* Show the user what's happening
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
void
|
void ShowProgress(char *msg, int done, int total)
|
||||||
ShowProgress (char *msg, int done, int total)
|
|
||||||
{
|
{
|
||||||
int ypos = (screenheight - 30) >> 1;
|
if(total <= 0) // division by 0 is bad!
|
||||||
|
return;
|
||||||
|
else if(done > total) // this shouldn't happen
|
||||||
|
done = total;
|
||||||
|
|
||||||
if (screenheight == 480)
|
int ypos = (screenheight - 30) >> 1;
|
||||||
ypos += 52;
|
|
||||||
else
|
|
||||||
ypos += 32;
|
|
||||||
|
|
||||||
int xpos;
|
if (screenheight == 480)
|
||||||
int i;
|
ypos += 52;
|
||||||
|
else
|
||||||
|
ypos += 32;
|
||||||
|
|
||||||
clearscreen ();
|
int xpos;
|
||||||
DrawText (-1, ypos, msg);
|
int i;
|
||||||
|
|
||||||
|
clearscreen();
|
||||||
|
DrawText(-1, ypos, msg);
|
||||||
|
|
||||||
/*** Draw a white outline box ***/
|
/*** Draw a white outline box ***/
|
||||||
for (i = 380; i < 401; i++)
|
for (i = 380; i < 401; i++)
|
||||||
DrawLine (100, i, 540, i, 0xff, 0xff, 0xff);
|
DrawLine(100, i, 540, i, 0xff, 0xff, 0xff);
|
||||||
|
|
||||||
/*** Show progess ***/
|
/*** Show progess ***/
|
||||||
xpos = (int) (((float) done / (float) total) * 438);
|
xpos = (int) (((float) done / (float) total) * 438);
|
||||||
|
|
||||||
for (i = 381; i < 400; i++)
|
for (i = 381; i < 400; i++)
|
||||||
DrawLine (101, i, 101 + xpos, i, 0x00, 0x00, 0x80);
|
DrawLine(101, i, 101 + xpos, i, 0x00, 0x00, 0x80);
|
||||||
|
|
||||||
showscreen ();
|
showscreen();
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
|
@ -352,7 +352,7 @@ 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);
|
||||||
}
|
}
|
||||||
@ -367,8 +367,11 @@ 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;
|
||||||
|
ShowProgress ((char *)"Loading...", boffset, length);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SMB_CloseFile (smbfile);
|
SMB_CloseFile (smbfile);
|
||||||
|
@ -102,7 +102,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
|
||||||
@ -129,9 +128,7 @@ UnZipBuffer (unsigned char *outbuffer, int method)
|
|||||||
|
|
||||||
pkzip.uncompressedSize = FLIP32 (pkzip.uncompressedSize);
|
pkzip.uncompressedSize = FLIP32 (pkzip.uncompressedSize);
|
||||||
|
|
||||||
sprintf (msg, "Unzipping %d bytes ... Wait",
|
ShowProgress ((char *)"Loading...", 0, pkzip.uncompressedSize);
|
||||||
pkzip.uncompressedSize);
|
|
||||||
ShowAction (msg);
|
|
||||||
|
|
||||||
/*** Prepare the zip stream ***/
|
/*** Prepare the zip stream ***/
|
||||||
memset (&zs, 0, sizeof (z_stream));
|
memset (&zs, 0, sizeof (z_stream));
|
||||||
@ -202,6 +199,7 @@ UnZipBuffer (unsigned char *outbuffer, int method)
|
|||||||
SMB_ReadFile(readbuffer, ZIPCHUNK, readoffset, smbfile);
|
SMB_ReadFile(readbuffer, ZIPCHUNK, readoffset, smbfile);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
ShowProgress ((char *)"Loading...", bufferoffset, pkzip.uncompressedSize);
|
||||||
}
|
}
|
||||||
while (res != Z_STREAM_END);
|
while (res != Z_STREAM_END);
|
||||||
|
|
||||||
@ -324,24 +322,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);
|
||||||
@ -351,29 +350,33 @@ 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;
|
if(maxRequiredSize > 1024) // only show progress for large reads
|
||||||
|
// this isn't quite right, but oh well
|
||||||
|
ShowProgress ((char *)"Loading...", s->pos, filelist[selection].length);
|
||||||
|
|
||||||
|
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((char *)"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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -525,37 +528,36 @@ void SzClose()
|
|||||||
|
|
||||||
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((char *)"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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
* Snes9x 1.51 Nintendo Wii/Gamecube Port
|
* Snes9x 1.51 Nintendo Wii/Gamecube Port
|
||||||
*
|
*
|
||||||
* softdev July 2006
|
* softdev July 2006
|
||||||
* Michniewski 2008
|
* Michniewski 2008
|
||||||
* Tantric September 2008
|
* Tantric September 2008
|
||||||
*
|
*
|
||||||
* unzip.h
|
* unzip.h
|
||||||
|
Loading…
Reference in New Issue
Block a user