add loading progress bars

This commit is contained in:
dborth 2008-10-15 06:35:14 +00:00
parent d9f13b8203
commit e222775a1a
7 changed files with 98 additions and 81 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -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;

View File

@ -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
***************************************************************************/
void
ShowProgress (char *msg, int done, int total)
void 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)
ypos += 52;
else
ypos += 32;
int ypos = (screenheight - 30) >> 1;
int xpos;
int i;
if (screenheight == 480)
ypos += 52;
else
ypos += 32;
clearscreen ();
DrawText (-1, ypos, msg);
int xpos;
int i;
clearscreen();
DrawText(-1, ypos, msg);
/*** Draw a white outline box ***/
for (i = 380; i < 401; i++)
DrawLine (100, i, 540, i, 0xff, 0xff, 0xff);
for (i = 380; i < 401; i++)
DrawLine(100, i, 540, i, 0xff, 0xff, 0xff);
/*** Show progess ***/
xpos = (int) (((float) done / (float) total) * 438);
xpos = (int) (((float) done / (float) total) * 438);
for (i = 381; i < 400; i++)
DrawLine (101, i, 101 + xpos, i, 0x00, 0x00, 0x80);
for (i = 381; i < 400; i++)
DrawLine(101, i, 101 + xpos, i, 0x00, 0x00, 0x80);
showscreen ();
showscreen();
}
/****************************************************************************

View File

@ -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);

View File

@ -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;
// the void* object is a SzFileInStream
SzFileInStream *s = (SzFileInStream *) object;
// calculate offset
u64 offset = (u64)(s->offset + s->pos);
// calculate offset
u64 offset = (u64) (s->offset + s->pos);
if(maxRequiredSize > 2048)
if (maxRequiredSize > 2048)
maxRequiredSize = 2048;
// read data
switch(szMethod)
// read data
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);
@ -351,29 +350,33 @@ SZ_RESULT SzFileReadImp(void *object, void **buffer, size_t maxRequiredSize, siz
break;
}
*buffer = sz_buffer;
*processedSize = maxRequiredSize;
s->pos += *processedSize;
*buffer = sz_buffer;
*processedSize = maxRequiredSize;
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
SZ_RESULT SzFileSeekImp(void *object, CFileSize pos)
{
// the void* object is a SzFileInStream
SzFileInStream *s = (SzFileInStream *)object;
// the void* object is a SzFileInStream
SzFileInStream *s = (SzFileInStream *) object;
// check if the 7z SDK wants to move the pointer to somewhere after the EOF
if(pos >= s->len)
{
WaitPrompt((char *)"7z Error: The 7z SDK wants to start reading somewhere behind the EOF...");
return SZE_FAIL;
}
// check if the 7z SDK wants to move the pointer to somewhere after the EOF
if (pos >= s->len)
{
WaitPrompt((char *) "7z: Error - attempt to read after EOF!");
return SZE_FAIL;
}
// save new position and return
s->pos = pos;
return SZ_OK;
// save new position and return
s->pos = pos;
return SZ_OK;
}
/****************************************************************************
@ -525,37 +528,36 @@ void SzClose()
int SzExtractFile(int i, unsigned char *buffer)
{
// prepare some variables
SzBlockIndex = 0xFFFFFFFF;
SzOffset = 0;
// prepare some variables
SzBlockIndex = 0xFFFFFFFF;
SzOffset = 0;
// Unzip the file
ShowAction((char *)"Unzipping file. Please wait...");
// Unzip the file
SzRes = SzExtract2(
&SzArchiveStream.InStream,
&SzDb,
i, // index of file
&SzBlockIndex, // index of solid block
&buffer,
&SzBufferSize,
&SzOffset, // offset of stream for required file in *outBuffer
&SzOutSizeProcessed, // size of file in *outBuffer
&SzAllocImp,
&SzAllocTempImp);
SzRes = SzExtract2(
&SzArchiveStream.InStream,
&SzDb,
i, // index of file
&SzBlockIndex, // index of solid block
&buffer,
&SzBufferSize,
&SzOffset, // offset of stream for required file in *outBuffer
&SzOutSizeProcessed, // size of file in *outBuffer
&SzAllocImp,
&SzAllocTempImp);
// close 7Zip archive and free memory
// close 7Zip archive and free memory
SzClose();
// check for errors
if(SzRes != SZ_OK)
{
// display error message
SzDisplayError(SzRes);
return 0;
}
else
{
return SzOutSizeProcessed;
}
// check for errors
if(SzRes != SZ_OK)
{
// display error message
SzDisplayError(SzRes);
return 0;
}
else
{
return SzOutSizeProcessed;
}
}

View File

@ -2,7 +2,7 @@
* Snes9x 1.51 Nintendo Wii/Gamecube Port
*
* softdev July 2006
* Michniewski 2008
* Michniewski 2008
* Tantric September 2008
*
* unzip.h