homescreenpluginsrv/hspsmanager/src/hspsserverutil.cpp
branchRCL_3
changeset 82 ace62b58f4b2
parent 78 1b207dd38b72
child 101 9e077f9a342c
equal deleted inserted replaced
78:1b207dd38b72 82:ace62b58f4b2
    35 _LIT(KHspsFolder, "\\200159c0\\themes\\" );
    35 _LIT(KHspsFolder, "\\200159c0\\themes\\" );
    36 _LIT(KSourcesFolder, "\\sources\\");
    36 _LIT(KSourcesFolder, "\\sources\\");
    37 _LIT( KThemesFolder, "\\themes\\" );
    37 _LIT( KThemesFolder, "\\themes\\" );
    38 _LIT( KDoubleBackSlash, "\\" );
    38 _LIT( KDoubleBackSlash, "\\" );
    39 _LIT8( KHexPrefix8, "0x" );
    39 _LIT8( KHexPrefix8, "0x" );
       
    40 _LIT( KClientSources, "c:\\private\\%x\\%D\\%D\\%D\\%S\\sources\\%S" );
    40 
    41 
    41 // -----------------------------------------------------------------------------
    42 // -----------------------------------------------------------------------------
    42 // hspsServerUtil::GenerateConfigurationAttributesL
    43 // hspsServerUtil::GenerateConfigurationAttributesL
    43 // -----------------------------------------------------------------------------
    44 // -----------------------------------------------------------------------------
    44 //
    45 //
   556             
   557             
   557     return ptr;
   558     return ptr;
   558     }    
   559     }    
   559 
   560 
   560 // -----------------------------------------------------------------------------
   561 // -----------------------------------------------------------------------------
       
   562 // hspsServerUtil::RemoveResourceFilesL
       
   563 // -----------------------------------------------------------------------------
       
   564 void hspsServerUtil::RemoveResourceFilesL(        
       
   565         CFileMan& aFilemanager,
       
   566         RFs& aFs,
       
   567         const TInt aAppUid,
       
   568         const ChspsODT& aPluginODT )
       
   569     {                           
       
   570     // Remove all plug-in resources
       
   571     for( TInt i=0; i< aPluginODT.ResourceCount(); i++ )
       
   572         {
       
   573         ChspsResource& r = aPluginODT.ResourceL( i );       
       
   574         if( r.FileName().Find( KSourcesFolder ) > 0 )
       
   575             {      
       
   576             TPtrC id( GetFixedOdtName( r.ResourceId() ) );
       
   577             const TDesC& ver( aPluginODT.ThemeVersion() );
       
   578             TFileName resource;
       
   579             resource.Format( 
       
   580                     KClientSources,
       
   581                     aAppUid,
       
   582                     aPluginODT.RootUid(),
       
   583                     aPluginODT.ProviderUid(),
       
   584                     aPluginODT.ThemeUid(),
       
   585                     &ver,
       
   586                     &id );
       
   587             if( BaflUtils::FileExists( aFs, resource ) )
       
   588                 {
       
   589                 aFilemanager.Delete( resource, 0 );
       
   590                 }            
       
   591             }
       
   592         }
       
   593     }
       
   594 
       
   595 
       
   596 // -----------------------------------------------------------------------------
       
   597 // hspsServerUtil::CopyResourceFilesL
       
   598 // -----------------------------------------------------------------------------
       
   599 TInt hspsServerUtil::CopyResourceFilesL(
       
   600         ChspsODT& aAppODT,
       
   601         RFs& aFs,
       
   602         CFileMan& aFilemanager,
       
   603         const TInt aDeviceLanguage,
       
   604         const TInt aConfUid,
       
   605         const TDesC& aDestination,
       
   606         const TBool aIsRelevant )
       
   607     {
       
   608     TInt error( KErrNone );
       
   609     RPointerArray<ChspsResource> widgetResources; // Objects are not owned.
       
   610     CleanupClosePushL( widgetResources );
       
   611     
       
   612     // Find resources for the language or common to all languages or test resources    
       
   613     // if others couldn't be found
       
   614     GetResourcesForLanguageL( 
       
   615         aAppODT,
       
   616         aConfUid,
       
   617         (TLanguage)aDeviceLanguage,
       
   618         widgetResources );
       
   619         
       
   620     // Copy the resources found    
       
   621     for( TInt i = 0; ( i < widgetResources.Count() && !error ); i++ )
       
   622         {      
       
   623         ChspsResource* resource = widgetResources[i];
       
   624         if( !resource )
       
   625             {
       
   626             continue;
       
   627             }
       
   628                 
       
   629         // Get relative path under the themes folder 
       
   630         TPath relativePath;
       
   631         GetRelativeResourcePath( 
       
   632                 resource->FileName(),
       
   633                 relativePath );
       
   634         
       
   635         // Strip language indicator from the relative path                                       
       
   636         GetLocaleIndependentResourcePath( 
       
   637                 resource->Language(),                            
       
   638                 relativePath );   
       
   639         
       
   640         // Finalize target path
       
   641         TPath targetPath;
       
   642         targetPath.Copy( aDestination );
       
   643         targetPath.Append( relativePath );        
       
   644              
       
   645         // Create target path and copy files when required
       
   646         error = CopyResourceFileL(
       
   647                 aFs,
       
   648                 aFilemanager, 
       
   649                 targetPath,
       
   650                 resource->FileName(),
       
   651                 aIsRelevant );        
       
   652         if ( error == KErrAlreadyExists )
       
   653             {
       
   654             error = KErrNone;
       
   655             }
       
   656         
       
   657         } // copy loop       
       
   658         
       
   659     widgetResources.Reset();
       
   660     CleanupStack::PopAndDestroy( 1, &widgetResources );
       
   661 
       
   662     return error;
       
   663     }  
       
   664 
       
   665 // -----------------------------------------------------------------------------
   561 // hspsServerUtil::CopyResourceFileL
   666 // hspsServerUtil::CopyResourceFileL
   562 // -----------------------------------------------------------------------------
   667 // -----------------------------------------------------------------------------
   563 //
   668 //
   564 TInt hspsServerUtil::CopyResourceFileL(
   669 TInt hspsServerUtil::CopyResourceFileL(
   565         RFs& aFs,
   670         RFs& aFs,
   566         CFileMan& aFilemanager,
   671         CFileMan& aFilemanager,
   567         const TPath& aTargetPath,
   672         const TPath& aTargetPath,
   568         const TFileName& aSourceFile )
   673         const TFileName& aSourceFile,
       
   674         const TBool aIsRelevant )
   569     {
   675     {
   570     // Construct target file with full path.
   676     // Construct target file with full path.
   571     TFileName targetFile;
   677     TFileName targetFile;
   572     
   678     
   573     TParse targetParser;
   679     TParse targetParser;
   585         targetFile.Append( sourceParser.NameAndExt() );    
   691         targetFile.Append( sourceParser.NameAndExt() );    
   586         }
   692         }
   587 
   693 
   588     TInt error = KErrNone;
   694     TInt error = KErrNone;
   589     
   695     
   590     if ( hspsServerUtil::ResourceCopyIsRelevantL( 
   696     if ( aIsRelevant 
   591             aSourceFile,
   697             || hspsServerUtil::ResourceCopyIsRelevantL( 
   592             targetFile,
   698                 aSourceFile,
   593             aFs ) 
   699                 targetFile,
       
   700                 aFs ) 
   594         )
   701         )
   595         {
   702         {
   596         // Make target folder
   703         // Make target folder
   597         error = aFs.MkDirAll( aTargetPath );
   704         error = aFs.MkDirAll( aTargetPath );
   598         if( error == KErrAlreadyExists )
   705         if( error == KErrAlreadyExists )
   614             // Clear readonly file attribs that might be inherited from the source file                
   721             // Clear readonly file attribs that might be inherited from the source file                
   615             aFilemanager.Attribs( 
   722             aFilemanager.Attribs( 
   616                 aTargetPath,
   723                 aTargetPath,
   617                 0,
   724                 0,
   618                 KEntryAttReadOnly,
   725                 KEntryAttReadOnly,
   619                 TTime( 0 ) ); // TTime(0) = preserve original time stamp.                                                                      
   726                 TTime( 0 ) ); // TTime(0) = preserve original time stamp.
       
   727                         
       
   728 #ifdef HSPS_LOG_ACTIVE
       
   729             if ( iLogBus )
       
   730                 {
       
   731                 iLogBus->LogText( 
       
   732                         _L( "hspsServerUtil::CopyResourceFileL(): - %S was copied" ), 
       
   733                         &aTargetPath 
       
   734                         );
       
   735                 } 
       
   736 #endif            
   620             }        
   737             }        
   621         }                
   738         }                
   622     
   739     
   623     return error;
   740     return error;
   624     }
   741     }
  1700     
  1817     
  1701     return ( aFilename.Length() > 0 );
  1818     return ( aFilename.Length() > 0 );
  1702     }
  1819     }
  1703 
  1820 
  1704 // -----------------------------------------------------------------------------
  1821 // -----------------------------------------------------------------------------
  1705 // hspsServerUtil::GetValidResourcesL
  1822 // hspsServerUtil::GetResourcesForLanguageL
  1706 // -----------------------------------------------------------------------------
  1823 // -----------------------------------------------------------------------------
  1707 void hspsServerUtil::GetValidResourcesL(
  1824 void hspsServerUtil::GetResourcesForLanguageL(
  1708         ChspsODT& aODT,        
  1825         ChspsODT& aODT,        
  1709         const TInt aConfUid,
  1826         const TInt aConfUid,
  1710         const TLanguage aActiveLanguage,
  1827         const TLanguage aActiveLanguage,
  1711         RPointerArray<ChspsResource>& aWidgetResources )
  1828         RPointerArray<ChspsResource>& aWidgetResources )
  1712     {    
  1829     {    
  1778     
  1895     
  1779     // Retrieve data for needed resource files.
  1896     // Retrieve data for needed resource files.
  1780     RPointerArray<ChspsResource> widgetResources; // Objects are not owned.
  1897     RPointerArray<ChspsResource> widgetResources; // Objects are not owned.
  1781     CleanupClosePushL( widgetResources );
  1898     CleanupClosePushL( widgetResources );
  1782     
  1899     
  1783     GetValidResourcesL( aODT,
  1900     GetResourcesForLanguageL( 
       
  1901         aODT,
  1784         aODT.ThemeUid(),
  1902         aODT.ThemeUid(),
  1785         aActiveLanguage,
  1903         aActiveLanguage,
  1786         widgetResources );
  1904         widgetResources );
  1787     
  1905     
  1788     TInt requiredDiskSpace = aAdditionalDiskSpace;
  1906     TInt requiredDiskSpace = aAdditionalDiskSpace;
  2047           } // dirlist
  2165           } // dirlist
  2048     
  2166     
  2049         } // driveIndex    
  2167         } // driveIndex    
  2050     }
  2168     }
  2051 
  2169 
       
  2170 // -----------------------------------------------------------------------------
       
  2171 // hspsServerUtil::GetInstalledLanguagesL
       
  2172 // -----------------------------------------------------------------------------
  2052 void hspsServerUtil::GetInstalledLanguagesL(
  2173 void hspsServerUtil::GetInstalledLanguagesL(
  2053         CArrayFixFlat<TInt>*& aLanguages )
  2174         CArrayFixFlat<TInt>*& aLanguages )
  2054     {
  2175     {
  2055     User::LeaveIfError( SysLangUtil::GetInstalledLanguages( aLanguages ) );
  2176     User::LeaveIfError( SysLangUtil::GetInstalledLanguages( aLanguages ) );
  2056     CleanupStack::PushL( aLanguages );
  2177     CleanupStack::PushL( aLanguages );