Ticket #9201: unzip_cpp.patch
File unzip_cpp.patch, 3.7 KB (added by , 14 years ago) |
---|
-
unzip.cpp
107 107 #include "common/unzip.h" 108 108 #include "common/file.h" 109 109 110 #ifdef ZIP_HASH 111 #include "common/hashmap.h" 112 #include "common/hash-str.h" 113 #endif 114 110 115 #if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP) 111 116 /* like the STRICT of WIN32, we define a pointer that cannot be converted 112 117 from (void*) without cast */ … … 362 367 uLong byte_before_the_zipfile;/* byte before the zipfile, (>0 for sfx)*/ 363 368 } file_in_zip_read_info_s; 364 369 370 #ifdef ZIP_HASH 365 371 372 typedef 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 380 typedef Common::HashMap<Common::String, cached_file_in_zip, Common::IgnoreCase_Hash, 381 Common::IgnoreCase_EqualTo> ZipHash; 382 383 #endif 384 366 385 /* unz_s contain internal information about the zipfile 367 386 */ 368 387 typedef struct { … … 382 401 unz_file_info_internal cur_file_info_internal; /* private info about it*/ 383 402 file_in_zip_read_info_s* pfile_in_zip_read; /* structure about the current 384 403 file if we are decompressing it */ 404 #ifdef ZIP_HASH 405 ZipHash _hash; 406 #endif 385 407 } unz_s; 386 408 387 409 /* =========================================================================== … … 589 611 us->central_pos = central_pos; 590 612 us->pfile_in_zip_read = NULL; 591 613 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 592 637 unzGoToFirstFile((unzFile)us); 638 #endif 593 639 return (unzFile)us; 594 640 } 595 641 … … 870 916 return err; 871 917 } 872 918 873 874 919 /* 875 920 Try locate the file szFileName in the zipfile. 876 921 For the iCaseSensitivity signification, see unzipStringFileNameCompare … … 881 926 */ 882 927 int unzLocateFile(unzFile file, const char *szFileName, int iCaseSensitivity) { 883 928 unz_s* s; 884 int err;885 929 886 887 uLong num_fileSaved;888 uLong pos_in_central_dirSaved;889 890 891 930 if (file==NULL) 892 931 return UNZ_PARAMERROR; 893 932 … … 898 937 if (!s->current_file_ok) 899 938 return UNZ_END_OF_LIST_OF_FILE; 900 939 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 901 961 num_fileSaved = s->num_file; 902 962 pos_in_central_dirSaved = s->pos_in_central_dir; 903 963 … … 916 976 917 977 s->num_file = num_fileSaved ; 918 978 s->pos_in_central_dir = pos_in_central_dirSaved ; 979 919 980 return err; 981 #endif 920 982 } 921 983 922 984