commands/fzip/fzipup.h
changeset 0 7f656887cf89
equal deleted inserted replaced
-1:000000000000 0:7f656887cf89
       
     1 // fzipup.h
       
     2 // 
       
     3 // Copyright (c) 2008 - 2010 Accenture. All rights reserved.
       
     4 // This component and the accompanying materials are made available
       
     5 // under the terms of the "Eclipse Public License v1.0"
       
     6 // which accompanies this distribution, and is available
       
     7 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 // 
       
     9 // Initial Contributors:
       
    10 // Accenture - Initial contribution
       
    11 //
       
    12 
       
    13 #ifndef __FZIP_UP_H__
       
    14 #define __FZIP_UP_H__
       
    15 
       
    16 #include <zipfile.h>
       
    17 #include <ezbufman.h>
       
    18 #include <fshell/ioutils.h>
       
    19 
       
    20 using namespace IoUtils;
       
    21 
       
    22 const TUint32 KDefaultZipBufferLength = 0x8000; // 32 Kbytes
       
    23 
       
    24 //
       
    25 // class CBufferManager
       
    26 // manage the i/o buffers for compression, wrapper over the MEZBufferManager mix-in
       
    27 // takes input data from one file stream & writes the compressed output to another file stream
       
    28 //
       
    29 class CBufferManager : public CBase, public MEZBufferManager
       
    30 	{
       
    31 public:
       
    32 	static CBufferManager *NewLC(RFileReadStream& aInput, RFileWriteStream& aOutput, TInt aInputStreamBytes, TInt aBufferSize);
       
    33 	~CBufferManager();
       
    34 	inline TInt TotalBytesOut(){ return iBytesWritten; }
       
    35 	
       
    36 	// from MEzBufferManager
       
    37 	void InitializeL(CEZZStream &aZStream);
       
    38 	void NeedInputL(CEZZStream &aZStream);
       
    39 	void NeedOutputL(CEZZStream &aZStream);
       
    40 	void FinalizeL(CEZZStream &aZStream);
       
    41 private:
       
    42 	CBufferManager(RFileReadStream& aInput, RFileWriteStream& aOutput, TInt aInputStreamBytes, TInt aBufferSize);
       
    43 	void ConstructL();
       
    44 	void ReadInputL();
       
    45 	void WriteOutputL(CEZZStream& aZStream);
       
    46 private:
       
    47 	RFileReadStream& iInput;
       
    48 	RFileWriteStream& iOutput;
       
    49 	TInt iInputStreamBytes; // size of the input stream in bytes
       
    50 	TInt iReadLength;
       
    51 	TInt iBufferSize;
       
    52 	TInt iBytesWritten;
       
    53 	TUint8* iInputBuffer;
       
    54 	TUint8* iOutputBuffer;
       
    55 	TPtr8 iInputDescriptor;
       
    56 	TPtr8 iOutputDescriptor;
       
    57 	};
       
    58 
       
    59 //
       
    60 // class CZipEntry
       
    61 // defines attributes associated with a file contained within a zip archive
       
    62 // note these are taken from PKWARE'S APPNOTE.TXT zip-file format specification
       
    63 //
       
    64 class CZipItUp;
       
    65 class CZipEntry : public CZipArchive
       
    66 {
       
    67 public:
       
    68 	friend class CZipItUp;
       
    69 	static CZipEntry* NewLC(RFs& aFs, const TDesC& aFilename, const TInt aUid);
       
    70         virtual ~CZipEntry();
       
    71 
       
    72 	void SetOffset(TUint32 aOffset);
       
    73 	TUint32 ReturnOffset();
       
    74 	TUint32 FileHeaderSize();
       
    75 private:
       
    76 	CZipEntry(RFs& aFs, const TInt aUid);
       
    77 	void ConstructL(const TDesC& aFilename);
       
    78 	void CalcCRCL();
       
    79 private:
       
    80         static const TInt iOffset;
       
    81         TLocalHeader iLFH;					// Local File Header
       
    82         HBufC8* iFileData;					// File Data
       
    83         TCentralDirectoryHeader iFH;		// File Header
       
    84         RFs& iFs;							// f32 hook
       
    85         TBuf8<KMaxFileName>	iAsciiName;	// Ascii file name
       
    86         RFile iInput;						// input data from file
       
    87         const TInt iUid;					// uid id'ing this particular zip entry
       
    88         TSglQueLink iLink;
       
    89 	};
       
    90 	
       
    91 //
       
    92 // class CZipItUp
       
    93 // create a zip archive
       
    94 //
       
    95 typedef TSglQue<CZipEntry> CZipMemberLinkedList;
       
    96 typedef TSglQueIter<CZipEntry> CZipMemberLinkedListIter;
       
    97 	
       
    98 class CZipItUp : public CBase
       
    99 	{
       
   100 public:
       
   101 	static CZipItUp* NewLC(RFs& aFs, TDesC& aArchive);
       
   102 	virtual ~CZipItUp();
       
   103 	void AddFileL(const TDesC& aFile);
       
   104 	void CreateZipL();
       
   105 private:
       
   106 	CZipItUp(RFs& aFs, TDesC& aArchive);
       
   107 	void ConstructL();
       
   108 	void AddEntryL(CZipEntry& aEntry);
       
   109 	TBool DuplicateEntryL(const TDesC& aFile);
       
   110 	void AppendLocalFileHeaderL(RFileWriteStream& aStream, CZipEntry& aZipEntry);
       
   111 	void AppendCompressedDataL(RFileWriteStream& aStream, CZipEntry& aZipEntry);
       
   112 	void AppendCentralDirectoryFileHeaderL(RFileWriteStream& aStream, CZipEntry& aEntry);
       
   113 	void AppendCentralDirectoryTrailerL(RFileWriteStream& aStream);
       
   114 private:
       
   115 	RFs& iFs;
       
   116 	TDesC& iFileName;
       
   117 	RFile iFile;
       
   118 	CZipMemberLinkedList iZipMemberLinkedList;
       
   119 	CZipMemberLinkedListIter iZipMemberLinkedListIter;
       
   120 	TInt iEntryUid;
       
   121 
       
   122   struct TCdt 
       
   123 		{
       
   124         TUint32 iSignature;
       
   125 		TUint16 iDiskNumber;
       
   126 		TUint16 iStartDiskNumber;
       
   127 		TUint16 iLocalEntryCount;
       
   128 		TUint16 iTotalEntryCount;
       
   129 		TUint32 iSize;
       
   130 		TUint32 iOffset;
       
   131 		TUint16 iCommentLength;
       
   132 		};
       
   133 	TCdt iCDT;		// Central Directory Trailer
       
   134 	};
       
   135 
       
   136 #endif // __FZIP_UP_H__