#ifndef AFX_ZIPTOOL_H__4C5F3720_4483_11D4_8D96_88668194683D__INCLUDED_ #define AFX_ZIPTOOL_H__4C5F3720_4483_11D4_8D96_88668194683D__INCLUDED_ // Zip Archive Extraction ... ( XacRett #39 SubSet ) // ローカルヘッダ struct ZipLocalHeader { // 'P' 'K' 03 04 WORD ver; // version_needed_to_extract WORD flg; // general_purpose_bit_flag WORD mhd; // compression_method WORD tim; // last_modified_file_time WORD dat; // last_modified_file_date DWORD crc; // crc32 DWORD csz; // compressed-size DWORD usz; // uncompressed-size WORD fnl; // filename-len WORD exl; // extra_field_length char fnm[MAX_PATH]; // BYTE ext[]; }; // 圧縮メソッドの種類 enum ZipMethod { Stored, // 0 Shrunk, // 1 Reduced1, // 2-5 Reduced2, Reduced3, Reduced4, Imploded, // 6 Tokenized, // 7 ( not supported ) Deflated, // 8 EnhDeflated,// 9 ( not supported ) DclImploded,//10 ( not supported ) Err=178 // this value is used by xacrett (^^; }; class CZipTool { public: //-- 外向きインターフェイス -------------- bool Extract( const char* aname, const char* dll, kiPath& dll_rel_path ); private: //-- Zip内部処理用 ----------------------- // CRC DWORD crc32( DWORD crc, const BYTE* dat, int len ); // ファイルIO FILE *zip,*out; void zipwrite( BYTE* dat, int len ) { fwrite( dat, 1, len, out ); } int zipread( BYTE* dat, int len ) { return fread( dat, 1, len, zip ); } // bit-reader unsigned long bitbuf; int bits_left; bool bits_eof; void initbits() { bits_eof=false, bits_left=0, bitbuf=0; } int getbits( int n ) { if( n <= bits_left ) { int c = (int)(bitbuf & ((1<>= n; bits_left -= n; return c; } return fillbits( n ); } int fillbits( int n ) { BYTE next; if( !zipread( &next,1 ) ) bits_eof = true; else { bitbuf |= (next<>= n; bits_left -= n; return c; } // 展開アルゴリズム void Unstore( DWORD usz, DWORD csz ); void Inflate( DWORD usz, DWORD csz ); // ヘッダ処理 // 面倒なのでCentralDirectory系は一切無視! // 現在のファイル位置からヘッダとして読む bool read_header( ZipLocalHeader* hdr ); // ヘッダ位置を探し出して読む bool doHeader( ZipLocalHeader* hdr ); }; #endif