mirror of
https://github.com/dborth/snes9xgx.git
synced 2024-11-01 08:25:18 +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,9 +920,13 @@ 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)
|
|
||||||
{
|
{
|
||||||
|
if(total <= 0) // division by 0 is bad!
|
||||||
|
return;
|
||||||
|
else if(done > total) // this shouldn't happen
|
||||||
|
done = total;
|
||||||
|
|
||||||
int ypos = (screenheight - 30) >> 1;
|
int ypos = (screenheight - 30) >> 1;
|
||||||
|
|
||||||
if (screenheight == 480)
|
if (screenheight == 480)
|
||||||
|
@ -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,6 +322,7 @@ 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
|
||||||
@ -355,6 +354,10 @@ SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, siz
|
|||||||
*processedSize = maxRequiredSize;
|
*processedSize = maxRequiredSize;
|
||||||
s->pos += *processedSize;
|
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;
|
return SZ_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -367,7 +370,7 @@ SZ_RESULT SzFileSeekImp(void *object, CFileSize pos)
|
|||||||
// 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -530,7 +533,6 @@ int SzExtractFile(int i, unsigned char *buffer)
|
|||||||
SzOffset = 0;
|
SzOffset = 0;
|
||||||
|
|
||||||
// Unzip the file
|
// Unzip the file
|
||||||
ShowAction((char *)"Unzipping file. Please wait...");
|
|
||||||
|
|
||||||
SzRes = SzExtract2(
|
SzRes = SzExtract2(
|
||||||
&SzArchiveStream.InStream,
|
&SzArchiveStream.InStream,
|
||||||
|
Loading…
Reference in New Issue
Block a user