supl/locationomasuplprotocolhandler/protocolhandlerver1/inc/epos_resourceutils.h
changeset 0 667063e416a2
equal deleted inserted replaced
-1:000000000000 0:667063e416a2
       
     1 /*
       
     2 * Copyright (c) 2009 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 "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: Resource utilities 
       
    15 *
       
    16 */
       
    17 
       
    18 // -----------------------------------------------------------------------------
       
    19 // -----------------------------------------------------------------------------
       
    20 //
       
    21 void FindResourceFileL( 
       
    22     RFs& aFsSession,
       
    23     const TDesC& aFilePathAndName,
       
    24     TFileName& aRscFile )
       
    25     {
       
    26     TParse parse;
       
    27     parse.Set( aFilePathAndName, NULL, NULL );
       
    28     
       
    29     TFindFile finder( aFsSession );
       
    30     if ( finder.FindByDir( parse.NameAndExt(), parse.Path() ) == KErrNone )
       
    31         {
       
    32         aRscFile.Copy( finder.File() );
       
    33         }
       
    34     else
       
    35         {
       
    36         User::Leave( KErrNotFound );
       
    37         }
       
    38     }
       
    39     
       
    40     
       
    41 // -----------------------------------------------------------------------------
       
    42 // COMASuplSession::ShowOfflineNoteL
       
    43 //  
       
    44 // -----------------------------------------------------------------------------
       
    45 void FindLocalizedResourceFileL( 
       
    46     RFs& aFsSession, 
       
    47     const TDesC& aRscFile,
       
    48     TFileName& aFileName )
       
    49     {
       
    50     TFileName fileName( aRscFile );
       
    51 
       
    52     TParse parse;
       
    53     parse.Set( aRscFile, NULL, NULL );
       
    54 
       
    55     // look on c: drives first
       
    56     BaflUtils::NearestLanguageFile( aFsSession, fileName );
       
    57     
       
    58     const TInt KLangPartOfExtensionLen = 2;
       
    59     
       
    60     TBool found = ( fileName.Right( KLangPartOfExtensionLen ) != 
       
    61                     aRscFile.Right( KLangPartOfExtensionLen ) );
       
    62     
       
    63     if ( !found )
       
    64         {
       
    65         // look on other drives
       
    66         TDriveList drives;
       
    67         aFsSession.DriveList( drives );
       
    68 
       
    69         for ( TInt drive = EDriveZ; drive >= EDriveA; drive-- )
       
    70             {
       
    71             if ( drive != EDriveC ) // already checked
       
    72                 {
       
    73                 TDriveInfo drvInfo;
       
    74                 aFsSession.Drive( drvInfo, drive );
       
    75                 
       
    76                 if ( drvInfo.iType != EMediaNotPresent )
       
    77                     {
       
    78                     TChar drv;
       
    79                     aFsSession.DriveToChar( drive, drv );
       
    80 
       
    81                     fileName.Zero();
       
    82                     fileName.Append( drv );
       
    83                     fileName.Append( KDriveDelimiter );
       
    84                     fileName.Append( parse.Path() );
       
    85                     fileName.Append( parse.NameAndExt() );
       
    86 
       
    87                     // look on c: and this drive
       
    88                     BaflUtils::NearestLanguageFile( aFsSession, fileName );
       
    89 
       
    90                     found = ( fileName.Right( KLangPartOfExtensionLen ) != 
       
    91                               aRscFile.Right( KLangPartOfExtensionLen ) );
       
    92                     if ( found ) break;
       
    93                     }
       
    94                 }
       
    95             }
       
    96         }
       
    97         
       
    98     if ( found )
       
    99         {
       
   100         aFileName.Copy( fileName );
       
   101         }
       
   102     else
       
   103         {
       
   104         // localized file not found, try using SC
       
   105         FindResourceFileL( aFsSession, aRscFile, aFileName );
       
   106         }
       
   107     }
       
   108 
       
   109 //////////////////////////////////////////////////////////////
       
   110 HBufC* LoadResourceTextL( 
       
   111     RFs& aFsSession, 
       
   112     const TDesC& aRscFile, 
       
   113     TInt aResourceId )
       
   114     {
       
   115  
       
   116     TFileName fileName;
       
   117     FindLocalizedResourceFileL( aFsSession, aRscFile, fileName );
       
   118 
       
   119     CResourceFile* resFile = CResourceFile::NewL( aFsSession, fileName, 0, 0 );
       
   120     CleanupStack::PushL( resFile );
       
   121     resFile->ConfirmSignatureL( 0 );
       
   122     
       
   123     RResourceReader reader;
       
   124     reader.OpenL( resFile, aResourceId );
       
   125     CleanupClosePushL( reader );
       
   126     
       
   127     HBufC* text = reader.ReadHBufC16L();
       
   128     
       
   129     CleanupStack::PopAndDestroy( &reader );
       
   130     CleanupStack::PopAndDestroy( resFile );
       
   131     return text;  
       
   132 
       
   133     }