mirror of
https://github.com/dborth/snes9xgx.git
synced 2024-11-24 03:29:22 +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;
|
||||
ShowAction ((char*) "Loading...");
|
||||
|
||||
if(length > 0)
|
||||
if(length > 0 && length <= 2048)
|
||||
{
|
||||
dvd_read (buffer, length, discoffset);
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ LoadFATFile (char * rbuffer, int length)
|
||||
fatfile = fopen (filepath, "rb");
|
||||
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);
|
||||
size = length;
|
||||
@ -205,7 +205,13 @@ LoadFATFile (char * rbuffer, int length)
|
||||
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);
|
||||
|
||||
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);
|
||||
|
@ -451,6 +451,8 @@ int FileSelector (int method)
|
||||
maxfiles = szfiles;
|
||||
inSz = true;
|
||||
}
|
||||
else
|
||||
WaitPrompt((char*) "Error opening archive!");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -472,21 +474,21 @@ int FileSelector (int method)
|
||||
if(inSz)
|
||||
SNESROMSize = LoadFATSzFile(szpath, (unsigned char *)Memory.ROM);
|
||||
else
|
||||
SNESROMSize = LoadFATFile ((char *)Memory.ROM, 0);
|
||||
SNESROMSize = LoadFATFile ((char *)Memory.ROM, filelist[selection].length);
|
||||
break;
|
||||
|
||||
case METHOD_DVD:
|
||||
if(inSz)
|
||||
SNESROMSize = SzExtractFile(filelist[selection].offset, (unsigned char *)Memory.ROM);
|
||||
else
|
||||
SNESROMSize = LoadDVDFile (Memory.ROM, 0);
|
||||
SNESROMSize = LoadDVDFile (Memory.ROM, filelist[selection].length);
|
||||
break;
|
||||
|
||||
case METHOD_SMB:
|
||||
if(inSz)
|
||||
SNESROMSize = LoadSMBSzFile(szpath, (unsigned char *)Memory.ROM);
|
||||
else
|
||||
SNESROMSize = LoadSMBFile ((char *)Memory.ROM, 0);
|
||||
SNESROMSize = LoadSMBFile ((char *)Memory.ROM, filelist[selection].length);
|
||||
break;
|
||||
}
|
||||
inSz = false;
|
||||
|
@ -920,9 +920,13 @@ DrawLine (int x1, int y1, int x2, int y2, u8 r, u8 g, u8 b)
|
||||
*
|
||||
* Show the user what's happening
|
||||
***************************************************************************/
|
||||
void
|
||||
ShowProgress (char *msg, int done, int total)
|
||||
void ShowProgress(char *msg, int done, int total)
|
||||
{
|
||||
if(total <= 0) // division by 0 is bad!
|
||||
return;
|
||||
else if(done > total) // this shouldn't happen
|
||||
done = total;
|
||||
|
||||
int ypos = (screenheight - 30) >> 1;
|
||||
|
||||
if (screenheight == 480)
|
||||
@ -933,20 +937,20 @@ ShowProgress (char *msg, int done, int total)
|
||||
int xpos;
|
||||
int i;
|
||||
|
||||
clearscreen ();
|
||||
DrawText (-1, ypos, msg);
|
||||
clearscreen();
|
||||
DrawText(-1, ypos, msg);
|
||||
|
||||
/*** Draw a white outline box ***/
|
||||
for (i = 380; i < 401; i++)
|
||||
DrawLine (100, i, 540, i, 0xff, 0xff, 0xff);
|
||||
DrawLine(100, i, 540, i, 0xff, 0xff, 0xff);
|
||||
|
||||
/*** Show progess ***/
|
||||
xpos = (int) (((float) done / (float) total) * 438);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
@ -367,8 +367,11 @@ 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;
|
||||
ShowProgress ((char *)"Loading...", boffset, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
SMB_CloseFile (smbfile);
|
||||
|
@ -102,7 +102,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
|
||||
@ -129,9 +128,7 @@ UnZipBuffer (unsigned char *outbuffer, int method)
|
||||
|
||||
pkzip.uncompressedSize = FLIP32 (pkzip.uncompressedSize);
|
||||
|
||||
sprintf (msg, "Unzipping %d bytes ... Wait",
|
||||
pkzip.uncompressedSize);
|
||||
ShowAction (msg);
|
||||
ShowProgress ((char *)"Loading...", 0, pkzip.uncompressedSize);
|
||||
|
||||
/*** Prepare the zip stream ***/
|
||||
memset (&zs, 0, sizeof (z_stream));
|
||||
@ -202,6 +199,7 @@ UnZipBuffer (unsigned char *outbuffer, int method)
|
||||
SMB_ReadFile(readbuffer, ZIPCHUNK, readoffset, smbfile);
|
||||
break;
|
||||
}
|
||||
ShowProgress ((char *)"Loading...", bufferoffset, pkzip.uncompressedSize);
|
||||
}
|
||||
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
|
||||
|
||||
SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, size_t *processedSize)
|
||||
{
|
||||
// the void* object is a SzFileInStream
|
||||
SzFileInStream *s = (SzFileInStream *)object;
|
||||
SzFileInStream *s = (SzFileInStream *) object;
|
||||
|
||||
// calculate offset
|
||||
u64 offset = (u64)(s->offset + s->pos);
|
||||
u64 offset = (u64) (s->offset + s->pos);
|
||||
|
||||
if(maxRequiredSize > 2048)
|
||||
if (maxRequiredSize > 2048)
|
||||
maxRequiredSize = 2048;
|
||||
|
||||
// read data
|
||||
switch(szMethod)
|
||||
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);
|
||||
@ -355,6 +354,10 @@ SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, siz
|
||||
*processedSize = maxRequiredSize;
|
||||
s->pos += *processedSize;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -362,12 +365,12 @@ SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, siz
|
||||
SZ_RESULT SzFileSeekImp(void *object, CFileSize pos)
|
||||
{
|
||||
// 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
|
||||
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;
|
||||
}
|
||||
|
||||
@ -530,7 +533,6 @@ int SzExtractFile(int i, unsigned char *buffer)
|
||||
SzOffset = 0;
|
||||
|
||||
// Unzip the file
|
||||
ShowAction((char *)"Unzipping file. Please wait...");
|
||||
|
||||
SzRes = SzExtract2(
|
||||
&SzArchiveStream.InStream,
|
||||
|
Loading…
Reference in New Issue
Block a user