appinstall_plat/appmngr2runtimeapi/src/appmngr2driveutils.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2008 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:   Utility functions for drive and file handling
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "appmngr2driveutils.h"         // TAppMngr2DriveUtils
       
    20 #include "appmngr2debugutils.h"         // FLOG macros
       
    21 #include <driveinfo.h>                  // DriveInfo
       
    22 #include <bautils.h>                    // BaflUtils
       
    23 #include <data_caging_path_literals.hrh> // KDC_* constant strings
       
    24 
       
    25 _LIT( KDriveFormat, "%c:" );
       
    26 
       
    27 
       
    28 // ======== MEMBER FUNCTIONS ========
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // TAppMngr2DriveUtils::LocationFromFileName()
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 EXPORT_C TAppMngr2Location TAppMngr2DriveUtils::LocationFromFileNameL(
       
    35         const TDesC& aFileName, RFs& aFs )
       
    36     {
       
    37     TParsePtrC fileNameParser( aFileName );
       
    38     const TChar driveLetter( fileNameParser.Drive()[ 0 ] );
       
    39     TInt driveNumber;
       
    40     User::LeaveIfError( aFs.CharToDrive( driveLetter, driveNumber ) );
       
    41     return LocationFromDriveL( driveNumber, aFs );
       
    42     }
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // TAppMngr2DriveUtils::LocationFromDrive()
       
    46 // ---------------------------------------------------------------------------
       
    47 //
       
    48 EXPORT_C TAppMngr2Location TAppMngr2DriveUtils::LocationFromDriveL(
       
    49         TInt aDrive, RFs& aFs )
       
    50     {
       
    51     TUint driveStatus = 0;
       
    52     User::LeaveIfError( DriveInfo::GetDriveStatus( aFs, aDrive, driveStatus ) );
       
    53     if( driveStatus & DriveInfo::EDriveRemovable )
       
    54         {
       
    55         return EAppMngr2LocationMemoryCard;
       
    56         }
       
    57     if( driveStatus & DriveInfo::EDriveExternallyMountable )
       
    58         {
       
    59         return EAppMngr2LocationMassStorage;
       
    60         }
       
    61     return EAppMngr2LocationPhone;
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------------------------
       
    65 // TAppMngr2DriveUtils::NearestResourceFileLC()
       
    66 // ---------------------------------------------------------------------------
       
    67 //
       
    68 EXPORT_C TFileName* TAppMngr2DriveUtils::NearestResourceFileLC(
       
    69         const TDesC& aFileName, RFs& aFs )
       
    70     {
       
    71     FLOG( "NearestResourceFileLC( %S )", &aFileName );
       
    72     
       
    73     TInt romDriveNumber = KErrNotFound;
       
    74     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, romDriveNumber );
       
    75     TChar romDriveLetter;
       
    76     User::LeaveIfError( aFs.DriveToChar( romDriveNumber, romDriveLetter ) );
       
    77 
       
    78     TFileName* fullName = new (ELeave) TFileName;
       
    79     CleanupStack::PushL( fullName );
       
    80 
       
    81     fullName->Format( KDriveFormat, static_cast<TUint>( romDriveLetter ) );
       
    82     fullName->Append( KDC_RESOURCE_FILES_DIR );
       
    83     fullName->Append( aFileName );
       
    84     
       
    85     BaflUtils::NearestLanguageFile( aFs, *fullName );
       
    86     FLOG( "NearestResourceFileLC, returns %S", fullName );
       
    87     return fullName;
       
    88     }
       
    89 
       
    90 // ---------------------------------------------------------------------------
       
    91 // TAppMngr2DriveUtils::FullBitmapFileNameLC()
       
    92 // ---------------------------------------------------------------------------
       
    93 //
       
    94 EXPORT_C HBufC* TAppMngr2DriveUtils::FullBitmapFileNameLC(
       
    95         const TDesC& aBitmapFile, RFs& aFs )
       
    96     {
       
    97     FLOG( "FullBitmapFileNameLC( %S )", &aBitmapFile );
       
    98     TInt romDriveNumber = KErrNotFound;
       
    99     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, romDriveNumber );
       
   100     TChar romDriveLetter;
       
   101     User::LeaveIfError( aFs.DriveToChar( romDriveNumber, romDriveLetter ) );
       
   102 
       
   103     HBufC* fullName = HBufC::NewLC( KMaxFileName );
       
   104     TPtr fullNameDes = fullName->Des();
       
   105 
       
   106     fullNameDes.Format( KDriveFormat, static_cast<TUint>( romDriveLetter ) );
       
   107     fullNameDes.Append( KDC_APP_BITMAP_DIR );
       
   108     fullNameDes.Append( aBitmapFile );
       
   109 
       
   110     FLOG( "FullBitmapFileNameLC, returns %S", fullName );
       
   111     return fullName;
       
   112     }
       
   113