Ticket #9201: unzip_cpp.patch

File unzip_cpp.patch, 3.7 KB (added by dreammaster, 14 years ago)

Patch file for common/unzip.cpp

  • unzip.cpp

     
    107107#include "common/unzip.h"
    108108#include "common/file.h"
    109109
     110#ifdef ZIP_HASH
     111#include "common/hashmap.h"
     112#include "common/hash-str.h"
     113#endif
     114
    110115#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
    111116/* like the STRICT of WIN32, we define a pointer that cannot be converted
    112117    from (void*) without cast */
     
    362367        uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/
    363368} file_in_zip_read_info_s;
    364369
     370#ifdef ZIP_HASH
    365371
     372typedef struct {
     373        uLong num_file;                                 /* number of the current file in the zipfile*/
     374        uLong pos_in_central_dir;               /* pos of the current file in the central dir*/
     375        uLong current_file_ok;                  /* flag about the usability of the current file*/
     376        unz_file_info cur_file_info;                                    /* public info about the current file in zip*/
     377        unz_file_info_internal cur_file_info_internal;  /* private info about it*/
     378} cached_file_in_zip;
     379
     380typedef Common::HashMap<Common::String, cached_file_in_zip, Common::IgnoreCase_Hash,
     381        Common::IgnoreCase_EqualTo> ZipHash;
     382
     383#endif
     384
    366385/* unz_s contain internal information about the zipfile
    367386*/
    368387typedef struct {
     
    382401        unz_file_info_internal cur_file_info_internal;  /* private info about it*/
    383402        file_in_zip_read_info_s* pfile_in_zip_read;             /* structure about the current
    384403                                                                                                        file if we are decompressing it */
     404#ifdef ZIP_HASH
     405        ZipHash _hash;
     406#endif
    385407} unz_s;
    386408
    387409/* ===========================================================================
     
    589611        us->central_pos = central_pos;
    590612        us->pfile_in_zip_read = NULL;
    591613
     614#ifdef ZIP_HASH
     615        err = unzGoToFirstFile((unzFile)us);
     616
     617        while (err == UNZ_OK) {
     618                // Get the file details
     619                char szCurrentFileName[UNZ_MAXFILENAMEINZIP+1];
     620                unzGetCurrentFileInfo(us, NULL, szCurrentFileName, sizeof(szCurrentFileName) - 1,
     621                                                        NULL, 0, NULL, 0);
     622
     623                // Save details into the hash
     624                cached_file_in_zip fe;
     625                fe.num_file = us->num_file;
     626                fe.pos_in_central_dir = us->pos_in_central_dir;
     627                fe.current_file_ok = us->current_file_ok;
     628                fe.cur_file_info = us->cur_file_info;
     629                fe.cur_file_info_internal = us->cur_file_info_internal;
     630
     631                us->_hash[Common::String(szCurrentFileName)] = fe;
     632
     633                // Move to the next file
     634                err = unzGoToNextFile((unzFile)us);
     635        }
     636#else
    592637        unzGoToFirstFile((unzFile)us);
     638#endif
    593639        return (unzFile)us;
    594640}
    595641
     
    870916        return err;
    871917}
    872918
    873 
    874919/*
    875920  Try locate the file szFileName in the zipfile.
    876921  For the iCaseSensitivity signification, see unzipStringFileNameCompare
     
    881926*/
    882927int unzLocateFile(unzFile file, const char *szFileName, int iCaseSensitivity) {
    883928        unz_s* s;
    884         int err;
    885929
    886 
    887         uLong num_fileSaved;
    888         uLong pos_in_central_dirSaved;
    889 
    890 
    891930        if (file==NULL)
    892931                return UNZ_PARAMERROR;
    893932
     
    898937        if (!s->current_file_ok)
    899938                return UNZ_END_OF_LIST_OF_FILE;
    900939
     940#ifdef ZIP_HASH
     941        // Check to see if the entry exists
     942        ZipHash::iterator i = s->_hash.find(Common::String(szFileName));
     943        if (i == s->_hash.end())
     944                return UNZ_END_OF_LIST_OF_FILE;
     945
     946        // Found it, so reset the details in the main structure
     947        cached_file_in_zip &fe = i->_value;
     948        s->num_file = fe.num_file;
     949        s->pos_in_central_dir = fe.pos_in_central_dir;
     950        s->current_file_ok = fe.current_file_ok;
     951        s->cur_file_info = fe.cur_file_info;
     952        s->cur_file_info_internal = fe.cur_file_info_internal;
     953
     954        return UNZ_OK;
     955#else
     956        int err;
     957
     958        uLong num_fileSaved;
     959        uLong pos_in_central_dirSaved;
     960
    901961        num_fileSaved = s->num_file;
    902962        pos_in_central_dirSaved = s->pos_in_central_dir;
    903963
     
    916976
    917977        s->num_file = num_fileSaved ;
    918978        s->pos_in_central_dir = pos_in_central_dirSaved ;
     979
    919980        return err;
     981#endif
    920982}
    921983
    922984