homescreenpluginsrv/hspsmanager/src/hspsserverutil.cpp
changeset 3 ff572005ac23
parent 2 b7904b40483f
child 12 502e5d91ad42
equal deleted inserted replaced
2:b7904b40483f 3:ff572005ac23
   581         TParse sourceParser;
   581         TParse sourceParser;
   582         sourceParser.Set( aSourceFile, NULL, NULL );
   582         sourceParser.Set( aSourceFile, NULL, NULL );
   583         targetFile = targetParser.DriveAndPath();
   583         targetFile = targetParser.DriveAndPath();
   584         targetFile.Append( sourceParser.NameAndExt() );    
   584         targetFile.Append( sourceParser.NameAndExt() );    
   585         }
   585         }
   586         
   586 
   587     // Make target folder
   587     TInt error = KErrNone;
   588     TInt error = aFs.MkDirAll( aTargetPath );            
   588     
   589     if( error == KErrAlreadyExists )
   589     if ( hspsServerUtil::ResourceCopyIsRelevantL( 
   590         {
   590             aSourceFile,
   591         // lets ignore error if directory already exists                
   591             targetFile,
   592         error = KErrNone;
   592             aFs ) 
   593         }       
   593         )
   594     if( !error )
   594         {
   595         {
   595         // Make target folder
   596         // Default to 'copying was not neccessary'
   596         error = aFs.MkDirAll( aTargetPath );
   597         error = KErrAlreadyExists;
   597         if( error == KErrAlreadyExists )
   598         
   598             {
   599         // Check whether the resource needs to be copied
   599             // lets ignore error if directory already exists                
   600         if ( hspsServerUtil::ResourceCopyIsRelevantL( 
   600             error = KErrNone;
   601                 aSourceFile,
   601             }
   602                 targetFile,
   602         
   603                 aFs ) 
   603         if( !error )
   604             )
       
   605             {        
   604             {        
   606             // Slowish operation
   605             // Slowish operation
   607             error = aFilemanager.Copy( 
   606             error = aFilemanager.Copy( 
   608                     aSourceFile, 
   607                     aSourceFile, 
   609                     aTargetPath );
   608                     aTargetPath );
   610             if( !error )
   609             }
   611                 {
       
   612                 // Clear readonly file attribs that might be inherited from the source file                
       
   613                 aFilemanager.Attribs( 
       
   614                     aTargetPath,
       
   615                     0,
       
   616                     KEntryAttReadOnly,
       
   617                     TTime( 0 ) ); // TTime(0) = preserve original time stamp.                                                                      
       
   618                 }
       
   619             
   610             
   620             } // copy op        
   611         if( !error )
   621         }
   612             {
       
   613             // Clear readonly file attribs that might be inherited from the source file                
       
   614             aFilemanager.Attribs( 
       
   615                 aTargetPath,
       
   616                 0,
       
   617                 KEntryAttReadOnly,
       
   618                 TTime( 0 ) ); // TTime(0) = preserve original time stamp.                                                                      
       
   619             }        
       
   620         }                
   622     
   621     
   623     return error;
   622     return error;
   624     }
   623     }
   625 
   624 
   626 // -----------------------------------------------------------------------------
   625 // -----------------------------------------------------------------------------
   637         {
   636         {
   638         return EFalse;
   637         return EFalse;
   639         }
   638         }
   640 
   639 
   641     // Collect data from files.
   640     // Collect data from files.
   642     
       
   643     TEntry sourceEntry;
       
   644     TInt entryError = aFs.Entry( aSource, sourceEntry ); 
       
   645     if( entryError != KErrNone )
       
   646         {
       
   647         // Problem. Do not copy.
       
   648         return EFalse;
       
   649         }            
       
   650 
   641 
   651     TEntry targetEntry;
   642     TEntry targetEntry;
   652     entryError = aFs.Entry( aTarget, targetEntry ); 
   643     TInt entryError = aFs.Entry( aTarget, targetEntry ); 
   653     if( entryError == KErrNotFound )
   644     if( entryError == KErrNotFound ||
       
   645         entryError == KErrPathNotFound )
   654         {
   646         {
   655         // Target does not exist. Copy needed.
   647         // Target does not exist. Copy needed.
   656         return ETrue;
   648         return ETrue;
   657         }           
   649         }           
   658     else if( entryError != KErrNone ) 
   650     else if( entryError != KErrNone ) 
   659         {
   651         {
   660         // All other errors handled here. Better not to copy.
   652         // All other errors handled here. Better not to copy.
   661         return EFalse;
   653         return EFalse;
   662         }
   654         }
       
   655     
       
   656     TEntry sourceEntry;
       
   657     entryError = aFs.Entry( aSource, sourceEntry ); 
       
   658     if( entryError != KErrNone )
       
   659         {
       
   660         // Problem. Do not copy.
       
   661         return EFalse;
       
   662         }            
   663     
   663     
   664     TParse sourceParser;
   664     TParse sourceParser;
   665     sourceParser.Set( aSource, NULL, NULL );
   665     sourceParser.Set( aSource, NULL, NULL );
   666     
   666     
   667     TParse targetParser;
   667     TParse targetParser;
   684         if( RFs::CharToDrive( targetParser.Drive()[0], tmpDriveNumber ) == KErrNone )
   684         if( RFs::CharToDrive( targetParser.Drive()[0], tmpDriveNumber ) == KErrNone )
   685             {
   685             {
   686             targetDriveNumber = tmpDriveNumber;
   686             targetDriveNumber = tmpDriveNumber;
   687             }        
   687             }        
   688         }   
   688         }   
   689 
   689             
   690     const TInt KTargetExists = BaflUtils::FileExists( aFs, aTarget ); 
   690     // Size and time stamp identical?
   691            
   691     if( sourceEntry.iSize == targetEntry.iSize &&
   692     // Target exists + size and time stamp identical?
       
   693     if( KTargetExists &&
       
   694         sourceEntry.iSize == targetEntry.iSize &&
       
   695         sourceEntry.iModified == targetEntry.iModified )
   692         sourceEntry.iModified == targetEntry.iModified )
   696         {
   693         {
   697         return EFalse;
   694         return EFalse;
   698         }    
   695         }    
   699     
   696     
   700     // Check required disk space.
   697     // Check required disk space.
   701     TInt requiredDiskSpace = 0;
   698     TInt requiredDiskSpace = 0;    
   702     
   699     if( sourceEntry.iSize > targetEntry.iSize )
   703     if( KTargetExists && sourceEntry.iSize > targetEntry.iSize )
       
   704         {
   700         {
   705         requiredDiskSpace = sourceEntry.iSize - targetEntry.iSize; 
   701         requiredDiskSpace = sourceEntry.iSize - targetEntry.iSize; 
   706         }
   702         }
   707     else if( !KTargetExists )
   703     else
   708         {
   704         {
   709         requiredDiskSpace = sourceEntry.iSize;
   705         requiredDiskSpace = sourceEntry.iSize;
   710         }
   706         }
   711     
   707     
   712     if( requiredDiskSpace != 0 )
   708     if( requiredDiskSpace != 0 )
  1718     // pick resources with the active language       
  1714     // pick resources with the active language       
  1719     for( TInt resourceIndex = 0; resourceIndex < resourceCount; resourceIndex++ )
  1715     for( TInt resourceIndex = 0; resourceIndex < resourceCount; resourceIndex++ )
  1720         {
  1716         {
  1721         ChspsResource& resource = aODT.ResourceL( resourceIndex );        
  1717         ChspsResource& resource = aODT.ResourceL( resourceIndex );        
  1722         if ( resource.ConfigurationUid() == aConfUid &&
  1718         if ( resource.ConfigurationUid() == aConfUid &&
  1723              resource.FileName().FindF( KSourcesFolder ) > 0 &&
  1719              resource.Language() == aActiveLanguage &&
  1724              resource.Language() == aActiveLanguage )                
  1720              resource.FileName().FindF( KSourcesFolder ) > 0 )                
  1725             {                                
  1721             {                                
  1726             aWidgetResources.Append( &resource );
  1722             aWidgetResources.Append( &resource );
  1727             }
  1723             }
  1728         }        
  1724         }        
  1729     
  1725