skins/AknSkins/srvsrc/AknsSrvUtils.cpp
changeset 0 05e9090e2422
child 54 08459e712984
child 64 ecb300a325e8
equal deleted inserted replaced
-1:000000000000 0:05e9090e2422
       
     1 /*
       
     2 * Copyright (c) 2003-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:  Skin server utils class.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <f32file.h>
       
    21 #include <bautils.h>
       
    22 
       
    23 #include <e32math.h>
       
    24 #include <DRMRights.h>
       
    25 
       
    26 #include <DRMHelper.h>
       
    27 #include <caf/caf.h>
       
    28 #include <caf/rightsinfo.h>
       
    29 
       
    30 #include "AknsSrvUtils.h"
       
    31 #include "AknsSrv.h"
       
    32 #include "AknsSrvDescriptorFileLayout.h"
       
    33 #include <AknsSkinUID.h>
       
    34 #include "AknsDriveMaster.h"
       
    35 
       
    36 
       
    37 #include "AknsDebug.h"
       
    38 
       
    39 #include <centralrepository.h>
       
    40 #include <AknSkinsInternalCRKeys.h>
       
    41 #include <AknsConstants.h>
       
    42 
       
    43 // Maximum lenght of uri.
       
    44 const TInt KMaxContentUriLength = 256;
       
    45 
       
    46 // Length of extension (including preceding dot).
       
    47 const TInt KExtensionLength = 4;
       
    48 
       
    49 // Mif-file extension
       
    50 _LIT( KAknsSkinSrvMifFileExt, ".mif" );
       
    51 
       
    52 const TInt KAknsDummySkinPkgID = 0x70000000;
       
    53 
       
    54 // ============================ MEMBER FUNCTIONS ===============================
       
    55 
       
    56 // -----------------------------------------------------------------------------
       
    57 // AknsSrvUtils::CheckAHOverrideFlag
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 TBool AknsSrvUtils::CheckAHOverrideFlagL( CAknsSrvFileBuffer& aFile )
       
    61     {
       
    62     TUint8 ahflag = GetUInt8L( aFile, EAknsSrvDFOSkinSkinType );
       
    63 
       
    64     if ( (ahflag&2) !=0 )
       
    65         {
       
    66         return ETrue;
       
    67         }
       
    68     else
       
    69         {
       
    70         return EFalse;
       
    71         }
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // AknsSrvUtils::SearchSkinsL
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 void AknsSrvUtils::SearchSkinsL(
       
    79     RFs& aRfs, const TDesC& aBasePath, const TDesC& aDirName,
       
    80     CDesCArray* aSkinFiles )
       
    81     {
       
    82     SearchSkinsL( aRfs, aBasePath, aDirName, KSKNPostFix, aSkinFiles );
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // AknsSrvUtils::SearchDirectoriesL
       
    87 // -----------------------------------------------------------------------------
       
    88 //
       
    89 void AknsSrvUtils::SearchDirectoriesL(
       
    90     RFs& aRFs, const TDesC& aPath, CDesCArray* aSkinFiles )
       
    91     {
       
    92     SearchDirectoriesL( aRFs, aPath, KSKNPostFix, aSkinFiles );
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // AknsSrvUtils::GetSkinPIDL
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 TAknsPkgID AknsSrvUtils::GetSkinPIDL(CAknsSrvFileBuffer& aFile)
       
   100     {
       
   101     TInt number = GetInt32L( aFile, EAknsSrvDFOSkinSkinPID1 );
       
   102     TInt timestamp = GetInt32L( aFile, EAknsSrvDFOSkinSkinPID2 );
       
   103 
       
   104     TAknsPkgID pid;
       
   105     pid.Set( timestamp, number );
       
   106     return pid;
       
   107     }
       
   108 
       
   109 // -----------------------------------------------------------------------------
       
   110 // AknsSrvUtils::BuildSkinInfoPackagesL
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 void AknsSrvUtils::BuildSkinInfoPackagesL(
       
   114     CArrayPtr<TAknsSrvSkinInfoPkg>* aSkinInfo, CDesCArray* aSkinArray,
       
   115     RFs& aFileSession, CDRMHelper& aDrmHelper )
       
   116     {
       
   117     AKNS_TRACE_INFO("AknsSrvUtils::BuildSkinInfoPackagesL BEGIN" );
       
   118     TAknsSrvSkinInfoPkg* infopkg = NULL;
       
   119 
       
   120     // Read default skin PID.
       
   121     CRepository* repository = CRepository::NewLC( KCRUidPersonalisation );
       
   122     TInt value = 0;
       
   123     TBuf<32> buf;
       
   124     TAknsPkgID defaultSkin = KAknsNullPkgID;
       
   125 
       
   126     TInt err = repository->Get( KPslnDefaultSkinUID, buf );
       
   127     if ( err != KErrNone || buf.Length() < 8 )
       
   128         {
       
   129         err = repository->Get( KPslnDefaultSkinID, value );
       
   130         if( err == KErrNone )
       
   131             {
       
   132             defaultSkin.Set( TUid::Uid( value ) );
       
   133             }
       
   134         }
       
   135     else
       
   136         {
       
   137         TInt bufLength = buf.Length();
       
   138         // If its 8 characters long, its UID.
       
   139         // PIDs are 16 characters (8 ID + 8 timestamp)
       
   140         if ( bufLength == 8 )
       
   141             {
       
   142             // Let's try to set it directly as Hex.
       
   143             TLex hexLex( buf );
       
   144             TUint pid;
       
   145             err = hexLex.Val( pid, EHex );
       
   146             if (!err)
       
   147                 {
       
   148                 // UIDs have no timestamp.
       
   149                 defaultSkin.Set( 0, pid );
       
   150                 }
       
   151             }
       
   152         else
       
   153             {
       
   154             // The skin PID is set in CenRep in format <PID1><PID2> and
       
   155             // values are in hex.
       
   156             TLex lex ( buf.Left( 8 ) );
       
   157             TLex lex2 ( buf.Right( 8 ) );
       
   158             TUint pid;
       
   159             TUint timeStamp;
       
   160             err = lex.Val( pid, EHex );
       
   161             if ( !err )
       
   162                 {
       
   163                 err = lex2.Val( timeStamp, EHex );
       
   164                 }
       
   165             if ( !err )
       
   166                 {
       
   167                 defaultSkin.Set( timeStamp, pid );
       
   168                 }
       
   169             }        
       
   170         }
       
   171     CleanupStack::PopAndDestroy( repository );  
       
   172 
       
   173     for( TInt skincount=0; skincount<aSkinArray->Count(); skincount++ )
       
   174         {
       
   175         TRAPD( err2, (infopkg=BuildSkinInfoPackageL(
       
   176             aSkinArray->MdcaPoint(skincount), aDrmHelper, aFileSession ) ) );
       
   177         TBool fabricated = EFalse;
       
   178 
       
   179         if( err2 != KErrNone )
       
   180             {
       
   181             // Fabricate skin information, since the array must contain
       
   182             // items for broken skins as well (to ensure that they can
       
   183             // be deleted).
       
   184             TInt index = aSkinArray->MdcaPoint(skincount).LocateReverse('\\');
       
   185             TPtrC filedir;
       
   186             filedir.Set( aSkinArray->MdcaPoint(skincount).Left(index) );
       
   187             TPtrC filename;
       
   188             filename.Set( aSkinArray->MdcaPoint(skincount).Mid(index+1) );
       
   189 
       
   190             infopkg = new (ELeave) TAknsSrvSkinInfoPkg;
       
   191             infopkg->iPID = KAknsNullPkgID;
       
   192             infopkg->iColorSchemePID = KAknsPIDColorBlue;
       
   193             infopkg->iSkinDirectoryBuf = filedir;
       
   194             infopkg->iSkinIniFileDirectoryBuf = filedir;
       
   195             infopkg->iSkinNameBuf = filename;
       
   196             infopkg->iIdleStateWallPaperImageName = KNullDesC;
       
   197             infopkg->iFullName = KNullDesC;
       
   198             infopkg->iIsCopyable = EFalse;
       
   199             infopkg->iIsDeletable = ETrue;
       
   200             infopkg->iIdleBgImageIndex = 0;
       
   201             infopkg->iProtectionType = EAknsSrvNoProtection;
       
   202             infopkg->iCorrupted = ETrue;
       
   203             fabricated = ETrue;
       
   204             }
       
   205         CleanupStack::PushL( infopkg );
       
   206 
       
   207         TBool mifFile = EFalse;
       
   208         TBool alreadyFound = EFalse;
       
   209 
       
   210         if( infopkg )
       
   211             {
       
   212             if ( infopkg->iFullName.Length() > 0 )
       
   213                 {
       
   214                 SkinHasMifFileL( mifFile, aFileSession, infopkg->iFullName );
       
   215                 }
       
   216 
       
   217             // If no mif-file, assume that skin is corrupted.
       
   218             if ( !mifFile )
       
   219                 {
       
   220                 infopkg->iCorrupted = ETrue;
       
   221                 }
       
   222 
       
   223             for( TInt i=0; i<aSkinInfo->Count(); i++ )
       
   224                 {
       
   225                 if( aSkinInfo->At(i)->iPID == infopkg->iPID )
       
   226                     {
       
   227                     alreadyFound = ETrue;
       
   228                     break;
       
   229                     }
       
   230                 }
       
   231             }
       
   232 
       
   233         if( infopkg && ((!alreadyFound) || fabricated) )
       
   234             {
       
   235             // Add all but default skin.
       
   236             if ( infopkg->iPID != KAknsPIDS60DefaultSkin )
       
   237                 {
       
   238                 aSkinInfo->AppendL(infopkg);
       
   239                 CleanupStack::Pop( infopkg );
       
   240                 }
       
   241             // If default skin ID has not been changed, show S60 default skin.
       
   242             else if ( defaultSkin == KAknsNullPkgID &&
       
   243                       infopkg->iPID == KAknsPIDS60DefaultSkin )
       
   244                 {
       
   245                 aSkinInfo->AppendL(infopkg);
       
   246                 CleanupStack::Pop( infopkg );
       
   247                 }
       
   248             else
       
   249                 {
       
   250                 CleanupStack::PopAndDestroy(); //infopkg
       
   251                 }
       
   252             }
       
   253         else
       
   254             {
       
   255             CleanupStack::PopAndDestroy(); // infopkg
       
   256             }
       
   257         }
       
   258     AKNS_TRACE_INFO("AknsSrvUtils::BuildSkinInfoPackagesL END" );
       
   259     }
       
   260 
       
   261 // -----------------------------------------------------------------------------
       
   262 // AknsSrvUtils::IsDrmProtectedL
       
   263 // -----------------------------------------------------------------------------
       
   264 //
       
   265 TBool AknsSrvUtils::IsDrmProtectedL(const TDesC& aFilename)
       
   266     {
       
   267     TBool isProtected(EFalse);
       
   268     TInt value = KErrNone;
       
   269 
       
   270     CContent* content = CContent::NewLC( aFilename );
       
   271     User::LeaveIfError( content->GetAttribute( EIsProtected, value ) );
       
   272     if ( value )
       
   273         {
       
   274         isProtected = ETrue;
       
   275         }
       
   276     CleanupStack::PopAndDestroy( content );
       
   277     return isProtected;
       
   278     }
       
   279 
       
   280 // -----------------------------------------------------------------------------
       
   281 // AknsSrvUtils::IsDrmProtectedL
       
   282 // -----------------------------------------------------------------------------
       
   283 //
       
   284 TBool AknsSrvUtils::IsDrmProtectedL(RFile& aFileHandle)
       
   285     {
       
   286     TBool isProtected(EFalse);
       
   287     TInt value = KErrNone;
       
   288 
       
   289     CContent* content = CContent::NewLC( aFileHandle );
       
   290     User::LeaveIfError( content->GetAttribute( EIsProtected, value ) );
       
   291     if ( value )
       
   292         {
       
   293         isProtected = ETrue;
       
   294         }
       
   295     CleanupStack::PopAndDestroy( content );
       
   296     return isProtected;
       
   297     }
       
   298 
       
   299 // -----------------------------------------------------------------------------
       
   300 // AknsSrvUtils::BuildSkinInfoPackageL
       
   301 // -----------------------------------------------------------------------------
       
   302 //
       
   303 TAknsSrvSkinInfoPkg* AknsSrvUtils::BuildSkinInfoPackageL(
       
   304     const TDesC& aFilename, CDRMHelper& aDrmHelper, RFs& aFileSession )
       
   305     {
       
   306     TAknsSrvSkinInfoPkg* infopkg = NULL;
       
   307     TAknsSkinSrvSkinProtectionType protectionType = EAknsSrvNoProtection;
       
   308     TBool isProtected(EFalse);
       
   309 
       
   310     TChar driveLetter = aFilename[0];
       
   311     TInt driveNumber;
       
   312     User::LeaveIfError(aFileSession.CharToDrive(driveLetter, driveNumber));
       
   313     User::LeaveIfError(aFileSession.ShareProtected());
       
   314 
       
   315     TInt err = aFileSession.CreatePrivatePath(driveNumber);
       
   316 
       
   317     if (err!=KErrNone && err!=KErrAlreadyExists)
       
   318         {
       
   319         User::Leave(err);
       
   320         }
       
   321 
       
   322     User::LeaveIfError(aFileSession.SetSessionToPrivate(driveNumber));
       
   323 
       
   324     RFile file;
       
   325     User::LeaveIfError(file.Open(aFileSession,aFilename, EFileRead | EFileShareReadersOnly));
       
   326     CleanupClosePushL(file); // 1
       
   327 
       
   328     // Files on ROM are not DRM protected
       
   329     if (aFilename[0] != 'Z')
       
   330         {
       
   331         isProtected = IsDrmProtectedL(file);
       
   332         if (isProtected)
       
   333             {
       
   334             // If protection is indicated, by default set it on.
       
   335             protectionType = EAknsSrvProtected;
       
   336 
       
   337             TBool expired = EFalse;
       
   338             TBool sendAllowed = EFalse; //not needed
       
   339             CDRMHelperRightsConstraints* playDrmHlpCons = NULL;
       
   340             CDRMHelperRightsConstraints* dispDrmHlpCons = NULL;
       
   341             CDRMHelperRightsConstraints* execDrmHlpCons = NULL;
       
   342             CDRMHelperRightsConstraints* printDrmHlpCons = NULL;
       
   343             TRAPD( drmErr, aDrmHelper.GetRightsDetailsL(
       
   344                 aFilename, ContentAccess::EView, expired, sendAllowed,
       
   345                 playDrmHlpCons, dispDrmHlpCons, execDrmHlpCons, printDrmHlpCons ) );
       
   346             // DrmHelper leaves if the content is protected, but there are rights.
       
   347             
       
   348             if ( drmErr == KErrCANoRights )
       
   349                 {
       
   350                 protectionType = EAknsSrvNoRights;
       
   351                 }
       
   352             else if ( drmErr == KErrArgument )
       
   353                 {
       
   354                 protectionType = EAknsSrvNoProtection;
       
   355                 }
       
   356             // Delete not needed constraints.
       
   357             delete printDrmHlpCons;
       
   358             delete execDrmHlpCons;
       
   359             delete playDrmHlpCons;
       
   360             CleanupStack::PushL( dispDrmHlpCons );
       
   361             // Check expiration. If expired and no rights => expired.
       
   362             if ( expired && !dispDrmHlpCons )
       
   363                 {
       
   364                 protectionType = EAknsSrvExpiredRights;
       
   365                 }
       
   366             // If expired, but there are rights => future rights.
       
   367             if ( expired && dispDrmHlpCons )
       
   368                 {
       
   369                 protectionType = EAknsSrvFutureRights;
       
   370                 }
       
   371             if ( dispDrmHlpCons )
       
   372                 {
       
   373                 TUint32 counter = 0;
       
   374                 TUint32 origCounter = 0;
       
   375                 TRAP( drmErr, dispDrmHlpCons->GetCountersL( counter, origCounter ) );
       
   376                 // No counters
       
   377                 if ( drmErr == KErrNotFound )
       
   378                     {
       
   379                     protectionType = EAknsSrvProtected;
       
   380                     }
       
   381                 else
       
   382                     {
       
   383                     protectionType = EAknsSrvCountBased;
       
   384                     }
       
   385                 }
       
   386             CleanupStack::PopAndDestroy( dispDrmHlpCons );
       
   387             }
       
   388         else
       
   389             {
       
   390             protectionType = EAknsSrvNoProtection;
       
   391             }
       
   392         }
       
   393     CAknsSrvFileBuffer* fileBuf = NULL;
       
   394     if (!isProtected) // The file is not protected, open it normally
       
   395         {
       
   396         fileBuf = CAknsSrvFileBuffer::NewL( file );
       
   397         CleanupStack::PushL( fileBuf ); // 2
       
   398         }
       
   399     else // The file is protected, open it ignoring the rights..
       
   400         {
       
   401         TInt error = aDrmHelper.ConsumeFile2(
       
   402             file, EInstall, CDRMHelper::EStart );
       
   403         if ( error == KErrCANoRights ||
       
   404              protectionType == EAknsSrvNoRights ||
       
   405              protectionType == EAknsSrvExpiredRights )
       
   406             {
       
   407             // Rights object deleted, bake up something
       
   408             // sensible
       
   409             TInt index = aFilename.LocateReverse('\\');
       
   410             TPtrC filedir;
       
   411             filedir.Set( aFilename.Left(index) );
       
   412             TPtrC filename;
       
   413             filename.Set( aFilename.Mid(index+1) );
       
   414             infopkg = new (ELeave) TAknsSrvSkinInfoPkg;
       
   415             //Create a Random id for DRM Expired Skin
       
   416             TAknsPkgID dummyPID  = { KAknsDummySkinPkgID + (Math::Random()>>4), 0 };
       
   417             infopkg->iPID = dummyPID;
       
   418             infopkg->iColorSchemePID = KAknsPIDColorBlue;
       
   419             infopkg->iSkinDirectoryBuf = filedir;
       
   420             infopkg->iSkinIniFileDirectoryBuf = filedir;
       
   421             infopkg->iSkinNameBuf = filename;
       
   422             infopkg->iIdleStateWallPaperImageName = KNullDesC;
       
   423             infopkg->iFullName = aFilename;
       
   424             infopkg->iIsCopyable = EFalse;
       
   425             infopkg->iIsDeletable = ETrue;
       
   426             infopkg->iIdleBgImageIndex = 0;
       
   427             infopkg->iProtectionType = protectionType;
       
   428             infopkg->iCorrupted = EFalse;
       
   429             CleanupStack::PopAndDestroy( ); // file
       
   430             return infopkg;
       
   431             }
       
   432         else if ( error != KErrNone )
       
   433             {
       
   434             User::Leave(KErrCorrupt);
       
   435             }
       
   436         fileBuf = CAknsSrvFileBuffer::NewL( file);
       
   437         CleanupStack::PushL( fileBuf ); // 2
       
   438         }
       
   439     if( CheckAHOverrideFlagL( *fileBuf ) )
       
   440         {
       
   441         // Do not build package for A&H override skins
       
   442         CleanupStack::PopAndDestroy(2); //fileBuf, file
       
   443         return NULL;
       
   444         }
       
   445 
       
   446     TAknsPkgID pid;
       
   447     pid.Set( GetSkinPIDL( *fileBuf ) );
       
   448 
       
   449     TInt index = aFilename.LocateReverse('\\');
       
   450     TPtrC filedir;
       
   451     filedir.Set( aFilename.Left(index));
       
   452 
       
   453     TInt idlebmpindex(0);
       
   454     HBufC* idlewallpaperbmpname = KAknsSkinSrvEmptyString().AllocL();
       
   455     CleanupStack::PushL(idlewallpaperbmpname); // 3
       
   456 
       
   457 
       
   458     HBufC* name = AknsSrvUtils::GetSkinNameL( *fileBuf );
       
   459     CleanupStack::PushL(name); // 4
       
   460 
       
   461     infopkg = new (ELeave) TAknsSrvSkinInfoPkg;
       
   462     infopkg->iPID = pid;
       
   463     infopkg->iColorSchemePID = KAknsPIDColorBlue;
       
   464     infopkg->iSkinDirectoryBuf = filedir;
       
   465     infopkg->iSkinNameBuf = *name;
       
   466     infopkg->iIdleStateWallPaperImageName = *idlewallpaperbmpname;
       
   467     infopkg->iFullName = aFilename;
       
   468     infopkg->iIsCopyable = EFalse;
       
   469     infopkg->iIsDeletable = EFalse;
       
   470     infopkg->iIdleBgImageIndex = idlebmpindex;
       
   471     infopkg->iCorrupted = EFalse;
       
   472     infopkg->iSupportAnimBg = AnimBackgroundSupportL( *fileBuf );
       
   473     
       
   474     if ( filedir.LocateF('Z') == 0)
       
   475         {
       
   476         TPath inifiledir;
       
   477         inifiledir.Append(filedir);
       
   478 
       
   479         TPath defaultDrive;
       
   480         CAknsSrvDriveMaster::GetDefaultDrive( DriveInfo::EDefaultSystem, defaultDrive );
       
   481         inifiledir.Replace( 0, 3, defaultDrive );
       
   482 
       
   483         infopkg->iSkinIniFileDirectoryBuf = inifiledir;
       
   484         infopkg->iProtectionType = EAknsSrvNoProtection;
       
   485         }
       
   486     else
       
   487         {
       
   488         infopkg->iSkinIniFileDirectoryBuf = filedir;
       
   489         infopkg->iProtectionType = protectionType;
       
   490         }
       
   491 
       
   492     CleanupStack::PopAndDestroy( 2, idlewallpaperbmpname );
       
   493     if (isProtected)
       
   494         {
       
   495         aDrmHelper.ConsumeFile2(
       
   496            file, EInstall, CDRMHelper::EFinish );
       
   497         }
       
   498     CleanupStack::PopAndDestroy(2); // file, fileBuf
       
   499     return infopkg;
       
   500     }
       
   501 
       
   502 // -----------------------------------------------------------------------------
       
   503 // AknsSrvUtils::AnimBackgroundSupportL
       
   504 // -----------------------------------------------------------------------------
       
   505 //
       
   506 TBool AknsSrvUtils::AnimBackgroundSupportL(CAknsSrvFileBuffer& aFile)
       
   507     {
       
   508     TInt32 numberofchunks = GetInt32L( aFile, EAknsSrvDFOSkinChunksN );
       
   509     TInt32 chunksize = 0;
       
   510     TUint16 chunktype = 0;
       
   511     TInt totaloffset = EAknsSrvDFOSkinContent;
       
   512     for (TInt count = 0;count< numberofchunks;count++)
       
   513         {
       
   514         chunksize = GetInt32L( aFile, totaloffset+EAknsSrvDFOCommonLength );
       
   515         chunktype = GetUInt16L( aFile, totaloffset+EAknsSrvDFOCommonType );
       
   516         if( chunktype == EAknsSkinDescSkinDescClass )
       
   517             {
       
   518             TInt chunkoffset = totaloffset;
       
   519             TInt32 chunkcount = GetInt32L( aFile,chunkoffset+EAknsSrvDFOClassChunksN );
       
   520             
       
   521             chunkoffset += EAknsSrvDFOClassContent;
       
   522             for (TInt count = 0;count < chunkcount;count++)
       
   523                 {
       
   524                 TInt32 chunklen = GetInt32L( aFile,chunkoffset+EAknsSrvDFOCommonLength );
       
   525                 TInt16 chunktype = GetUInt16L( aFile,chunkoffset+EAknsSrvDFOCommonType );
       
   526                 if ( chunktype == EAknsSkinDescSkinDescStringItemDef )
       
   527                     {
       
   528                     TInt32 major = GetInt32L( aFile,chunkoffset+EAknsSrvDFOStringMajor );
       
   529                     TInt32 minor = GetInt32L( aFile,chunkoffset+EAknsSrvDFOStringMinor );
       
   530                     if ( major == EAknsMajorProperty && 
       
   531                             minor == EAknsMinorPropertyAnimBgParam  )
       
   532                         {
       
   533                         return ETrue;
       
   534                         }
       
   535                     }
       
   536                 chunkoffset += chunklen;
       
   537                 if( GetUInt8L( aFile, chunkoffset-1 ) != 0xf5 )
       
   538                     {
       
   539                     return EFalse;
       
   540                     }
       
   541                 }   
       
   542             }
       
   543         totaloffset+=chunksize;
       
   544         if( AknsSrvUtils::GetUInt8L( aFile, totaloffset-1 ) != 0xf5 )
       
   545             {
       
   546             return EFalse;
       
   547             }        
       
   548         }
       
   549     return EFalse;
       
   550     }
       
   551 
       
   552 // -----------------------------------------------------------------------------
       
   553 // AknsSrvUtils::GetSkinFileNameL
       
   554 // -----------------------------------------------------------------------------
       
   555 //
       
   556 HBufC* AknsSrvUtils::GetSkinFileNameL(
       
   557     const TDesC& aPath, const TAknsPkgID aPID, RFs& aFileSession )
       
   558     {
       
   559     AKNS_TRACE_INFO("CAknsSrvUtils::GetSkinFilename ENTERED");
       
   560     HBufC* filename = NULL;
       
   561 
       
   562     CDesC16ArrayFlat* skinfiles = new (ELeave) CDesC16ArrayFlat(5);
       
   563     CleanupStack::PushL(skinfiles);
       
   564 
       
   565     TPath skindir;
       
   566     skindir.AppendNumFixedWidthUC( aPID.iNumber, EHex, 8 );
       
   567     if( !aPID.IsUid() )
       
   568         {
       
   569         skindir.AppendNumFixedWidthUC( aPID.iTimestamp, EHex, 8 );
       
   570         }
       
   571 
       
   572     // No leave here, since path may be missing on some drives
       
   573     TRAPD( err, SearchSkinsL(aFileSession, aPath, skindir, skinfiles ) );
       
   574     if( err )
       
   575         {
       
   576         AKNS_TRACE_ERROR1("CAknsSrvUtils::GetSkinFilename SearchSkinsL FAILED %d", err);
       
   577         CleanupStack::PopAndDestroy( skinfiles );
       
   578         return NULL;
       
   579         }
       
   580 
       
   581     if (skinfiles->Count() > 0)
       
   582         {
       
   583         // pickup the first file
       
   584         filename = (skinfiles->MdcaPoint(0)).AllocL();
       
   585         }
       
   586     CleanupStack::Pop( skinfiles );
       
   587     skinfiles->Reset();
       
   588     delete skinfiles;   
       
   589     return filename;
       
   590     }
       
   591 
       
   592 // -----------------------------------------------------------------------------
       
   593 // AknsSrvUtils::ReadSkinDescL
       
   594 // -----------------------------------------------------------------------------
       
   595 //
       
   596 TUint8* AknsSrvUtils::ReadSkinDescL(
       
   597     CAknsSrvFileBuffer& aFile, const TUint aOffset, const TUint aCount )
       
   598     {
       
   599     TUint8* buff = new (ELeave) TUint8[aCount];
       
   600     CleanupStack::PushL( buff );
       
   601     for( TUint i=0; i<aCount; i++ )
       
   602         {
       
   603         buff[i] = GetUInt8L( aFile, aOffset+i );
       
   604         }
       
   605     CleanupStack::Pop( buff );
       
   606     return buff;
       
   607     }
       
   608 
       
   609 // -----------------------------------------------------------------------------
       
   610 // AknsSrvUtils::GetInt32L
       
   611 // -----------------------------------------------------------------------------
       
   612 //
       
   613 TInt32 AknsSrvUtils::GetInt32L(CAknsSrvFileBuffer& aFile, const TUint aOffset)
       
   614     {
       
   615     return aFile.GetInt32L( aOffset );
       
   616     }
       
   617 
       
   618 // -----------------------------------------------------------------------------
       
   619 // AknsSrvUtils::GetUInt16L
       
   620 // -----------------------------------------------------------------------------
       
   621 //
       
   622 TUint16 AknsSrvUtils::GetUInt16L(CAknsSrvFileBuffer& aFile, const TUint aOffset)
       
   623     {
       
   624     return aFile.GetUint16L( aOffset );
       
   625     }
       
   626 
       
   627 // -----------------------------------------------------------------------------
       
   628 // AknsSrvUtils::GetInt16L
       
   629 // -----------------------------------------------------------------------------
       
   630 //
       
   631 TInt16 AknsSrvUtils::GetInt16L(CAknsSrvFileBuffer& aFile, const TUint aOffset)
       
   632     {
       
   633     return aFile.GetInt16L( aOffset );
       
   634     }
       
   635 
       
   636 // -----------------------------------------------------------------------------
       
   637 // AknsSrvUtils::GetUInt8L
       
   638 // -----------------------------------------------------------------------------
       
   639 //
       
   640 TUint8 AknsSrvUtils::GetUInt8L(CAknsSrvFileBuffer& aFile, const TUint aOffset)
       
   641     {
       
   642     return aFile.GetUint8L( aOffset );
       
   643     }
       
   644 
       
   645 // -----------------------------------------------------------------------------
       
   646 // AknsSrvUtils::GetSkinNameL
       
   647 // -----------------------------------------------------------------------------
       
   648 //
       
   649 HBufC* AknsSrvUtils::GetSkinNameL(CAknsSrvFileBuffer& aFile)
       
   650     {
       
   651     TInt32 numberofchunks =
       
   652         GetInt32L( aFile, EAknsSrvDFOSkinChunksN );
       
   653     TInt32 chunksize = 0;
       
   654     TInt offset = EAknsSrvDFOSkinContent;
       
   655     TUint16 chunktype = 0;
       
   656     TUint16 language = 0;
       
   657     HBufC* name = NULL;
       
   658 
       
   659     TLanguage bestfound = ELangOther; // Currently the best match
       
   660     TLanguage phonelang = User::Language();
       
   661     for (TInt count = 0;count< numberofchunks;count++)
       
   662         {
       
   663         chunksize = GetInt32L( aFile, offset+EAknsSrvDFOCommonLength );
       
   664         chunktype = GetUInt16L( aFile, offset+EAknsSrvDFOCommonType );
       
   665         if( chunktype == EAknsSkinDescName )
       
   666             {
       
   667             language = GetUInt16L( aFile, offset+EAknsSrvDFONameLanguage );
       
   668             if ( (bestfound == ELangOther) ||
       
   669                 (language == ELangEnglish) ||
       
   670                 (language == phonelang) )
       
   671                 {
       
   672                 if (name)
       
   673                     {
       
   674                     CleanupStack::Pop(name);
       
   675                     delete name;
       
   676                     }
       
   677                 TUint16 namelen = GetUInt16L(
       
   678                     aFile, offset+EAknsSrvDFONameNameLen );
       
   679                 TUint8* namebuf = ReadSkinDescL(
       
   680                     aFile, offset+EAknsSrvDFONameName, 2*namelen );
       
   681                 TBuf<128> buf;
       
   682                 // We only want 128 leftmost characters from the skin name
       
   683                 // and the rest is discarded...
       
   684                 if( namelen>127 )
       
   685                     {
       
   686                     namelen = 127;
       
   687                     }
       
   688                 buf.Append( reinterpret_cast<TUint16*>(namebuf), namelen );
       
   689                 buf.ZeroTerminate();
       
   690                 delete [] namebuf;
       
   691                 name = buf.AllocL();
       
   692                 CleanupStack::PushL(name);
       
   693                 bestfound = static_cast<TLanguage>(language);
       
   694                 if (bestfound == phonelang)
       
   695                     {
       
   696                     break; // Found the correct language, break here...
       
   697                     }
       
   698                 }
       
   699             }
       
   700         offset+=chunksize;
       
   701         if( AknsSrvUtils::GetUInt8L( aFile, offset-1 ) != 0xf5 )
       
   702             {
       
   703             AKNS_TRACE_ERROR("AknsSrvUtils::GetSkinNameL CORRUPTED FILE!");
       
   704             User::Leave( KErrCorrupt );
       
   705             }
       
   706         }
       
   707     if (name)
       
   708         {
       
   709         CleanupStack::Pop(name);
       
   710         }
       
   711     return name;
       
   712     }
       
   713 
       
   714 // -----------------------------------------------------------------------------
       
   715 // AknsSrvUtils::IsFile
       
   716 // -----------------------------------------------------------------------------
       
   717 //
       
   718 TBool AknsSrvUtils::IsFile( RFs& aFileSession, const TDesC& aFilename )
       
   719     {
       
   720     TBool result = EFalse;
       
   721     {
       
   722     TUint attValue;
       
   723     if( aFileSession.Att( aFilename, attValue ) == KErrNone )
       
   724         {
       
   725         result = ETrue;
       
   726         }
       
   727     }
       
   728     return result;
       
   729     }
       
   730 
       
   731 // -----------------------------------------------------------------------------
       
   732 // AknsSrvUtils::SearchSkinsL
       
   733 // -----------------------------------------------------------------------------
       
   734 //
       
   735 void AknsSrvUtils::SearchSkinsL(
       
   736     RFs& aRfs, const TDesC& aBasePath, const TDesC& aDirName,
       
   737     const TDesC& aExtension, CDesCArray* aSkinFiles )
       
   738     {
       
   739     CDir* dir = NULL;
       
   740     TPath path;
       
   741     path.Append(aBasePath);
       
   742     path.Append(aDirName);
       
   743     path.Append( aExtension );
       
   744 
       
   745     TFileName filename;
       
   746     User::LeaveIfError(
       
   747         aRfs.GetDir( path, KEntryAttMaskSupported, ESortByName, dir) );
       
   748 
       
   749     CleanupStack::PushL( dir );
       
   750 
       
   751     TInt filecount = dir->Count();
       
   752     AKNS_TRACE_INFO1("AknsSrvUtils::SearchSkinsL filecount = %d", filecount );
       
   753 
       
   754     for (TInt file = 0;file<filecount;file++)
       
   755         {
       
   756         filename.Copy(aBasePath);
       
   757         filename.Append(aDirName);
       
   758         filename.Append('\\');
       
   759         filename.Append((*dir)[file].iName);
       
   760 
       
   761         aSkinFiles->AppendL(filename);
       
   762         }
       
   763     AKNS_TRACE_INFO1("AknsSrvUtils::SearchSkinsL skinFiles = %d", aSkinFiles->Count() );
       
   764     CleanupStack::PopAndDestroy( dir );
       
   765     }
       
   766 
       
   767 // -----------------------------------------------------------------------------
       
   768 // AknsSrvUtils::SearchDirectoriesL
       
   769 // -----------------------------------------------------------------------------
       
   770 //
       
   771 void AknsSrvUtils::SearchDirectoriesL(
       
   772     RFs& aRfs, const TDesC& aPath, const TDesC& aExtension, CDesCArray* aSkinFiles )
       
   773     {
       
   774     // First read the directory containing skins
       
   775     TInt dircount;
       
   776     CDir* dir;
       
   777 
       
   778     // We don't want to leave here, the path to be searched might not be
       
   779     // present on all drives....
       
   780     TInt err = aRfs.GetDir( aPath,
       
   781         KEntryAttMatchExclusive |KEntryAttMatchMask |KEntryAttDir,
       
   782         ESortByName,dir );
       
   783     if (err)
       
   784         {
       
   785         return;
       
   786         }
       
   787 
       
   788     CleanupStack::PushL(dir);
       
   789 
       
   790     dircount = dir->Count();
       
   791 
       
   792     for (TInt direntry = 0;direntry<dircount;direntry++)
       
   793         {
       
   794         SearchSkinsL(aRfs, aPath, (*dir)[direntry].iName, aExtension, aSkinFiles);
       
   795         }
       
   796     CleanupStack::PopAndDestroy( dir );
       
   797     }
       
   798 
       
   799 // -----------------------------------------------------------------------------
       
   800 // AknsSrvUtils::GetSkinFileNameL
       
   801 // -----------------------------------------------------------------------------
       
   802 //
       
   803 HBufC* AknsSrvUtils::GetSkinFileNameL(
       
   804             CAknsSrvDriveMaster& aDriveMaster,
       
   805             const TAknsPkgID aPID,
       
   806             RFs& aFileSession,
       
   807             CAknsSrvDriveMaster::TAknsSrvSkinDriveList aDriveType )
       
   808     {
       
   809     HBufC* skinFileName = NULL;
       
   810     TFileName path;
       
   811     TInt driveCount = aDriveMaster.GetNumberOfDrives( aDriveType );
       
   812     TInt index = 0;
       
   813     for ( ; index < driveCount; index++ )
       
   814         {
       
   815         aDriveMaster.SkinDirectoryOnDrive(
       
   816             aDriveType, index, path );
       
   817         skinFileName = GetSkinFileNameL( path, aPID, aFileSession );
       
   818         if ( skinFileName )
       
   819             {
       
   820             // break the loop when first matching skin file found.
       
   821             index = driveCount;
       
   822             }
       
   823         }
       
   824     return skinFileName;
       
   825     }
       
   826 
       
   827 // -----------------------------------------------------------------------------
       
   828 // AknsSrvUtils::GetContentUriFromFileL
       
   829 // -----------------------------------------------------------------------------
       
   830 //
       
   831 HBufC8* AknsSrvUtils::GetContentUriFromFileL( const TDesC& aFilename )
       
   832     {
       
   833     HBufC8* contenturi = NULL;
       
   834     CContent* content = CContent::NewLC( aFilename );
       
   835 
       
   836     HBufC* contentUri = HBufC::NewLC( KMaxContentUriLength );
       
   837     TPtr tempPtr = contentUri->Des();
       
   838     // "EContentID" has the "content uri" we want. Not "EContentURI".
       
   839     TInt err = content->GetStringAttribute( ContentAccess::EContentID, tempPtr );
       
   840     if ( !err )
       
   841         {
       
   842         // Convert to 8-bit string
       
   843         contenturi = HBufC8::NewL( contentUri->Length() );
       
   844         contenturi->Des().Copy( *contentUri );
       
   845         }
       
   846     CleanupStack::PopAndDestroy( 2, content ); // content, contentUri
       
   847     return contenturi;
       
   848     }
       
   849 
       
   850 // -----------------------------------------------------------------------------
       
   851 // AknsSrvUtils::GetProtectionTypeL
       
   852 // -----------------------------------------------------------------------------
       
   853 //
       
   854 void AknsSrvUtils::GetProtectionTypeL(
       
   855     const TDesC& aFilename,
       
   856     TAknsSkinSrvSkinProtectionType& aProtectionType )
       
   857     {
       
   858     CContent* content = CContent::NewLC( aFilename );
       
   859     TInt value = KErrNone;
       
   860 
       
   861     User::LeaveIfError( content->GetAttribute( ERightsNone, value ) );
       
   862     if ( value )
       
   863         {
       
   864         aProtectionType = EAknsSrvNoRights;
       
   865         CleanupStack::PopAndDestroy( content );
       
   866         return;
       
   867         }
       
   868     User::LeaveIfError( content->GetAttribute( ERightsHaveExpired, value ) );
       
   869     if ( value )
       
   870         {
       
   871         aProtectionType = EAknsSrvExpiredRights;
       
   872         CleanupStack::PopAndDestroy( content );
       
   873         return;
       
   874         }
       
   875     User::LeaveIfError( content->GetAttribute( ECanView, value ) );
       
   876     if ( value )
       
   877         {
       
   878         aProtectionType = EAknsSrvProtected;
       
   879         CleanupStack::PopAndDestroy( content );
       
   880         return;
       
   881         }
       
   882     CleanupStack::PopAndDestroy( content );
       
   883     AKNS_TRACE_INFO1("AknsSrvUtils::GetProtectionTypeL - aProtectionType = %d", aProtectionType);
       
   884     return;
       
   885     }
       
   886 
       
   887 // -----------------------------------------------------------------------------
       
   888 // AknsSrvUtils::SkinHasMifFileL
       
   889 // -----------------------------------------------------------------------------
       
   890 //
       
   891 void AknsSrvUtils::SkinHasMifFileL( TBool& aHasMifFile,
       
   892     RFs& aFileSession, const TDesC& aFilename )
       
   893     {
       
   894     aHasMifFile = ETrue;
       
   895     _LIT( KAknsStaticPath, "\\resource\\skins" );
       
   896     TBool parseError = EFalse;
       
   897 
       
   898     // No need to make checks for ROM skins.
       
   899     if ( aFilename[0] == 'Z' )
       
   900         {
       
   901         return;
       
   902         }
       
   903 
       
   904     HBufC* fileNameBuffer = HBufC::NewL( KMaxFileName );
       
   905     TParsePtrC fileName( aFilename );
       
   906     TPtr bufferPtr = fileNameBuffer->Des();
       
   907 
       
   908     // First append drive and static path.
       
   909     if ( fileName.DrivePresent() )
       
   910         {
       
   911         bufferPtr.Append( fileName.Drive() );
       
   912         }
       
   913     else
       
   914         {
       
   915         delete fileNameBuffer;
       
   916         aHasMifFile = EFalse;
       
   917         return;
       
   918         }
       
   919 
       
   920     // Append resource path
       
   921     if ( !parseError )
       
   922         {
       
   923         bufferPtr.Append( KAknsStaticPath );
       
   924         }
       
   925 
       
   926     if ( fileName.PathPresent() && !parseError )
       
   927         {
       
   928         // Take path without the trailing backslash.
       
   929         TPtrC path = fileName.Path().Left( fileName.Path().Length() - 1 );
       
   930 
       
   931         // Locate last backslash.
       
   932         TChar backslash('\\');
       
   933         TInt bsLoc = path.LocateReverse( backslash );
       
   934 
       
   935         // Append skin PID to the directory.
       
   936         bufferPtr.Append( fileName.Path().Mid( bsLoc ) );
       
   937 
       
   938         if ( fileName.ExtPresent() )
       
   939             {
       
   940             // Last, append filename. Now string is complete.
       
   941             bufferPtr.Append( fileName.NameAndExt() );
       
   942 
       
   943             // switch the extension and check for file existance.
       
   944             bufferPtr.Replace(
       
   945                 bufferPtr.Length() - KExtensionLength,
       
   946                 KExtensionLength,
       
   947                 KAknsSkinSrvMifFileExt );
       
   948             if ( !BaflUtils::FileExists( aFileSession, bufferPtr ) )
       
   949                 {
       
   950                 // Finally, check if this could be old skin - check if
       
   951                 // .mif file is in the same directory.
       
   952                 bufferPtr.Zero();
       
   953                 bufferPtr.Append( fileName.FullName() );
       
   954                 bufferPtr.Replace(
       
   955                     bufferPtr.Length() - KExtensionLength,
       
   956                     KExtensionLength,
       
   957                     KAknsSkinSrvMifFileExt );
       
   958                 if ( !BaflUtils::FileExists( aFileSession, bufferPtr ) )
       
   959                     {
       
   960                     // There is no matching .mif-file => leave.
       
   961                     delete fileNameBuffer;
       
   962                     aHasMifFile = EFalse;
       
   963                     return;
       
   964                     }
       
   965                 }
       
   966 
       
   967             // switch back the graphics file extension.
       
   968             bufferPtr.Replace(
       
   969                 bufferPtr.Length() - KExtensionLength,
       
   970                 KExtensionLength,
       
   971                 fileName.Ext() );
       
   972             }
       
   973         else
       
   974             {
       
   975             delete fileNameBuffer;
       
   976             aHasMifFile = EFalse;
       
   977             return;
       
   978             }
       
   979         }
       
   980     else
       
   981         {
       
   982         delete fileNameBuffer;
       
   983         aHasMifFile = EFalse;
       
   984         return;
       
   985         }
       
   986     delete fileNameBuffer;
       
   987     }
       
   988 
       
   989 //  End of File