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