omadrm/drmengine/drmbackup/src/DRMBackup.cpp
branchRCL_3
changeset 18 8a03a285ab14
parent 0 95b198f216e5
equal deleted inserted replaced
17:e16d72588c28 18:8a03a285ab14
    20 #include <s32mem.h>
    20 #include <s32mem.h>
    21 
    21 
    22 #include <sysutil.h>
    22 #include <sysutil.h>
    23 
    23 
    24 #ifdef RD_MULTIPLE_DRIVE
    24 #ifdef RD_MULTIPLE_DRIVE
    25 #include <DriveInfo.h>
    25 #include <driveinfo.h>
    26 #endif
    26 #endif
    27 
    27 
    28 #include "DRMBackup.h"
    28 #include "DRMBackup.h"
    29 #include "DRMLog.h"
    29 #include "drmlog.h"
    30 #include "RoapStorageClient.h"
    30 #include "RoapStorageClient.h"
    31 #include "DRMRightsDB.h"
    31 #include "drmrightsdb.h"
    32 #include "drmbackupinterface.h"
    32 #include "DRMBackupInterface.h"
    33 /*
    33 /*
    34 #include "flogger.h"
    34 #include "flogger.h"
    35 
    35 
    36 
    36 
    37 _LIT( KLogDir, "drm");
    37 _LIT( KLogDir, "drm");
    38 _LIT( KLogName, "backup.log");
    38 _LIT( KLogName, "backup.log");
    39 */
    39 */
    40 
    40 
    41 // EXTERNAL DATA STRUCTURES
    41 // EXTERNAL DATA STRUCTURES
    42 
    42 
    43 // EXTERNAL FUNCTION PROTOTYPES  
    43 // EXTERNAL FUNCTION PROTOTYPES
    44 
    44 
    45 // CONSTANTS
    45 // CONSTANTS
    46 const TInt KDoBackup        =   0x00000001;
    46 const TInt KDoBackup        =   0x00000001;
    47 const TInt KRightsFileOpen  =   0x00000002;
    47 const TInt KRightsFileOpen  =   0x00000002;
    48 const TInt KContextFileOpen =   0x00000004;
    48 const TInt KContextFileOpen =   0x00000004;
    72 // -----------------------------------------------------------------------------
    72 // -----------------------------------------------------------------------------
    73 //
    73 //
    74 LOCAL_C void CleanupData( TAny* aPtr )
    74 LOCAL_C void CleanupData( TAny* aPtr )
    75     {
    75     {
    76     CDRMBackup* backup = reinterpret_cast<CDRMBackup*>( aPtr );
    76     CDRMBackup* backup = reinterpret_cast<CDRMBackup*>( aPtr );
    77     
    77 
    78     backup->PerformCleanup();
    78     backup->PerformCleanup();
    79     }
    79     }
    80 
    80 
    81 
    81 
    82 // ============================ MEMBER FUNCTIONS ===============================
    82 // ============================ MEMBER FUNCTIONS ===============================
    86 // CDRMBackup::CDRMBackup
    86 // CDRMBackup::CDRMBackup
    87 // C++ default constructor can NOT contain any code, that
    87 // C++ default constructor can NOT contain any code, that
    88 // might leave.
    88 // might leave.
    89 // -----------------------------------------------------------------------------
    89 // -----------------------------------------------------------------------------
    90 //
    90 //
    91 CDRMBackup::CDRMBackup( CDRMRightsDB* aRightsDatabase, 
    91 CDRMBackup::CDRMBackup( CDRMRightsDB* aRightsDatabase,
    92                         RFs& aFileServer ) :
    92                         RFs& aFileServer ) :
    93     iFileServer( aFileServer ),                        
    93     iFileServer( aFileServer ),
    94     iDRMRightsDB( aRightsDatabase ),
    94     iDRMRightsDB( aRightsDatabase ),
    95     iRightsFileSize( 0 ),
    95     iRightsFileSize( 0 ),
    96     iContextFileSize( 0 ),
    96     iContextFileSize( 0 ),
    97     iPosition( 0 ),
    97     iPosition( 0 ),
    98     iReadData( 0 ),
    98     iReadData( 0 ),
    99     iStatus( 0 )
    99     iStatus( 0 )
   100     {      
   100     {
   101     };
   101     };
   102 
   102 
   103 // -----------------------------------------------------------------------------
   103 // -----------------------------------------------------------------------------
   104 // CDRMBackup::ConstructL
   104 // CDRMBackup::ConstructL
   105 // Symbian 2nd phase constructor can leave.
   105 // Symbian 2nd phase constructor can leave.
   106 // -----------------------------------------------------------------------------
   106 // -----------------------------------------------------------------------------
   107 //
   107 //
   108 void CDRMBackup::ConstructL()
   108 void CDRMBackup::ConstructL()
   109     {
   109     {
   110     TInt error = KErrNone;
   110     TInt error = KErrNone;
   111     
   111 
   112 #ifndef RD_MULTIPLE_DRIVE
   112 #ifndef RD_MULTIPLE_DRIVE
   113     
   113 
   114     // Create the backup directory if needed
   114     // Create the backup directory if needed
   115     error = iFileServer.MkDirAll( KBackupDirectory );
   115     error = iFileServer.MkDirAll( KBackupDirectory );
   116     
   116 
   117 #else //RD_MULTIPLE_DRIVE
   117 #else //RD_MULTIPLE_DRIVE
   118     
   118 
   119     TInt driveNumber( -1 );
   119     TInt driveNumber( -1 );
   120     TChar driveLetter;
   120     TChar driveLetter;
   121     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber );
   121     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber );
   122 	iFileServer.DriveToChar( driveNumber, driveLetter );
   122     iFileServer.DriveToChar( driveNumber, driveLetter );
   123     
   123 
   124 	TFileName backupDir;
   124     TFileName backupDir;
   125 	backupDir.Format( KBackupDir, (TUint)driveLetter );
   125     backupDir.Format( KBackupDir, (TUint)driveLetter );
   126     
   126 
   127     // Create the backup directory if needed
   127     // Create the backup directory if needed
   128     error = iFileServer.MkDirAll( backupDir );
   128     error = iFileServer.MkDirAll( backupDir );
   129     
   129 
   130 #endif
   130 #endif
   131     
   131 
   132     if( error != KErrAlreadyExists )
   132     if( error != KErrAlreadyExists )
   133         {
   133         {
   134         User::LeaveIfError( error );
   134         User::LeaveIfError( error );
   135         }
   135         }
   136     
   136 
   137 #ifndef RD_MULTIPLE_DRIVE
   137 #ifndef RD_MULTIPLE_DRIVE
   138     
   138 
   139     iRightsFileName.Copy( KBackupDirectory );
   139     iRightsFileName.Copy( KBackupDirectory );
   140     
   140 
   141 #else //RD_MULTIPLE_DRIVE
   141 #else //RD_MULTIPLE_DRIVE
   142 
   142 
   143     iRightsFileName.Copy( backupDir );
   143     iRightsFileName.Copy( backupDir );
   144     
   144 
   145 #endif
   145 #endif
   146     
   146 
   147     iRightsFileName.Append( KRightsDbBackupFile );
   147     iRightsFileName.Append( KRightsDbBackupFile );
   148     iSizeBuffer.SetLength( 4 );    
   148     iSizeBuffer.SetLength( 4 );
   149     };
   149     };
   150 
   150 
   151 // -----------------------------------------------------------------------------
   151 // -----------------------------------------------------------------------------
   152 // CDRMBackup::NewLC
   152 // CDRMBackup::NewLC
   153 // Two-phased constructor
   153 // Two-phased constructor
   154 // -----------------------------------------------------------------------------
   154 // -----------------------------------------------------------------------------
   155 //
   155 //
   156 CDRMBackup* CDRMBackup::NewLC( CDRMRightsDB* aRightsDatabase, 
   156 CDRMBackup* CDRMBackup::NewLC( CDRMRightsDB* aRightsDatabase,
   157                                RFs& aFileServer )
   157                                RFs& aFileServer )
   158     {
   158     {
   159     CDRMBackup* self = new(ELeave) CDRMBackup( aRightsDatabase, 
   159     CDRMBackup* self = new(ELeave) CDRMBackup( aRightsDatabase,
   160                                                aFileServer );
   160                                                aFileServer );
   161     CleanupStack::PushL( self );
   161     CleanupStack::PushL( self );
   162     self->ConstructL();
   162     self->ConstructL();
   163     
   163 
   164     return self;
   164     return self;
   165     };
   165     };
   166 
   166 
   167 // -----------------------------------------------------------------------------
   167 // -----------------------------------------------------------------------------
   168 // CDRMBackup::NewL
   168 // CDRMBackup::NewL
   169 // Two-phased constructor
   169 // Two-phased constructor
   170 // -----------------------------------------------------------------------------
   170 // -----------------------------------------------------------------------------
   171 //
   171 //
   172 CDRMBackup* CDRMBackup::NewL( CDRMRightsDB* aRightsDatabase, 
   172 CDRMBackup* CDRMBackup::NewL( CDRMRightsDB* aRightsDatabase,
   173                               RFs& aFileServer )
   173                               RFs& aFileServer )
   174     {
   174     {
   175     CDRMBackup* self = NewLC( aRightsDatabase, 
   175     CDRMBackup* self = NewLC( aRightsDatabase,
   176                               aFileServer );
   176                               aFileServer );
   177     CleanupStack::Pop();
   177     CleanupStack::Pop();
   178 
   178 
   179     return self;
   179     return self;
   180     };
   180     };
   181   
   181 
   182 // ---------------------------------------------------------
   182 // ---------------------------------------------------------
   183 // CDRMBackup::~CDRMBackup
   183 // CDRMBackup::~CDRMBackup
   184 // Destructor
   184 // Destructor
   185 // ---------------------------------------------------------
   185 // ---------------------------------------------------------
   186 //  
   186 //
   187 CDRMBackup::~CDRMBackup()
   187 CDRMBackup::~CDRMBackup()
   188     {
   188     {
   189     };
   189     };
   190 
   190 
   191 
   191 
   192 // ---------------------------------------------------------
   192 // ---------------------------------------------------------
   193 // CDRMBackup::AllSnapshotsSuppliedL
   193 // CDRMBackup::AllSnapshotsSuppliedL
   194 // ---------------------------------------------------------
   194 // ---------------------------------------------------------
   195 // 
   195 //
   196 void CDRMBackup::AllSnapshotsSuppliedL()
   196 void CDRMBackup::AllSnapshotsSuppliedL()
   197     {
   197     {
   198     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("AllSnapshotsSuppliedL\n\r"));      
   198     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("AllSnapshotsSuppliedL\n\r"));
   199     return;
   199     return;
   200     };
   200     };
   201 
   201 
   202 // ---------------------------------------------------------
   202 // ---------------------------------------------------------
   203 // CDRMBackup::ReceiveSnapshotDataL
   203 // CDRMBackup::ReceiveSnapshotDataL
   204 // ---------------------------------------------------------
   204 // ---------------------------------------------------------
   205 // 
   205 //
   206 void CDRMBackup::ReceiveSnapshotDataL(TDriveNumber /* aDrive */, 
   206 void CDRMBackup::ReceiveSnapshotDataL(TDriveNumber /* aDrive */,
   207                                       TDesC8& /* aBuffer */, 
   207                                       TDesC8& /* aBuffer */,
   208                                       TBool /* aLastSection */)
   208                                       TBool /* aLastSection */)
   209     {
   209     {
   210     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RecieveSnapshotdataL\n\r"));   
   210     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RecieveSnapshotdataL\n\r"));
   211     User::Leave( KErrNotSupported );
   211     User::Leave( KErrNotSupported );
   212     };
   212     };
   213 
   213 
   214 // ---------------------------------------------------------
   214 // ---------------------------------------------------------
   215 // CDRMBackup::GetExpectedDataSize
   215 // CDRMBackup::GetExpectedDataSize
   216 // ---------------------------------------------------------
   216 // ---------------------------------------------------------
   217 // 
   217 //
   218 TUint CDRMBackup::GetExpectedDataSize(TDriveNumber /* aDrive */)
   218 TUint CDRMBackup::GetExpectedDataSize(TDriveNumber /* aDrive */)
   219     {
   219     {
   220     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("GetExpectedDataSize\n\r"));       
   220     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("GetExpectedDataSize\n\r"));
   221     return 0;
   221     return 0;
   222     };
   222     };
   223 
   223 
   224 // ---------------------------------------------------------
   224 // ---------------------------------------------------------
   225 // CDRMBackup::GetSnapshotDataL
   225 // CDRMBackup::GetSnapshotDataL
   226 // ---------------------------------------------------------
   226 // ---------------------------------------------------------
   227 // 
   227 //
   228 void CDRMBackup::GetSnapshotDataL(TDriveNumber /* aDrive */, 
   228 void CDRMBackup::GetSnapshotDataL(TDriveNumber /* aDrive */,
   229                                   TPtr8& /* aBuffer */, 
   229                                   TPtr8& /* aBuffer */,
   230                                   TBool& /* aFinished */)
   230                                   TBool& /* aFinished */)
   231     {
   231     {
   232     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("GetSnapShopDataL\n\r"));       
   232     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("GetSnapShopDataL\n\r"));
   233     User::Leave( KErrNotSupported );
   233     User::Leave( KErrNotSupported );
   234     };
   234     };
   235 
   235 
   236 // ---------------------------------------------------------
   236 // ---------------------------------------------------------
   237 // CDRMBackup::InitialiseGetBackupDataL
   237 // CDRMBackup::InitialiseGetBackupDataL
   238 // ---------------------------------------------------------
   238 // ---------------------------------------------------------
   239 // 
   239 //
   240 void CDRMBackup::InitialiseGetBackupDataL(TDriveNumber aDrive)
   240 void CDRMBackup::InitialiseGetBackupDataL(TDriveNumber aDrive)
   241     {
   241     {
   242     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("Init backup data\n\r"));    
   242     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("Init backup data\n\r"));
   243     // Clean up existing data:
   243     // Clean up existing data:
   244     PerformCleanup();
   244     PerformCleanup();
   245     
   245 
   246 #ifndef RD_MULTIPLE_DRIVE
   246 #ifndef RD_MULTIPLE_DRIVE
   247     
   247 
   248     // Only do a backup when backing up drive C
   248     // Only do a backup when backing up drive C
   249     if( aDrive == EDriveC )
   249     if( aDrive == EDriveC )
   250     
   250 
   251 #else //RD_MULTIPLE_DRIVE
   251 #else //RD_MULTIPLE_DRIVE
   252     
   252 
   253     TInt driveNumber( -1 );
   253     TInt driveNumber( -1 );
   254     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber );
   254     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber );
   255 	
   255 
   256 	// Only do a backup when backing up system drive
   256     // Only do a backup when backing up system drive
   257     if( aDrive == driveNumber )
   257     if( aDrive == driveNumber )
   258     
   258 
   259 #endif
   259 #endif
   260         {
   260         {
   261         iStatus |= KDoBackup;
   261         iStatus |= KDoBackup;
   262         }
   262         }
   263     else
   263     else
   264         {
   264         {
   265         iStatus &= ~KDoBackup;
   265         iStatus &= ~KDoBackup;
   266         return;
   266         return;
   267         }
   267         }
   268     
   268 
   269     // Add the cleanup item to the cleanup stack    
   269     // Add the cleanup item to the cleanup stack
   270     TCleanupItem resetAndDestroy( CleanupData, reinterpret_cast<TAny*>(this) );
   270     TCleanupItem resetAndDestroy( CleanupData, reinterpret_cast<TAny*>(this) );
   271     CleanupStack::PushL( resetAndDestroy );
   271     CleanupStack::PushL( resetAndDestroy );
   272     
   272 
   273     // This function needs to write the two files required to be backed up.
   273     // This function needs to write the two files required to be backed up.
   274     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("Init: create rights file\n\r"));     
   274     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("Init: create rights file\n\r"));
   275     // create the rights database backup file
   275     // create the rights database backup file
   276     CreateRightsBackupFileL();
   276     CreateRightsBackupFileL();
   277     
   277 
   278     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("Init: create context file\n\r"));     
   278     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("Init: create context file\n\r"));
   279     // create the context database backup file
   279     // create the context database backup file
   280     CreateContextBackupFileL();
   280     CreateContextBackupFileL();
   281     
   281 
   282     // If everything went properly, pop
   282     // If everything went properly, pop
   283     CleanupStack::Pop();
   283     CleanupStack::Pop();
   284     };
   284     };
   285 
   285 
   286 // ---------------------------------------------------------
   286 // ---------------------------------------------------------
   287 // CDRMBackup::GetBackupDataSectionL
   287 // CDRMBackup::GetBackupDataSectionL
   288 // ---------------------------------------------------------
   288 // ---------------------------------------------------------
   289 // 
   289 //
   290 void CDRMBackup::GetBackupDataSectionL(TPtr8& aBuffer, TBool& aFinished)
   290 void CDRMBackup::GetBackupDataSectionL(TPtr8& aBuffer, TBool& aFinished)
   291     {
   291     {
   292     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("GetBackupDataSectionL\n\r"));       
   292     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("GetBackupDataSectionL\n\r"));
   293     TInt seekAmount = 0;
   293     TInt seekAmount = 0;
   294     
   294 
   295     // if we are not supposed to do anything, just return
   295     // if we are not supposed to do anything, just return
   296     if( !(iStatus & KDoBackup ) )
   296     if( !(iStatus & KDoBackup ) )
   297         {
   297         {
   298         // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("GetBackupDataSectionL: no Do Backup\n\r"));          
   298         // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("GetBackupDataSectionL: no Do Backup\n\r"));
   299         aFinished = ETrue;
   299         aFinished = ETrue;
   300         return;
   300         return;
   301         }
   301         }
   302     
   302 
   303     // Make sure that the buffer is empty and starts from the beginning
   303     // Make sure that the buffer is empty and starts from the beginning
   304     aBuffer.SetLength(0);
   304     aBuffer.SetLength(0);
   305         
   305 
   306      // Add the cleanup item to the cleanup stack    
   306      // Add the cleanup item to the cleanup stack
   307     TCleanupItem resetAndDestroy( CleanupData, reinterpret_cast<TAny*>(this) );
   307     TCleanupItem resetAndDestroy( CleanupData, reinterpret_cast<TAny*>(this) );
   308     CleanupStack::PushL( resetAndDestroy );
   308     CleanupStack::PushL( resetAndDestroy );
   309        
   309 
   310     if( iPosition < iRightsFileSize )
   310     if( iPosition < iRightsFileSize )
   311         {        
   311         {
   312         // Find the right position    
   312         // Find the right position
   313         iRightsBackupFile.Seek( ESeekStart,iPosition );
   313         iRightsBackupFile.Seek( ESeekStart,iPosition );
   314 
   314 
   315         // Read data
   315         // Read data
   316         User::LeaveIfError( iRightsBackupFile.Read( aBuffer ) );
   316         User::LeaveIfError( iRightsBackupFile.Read( aBuffer ) );
   317         
   317 
   318         iPosition += aBuffer.Length();
   318         iPosition += aBuffer.Length();
   319         
   319 
   320         if( iPosition == iRightsFileSize )
   320         if( iPosition == iRightsFileSize )
   321             {
   321             {
   322             aFinished = ETrue;
   322             aFinished = ETrue;
   323             }
   323             }
   324         else
   324         else
   325             {                
   325             {
   326             aFinished = EFalse;         
   326             aFinished = EFalse;
   327             }        
   327             }
   328             
   328 
   329         }
   329         }
   330     else if( iPosition < iRightsFileSize + iContextFileSize )
   330     else if( iPosition < iRightsFileSize + iContextFileSize )
   331         {   
   331         {
   332         // Find the right position
   332         // Find the right position
   333         seekAmount = iPosition-iRightsFileSize;  
   333         seekAmount = iPosition-iRightsFileSize;
   334         iContextBackupFile.Seek( ESeekStart, seekAmount );
   334         iContextBackupFile.Seek( ESeekStart, seekAmount );
   335         
   335 
   336         // Read data
   336         // Read data
   337         User::LeaveIfError( iContextBackupFile.Read( aBuffer ) );
   337         User::LeaveIfError( iContextBackupFile.Read( aBuffer ) );
   338         
   338 
   339         iPosition += aBuffer.Length();
   339         iPosition += aBuffer.Length();
   340         
   340 
   341         if( iPosition-iRightsFileSize == iContextFileSize )
   341         if( iPosition-iRightsFileSize == iContextFileSize )
   342             {
   342             {
   343             aFinished = ETrue;
   343             aFinished = ETrue;
   344             }
   344             }
   345         else
   345         else
   346             {                
   346             {
   347             aFinished = EFalse;         
   347             aFinished = EFalse;
   348             }
   348             }
   349         }
   349         }
   350     else
   350     else
   351         {
   351         {
   352         // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("GetBackupDataSectionL - Error\n\r"));         
   352         // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("GetBackupDataSectionL - Error\n\r"));
   353         User::Leave( KErrGeneral );
   353         User::Leave( KErrGeneral );
   354         }
   354         }
   355     
   355 
   356     // if we are finished, we can clean up the stuff otherwise not     
   356     // if we are finished, we can clean up the stuff otherwise not
   357     if( aFinished )
   357     if( aFinished )
   358         {
   358         {
   359         // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("GetBackupDataSectionL - Finished\n\r"));        
   359         // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("GetBackupDataSectionL - Finished\n\r"));
   360         CleanupStack::PopAndDestroy();           
   360         CleanupStack::PopAndDestroy();
   361         }
   361         }
   362     else
   362     else
   363         {
   363         {
   364         // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("GetBackupDataSectionL - Continues\n\r"));        
   364         // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("GetBackupDataSectionL - Continues\n\r"));
   365         CleanupStack::Pop();   
   365         CleanupStack::Pop();
   366         }              
   366         }
   367     };
   367     };
   368 
   368 
   369 // ---------------------------------------------------------
   369 // ---------------------------------------------------------
   370 // CDRMBackup::InitialiseRestoreBaseDataL
   370 // CDRMBackup::InitialiseRestoreBaseDataL
   371 // ---------------------------------------------------------
   371 // ---------------------------------------------------------
   372 // 
   372 //
   373 void CDRMBackup::InitialiseRestoreBaseDataL(TDriveNumber aDrive)
   373 void CDRMBackup::InitialiseRestoreBaseDataL(TDriveNumber aDrive)
   374     {
   374     {
   375     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("InitializeRestoreBaseDataL\n\r")); 
   375     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("InitializeRestoreBaseDataL\n\r"));
   376         
   376 
   377     // Clean up existing data:
   377     // Clean up existing data:
   378     PerformCleanup();
   378     PerformCleanup();
   379     
   379 
   380 #ifndef RD_MULTIPLE_DRIVE
   380 #ifndef RD_MULTIPLE_DRIVE
   381     
   381 
   382     // Only do a restore when restoring drive C
   382     // Only do a restore when restoring drive C
   383     if( aDrive == EDriveC )
   383     if( aDrive == EDriveC )
   384     
   384 
   385 #else //RD_MULTIPLE_DRIVE
   385 #else //RD_MULTIPLE_DRIVE
   386     
   386 
   387     TInt driveNumber( -1 );
   387     TInt driveNumber( -1 );
   388     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber );
   388     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber );
   389 	
   389 
   390     // Only do a restore when restoring drive C
   390     // Only do a restore when restoring drive C
   391     if( aDrive == driveNumber )
   391     if( aDrive == driveNumber )
   392     
   392 
   393 #endif
   393 #endif
   394         {
   394         {
   395         iStatus |= KDoBackup;
   395         iStatus |= KDoBackup;
   396         }
   396         }
   397     else
   397     else
   402 
   402 
   403 // ---------------------------------------------------------
   403 // ---------------------------------------------------------
   404 // CDRMBackup::RestoreBaseDataSectionL
   404 // CDRMBackup::RestoreBaseDataSectionL
   405 // Create the files where the restore is performed from
   405 // Create the files where the restore is performed from
   406 // ---------------------------------------------------------
   406 // ---------------------------------------------------------
   407 // 
   407 //
   408 void CDRMBackup::RestoreBaseDataSectionL(TDesC8& aBuffer, TBool aFinished)
   408 void CDRMBackup::RestoreBaseDataSectionL(TDesC8& aBuffer, TBool aFinished)
   409     {
   409     {
   410     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreBaseDataSectionL\n\r")); 
   410     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreBaseDataSectionL\n\r"));
   411         
   411 
   412     TInt seekAmount = 0;
   412     TInt seekAmount = 0;
   413     Roap::RRoapStorageClient client;
   413     Roap::RRoapStorageClient client;
   414     TFileName tempFileName;
   414     TFileName tempFileName;
   415     TPtrC8 buffer( aBuffer );
   415     TPtrC8 buffer( aBuffer );
   416         
   416 
   417     if( !(iStatus & KDoBackup ) )
   417     if( !(iStatus & KDoBackup ) )
   418         {
   418         {
   419         return;
   419         return;
   420         }
   420         }
   421         
   421 
   422      // Add the cleanup item to the cleanup stack    
   422      // Add the cleanup item to the cleanup stack
   423     TCleanupItem resetAndDestroy( CleanupData, reinterpret_cast<TAny*>(this) );
   423     TCleanupItem resetAndDestroy( CleanupData, reinterpret_cast<TAny*>(this) );
   424     CleanupStack::PushL( resetAndDestroy );        
   424     CleanupStack::PushL( resetAndDestroy );
   425         
   425 
   426     // Read the size of the first file, even if it comes in one byte chunks
   426     // Read the size of the first file, even if it comes in one byte chunks
   427     if( iPosition == 0 && iReadData < 4 && !( iStatus & KRightsSizeRead ) )
   427     if( iPosition == 0 && iReadData < 4 && !( iStatus & KRightsSizeRead ) )
   428         {
   428         {
   429         if( iReadData + buffer.Length() >= 4 )
   429         if( iReadData + buffer.Length() >= 4 )
   430             {
   430             {
   432                        buffer.Ptr(), 4-iReadData );
   432                        buffer.Ptr(), 4-iReadData );
   433             RMemReadStream stream( iSizeBuffer.Ptr(), 4 );
   433             RMemReadStream stream( iSizeBuffer.Ptr(), 4 );
   434             CleanupClosePushL( stream );
   434             CleanupClosePushL( stream );
   435             iRightsFileSize = stream.ReadInt32L();
   435             iRightsFileSize = stream.ReadInt32L();
   436             CleanupStack::PopAndDestroy();
   436             CleanupStack::PopAndDestroy();
   437             
   437 
   438             // Remove the 'used' data from the beginning of the data block
   438             // Remove the 'used' data from the beginning of the data block
   439             buffer.Set( buffer.Mid( 4-iReadData ) );
   439             buffer.Set( buffer.Mid( 4-iReadData ) );
   440             
   440 
   441             iStatus |= KRightsSizeRead;
   441             iStatus |= KRightsSizeRead;
   442              
   442 
   443             iReadData = 0;
   443             iReadData = 0;
   444             }
   444             }
   445         else
   445         else
   446             {
   446             {
   447             if( aFinished )
   447             if( aFinished )
   448                 {
   448                 {
   449                 CleanupStack::PopAndDestroy();
   449                 CleanupStack::PopAndDestroy();
   450                 return;
   450                 return;
   451                 }               
   451                 }
   452             // copy the data to the temp buffer
   452             // copy the data to the temp buffer
   453             Mem::Copy( const_cast<TUint8*>( iSizeBuffer.Ptr() ) + iReadData,
   453             Mem::Copy( const_cast<TUint8*>( iSizeBuffer.Ptr() ) + iReadData,
   454                        buffer.Ptr(), buffer.Length() );
   454                        buffer.Ptr(), buffer.Length() );
   455             iReadData += buffer.Length();
   455             iReadData += buffer.Length();
   456             CleanupStack::Pop();          
   456             CleanupStack::Pop();
   457             return;           
   457             return;
   458             }
   458             }
   459         }
   459         }
   460     
   460 
   461     // Read the size of the 2nd file when it's needed:    
   461     // Read the size of the 2nd file when it's needed:
   462     if( iPosition == iRightsFileSize && iReadData < 4 && !(iStatus & KContextSizeRead) )
   462     if( iPosition == iRightsFileSize && iReadData < 4 && !(iStatus & KContextSizeRead) )
   463         {
   463         {
   464         if( iReadData + buffer.Length() >= 4 )
   464         if( iReadData + buffer.Length() >= 4 )
   465             {
   465             {
   466             Mem::Copy( const_cast<TUint8*>( iSizeBuffer.Ptr() ) + iReadData,
   466             Mem::Copy( const_cast<TUint8*>( iSizeBuffer.Ptr() ) + iReadData,
   467                        buffer.Ptr(), 4-iReadData );
   467                        buffer.Ptr(), 4-iReadData );
   468             RMemReadStream stream( iSizeBuffer.Ptr(), 4 );
   468             RMemReadStream stream( iSizeBuffer.Ptr(), 4 );
   469             CleanupClosePushL( stream );
   469             CleanupClosePushL( stream );
   470             iContextFileSize = stream.ReadInt32L();
   470             iContextFileSize = stream.ReadInt32L();
   471             CleanupStack::PopAndDestroy();
   471             CleanupStack::PopAndDestroy();
   472             
   472 
   473             // Remove the 'used' data from the beginning of the data block
   473             // Remove the 'used' data from the beginning of the data block
   474             buffer.Set( buffer.Mid( 4-iReadData ) );
   474             buffer.Set( buffer.Mid( 4-iReadData ) );
   475             
   475 
   476             iStatus |= KContextSizeRead;
   476             iStatus |= KContextSizeRead;
   477             iReadData = 0;
   477             iReadData = 0;
   478 
   478 
   479             }
   479             }
   480         else
   480         else
   481             {
   481             {
   482             if( aFinished )
   482             if( aFinished )
   483                 {
   483                 {
   484                 // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreBaseDataSectionL : buggy file(1)\n\r"));                
   484                 // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreBaseDataSectionL : buggy file(1)\n\r"));
   485                 CleanupStack::PopAndDestroy();
   485                 CleanupStack::PopAndDestroy();
   486                 return;
   486                 return;
   487                 }             
   487                 }
   488             // copy the data to the temp buffer
   488             // copy the data to the temp buffer
   489             Mem::Copy( const_cast<TUint8*>( iSizeBuffer.Ptr()) + iReadData,
   489             Mem::Copy( const_cast<TUint8*>( iSizeBuffer.Ptr()) + iReadData,
   490                        buffer.Ptr(), buffer.Length() );
   490                        buffer.Ptr(), buffer.Length() );
   491             iReadData += buffer.Length();
   491             iReadData += buffer.Length();
   492             CleanupStack::Pop();           
   492             CleanupStack::Pop();
   493             return;           
   493             return;
   494             }       
   494             }
   495         }
   495         }
   496         
   496 
   497     // Restore the two files:
   497     // Restore the two files:
   498     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreBaseDataSectionL : before restore\n\r"));
   498     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreBaseDataSectionL : before restore\n\r"));
   499         
   499 
   500     if( iPosition < iRightsFileSize )
   500     if( iPosition < iRightsFileSize )
   501         {
   501         {
   502         // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreBaseDataSectionL : restore starts\n\r"));
   502         // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreBaseDataSectionL : restore starts\n\r"));
   503         if( !( iStatus & KRightsFileOpen ) )
   503         if( !( iStatus & KRightsFileOpen ) )
   504             {
   504             {
   505             // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreBaseDataSectionL : replace the file\n\r"));            
   505             // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreBaseDataSectionL : replace the file\n\r"));
   506             User::LeaveIfError( iRightsBackupFile.Replace( iFileServer,
   506             User::LeaveIfError( iRightsBackupFile.Replace( iFileServer,
   507                                                            iRightsFileName,
   507                                                            iRightsFileName,
   508                                                            EFileRead|EFileWrite ) );
   508                                                            EFileRead|EFileWrite ) );
   509             iStatus |= KRightsFileOpen;
   509             iStatus |= KRightsFileOpen;
   510             // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreBaseDataSectionL : write startn\r"));                                            
   510             // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreBaseDataSectionL : write startn\r"));
   511             iRightsBackupFile.Write( iSizeBuffer, 4 );
   511             iRightsBackupFile.Write( iSizeBuffer, 4 );
   512             // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreBaseDataSectionL : write end\n\r"));            
   512             // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreBaseDataSectionL : write end\n\r"));
   513             iPosition += 4;
   513             iPosition += 4;
   514             }
   514             }
   515     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreBaseDataSectionL : before seek\n\r"));            
   515     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreBaseDataSectionL : before seek\n\r"));
   516         // Find the right position    
   516         // Find the right position
   517         User::LeaveIfError( iRightsBackupFile.Seek( ESeekStart,iPosition ) );
   517         User::LeaveIfError( iRightsBackupFile.Seek( ESeekStart,iPosition ) );
   518         
   518 
   519         
   519 
   520     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreBaseDataSectionL : after seek\n\r"));        
   520     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreBaseDataSectionL : after seek\n\r"));
   521         // Read data
   521         // Read data
   522         User::LeaveIfError( iRightsBackupFile.Write( buffer ) );
   522         User::LeaveIfError( iRightsBackupFile.Write( buffer ) );
   523         
   523 
   524     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreBaseDataSectionL : after write\n\r"));        
   524     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreBaseDataSectionL : after write\n\r"));
   525         iPosition += buffer.Length();
   525         iPosition += buffer.Length();
   526         }
   526         }
   527     else if( iPosition < iRightsFileSize + iContextFileSize )
   527     else if( iPosition < iRightsFileSize + iContextFileSize )
   528         {
   528         {
   529                
   529 
   530         // Open the file if it's not open
   530         // Open the file if it's not open
   531         if( !( iStatus & KContextFileOpen ) )
   531         if( !( iStatus & KContextFileOpen ) )
   532             {
   532             {
   533             User::LeaveIfError( iContextBackupFile.Replace( iFileServer,
   533             User::LeaveIfError( iContextBackupFile.Replace( iFileServer,
   534                                                             iContextFileName, 
   534                                                             iContextFileName,
   535                                                             EFileRead|EFileWrite ) );
   535                                                             EFileRead|EFileWrite ) );
   536             iStatus |= KContextFileOpen;                                                             
   536             iStatus |= KContextFileOpen;
   537             iContextBackupFile.Write( iSizeBuffer, 4 );
   537             iContextBackupFile.Write( iSizeBuffer, 4 );
   538             iPosition += 4;
   538             iPosition += 4;
   539             }
   539             }
   540             
   540 
   541         // Find the right position
   541         // Find the right position
   542         seekAmount = iPosition-iRightsFileSize;  
   542         seekAmount = iPosition-iRightsFileSize;
   543         iContextBackupFile.Seek( ESeekStart, seekAmount );
   543         iContextBackupFile.Seek( ESeekStart, seekAmount );
   544         
   544 
   545         // Read data
   545         // Read data
   546         User::LeaveIfError( iContextBackupFile.Write( buffer ) );
   546         User::LeaveIfError( iContextBackupFile.Write( buffer ) );
   547         
   547 
   548         iPosition += buffer.Length();
   548         iPosition += buffer.Length();
   549         }
   549         }
   550     else
   550     else
   551         {
   551         {
   552         // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreBaseDataSectionL : error\n\r"));        
   552         // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreBaseDataSectionL : error\n\r"));
   553         User::Leave( KErrGeneral );
   553         User::Leave( KErrGeneral );
   554         }
   554         }
   555   
   555 
   556     CleanupStack::Pop();         
   556     CleanupStack::Pop();
   557     };
   557     };
   558 
   558 
   559 // ---------------------------------------------------------
   559 // ---------------------------------------------------------
   560 // CDRMBackup::InitialiseRestoreIncrementDataL
   560 // CDRMBackup::InitialiseRestoreIncrementDataL
   561 // ---------------------------------------------------------
   561 // ---------------------------------------------------------
   562 // 
   562 //
   563 void CDRMBackup::InitialiseRestoreIncrementDataL(TDriveNumber /* aDrive */)
   563 void CDRMBackup::InitialiseRestoreIncrementDataL(TDriveNumber /* aDrive */)
   564     {
   564     {
   565     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("init incremental restore\n\r"));        
   565     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("init incremental restore\n\r"));
   566     User::Leave( KErrNotSupported );
   566     User::Leave( KErrNotSupported );
   567     };
   567     };
   568 
   568 
   569 // ---------------------------------------------------------
   569 // ---------------------------------------------------------
   570 // CDRMBackup::RestoreIncrementDataSectionL
   570 // CDRMBackup::RestoreIncrementDataSectionL
   571 // ---------------------------------------------------------
   571 // ---------------------------------------------------------
   572 //
   572 //
   573 void CDRMBackup::RestoreIncrementDataSectionL(TDesC8& /* aBuffer */, TBool /* aFinished */)
   573 void CDRMBackup::RestoreIncrementDataSectionL(TDesC8& /* aBuffer */, TBool /* aFinished */)
   574     {
   574     {
   575     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("restore incremenetal\n\r"));        
   575     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("restore incremenetal\n\r"));
   576     User::Leave( KErrNotSupported );
   576     User::Leave( KErrNotSupported );
   577     };
   577     };
   578 
   578 
   579 // ---------------------------------------------------------
   579 // ---------------------------------------------------------
   580 // CDRMBackup::RestoreComplete
   580 // CDRMBackup::RestoreComplete
   581 // This function performs the actual restoring
   581 // This function performs the actual restoring
   582 // ---------------------------------------------------------
   582 // ---------------------------------------------------------
   583 // 
   583 //
   584 void CDRMBackup::RestoreComplete(TDriveNumber aDrive)
   584 void CDRMBackup::RestoreComplete(TDriveNumber aDrive)
   585     {
   585     {
   586     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreComplete\n\r"));     
   586     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreComplete\n\r"));
   587     TInt error = KErrNone;
   587     TInt error = KErrNone;
   588     TBool doUdt = EFalse;
   588     TBool doUdt = EFalse;
   589     
   589 
   590 #ifndef RD_MULTIPLE_DRIVE
   590 #ifndef RD_MULTIPLE_DRIVE
   591     
   591 
   592     // Only do a backup when backing up drive C
   592     // Only do a backup when backing up drive C
   593     if( aDrive != EDriveC )
   593     if( aDrive != EDriveC )
   594     
   594 
   595 #else //RD_MULTIPLE_DRIVE
   595 #else //RD_MULTIPLE_DRIVE
   596     
   596 
   597     TInt driveNumber( -1 );
   597     TInt driveNumber( -1 );
   598     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber );
   598     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber );
   599 	
   599 
   600     // Only do a backup when backing up drive C
   600     // Only do a backup when backing up drive C
   601     if( aDrive != driveNumber )
   601     if( aDrive != driveNumber )
   602     
   602 
   603 #endif
   603 #endif
   604         {
   604         {
   605         // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreComplete : not Drive C\n\r"));         
   605         // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("RestoreComplete : not Drive C\n\r"));
   606         return;
   606         return;
   607         }
   607         }
   608     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("PerformRightsMergeL\n\r")); 
   608     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("PerformRightsMergeL\n\r"));
   609 
   609 
   610     
   610 
   611 
   611 
   612     // Merge the rights    
   612     // Merge the rights
   613     TRAP( error, PerformRightsMergeL() );
   613     TRAP( error, PerformRightsMergeL() );
   614     if( error )
   614     if( error )
   615         {
   615         {
   616         if( error == KErrPermissionDenied )
   616         if( error == KErrPermissionDenied )
   617             {
   617             {
   618             doUdt = ETrue;                 
   618             doUdt = ETrue;
   619             }
   619             }
   620         // Log some error
   620         // Log some error
   621         error = KErrNone;
   621         error = KErrNone;
   622         }
   622         }
   623     
   623 
   624     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("PerformContextMergeL\n\r"));     
   624     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("PerformContextMergeL\n\r"));
   625 
   625 
   626     // Merge the Contexts
   626     // Merge the Contexts
   627     TRAP( error, PerformContextMergeL() );
   627     TRAP( error, PerformContextMergeL() );
   628     if( error )
   628     if( error )
   629         {
   629         {
   630         // Log some error
   630         // Log some error
   631         error = KErrNone;        
   631         error = KErrNone;
   632         }
   632         }
   633         
   633 
   634     PerformCleanup( doUdt );                
   634     PerformCleanup( doUdt );
   635     };
   635     };
   636 
   636 
   637 // ---------------------------------------------------------
   637 // ---------------------------------------------------------
   638 // CDRMBackup::TerminateMultiStageOperation
   638 // CDRMBackup::TerminateMultiStageOperation
   639 // ---------------------------------------------------------
   639 // ---------------------------------------------------------
   640 // 
   640 //
   641 void CDRMBackup::TerminateMultiStageOperation()
   641 void CDRMBackup::TerminateMultiStageOperation()
   642     {
   642     {
   643     PerformCleanup();
   643     PerformCleanup();
   644     };
   644     };
   645 
   645 
   646 // ---------------------------------------------------------
   646 // ---------------------------------------------------------
   647 // CDRMBackup::GetDataChecksum
   647 // CDRMBackup::GetDataChecksum
   648 // ---------------------------------------------------------
   648 // ---------------------------------------------------------
   649 // 
   649 //
   650 TUint CDRMBackup::GetDataChecksum(TDriveNumber /* aDrive */)
   650 TUint CDRMBackup::GetDataChecksum(TDriveNumber /* aDrive */)
   651     {
   651     {
   652     return 0;
   652     return 0;
   653     };
   653     };
   654        
   654 
   655 // ---------------------------------------------------------
   655 // ---------------------------------------------------------
   656 // CDRMBackup::CreateRightsBackupFileL
   656 // CDRMBackup::CreateRightsBackupFileL
   657 // ---------------------------------------------------------
   657 // ---------------------------------------------------------
   658 // 
   658 //
   659 void CDRMBackup::CreateRightsBackupFileL()
   659 void CDRMBackup::CreateRightsBackupFileL()
   660     {
   660     {
   661     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("Create backup file\n\r"));    
   661     // RFileLogger::Write(KLogDir, KLogName, EFileLoggingModeAppend, _L8("Create backup file\n\r"));
   662      
   662 
   663     // Open the file and get the filename
   663     // Open the file and get the filename
   664     User::LeaveIfError( iRightsBackupFile.Replace( iFileServer,
   664     User::LeaveIfError( iRightsBackupFile.Replace( iFileServer,
   665                                                    iRightsFileName,
   665                                                    iRightsFileName,
   666                                                    EFileRead|EFileWrite ) );                                        
   666                                                    EFileRead|EFileWrite ) );
   667     iStatus |= KRightsFileOpen; 
   667     iStatus |= KRightsFileOpen;
   668                                                         
   668 
   669     iDRMRightsDB->BackupContentToFileL( iRightsBackupFile, KNullDesC8 );
   669     iDRMRightsDB->BackupContentToFileL( iRightsBackupFile, KNullDesC8 );
   670     
   670 
   671     User::LeaveIfError( iRightsBackupFile.Size( iRightsFileSize ) );
   671     User::LeaveIfError( iRightsBackupFile.Size( iRightsFileSize ) );
   672     };
   672     };
   673 
   673 
   674 // ---------------------------------------------------------
   674 // ---------------------------------------------------------
   675 // CDRMBackup::CreateContextBackupFileL
   675 // CDRMBackup::CreateContextBackupFileL
   676 // ---------------------------------------------------------
   676 // ---------------------------------------------------------
   677 // 
   677 //
   678 void CDRMBackup::CreateContextBackupFileL()
   678 void CDRMBackup::CreateContextBackupFileL()
   679     {
   679     {
   680     //Roap::RRoapStorageClient client;
   680     //Roap::RRoapStorageClient client;
   681 
   681 
   682     // Open the file and get the filename
   682     // Open the file and get the filename
   683 /*    User::LeaveIfError( iContextBackupFile.Replace( iFileServer,
   683 /*    User::LeaveIfError( iContextBackupFile.Replace( iFileServer,
   684                                                     iContextFileName,
   684                                                     iContextFileName,
   685                                                     EFileRead|EFileWrite ) );  
   685                                                     EFileRead|EFileWrite ) );
   686 
   686 
   687     iStatus |= KContextFileOpen;
   687     iStatus |= KContextFileOpen;
   688 */        
   688 */
   689     // Connect to the roap storage server                               
   689     // Connect to the roap storage server
   690     //User::LeaveIfError( client.Connect() );
   690     //User::LeaveIfError( client.Connect() );
   691     //CleanupClosePushL( client );
   691     //CleanupClosePushL( client );
   692     
   692 
   693     //client.BackupContentToFileL( iContextBackupFile, KNullDesC8 );
   693     //client.BackupContentToFileL( iContextBackupFile, KNullDesC8 );
   694     };
   694     };
   695 
   695 
   696 // ---------------------------------------------------------
   696 // ---------------------------------------------------------
   697 // CDRMBackup::PerformRightsMergeL
   697 // CDRMBackup::PerformRightsMergeL
   698 // ---------------------------------------------------------
   698 // ---------------------------------------------------------
   699 // 
   699 //
   700 void CDRMBackup::PerformRightsMergeL()
   700 void CDRMBackup::PerformRightsMergeL()
   701     {
   701     {
   702     if( iStatus & KRightsFileOpen )
   702     if( iStatus & KRightsFileOpen )
   703         {
   703         {
   704         iDRMRightsDB->RestoreContentFromFileL( iRightsBackupFile, KNullDesC8, 
   704         iDRMRightsDB->RestoreContentFromFileL( iRightsBackupFile, KNullDesC8,
   705                                                KDRMNormalBackup );
   705                                                KDRMNormalBackup );
   706         }
   706         }
   707     else 
   707     else
   708         {
   708         {
   709         User::Leave(KErrNotReady);    
   709         User::Leave(KErrNotReady);
   710         }
   710         }
   711     };
   711     };
   712 
   712 
   713 // ---------------------------------------------------------
   713 // ---------------------------------------------------------
   714 // CDRMBackup::PerformContextMergeL
   714 // CDRMBackup::PerformContextMergeL
   715 // ---------------------------------------------------------
   715 // ---------------------------------------------------------
   716 // 
   716 //
   717 void CDRMBackup::PerformContextMergeL()
   717 void CDRMBackup::PerformContextMergeL()
   718     {
   718     {
   719     //Roap::RRoapStorageClient client;
   719     //Roap::RRoapStorageClient client;
   720                                       
   720 
   721     // Connect to the roap storage server 
   721     // Connect to the roap storage server
   722     //User::LeaveIfError( client.Connect() );
   722     //User::LeaveIfError( client.Connect() );
   723     //CleanupClosePushL( client );
   723     //CleanupClosePushL( client );
   724 
   724 
   725     //client.RestoreContentFromFileL( iContextBackupFile, KNullDesC8 );
   725     //client.RestoreContentFromFileL( iContextBackupFile, KNullDesC8 );
   726     
   726 
   727     //CleanupStack::PopAndDestroy();// client
   727     //CleanupStack::PopAndDestroy();// client
   728     };
   728     };
   729 
   729 
   730 // ---------------------------------------------------------
   730 // ---------------------------------------------------------
   731 // CDRMBackup::PerformCleanup
   731 // CDRMBackup::PerformCleanup
   732 // ---------------------------------------------------------
   732 // ---------------------------------------------------------
   733 // 
   733 //
   734 void CDRMBackup::PerformCleanup( TBool aUdt )
   734 void CDRMBackup::PerformCleanup( TBool aUdt )
   735     {
   735     {
   736     iRightsFileSize = 0;
   736     iRightsFileSize = 0;
   737     iContextFileSize = 0;
   737     iContextFileSize = 0;
   738     
   738 
   739     if( iStatus & KRightsFileOpen ) 
   739     if( iStatus & KRightsFileOpen )
   740         {
   740         {
   741         if( !aUdt ) 
   741         if( !aUdt )
   742             {
   742             {
   743             iRightsBackupFile.SetSize(0);                
   743             iRightsBackupFile.SetSize(0);
   744             }
   744             }
   745 
   745 
   746         iRightsBackupFile.Close();
   746         iRightsBackupFile.Close();
   747         
   747 
   748         if( !aUdt )
   748         if( !aUdt )
   749             {
   749             {
   750             iFileServer.Delete( iRightsFileName );                 
   750             iFileServer.Delete( iRightsFileName );
   751             }
   751             }
   752         }
   752         }
   753         
   753 
   754     if( iStatus & KContextFileOpen ) 
   754     if( iStatus & KContextFileOpen )
   755         {
   755         {
   756         if( !aUdt )
   756         if( !aUdt )
   757             {
   757             {
   758             iContextBackupFile.SetSize(0);                
   758             iContextBackupFile.SetSize(0);
   759             }
   759             }
   760 
   760 
   761         iContextBackupFile.Close();   
   761         iContextBackupFile.Close();
   762              
   762 
   763         if( !aUdt )
   763         if( !aUdt )
   764             {
   764             {
   765             iFileServer.Delete( iContextFileName );                          
   765             iFileServer.Delete( iContextFileName );
   766             } 
   766             }
   767         }
   767         }
   768 
   768 
   769     iPosition = 0;
   769     iPosition = 0;
   770     Mem::FillZ(const_cast<TUint8*>(iSizeBuffer.Ptr()), 4);
   770     Mem::FillZ(const_cast<TUint8*>(iSizeBuffer.Ptr()), 4);
   771     iReadData = 0;
   771     iReadData = 0;