secureswitools/swisistools/source/rscparser/barscimpl.h
changeset 25 98b66e4fb0be
child 33 8110bf1194d1
equal deleted inserted replaced
24:84a16765cd86 25:98b66e4fb0be
       
     1 // Copyright (c) 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 "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /** 
       
    17 * @file barscimpl.h
       
    18 *
       
    19 * @internalComponent
       
    20 * @released
       
    21 */
       
    22 
       
    23 #ifndef __BARSCIMPL_H__
       
    24 #define __BARSCIMPL_H__
       
    25 
       
    26 #include <string>
       
    27 #include "commontypes.h"
       
    28 
       
    29 /** 
       
    30 Accesses a resource file and reads the resource data into a buffer.
       
    31 It is the implementation class for CResourceFile class.
       
    32 */
       
    33 class RResourceFileImpl
       
    34 	{
       
    35 
       
    36 public:
       
    37 	RResourceFileImpl();
       
    38 	~RResourceFileImpl();
       
    39 	/** 
       
    40 	Opens the resource file reader.
       
    41 	The resource file reader must be opened before reading resources.
       
    42 	@param aName name of the RSC file.
       
    43 	@param aFileOffset RSC file offset 
       
    44 	@param aFileSize RSC file size
       
    45 	*/
       
    46 	void OpenL(const std::string& aName, TUint32 aFileOffset=0, TInt aFileSize=0);
       
    47 	/** 
       
    48 	Reads a resource after allocating heap memory for it.
       
    49 	Ownership of the allocated heap is passes to the caller who must 
       
    50 	free it.	
       
    51 	@param aResourceId The numeric id of the resource to be read.
       
    52 	@return Pointer to the heap containing the resource.
       
    53 	*/
       
    54 	Ptr8* AllocReadL(const TInt& aResourceId);
       
    55 
       
    56 	/** Initialises the offset value from the first resource.
       
    57 
       
    58 	The function tests to catch cases where the first resource is not an RSS_SIGNATURE.
       
    59 	It assumes that the first resource in the file consists of
       
    60 	two 32-bit integers. The first integer contains the version number and
       
    61 	the second is a self-referencing link whose value is the offset for
       
    62 	the resources in the file, plus 1.This function must be called before
       
    63 	calling Offset(), AllocReadL(), AllocReadLC() or ReadL().
       
    64 	*/
       
    65 	void ConfirmSignatureL();
       
    66 	
       
    67 	/** 
       
    68 	Tests whether the resource file owns the specified resource id.
       
    69 	@param aResourceId The resource id to test.
       
    70 	@return True, if the resource file owns the id, false otherwise.
       
    71 	*/
       
    72 	TBool OwnsResourceId(const TInt& aResourceId) const;
       
    73 
       
    74 	/** 
       
    75 	Function to read specified bytes from the RSC file
       
    76 	@param aPos Offset from where to begin reading
       
    77 	@param aData Buffer to store read values
       
    78 	@param aLength Length of the bytes to be read.
       
    79 	*/
       
    80 	void ReadL(TInt aPos,TUint8* aData,const TInt& aLength) ;
       
    81 
       
    82 
       
    83 private:
       
    84 	struct SSigRecord
       
    85 		{
       
    86 		TInt signature;
       
    87 		TInt offset;
       
    88 		};
       
    89   enum
       
    90 		{
       
    91 		EFlagIsRomFile																=0x80000000,
       
    92 		EFlagPotentiallyContainsCompressedUnicode									=0x40000000,
       
    93 		EFlagDictionaryCompressed													=0x20000000,
       
    94 		EFlagThirdUidIsOffset														=0x10000000,
       
    95 		EFlagGenerate_RSS_SIGNATURE_ForFirstUserResource							=0x08000000,
       
    96 		EFlagFirstResourceIsGeneratedBitArrayOfResourcesContainingCompressedUnicode	=0x04000000,
       
    97 		EFlagCalypsoFileFormat														=0x02000000,
       
    98 		EFlagIsBufferRscFile														=0x01000000,
       
    99 		EAllFlags																	=0xff000000
       
   100 		};
       
   101 	enum
       
   102 		{
       
   103 		EOffsetBits	=0xfffff000,
       
   104 		EIdBits		=0x00000fff
       
   105 		};
       
   106 
       
   107 	class TExtra;
       
   108 
       
   109 
       
   110 private:	
       
   111 	/** 
       
   112 	Function to read specified bytes from the RSC file
       
   113 	@param aFlags Integer conatainig no of resource and status flags.
       
   114 	@param aPos Offset from where to begin reading
       
   115 	@param aData Buffer to store read values
       
   116 	@param aLength Length of the bytes to be read.
       
   117 	*/
       
   118 	void ReadL(const TUint32& aFlags, TInt aPos, TUint8* aData, const TInt& aLength);
       
   119 
       
   120 	/** @internalComponent
       
   121 	@return The first resource record.
       
   122 	@panic Some BAFL panic codes, if the file is corrupted.
       
   123 	@leave KErrCorrupt The file is corrupted.
       
   124 	Some other error codes are possible too.
       
   125 	The method could panic or leave depending on the state of
       
   126 	iAssertObj member of RResourceFileImpl::TExtra class. */
       
   127 	SSigRecord FirstRecordL() const;
       
   128 
       
   129 	
       
   130 	/** 
       
   131 	Function to retrieve the header and 
       
   132 	resource index information of the RSC file.
       
   133 	*/
       
   134 	void ReadHeaderAndResourceIndexL();
       
   135 	
       
   136 	/** 
       
   137 	The method will decomress the unicode data (aCompressedUnicode argument) and append
       
   138 	the decompressed data to the end of aBuffer (aBuffer argument).
       
   139 
       
   140 	@param aBuffer Destination buffer.
       
   141 	@param aCompressedUnicode Pointer to compressed unicode data.
       
   142 	@param aLengthOfCompressedUnicode Length of compressed unicode data.
       
   143 	*/
       
   144 	void AppendDecompressedUnicodeL(
       
   145 								Ptr8* aBuffer,
       
   146 								const TUint8*  aCompressedUnicode,
       
   147 								const TInt& aLengthOfCompressedUnicode) const;
       
   148 	/** 
       
   149 	The method will decompress the unicode data (aInputResourceData argument), allocate enough
       
   150 	memory from the heap for the decompressed data, copy the data there and return a pointer
       
   151 	to the decompressed data.
       
   152 	The method doesn't own the allocated heap memory for the decompressed data. It's a caller
       
   153 	responsibility to deallocate the allocated memory.
       
   154 	@param aInputResourceData Compressed data.
       
   155 	@return Pointer to decompressed data 
       
   156 	*/
       
   157 	Ptr8* DecompressUnicodeL(const Ptr8* aInputResourceData) const;
       
   158 	
       
   159 	/**
       
   160 	Get the two bytes(in Little Endian format) from the specified buffer
       
   161 	@param aBuffer Buffer address from which 2-bytes are to be achieved.
       
   162 	@param aIndexOfFirstByte Offset of the first byte to be retrieved from the
       
   163            buffer.
       
   164 	@return 2-bytes read from the buffer.
       
   165 	*/
       
   166 	TInt LittleEndianTwoByteInteger(TUint8* aBuffer,const TInt& aIndexOfFirstByte) const;
       
   167 	Ptr8* GetDecompressedResourceDataL(
       
   168 									const TInt& aResourceIndex,			
       
   169 									const TUint32& aFlags);
       
   170 
       
   171 private:
       
   172 	std::ifstream* iResourceContents;	
       
   173 	TInt iSizeOfLargestResourceWhenCompletelyUncompressed;
       
   174 	// An array of (unsigned) 16-bit file-positions
       
   175 	TUint16* iIndex; 
       
   176 	TInt iOffset; 
       
   177 	TExtra* iExtra;
       
   178 	TUint32 iFlagsAndNumberOfResources;
       
   179 	};
       
   180 
       
   181 
       
   182 /** 
       
   183 Stores the RSC filesize, offset and the bit-array 
       
   184 representing resources containing compressed unicode.
       
   185 */
       
   186 class RResourceFileImpl::TExtra
       
   187 	{
       
   188 
       
   189 public:
       
   190 	TExtra();
       
   191 	~TExtra();
       
   192 	/**
       
   193 	Finds whether the specified resource contain compressed unicode
       
   194 	@param aRscIdx Resource Index
       
   195 	@return Status of whether the resource is actually present or not.
       
   196 	*/
       
   197 	TInt32 ContainsCompressedUnicode(const TInt& aRscIdx) const;
       
   198 
       
   199 private:
       
   200 	// Prevent default copy constructor
       
   201 	TExtra(const TExtra&);
       
   202 	// Prevent default "=" operator
       
   203 	TExtra& operator=(const TExtra&);
       
   204 
       
   205 public:
       
   206 	// RSC file UID
       
   207 	sTUid iUid;
       
   208 	// An array of bits, one for each resource in the resource file
       
   209 	TUint8* iBitArrayOfResourcesContainingCompressedUnicode; 
       
   210 	// Offset of RSC chunk
       
   211 	TInt iFileOffset;	
       
   212 	// RSC file size 
       
   213 	TUint32 iFileSize;		
       
   214 	};
       
   215 
       
   216 #endif//__BARSCIMPL_H__