From b67554f47b20316a9638648f2c6e8a65f8882755 Mon Sep 17 00:00:00 2001 From: zeromus Date: Wed, 13 Aug 2008 08:40:12 +0000 Subject: [PATCH] restore unzipping for sdl, also --- changelog.txt | 2 +- src/file.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index 700e335a..4d492680 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,6 +1,6 @@ ---version 2.0.2 released--- -13-aug-2008 - zeromus - restore ungzipping capability which was lost when archive support was added +13-aug-2008 - zeromus - restore ungzipping (and unzipping in sdl) capability which was lost when archive support was added 13-aug-2008 - zeromus - add FORBID breakpoints - regions which block breakpoints from happening if they contain the PC 13-aug-2008 - punkrockguy318 - SDL: fixed --input(1-4) options. input1 and 2 are regular inputs, input3 and 4 are famicom expansion inputs 12-aug-2008 - zeromus - fix SDL configfile woes. configfile now goes to ~/.fceux/fceux.cfg diff --git a/src/file.cpp b/src/file.cpp index 2cd474b5..c9fb7c59 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -184,6 +184,73 @@ FileBaseInfo DetermineFileBase(const char *f) { inline FileBaseInfo DetermineFileBase(const std::string& str) { return DetermineFileBase(str.c_str()); } +static FCEUFILE * TryUnzip(const std::string& path) { + unzFile tz; + if((tz=unzOpen(path.c_str()))) // If it's not a zip file, use regular file handlers. + // Assuming file type by extension usually works, + // but I don't like it. :) + { + if(unzGoToFirstFile(tz)==UNZ_OK) + { + for(;;) + { + char tempu[512]; // Longer filenames might be possible, but I don't + // think people would name files that long in zip files... + unzGetCurrentFileInfo(tz,0,tempu,512,0,0,0,0); + tempu[511]=0; + if(strlen(tempu)>=4) + { + char *za=tempu+strlen(tempu)-4; + + //if(!ext) + { + if(!strcasecmp(za,".nes") || !strcasecmp(za,".fds") || + !strcasecmp(za,".nsf") || !strcasecmp(za,".unf") || + !strcasecmp(za,".nez")) + break; + } + //else if(!strcasecmp(za,ext)) + // break; + } + if(strlen(tempu)>=5) + { + if(!strcasecmp(tempu+strlen(tempu)-5,".unif")) + break; + } + if(unzGoToNextFile(tz)!=UNZ_OK) + { + if(unzGoToFirstFile(tz)!=UNZ_OK) goto zpfail; + break; + } + } + if(unzOpenCurrentFile(tz)!=UNZ_OK) + goto zpfail; + } + else + { +zpfail: + unzClose(tz); + return 0; + } + + unz_file_info ufo; + unzGetCurrentFileInfo(tz,&ufo,0,0,0,0,0,0); + + int size = ufo.uncompressed_size; + memorystream* ms = new memorystream(size); + unzReadCurrentFile(tz,ms->buf(),ufo.uncompressed_size); + unzCloseCurrentFile(tz); + unzClose(tz); + + FCEUFILE *fceufp=fceufp = new FCEUFILE(); + fceufp->stream = ms; + fceufp->size = size; + return fceufp; + + } + + return 0; +} FCEUFILE * FCEU_fopen(const char *path, const char *ipsfn, char *mode, char *ext, int index) { @@ -218,6 +285,19 @@ FCEUFILE * FCEU_fopen(const char *path, const char *ipsfn, char *mode, char *ext return 0; } + //try to read a zip file + { + fceufp = TryUnzip(fileToOpen); + if(fceufp) { + delete fp; + fceufp->filename = fileToOpen; + fceufp->logicalPath = fileToOpen; + fceufp->fullFilename = fileToOpen; + fceufp->archiveIndex = -1; + goto applyips; + } + } + //try to read a gzipped file { uint32 magic;