commonservices/PlatformEnv/src/PathInfo.cpp
changeset 0 4e1aa6a622a0
equal deleted inserted replaced
-1:000000000000 0:4e1aa6a622a0
       
     1 /*
       
     2 * Copyright (c) 2002-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:  Holds information of system paths.
       
    15 *                These utility methods should be used instead of hard coded.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include    "pathinfo.h"
       
    23 #include    "pathconfiguration.hrh"
       
    24 #include    <e32std.h>
       
    25 #include    <f32file.h>
       
    26 #include    <badesca.h>
       
    27 #include    "platformenvdebug.h"
       
    28 
       
    29 // MACROS
       
    30 
       
    31 // needed because _LIT macro does not expand parameter, which is also macro
       
    32 #define _CREATE_LIT(a,b) _LIT(a,b)
       
    33 
       
    34 #define ARRAY_LEN( a ) ( sizeof( a ) / sizeof( a[ 0 ] ) )
       
    35 
       
    36 // CONSTANTS
       
    37 
       
    38 _CREATE_LIT( KRomRootPath,              text_rom_root_path );
       
    39 _CREATE_LIT( KPhoneMemoryRootPath,      text_phone_memory_root_path );
       
    40 _CREATE_LIT( KMemoryCardRootPath,       text_memory_card_root_path );
       
    41 
       
    42 _CREATE_LIT( KGamesPath,                text_games_path );
       
    43 _CREATE_LIT( KInstallsPath,             text_installs_path );
       
    44 _CREATE_LIT( KOthersPath,               text_others_path );
       
    45 _CREATE_LIT( KVideosPath,               text_videos_path );
       
    46 _CREATE_LIT( KImagesPath,               text_images_path );
       
    47 _CREATE_LIT( KImagesThumbnailPath,      text_images_thumbnail_path );
       
    48 _CREATE_LIT( KPicturesPath,             text_pictures_path );
       
    49 _CREATE_LIT( KGmsPicturesPath,          text_gms_pictures_path );
       
    50 _CREATE_LIT( KMmsBackgroundImagesPath,  text_mms_background_images_path );
       
    51 _CREATE_LIT( KPresenceLogosPath,        text_presence_logos_path );
       
    52 _CREATE_LIT( KSoundsPath,               text_sounds_path );
       
    53 _CREATE_LIT( KDigitalSoundsPath,        text_digital_sounds_path );
       
    54 _CREATE_LIT( KSimpleSoundsPath,         text_simple_sounds_path );
       
    55 _CREATE_LIT( KMemoryCardContactsPath,   text_memory_card_contacts_path );
       
    56 
       
    57 _LIT( KPanicCategory, "PATHINFO" );
       
    58 
       
    59 _LIT( KDriveLetterMatch, "?:\\*" );
       
    60 _LIT( KDriveDefaultPath, ":\\" );
       
    61 const TInt KDriveNameLen = 3; // Length of drive letter, colon and backslash
       
    62 
       
    63 // Path property bit mask definitions
       
    64 enum TPathInfoProperty
       
    65     {
       
    66     EPathInfoPropNone = 0x0, // No special handling is required
       
    67     EPathInfoPropAppendDenied = 0x1, // Append to root path is denied
       
    68     EPathInfoPropDriveSpecific = 0x2, // Path is strictly drive specific
       
    69     EPathInfoPropUnavailableForPhoneMem = 0x4 // Path is unavailable for default phone memory
       
    70     };
       
    71 
       
    72 // Path property definitions that must exist for each path
       
    73 const TUint KPathProperties[] =
       
    74     {
       
    75     EPathInfoPropDriveSpecific,  // PathInfo::ERomRootPath, 0
       
    76     EPathInfoPropDriveSpecific,  // PathInfo::EPhoneMemoryRootPath, 1
       
    77     EPathInfoPropDriveSpecific,  // PathInfo::EMemoryCardRootPath, 2
       
    78     EPathInfoPropNone,  // PathInfo::EGamesPath, 3
       
    79     EPathInfoPropNone,  // PathInfo::EInstallsPath, 4
       
    80     EPathInfoPropNone,  // PathInfo::EOthersPath, 5
       
    81     EPathInfoPropNone,  // PathInfo::EVideosPath, 6
       
    82     EPathInfoPropNone,  // PathInfo::EImagesPath, 7
       
    83     EPathInfoPropNone,  // PathInfo::EGsmPicturesPath, 8
       
    84     EPathInfoPropNone,  // PathInfo::EMmsBackgroundImagesPath, 9
       
    85     EPathInfoPropNone,  // PathInfo::EPresenceLogosPath, 10
       
    86     EPathInfoPropNone,  // PathInfo::ESoundsPath, 11
       
    87     EPathInfoPropNone,  // PathInfo::EDigitalSoundsPath, 12
       
    88     EPathInfoPropNone,  // PathInfo::ESimpleSoundsPath, 13
       
    89     EPathInfoPropAppendDenied, // PathInfo::EImagesThumbnailPath, 14
       
    90     EPathInfoPropUnavailableForPhoneMem // PathInfo::EMemoryCardContactsPath, 15
       
    91     };
       
    92 
       
    93 // DATA TYPES
       
    94 
       
    95 enum TPathInfoPanic
       
    96     {
       
    97     EInvalidParameter        = 0 // Invalid parameter.
       
    98     };
       
    99 
       
   100 // ============================= LOCAL FUNCTIONS ===============================
       
   101 // -----------------------------------------------------------------------------
       
   102 // ThumbnailPath
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 static TBool ThumbnailPath( const TDesC& aFullPath )
       
   106     {
       
   107     FUNC_LOG
       
   108 
       
   109     TInt len( KImagesThumbnailPath().Length() );
       
   110     if ( aFullPath.Length() >= len &&
       
   111         !aFullPath.Right( len ).CompareF( KImagesThumbnailPath ) )
       
   112         {
       
   113         return ETrue;
       
   114         }
       
   115     return EFalse;
       
   116     }
       
   117 
       
   118 // ============================ MEMBER FUNCTIONS ===============================
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 // PathInfo::RomRootPath
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 EXPORT_C const TDesC& PathInfo::RomRootPath()
       
   125     {
       
   126     return KRomRootPath;
       
   127     }
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // PathInfo::PhoneMemoryRootPath
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 EXPORT_C const TDesC& PathInfo::PhoneMemoryRootPath()
       
   134     {
       
   135     return KPhoneMemoryRootPath;
       
   136     }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // PathInfo::MemoryCardRootPath
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 EXPORT_C const TDesC& PathInfo::MemoryCardRootPath()
       
   143     {
       
   144     return KMemoryCardRootPath;
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // PathInfo::GamesPath
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 EXPORT_C const TDesC& PathInfo::GamesPath()
       
   152     {
       
   153     return KGamesPath;
       
   154     }
       
   155 
       
   156 // -----------------------------------------------------------------------------
       
   157 // PathInfo::InstallsPath
       
   158 // -----------------------------------------------------------------------------
       
   159 //
       
   160 EXPORT_C const TDesC& PathInfo::InstallsPath()
       
   161     {
       
   162     return KInstallsPath;
       
   163     }
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 // PathInfo::OthersPath
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 EXPORT_C const TDesC& PathInfo::OthersPath()
       
   170     {
       
   171     return KOthersPath;
       
   172     }
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // PathInfo::VideosPath
       
   176 // -----------------------------------------------------------------------------
       
   177 //
       
   178 EXPORT_C const TDesC& PathInfo::VideosPath()
       
   179     {
       
   180     return KVideosPath;
       
   181     }
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // PathInfo::ImagesPath
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 EXPORT_C const TDesC& PathInfo::ImagesPath()
       
   188     {
       
   189     return KImagesPath;
       
   190     }
       
   191 
       
   192 // -----------------------------------------------------------------------------
       
   193 // PathInfo::ImagesThumbnailPath
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 EXPORT_C const TDesC& PathInfo::ImagesThumbnailPath()
       
   197     {
       
   198     return KImagesThumbnailPath;
       
   199     }
       
   200 
       
   201 // -----------------------------------------------------------------------------
       
   202 // PathInfo::PicturesPath
       
   203 // -----------------------------------------------------------------------------
       
   204 //
       
   205 EXPORT_C const TDesC& PathInfo::PicturesPath()
       
   206     {
       
   207     return KPicturesPath;
       
   208     }
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // PathInfo::GmsPicturesPath
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 EXPORT_C const TDesC& PathInfo::GmsPicturesPath()
       
   215     {
       
   216     return KGmsPicturesPath;
       
   217     }
       
   218 
       
   219 // -----------------------------------------------------------------------------
       
   220 // PathInfo::MmsBackgroundImagesPath
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 EXPORT_C const TDesC& PathInfo::MmsBackgroundImagesPath()
       
   224     {
       
   225     return KMmsBackgroundImagesPath;
       
   226     }
       
   227 
       
   228 // -----------------------------------------------------------------------------
       
   229 // PathInfo::PresenceLogosPath
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 EXPORT_C const TDesC& PathInfo::PresenceLogosPath()
       
   233     {
       
   234     return KPresenceLogosPath;
       
   235     }
       
   236 
       
   237 // -----------------------------------------------------------------------------
       
   238 // PathInfo::SoundsPath
       
   239 // -----------------------------------------------------------------------------
       
   240 //
       
   241 EXPORT_C const TDesC& PathInfo::SoundsPath()
       
   242     {
       
   243     return KSoundsPath;
       
   244     }
       
   245 
       
   246 // -----------------------------------------------------------------------------
       
   247 // PathInfo::DigitalSoundsPath
       
   248 // -----------------------------------------------------------------------------
       
   249 //
       
   250 EXPORT_C const TDesC& PathInfo::DigitalSoundsPath()
       
   251     {
       
   252     return KDigitalSoundsPath;
       
   253     }
       
   254 
       
   255 // -----------------------------------------------------------------------------
       
   256 // PathInfo::SimpleSoundsPath
       
   257 // -----------------------------------------------------------------------------
       
   258 //
       
   259 EXPORT_C const TDesC& PathInfo::SimpleSoundsPath()
       
   260     {
       
   261     return KSimpleSoundsPath;
       
   262     }
       
   263 
       
   264 // -----------------------------------------------------------------------------
       
   265 // PathInfo::MemoryCardContactsPath
       
   266 // -----------------------------------------------------------------------------
       
   267 //
       
   268 EXPORT_C const TDesC& PathInfo::MemoryCardContactsPath()
       
   269     {
       
   270     return KMemoryCardContactsPath;
       
   271     }
       
   272 
       
   273 // -----------------------------------------------------------------------------
       
   274 // PathInfo::GetPath
       
   275 // -----------------------------------------------------------------------------
       
   276 //
       
   277 EXPORT_C const TDesC& PathInfo::GetPath( TInt aPath )
       
   278     {
       
   279     FUNC_LOG_WITH_CLIENT_NAME
       
   280 
       
   281     switch( aPath )
       
   282         {
       
   283         case PathInfo::ERomRootPath:
       
   284             return KRomRootPath;
       
   285 
       
   286         case PathInfo::EPhoneMemoryRootPath:
       
   287             return KPhoneMemoryRootPath;
       
   288 
       
   289 	    case PathInfo::EMemoryCardRootPath: 
       
   290             return KMemoryCardRootPath;
       
   291 
       
   292         case PathInfo::EGamesPath:
       
   293             return KGamesPath;
       
   294 
       
   295         case PathInfo::EInstallsPath:
       
   296             return KInstallsPath;
       
   297             
       
   298         case PathInfo::EOthersPath:
       
   299             return KOthersPath;
       
   300 
       
   301         case PathInfo::EVideosPath:
       
   302             return KVideosPath;
       
   303 
       
   304         case PathInfo::EImagesPath:
       
   305             return KImagesPath;
       
   306 
       
   307         case PathInfo::EGsmPicturesPath:
       
   308             return KGmsPicturesPath;
       
   309 
       
   310         case PathInfo::EMmsBackgroundImagesPath:
       
   311             return KMmsBackgroundImagesPath;
       
   312 
       
   313         case PathInfo::EPresenceLogosPath:
       
   314             return KPresenceLogosPath;
       
   315 
       
   316         case PathInfo::ESoundsPath:   
       
   317             return KSoundsPath;
       
   318          
       
   319         case PathInfo::EDigitalSoundsPath:
       
   320             return KDigitalSoundsPath;
       
   321 
       
   322         case PathInfo::ESimpleSoundsPath:
       
   323             return KSimpleSoundsPath;
       
   324 
       
   325         case PathInfo::EImagesThumbnailPath:
       
   326             return KImagesThumbnailPath;
       
   327 
       
   328         case PathInfo::EMemoryCardContactsPath:  
       
   329             return KMemoryCardContactsPath; 
       
   330         
       
   331         default:
       
   332             User::Panic( KPanicCategory, EInvalidParameter );
       
   333             // To get rid of compilation warnings.
       
   334             return KNullDesC;
       
   335 
       
   336         }
       
   337     }
       
   338 
       
   339 // -----------------------------------------------------------------------------
       
   340 // PathInfo::GetRootPath
       
   341 // -----------------------------------------------------------------------------
       
   342 //
       
   343 EXPORT_C TInt PathInfo::GetRootPath( TDes& aRootPath, TInt aDrive )
       
   344     {
       
   345     FUNC_LOG_WITH_CLIENT_NAME
       
   346 
       
   347     aRootPath.Zero();
       
   348     TChar ch( 0 );
       
   349     TInt ret( RFs::DriveToChar( aDrive, ch ) );
       
   350     if ( ret == KErrNone )
       
   351         {
       
   352         if ( ch == KRomRootPath()[ 0 ] )
       
   353             {
       
   354             aRootPath.Copy( KRomRootPath );
       
   355             }
       
   356         else if ( ch == KPhoneMemoryRootPath()[ 0 ] )
       
   357             {
       
   358             aRootPath.Copy( KPhoneMemoryRootPath );
       
   359             }
       
   360         else if ( ch == KMemoryCardRootPath()[ 0 ] )
       
   361             {
       
   362             aRootPath.Copy( KMemoryCardRootPath );
       
   363             }
       
   364         else
       
   365             {
       
   366             aRootPath.Append( ch );
       
   367             aRootPath.Append( KDriveDefaultPath );
       
   368             }
       
   369         }
       
   370 
       
   371     INFO_LOG2( "PathInfo::GetRootPath-aRootPath=%S,aDrive=%d",
       
   372         &aRootPath, aDrive )
       
   373 
       
   374     LOG_IF_ERROR2( ret, "PathInfo::GetRootPath-aDrive=%d,ret=%d",
       
   375         aDrive, ret )
       
   376 
       
   377     return ret;
       
   378     }
       
   379 
       
   380 // -----------------------------------------------------------------------------
       
   381 // PathInfo::GetFullPath
       
   382 // -----------------------------------------------------------------------------
       
   383 //
       
   384 EXPORT_C TInt PathInfo::GetFullPath( TDes& aFullPath, TInt aDrive, TInt aPath )
       
   385     {
       
   386     FUNC_LOG_WITH_CLIENT_NAME
       
   387 
       
   388     aFullPath.Zero();
       
   389 
       
   390     // Check if requested path is valid or not
       
   391     TInt count( ARRAY_LEN( KPathProperties ) );
       
   392     if ( aPath < 0 || aPath >= count )
       
   393         {
       
   394         ERROR_LOG3( "PathInfo::GetFullPath-aDrive=%d,aPath=%d,ret=%d",
       
   395             aDrive, aPath, KErrArgument )
       
   396 
       
   397         return KErrArgument; // Invalid path value
       
   398         }
       
   399 
       
   400     TUint pathProp( KPathProperties[ aPath ] );
       
   401 
       
   402     INFO_LOG2( "PathInfo::GetFullPath-aPath=%d,pathProp=0x%x",
       
   403         aPath, pathProp )
       
   404 
       
   405     if ( pathProp & EPathInfoPropAppendDenied )
       
   406         {
       
   407         return KErrNotFound; // Cannot append path to root path
       
   408         }
       
   409 
       
   410     TChar ch( 0 );
       
   411     TInt ret( RFs::DriveToChar( aDrive, ch ) );
       
   412     if ( ret != KErrNone )
       
   413         {
       
   414         ERROR_LOG3( "PathInfo::GetFullPath-aDrive=%d,aPath=%d,ret=%d",
       
   415             aDrive, aPath, ret )
       
   416 
       
   417         return ret; // No drive letter
       
   418         }
       
   419 
       
   420     if ( pathProp & EPathInfoPropUnavailableForPhoneMem )
       
   421         {
       
   422         if ( ch == KPhoneMemoryRootPath()[ 0 ] )
       
   423             {
       
   424             return KErrNotFound; // Drive is phone memory
       
   425             }
       
   426         }
       
   427 
       
   428     TPtrC path( GetPath( aPath ) );
       
   429     if ( !path.MatchF( KDriveLetterMatch ) )
       
   430         {
       
   431         if ( pathProp & EPathInfoPropDriveSpecific )
       
   432             {
       
   433             // The path is drive specific
       
   434             if ( ch == path[ 0 ] )
       
   435                 {
       
   436                 aFullPath.Copy( path );
       
   437                 }
       
   438             else
       
   439                 {
       
   440                 ret = KErrNotFound;
       
   441                 }
       
   442             }
       
   443         else
       
   444             {
       
   445             // Apply path to requested drive
       
   446             ret = GetRootPath( aFullPath, aDrive );
       
   447             if ( ret == KErrNone )
       
   448                 {
       
   449                 aFullPath.Append( path.Mid( KDriveNameLen ) );
       
   450                 }
       
   451             }
       
   452         }
       
   453     else
       
   454         {
       
   455         // Apply path to requested drive
       
   456         ret = GetRootPath( aFullPath, aDrive );
       
   457         if ( ret == KErrNone )
       
   458             {
       
   459             aFullPath.Append( path );
       
   460             }
       
   461         }
       
   462 
       
   463     INFO_LOG3( "PathInfo::GetFullPath-aFullPath=%S,aPath=%d,ret=%d",
       
   464         &aFullPath, aPath, ret )
       
   465 
       
   466 #ifdef PLATFORM_ENV_ERROR_LOG
       
   467     // Trace only unexpected errors, KErrNotFound is ok at this point
       
   468     if ( ret != KErrNone && ret != KErrNotFound )
       
   469         {
       
   470         ERROR_LOG3( "PathInfo::GetFullPath-aDrive=%d,aPath=%d,ret=%d",
       
   471             aDrive, aPath, ret )
       
   472         }
       
   473 #endif // PLATFORM_ENV_ERROR_LOG
       
   474 
       
   475     if ( ret != KErrNone )
       
   476         {
       
   477         aFullPath.Zero();
       
   478         }
       
   479 
       
   480     return ret;
       
   481     }
       
   482 
       
   483 // -----------------------------------------------------------------------------
       
   484 // PathInfo::PathType
       
   485 // -----------------------------------------------------------------------------
       
   486 //
       
   487 EXPORT_C TInt PathInfo::PathType( const TDesC& aFullPath )
       
   488     {
       
   489     FUNC_LOG_WITH_CLIENT_NAME
       
   490 
       
   491     if ( aFullPath.MatchF( KDriveLetterMatch ) )
       
   492         {
       
   493         INFO_LOG2( "PathInfo::PathType-aFullPath=%S,ret=%d",
       
   494             &aFullPath, ENotSystemPath )
       
   495 
       
   496         return ENotSystemPath;
       
   497         }
       
   498 
       
   499     // Thumbnail path needs different handling because
       
   500     // it is used differently compared to other paths
       
   501     if ( ThumbnailPath( aFullPath ) )
       
   502         {
       
   503         INFO_LOG2( "PathInfo::PathType-aFullPath=%S,ret=%d",
       
   504             &aFullPath, EImagesThumbnailPath )
       
   505 
       
   506         return EImagesThumbnailPath;
       
   507         }
       
   508 
       
   509     TInt drive( 0 );
       
   510     if ( RFs::CharToDrive( aFullPath[ 0 ], drive ) != KErrNone )
       
   511         {
       
   512         INFO_LOG2( "PathInfo::PathType-aFullPath=%S,ret=%d",
       
   513             &aFullPath, ENotSystemPath )
       
   514 
       
   515         return ENotSystemPath;
       
   516         }
       
   517 
       
   518     // Get the path count from the property array
       
   519     TInt count( ARRAY_LEN( KPathProperties ) );
       
   520 
       
   521     TFileName path;
       
   522     for( TInt i( 0 ); i < count; ++i )
       
   523         {
       
   524         if ( GetFullPath( path, drive, i ) == KErrNone )
       
   525             {
       
   526             if( !aFullPath.CompareF( path ) )
       
   527                 {
       
   528                 INFO_LOG2( "PathInfo::PathType-aFullPath=%S,ret=%d",
       
   529                     &aFullPath, i )
       
   530 
       
   531                 return i;
       
   532                 }
       
   533             }
       
   534         }
       
   535 
       
   536     INFO_LOG2( "PathInfo::PathType-aFullPath=%S,ret=%d",
       
   537         &aFullPath, ENotSystemPath )
       
   538 
       
   539     return ENotSystemPath;
       
   540     }
       
   541 
       
   542 // -----------------------------------------------------------------------------
       
   543 // PathInfo::GetListOfPathsLC
       
   544 // -----------------------------------------------------------------------------
       
   545 //
       
   546 EXPORT_C CDesCArray* PathInfo::GetListOfPathsLC( TInt aDrive )
       
   547     {
       
   548     CDesCArray* ret = NULL;
       
   549     FUNC_LOG_WITH_CLIENT_NAME_LC( ret )
       
   550 
       
   551     ret = GetListOfPathsL( aDrive );
       
   552     CleanupStack::PushL( ret );
       
   553     return ret;
       
   554     }
       
   555 
       
   556 // -----------------------------------------------------------------------------
       
   557 // PathInfo::GetListOfPathsL
       
   558 // -----------------------------------------------------------------------------
       
   559 //
       
   560 EXPORT_C CDesCArray* PathInfo::GetListOfPathsL( TInt aDrive )
       
   561     {
       
   562     FUNC_LOG_WITH_CLIENT_NAME
       
   563 
       
   564     // Get the path count from the property array
       
   565     TInt count( ARRAY_LEN( KPathProperties ) );
       
   566     CDesCArray* ret = new( ELeave ) CDesCArrayFlat( count );
       
   567     CleanupStack::PushL( ret );
       
   568     TFileName path;
       
   569     for ( TInt i( 0 ); i < count; ++i )
       
   570         {
       
   571         if ( GetFullPath( path, aDrive, i ) == KErrNone )
       
   572             {
       
   573             ret->AppendL( path );
       
   574             }
       
   575         }
       
   576     CleanupStack::Pop( ret );
       
   577     return ret;
       
   578     }
       
   579 
       
   580 //  End of File