X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=source%2Fmupen64launcher%2Fsrc%2Fczip.cpp;fp=source%2Fmupen64launcher%2Fsrc%2Fczip.cpp;h=a9f41bb906eb36384646c81626dd38d85053b8c0;hb=8b5037a6470762c73ca6f5e1e9bb5566f805e948;hp=0000000000000000000000000000000000000000;hpb=ac4f8e4321adb765745b2da188b8b359735ea379;p=mupen64plus-pandora.git diff --git a/source/mupen64launcher/src/czip.cpp b/source/mupen64launcher/src/czip.cpp new file mode 100755 index 0000000..a9f41bb --- /dev/null +++ b/source/mupen64launcher/src/czip.cpp @@ -0,0 +1,456 @@ +/** + * @section LICENSE + * + * PickleLauncher + * Copyright (C) 2010-2011 Scott Smith + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * @section LOCATION + */ + + /* + czip.cpp is based on miniunz.c + + miniunz.c + Version 1.1, February 14h, 2010 + sample part of the MiniZip project - ( http://www.winimage.com/zLibDll/minizip.html ) + + Copyright (C) 1998-2010 Gilles Vollant (minizip) ( http://www.winimage.com/zLibDll/minizip.html ) + + Modifications of Unzip for Zip64 + Copyright (C) 2007-2008 Even Rouault + + Modifications for Zip64 support on both zip and unzip + Copyright (C) 2009-2010 Mathias Svensson ( http://result42.com ) +*/ + +#include "czip.h" + +CZip::CZip() : CBase(), + UnzipFiles () +{ +} + +CZip::~CZip() +{ +} + +void CZip::ListFiles( const string& zipfile, vector& list ) +{ + uint32_t i; + int32_t err; + unzFile uf=NULL; + unz_global_info64 gi; + + // Open the zip file + uf = unzOpen64( zipfile.c_str() ); + + if (uf != NULL) + { + // Get file info for the zip file + err = unzGetGlobalInfo64( uf,&gi ); + if (err != UNZ_OK) + { + Log( "error %d with zipfile in unzGetGlobalInfo\n",err); + return; + } + } + else + { + Log( "error with zipfile %s in unzOpen64\n", zipfile.c_str() ); + return; + } + Log( "Reading zip file %s\n", zipfile.c_str() ); + + // Spit out some information about the files in the zip for debug + Log( " Length Method Size Ratio Date Time CRC-32 Name\n" ); + Log( " ------ ------ ---- ----- ---- ---- ------ ----\n" ); + for (i=0; i 0) + ratio = (uLong)((file_info.compressed_size*100)/file_info.uncompressed_size); + + /* display a '*' if the file is crypted */ + if ((file_info.flag & 1) != 0) + charCrypt='*'; + + if (file_info.compression_method == 0) + string_method="Stored"; + else + if (file_info.compression_method == Z_DEFLATED) + { + uInt iLevel=(uInt)((file_info.flag & 0x6)/2); + if (iLevel==0) + string_method="Defl:N"; + else if (iLevel==1) + string_method="Defl:X"; + else if ((iLevel==2) || (iLevel==3)) + string_method="Defl:F"; /* 2:fast , 3 : extra fast*/ + } + else + if (file_info.compression_method == Z_BZIP2ED) + { + string_method="BZip2 "; + } + else + string_method="Unkn. "; + + Display64BitsSize( file_info.uncompressed_size,7 ); + Log( " %6s%c",string_method,charCrypt); + Display64BitsSize( file_info.compressed_size,7 ); + Log( " %3lu%% %2.2lu-%2.2lu-%2.2lu %2.2lu:%2.2lu %8.8lx %s\n", + ratio, + (uLong)file_info.tmu_date.tm_mon + 1, + (uLong)file_info.tmu_date.tm_mday, + (uLong)file_info.tmu_date.tm_year % 100, + (uLong)file_info.tmu_date.tm_hour,(uLong)file_info.tmu_date.tm_min, + (uLong)file_info.crc,filename_inzip); + if ((i+1) < gi.number_entry) + { + err = unzGoToNextFile( uf ); + if (err != UNZ_OK) + { + Log( "error %d with zipfile in unzGoToNextFile\n",err); + break; + } + } + + // Save the names of the files in the zip + list.push_back( filename_inzip ); + } + + // Close the zip file + unzClose( uf ); +} + +void CZip::ExtractFile( const string& zipfile, const string& location, const string& filename ) +{ + uint32_t i; + int32_t err; + unzFile uf = NULL; + unz_global_info64 gi; + + // Open the zip file + uf = unzOpen64( zipfile.c_str() ); + + if (uf != NULL) + { + // Get file info for the zip file + err = unzGetGlobalInfo64( uf,&gi ); + if (err != UNZ_OK) + { + Log( "error %d with zipfile in unzGetGlobalInfo\n",err); + return; + } + } + else + { + Log( "error with zipfile %s in unzOpen64\n", zipfile.c_str() ); + return; + } + + for (i=0; i 0) + { + if (fwrite( buf, err, 1, fout ) != 1) + { + Log( "error in writing extracted file\n" ); + err = UNZ_ERRNO; + break; + } + } + } + while (err > 0); + + if (fout) + { + fclose( fout ); + } + } + + if (err==UNZ_OK) + { + err = unzCloseCurrentFile( uf ); + if (err != UNZ_OK) + { + Log( "error %d with zipfile in unzCloseCurrentFile\n",err); + } + + AddUnzipFile( write_filename ); + } + else + { + unzCloseCurrentFile( uf ); /* don't lose the error */ + } + + free(buf); + return err; +} + +void CZip::Display64BitsSize(ZPOS64_T n, int size_char) +{ + /* to avoid compatibility problem , we do here the conversion */ + char number[21]; + int offset=19; + int pos_string = 19; + number[20]=0; + for (;;) { + number[offset]=(char)((n%10)+'0'); + if (number[offset] != '0') + pos_string=offset; + n/=10; + if (offset==0) + break; + offset--; + } + { + int size_display_string = 19-pos_string; + while (size_char > size_display_string) + { + size_char--; + Log( " " ); + } + } + + Log( "%s",&number[pos_string]); +} + +void CZip::AddUnzipFile( const string& filename ) +{ + uint16_t i; + + for (i=0; i0) + { +#if defined(DEBUG) + Log( "Saving file %s to ziplist\n", UnzipFiles.at(i).c_str()); +#endif + fout << UnzipFiles.at(i) << endl; + } + } + } + + return 0; +} + +int8_t CZip::LoadUnzipList( const string& location ) +{ + string line; + ifstream fin; + + fin.open(location.c_str(), ios_base::in); + + if (!fin) + { + Log( "Failed to open unziplist at %s\n", location.c_str() ); + return 0; // Dont stop the app if it cant be opened, default values will be used and then save to file. + } + + UnzipFiles.clear(); + + // Read in the profile + if (fin.is_open()) + { + while (!fin.eof()) + { + getline(fin,line); + + if (line.length() > 0) + { + UnzipFiles.push_back(line); + } + } + } + + return 0; +} +