homescreenpluginsrv/hspsmanager/src/hspsserverutil.cpp
branchRCL_3
changeset 31 8baec10861af
parent 30 a5a39a295112
equal deleted inserted replaced
30:a5a39a295112 31:8baec10861af
    33 #include <driveinfo.h>
    33 #include <driveinfo.h>
    34 
    34 
    35 
    35 
    36 _LIT(KHspsFolder, "\\200159c0\\themes\\" );
    36 _LIT(KHspsFolder, "\\200159c0\\themes\\" );
    37 _LIT(KSourcesFolder, "\\sources\\");
    37 _LIT(KSourcesFolder, "\\sources\\");
       
    38 _LIT(KLocalesFolder, "\\locales\\");
    38 _LIT( KThemesFolder, "\\themes\\" );
    39 _LIT( KThemesFolder, "\\themes\\" );
    39 _LIT( KDoubleBackSlash, "\\" );
    40 _LIT( KDoubleBackSlash, "\\" );
    40 _LIT8( KHexPrefix8, "0x" );
    41 _LIT8( KHexPrefix8, "0x" );
    41 _LIT( KClientSources, "c:\\private\\%x\\%D\\%D\\%D\\%S\\sources\\%S" );
    42 _LIT( KClientSources, "c:\\private\\%x\\%D\\%D\\%D\\%S\\sources\\%S" );
    42 
    43 
   948 // -----------------------------------------------------------------------------
   949 // -----------------------------------------------------------------------------
   949 //
   950 //
   950 void hspsServerUtil::FindUniquePluginsL( 
   951 void hspsServerUtil::FindUniquePluginsL( 
   951         ChspsODT& aOdt, 
   952         ChspsODT& aOdt, 
   952         RArray<TInt>& aPluginArray )
   953         RArray<TInt>& aPluginArray )
   953     {    
   954     {
   954     aPluginArray.Reset();          
   955     aPluginArray.Reset();
       
   956     CleanupClosePushL( aPluginArray );
       
   957 
   955     ChspsDomDocument& dom = aOdt.DomDocument();
   958     ChspsDomDocument& dom = aOdt.DomDocument();
   956     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( *dom.RootNode() );
   959     ChspsDomDepthIterator* iter = ChspsDomDepthIterator::NewL( *dom.RootNode() );
   957     CleanupStack::PushL( iter );
   960     CleanupStack::PushL( iter );
   958     
   961     
   959     ChspsDomNode* node = iter->First();
   962     ChspsDomNode* node = iter->First();
   960     ChspsDomNode* prevNode = NULL;
   963     ChspsDomNode* prevNode = NULL;
   961     while( node && prevNode != node )
   964     while( node && prevNode != node )
   962        {                
   965         {
   963        const TDesC8& name = node->Name();
   966         const TDesC8& name = node->Name();
   964        
   967        
   965        // Plugin element was found 
   968         // Plugin element was found 
   966        if ( name == KPluginElement )
   969         if ( name == KPluginElement )
   967            {           
   970             {           
   968            ChspsDomList& attrList = node->AttributeList();                    
   971             ChspsDomList& attrList = node->AttributeList();                    
   969            ChspsDomAttribute* uidAttr = static_cast<ChspsDomAttribute*>( attrList.FindByName(KPluginAttrUid) );            
   972             ChspsDomAttribute* uidAttr = static_cast<ChspsDomAttribute*>( attrList.FindByName(KPluginAttrUid) );            
   970            if ( uidAttr )
   973             if ( uidAttr )
   971                {     
   974                 {     
   972                // Convert from hex to int
   975                 // Convert from hex to int
   973                const TUid pluginUid = ConvertDescIntoUid( uidAttr->Value() );               
   976                 const TUid pluginUid = ConvertDescIntoUid( uidAttr->Value() );               
   974                if ( pluginUid.iUid > 0 )
   977                 if ( pluginUid.iUid > 0 )
   975                    {
   978                     {
   976                    TBool isUnique = ETrue;
   979                     TBool isUnique = ETrue;
   977                    for( TInt i=0; isUnique && i<aPluginArray.Count();i++ )
   980                     for( TInt i=0; isUnique && i<aPluginArray.Count();i++ )
   978                        {
   981                         {
   979                        if ( aPluginArray[i] == pluginUid.iUid )
   982                         if ( aPluginArray[i] == pluginUid.iUid )
   980                            {
   983                             {
   981                            isUnique=EFalse;
   984                             isUnique=EFalse;
   982                            }
   985                             }
   983                        }
   986                         }
   984                    if ( isUnique )
   987                     if ( isUnique )
   985                        {
   988                         {
   986                        aPluginArray.Append( pluginUid.iUid );
   989                         aPluginArray.AppendL( pluginUid.iUid );
   987                        }
   990                         }
   988                    }               
   991                    }               
   989                }
   992                }
   990            }
   993            }
   991            
   994            
   992            prevNode = node;        
   995            prevNode = node;        
   993            node = iter->NextL();        
   996            node = iter->NextL();        
   994            }
   997            }
   995    CleanupStack::PopAndDestroy( iter );      
   998 
   996 }
   999     CleanupStack::PopAndDestroy( iter );
       
  1000     CleanupStack::Pop( &aPluginArray );
       
  1001     }
   997 
  1002 
   998 //----------------------------------------------------------------------------
  1003 //----------------------------------------------------------------------------
   999 // CHspsServiceUtilities::HexString2Uint
  1004 // CHspsServiceUtilities::HexString2Uint
  1000 // ----------------------------------------------------------------------------
  1005 // ----------------------------------------------------------------------------
  1001 //
  1006 //
  1273         // Add found file with full path to file array
  1278         // Add found file with full path to file array
  1274         const TEntry& fileEntry = (*fileList)[k];
  1279         const TEntry& fileEntry = (*fileList)[k];
  1275         TFileName file;
  1280         TFileName file;
  1276         file.Append( aDirName );
  1281         file.Append( aDirName );
  1277         file.Append( fileEntry.iName );
  1282         file.Append( fileEntry.iName );
  1278         aFiles.Append( file );
  1283         aFiles.AppendL( file );
  1279         }
  1284         }
  1280     CleanupStack::PopAndDestroy( fileList );
  1285     CleanupStack::PopAndDestroy( fileList );
  1281 
       
  1282     CleanupStack::PopAndDestroy(); // fs
  1286     CleanupStack::PopAndDestroy(); // fs
  1283     }
  1287     }
  1284 
  1288 
  1285 // -----------------------------------------------------------------------------
  1289 // -----------------------------------------------------------------------------
  1286 // hspsServerUtil::SetAttributeValueL
  1290 // hspsServerUtil::SetAttributeValueL
  1408 // -----------------------------------------------------------------------------
  1412 // -----------------------------------------------------------------------------
  1409 // hspsServerUtil::CheckResourceFilesL
  1413 // hspsServerUtil::CheckResourceFilesL
  1410 // -----------------------------------------------------------------------------
  1414 // -----------------------------------------------------------------------------
  1411 //
  1415 //
  1412 void hspsServerUtil::CheckResourceFilesL( 
  1416 void hspsServerUtil::CheckResourceFilesL( 
  1413     const ChspsODT& aOdt,
  1417     ChspsODT& aAppOdt,    
  1414     const TInt aConfUid )
  1418     const ChspsODT& aPluginHeader,
       
  1419     RFs& aRfs )
  1415     {
  1420     {
  1416     __UHEAP_MARK;
  1421     __UHEAP_MARK;
  1417 
  1422     
  1418     // Convert configuration UID to decimal string
  1423     // Get all languages which the HW image supports
  1419     TBuf<10> confUid; 
  1424     CArrayFixFlat<TInt>* supportedLanguages = NULL;
  1420     _LIT( KFormat, "%D" );
  1425     hspsServerUtil::GetInstalledLanguagesL( supportedLanguages );
  1421     confUid.AppendFormat( KFormat, aConfUid );
  1426     CleanupStack::PushL( supportedLanguages );
  1422 
  1427     supportedLanguages->InsertL( 0, ELangNone ); // language independent resources
  1423     RFs fs;
  1428     const TInt languagesCount = supportedLanguages->Count();
  1424     CleanupClosePushL( fs );
  1429     
  1425     User::LeaveIfError( fs.Connect() );
  1430     // If set, the plug-in resources need to be updated
  1426     
  1431     TBool isBroken = EFalse;        
  1427     TInt resCount = aOdt.ResourceCount();
  1432         
  1428     for ( TInt i = 0; i < resCount; i++ )
  1433     // Loop resources from the application configuration and
  1429         {
  1434     // fix the language specific resources.
  1430         // Check if resource file belongs to defined configuration
  1435     // Use case: backup has been taken from another variant
  1431         // (file path contains configuration UID string)
  1436     const TInt count = aAppOdt.ResourceCount();
  1432         ChspsResource& res = aOdt.ResourceL( i );
  1437     for ( TInt i = 0; i < count; i++ )
  1433         TPtrC resFile = res.FileName();
  1438         {        
  1434         if ( resFile.FindC( confUid ) != KErrNotFound )
  1439         ChspsResource& appResource = aAppOdt.ResourceL( i );
  1435             {
  1440              
  1436             // Check that resource files exists
  1441         // If this resource needs to be checked 
  1437             if ( !BaflUtils::FileExists( fs, resFile ) )
  1442         if ( appResource.ConfigurationUid() == aPluginHeader.ThemeUid() )
  1438                 {
  1443             {
  1439                 User::Leave( KErrNotFound );
  1444             // Test if localization matches
       
  1445             TBool wasFound = EFalse;
       
  1446             for( TInt j=0; j < languagesCount; j++ )
       
  1447                 {
       
  1448                 if( appResource.Language() == supportedLanguages->At( j ) )
       
  1449                     {
       
  1450                     wasFound = ETrue;
       
  1451                     break;                                               
       
  1452                     }
  1440                 }
  1453                 }
  1441             }
  1454             if( !wasFound )
  1442         }
  1455                 {
  1443     
  1456                 isBroken = ETrue;
  1444     CleanupStack::PopAndDestroy(); // fs
  1457                 break;
       
  1458                 }
       
  1459             }
       
  1460         }
       
  1461    
       
  1462     if( isBroken )
       
  1463         {                                             
       
  1464         // Remove all resources 
       
  1465         RemovePluginResourcesL( aAppOdt, aPluginHeader.ThemeUid() );
       
  1466    
       
  1467         // Add back the matching resources        
       
  1468         const TInt resourceCount = aPluginHeader.ResourceCount();
       
  1469         for ( TInt i=0; i < resourceCount; i++ )
       
  1470             {                    
       
  1471             ChspsResource& resource = aPluginHeader.ResourceL( i );
       
  1472 
       
  1473             // Ignore the ODT resource
       
  1474             if ( resource.FileName().FindF( KSourcesFolder ) > 0
       
  1475                 || resource.FileName().FindF( KLocalesFolder ) > 0 )                               
       
  1476                 {
       
  1477                 
       
  1478                 // Find valid resources                
       
  1479                 for( TInt j=0; j < languagesCount; j++ )
       
  1480                     {
       
  1481                     if( resource.Language() == supportedLanguages->At( j ) )
       
  1482                         {
       
  1483                         // Make sure the file exists    
       
  1484                         if( !BaflUtils::FileExists( aRfs, resource.FileName() ) )
       
  1485                             {
       
  1486                             User::Leave( KErrNotFound );
       
  1487                             }
       
  1488                         // Finally append the resource array of the application configuration 
       
  1489                         ChspsResource* clonedResource = resource.CloneL();
       
  1490                         CleanupStack::PushL( clonedResource );
       
  1491                         aAppOdt.AddResourceL( clonedResource );
       
  1492                         CleanupStack::Pop( clonedResource );
       
  1493                         }
       
  1494                     }
       
  1495                 
       
  1496                 }
       
  1497             }                
       
  1498                 
       
  1499         }
       
  1500     
       
  1501     CleanupStack::PopAndDestroy( supportedLanguages );
  1445     
  1502     
  1446     __UHEAP_MARKEND;
  1503     __UHEAP_MARKEND;
  1447     
       
  1448     }
  1504     }
  1449 
  1505 
  1450 // -----------------------------------------------------------------------------
  1506 // -----------------------------------------------------------------------------
  1451 // hspsServerUtil::GetConfigurationVersionL
  1507 // hspsServerUtil::GetConfigurationVersionL
  1452 // -----------------------------------------------------------------------------
  1508 // -----------------------------------------------------------------------------
  1990              TInt drive = hspsServerUtil::GetEmmcDrivePath( aFs );
  2046              TInt drive = hspsServerUtil::GetEmmcDrivePath( aFs );
  1991              if ( drive != KErrNotFound )
  2047              if ( drive != KErrNotFound )
  1992                  {
  2048                  {
  1993                  aFs.SetSessionToPrivate( drive );
  2049                  aFs.SetSessionToPrivate( drive );
  1994                  }
  2050                  }
       
  2051 // When Emmc drive is not present in emulator it is replaced by D drive
       
  2052 #ifdef __WINSCW__
       
  2053              else 
       
  2054                  {
       
  2055                  aFs.SetSessionToPrivate( EDriveD );
       
  2056                  }
       
  2057 #endif
  1995              }
  2058              }
  1996          else 
  2059          else 
  1997              {
  2060              {
  1998              aFs.SetSessionToPrivate( EDriveZ );
  2061              aFs.SetSessionToPrivate( EDriveZ );
  1999              }
  2062              }
  2100         fileFinder.FindWildByPath( path, NULL, dirList );
  2163         fileFinder.FindWildByPath( path, NULL, dirList );
  2101         if ( dirList )
  2164         if ( dirList )
  2102             {
  2165             {
  2103             CleanupStack::PushL( dirList );
  2166             CleanupStack::PushL( dirList );
  2104                        
  2167                        
       
  2168             // Loop entries
  2105             const TInt count = dirList->Count();          
  2169             const TInt count = dirList->Count();          
  2106             for( TInt entryIndex = 0; entryIndex < count; entryIndex++ )
  2170             for( TInt entryIndex = 0; entryIndex < count; entryIndex++ )
  2107                 {
  2171                 {
  2108                 const TEntry& entry = (*dirList)[ entryIndex ];                        
  2172                 const TEntry& entry = (*dirList)[ entryIndex ];                        
  2109                                                          
  2173                                                          
  2110                 TFileName file( path );              
  2174                 TFileName file( path );              
  2111                 file.Append( entry.iName );
  2175                 file.Append( entry.iName );
  2112                 
  2176                 
  2113                 if( entry.IsDir() )
  2177                 if( entry.IsDir() )
  2114                     {                               
  2178                     {   
       
  2179 					                            
  2115                     if( aDeviceLanguages )
  2180                     if( aDeviceLanguages )
  2116                         {
  2181                         {
       
  2182 #if defined(WINSCW) || defined(__WINS__)
       
  2183                         // Emulator environment supports all languages, include all directories
       
  2184 #else
       
  2185                         // Devices have less languages, therefore include specific directories only
  2117                         TInt dirLanguage = 0;
  2186                         TInt dirLanguage = 0;
  2118                         TLex lex( entry.iName );
  2187                         TLex lex( entry.iName );
  2119                         TBool skipDir = ETrue;
  2188                         TBool skipDir = ETrue;                        
       
  2189                         // If conversion succeeded
  2120                         if( lex.Val( dirLanguage ) == KErrNone && dirLanguage >= ELangTest )
  2190                         if( lex.Val( dirLanguage ) == KErrNone && dirLanguage >= ELangTest )
  2121                             {                   
  2191                             {                   
  2122                             for( TInt i=0; i < aDeviceLanguages->Count(); i++ )
  2192                             for( TInt i=0; i < aDeviceLanguages->Count(); i++ )
  2123                                 {
  2193                                 {
  2124                                 TInt supportedLanguage = aDeviceLanguages->At( i );
  2194                                 TInt supportedLanguage = aDeviceLanguages->At( i );
  2127                                     skipDir = EFalse;
  2197                                     skipDir = EFalse;
  2128                                     break;
  2198                                     break;
  2129                                     }
  2199                                     }
  2130                                 }
  2200                                 }
  2131                             }
  2201                             }
       
  2202                         
       
  2203                         // If the language is not supported by the device  
  2132                         if( skipDir )
  2204                         if( skipDir )
  2133                             {
  2205                             {
  2134                             continue;
  2206                             continue;
  2135                             }
  2207                             }
       
  2208 #endif                                                
  2136                         }
  2209                         }
  2137               
  2210 						
  2138                   file.Append( KDoubleBackSlash );
  2211                     file.Append( KDoubleBackSlash );
  2139                   }
  2212                     }
  2140                                 
  2213                                 
  2141               if( entry.IsDir() && aRecursive )
  2214               if( entry.IsDir() && aRecursive )
  2142                   {                   
  2215                   {                   
  2143                   // Find files from the directory and drive
  2216                   // Find files from the subdirectory and the drive
  2144                   RArray<TInt> driveArray;
  2217                   RArray<TInt> driveArray;
  2145                   CleanupClosePushL( driveArray );                  
  2218                   CleanupClosePushL( driveArray );                  
  2146                   driveArray.Append( aDriveArray[driveIndex] );                                   
  2219                   driveArray.AppendL( aDriveArray[driveIndex] );                                   
  2147                   FindResourcesL( aFs, driveArray, file, aFileArray, NULL );   
  2220                   FindResourcesL( aFs, driveArray, file, aFileArray, NULL );   
  2148                   CleanupStack::PopAndDestroy( &driveArray );
  2221                   CleanupStack::PopAndDestroy( &driveArray );
  2149                   }
  2222                   }
  2150               else
  2223               else
  2151                   {                                                  
  2224                   {              
       
  2225                   // Append the results array
  2152                   HBufC* nameBuf = file.AllocLC();                
  2226                   HBufC* nameBuf = file.AllocLC();                
  2153                   aFileArray.AppendL( nameBuf );
  2227                   aFileArray.AppendL( nameBuf );
  2154                   CleanupStack::Pop( nameBuf );                      
  2228                   CleanupStack::Pop( nameBuf );                      
  2155                   }              
  2229                   }              
  2156               } 
  2230               } 
  2168 void hspsServerUtil::GetInstalledLanguagesL(
  2242 void hspsServerUtil::GetInstalledLanguagesL(
  2169         CArrayFixFlat<TInt>*& aLanguages )
  2243         CArrayFixFlat<TInt>*& aLanguages )
  2170     {
  2244     {
  2171     User::LeaveIfError( SysLangUtil::GetInstalledLanguages( aLanguages ) );
  2245     User::LeaveIfError( SysLangUtil::GetInstalledLanguages( aLanguages ) );
  2172     CleanupStack::PushL( aLanguages );
  2246     CleanupStack::PushL( aLanguages );
  2173     
  2247 
  2174     const TInt testLang = (TInt)ELangTest;
  2248     // Check for a duplicate entry
  2175     
  2249     const TInt KTestLang = (TInt)ELangTest;    
  2176     TBool isIncluded = EFalse;           
  2250     TBool isIncluded = EFalse;           
  2177     for( TInt i = 0; i < aLanguages->Count(); i++ )
  2251     for( TInt i = 0; i < aLanguages->Count(); i++ )
  2178         {
  2252         {
  2179         if( aLanguages->At( i ) == testLang )
  2253         if( aLanguages->At( i ) == KTestLang )
  2180             {    
  2254             {    
  2181             isIncluded = ETrue;            
  2255             isIncluded = ETrue;            
  2182             break;
  2256             break;
  2183             }
  2257             }
  2184         }    
  2258         }    
  2185     
  2259     
  2186     if( !isIncluded )
  2260     if( !isIncluded )
  2187         {
  2261         {
  2188         aLanguages->InsertL( 0, testLang );        
  2262         aLanguages->InsertL( 0, KTestLang );        
  2189         }
  2263         }
  2190     
  2264     
  2191     CleanupStack::Pop( aLanguages );
  2265     CleanupStack::Pop( aLanguages );
  2192     }
  2266     }
  2193     
  2267