pushmtm/Plugins/PushContentHandler/StringResourceReader.cpp
changeset 51 48e827313edd
parent 37 481242ead638
child 53 f427d27b98d8
equal deleted inserted replaced
37:481242ead638 51:48e827313edd
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "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 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *     Implementation of CStringResourceReader
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 
       
    23 #include "StringResourceReader.h"
       
    24 #include <f32file.h>
       
    25 #include <barsread.h>
       
    26 #include <bautils.h>
       
    27 
       
    28 // ================= MEMBER FUNCTIONS =======================
       
    29 
       
    30 // ---------------------------------------------------------
       
    31 // CStringResourceReader::CStringResourceReader
       
    32 // ---------------------------------------------------------
       
    33 //
       
    34 CStringResourceReader::CStringResourceReader
       
    35     ( RFs& aFs, const TDesC& aRscFileWithPathAndDrive )
       
    36 :   CBase(), iFs( aFs ), iInitialized( EFalse )
       
    37     {
       
    38     iRscFileName.Copy( aRscFileWithPathAndDrive );
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------
       
    42 // CStringResourceReader::~CStringResourceReader
       
    43 // ---------------------------------------------------------
       
    44 //
       
    45 CStringResourceReader::~CStringResourceReader()
       
    46     {
       
    47     iResourceFile.Close();
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------
       
    51 // CStringResourceReader::AllocReadResourceL
       
    52 // ---------------------------------------------------------
       
    53 //
       
    54 HBufC* CStringResourceReader::AllocReadResourceL( TInt aResId )
       
    55     {
       
    56     InitializeL();
       
    57     //
       
    58     HBufC8* buf8 = iResourceFile.AllocReadLC( aResId );
       
    59 #ifdef _UNICODE
       
    60     const TPtrC buf( (const TUint16*)buf8->Ptr(), buf8->Size()/2 );
       
    61 #else
       
    62     const TPtrC buf( buf8->Ptr(), buf8->Size() );
       
    63 #endif
       
    64     HBufC* retBuf = buf.AllocL();
       
    65     CleanupStack::PopAndDestroy( buf8 );
       
    66 
       
    67     return retBuf;
       
    68     }
       
    69 
       
    70 // ---------------------------------------------------------
       
    71 // CStringResourceReader::AllocReadResourceLC
       
    72 // ---------------------------------------------------------
       
    73 //
       
    74 HBufC* CStringResourceReader::AllocReadResourceLC( TInt aResId )
       
    75     {
       
    76     HBufC* temp = AllocReadResourceL( aResId );
       
    77     CleanupStack::PushL( temp );
       
    78     return temp;
       
    79     }
       
    80 
       
    81 // ---------------------------------------------------------
       
    82 // CStringResourceReader::InitializeL
       
    83 // ---------------------------------------------------------
       
    84 //
       
    85 void CStringResourceReader::InitializeL()
       
    86     {
       
    87     if ( !iInitialized )
       
    88         {
       
    89         TFileName resourceFileName( iRscFileName );
       
    90         BaflUtils::NearestLanguageFile( iFs, resourceFileName );
       
    91         iResourceFile.OpenL( iFs, resourceFileName );
       
    92         iResourceFile.ConfirmSignatureL( iResourceFile.SignatureL() );
       
    93         iInitialized = ETrue;
       
    94         }
       
    95     }
       
    96 
       
    97 // End of file.