39
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-2008 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: CMMCScBkupEngineImpl implementation
|
|
15 |
*
|
|
16 |
*
|
|
17 |
*/
|
|
18 |
|
|
19 |
#include "CMMCScBkupEngineImpl.h"
|
|
20 |
|
|
21 |
// User includes
|
|
22 |
#include "MMCScBkupLogger.h"
|
|
23 |
#include "CMMCScBkupState.h"
|
|
24 |
#include "MMCScBkupSBEUtils.h"
|
|
25 |
#include "CMMCScBkupArchive.h"
|
|
26 |
#include "MMCScBkupOperations.h"
|
|
27 |
#include "MMCScBkupArchiveUtils.h"
|
|
28 |
#include "CMMCScBkupStateFactory.h"
|
|
29 |
#include "MMCScBkupPhoneModelUtils.h"
|
|
30 |
#include "MMMCScBkupEngineObserver.h"
|
|
31 |
#include "CMMCScBkupFileListCollection.h"
|
|
32 |
#include "CMMCScBkupDataOwnerCollection.h"
|
|
33 |
#include "CMMCScBkupOperationParameters.h"
|
|
34 |
#include "CMMCScBkupArchiveInfo.h"
|
|
35 |
#include "BkupEngine.hrh"
|
|
36 |
#include <pathinfo.h>
|
|
37 |
|
|
38 |
// ========================= MEMBER FUNCTIONS ================================
|
|
39 |
|
|
40 |
// ---------------------------------------------------------------------------
|
|
41 |
// CMMCScBkupEngineImpl::CMMCScBkupEngineImpl()
|
|
42 |
//
|
|
43 |
// C++ constructor.
|
|
44 |
// ---------------------------------------------------------------------------
|
|
45 |
CMMCScBkupEngineImpl::CMMCScBkupEngineImpl( RFs& aFsSession )
|
|
46 |
: CActive( CActive::EPriorityIdle ),
|
|
47 |
iFsSession(aFsSession),
|
|
48 |
iCurrentArchive(0),
|
|
49 |
iTotalProgress(0),
|
|
50 |
iActiveDataProcessingOngoing(EFalse)
|
|
51 |
{
|
|
52 |
CActiveScheduler::Add(this);
|
|
53 |
}
|
|
54 |
|
|
55 |
|
|
56 |
// ---------------------------------------------------------------------------
|
|
57 |
// CMMCScBkupEngineImpl::~CMMCScBkupEngineImpl()
|
|
58 |
//
|
|
59 |
// Destructor.
|
|
60 |
// ---------------------------------------------------------------------------
|
|
61 |
CMMCScBkupEngineImpl::~CMMCScBkupEngineImpl()
|
|
62 |
{
|
|
63 |
Cancel();
|
|
64 |
//
|
|
65 |
TRAP_IGNORE(CleanupL());
|
|
66 |
|
|
67 |
iArchives.Close();
|
|
68 |
iDataOwners.Close();
|
|
69 |
iFileLists.Close();
|
|
70 |
delete iSBEClient;
|
|
71 |
}
|
|
72 |
|
|
73 |
|
|
74 |
// ---------------------------------------------------------------------------
|
|
75 |
// CMMCScBkupEngineImpl::ConstructL()
|
|
76 |
//
|
|
77 |
// Second phase constructor
|
|
78 |
// ---------------------------------------------------------------------------
|
|
79 |
void CMMCScBkupEngineImpl::ConstructL()
|
|
80 |
{
|
|
81 |
__LOG("CMMCScBkupEngineImpl::ConstructL() - START");
|
|
82 |
|
|
83 |
#ifdef MAKE_SBE_LOGGING_DIRECTORY
|
|
84 |
_LIT( KSBELoggingDir, "C:\\Logs\\connect\\" );
|
|
85 |
iFsSession.MkDirAll( KSBELoggingDir );
|
|
86 |
#endif
|
|
87 |
#ifdef MAKE_MMCSCBKUP_LOGGING_DIRECTORY
|
|
88 |
iFsSession.MkDirAll( KMMCScBkupLoggingFullPath );
|
|
89 |
#endif
|
|
90 |
|
|
91 |
__LOG("CMMCScBkupEngineImpl::ConstructL() - END");
|
|
92 |
}
|
|
93 |
|
|
94 |
|
|
95 |
// ---------------------------------------------------------------------------
|
|
96 |
// CMMCScBkupEngineImpl::NewL()
|
|
97 |
//
|
|
98 |
// Static constructor
|
|
99 |
// ---------------------------------------------------------------------------
|
|
100 |
CMMCScBkupEngineImpl* CMMCScBkupEngineImpl::NewL( RFs& aFsSession )
|
|
101 |
{
|
|
102 |
CMMCScBkupEngineImpl* self = new(ELeave) CMMCScBkupEngineImpl( aFsSession );
|
|
103 |
CleanupStack::PushL( self );
|
|
104 |
self->ConstructL();
|
|
105 |
CleanupStack::Pop( self );
|
|
106 |
return self;
|
|
107 |
}
|
|
108 |
|
|
109 |
|
|
110 |
// ---------------------------------------------------------------------------
|
|
111 |
// CMMCScBkupEngineImpl::StartOperationL()
|
|
112 |
//
|
|
113 |
//
|
|
114 |
// ---------------------------------------------------------------------------
|
|
115 |
void CMMCScBkupEngineImpl::StartOperationL(TMMCScBkupOperationType aOperation, MMMCScBkupEngineObserver& aObserver, CMMCScBkupOpParamsBase* aParams)
|
|
116 |
{
|
|
117 |
__ASSERT_DEBUG(DrvOperation() == EMMCScBkupOperationTypeIdle, User::Invariant()); //
|
|
118 |
|
|
119 |
// Setup our observer - we will report progress via this interface
|
|
120 |
iObserver = &aObserver;
|
|
121 |
|
|
122 |
// Take ownership of the parameters immediately
|
|
123 |
SetParameters(aParams);
|
|
124 |
|
|
125 |
if(!iSBEClient)
|
|
126 |
{
|
|
127 |
__LOG("CMMCScBkupEngineImpl::ConstructL() - creating SBE client...");
|
|
128 |
iSBEClient = CSBEClient::NewL();
|
|
129 |
}
|
|
130 |
|
|
131 |
#if defined(__MMCSCBKUPLOGGING_ENABLED__)
|
|
132 |
// Create a logging directory for logging purposes and empty contents
|
|
133 |
// in order to have the log only from last backup or restore operation
|
|
134 |
CFileMan* fileMan = CFileMan::NewL( iFsSession );
|
|
135 |
CleanupStack::PushL( fileMan );
|
|
136 |
TParse* path = new(ELeave) TParse();
|
|
137 |
|
|
138 |
CleanupStack::PushL(path);
|
|
139 |
path->Set(KMMCScBkupLoggingFullPathAndName, NULL, NULL);
|
|
140 |
fileMan->Delete( path->Path(), CFileMan::ERecurse ); // Ignore error
|
|
141 |
iFsSession.MkDirAll( path->Path() );
|
|
142 |
|
|
143 |
CleanupStack::PopAndDestroy(2, fileMan );
|
|
144 |
#endif
|
|
145 |
|
|
146 |
// Prepare supporting objects
|
|
147 |
PrepareObjectsL();
|
|
148 |
|
|
149 |
// Work out what to do...
|
|
150 |
CreateFactoryL( aOperation );
|
|
151 |
//
|
|
152 |
switch(aOperation)
|
|
153 |
{
|
|
154 |
case EMMCScBkupOperationTypeIdle:
|
|
155 |
__ASSERT_ALWAYS(EFalse, User::Invariant());
|
|
156 |
break;
|
|
157 |
case EMMCScBkupOperationTypeFullBackup:
|
|
158 |
case EMMCScBkupOperationTypePartialBackup:
|
|
159 |
PrepareForBackupL( DrvOperation() == EMMCScBkupOperationTypePartialBackup );
|
|
160 |
break;
|
|
161 |
case EMMCScBkupOperationTypeFullRestore:
|
|
162 |
case EMMCScBkupOperationTypePartialRestore:
|
|
163 |
PrepareForRestoreL( DrvOperation() == EMMCScBkupOperationTypePartialRestore );
|
|
164 |
break;
|
|
165 |
}
|
|
166 |
|
|
167 |
// Do this last, after everything that can leave has been executed
|
|
168 |
iOperationType = aOperation;
|
|
169 |
|
|
170 |
// Notify the observer we're starting up
|
|
171 |
NotifyObserver(MMMCScBkupEngineObserver::ECommonOperationStarting);
|
|
172 |
}
|
|
173 |
|
|
174 |
|
|
175 |
// ---------------------------------------------------------------------------
|
|
176 |
// CMMCScBkupEngineImpl::ValidArchiveForRestoreL()
|
|
177 |
//
|
|
178 |
//
|
|
179 |
// ---------------------------------------------------------------------------
|
|
180 |
TBool CMMCScBkupEngineImpl::ValidArchiveForRestoreL( const TDesC& aFileName )
|
|
181 |
{
|
|
182 |
const TBool valid = CMMCScBkupArchive::ValidArchiveForRestoreL( iFsSession, aFileName );
|
|
183 |
return valid;
|
|
184 |
}
|
|
185 |
|
|
186 |
|
|
187 |
// ---------------------------------------------------------------------------
|
|
188 |
// CMMCScBkupEngineImpl::TotalOperationSizeL()
|
|
189 |
//
|
|
190 |
//
|
|
191 |
// ---------------------------------------------------------------------------
|
|
192 |
TInt64 CMMCScBkupEngineImpl::TotalOperationSizeL() const
|
|
193 |
{
|
|
194 |
const TInt64 size = iDataOwners[iCurrentArchive]->TotalOperationalSizeL();
|
|
195 |
return size;
|
|
196 |
}
|
|
197 |
|
|
198 |
|
|
199 |
// ---------------------------------------------------------------------------
|
|
200 |
// CMMCScBkupEngineImpl::RebootRequired()
|
|
201 |
//
|
|
202 |
// NOTE: This method is not used in S60 3.x - Sysap handles the reboot
|
|
203 |
// ---------------------------------------------------------------------------
|
|
204 |
TBool CMMCScBkupEngineImpl::RebootRequired() const
|
|
205 |
{
|
|
206 |
// Criteria for a reboot are:
|
|
207 |
//
|
|
208 |
// 1) One or more data owners indicate that a reboot is necessary
|
|
209 |
// via their backup_registration.xml files.
|
|
210 |
//
|
|
211 |
// 2) The current operation is some form of restore (partial or full).
|
|
212 |
|
|
213 |
const TMMCScBkupOperationType currentOp = DrvOperation();
|
|
214 |
__LOG1("CMMCScBkupEngineImpl::RebootRequired() - operation type is: %d", currentOp);
|
|
215 |
|
|
216 |
TBool singleDataOwnerNeedsReboot = EFalse;
|
|
217 |
|
|
218 |
for(TInt i = 0; i < iDataOwners.Count(); i++)
|
|
219 |
{
|
|
220 |
singleDataOwnerNeedsReboot |= iDataOwners[i]->RebootRequired();
|
|
221 |
}
|
|
222 |
|
|
223 |
__LOG1("CMMCScBkupEngineImpl::RebootRequired() - D.O requires reboot?: %d", singleDataOwnerNeedsReboot);
|
|
224 |
|
|
225 |
const TBool rebootRequired = singleDataOwnerNeedsReboot &&
|
|
226 |
( currentOp == EMMCScBkupOperationTypeFullRestore ||
|
|
227 |
currentOp == EMMCScBkupOperationTypePartialRestore );
|
|
228 |
__LOG1("CMMCScBkupEngineImpl::RebootRequired() - final rebootRequired value: %d", rebootRequired);
|
|
229 |
|
|
230 |
// We return the value to the caller - the UI will display appropriate
|
|
231 |
// UI dialogs and reset the machine as appropriate.
|
|
232 |
return rebootRequired;
|
|
233 |
}
|
|
234 |
|
|
235 |
|
|
236 |
// ---------------------------------------------------------------------------
|
|
237 |
// CMMCScBkupEngineImpl::DrvADI()
|
|
238 |
//
|
|
239 |
//
|
|
240 |
// ---------------------------------------------------------------------------
|
|
241 |
MMMCScBkupArchiveDataInterface& CMMCScBkupEngineImpl::DrvADI() const
|
|
242 |
{
|
|
243 |
return iArchives[iCurrentArchive]->ADI();
|
|
244 |
}
|
|
245 |
|
|
246 |
|
|
247 |
// ---------------------------------------------------------------------------
|
|
248 |
// CMMCScBkupEngineImpl::DrvArchive()
|
|
249 |
//
|
|
250 |
//
|
|
251 |
// ---------------------------------------------------------------------------
|
|
252 |
CMMCScBkupArchive& CMMCScBkupEngineImpl::DrvArchive() const
|
|
253 |
{
|
|
254 |
__ASSERT_ALWAYS(iCurrentArchive < iArchives.Count(), User::Invariant());
|
|
255 |
|
|
256 |
return *iArchives[iCurrentArchive];
|
|
257 |
}
|
|
258 |
|
|
259 |
|
|
260 |
// ---------------------------------------------------------------------------
|
|
261 |
// CMMCScBkupEngineImpl::DrvSecureBackupClient()
|
|
262 |
//
|
|
263 |
//
|
|
264 |
// ---------------------------------------------------------------------------
|
|
265 |
CSBEClient& CMMCScBkupEngineImpl::DrvSecureBackupClient() const
|
|
266 |
{
|
|
267 |
return *iSBEClient;
|
|
268 |
}
|
|
269 |
|
|
270 |
|
|
271 |
// ---------------------------------------------------------------------------
|
|
272 |
// CMMCScBkupEngineImpl::DrvOperation()
|
|
273 |
//
|
|
274 |
//
|
|
275 |
// ---------------------------------------------------------------------------
|
|
276 |
TMMCScBkupOperationType CMMCScBkupEngineImpl::DrvOperation() const
|
|
277 |
{
|
|
278 |
return iOperationType;
|
|
279 |
}
|
|
280 |
|
|
281 |
|
|
282 |
// ---------------------------------------------------------------------------
|
|
283 |
// CMMCScBkupEngineImpl::DrvParamsBase()
|
|
284 |
//
|
|
285 |
//
|
|
286 |
// ---------------------------------------------------------------------------
|
|
287 |
CMMCScBkupOpParamsBase& CMMCScBkupEngineImpl::DrvParamsBase() const
|
|
288 |
{
|
|
289 |
return *iParameters;
|
|
290 |
}
|
|
291 |
|
|
292 |
|
|
293 |
// ---------------------------------------------------------------------------
|
|
294 |
// CMMCScBkupEngineImpl::DrvDataOwners()
|
|
295 |
//
|
|
296 |
//
|
|
297 |
// ---------------------------------------------------------------------------
|
|
298 |
CMMCScBkupDataOwnerCollection& CMMCScBkupEngineImpl::DrvDataOwners() const
|
|
299 |
{
|
|
300 |
__ASSERT_ALWAYS(iCurrentArchive < iDataOwners.Count(), User::Invariant());
|
|
301 |
|
|
302 |
return *iDataOwners[iCurrentArchive];
|
|
303 |
}
|
|
304 |
|
|
305 |
|
|
306 |
// ---------------------------------------------------------------------------
|
|
307 |
// CMMCScBkupEngineImpl::DrvDataOwnersAll()
|
|
308 |
//
|
|
309 |
//
|
|
310 |
// ---------------------------------------------------------------------------
|
|
311 |
RPointerArray<CMMCScBkupDataOwnerCollection>& CMMCScBkupEngineImpl::DrvDataOwnersAll()
|
|
312 |
{
|
|
313 |
return iDataOwners;
|
|
314 |
}
|
|
315 |
|
|
316 |
|
|
317 |
// ---------------------------------------------------------------------------
|
|
318 |
// CMMCScBkupEngineImpl::DrvFileList()
|
|
319 |
//
|
|
320 |
//
|
|
321 |
// ---------------------------------------------------------------------------
|
|
322 |
CMMCScBkupFileListCollection& CMMCScBkupEngineImpl::DrvFileList() const
|
|
323 |
{
|
|
324 |
__ASSERT_ALWAYS(iCurrentArchive < iFileLists.Count(), User::Invariant());
|
|
325 |
|
|
326 |
return *iFileLists[iCurrentArchive];
|
|
327 |
}
|
|
328 |
|
|
329 |
|
|
330 |
// ---------------------------------------------------------------------------
|
|
331 |
// CMMCScBkupEngineImpl::DrvLastCategory()
|
|
332 |
//
|
|
333 |
//
|
|
334 |
// ---------------------------------------------------------------------------
|
|
335 |
TBool CMMCScBkupEngineImpl::DrvLastCategory() const
|
|
336 |
{
|
|
337 |
return ( (iCurrentArchive + 1) == iArchives.Count() );
|
|
338 |
}
|
|
339 |
|
|
340 |
|
|
341 |
// ---------------------------------------------------------------------------
|
|
342 |
// CMMCScBkupEngineImpl::DrvStoreTotalProgress()
|
|
343 |
//
|
|
344 |
//
|
|
345 |
// ---------------------------------------------------------------------------
|
|
346 |
void CMMCScBkupEngineImpl::DrvStoreTotalProgress(TInt64 aProgress)
|
|
347 |
{
|
|
348 |
iTotalProgress += aProgress;
|
|
349 |
}
|
|
350 |
|
|
351 |
|
|
352 |
// ---------------------------------------------------------------------------
|
|
353 |
// CMMCScBkupEngineImpl::DrvTotalProgress()
|
|
354 |
//
|
|
355 |
//
|
|
356 |
// ---------------------------------------------------------------------------
|
|
357 |
TInt64 CMMCScBkupEngineImpl::DrvTotalProgress() const
|
|
358 |
{
|
|
359 |
return iTotalProgress;
|
|
360 |
}
|
|
361 |
|
|
362 |
// ---------------------------------------------------------------------------
|
|
363 |
// CMMCScBkupEngineImpl::DrvProgressHandler()
|
|
364 |
//
|
|
365 |
//
|
|
366 |
// ---------------------------------------------------------------------------
|
|
367 |
MMMCScBkupProgressObserver& CMMCScBkupEngineImpl::DrvProgressHandler() const
|
|
368 |
{
|
|
369 |
CMMCScBkupEngineImpl* self = const_cast< CMMCScBkupEngineImpl* > (this);
|
|
370 |
return *self;
|
|
371 |
}
|
|
372 |
|
|
373 |
|
|
374 |
// ---------------------------------------------------------------------------
|
|
375 |
// CMMCScBkupEngineImpl::MMCScBkupHandleProgress()
|
|
376 |
//
|
|
377 |
//
|
|
378 |
// ---------------------------------------------------------------------------
|
|
379 |
void CMMCScBkupEngineImpl::MMCScBkupHandleProgress( TInt aAmountCompleted )
|
|
380 |
{
|
|
381 |
__ASSERT_ALWAYS( aAmountCompleted >= 0, User::Invariant() );
|
|
382 |
if (aAmountCompleted > 0)
|
|
383 |
{
|
|
384 |
__LOG1("CMMCScBkupEngineImpl::MMCScBkupHandleProgress() - amount: %d", aAmountCompleted);
|
|
385 |
iCumulativeProgress += aAmountCompleted;
|
|
386 |
|
|
387 |
// Notify the observer that we've calculated the operational size
|
|
388 |
NotifyObserver( MMMCScBkupEngineObserver::ECommonProgress, iCumulativeProgress );
|
|
389 |
}
|
|
390 |
}
|
|
391 |
|
|
392 |
|
|
393 |
// ---------------------------------------------------------------------------
|
|
394 |
// CMMCScBkupEngineImpl::MMCScBkupHandleProgressDomainUnderstood()
|
|
395 |
//
|
|
396 |
//
|
|
397 |
// ---------------------------------------------------------------------------
|
|
398 |
void CMMCScBkupEngineImpl::MMCScBkupHandleProgressDomainUnderstood( TInt aTotalProgressAmount )
|
|
399 |
{
|
|
400 |
__LOG1("CMMCScBkupEngineImpl::MMCScBkupHandleProgressDomainUnderstood() - ##### TOTAL PROGRESS AMOUNT IS: %d", aTotalProgressAmount);
|
|
401 |
|
|
402 |
// Notify the observer that we've calculated the operational size
|
|
403 |
NotifyObserver( MMMCScBkupEngineObserver::ECommonSizeOfTaskUnderstood, aTotalProgressAmount );
|
|
404 |
}
|
|
405 |
|
|
406 |
|
|
407 |
// ---------------------------------------------------------------------------
|
|
408 |
// CMMCScBkupEngineImpl::MMCScBkupHandleFreeSpace()
|
|
409 |
//
|
|
410 |
//
|
|
411 |
// ---------------------------------------------------------------------------
|
|
412 |
TInt CMMCScBkupEngineImpl::MMCScBkupHandleFreeSpace( TInt aPercentualFree )
|
|
413 |
{
|
|
414 |
TInt error(KErrNone);
|
|
415 |
|
|
416 |
TRAP_IGNORE( error = iObserver->HandleBkupEngineEventL( MMMCScBkupEngineObserver::EBackupAnalysingData, aPercentualFree ) );
|
|
417 |
|
|
418 |
return error;
|
|
419 |
}
|
|
420 |
|
|
421 |
// ---------------------------------------------------------------------------
|
|
422 |
// CMMCScBkupEngineImpl::MMCScBkupStartBackuping()
|
|
423 |
//
|
|
424 |
//
|
|
425 |
// ---------------------------------------------------------------------------
|
|
426 |
void CMMCScBkupEngineImpl::MMCScBkupStartBackuping( TBool aProceed )
|
|
427 |
{
|
|
428 |
__LOG1("CMMCScBkupEngineImpl::MMCScBkupStartBackuping() - Disk space validation done, proceed %d", aProceed);
|
|
429 |
|
|
430 |
if( !aProceed )
|
|
431 |
{
|
|
432 |
// If there is no space to carry out backup, "restore" existing backup file,
|
|
433 |
// so that it can still be restored.
|
|
434 |
for(TInt i = 0; i < iArchives.Count(); i++)
|
|
435 |
{
|
|
436 |
iArchives[i]->RestoreOldArchive( );
|
|
437 |
}
|
|
438 |
}
|
|
439 |
else
|
|
440 |
{
|
|
441 |
// Clean up existing backup files.
|
|
442 |
for(TInt i = 0; i < iArchives.Count(); i++)
|
|
443 |
{
|
|
444 |
iArchives[i]->DeleteOldArchive( );
|
|
445 |
}
|
|
446 |
}
|
|
447 |
}
|
|
448 |
|
|
449 |
// ---------------------------------------------------------------------------
|
|
450 |
// CMMCScBkupEngineImpl::RunL()
|
|
451 |
//
|
|
452 |
//
|
|
453 |
// ---------------------------------------------------------------------------
|
|
454 |
void CMMCScBkupEngineImpl::RunL()
|
|
455 |
{
|
|
456 |
__LOG(" ");
|
|
457 |
__LOG(" ");
|
|
458 |
if ( !CurrentStateAvailable() )
|
|
459 |
{
|
|
460 |
__LOG2("CMMCScBkupEngineImpl::RunL() - START - iStatus: %d, iCurrentArchive %d",
|
|
461 |
iStatus.Int(), iCurrentArchive);
|
|
462 |
}
|
|
463 |
else
|
|
464 |
{
|
|
465 |
__LOG3("CMMCScBkupEngineImpl::RunL() - START - iStatus: %d, state: 0x%08x, iCurrentArchive %d",
|
|
466 |
iStatus.Int(), CurrentState().StateId().iUid, iCurrentArchive);
|
|
467 |
}
|
|
468 |
|
|
469 |
User::LeaveIfError(iStatus.Int());
|
|
470 |
|
|
471 |
// Get the state that just finished - its always the head item
|
|
472 |
const TBool stateStepAvailable = CurrentStateAvailable();
|
|
473 |
__ASSERT_ALWAYS(stateStepAvailable, User::Invariant());
|
|
474 |
CMMCScBkupState& currentState = CurrentState();
|
|
475 |
|
|
476 |
// Store completed state id as we're about to delete the object
|
|
477 |
// so it won't be available afterwards...
|
|
478 |
const TMMCScBkupStateId completedState = currentState.StateId();
|
|
479 |
|
|
480 |
// Identify which state should run next. In effect each state
|
|
481 |
// defines the overall state machine. This is required since
|
|
482 |
// some states need to dynamically change which state is executed
|
|
483 |
// next. A good example is the archive op for active data - when
|
|
484 |
// one or more active data clients are not ready, then the next
|
|
485 |
// state should be to requery their readyness. After their
|
|
486 |
// readyness has been ascertained, then any DO's that have now
|
|
487 |
// become ready should be archived. This process continues
|
|
488 |
// until all Active Data owners have provided all their data.
|
|
489 |
TMMCScBkupStateId nextState;
|
|
490 |
|
|
491 |
__LOG3("CMMCScBkupEngineImpl::RunL() - iActiveDataProcessingOngoing %d, completedState 0x%08x, nextState 0x%08x",
|
|
492 |
iActiveDataProcessingOngoing, completedState.iUid, currentState.NextStateId().iUid);
|
|
493 |
|
|
494 |
// Identify should we run current state again, i.e. run that state
|
|
495 |
// for next category. If state does not require processing of same
|
|
496 |
// state several times, then move on to next state.
|
|
497 |
if( currentState.CategorySpecific() != CMMCScBkupState::EStateOnce )
|
|
498 |
{
|
|
499 |
// For simplicity let's collect active data for each category in row.
|
|
500 |
// This means checking data owner status before proceeding to next category.
|
|
501 |
if( iActiveDataProcessingOngoing )
|
|
502 |
{
|
|
503 |
iActiveDataProcessingOngoing = EFalse;
|
|
504 |
nextState = currentState.NextStateId();
|
|
505 |
}
|
|
506 |
else
|
|
507 |
{
|
|
508 |
if( completedState == KMMCScBkupStateIdArchiveOpActiveData )
|
|
509 |
{
|
|
510 |
if( currentState.NextStateId() == KMMCScBkupStateIdGetDataOwnerStatuses )
|
|
511 |
{
|
|
512 |
// There is still some active data to be processed
|
|
513 |
iActiveDataProcessingOngoing = ETrue;
|
|
514 |
nextState = KMMCScBkupStateIdGetDataOwnerStatuses;
|
|
515 |
}
|
|
516 |
}
|
|
517 |
|
|
518 |
if( !iActiveDataProcessingOngoing )
|
|
519 |
{
|
|
520 |
if( ++iCurrentArchive < iArchives.Count() )
|
|
521 |
{
|
|
522 |
nextState = completedState;
|
|
523 |
}
|
|
524 |
else
|
|
525 |
{
|
|
526 |
iCurrentArchive = 0;
|
|
527 |
nextState = currentState.NextStateId();
|
|
528 |
}
|
|
529 |
}
|
|
530 |
}
|
|
531 |
}
|
|
532 |
else
|
|
533 |
{
|
|
534 |
iCurrentArchive = 0;
|
|
535 |
nextState = currentState.NextStateId();
|
|
536 |
}
|
|
537 |
|
|
538 |
if(nextState == completedState && currentState.CategorySpecific() == CMMCScBkupState::EStatePerCategoryCommon)
|
|
539 |
{
|
|
540 |
__LOG2("CMMCScBkupEngineImpl::RunL() - object not recreated for state: 0x%08x, iCurrentArchive %d",
|
|
541 |
nextState.iUid, iCurrentArchive);
|
|
542 |
}
|
|
543 |
else
|
|
544 |
{
|
|
545 |
// Remove the completed state (destroys 'currentState')
|
|
546 |
DestroyCurrentState();
|
|
547 |
// Identify the next state. Causes RunL to be called when the state
|
|
548 |
// has finished executing
|
|
549 |
__LOG2("CMMCScBkupEngineImpl::RunL() - preparing state: 0x%08x, iCurrentArchive %d",
|
|
550 |
nextState.iUid, iCurrentArchive);
|
|
551 |
|
|
552 |
PrepareNextStateL( nextState );
|
|
553 |
}
|
|
554 |
|
|
555 |
if (CurrentStateAvailable())
|
|
556 |
{
|
|
557 |
#if defined(__MMCSCBKUPLOGGING_ENABLED__)
|
|
558 |
CMMCScBkupState& newState = CurrentState();
|
|
559 |
if( newState.CategorySpecific() != CMMCScBkupState::EStateOnce )
|
|
560 |
{
|
|
561 |
__LOG2("CMMCScBkupEngineImpl::RunL() - executing category specific state: 0x%08x for category 0x%x",
|
|
562 |
nextState.iUid, iArchives[iCurrentArchive]->Category().iFlags);
|
|
563 |
}
|
|
564 |
else
|
|
565 |
{
|
|
566 |
__LOG1("CMMCScBkupEngineImpl::RunL() - executing non category specific state: 0x%08x", nextState.iUid);
|
|
567 |
}
|
|
568 |
#endif
|
|
569 |
ExecuteStateL();
|
|
570 |
}
|
|
571 |
else
|
|
572 |
{
|
|
573 |
if ( iSBEClient )
|
|
574 |
{
|
|
575 |
MMCScBkupSBEUtils::EndBackupOrRestoreL( *iSBEClient );
|
|
576 |
}
|
|
577 |
// Signal we are about to finish, so that bkupchecker can be notified.
|
|
578 |
NotifyObserver(MMMCScBkupEngineObserver::ECommonOperationPrepareEnded);
|
|
579 |
// We've finished
|
|
580 |
CleanupL();
|
|
581 |
NotifyObserver(MMMCScBkupEngineObserver::ECommonOperationEnded);
|
|
582 |
// Remove observer
|
|
583 |
iObserver = NULL;
|
|
584 |
}
|
|
585 |
|
|
586 |
__LOG3("CMMCScBkupEngineImpl::RunL() - END - nextState: 0x%08x, isActive: %d, iStatus: %d", nextState.iUid, IsActive(), iStatus.Int());
|
|
587 |
__LOG(" ");
|
|
588 |
__LOG(" ");
|
|
589 |
}
|
|
590 |
|
|
591 |
|
|
592 |
// ---------------------------------------------------------------------------
|
|
593 |
// CMMCScBkupEngineImpl::DoCancel()
|
|
594 |
//
|
|
595 |
//
|
|
596 |
// ---------------------------------------------------------------------------
|
|
597 |
void CMMCScBkupEngineImpl::DoCancel()
|
|
598 |
{
|
|
599 |
__LOG("CMMCScBkupEngineImpl::DoCancel() - START");
|
|
600 |
|
|
601 |
if (CurrentStateAvailable())
|
|
602 |
{
|
|
603 |
__LOG1("CMMCScBkupEngineImpl::DoCancel() - current state is: 0x%08x", CurrentState().StateId().iUid);
|
|
604 |
|
|
605 |
// Our request should be completed by the state
|
|
606 |
CurrentState().Cancel();
|
|
607 |
}
|
|
608 |
|
|
609 |
// Signal we are about to finish, so that bkupchecker can be notified.
|
|
610 |
NotifyObserver(MMMCScBkupEngineObserver::ECommonOperationPrepareEnded);
|
|
611 |
// Cleanup
|
|
612 |
TRAP_IGNORE( CleanupL( KErrCancel ) );
|
|
613 |
|
|
614 |
// Ensure observer is informed
|
|
615 |
NotifyObserver(MMMCScBkupEngineObserver::ECommonOperationError, KErrCancel);
|
|
616 |
NotifyObserver(MMMCScBkupEngineObserver::ECommonOperationEnded, KErrCancel);
|
|
617 |
// Remove observer
|
|
618 |
iObserver = NULL;
|
|
619 |
|
|
620 |
__LOG("CMMCScBkupEngineImpl::DoCancel() - END");
|
|
621 |
}
|
|
622 |
|
|
623 |
|
|
624 |
// ---------------------------------------------------------------------------
|
|
625 |
// CMMCScBkupEngineImpl::RunError()
|
|
626 |
//
|
|
627 |
//
|
|
628 |
// ---------------------------------------------------------------------------
|
|
629 |
TInt CMMCScBkupEngineImpl::RunError(TInt aError)
|
|
630 |
{
|
|
631 |
__LOG1("CMMCScBkupEngineImpl::RunError() - START - aError: %d", aError);
|
|
632 |
|
|
633 |
// Inform observer of error
|
|
634 |
NotifyObserver(MMMCScBkupEngineObserver::ECommonOperationError, aError);
|
|
635 |
// Signal we are about to finish, so that bkupchecker can be notified.
|
|
636 |
NotifyObserver(MMMCScBkupEngineObserver::ECommonOperationPrepareEnded);
|
|
637 |
// Cleanup
|
|
638 |
TRAP_IGNORE( CleanupL( aError ) );
|
|
639 |
|
|
640 |
// Finalize observer
|
|
641 |
NotifyObserver(MMMCScBkupEngineObserver::ECommonOperationEnded, aError);
|
|
642 |
// Remove observer
|
|
643 |
iObserver = NULL;
|
|
644 |
|
|
645 |
// Return KErrNone to stop the scheduler from panicking our thread
|
|
646 |
|
|
647 |
__LOG("CMMCScBkupEngineImpl::RunError() - END");
|
|
648 |
return KErrNone;
|
|
649 |
}
|
|
650 |
|
|
651 |
|
|
652 |
// ---------------------------------------------------------------------------
|
|
653 |
// CMMCScBkupEngineImpl::CompleteOwnRequest()
|
|
654 |
//
|
|
655 |
//
|
|
656 |
// ---------------------------------------------------------------------------
|
|
657 |
void CMMCScBkupEngineImpl::CompleteOwnRequest(TInt aCompletionCode, TBool aSetActive)
|
|
658 |
{
|
|
659 |
if (aSetActive)
|
|
660 |
{
|
|
661 |
SetActive();
|
|
662 |
}
|
|
663 |
//
|
|
664 |
TRequestStatus* status = &iStatus;
|
|
665 |
User::RequestComplete(status, aCompletionCode);
|
|
666 |
}
|
|
667 |
|
|
668 |
|
|
669 |
// ---------------------------------------------------------------------------
|
|
670 |
// CMMCScBkupEngineImpl::NotifyObserver()
|
|
671 |
//
|
|
672 |
//
|
|
673 |
// ---------------------------------------------------------------------------
|
|
674 |
void CMMCScBkupEngineImpl::NotifyObserver( MMMCScBkupEngineObserver::TEvent aEvent, TInt aAssociatedData )
|
|
675 |
{
|
|
676 |
if ( iObserver )
|
|
677 |
{
|
|
678 |
TRAP_IGNORE( iObserver->HandleBkupEngineEventL( aEvent, aAssociatedData ) );
|
|
679 |
}
|
|
680 |
}
|
|
681 |
|
|
682 |
|
|
683 |
// ---------------------------------------------------------------------------
|
|
684 |
// CMMCScBkupEngineImpl::PrepareForBackupL()
|
|
685 |
//
|
|
686 |
//
|
|
687 |
// ---------------------------------------------------------------------------
|
|
688 |
void CMMCScBkupEngineImpl::PrepareForBackupL( TBool aPartial )
|
|
689 |
{
|
|
690 |
#ifdef DEBUGGING_DATA_TRANSFER
|
|
691 |
CleanBackupFilesL();
|
|
692 |
#endif
|
|
693 |
|
|
694 |
// Open the archives for writing
|
|
695 |
for(TInt i = 0; i < iArchives.Count(); i++)
|
|
696 |
{
|
|
697 |
const TPtrC pArchiveName( DrvParamsBase().FileName(i) );
|
|
698 |
iArchives[i]->OpenForWritingL( pArchiveName );
|
|
699 |
}
|
|
700 |
|
|
701 |
// Initialise our state model
|
|
702 |
if ( !aPartial )
|
|
703 |
{
|
|
704 |
// Starting a FULL BACKUP
|
|
705 |
PrepareNextStateL( KMMCScBkupStateArchiveOpArchiveHeader );
|
|
706 |
ExecuteStateL();
|
|
707 |
}
|
|
708 |
else
|
|
709 |
{
|
|
710 |
User::Leave( KErrNotSupported );
|
|
711 |
}
|
|
712 |
}
|
|
713 |
|
|
714 |
|
|
715 |
// ---------------------------------------------------------------------------
|
|
716 |
// CMMCScBkupEngineImpl::PrepareForRestoreL()
|
|
717 |
//
|
|
718 |
//
|
|
719 |
// ---------------------------------------------------------------------------
|
|
720 |
void CMMCScBkupEngineImpl::PrepareForRestoreL( TBool aPartial )
|
|
721 |
{
|
|
722 |
#ifdef DEBUGGING_DATA_TRANSFER
|
|
723 |
ClearRestoreFilesL();
|
|
724 |
#endif
|
|
725 |
|
|
726 |
// Open the archives for reading
|
|
727 |
for(TInt i = 0; i < iArchives.Count(); i++)
|
|
728 |
{
|
|
729 |
const TPtrC pArchiveName( DrvParamsBase().FileName(i) );
|
|
730 |
iArchives[i]->OpenForReadingL( pArchiveName );
|
|
731 |
|
|
732 |
#ifdef RD_FILE_MANAGER_BACKUP
|
|
733 |
// Validate archive content is not altered
|
|
734 |
#if defined(__MMCSCBKUPLOGGING_ENABLED__)
|
|
735 |
TUint32 startTime = User::NTickCount();
|
|
736 |
#endif
|
|
737 |
TInt validArchiveForRestore = MMCScBkupArchiveUtils::ValidateArchiveCrcsL( iFsSession, pArchiveName );
|
|
738 |
#if defined(__MMCSCBKUPLOGGING_ENABLED__)
|
|
739 |
__LOG2("CMMCScBkupEngineImpl::PrepareForRestoreL - crcs validation result %d, ticks in ms %u",
|
|
740 |
validArchiveForRestore, User::NTickCount() - startTime);
|
|
741 |
#endif
|
|
742 |
if(validArchiveForRestore == EFalse)
|
|
743 |
{
|
|
744 |
User::Leave(KErrCorrupt);
|
|
745 |
}
|
|
746 |
#endif
|
|
747 |
}
|
|
748 |
|
|
749 |
// Initialise our state model
|
|
750 |
if ( !aPartial )
|
|
751 |
{
|
|
752 |
// Starting a FULL RESTORE
|
|
753 |
PrepareNextStateL( KMMCScBkupStateArchiveOpArchiveHeader );
|
|
754 |
ExecuteStateL();
|
|
755 |
}
|
|
756 |
else
|
|
757 |
{
|
|
758 |
User::Leave( KErrNotSupported );
|
|
759 |
}
|
|
760 |
}
|
|
761 |
|
|
762 |
|
|
763 |
// ---------------------------------------------------------------------------
|
|
764 |
// CMMCScBkupEngineImpl::SetParameters()
|
|
765 |
//
|
|
766 |
//
|
|
767 |
// ---------------------------------------------------------------------------
|
|
768 |
void CMMCScBkupEngineImpl::SetParameters(CMMCScBkupOpParamsBase* aParameters)
|
|
769 |
{
|
|
770 |
__ASSERT_ALWAYS(aParameters != NULL, User::Invariant());
|
|
771 |
//
|
|
772 |
delete iParameters;
|
|
773 |
iParameters = aParameters;
|
|
774 |
}
|
|
775 |
|
|
776 |
|
|
777 |
// ---------------------------------------------------------------------------
|
|
778 |
// CMMCScBkupEngineImpl::CreateFactoryL()
|
|
779 |
//
|
|
780 |
//
|
|
781 |
// ---------------------------------------------------------------------------
|
|
782 |
void CMMCScBkupEngineImpl::CreateFactoryL(TMMCScBkupOperationType aOperation)
|
|
783 |
{
|
|
784 |
__ASSERT_DEBUG(iFactory == NULL, User::Invariant());
|
|
785 |
//
|
|
786 |
CMMCScBkupStateFactory* factory = CMMCScBkupStateFactory::FactoryByOperationTypeLC(aOperation);
|
|
787 |
delete iFactory;
|
|
788 |
iFactory = factory;
|
|
789 |
CleanupStack::Pop( factory );
|
|
790 |
}
|
|
791 |
|
|
792 |
|
|
793 |
// ---------------------------------------------------------------------------
|
|
794 |
// CMMCScBkupEngineImpl::CurrentStateAvailable()
|
|
795 |
//
|
|
796 |
//
|
|
797 |
// ---------------------------------------------------------------------------
|
|
798 |
TBool CMMCScBkupEngineImpl::CurrentStateAvailable() const
|
|
799 |
{
|
|
800 |
return (iCurrentState != NULL);
|
|
801 |
}
|
|
802 |
|
|
803 |
|
|
804 |
// ---------------------------------------------------------------------------
|
|
805 |
// CMMCScBkupEngineImpl::CurrentStateId()
|
|
806 |
//
|
|
807 |
//
|
|
808 |
// ---------------------------------------------------------------------------
|
|
809 |
TMMCScBkupStateId CMMCScBkupEngineImpl::CurrentStateId() const
|
|
810 |
{
|
|
811 |
__ASSERT_ALWAYS(CurrentStateAvailable(), User::Invariant());
|
|
812 |
return CurrentState().StateId();
|
|
813 |
}
|
|
814 |
|
|
815 |
|
|
816 |
// ---------------------------------------------------------------------------
|
|
817 |
// CMMCScBkupEngineImpl::CurrentState()
|
|
818 |
//
|
|
819 |
//
|
|
820 |
// ---------------------------------------------------------------------------
|
|
821 |
CMMCScBkupState& CMMCScBkupEngineImpl::CurrentState()
|
|
822 |
{
|
|
823 |
return *iCurrentState;
|
|
824 |
}
|
|
825 |
|
|
826 |
|
|
827 |
// ---------------------------------------------------------------------------
|
|
828 |
// CMMCScBkupEngineImpl::CurrentState()
|
|
829 |
//
|
|
830 |
//
|
|
831 |
// ---------------------------------------------------------------------------
|
|
832 |
const CMMCScBkupState& CMMCScBkupEngineImpl::CurrentState() const
|
|
833 |
{
|
|
834 |
return *iCurrentState;
|
|
835 |
}
|
|
836 |
|
|
837 |
|
|
838 |
// ---------------------------------------------------------------------------
|
|
839 |
// CMMCScBkupEngineImpl::PrepareNextStateL()
|
|
840 |
//
|
|
841 |
//
|
|
842 |
// ---------------------------------------------------------------------------
|
|
843 |
void CMMCScBkupEngineImpl::PrepareNextStateL( TMMCScBkupStateId aNextState )
|
|
844 |
{
|
|
845 |
if ( aNextState != KMMCScBkupStateIdOperationComplete )
|
|
846 |
{
|
|
847 |
CMMCScBkupState* nextState = iFactory->GetStateLC( aNextState, *this );
|
|
848 |
delete iCurrentState;
|
|
849 |
iCurrentState = nextState;
|
|
850 |
CleanupStack::Pop( nextState );
|
|
851 |
}
|
|
852 |
}
|
|
853 |
|
|
854 |
|
|
855 |
// ---------------------------------------------------------------------------
|
|
856 |
// CMMCScBkupEngineImpl::DestroyCurrentState()
|
|
857 |
//
|
|
858 |
//
|
|
859 |
// ---------------------------------------------------------------------------
|
|
860 |
void CMMCScBkupEngineImpl::DestroyCurrentState()
|
|
861 |
{
|
|
862 |
delete iCurrentState;
|
|
863 |
iCurrentState = NULL;
|
|
864 |
}
|
|
865 |
|
|
866 |
|
|
867 |
// ---------------------------------------------------------------------------
|
|
868 |
// CMMCScBkupEngineImpl::ExecuteStateL()
|
|
869 |
//
|
|
870 |
//
|
|
871 |
// ---------------------------------------------------------------------------
|
|
872 |
void CMMCScBkupEngineImpl::ExecuteStateL()
|
|
873 |
{
|
|
874 |
const TBool stateStepAvailable = CurrentStateAvailable();
|
|
875 |
__ASSERT_ALWAYS(stateStepAvailable, User::Invariant());
|
|
876 |
//
|
|
877 |
CMMCScBkupState& currentState = CurrentState();
|
|
878 |
//
|
|
879 |
currentState.ExecuteL(iStatus);
|
|
880 |
SetActive();
|
|
881 |
|
|
882 |
// RunL will now be called when the state has completed execution
|
|
883 |
}
|
|
884 |
|
|
885 |
|
|
886 |
// ---------------------------------------------------------------------------
|
|
887 |
// CMMCScBkupEngineImpl::CleanupL()
|
|
888 |
//
|
|
889 |
//
|
|
890 |
// ---------------------------------------------------------------------------
|
|
891 |
void CMMCScBkupEngineImpl::CleanupL( TInt aError )
|
|
892 |
{
|
|
893 |
__LOG1("CMMCScBkupEngineImpl::CleanupL() - START - aError: %d", aError);
|
|
894 |
|
|
895 |
// If SBE died, then recreate
|
|
896 |
if ( aError == KErrServerTerminated )
|
|
897 |
{
|
|
898 |
__LOG("CMMCScBkupEngineImpl::CleanupL() - assuming SBE panicked - re-creating SBE session...");
|
|
899 |
CSBEClient* newSBEClient = CSBEClient::NewL();
|
|
900 |
delete iSBEClient;
|
|
901 |
iSBEClient = newSBEClient;
|
|
902 |
}
|
|
903 |
|
|
904 |
|
|
905 |
__LOG("CMMCScBkupEngineImpl::CleanupL() - destroying current state...");
|
|
906 |
DestroyCurrentState();
|
|
907 |
|
|
908 |
const TBool backupOrRestoreUnderway = MMCScBkupSBEUtils::PhoneIsInBackupOrRestoreModeL();
|
|
909 |
__LOG1("CMMCScBkupEngineImpl::CleanupL() - backupOrRestoreUnderway: %d", backupOrRestoreUnderway);
|
|
910 |
if ( backupOrRestoreUnderway && iSBEClient )
|
|
911 |
{
|
|
912 |
// Must end backup or restore
|
|
913 |
__LOG("CMMCScBkupEngineImpl::CleanupL() - ending backup or restore...");
|
|
914 |
MMCScBkupSBEUtils::EndBackupOrRestoreL( *iSBEClient );
|
|
915 |
}
|
|
916 |
|
|
917 |
// Ensure the archive is closed
|
|
918 |
if ( iArchives.Count() )
|
|
919 |
{
|
|
920 |
__LOG("CMMCScBkupEngineImpl::CleanupL() - closing archives...");
|
|
921 |
for(TInt i = 0; i < iArchives.Count(); i++)
|
|
922 |
{
|
|
923 |
iArchives[i]->Close( aError );
|
|
924 |
}
|
|
925 |
|
|
926 |
__LOG("CMMCScBkupEngineImpl::CleanupL() - reseting archive array...");
|
|
927 |
iArchives.ResetAndDestroy();
|
|
928 |
}
|
|
929 |
|
|
930 |
// Destroy old parameters
|
|
931 |
__LOG("CMMCScBkupEngineImpl::CleanupL() - destroying parameters...");
|
|
932 |
delete iParameters;
|
|
933 |
iParameters = NULL;
|
|
934 |
|
|
935 |
// Set back to idle
|
|
936 |
__LOG("CMMCScBkupEngineImpl::CleanupL() - setting operation status to idle...");
|
|
937 |
iOperationType = EMMCScBkupOperationTypeIdle;
|
|
938 |
|
|
939 |
// Dispose of our collections
|
|
940 |
__LOG("CMMCScBkupEngineImpl::CleanupL() - destroying data owners and file lists...");
|
|
941 |
iDataOwners.ResetAndDestroy();
|
|
942 |
iFileLists.ResetAndDestroy();
|
|
943 |
|
|
944 |
// Dispose of state factory
|
|
945 |
__LOG("CMMCScBkupEngineImpl::CleanupL() - destroying factory...");
|
|
946 |
delete iFactory;
|
|
947 |
iFactory = NULL;
|
|
948 |
|
|
949 |
// Reset progress
|
|
950 |
iCumulativeProgress = 0;
|
|
951 |
|
|
952 |
// Reduce memory consumption by deleting SBE client. Session will be closed
|
|
953 |
// and SBE frees reserved (e.g. 128 kB...) memory pool.
|
|
954 |
if(iSBEClient)
|
|
955 |
{
|
|
956 |
__LOG("CMMCScBkupEngineImpl::CleanupL() - deleting SBE client...");
|
|
957 |
delete iSBEClient;
|
|
958 |
iSBEClient = NULL;
|
|
959 |
}
|
|
960 |
|
|
961 |
__LOG("CMMCScBkupEngineImpl::CleanupL() - END");
|
|
962 |
}
|
|
963 |
|
|
964 |
|
|
965 |
// ---------------------------------------------------------------------------
|
|
966 |
// CMMCScBkupEngineImpl::PrepareObjectsL()
|
|
967 |
//
|
|
968 |
//
|
|
969 |
// ---------------------------------------------------------------------------
|
|
970 |
void CMMCScBkupEngineImpl::PrepareObjectsL()
|
|
971 |
{
|
|
972 |
__LOG("CMMCScBkupEngineImpl::PrepareObjectsL() - creating objects...");
|
|
973 |
|
|
974 |
iTotalProgress = 0;
|
|
975 |
iCurrentArchive = 0;
|
|
976 |
|
|
977 |
const RMMCScBkupPointerArray<CMMCScBkupArchiveInfo>& archives = DrvParamsBase().ArchiveInfos();
|
|
978 |
TInt count = archives.Count();
|
|
979 |
|
|
980 |
if(count == 0)
|
|
981 |
{
|
|
982 |
__LOG("CMMCScBkupEngineImpl::PrepareObjectsL() - nothing to be done, leaving...");
|
|
983 |
User::Leave(KErrCancel);
|
|
984 |
}
|
|
985 |
|
|
986 |
for(TInt i = 0; i < count; i++)
|
|
987 |
{
|
|
988 |
CMMCScBkupArchive* archive;
|
|
989 |
archive = CMMCScBkupArchive::NewL( iFsSession, DrvProgressHandler(), *this, archives[i]->Category() );
|
|
990 |
CleanupStack::PushL( archive );
|
|
991 |
iArchives.AppendL( archive );
|
|
992 |
CleanupStack::Pop( archive );
|
|
993 |
|
|
994 |
CMMCScBkupDataOwnerCollection* dataOwners;
|
|
995 |
dataOwners = CMMCScBkupDataOwnerCollection::NewL( *this, archives[i]->Category() );
|
|
996 |
CleanupStack::PushL( dataOwners );
|
|
997 |
iDataOwners.AppendL( dataOwners );
|
|
998 |
CleanupStack::Pop( dataOwners );
|
|
999 |
|
|
1000 |
CMMCScBkupFileListCollection* fileList;
|
|
1001 |
fileList = CMMCScBkupFileListCollection::NewL( archives[i]->Category(), iFsSession );
|
|
1002 |
CleanupStack::PushL( fileList );
|
|
1003 |
iFileLists.AppendL( fileList );
|
|
1004 |
CleanupStack::Pop( fileList );
|
|
1005 |
}
|
|
1006 |
}
|
|
1007 |
|
|
1008 |
|
|
1009 |
// ---------------------------------------------------------------------------
|
|
1010 |
// CMMCScBkupEngineImpl::ResetAndDestroyArchives
|
|
1011 |
// ---------------------------------------------------------------------------
|
|
1012 |
//
|
|
1013 |
void CMMCScBkupEngineImpl::ResetAndDestroyArchives( TAny* aPtr )
|
|
1014 |
{
|
|
1015 |
RPointerArray< CMMCScBkupArchiveInfo >* archive =
|
|
1016 |
static_cast< RPointerArray< CMMCScBkupArchiveInfo >* >( aPtr );
|
|
1017 |
archive->ResetAndDestroy();
|
|
1018 |
archive->Close();
|
|
1019 |
}
|
|
1020 |
|
|
1021 |
// ---------------------------------------------------------------------------
|
|
1022 |
// CMMCScBkupEngineImpl::ListArchivesL()
|
|
1023 |
//
|
|
1024 |
// Provide a list of valid (both content and category do match) archives
|
|
1025 |
// available on all drives' backup folder
|
|
1026 |
// ---------------------------------------------------------------------------
|
|
1027 |
void CMMCScBkupEngineImpl::ListArchivesL(
|
|
1028 |
RPointerArray< CMMCScBkupArchiveInfo >& aArchives,
|
|
1029 |
CMMCScBkupOpParamsBase* aParams,
|
|
1030 |
const TUint32 aDriveAttMatch,
|
|
1031 |
const TInt aDriveMatch )
|
|
1032 |
{
|
|
1033 |
__LOG("CMMCScBkupEngineImpl::ListArchivesL() - START");
|
|
1034 |
|
|
1035 |
TCleanupItem cleanupItem( ResetAndDestroyArchives, &aArchives );
|
|
1036 |
CleanupStack::PushL( cleanupItem );
|
|
1037 |
|
|
1038 |
for(TInt i = 0; i < KMaxDrives; i++)
|
|
1039 |
{
|
|
1040 |
// Check is drive number allowed
|
|
1041 |
if ( aDriveMatch != KErrNotFound && aDriveMatch != i )
|
|
1042 |
{
|
|
1043 |
continue;
|
|
1044 |
}
|
|
1045 |
// Check are drive attributes allowed
|
|
1046 |
TBool supported( EFalse );
|
|
1047 |
TDriveInfo driveInfo;
|
|
1048 |
if ( iFsSession.Drive( driveInfo, i ) == KErrNone )
|
|
1049 |
{
|
|
1050 |
if ( driveInfo.iDriveAtt & aDriveAttMatch )
|
|
1051 |
{
|
|
1052 |
supported = ETrue;
|
|
1053 |
}
|
|
1054 |
}
|
|
1055 |
if ( !supported )
|
|
1056 |
{
|
|
1057 |
continue;
|
|
1058 |
}
|
|
1059 |
|
|
1060 |
const TDriveUnit driveUnit(i);
|
|
1061 |
const TDriveName driveName(driveUnit.Name());
|
|
1062 |
CDir* pFiles = NULL;
|
|
1063 |
TFileName path;
|
|
1064 |
path.Append(driveName);
|
|
1065 |
path.Append(KBackUpFolder());
|
|
1066 |
path.Append(KBackUpFiles());
|
|
1067 |
|
|
1068 |
// Scan for all archives
|
|
1069 |
iFsSession.GetDir(path, KEntryAttMatchMask, ESortNone, pFiles);
|
|
1070 |
CleanupStack::PushL(pFiles);
|
|
1071 |
|
|
1072 |
if(pFiles)
|
|
1073 |
{
|
|
1074 |
TInt count = pFiles->Count();
|
|
1075 |
for (TInt x = 0; x < count; x++)
|
|
1076 |
{
|
|
1077 |
const TEntry& entryPtr = (*pFiles)[x];
|
|
1078 |
TEntry entry(entryPtr);
|
|
1079 |
TFileName pathAndFile;
|
|
1080 |
pathAndFile.Append(driveName);
|
|
1081 |
pathAndFile.Append(KBackUpFolder());
|
|
1082 |
pathAndFile.Append(entry.iName);
|
|
1083 |
|
|
1084 |
entry.iName = pathAndFile;
|
|
1085 |
|
|
1086 |
// Read category information from archive
|
|
1087 |
TBitFlags category;
|
|
1088 |
TRAPD(err, category = MMCScBkupArchiveUtils::ReadBkUpCategoryInformationL( iFsSession, pathAndFile ));
|
|
1089 |
|
|
1090 |
if(err == KErrNone)
|
|
1091 |
{
|
|
1092 |
// Append archive in list when valid
|
|
1093 |
if((category.Value() & aParams->Categories().Value()) && ValidArchiveForRestoreL( pathAndFile ))
|
|
1094 |
{
|
|
1095 |
__LOG2("CMMCScBkupEngineImpl::ListArchivesL() - adding archive %S of category 0x%x",
|
|
1096 |
&pathAndFile, category.Value());
|
|
1097 |
CMMCScBkupArchiveInfo* archiveInfo = CMMCScBkupArchiveInfo::NewLC( entry );
|
|
1098 |
// Set category in archive info - can be used for filtering
|
|
1099 |
archiveInfo->SetCategory( category );
|
|
1100 |
// Move ownership to array
|
|
1101 |
aArchives.AppendL(archiveInfo);
|
|
1102 |
CleanupStack::Pop(archiveInfo);
|
|
1103 |
}
|
|
1104 |
else
|
|
1105 |
{
|
|
1106 |
__LOG3("CMMCScBkupEngineImpl::ListArchivesL() - archive %S of category 0x%x (vs. 0x%x) not included",
|
|
1107 |
&pathAndFile, category.Value(), aParams->Categories().Value());
|
|
1108 |
}
|
|
1109 |
}
|
|
1110 |
}
|
|
1111 |
}
|
|
1112 |
|
|
1113 |
CleanupStack::PopAndDestroy(pFiles);
|
|
1114 |
}
|
|
1115 |
CleanupStack::Pop( &aArchives );
|
|
1116 |
__LOG("CMMCScBkupEngineImpl::ListArchivesL() - END");
|
|
1117 |
}
|
|
1118 |
|
|
1119 |
|
|
1120 |
#ifdef DEBUGGING_DATA_TRANSFER
|
|
1121 |
// ---------------------------------------------------------------------------
|
|
1122 |
// CMMCScBkupEngineImpl::CleanBackupFilesL()
|
|
1123 |
//
|
|
1124 |
//
|
|
1125 |
// ---------------------------------------------------------------------------
|
|
1126 |
void CMMCScBkupEngineImpl::CleanBackupFilesL()
|
|
1127 |
{
|
|
1128 |
CFileMan* fileMan = CFileMan::NewL( iFsSession );
|
|
1129 |
CleanupStack::PushL( fileMan );
|
|
1130 |
|
|
1131 |
// Make directory, ignore error, ugly, functionise later on...
|
|
1132 |
_LIT(KMMCScBkupFormatDes, "%S%S%S%S");
|
|
1133 |
TFileName cleanPath;
|
|
1134 |
const TDesC& path = PathInfo::MemoryCardRootPath();
|
|
1135 |
|
|
1136 |
//
|
|
1137 |
cleanPath.Format(KMMCScBkupFormatDes, &path, &KMMCScBkupDataTransferDebuggingPathRoot, &KMMCScBkupDataTransferDebuggingPathDataJava, &KMMCScBkupDataTransferDebuggingPathDataBackup);
|
|
1138 |
fileMan->Delete( cleanPath, CFileMan::ERecurse ); // Ignore error
|
|
1139 |
iFsSession.MkDirAll( cleanPath );
|
|
1140 |
cleanPath.Format(KMMCScBkupFormatDes, &path, &KMMCScBkupDataTransferDebuggingPathRoot, &KMMCScBkupDataTransferDebuggingPathDataSystem, &KMMCScBkupDataTransferDebuggingPathDataBackup);
|
|
1141 |
fileMan->Delete( cleanPath, CFileMan::ERecurse ); // Ignore error
|
|
1142 |
iFsSession.MkDirAll( cleanPath );
|
|
1143 |
cleanPath.Format(KMMCScBkupFormatDes, &path, &KMMCScBkupDataTransferDebuggingPathRoot, &KMMCScBkupDataTransferDebuggingPathDataPassive, &KMMCScBkupDataTransferDebuggingPathDataBackup);
|
|
1144 |
fileMan->Delete( cleanPath, CFileMan::ERecurse ); // Ignore error
|
|
1145 |
iFsSession.MkDirAll( cleanPath );
|
|
1146 |
cleanPath.Format(KMMCScBkupFormatDes, &path, &KMMCScBkupDataTransferDebuggingPathRoot, &KMMCScBkupDataTransferDebuggingPathDataActive, &KMMCScBkupDataTransferDebuggingPathDataBackup);
|
|
1147 |
fileMan->Delete( cleanPath, CFileMan::ERecurse ); // Ignore error
|
|
1148 |
iFsSession.MkDirAll( cleanPath );
|
|
1149 |
//
|
|
1150 |
CleanupStack::PopAndDestroy( fileMan );
|
|
1151 |
}
|
|
1152 |
|
|
1153 |
|
|
1154 |
// ---------------------------------------------------------------------------
|
|
1155 |
// CMMCScBkupEngineImpl::ClearRestoreFilesL()
|
|
1156 |
//
|
|
1157 |
//
|
|
1158 |
// ---------------------------------------------------------------------------
|
|
1159 |
void CMMCScBkupEngineImpl::ClearRestoreFilesL()
|
|
1160 |
{
|
|
1161 |
CFileMan* fileMan = CFileMan::NewL( iFsSession );
|
|
1162 |
CleanupStack::PushL( fileMan );
|
|
1163 |
|
|
1164 |
// Make directory, ignore error, ugly, functionise later on...
|
|
1165 |
_LIT(KMMCScBkupFormatDes, "%S%S%S%S");
|
|
1166 |
TFileName cleanPath;
|
|
1167 |
const TDesC& path = PathInfo::MemoryCardRootPath();
|
|
1168 |
|
|
1169 |
//
|
|
1170 |
cleanPath.Format(KMMCScBkupFormatDes, &path, &KMMCScBkupDataTransferDebuggingPathRoot, &KMMCScBkupDataTransferDebuggingPathDataJava, &KMMCScBkupDataTransferDebuggingPathDataRestore);
|
|
1171 |
fileMan->Delete( cleanPath, CFileMan::ERecurse ); // Ignore error
|
|
1172 |
iFsSession.MkDirAll( cleanPath );
|
|
1173 |
cleanPath.Format(KMMCScBkupFormatDes, &path, &KMMCScBkupDataTransferDebuggingPathRoot, &KMMCScBkupDataTransferDebuggingPathDataSystem, &KMMCScBkupDataTransferDebuggingPathDataRestore);
|
|
1174 |
fileMan->Delete( cleanPath, CFileMan::ERecurse ); // Ignore error
|
|
1175 |
iFsSession.MkDirAll( cleanPath );
|
|
1176 |
cleanPath.Format(KMMCScBkupFormatDes, &path, &KMMCScBkupDataTransferDebuggingPathRoot, &KMMCScBkupDataTransferDebuggingPathDataPassive, &KMMCScBkupDataTransferDebuggingPathDataRestore);
|
|
1177 |
fileMan->Delete( cleanPath, CFileMan::ERecurse ); // Ignore error
|
|
1178 |
iFsSession.MkDirAll( cleanPath );
|
|
1179 |
cleanPath.Format(KMMCScBkupFormatDes, &path, &KMMCScBkupDataTransferDebuggingPathRoot, &KMMCScBkupDataTransferDebuggingPathDataActive, &KMMCScBkupDataTransferDebuggingPathDataRestore);
|
|
1180 |
fileMan->Delete( cleanPath, CFileMan::ERecurse ); // Ignore error
|
|
1181 |
iFsSession.MkDirAll( cleanPath );
|
|
1182 |
//
|
|
1183 |
CleanupStack::PopAndDestroy( fileMan );
|
|
1184 |
}
|
|
1185 |
|
|
1186 |
#endif
|
|
1187 |
|
|
1188 |
|
|
1189 |
|
|
1190 |
|
|
1191 |
|
|
1192 |
|
|
1193 |
|
|
1194 |
|
|
1195 |
|
|
1196 |
|
|
1197 |
|
|
1198 |
|
|
1199 |
|
|
1200 |
|
|
1201 |
|
|
1202 |
|
|
1203 |
|
|
1204 |
|