devicediagnosticsfw/diagpluginbase/src/diagpluginbaseutils.cpp
branchRCL_3
changeset 26 19bba8228ff0
parent 0 b497e44ab2fc
equal deleted inserted replaced
25:b183ec05bd8c 26:19bba8228ff0
       
     1 /*
       
     2 * Copyright (c) 2007 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:  Collection of utility functions useful for plugins
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // SYSTEM INCLUDE FILES
       
    20 #include <bautils.h>                        // BaflUtils
       
    21 #include <ConeResLoader.h>                  // RConeResourceLoader
       
    22 #include <f32file.h>                        // RFs
       
    23 #include <data_caging_path_literals.hrh>    // KDC_RESOURCE_FILES_DIR
       
    24 #include <DiagFrameworkDebug.h>             // LOGSTRING
       
    25 
       
    26 // USER INCLUDE FILES
       
    27 #include "diagpluginbaseutils.h"        // CDiagPluginUtils
       
    28 
       
    29 // ======== LOCAL FUNCTIONS ========
       
    30 
       
    31 // ======== MEMBER FUNCTIONS ========
       
    32 
       
    33 // ---------------------------------------------------------------------------
       
    34 // DiagPluginBaseUtils::OpenResourceFileL()
       
    35 // ---------------------------------------------------------------------------
       
    36 //
       
    37 void DiagPluginBaseUtils::OpenResourceFileL(
       
    38         const TDesC& aResourceFileName,
       
    39         RConeResourceLoader& aResourceLoader,
       
    40         RFs& aFsSession )
       
    41     {
       
    42     // Find the resource file:
       
    43     TParse parse;
       
    44     parse.Set( aResourceFileName, &KDC_RESOURCE_FILES_DIR, NULL );
       
    45     TFileName fileName( parse.FullName() );
       
    46 
       
    47     // Get language of resource file:
       
    48     BaflUtils::NearestLanguageFile( aFsSession, fileName );
       
    49 
       
    50     LOGSTRING( "CDiagPluginBaseUtils::OpenLocalizedResourceFileL: FileName:" )
       
    51     LOGTEXT( fileName )
       
    52 
       
    53     // Open resource file:
       
    54     TRAPD( err, aResourceLoader.OpenL( fileName ) )
       
    55 
       
    56 #ifdef _DEBUG
       
    57     if ( err != KErrNone )
       
    58         {
       
    59         // if it is a debug build, and it fails to load the resource, try 
       
    60         // again with C: as base directory.
       
    61         // This allows installation of plug-ins as SIS file without changing
       
    62         // code in the plug-in itself.
       
    63         _LIT( KCDriveName, "c" );
       
    64         fileName.Replace( 0, 1, KCDriveName );
       
    65 
       
    66         LOGSTRING( "CDiagPluginBaseUtils::OpenLocalizedResourceFileL: Retry:" )
       
    67         LOGTEXT( fileName )
       
    68         TRAP( err, aResourceLoader.OpenL( fileName ) )
       
    69         }
       
    70 #endif // _DEBUG
       
    71 
       
    72     if ( err != KErrNone )
       
    73         {
       
    74         LOGSTRING2( "CDiagPluginBaseUtils::OpenLocalizedResourceFileL:"
       
    75             L" Failed err = %d", err )
       
    76         User::Leave( err );
       
    77         }
       
    78 
       
    79     LOGSTRING( "CDiagPluginBaseUtils::OpenLocalizedResourceFileL: Resource Opened" )
       
    80     }
       
    81 
       
    82 // End of File
       
    83