mirror of https://github.com/stella-emu/stella.git
Added disclaimer for new ZipHandler code, and cleaned up some
debug code and formatting issues. git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@2604 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
parent
b6b6835435
commit
3aa7bfd8e3
|
@ -36,3 +36,38 @@ FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. THIS SOFTWARE IS
|
||||||
PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO
|
PROVIDED ON AN "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO
|
||||||
OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
|
OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR
|
||||||
MODIFICATIONS.
|
MODIFICATIONS.
|
||||||
|
|
||||||
|
/***************************************************************************
|
||||||
|
The Stella project uses certain portions of code under the following
|
||||||
|
licensing; the specific files also contain this disclaimer:
|
||||||
|
|
||||||
|
Copyright Aaron Giles
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are
|
||||||
|
met:
|
||||||
|
|
||||||
|
* Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
* Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in
|
||||||
|
the documentation and/or other materials provided with the
|
||||||
|
distribution.
|
||||||
|
* Neither the name 'MAME' nor the names of its contributors may be
|
||||||
|
used to endorse or promote products derived from this software
|
||||||
|
without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY AARON GILES ''AS IS'' AND ANY EXPRESS OR
|
||||||
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL AARON GILES BE LIABLE FOR ANY DIRECT,
|
||||||
|
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||||
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||||
|
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||||
|
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||||
|
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
|
POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
***************************************************************************/
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
This is release 3.7.5 of Stella. Stella is a multi-platform Atari 2600 VCS
|
Stella is a multi-platform Atari 2600 VCS emulator which allows you to
|
||||||
emulator which allows you to play all of your favourite Atari 2600 games
|
play all of your favourite Atari 2600 games on your PC. You'll find the
|
||||||
on your PC. You'll find the Stella Users Manual in the docs subdirectory.
|
Stella Users Manual in the docs subdirectory. If you'd like to verify
|
||||||
If you'd like to verify that you have the latest release of Stella visit
|
that you have the latest release of Stella, visit the Stella Website at:
|
||||||
the Stella Website at:
|
|
||||||
|
|
||||||
http://stella.sourceforge.net
|
http://stella.sourceforge.net
|
||||||
|
|
||||||
|
|
|
@ -167,8 +167,10 @@ ZipHandler::zip_error ZipHandler::zip_file_open(const char *filename, zip_file *
|
||||||
{
|
{
|
||||||
zip_file *cached = myZipCache[cachenum];
|
zip_file *cached = myZipCache[cachenum];
|
||||||
|
|
||||||
/* if we have a valid entry and it matches our filename, use it and remove from the cache */
|
/* if we have a valid entry and it matches our filename, use it and remove
|
||||||
if (cached != NULL && cached->filename != NULL && strcmp(filename, cached->filename) == 0)
|
from the cache */
|
||||||
|
if (cached != NULL && cached->filename != NULL &&
|
||||||
|
strcmp(filename, cached->filename) == 0)
|
||||||
{
|
{
|
||||||
*zip = cached;
|
*zip = cached;
|
||||||
myZipCache[cachenum] = NULL;
|
myZipCache[cachenum] = NULL;
|
||||||
|
@ -195,7 +197,8 @@ ZipHandler::zip_error ZipHandler::zip_file_open(const char *filename, zip_file *
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
/* verify that we can work with this zipfile (no disk spanning allowed) */
|
/* verify that we can work with this zipfile (no disk spanning allowed) */
|
||||||
if (newzip->ecd.disk_number != newzip->ecd.cd_start_disk_number || newzip->ecd.cd_disk_entries != newzip->ecd.cd_total_entries)
|
if (newzip->ecd.disk_number != newzip->ecd.cd_start_disk_number ||
|
||||||
|
newzip->ecd.cd_disk_entries != newzip->ecd.cd_total_entries)
|
||||||
{
|
{
|
||||||
ziperr = ZIPERR_UNSUPPORTED;
|
ziperr = ZIPERR_UNSUPPORTED;
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -210,7 +213,8 @@ ZipHandler::zip_error ZipHandler::zip_file_open(const char *filename, zip_file *
|
||||||
}
|
}
|
||||||
|
|
||||||
/* read the central directory */
|
/* read the central directory */
|
||||||
success = stream_read(newzip->file, newzip->cd, newzip->ecd.cd_start_disk_offset, newzip->ecd.cd_size, read_length);
|
success = stream_read(newzip->file, newzip->cd, newzip->ecd.cd_start_disk_offset,
|
||||||
|
newzip->ecd.cd_size, read_length);
|
||||||
if (!success || read_length != newzip->ecd.cd_size)
|
if (!success || read_length != newzip->ecd.cd_size)
|
||||||
{
|
{
|
||||||
ziperr = success ? ZIPERR_FILE_TRUNCATED : ZIPERR_FILE_ERROR;
|
ziperr = success ? ZIPERR_FILE_TRUNCATED : ZIPERR_FILE_ERROR;
|
||||||
|
@ -275,7 +279,6 @@ void ZipHandler::zip_file_cache_clear(void)
|
||||||
for (int cachenum = 0; cachenum < ZIP_CACHE_SIZE; cachenum++)
|
for (int cachenum = 0; cachenum < ZIP_CACHE_SIZE; cachenum++)
|
||||||
if (myZipCache[cachenum] != NULL)
|
if (myZipCache[cachenum] != NULL)
|
||||||
{
|
{
|
||||||
cerr << "free cache: " << myZipCache[cachenum]->filename << endl;
|
|
||||||
free_zip_file(myZipCache[cachenum]);
|
free_zip_file(myZipCache[cachenum]);
|
||||||
myZipCache[cachenum] = NULL;
|
myZipCache[cachenum] = NULL;
|
||||||
}
|
}
|
||||||
|
@ -345,39 +348,40 @@ const ZipHandler::zip_file_header* ZipHandler::zip_file_next_file(zip_file *zip)
|
||||||
zip_file_decompress - decompress a file
|
zip_file_decompress - decompress a file
|
||||||
from a ZIP into the target buffer
|
from a ZIP into the target buffer
|
||||||
-------------------------------------------------*/
|
-------------------------------------------------*/
|
||||||
ZipHandler::zip_error ZipHandler::zip_file_decompress(zip_file *zip, void *buffer, uInt32 length)
|
ZipHandler::zip_error
|
||||||
|
ZipHandler::zip_file_decompress(zip_file *zip, void *buffer, uInt32 length)
|
||||||
{
|
{
|
||||||
zip_error ziperr;
|
zip_error ziperr;
|
||||||
uInt64 offset;
|
uInt64 offset;
|
||||||
|
|
||||||
/* if we don't have enough buffer, error */
|
/* if we don't have enough buffer, error */
|
||||||
if (length < zip->header.uncompressed_length)
|
if (length < zip->header.uncompressed_length)
|
||||||
return ZIPERR_BUFFER_TOO_SMALL;
|
return ZIPERR_BUFFER_TOO_SMALL;
|
||||||
|
|
||||||
/* make sure the info in the header aligns with what we know */
|
/* make sure the info in the header aligns with what we know */
|
||||||
if (zip->header.start_disk_number != zip->ecd.disk_number)
|
if (zip->header.start_disk_number != zip->ecd.disk_number)
|
||||||
return ZIPERR_UNSUPPORTED;
|
return ZIPERR_UNSUPPORTED;
|
||||||
|
|
||||||
/* get the compressed data offset */
|
/* get the compressed data offset */
|
||||||
ziperr = get_compressed_data_offset(zip, &offset);
|
ziperr = get_compressed_data_offset(zip, &offset);
|
||||||
if (ziperr != ZIPERR_NONE)
|
if (ziperr != ZIPERR_NONE)
|
||||||
return ziperr;
|
return ziperr;
|
||||||
|
|
||||||
/* handle compression types */
|
/* handle compression types */
|
||||||
switch (zip->header.compression)
|
switch (zip->header.compression)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
ziperr = decompress_data_type_0(zip, offset, buffer, length);
|
ziperr = decompress_data_type_0(zip, offset, buffer, length);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 8:
|
case 8:
|
||||||
ziperr = decompress_data_type_8(zip, offset, buffer, length);
|
ziperr = decompress_data_type_8(zip, offset, buffer, length);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
ziperr = ZIPERR_UNSUPPORTED;
|
ziperr = ZIPERR_UNSUPPORTED;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return ziperr;
|
return ziperr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,7 +397,6 @@ void ZipHandler::free_zip_file(zip_file *zip)
|
||||||
{
|
{
|
||||||
if (zip != NULL)
|
if (zip != NULL)
|
||||||
{
|
{
|
||||||
if (zip->file) cerr << "free: " << zip->filename << endl;
|
|
||||||
if (zip->file)
|
if (zip->file)
|
||||||
stream_close(&zip->file);
|
stream_close(&zip->file);
|
||||||
if (zip->filename != NULL)
|
if (zip->filename != NULL)
|
||||||
|
@ -435,7 +438,8 @@ ZipHandler::zip_error ZipHandler::read_ecd(zip_file *zip)
|
||||||
return ZIPERR_OUT_OF_MEMORY;
|
return ZIPERR_OUT_OF_MEMORY;
|
||||||
|
|
||||||
/* read in one buffers' worth of data */
|
/* read in one buffers' worth of data */
|
||||||
bool success = stream_read(zip->file, buffer, zip->length - buflen, buflen, read_length);
|
bool success = stream_read(zip->file, buffer, zip->length - buflen,
|
||||||
|
buflen, read_length);
|
||||||
if (!success || read_length != buflen)
|
if (!success || read_length != buflen)
|
||||||
{
|
{
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
@ -444,7 +448,8 @@ ZipHandler::zip_error ZipHandler::read_ecd(zip_file *zip)
|
||||||
|
|
||||||
/* find the ECD signature */
|
/* find the ECD signature */
|
||||||
for (offset = buflen - 22; offset >= 0; offset--)
|
for (offset = buflen - 22; offset >= 0; offset--)
|
||||||
if (buffer[offset + 0] == 'P' && buffer[offset + 1] == 'K' && buffer[offset + 2] == 0x05 && buffer[offset + 3] == 0x06)
|
if (buffer[offset + 0] == 'P' && buffer[offset + 1] == 'K' &&
|
||||||
|
buffer[offset + 2] == 0x05 && buffer[offset + 3] == 0x06)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* if we found it, fill out the data */
|
/* if we found it, fill out the data */
|
||||||
|
@ -485,7 +490,8 @@ ZipHandler::zip_error ZipHandler::read_ecd(zip_file *zip)
|
||||||
get_compressed_data_offset - return the
|
get_compressed_data_offset - return the
|
||||||
offset of the compressed data
|
offset of the compressed data
|
||||||
-------------------------------------------------*/
|
-------------------------------------------------*/
|
||||||
ZipHandler::zip_error ZipHandler::get_compressed_data_offset(zip_file *zip, uInt64 *offset)
|
ZipHandler::zip_error
|
||||||
|
ZipHandler::get_compressed_data_offset(zip_file *zip, uInt64 *offset)
|
||||||
{
|
{
|
||||||
uInt32 read_length;
|
uInt32 read_length;
|
||||||
|
|
||||||
|
@ -494,7 +500,8 @@ ZipHandler::zip_error ZipHandler::get_compressed_data_offset(zip_file *zip, uInt
|
||||||
return ZIPERR_FILE_ERROR;
|
return ZIPERR_FILE_ERROR;
|
||||||
|
|
||||||
/* now go read the fixed-sized part of the local file header */
|
/* now go read the fixed-sized part of the local file header */
|
||||||
bool success = stream_read(zip->file, zip->buffer, zip->header.local_header_offset, ZIPNAME, read_length);
|
bool success = stream_read(zip->file, zip->buffer, zip->header.local_header_offset,
|
||||||
|
ZIPNAME, read_length);
|
||||||
if (!success || read_length != ZIPNAME)
|
if (!success || read_length != ZIPNAME)
|
||||||
return success ? ZIPERR_FILE_TRUNCATED : ZIPERR_FILE_ERROR;
|
return success ? ZIPERR_FILE_TRUNCATED : ZIPERR_FILE_ERROR;
|
||||||
|
|
||||||
|
@ -514,12 +521,15 @@ ZipHandler::zip_error ZipHandler::get_compressed_data_offset(zip_file *zip, uInt
|
||||||
decompress_data_type_0 - "decompress"
|
decompress_data_type_0 - "decompress"
|
||||||
type 0 data (which is uncompressed)
|
type 0 data (which is uncompressed)
|
||||||
-------------------------------------------------*/
|
-------------------------------------------------*/
|
||||||
ZipHandler::zip_error ZipHandler::decompress_data_type_0(zip_file *zip, uInt64 offset, void *buffer, uInt32 length)
|
ZipHandler::zip_error
|
||||||
|
ZipHandler::decompress_data_type_0(zip_file *zip, uInt64 offset,
|
||||||
|
void *buffer, uInt32 length)
|
||||||
{
|
{
|
||||||
uInt32 read_length;
|
uInt32 read_length;
|
||||||
|
|
||||||
/* the data is uncompressed; just read it */
|
/* the data is uncompressed; just read it */
|
||||||
bool success = stream_read(zip->file, buffer, offset, zip->header.compressed_length, read_length);
|
bool success = stream_read(zip->file, buffer, offset, zip->header.compressed_length,
|
||||||
|
read_length);
|
||||||
if (!success)
|
if (!success)
|
||||||
return ZIPERR_FILE_ERROR;
|
return ZIPERR_FILE_ERROR;
|
||||||
else if (read_length != zip->header.compressed_length)
|
else if (read_length != zip->header.compressed_length)
|
||||||
|
@ -532,7 +542,9 @@ ZipHandler::zip_error ZipHandler::decompress_data_type_0(zip_file *zip, uInt64 o
|
||||||
decompress_data_type_8 - decompress
|
decompress_data_type_8 - decompress
|
||||||
type 8 data (which is deflated)
|
type 8 data (which is deflated)
|
||||||
-------------------------------------------------*/
|
-------------------------------------------------*/
|
||||||
ZipHandler::zip_error ZipHandler::decompress_data_type_8(zip_file *zip, uInt64 offset, void *buffer, uInt32 length)
|
ZipHandler::zip_error
|
||||||
|
ZipHandler::decompress_data_type_8(zip_file *zip, uInt64 offset,
|
||||||
|
void *buffer, uInt32 length)
|
||||||
{
|
{
|
||||||
uInt32 input_remaining = zip->header.compressed_length;
|
uInt32 input_remaining = zip->header.compressed_length;
|
||||||
uInt32 read_length;
|
uInt32 read_length;
|
||||||
|
@ -557,7 +569,9 @@ ZipHandler::zip_error ZipHandler::decompress_data_type_8(zip_file *zip, uInt64 o
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
/* read in the next chunk of data */
|
/* read in the next chunk of data */
|
||||||
bool success = stream_read(zip->file, zip->buffer, offset, BSPF_min(input_remaining, (uInt32)sizeof(zip->buffer)), read_length);
|
bool success = stream_read(zip->file, zip->buffer, offset,
|
||||||
|
BSPF_min(input_remaining, (uInt32)sizeof(zip->buffer)),
|
||||||
|
read_length);
|
||||||
if (!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
inflateEnd(&stream);
|
inflateEnd(&stream);
|
||||||
|
|
|
@ -86,7 +86,8 @@ class ZipHandler
|
||||||
// Replaces functionaity of various osd_xxxx functions
|
// Replaces functionaity of various osd_xxxx functions
|
||||||
static bool stream_open(const char* filename, fstream** stream, uInt64& length);
|
static bool stream_open(const char* filename, fstream** stream, uInt64& length);
|
||||||
static void stream_close(fstream** stream);
|
static void stream_close(fstream** stream);
|
||||||
static bool stream_read(fstream* stream, void* buffer, uInt64 offset, uInt32 length, uInt32& actual);
|
static bool stream_read(fstream* stream, void* buffer, uInt64 offset,
|
||||||
|
uInt32 length, uInt32& actual);
|
||||||
|
|
||||||
/* Error types */
|
/* Error types */
|
||||||
enum zip_error
|
enum zip_error
|
||||||
|
@ -253,8 +254,10 @@ class ZipHandler
|
||||||
static zip_error get_compressed_data_offset(zip_file *zip, uInt64 *offset);
|
static zip_error get_compressed_data_offset(zip_file *zip, uInt64 *offset);
|
||||||
|
|
||||||
/* decompression interfaces */
|
/* decompression interfaces */
|
||||||
static zip_error decompress_data_type_0(zip_file *zip, uInt64 offset, void *buffer, uInt32 length);
|
static zip_error decompress_data_type_0(zip_file *zip, uInt64 offset,
|
||||||
static zip_error decompress_data_type_8(zip_file *zip, uInt64 offset, void *buffer, uInt32 length);
|
void *buffer, uInt32 length);
|
||||||
|
static zip_error decompress_data_type_8(zip_file *zip, uInt64 offset,
|
||||||
|
void *buffer, uInt32 length);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
zip_file* myZip;
|
zip_file* myZip;
|
||||||
|
|
Loading…
Reference in New Issue