/* ========================================================================== * ÀÛ ¼º ÀÚ : À̼ø±Ô * ÀÛ ¼º ÀÏ : 2006.09.19 * * ³» ¿ë : ÆÄÀÏ ÆÑ * ÁÖÀÇ»çÇ× : *===========================================================================*/ #pragma once //#include #include "ZipArchive.h" /// ÆÄÀÏ ½Ã°£ class cFileTime { public: cFileTime(); cFileTime( time_t time ); cFileTime( const FILETIME& time ); const FILETIME& GetFileTime(); // void operator =( const cFileTime& that ); protected: FILETIME mFileTime; }; /// ÆÑ ¾È¿¡ ÀÖ´Â ÆÄÀÏÀÇ Á¤º¸ class cFileInPackInfo { friend class cFilePack; public: cFileInPackInfo() {} ~cFileInPackInfo() {} bool SetPathName( LPCTSTR pathName ); void SetWriteTime( const time_t& time ); const cStringT& GetPathName() const; unsigned int GetSize() const; const cFileTime& GetWriteTime() const; bool IsDirectory() const; time_t GetUnixWriteTime(); FILETIME* GetWriteTimeInExtraBuf(); WORD GetExtraFieldSize(); CZipString GetComment(); protected: void UpdateFromHeader(); protected: /// Çì´õ CZipFileHeader mHeader; /// À̸§ cStringT mPathName; /// ½Ã°£ cFileTime mWriteTime; }; inline CZipString cFileInPackInfo::GetComment() { return mHeader.GetComment(); } inline WORD cFileInPackInfo::GetExtraFieldSize() { return mHeader.GetExtraFieldSize(); } inline time_t cFileInPackInfo::GetUnixWriteTime() { return mHeader.GetTime(); } inline const cStringT& cFileInPackInfo::GetPathName() const { return mPathName; } inline unsigned int cFileInPackInfo::GetSize() const { return (unsigned int)mHeader.m_uUncomprSize; } inline const cFileTime& cFileInPackInfo::GetWriteTime() const { return mWriteTime; } inline bool cFileInPackInfo::IsDirectory() const { return mHeader.IsDirectory(); } static BYTE SY_KEY_TABLE[64]= { 0x23, 0xbe, 0x84, 0xe1, 0x6c, 0xd6, 0xae, 0x52, 0x90, 0x49, 0xf1, 0xf1, 0xbb, 0xe9, 0xeb, 0xb3, 0xa6, 0xdb, 0x3c, 0x87, 0x0c, 0x3e, 0x99, 0x24, 0x5e, 0x0d, 0x1c, 0x06, 0xb7, 0x47, 0xde, 0xb3, 0x12, 0x4d, 0xc8, 0x43, 0xbb, 0x8b, 0xa6, 0x1f, 0x03, 0x5a, 0x7d, 0x09, 0x38, 0x25, 0x1f, 0x5d, 0xd4, 0xcb, 0xfc, 0x96, 0xf5, 0x45, 0x3b, 0x13, 0x0d, 0x89, 0x0a, 0x1c, 0xdb, 0xae, 0x32, 0x20 }; static BYTE MIX_TABLE[64] = { 58, 22, 59, 17, 45, 46, 36, 8, 57, 62, 18, 27, 37, 3, 37, 60, 52, 5, 19, 24, 40, 14, 11, 53, 5, 32, 25, 61, 23, 39, 10, 25, 54, 45, 16, 2, 9, 13, 40, 20, 9, 42, 57, 37, 8, 33, 0, 20, 25, 44, 33, 38, 30, 14, 33, 48, 28, 62, 25, 49, 31, 34, 37, 34 }; /// ÆÄÀÏ ÆÑ class cFilePack { public: /// ¿­±â ¸ðµå enum eOpenMode { OPEN_READONLY = CZipArchive::zipOpenReadOnly, OPEN = CZipArchive::zipOpen, CREATE = CZipArchive::zipCreate }; public: cFilePack(); ~cFilePack(); /// ¿­±â bool Open( LPCTSTR pathName, eOpenMode mode ); /// ´Ý±â void Close(); /// ÆÐ½º¿öµå /// ÆÄÀÏ ÆÑÀ» ¿¬ ÈÄ, ÆÄÀÏÀ» »ý¼ºÇϰųª Ãß°¡Çϱâ Àü¿¡ »ç¿ëÇÑ´Ù. bool SetPassword( LPCTSTR password = 0 ); /// DecryptÇÑ ÆÐ½º¿öµå¸¦ ³Ö´Â´Ù. bool SetPasswordEx( const char* password = 0, int len = 0 ); /// ÆÄÀÏ °Ë»ö /// ÆÄÀÏ À妽º¸¦ ¸®ÅÏÇÑ´Ù. ½ÇÆÐÇϸé -1À» ¸®ÅÏÇÑ´Ù. int FindFile( const cStringT& pathName, bool caseSensitive = false ); /// ÆÄÀÏ »èÁ¦ void DeleteFile( int index ); void DeleteFiles( const tArray& indexArray ); void DeleteFiles( CZipWordArray& indexArray ); void DeleteFiles( CZipStringArray *stringArray ); /// ÆÄÀÏ À̸§ º¯°æ bool RenameFile( int index, const cStringT& newPathName ); /// ÆÄÀÏ ¿­±â bool OpenFile( int index ); /// ÆÄÀÏ ´Ý±â bool CloseFile(); /// ÆÄÀÏ Àбâ /// OpenFile() ÇÔ¼ö·Î ¿­·Á ÀÖ¾î¾ß ÇÑ´Ù. /// ¼º°øÇÏ¸é ½ÇÁ¦·Î ÀоîµéÀÎ ¹ÙÀÌÆ® ¼ö¸¦ ¸®ÅÏÇϰí, ½ÇÆÐÇϸé 0À» ¸®ÅÏÇÑ´Ù. unsigned int ReadFile( void* buffer, unsigned int size ); /// »õ ÆÄÀÏ ¿­±â /// compressLevel : ¾ÐÃà ¼öÁØ /// filePath : ÇØ´ç °æ·ÎÀÇ ÆÄÀϷκÎÅÍ ½Ã°£ Á¤º¸¿Í ¼Ó¼ºÀ» °¡Á®¿Â´Ù. bool OpenNewFile( cFileInPackInfo& fi, int compressLevel = Z_NO_COMPRESSION, LPCTSTR filePath = 0 ); /// ¾ÐÃà ÆÄÀÏ ¾ÈÀÇ ÆÄÀÏ ´Ý±â bool CloseNewFile(); /// ¹öÆÛÀÇ ³»¿ëÀ» ¾ÐÃàÇØ¼­ ÀúÀå /// OpenNewFile() ÇÔ¼ö·Î ¿­·Á ÀÖ¾î¾ß ÇÑ´Ù. bool WriteNewFile( const void* buffer, unsigned int size ); /// ³»ºÎ ¹öÆÛÀÇ ³»¿ëÀ» ¸ðµÎ ÀúÀå¼Ò¿¡ ±â·Ï void Flush(); /// ÆÄÀÏÀÌ ¿­·È´ÂÁö¸¦ ¸®ÅÏ bool IsOpened(); /// ÆÄÀÏ ¼ö¸¦ ¸®ÅÏ int GetNumFiles() const; /// ÆÄÀÏ Á¤º¸¸¦ ¸®ÅÏ bool GetFileInfo( cFileInPackInfo* fi, int index ) const; /// Ãß°¡ ¸Þ¸ð¸® ¼³Á¤ const char* SetExtraFieldEx(const char *pBuf, WORD iSize); /// ÆÄÀÏ À̸§µé·Î À妽ºµé ¾ò¾î¿À±â void GetIndexes(const CZipStringArray &aNames, CZipWordArray& aIndexes); /// ÆÄÀÏ À̸§À¸·Î À妽º ¾ò¾î¿À±â int GetIndex( LPCTSTR Names ); /// ¸Þ¸ð¸®¿¡ ¾ÐÃà Ç®±â bool ExtractFileInMem(WORD uIndex, CZipMemFile& mf, bool bRewind = true, DWORD nBufSize = 65536); /// ¸Þ¸ð¸®¿¡ ÀÖ´Â ÆÄÀÏÀ» ÆÑ¿¡ Ãß°¡Çϱâ. bool AddNewFile(CZipMemFile& mf, LPCTSTR lpszFileNameInZip, int iComprLevel = -1, int iSmartLevel = CZipArchive::zipsmSafeSmart, unsigned long nBufSize = 65536); bool SetFileComment(WORD uIndex, LPCTSTR lpszComment); private: /// ¾ÐÃà ÀúÀå¼Ò CZipArchive mZip; }; inline bool cFilePack::SetFileComment(WORD uIndex, LPCTSTR lpszComment) { return mZip.SetFileComment( uIndex, lpszComment ); } inline int cFilePack::GetIndex( LPCTSTR Names ) { return mZip.FindFile( Names ); } inline bool cFilePack::AddNewFile( CZipMemFile& mf, LPCTSTR lpszFileNameInZip, int iComprLevel /* = -1 */, int iSmartLevel /* = CZipArchive::zipsmSafeSmart */, unsigned long nBufSize /* = 65536 */ ) { return mZip.AddNewFile( mf, lpszFileNameInZip, iComprLevel, iSmartLevel, nBufSize ); } inline bool cFilePack::ExtractFileInMem(WORD uIndex, CZipMemFile& mf, bool bRewind /* = true */, DWORD nBufSize /* = 65536 */) { return mZip.ExtractFile( uIndex, mf, bRewind, nBufSize ); } inline void cFilePack::GetIndexes( const CZipStringArray &aNames, CZipWordArray& aIndexes ) { return mZip.GetIndexes( aNames, aIndexes ); } inline bool cFilePack::SetPassword( const charT* password ) { return mZip.SetPassword( password ); } inline bool cFilePack::SetPasswordEx( const char* password , int len ) { char *pDecryptPassword; pDecryptPassword = new char[len+1]; pDecryptPassword[len] = 0; for( int idx = 0; idx < len; ++idx ) { BYTE keyIdx = MIX_TABLE[ idx % 64 ]; pDecryptPassword[idx] = password[idx] ^ SY_KEY_TABLE[keyIdx]; } bool ret = false; charT *pUnicodeDecryptPassword; pUnicodeDecryptPassword = new charT[len+2]; pUnicodeDecryptPassword[len+1] = 0; #ifdef _UNICODE size_t lenDecrypt = ::strlen(pDecryptPassword); if( lenDecrypt == 0 ) return ret; int iLen = ::MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, pDecryptPassword, lenDecrypt, NULL, 0 ); if (iLen > 0) { assert( iLen+1 < (int)lenDecrypt+2 ); iLen = ::MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, pDecryptPassword, -1, (LPWSTR)pUnicodeDecryptPassword, iLen+1 ); assert(iLen != 0); } else { iLen --; // return -1 } #else #if (_MSC_VER >= 1400) _tcscpy_s( pUnicodeDecryptPassword, len+2, pDecryptPassword ); #else _tcscpy( pUnicodeDecryptPassword, pDecryptPassword ); #endif #endif ret = mZip.SetPassword( pUnicodeDecryptPassword ); delete[] pDecryptPassword; delete[] pUnicodeDecryptPassword; return ret; } inline bool cFilePack::IsOpened() { return !mZip.IsClosed(); } inline int cFilePack::GetNumFiles() const { return mZip.GetCount(); } inline const char* cFilePack::SetExtraFieldEx( const char *pBuf, WORD iSize ) { return mZip.SetExtraFieldEx( pBuf, iSize ); };