epoc32/include/zipfile.h
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
child 4 837f303aceeb
equal deleted inserted replaced
1:666f914201fb 2:2fe1408b6811
     1 zipfile.h
     1 // Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // $Revision: 1.1 $
       
    15 // 
       
    16 //
       
    17 
       
    18 #ifndef _ZIP_FILE_H_
       
    19 #define _ZIP_FILE_H_
       
    20 
       
    21 #include <e32std.h>
       
    22 #include <s32file.h>
       
    23 #include <charconv.h>
       
    24 
       
    25 #include "localtypes.h"
       
    26 #include "ziparchive.h"
       
    27 #include "zipfilememberinputstream.h"
       
    28 #include <zipfilememberiterator.h>
       
    29 #include <zipfilemember.h>
       
    30 
       
    31 // Forward Class Declaration(s)
       
    32 
       
    33 class CFileInputStream;
       
    34 class CZipFileMemberIterator;
       
    35 class CZipFileMember;
       
    36 namespace ContentAccess
       
    37 	{
       
    38 	class CData;
       
    39 	}
       
    40 
       
    41 // End of Forward Class Declaration(s)
       
    42 
       
    43 
       
    44 /** 
       
    45 A CZipFile represents a ZIP archive contained in a single file. 
       
    46 Multi file zip archives are not supported.
       
    47 
       
    48 @publishedAll
       
    49 @released
       
    50 */
       
    51 class CZipFile : public CZipArchive
       
    52 	{
       
    53 	friend class RZipFileMemberReaderStream;
       
    54 	friend class CZipFileMemberIterator;
       
    55 
       
    56 	public:
       
    57 		/**	ZipFile error enumeration.
       
    58 		*/
       
    59 		enum
       
    60 			{
       
    61 			/** Cannot read file directory in the archive file*/
       
    62 			KZipFileError 		= KZipArchiveMinError - 1,
       
    63 			
       
    64 			/** File not found error. It is not used in current implemenation*/
       
    65 			KZipFileNotFound	= KZipFileError - 1,
       
    66 			
       
    67 			/** File IO error.Any error occurs during a archive file is readed. 
       
    68 			For examples, any error about reading number of disk,
       
    69 			an offset of signature, or the content of file is non-readable.
       
    70 			*/
       
    71 			KZipFileIOError 	= KZipFileError - 2
       
    72 			};
       
    73 
       
    74 	public:
       
    75 		IMPORT_C static CZipFile* NewL(RFs& aFs, RFile& aFile);	
       
    76 		IMPORT_C static CZipFile* NewL(RFs& aFs, const TDesC& aFileName);
       
    77 		IMPORT_C CZipFile(RFs& aFs, const TDesC& aFileName);
       
    78 		IMPORT_C TInt OpenL(void);
       
    79 		IMPORT_C void Close(void);
       
    80 		IMPORT_C virtual ~CZipFile();
       
    81 
       
    82 	protected:
       
    83 		IMPORT_C void ConstructL(const TDesC& aFileName);
       
    84 		
       
    85 		IMPORT_C void ConstructL(RFile& aFile);
       
    86 
       
    87 	public:
       
    88 		IMPORT_C TInt Size(TInt& aSize) const;
       
    89     
       
    90 		IMPORT_C CZipFileMember* MemberL(const TDesC& aName);
       
    91 		IMPORT_C CZipFileMember* CaseInsensitiveMemberL(const TDesC& aName);
       
    92 		IMPORT_C CZipFileMember* CaseSensitiveOrCaseInsensitiveMemberL(const TDesC& aName);
       
    93 		IMPORT_C TInt GetInputStreamL(const CZipFileMember* aMember, RZipFileMemberReaderStream*& aStream);
       
    94 
       
    95   		IMPORT_C CZipFileMemberIterator* GetMembersL(void);
       
    96 	
       
    97     
       
    98 protected:
       
    99 
       
   100 	/** 
       
   101 	Internal representation of a compressed file in a zipfile
       
   102 	@publishedAll
       
   103 	@released
       
   104 	*/
       
   105 	struct TMemberPointer
       
   106 		{
       
   107 		/** the name of a compressed file*/
       
   108 		TFileName*  iName;
       
   109 		
       
   110 		/** Not used in current implementation*/
       
   111 		TUint32		iCentralHeaderOffset;
       
   112 		
       
   113 		/** The local offset of header in a compressed file*/
       
   114 		TUint32	iLocalHeaderOffset;
       
   115 		
       
   116 		/** CRC with 32 bits length in a compressed file*/
       
   117 		TUint32 iCRC32;
       
   118 		
       
   119 		/** The size of compressed file */	
       
   120 		TUint32	iCompressedSize;
       
   121 		
       
   122 		/** The size of file without compressed*/
       
   123 		TUint32	iUncompressedSize;
       
   124 		};
       
   125 		
       
   126 protected:
       
   127 	TInt FindCentralDirectoryTrailer(TUint32& offset);
       
   128     TInt ReadCentralDirectoryTrailer(TUint32 offset, TCentralDirectoryTrailer&);
       
   129     TInt ReadCentralDirectoryHeaderL(TCentralDirectoryHeader&, TMemberPointer&,
       
   130     	CCnvCharacterSetConverter* aConverter, TInt aConverterState);
       
   131 
       
   132 	TInt ReadLocalHeader(TUint32, TLocalHeader&);
       
   133 	
       
   134 	const TMemberPointer* FindMemberPointer(const TDesC&, TBool);
       
   135 	
       
   136     TInt LoadMemberPointersL(void);
       
   137     
       
   138 	RZipFileMemberReaderStream*   MakeInputStreamL(TUint32, TUint32, TUint32, TUint32);
       
   139     CZipFileMember* MakeMemberL(TInt);
       
   140     CZipFileMember* MakeMemberL(const TMemberPointer&, const TLocalHeader&);
       
   141     
       
   142     // File I/O Support
       
   143     void OpenFileL(const TDesC& aFileName);
       
   144   
       
   145     TInt Read(TByte*, TUint32);
       
   146     TInt Read(TUint16&);
       
   147     TInt Read(TUint32&);
       
   148     
       
   149     TInt Seek(TInt);
       
   150 
       
   151 	// Misc
       
   152 	void DeleteMemberPointers(void);
       
   153 
       
   154 private:
       
   155     const TDesC&				iFileName;
       
   156     TUint32 iFileLength;
       
   157 	
       
   158 	/** The central directory of ZIP File Trailer*/
       
   159 	TCentralDirectoryTrailer iTrailer;
       
   160 	
       
   161 	/** The pointer to a a compressed file in a zipfile*/
       
   162 	TMemberPointer*	iMemberPointers;
       
   163 	
       
   164 	RFs& iFs;
       
   165 	
       
   166 	/** The pointer to CData object created from a zip file*/
       
   167 	ContentAccess::CData* iData;
       
   168 	};
       
   169 
       
   170 #endif /* !_ZIP_FILE_H_ */