secureswitools/swisistools/source/rscparser/barsc2.cpp
branchRCL_3
changeset 25 7333d7932ef7
equal deleted inserted replaced
24:5cc91383ab1e 25:7333d7932ef7
       
     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 * @file barsc2.cpp
       
    17 *
       
    18 * @internalComponent
       
    19 * @released
       
    20 */
       
    21 #include <iostream>
       
    22 #include <sstream>
       
    23 #include "barsc2.h"
       
    24 #include <string>
       
    25 
       
    26 CResourceFile::CResourceFile(const std::string& aName,TUint32 aFileOffset, TInt aFileSize)
       
    27 	{
       
    28 	// Creating the implementation instance with a placement new operator.
       
    29 	new (iImpl) RResourceFileImpl;
       
    30 	
       
    31 	// Open the resource file for reading.
       
    32 	Impl()->OpenL(aName, aFileOffset, aFileSize);
       
    33 	}
       
    34 
       
    35 
       
    36 CResourceFile::~CResourceFile()
       
    37 	{
       
    38 	RResourceFileImpl* impl = Impl();
       
    39 	impl->~RResourceFileImpl();
       
    40 	}
       
    41 
       
    42 
       
    43 Ptr8* CResourceFile::AllocReadL(const TInt& aResourceId)
       
    44 	{
       
    45 	return Impl()->AllocReadL(aResourceId);
       
    46 	}
       
    47 
       
    48 /** Initialises the offset value from the first resource.
       
    49 
       
    50 The function tests to catch cases where the first resource is not an RSS_SIGNATURE.
       
    51 It assumes that the first resource in the file consists of
       
    52 two 32-bit integers. The first integer contains the version number and
       
    53 the second is a self-referencing link whose value is the offset for
       
    54 the resources in the file, plus 1.This function must be called before
       
    55 calling Offset(), AllocReadL(), AllocReadLC() or ReadL().
       
    56 @leave The function leaves if this resource id is not in this
       
    57 resource file or the file is corrupted. */
       
    58 void CResourceFile::ConfirmSignatureL()
       
    59 	{
       
    60 	Impl()->ConfirmSignatureL();
       
    61 	}
       
    62 
       
    63 // Read Uid3 of Resource File
       
    64 TUid CResourceFile::ReadAppUidL()
       
    65 	{
       
    66 	// Unicode compressed RSC file will have 19 bytes header.
       
    67 	const TUint8 Read_Byte = 4;
       
    68 	TUint8 header[Read_Byte];
       
    69 	sTUid uid;
       
    70 		
       
    71 	// Read Uid3 of Resource File
       
    72 	Impl()->ReadL(8,header,Read_Byte);
       
    73 	// Get the Third UID
       
    74 	memcpy((TUint8*)&uid.iUid1,header,Read_Byte);
       
    75 
       
    76 	TUid iUid = {uid.iUid1};
       
    77 	return iUid;
       
    78 	}
       
    79 
       
    80 // Read Uid2 of Resource File
       
    81 TUid CResourceFile::ReadFileUidL()
       
    82 	{
       
    83 	// Unicode compressed RSC file will have 19 bytes header.
       
    84 	const TUint8 Read_Byte = 4;
       
    85 	TUint8 header[Read_Byte];
       
    86 	sTUid uid;
       
    87 		
       
    88 	// Read Uid3 of Resource File
       
    89 	Impl()->ReadL(4,header,Read_Byte);
       
    90 	// Get the Third UID
       
    91 	memcpy((TUint8*)&uid.iUid1,header,Read_Byte);
       
    92 
       
    93 	TUid iUid = {uid.iUid1};
       
    94 	return iUid;
       
    95 	}
       
    96 
       
    97 TBool CResourceFile::OwnsResourceId(const TInt& aResourceId) const
       
    98 	{
       
    99 	return Impl()->OwnsResourceId(aResourceId);
       
   100 	}
       
   101 
       
   102 
       
   103 RResourceFileImpl* CResourceFile::Impl()
       
   104 	{
       
   105 	return reinterpret_cast <RResourceFileImpl*> (iImpl);
       
   106 	}
       
   107 
       
   108 
       
   109 const RResourceFileImpl* CResourceFile::Impl() const
       
   110 	{
       
   111 	return reinterpret_cast <const RResourceFileImpl*> (iImpl);
       
   112 	}
       
   113 
       
   114 
       
   115 void CResourceFileException::Display() const 
       
   116 	{
       
   117 	std::ostringstream errDispStream;
       
   118 	errDispStream<<iValue;
       
   119 	errDispStream<<std::endl;
       
   120 
       
   121 // Note: Remove the following tow sentences after integrating with Interpretsis.	
       
   122 	std::string str = errDispStream.str();
       
   123 	std::cout<<str;
       
   124 
       
   125 //  Note: Put this when integrating with InterpretSis
       
   126 //	std::wstring finalMessage = Utf8ToUcs2( errDispStream.str() );
       
   127 //  LERROR( finalMessage );
       
   128 	}
       
   129 
       
   130 	/**
       
   131 	Get the exception message
       
   132 	*/
       
   133 std::string CResourceFileException::GetMsg()
       
   134 	{
       
   135 		return iValue;
       
   136 	}
       
   137