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: CMMCScBkupStateArchiveOpPublicDataFiles implementation |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 #include "CMMCScBkupStateArchiveOpPublicDataFiles.h" |
|
20 |
|
21 // System includes |
|
22 #include <e32std.h> |
|
23 #include <s32strm.h> |
|
24 #include <s32mem.h> |
|
25 |
|
26 // User includes |
|
27 #include "MMCScBkupLogger.h" |
|
28 #include "MMCScBkupConfig.h" |
|
29 #include "CMMCScBkupArchive.h" |
|
30 #include "CMMCScBkupArchiveFooter.h" |
|
31 #include "CMMCScBkupIndexPublicDataFiles.h" |
|
32 #include "MMMCScBkupArchiveDataInterface.h" |
|
33 #include "CMMCScBkupFileInfo.h" |
|
34 #include "CMMCScBkupFileListCollection.h" |
|
35 #include "CMMCScBkupDataOwnerInfo.h" |
|
36 #include "CMMCScBkupDataOwnerCollection.h" |
|
37 #include "MMCScBkupOperations.h" |
|
38 |
|
39 // ========================= MEMBER FUNCTIONS ================================ |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // CMMCScBkupStateArchiveOpPublicDataFiles::CMMCScBkupStateArchiveOpPublicDataFiles() |
|
43 // |
|
44 // C++ constructor. |
|
45 // --------------------------------------------------------------------------- |
|
46 CMMCScBkupStateArchiveOpPublicDataFiles::CMMCScBkupStateArchiveOpPublicDataFiles( MMMCScBkupDriver& aDriver ) |
|
47 : CMMCScBkupStateOpAware( aDriver ), iIndexValueCurrent( -1 ) |
|
48 { |
|
49 __LOG1("CMMCScBkupStateArchiveOpPublicDataFiles::CMMCScBkupStateArchiveOpPublicDataFiles() - 0x%08x", StateId().iUid ); |
|
50 } |
|
51 |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // CMMCScBkupStateArchiveOpPublicDataFiles::NewL() |
|
55 // |
|
56 // |
|
57 // --------------------------------------------------------------------------- |
|
58 CMMCScBkupStateArchiveOpPublicDataFiles* CMMCScBkupStateArchiveOpPublicDataFiles::NewL( MMMCScBkupDriver& aDriver ) |
|
59 { |
|
60 CMMCScBkupStateArchiveOpPublicDataFiles* self = new(ELeave) CMMCScBkupStateArchiveOpPublicDataFiles( aDriver ); |
|
61 return self; |
|
62 } |
|
63 |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // CMMCScBkupStateArchiveOpPublicDataFiles::StateId() |
|
67 // |
|
68 // |
|
69 // --------------------------------------------------------------------------- |
|
70 TMMCScBkupStateId CMMCScBkupStateArchiveOpPublicDataFiles::StateId() const |
|
71 { |
|
72 return KMMCScBkupStateIdArchiveOpPublicDataFiles; |
|
73 } |
|
74 |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // CMMCScBkupStateArchiveOpPublicDataFiles::NextStateBackupId() |
|
78 // |
|
79 // |
|
80 // --------------------------------------------------------------------------- |
|
81 TMMCScBkupStateId CMMCScBkupStateArchiveOpPublicDataFiles::NextStateBackupId( TBool /*aPartial*/ ) const |
|
82 { |
|
83 return KMMCScBkupStateIdArchiveOpSystemData; |
|
84 } |
|
85 |
|
86 |
|
87 // --------------------------------------------------------------------------- |
|
88 // CMMCScBkupStateArchiveOpPublicDataFiles::NextStateRestoreId() |
|
89 // |
|
90 // |
|
91 // --------------------------------------------------------------------------- |
|
92 TMMCScBkupStateId CMMCScBkupStateArchiveOpPublicDataFiles::NextStateRestoreId( TBool /*aPartial*/ ) const |
|
93 { |
|
94 return KMMCScBkupStateIdOperationComplete; |
|
95 } |
|
96 |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // CMMCScBkupStateArchiveOpPublicDataFiles::PerformStateInitBackupL() |
|
100 // |
|
101 // |
|
102 // --------------------------------------------------------------------------- |
|
103 void CMMCScBkupStateArchiveOpPublicDataFiles::PerformStateInitBackupL( TBool /*aPartial*/ ) |
|
104 { |
|
105 __DEBUG_TESTING_SKIP_BACKUP_PUB_DATA; |
|
106 |
|
107 CompleteSelf(); |
|
108 SetState( EStateCommonKickOff ); |
|
109 } |
|
110 |
|
111 |
|
112 // --------------------------------------------------------------------------- |
|
113 // CMMCScBkupStateArchiveOpPublicDataFiles::PerformStateInitRestoreL() |
|
114 // |
|
115 // |
|
116 // --------------------------------------------------------------------------- |
|
117 void CMMCScBkupStateArchiveOpPublicDataFiles::PerformStateInitRestoreL( TBool /*aPartial*/ ) |
|
118 { |
|
119 __DEBUG_TESTING_SKIP_RESTORE_PUB_DATA; |
|
120 |
|
121 CompleteSelf(); |
|
122 SetState( EStateCommonKickOff ); |
|
123 } |
|
124 |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // CMMCScBkupStateArchiveOpPublicDataFiles::PerformAsynchronousStateStepBackupL() |
|
128 // |
|
129 // |
|
130 // --------------------------------------------------------------------------- |
|
131 void CMMCScBkupStateArchiveOpPublicDataFiles::PerformAsynchronousStateStepBackupL( TBool /*aPartial*/ ) |
|
132 { |
|
133 const TState justFinishedExecutingState = State(); |
|
134 // |
|
135 switch( justFinishedExecutingState ) |
|
136 { |
|
137 case EStateCommonKickOff: |
|
138 CompressingAndWritingFileL(); |
|
139 break; |
|
140 case EStateCommonProcessingFile: |
|
141 AddIndexRecordL(); |
|
142 break; |
|
143 case EStateBackupAddIndexRecord: |
|
144 SetState( EStateCommonKickOff ); |
|
145 CompleteSelf(); |
|
146 break; |
|
147 default: |
|
148 ASSERT( EFalse ); |
|
149 break; |
|
150 } |
|
151 } |
|
152 |
|
153 |
|
154 // --------------------------------------------------------------------------- |
|
155 // CMMCScBkupStateArchiveOpPublicDataFiles::PerformAsynchronousStateStepRestoreL() |
|
156 // |
|
157 // |
|
158 // --------------------------------------------------------------------------- |
|
159 void CMMCScBkupStateArchiveOpPublicDataFiles::PerformAsynchronousStateStepRestoreL( TBool /*aPartial*/ ) |
|
160 { |
|
161 const TState justFinishedExecutingState = State(); |
|
162 // |
|
163 switch( justFinishedExecutingState ) |
|
164 { |
|
165 case EStateCommonKickOff: |
|
166 DecompressingAndWritingFileL(); |
|
167 break; |
|
168 case EStateCommonProcessingFile: |
|
169 RestoreFileAttributesL(); |
|
170 break; |
|
171 case EStateRestoreResetAttributes: |
|
172 SetState( EStateCommonKickOff ); |
|
173 CompleteSelf(); |
|
174 break; |
|
175 default: |
|
176 ASSERT( EFalse ); |
|
177 break; |
|
178 } |
|
179 } |
|
180 |
|
181 |
|
182 // --------------------------------------------------------------------------- |
|
183 // CMMCScBkupStateArchiveOpPublicDataFiles::PerformAsynchronousErrorCleanupBackup() |
|
184 // |
|
185 // |
|
186 // --------------------------------------------------------------------------- |
|
187 TBool CMMCScBkupStateArchiveOpPublicDataFiles::PerformAsynchronousErrorCleanupBackup( TBool /*aPartial*/, TInt aError ) |
|
188 { |
|
189 (void) aError; |
|
190 __LOG1("CMMCScBkupStateArchiveOpPublicDataFiles::PerformAsynchronousErrorCleanupBackup() - **** - error: %d", aError ); |
|
191 TBool continueProcessing = ETrue; |
|
192 |
|
193 // Reset state and move to next item. Treat the current (badly behaving) item |
|
194 // as completed/processed. |
|
195 const CMMCScBkupFileListCollection& fileList = Driver().DrvFileList(); |
|
196 if ( iIndexValueCurrent < fileList.Count() ) |
|
197 { |
|
198 const CMMCScBkupFileInfo& fileInfo = fileList.Entry(iIndexValueCurrent); |
|
199 (void) fileInfo; |
|
200 |
|
201 __LOGFILE2("CMMCScBkupStateArchiveOpPublicDataFiles::PerformAsynchronousErrorCleanupBackup() - **** - error: %d, file: %S - public data skipped", aError, &fileInfo.FileName()); |
|
202 |
|
203 // Ensures that asynchronous state step is called again.. |
|
204 CompleteSelf(); |
|
205 SetState( EStateCommonKickOff ); |
|
206 } |
|
207 |
|
208 return continueProcessing; |
|
209 } |
|
210 |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 // CMMCScBkupStateArchiveOpPublicDataFiles::PerformAsynchronousErrorCleanupRestore() |
|
214 // |
|
215 // |
|
216 // --------------------------------------------------------------------------- |
|
217 TBool CMMCScBkupStateArchiveOpPublicDataFiles::PerformAsynchronousErrorCleanupRestore( TBool /*aPartial*/, TInt aError ) |
|
218 { |
|
219 (void) aError; |
|
220 __LOG1("CMMCScBkupStateArchiveOpPublicDataFiles::PerformAsynchronousErrorCleanupRestore() - **** - error: %d", aError ); |
|
221 TBool continueProcessing = ETrue; |
|
222 |
|
223 CMMCScBkupArchiveFooter& footer = Driver().DrvArchive().Footer(); |
|
224 CMMCScBkupIndexPublicDataFiles& index = static_cast<CMMCScBkupIndexPublicDataFiles&>( footer.IndexByType( EMMCScBkupOwnerDataTypePublicData ) ); |
|
225 const TInt count = index.Count(); |
|
226 // |
|
227 if ( iIndexValueCurrent < count ) |
|
228 { |
|
229 // Get the entry to restore |
|
230 TMMCScBkupArchiveVector entryInfo; |
|
231 const CMMCScBkupFileInfo& fileInfo = index.At( iIndexValueCurrent, entryInfo ); |
|
232 (void) fileInfo; |
|
233 |
|
234 __LOGFILE2("CMMCScBkupStateArchiveOpPublicDataFiles::PerformAsynchronousErrorCleanupRestore() - **** - error: %d, file: %S - public data skipped", aError, &fileInfo.FileName()); |
|
235 |
|
236 // Try to restore the next public file |
|
237 //SetState( EStateCommonKickOff ); |
|
238 SetState( EStateCommonProcessingFile ); |
|
239 CompleteSelf(); |
|
240 } |
|
241 |
|
242 return continueProcessing; |
|
243 } |
|
244 |
|
245 |
|
246 // --------------------------------------------------------------------------- |
|
247 // CMMCScBkupStateArchiveOpPublicDataFiles::PerformAsynchronousCancellation() |
|
248 // |
|
249 // |
|
250 // --------------------------------------------------------------------------- |
|
251 void CMMCScBkupStateArchiveOpPublicDataFiles::PerformAsynchronousCancellation() |
|
252 { |
|
253 switch( State() ) |
|
254 { |
|
255 case EStateCommonProcessingFile: |
|
256 // Asynchronous request issued to ADI. |
|
257 Driver().DrvADI().ADIAsynchronousCancel(); |
|
258 break; |
|
259 |
|
260 case EStateCommonKickOff: |
|
261 case EStateBackupAddIndexRecord: |
|
262 case EStateRestoreResetAttributes: |
|
263 // Other states complete this objects own request status => no action |
|
264 // needed. |
|
265 break; |
|
266 |
|
267 default: |
|
268 case EStateCommonIdle: |
|
269 ASSERT( EFalse ); |
|
270 } |
|
271 } |
|
272 |
|
273 |
|
274 // --------------------------------------------------------------------------- |
|
275 // CMMCScBkupStateArchiveOpPublicDataFiles::PerformLastRightsBackupL() |
|
276 // |
|
277 // |
|
278 // --------------------------------------------------------------------------- |
|
279 void CMMCScBkupStateArchiveOpPublicDataFiles::PerformLastRightsBackupL( TBool /*aPartial*/ ) |
|
280 { |
|
281 CMMCScBkupIndexBase& index = Driver().DrvArchive().Footer().IndexByType( EMMCScBkupOwnerDataTypePublicData ); |
|
282 index.StoreL( Driver() ); |
|
283 |
|
284 Driver().DrvADI().ADIResetResources(EMMCScBkupOperationTypeFullBackup); |
|
285 } |
|
286 |
|
287 |
|
288 // --------------------------------------------------------------------------- |
|
289 // CMMCScBkupStateArchiveOpPublicDataFiles::PerformLastRightsRestoreL() |
|
290 // |
|
291 // |
|
292 // --------------------------------------------------------------------------- |
|
293 void CMMCScBkupStateArchiveOpPublicDataFiles::PerformLastRightsRestoreL( TBool /*aPartial*/ ) |
|
294 { |
|
295 Driver().DrvADI().ADIResetResources(EMMCScBkupOperationTypeFullRestore); |
|
296 } |
|
297 |
|
298 |
|
299 // --------------------------------------------------------------------------- |
|
300 // CMMCScBkupStateArchiveOpPublicDataFiles::CompressingAndWritingFileL() |
|
301 // |
|
302 // |
|
303 // --------------------------------------------------------------------------- |
|
304 void CMMCScBkupStateArchiveOpPublicDataFiles::CompressingAndWritingFileL() |
|
305 { |
|
306 const CMMCScBkupFileListCollection& fileList = Driver().DrvFileList(); |
|
307 const TInt count = fileList.Count(); |
|
308 // |
|
309 if ( ++iIndexValueCurrent < count ) |
|
310 { |
|
311 const CMMCScBkupFileInfo& fileInfo = fileList.Entry(iIndexValueCurrent); |
|
312 |
|
313 __LOG1("CMMCScBkupStateArchiveOpPublicDataFiles::CompressingAndWritingFileL() - BACKUP - compressing file: %S", &fileInfo.FileName()); |
|
314 |
|
315 // Compress the file & externalise it to the archive |
|
316 Driver().DrvADI().ADIWriteFileL( fileInfo.FileName(), iStatus ); |
|
317 |
|
318 // Indicate the state we are in |
|
319 SetActive(); |
|
320 SetState( EStateCommonProcessingFile ); |
|
321 } |
|
322 } |
|
323 |
|
324 |
|
325 // --------------------------------------------------------------------------- |
|
326 // CMMCScBkupStateArchiveOpPublicDataFiles::DecompressingAndWritingFileL() |
|
327 // |
|
328 // |
|
329 // --------------------------------------------------------------------------- |
|
330 void CMMCScBkupStateArchiveOpPublicDataFiles::DecompressingAndWritingFileL() |
|
331 { |
|
332 CMMCScBkupArchiveFooter& footer = Driver().DrvArchive().Footer(); |
|
333 CMMCScBkupIndexPublicDataFiles& index = static_cast<CMMCScBkupIndexPublicDataFiles&>( footer.IndexByType( EMMCScBkupOwnerDataTypePublicData ) ); |
|
334 const TInt count = index.Count(); |
|
335 // |
|
336 if ( ++iIndexValueCurrent < count ) |
|
337 { |
|
338 // Get the entry to restore |
|
339 TMMCScBkupArchiveVector entryInfo; |
|
340 const CMMCScBkupFileInfo& fileInfo = index.At( iIndexValueCurrent, entryInfo ); |
|
341 |
|
342 __LOG3("CMMCScBkupStateArchiveOpPublicDataFiles::DecompressingAndWritingFileL() - RESTORE - decompressing file: %S, offset: %8d, length: %8d", &fileInfo.FileName(), entryInfo.Offset(), entryInfo.Length()); |
|
343 |
|
344 // Restore it! |
|
345 Driver().DrvADI().ADIReadFileL( fileInfo.FileName(), entryInfo, iStatus ); |
|
346 |
|
347 // Indicate the state we are in |
|
348 SetActive(); |
|
349 SetState( EStateCommonProcessingFile ); |
|
350 } |
|
351 } |
|
352 |
|
353 |
|
354 // --------------------------------------------------------------------------- |
|
355 // CMMCScBkupStateArchiveOpPublicDataFiles::AddIndexRecordL() |
|
356 // |
|
357 // |
|
358 // --------------------------------------------------------------------------- |
|
359 void CMMCScBkupStateArchiveOpPublicDataFiles::AddIndexRecordL() |
|
360 { |
|
361 CMMCScBkupDataOwnerCollection& dataOwners = Driver().DrvDataOwners(); |
|
362 CMMCScBkupArchiveFooter& footer = Driver().DrvArchive().Footer(); |
|
363 CMMCScBkupIndexPublicDataFiles& index = static_cast<CMMCScBkupIndexPublicDataFiles&>(footer.IndexByType(EMMCScBkupOwnerDataTypePublicData)); |
|
364 const CMMCScBkupFileListCollection& fileList = Driver().DrvFileList(); |
|
365 const CMMCScBkupFileInfo& fileInfo = fileList.Entry(iIndexValueCurrent); |
|
366 |
|
367 // Save the offset of the data owner |
|
368 const TMMCScBkupArchiveVector& info = Driver().DrvADI().ADICurrentArchiveVectorInfo(); |
|
369 index.AddIndexRecordL( info, fileInfo ); |
|
370 |
|
371 // And update the file info so that we can know how much compressed |
|
372 // data must be read during restore. This allows us to report accurate |
|
373 // progress info. See CMMCScBkupStateRequestListOfPublicFiles::PerformLastRightsL() |
|
374 // for the point when the public data size is zeroed. |
|
375 |
|
376 // First, find the associated data owner. |
|
377 CMMCScBkupDataOwnerInfo& owner = dataOwners.OwnerL( fileInfo.SecureId() ); |
|
378 |
|
379 __LOG3("CMMCScBkupStateArchiveOpPublicDataFiles::AddIndexRecordL() - offset: %6d, length: %6d, file: %S", info.Offset(), info.Length(), &fileInfo.FileName()); |
|
380 |
|
381 // Indicate the state we are in |
|
382 SetState( EStateBackupAddIndexRecord ); |
|
383 CompleteSelf(); |
|
384 } |
|
385 |
|
386 |
|
387 // --------------------------------------------------------------------------- |
|
388 // CMMCScBkupStateArchiveOpPublicDataFiles::RestoreFileAttributesL() |
|
389 // |
|
390 // |
|
391 // --------------------------------------------------------------------------- |
|
392 void CMMCScBkupStateArchiveOpPublicDataFiles::RestoreFileAttributesL() |
|
393 { |
|
394 RFs& fsSession = Driver().DrvADI().ADIFsSession(); |
|
395 CMMCScBkupArchiveFooter& footer = Driver().DrvArchive().Footer(); |
|
396 CMMCScBkupIndexPublicDataFiles& index = static_cast<CMMCScBkupIndexPublicDataFiles&>( footer.IndexByType( EMMCScBkupOwnerDataTypePublicData ) ); |
|
397 |
|
398 // Get the entry who's attributes need restoring |
|
399 TMMCScBkupArchiveVector entryInfo; |
|
400 const CMMCScBkupFileInfo& fileInfo = index.At( iIndexValueCurrent, entryInfo ); |
|
401 |
|
402 // If file is in Photo Album Thumbnail folder |
|
403 // or file in videocenter folder and its subfolders |
|
404 if ( fileInfo.FileName().MatchF( KMMCScBkupMediaGalleryThumbnailFolder ) != KErrNotFound ) |
|
405 { |
|
406 // Get folder path length |
|
407 const TChar backslash('\\'); |
|
408 const TInt pathlength = fileInfo.FileName().LocateReverseF( backslash ) + 1; |
|
409 |
|
410 // Set hidden attribute for Thumbnail folder. |
|
411 // If folder does not exist, create it |
|
412 fsSession.SetAtt( fileInfo.FileName().Left( pathlength ), KEntryAttHidden, KEntryAttNormal ); |
|
413 } |
|
414 |
|
415 if ( fileInfo.FileName().MatchF( KMMCScBkupVideoCenterFolder ) != KErrNotFound) |
|
416 { |
|
417 // Get folder path length |
|
418 const TChar backslash('\\'); |
|
419 const TInt pathlength = fileInfo.FileName().LocateReverseF( backslash ) + 1; |
|
420 |
|
421 // Set hidden attribute for the video center's sub folder. |
|
422 // If foler does not exist, create it |
|
423 fsSession.SetAtt( fileInfo.FileName().Left( pathlength ), KEntryAttHidden, KEntryAttNormal ); |
|
424 |
|
425 //Manually set the videocenter main folder to be hidden |
|
426 fsSession.SetAtt( KMMCScBkupVideoCenterFolderPath, KEntryAttHidden, KEntryAttNormal ); |
|
427 } |
|
428 // Set the original attributes, clear the others |
|
429 const TInt error = fsSession.SetEntry( fileInfo.FileName(), |
|
430 fileInfo.DateTime(), |
|
431 fileInfo.Attributes(), |
|
432 !fileInfo.Attributes() ); |
|
433 |
|
434 (void) error; |
|
435 |
|
436 |
|
437 // Indicate the state we are in |
|
438 SetState( EStateRestoreResetAttributes ); |
|
439 CompleteSelf(); |
|
440 } |
|
441 |
|
442 |
|
443 |
|