|
1 |
|
2 // Copyright (c) 2004-2009 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: |
|
15 // Implementation of CPackageDataTransfer |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file |
|
21 */ |
|
22 #include "sbedataowner.h" |
|
23 #include "sbebufferhandler.h" |
|
24 #include "sbpackagedatatransfer.h" |
|
25 #include "sblog.h" |
|
26 |
|
27 #include <babackup.h> |
|
28 #include <swi/backuprestore.h> |
|
29 #include <swi/sisregistryentry.h> |
|
30 #include <swi/sisregistrypackage.h> |
|
31 |
|
32 #include "sbeparserdefs.h" |
|
33 |
|
34 namespace conn |
|
35 { |
|
36 _LIT(KSys, "?:\\sys\\*"); |
|
37 _LIT(KResource, "?:\\resource\\*"); |
|
38 _LIT(KPrivateMatch, "?:\\private\\*"); |
|
39 _LIT(KImport, "*\\import\\*"); |
|
40 _LIT(KTempPath, ":\\system\\temp\\"); |
|
41 |
|
42 CPackageDataTransfer* CPackageDataTransfer::NewL(TUid aPid, CDataOwnerManager* aDOM) |
|
43 /** Standard Symbian Constructor |
|
44 |
|
45 @param aPid Package Id |
|
46 @return a CPackageDataTransfer object |
|
47 */ |
|
48 { |
|
49 CPackageDataTransfer* self = CPackageDataTransfer::NewLC(aPid, aDOM); |
|
50 CleanupStack::Pop(self); |
|
51 return self; |
|
52 } |
|
53 |
|
54 CPackageDataTransfer* CPackageDataTransfer::NewLC(TUid aPid, CDataOwnerManager* aDOM) |
|
55 /** Standard Symbian Constructor |
|
56 |
|
57 @param aPid Package Id |
|
58 @return a CPackageDataTransfer object |
|
59 */ |
|
60 { |
|
61 CPackageDataTransfer *self = new(ELeave) CPackageDataTransfer(aPid, aDOM); |
|
62 CleanupStack::PushL(self); |
|
63 self->ConstructL(); |
|
64 return self; |
|
65 } |
|
66 |
|
67 CPackageDataTransfer::CPackageDataTransfer(TUid aPid, CDataOwnerManager* aDOM) : |
|
68 /** Standard C++ Constructor |
|
69 |
|
70 @param aPid Package Id |
|
71 */ |
|
72 iBufferSnapshotReader(NULL), |
|
73 iBufferFileWriter(NULL), iBufferSnapshotWriter(NULL), |
|
74 iPackageID(aPid), iSnapshot(NULL), iMetaData(NULL), ipDataOwnerManager(aDOM), iRestored(EFalse) |
|
75 { |
|
76 // needed for intiliazion |
|
77 iDriveList.SetLength(KMaxDrives); |
|
78 iDriveList.FillZ(); |
|
79 // needed for hashes in registry on drive C (i.e. MMC card app's hash) |
|
80 iDriveList[EDriveC] = ETrue; |
|
81 } |
|
82 |
|
83 void CPackageDataTransfer::ConstructL() |
|
84 /** Standard Symbian second phase constructor |
|
85 */ |
|
86 { |
|
87 User::LeaveIfError(iSWIRestore.Connect()); |
|
88 User::LeaveIfError(iSWIBackup.Connect()); |
|
89 User::LeaveIfError(iFs.Connect()); |
|
90 User::LeaveIfError(iFs.ShareProtected()); |
|
91 iRegistrationFile = HBufC::NewL(0); |
|
92 iFileName = HBufC::NewL(KMaxFileName); |
|
93 iTempFileName = HBufC::NewL(KMaxFileName); |
|
94 } |
|
95 |
|
96 CPackageDataTransfer::~CPackageDataTransfer() |
|
97 /** Standard C++ Destructor |
|
98 */ |
|
99 { |
|
100 iSWIRestore.Close(); |
|
101 iSWIBackup.Close(); |
|
102 iFileHandle.Close(); |
|
103 iFiles.ResetAndDestroy(); |
|
104 iPublicSelections.ResetAndDestroy(); |
|
105 |
|
106 delete iRegistrationFile; |
|
107 delete iBufferFileWriter; |
|
108 delete iBufferSnapshotReader; |
|
109 delete iBufferSnapshotWriter; |
|
110 delete iSnapshot; |
|
111 delete iMetaData; |
|
112 delete iFileName; |
|
113 delete iTempFileName; |
|
114 iFs.Close(); |
|
115 } |
|
116 |
|
117 |
|
118 void CPackageDataTransfer::WriteData(TAny* aItem, TPtr8& aBuffer, |
|
119 TInt aSize) |
|
120 /** Used to write data to a buffer |
|
121 |
|
122 @param aItem Item to write |
|
123 @param aBuffer Buffer to write aItem to |
|
124 @param aSize Size of the aItem |
|
125 */ |
|
126 { |
|
127 TUint8 *pos = reinterpret_cast<TUint8*>(aItem); |
|
128 for (TInt i = 0; i < aSize; ++i) |
|
129 { |
|
130 aBuffer.Append(pos[i]); |
|
131 } |
|
132 } |
|
133 |
|
134 TUid CPackageDataTransfer::PackageId() const |
|
135 /** Returns the package Id |
|
136 |
|
137 @return the package Id |
|
138 */ |
|
139 { |
|
140 return iPackageID; |
|
141 } |
|
142 |
|
143 void CPackageDataTransfer::BuildPackageFileList() |
|
144 /** Builds the file list of all files in the package on the given drive |
|
145 |
|
146 @param aDriveNumber drive the files must be on to be included in the list |
|
147 @param apSnapshot (OPTIONAL)A file will only be included if the file is not |
|
148 in the snapshot is newer than the file in the snapshot |
|
149 @param aFileNames on return the list of files |
|
150 */ |
|
151 { |
|
152 __LOG("CPackageDataTransfer::BuildPackageFileListL() - START"); |
|
153 // Establish a connection to the registry and read the list of |
|
154 // filenames into array. |
|
155 // |
|
156 |
|
157 iDriveList.SetLength(KMaxDrives); |
|
158 iDriveList.FillZ(); |
|
159 // also set EDriveC to True for hashesh of the registry |
|
160 iDriveList[EDriveC] = ETrue; |
|
161 |
|
162 TUint count = iFiles.Count(); |
|
163 __LOG1("CPackageDataTransfer::BuildPackageFileListL() - No of files: %d", count); |
|
164 while (count > 0) |
|
165 { |
|
166 count--; |
|
167 TBool remove = EFalse; |
|
168 TFileName fileName (*iFiles[count]); |
|
169 |
|
170 if ((fileName.FindC(KPrimaryBackupRegistrationFile) < 0) && |
|
171 (fileName.MatchC(KSys) < 0) && |
|
172 (fileName.MatchC(KResource) < 0) && |
|
173 (fileName.MatchC(KImport) < 0 )) |
|
174 { |
|
175 remove = ETrue; |
|
176 } |
|
177 |
|
178 // check read only media |
|
179 if (!remove && (NULL != iFs.IsFileInRom(fileName))) |
|
180 { |
|
181 remove = ETrue; |
|
182 } |
|
183 |
|
184 // check if real entry |
|
185 if (!remove) |
|
186 { |
|
187 TEntry entry; |
|
188 TInt err = iFs.Entry(fileName, entry); |
|
189 if (err != KErrNone) |
|
190 { |
|
191 remove = ETrue; |
|
192 } |
|
193 } |
|
194 |
|
195 // remove? |
|
196 if (remove) |
|
197 { |
|
198 delete iFiles[count]; |
|
199 iFiles[count] = NULL; |
|
200 iFiles.Remove(count); |
|
201 } |
|
202 else |
|
203 { |
|
204 // append to drive list |
|
205 TInt num; |
|
206 TChar ch = fileName[0]; |
|
207 TInt err = iFs.CharToDrive(ch, num); |
|
208 if (err == KErrNone) |
|
209 { |
|
210 iDriveList[num] = ETrue; |
|
211 } |
|
212 } |
|
213 } // for |
|
214 |
|
215 |
|
216 #ifdef SBE_LOGGING_ENABLED |
|
217 const TUint fNameCount = iFiles.Count(); |
|
218 if (fNameCount) |
|
219 { |
|
220 for(TUint k=0; k<fNameCount; k++) |
|
221 { |
|
222 const TDesC& file = *iFiles[k]; |
|
223 __LOG2("CPackageDataTransfer::BuildPackageFileListL() - Files Added - file entry[%03d] %S", k, &file); |
|
224 } |
|
225 } |
|
226 #endif |
|
227 |
|
228 |
|
229 __LOG("CPackageDataTransfer::BuildPackageFileListL() - END"); |
|
230 } |
|
231 |
|
232 |
|
233 void CPackageDataTransfer::GetExpectedDataSizeL(TPackageDataType aTransferType, TDriveNumber aDriveNumber, TUint& aSize) |
|
234 /** Get the expected data size of a request for data |
|
235 |
|
236 @param aTransferType the type of data to check the size of |
|
237 @param aDriveNumber the drive to check |
|
238 @param aSize on return the size of the data |
|
239 */ |
|
240 { |
|
241 __LOG("CPackageDataTransfer::GetExpectedDataSizeL - Begin getmetadata"); |
|
242 if (iMetaData == NULL) |
|
243 { |
|
244 TRAPD(err, iMetaData = iSWIBackup.GetMetaDataL(iPackageID, iFiles)); |
|
245 |
|
246 if(KErrNotSupported == err) |
|
247 {//Non-Removable package, nothing to backup |
|
248 aSize = 0; |
|
249 __LOG("CPackageDataTransfer::GetExpectedDataSizeL - GetMetaDataL - KErrNotSupported"); |
|
250 return; |
|
251 } |
|
252 else if(KErrNone != err) |
|
253 { |
|
254 __LOG1("CPackageDataTransfer::GetExpectedDataSizeL - GetMetaDataL leave with %d", err); |
|
255 User::Leave(err); |
|
256 } |
|
257 |
|
258 iMetaDataSize = iMetaData->Size(); |
|
259 BuildPackageFileList(); |
|
260 } |
|
261 __LOG("CPackageDataTransfer::GetExpectedDataSizeL - End getmetadata"); |
|
262 |
|
263 if (!IsDataOnDrive(aDriveNumber)) |
|
264 { |
|
265 // no data on drive |
|
266 aSize = 0; |
|
267 return; |
|
268 } |
|
269 |
|
270 aSize = iMetaData->Size(); |
|
271 TUint count = iFiles.Count(); |
|
272 |
|
273 switch (aTransferType) |
|
274 { |
|
275 case ESystemSnapshotData: |
|
276 { |
|
277 __LOG1("CPackageDataTransfer::GetExpectedDataSizeL() - START - ESystemSnapshotData - aDriveNumber: %c", aDriveNumber + 'A'); |
|
278 // Find all files |
|
279 aSize = (count * sizeof(TSnapshot)); |
|
280 __LOG1("CPackageDataTransfer::GetExpectedDataSizeL() - passive snapshot count: %d", count); |
|
281 for (TUint x = 0; x < count; x++) |
|
282 { |
|
283 const TDesC& fileName = *iFiles[x]; |
|
284 const TInt fileSize = fileName.Length();; |
|
285 __LOG2("CPackageDataTransfer::GetExpectedDataSizeL() - passive snapshot file: %S, size: %d", &fileName, fileSize); |
|
286 aSize += fileSize; |
|
287 } // for x |
|
288 |
|
289 break; |
|
290 } |
|
291 case ESystemData: |
|
292 { |
|
293 __LOG1("CPackageDataTransfer::GetExpectedDataSizeL() - START - ESystemData - aDriveNumber: %c", aDriveNumber + 'A'); |
|
294 |
|
295 aSize += sizeof(TInt); |
|
296 |
|
297 TEntry entry; |
|
298 __LOG1("CPackageDataTransfer::GetExpectedDataSizeL() - passive file count: %d", count); |
|
299 for (TUint x = 0; x < count; x++) |
|
300 { |
|
301 const TDesC& fileName = *iFiles[x]; |
|
302 TInt err = iFs.Entry(fileName, entry); |
|
303 TUint fileSize = entry.iSize; |
|
304 __LOG2("CPackageDataTransfer::GetExpectedDataSizeL() - passive file: %S, size: %d", &fileName, fileSize); |
|
305 switch(err) |
|
306 { |
|
307 case KErrNone: |
|
308 aSize += fileSize; |
|
309 break; |
|
310 case KErrNotFound: |
|
311 case KErrPathNotFound: |
|
312 case KErrBadName: |
|
313 __LOG2("CPackageDataTransfer::GetExpectedDataSizeL() - error getting passive file: %S, error: %d", &fileName, err); |
|
314 break; |
|
315 default: |
|
316 User::Leave(err); |
|
317 } |
|
318 } |
|
319 |
|
320 break; |
|
321 } |
|
322 default: |
|
323 { |
|
324 __LOG2("CPackageDataTransfer::GetExpectedDataSizeL() - No case for TransferType: %d, data owner 0x%08x", aTransferType, iPackageID.iUid); |
|
325 User::Leave(KErrNotSupported); |
|
326 } |
|
327 } // switch |
|
328 __LOG2("CPackageDataTransfer::GetExpectedDataSizeL() - END - size is: %d, data owner 0x%08x", aSize, iPackageID.iUid); |
|
329 } |
|
330 |
|
331 void CPackageDataTransfer::RequestDataL(TDriveNumber aDriveNumber, |
|
332 TPackageDataType aTransferType, |
|
333 TPtr8& aBuffer, |
|
334 TBool& aLastSection) |
|
335 /** Request data |
|
336 |
|
337 @param aDriveNumber the drive you want data from |
|
338 @param aTransferType the type of data you require |
|
339 @param aBuffer the buffer to write the data |
|
340 @param aLastSection has all the data been supplied. If all data is not |
|
341 supplied a further calls to the function will return the extra |
|
342 data. |
|
343 */ |
|
344 { |
|
345 __LOG6("CPackageDataTransfer::RequestDataL() - START - aDrive: %c, aTransferType: %d, iSecureId: 0x%08x, iState.iState: %d, iState.iTransferType: %d, aBuffer.Length(): %d", aDriveNumber + 'A', aTransferType, iPackageID.iUid, iState.iState, iState.iTransferType, aBuffer.Length()); |
|
346 //__LOGDATA("CPackageDataTransfer::RequestDataL() - %S", aBuffer.Ptr(), aBuffer.Length() ); |
|
347 |
|
348 TInt err = KErrNone; |
|
349 |
|
350 if (iMetaData == NULL) |
|
351 { |
|
352 TRAPD(err, iMetaData = iSWIBackup.GetMetaDataL(iPackageID, iFiles)); |
|
353 |
|
354 if(KErrNotSupported == err) |
|
355 {//Non-Removable package, nothing to backup |
|
356 iState.iState = ENone; |
|
357 Cleanup(); |
|
358 return; |
|
359 } |
|
360 else if(KErrNone != err) |
|
361 { |
|
362 iState.iState = ENone; |
|
363 Cleanup(); |
|
364 User::Leave(err); |
|
365 } |
|
366 |
|
367 iMetaDataSize = iMetaData->Size(); |
|
368 BuildPackageFileList(); |
|
369 } |
|
370 |
|
371 // Check our state |
|
372 if (!((iState.iState == ENone) || (iState.iState == EBuffer) || |
|
373 ((iState.iState == ERequest) && (iState.iDriveNumber == aDriveNumber) && |
|
374 (iState.iTransferType == aTransferType)))) |
|
375 { |
|
376 __LOG("CPackageDataTransfer::RequestDataL() - bad state => ERROR => KErrNotReady"); |
|
377 User::Leave(KErrNotReady); |
|
378 } |
|
379 |
|
380 // Set the state? |
|
381 if (iState.iState == ENone) |
|
382 { |
|
383 iState.iDriveNumber = aDriveNumber; |
|
384 iState.iTransferType = aTransferType; |
|
385 } |
|
386 |
|
387 switch (aTransferType) |
|
388 { |
|
389 case ESystemSnapshotData: |
|
390 { |
|
391 TRAP(err, RequestSnapshotL(aDriveNumber, aBuffer, aLastSection)); |
|
392 break; |
|
393 } |
|
394 case ESystemData: |
|
395 { |
|
396 TRAP(err, DoRequestDataL(aDriveNumber, aBuffer, aLastSection)); |
|
397 break; |
|
398 } |
|
399 default: |
|
400 { |
|
401 err = KErrNotSupported; |
|
402 } |
|
403 } // switch |
|
404 |
|
405 if (err != KErrNone) |
|
406 { |
|
407 iState.iState = ENone; |
|
408 Cleanup(); |
|
409 __LOG1("CPackageDataTransfer::RequestDataL() - Left with error: %d", err); |
|
410 User::Leave(err); |
|
411 } // if |
|
412 __LOG("CPackageDataTransfer::RequestDataL() - END"); |
|
413 } |
|
414 |
|
415 |
|
416 void CPackageDataTransfer::ReadData(TAny* aDestinationAddress, const TDesC8& aBuffer, TInt aSize) |
|
417 /** Read data from the given buffer |
|
418 |
|
419 @param aItem the item to fill |
|
420 @param aBuffer the buffer to read the data from |
|
421 @param aSize the size of the item to fill |
|
422 */ |
|
423 { |
|
424 TUint8* pos = reinterpret_cast<TUint8*>(aDestinationAddress); |
|
425 for (TInt i = 0; i < aSize; ++i) |
|
426 { |
|
427 pos[i] = aBuffer[i]; |
|
428 } |
|
429 } |
|
430 |
|
431 void CPackageDataTransfer::SupplyFileDataL( const TDesC8& aBuffer, TBool aLastSection) |
|
432 /** Restores files from the buffer to the package. |
|
433 |
|
434 @param aBuffer the buffer to read data from |
|
435 @param aLastSection has all data been supplied |
|
436 */ |
|
437 { |
|
438 __LOG1("CPackageDataTransfer::SupplyFileDataL() - START - aLastSection: %d", aLastSection); |
|
439 TUint8* current = const_cast<TUint8*>(aBuffer.Ptr()); |
|
440 const TUint8* end = current + aBuffer.Size(); |
|
441 while (current < end) |
|
442 { |
|
443 if (!iFixedHeaderRead) |
|
444 { |
|
445 if (ReadFromBufferF(iFixedHeader, current, end) == EFalse) |
|
446 { |
|
447 __LOG("CPackageDataTransfer::SupplyFileDataL() - ReadFromBufferF() returned False so breaking!"); |
|
448 break; |
|
449 } // if |
|
450 |
|
451 __LOG1("CPackageDataTransfer::SupplyFileDataL() - fixed header - iFileNameLength: %d", iFixedHeader.iFileNameLength); |
|
452 __LOG1("CPackageDataTransfer::SupplyFileDataL() - fixed header - iFileSize: %d", iFixedHeader.iFileSize); |
|
453 __LOG1("CPackageDataTransfer::SupplyFileDataL() - fixed header - iAttributes: %d", iFixedHeader.iAttributes); |
|
454 |
|
455 if ((iFixedHeader.iFileNameLength > KMaxFileName) || (!iFixedHeader.iFileNameLength)) |
|
456 { |
|
457 __LOG1("CBufferFileReader::SupplyFileDataL() - Leaving - iFileNameLength: %d more then MaxLength", iFixedHeader.iFileNameLength); |
|
458 User::Leave(KErrOverflow); |
|
459 } |
|
460 |
|
461 iFixedHeaderRead = ETrue; |
|
462 } //if |
|
463 if (!iFileNameRead) |
|
464 { |
|
465 TPtr8 ptr(reinterpret_cast<TUint8*>(const_cast<TUint16*>(iFileName->Des().Ptr())), iBytesRead,iFixedHeader.iFileNameLength * KCharWidthInBytes); |
|
466 |
|
467 if (ReadFromBufferV(ptr, iFixedHeader.iFileNameLength * KCharWidthInBytes, current, end) == EFalse) |
|
468 { |
|
469 iBytesRead = ptr.Size(); |
|
470 __LOG1("CPackageDataTransfer::SupplyFileDataL() - ReadFromBufferV() returned False - Filename bytes read: %d", iBytesRead); |
|
471 break; |
|
472 } // if |
|
473 |
|
474 if (iFixedHeader.iFileNameLength > KMaxFileName) |
|
475 { |
|
476 __LOG("CBufferFileReader::SupplyFileDataL() - Leave with KErrOverflow"); |
|
477 User::Leave(KErrOverflow); |
|
478 } |
|
479 |
|
480 iFileName->Des().SetLength(iFixedHeader.iFileNameLength); |
|
481 iFileNameRead = ETrue; |
|
482 |
|
483 __LOG1("CPackageDataTransfer::SupplyFileDataL() - FileName: %S", iFileName); |
|
484 } |
|
485 |
|
486 if (!iFileOpen) |
|
487 { |
|
488 TFileName tempPath; |
|
489 // 0 is first character which will reperesent a drive |
|
490 tempPath.Append((*iFileName)[0]); |
|
491 tempPath.Append(KTempPath); |
|
492 // Create file on the drive |
|
493 TInt tempErr = iFs.MkDirAll(tempPath); |
|
494 if (tempErr == KErrNone || tempErr == KErrAlreadyExists) |
|
495 { |
|
496 TFileName tempFile; |
|
497 tempErr = iFileHandle.Temp(iFs, tempPath, tempFile, EFileWrite); |
|
498 if (iTempFileName) |
|
499 { |
|
500 delete iTempFileName; |
|
501 } |
|
502 iTempFileName = tempFile.AllocL(); |
|
503 } |
|
504 |
|
505 if (tempErr != KErrNone) |
|
506 { |
|
507 __LOG2("CPackageDataTransfer::SupplyFileDataL() - Left creating temp file in: %S , with %d", &tempPath, tempErr); |
|
508 User::Leave(tempErr); |
|
509 } |
|
510 |
|
511 |
|
512 iFileOpen = ETrue; |
|
513 } |
|
514 |
|
515 // Write to the file |
|
516 TInt filesize; |
|
517 iFileHandle.Size(filesize); |
|
518 |
|
519 if ((end - current) >= (iFixedHeader.iFileSize - filesize)) |
|
520 { |
|
521 TPtr8 ptr(current, iFixedHeader.iFileSize - filesize, iFixedHeader.iFileSize - filesize); |
|
522 User::LeaveIfError(iFileHandle.Write(ptr)); |
|
523 |
|
524 // Write the attributes & modified time |
|
525 User::LeaveIfError(iFileHandle.Set(iFixedHeader.iModified, iFixedHeader.iAttributes, KEntryAttNormal)); |
|
526 |
|
527 TInt err = KErrNone; |
|
528 if (((*iFileName).FindC(KPrimaryBackupRegistrationFile) >= 0) || |
|
529 ((*iFileName).MatchC(KSys) >= 0) || |
|
530 ((*iFileName).MatchC(KResource) >= 0) || |
|
531 ((*iFileName).MatchC(KImport) >= 0) ) |
|
532 { |
|
533 __LOG("CPackageDataTransfer::SupplyFileDataL() - about to call RestoreFileL()"); |
|
534 TRAP(err, iSWIRestore.RestoreFileL(iFileHandle, *iFileName)); |
|
535 __LOG1("CPackageDataTransfer::SupplyFileDataL() - RestoreFileL() - err :%d", err); |
|
536 } |
|
537 else if ((*iFileName).MatchC(KPrivateMatch) >= 0) |
|
538 { |
|
539 User::LeaveIfError(iFs.MkDirAll((*iFileName))); |
|
540 User::LeaveIfError(iFileHandle.Rename((*iFileName))); |
|
541 } |
|
542 |
|
543 |
|
544 // Finished reset state |
|
545 iFileHandle.Close(); |
|
546 // Delete temp file |
|
547 if (iTempFileName) |
|
548 { |
|
549 // don't care if there is error |
|
550 iFs.Delete(*iTempFileName); |
|
551 delete iTempFileName; |
|
552 iTempFileName = NULL; |
|
553 } |
|
554 iFileOpen = EFalse; |
|
555 iFileNameRead = EFalse; |
|
556 iFileName->Des().SetLength(0); |
|
557 iFixedHeaderRead = EFalse; |
|
558 iBytesRead = 0; |
|
559 |
|
560 // Move current along |
|
561 current += iFixedHeader.iFileSize - filesize; |
|
562 } |
|
563 else |
|
564 { |
|
565 TInt fsize = end - current; |
|
566 TPtr8 ptr(current, fsize, fsize); |
|
567 User::LeaveIfError(iFileHandle.Write(ptr)); |
|
568 break; |
|
569 } |
|
570 } // while |
|
571 |
|
572 if (aLastSection && iFileOpen) |
|
573 { |
|
574 User::Leave(KErrUnderflow); |
|
575 } // if |
|
576 __LOG("CPackageDataTransfer::SupplyFileDataL() - END"); |
|
577 } // SupplyFileDataL |
|
578 |
|
579 void CPackageDataTransfer::SupplyDataL(TDriveNumber aDriveNumber, |
|
580 TPackageDataType aTransferType, |
|
581 TDesC8& aBuffer, |
|
582 TBool aLastSection) |
|
583 /** Request data |
|
584 |
|
585 @param aDriveNumber the drive you want data from |
|
586 @param aTransferType the type of data you require |
|
587 @param aBuffer the buffer to write the data |
|
588 @param aLastSection is this the last section |
|
589 */ |
|
590 { |
|
591 __LOG5("CPackageDataTransfer::SupplyDataL() - START - aDrive: %c, aTransferType: %d, iSecureId: 0x%08x, iState.iState: %d, iState.iTransferType: %d", aDriveNumber + 'A', aTransferType, iPackageID.iUid, iState.iState, iState.iTransferType); |
|
592 |
|
593 if (!iRestored) |
|
594 { |
|
595 TInt err = KErrNone; |
|
596 if (!((iState.iState == ENone) || |
|
597 ((iState.iState == ESupply || iState.iState == EBuffer) && (iState.iDriveNumber == aDriveNumber) && |
|
598 (iState.iTransferType == aTransferType)))) |
|
599 { |
|
600 __LOG("CPackageDataTransfer::SupplyDataL() - bad state => ERROR => KErrNotReady"); |
|
601 User::Leave(KErrNotReady); |
|
602 } |
|
603 |
|
604 // Set the state? |
|
605 if (iState.iState == ENone) |
|
606 { |
|
607 iState.iDriveNumber = aDriveNumber; |
|
608 iState.iTransferType = aTransferType; |
|
609 } // if |
|
610 |
|
611 switch (aTransferType) |
|
612 { |
|
613 case ESystemSnapshotData: |
|
614 { |
|
615 TRAP(err, SupplySnapshotL(aDriveNumber, aBuffer, aLastSection)); |
|
616 break; |
|
617 } |
|
618 case ESystemData: |
|
619 { |
|
620 TRAP(err, DoSupplyDataL(aDriveNumber, aBuffer, aLastSection)); |
|
621 break; |
|
622 } |
|
623 default: |
|
624 { |
|
625 err = KErrNotSupported; |
|
626 } |
|
627 } // switch |
|
628 |
|
629 if (err != KErrNone) // Must reset state on error |
|
630 { |
|
631 iState.iState = ENone; |
|
632 if (err != KErrAlreadyExists) |
|
633 { |
|
634 Cleanup(); |
|
635 iSWIRestore.Close(); |
|
636 User::LeaveIfError(iSWIRestore.Connect()); |
|
637 } |
|
638 __LOG1("CPackageDataTransfer::SupplyDataL() - Left with error: %d", err); |
|
639 User::Leave(err); |
|
640 } //else |
|
641 } |
|
642 |
|
643 __LOG("CPackageDataTransfer::SupplyDataL() - END"); |
|
644 |
|
645 } |
|
646 |
|
647 void CPackageDataTransfer::DoSupplyDataL(TDriveNumber /*aDriveNumber*/, const TDesC8& aBuffer, TBool aLastSection) |
|
648 /** Handles the actual supply of package data |
|
649 |
|
650 @param aDriveNumber not used. |
|
651 @param aBuffer the data that was supplied |
|
652 @param aLastSection was this the last section of data |
|
653 */ |
|
654 { |
|
655 __LOG3("CPackageDataTransfer::DoSupplyDataL() - START - aBuffer length: %d, aLastSection: %d, iState: %d", aBuffer.Length(), aLastSection, iState.iState); |
|
656 //__LOGDATA("CPackageDataTransfer::DoSupplyDataL() - %S", aBuffer.Ptr(), Min( aBuffer.Length(), 1024 )); |
|
657 |
|
658 TInt currentPos = 0; |
|
659 const TInt sourceBufferLength = aBuffer.Length(); |
|
660 |
|
661 if ( iState.iState != ESupply ) |
|
662 { |
|
663 if (iState.iState == ENone ) |
|
664 { |
|
665 __LOG("CPackageDataTransfer::DoSupplyDataL() - iState == ENone - set up for initial meta data read..."); |
|
666 |
|
667 // Retrieve metadata and file list from the buffer |
|
668 ReadData(&iMetaDataSize, aBuffer, sizeof(TInt)); |
|
669 __LOG1("CPackageDataTransfer::DoSupplyDataL() - meta data size: %d", iMetaDataSize); |
|
670 currentPos += sizeof(TInt); |
|
671 |
|
672 if (iMetaDataSize >= (KMaxTInt/2) || iMetaDataSize < 0) |
|
673 { |
|
674 __LOG("CPackageDataTransfer::DoSupplyDataL() - size read is too big"); |
|
675 User::Leave(KErrCorrupt); |
|
676 } |
|
677 |
|
678 __LOG1("CPackageDataTransfer::DoSupplyDataL() - creating meta data buffer of length: %d bytes", iMetaDataSize); |
|
679 HBufC8* metaDataBuffer = HBufC8::NewL(iMetaDataSize); |
|
680 delete iMetaData; |
|
681 iMetaData = metaDataBuffer; |
|
682 TPtr8 data(iMetaData->Des()); |
|
683 |
|
684 if (iMetaDataSize > sourceBufferLength ) |
|
685 { |
|
686 __LOG("CPackageDataTransfer::DoSupplyDataL() - not enough source data to obtain entire meta data in one pass..."); |
|
687 |
|
688 if (aLastSection) |
|
689 { |
|
690 __LOG("CPackageDataTransfer::DoSupplyDataL() - Underflow1"); |
|
691 User::Leave(KErrUnderflow); |
|
692 } |
|
693 else |
|
694 { |
|
695 data.Append(aBuffer.Mid(currentPos)); |
|
696 iState.iState = EBuffer; |
|
697 __LOG2("CPackageDataTransfer::DoSupplyDataL() - got %d bytes of meta data (%d bytes remaining) => changing state to EBuffer", data.Length(), iMetaDataSize - data.Length() ); |
|
698 } |
|
699 } |
|
700 else |
|
701 { |
|
702 __LOG("CPackageDataTransfer::DoSupplyDataL() - able to read entire meta data buffer in a single pass... "); |
|
703 data.Append(aBuffer.Mid(currentPos, iMetaDataSize)); |
|
704 currentPos += iMetaDataSize; |
|
705 } |
|
706 } |
|
707 else if (iState.iState == EBuffer) |
|
708 { |
|
709 __LOG1("CPackageDataTransfer::DoSupplyDataL() - iState == EBuffer, iMetaData length: %d", iMetaData->Length()); |
|
710 TPtr8 ptr( iMetaData->Des() ); |
|
711 const TInt leftToRead = iMetaDataSize - ptr.Length(); |
|
712 __LOG1("CPackageDataTransfer::DoSupplyDataL() - meta data buffer left to read: %d", leftToRead); |
|
713 |
|
714 if (sourceBufferLength < leftToRead) |
|
715 { |
|
716 __LOG("CPackageDataTransfer::DoSupplyDataL() - not enough source data to obtain remaining required meta data in this pass..."); |
|
717 |
|
718 if (aLastSection) |
|
719 { |
|
720 __LOG("CPackageDataTransfer::DoSupplyDataL() - Underflow2"); |
|
721 User::Leave(KErrUnderflow); |
|
722 } |
|
723 |
|
724 ptr.Append(aBuffer); |
|
725 __LOG1("CPackageDataTransfer::DoSupplyDataL() - meta data buffered again: %d", ptr.Length()); |
|
726 iState.iState = EBuffer; |
|
727 return; |
|
728 } |
|
729 else |
|
730 { |
|
731 __LOG("CPackageDataTransfer::DoSupplyDataL() - able to complete meta data read in this pass..."); |
|
732 ptr.Append( aBuffer.Left(leftToRead) ); |
|
733 __LOG1("CPackageDataTransfer::DoSupplyDataL() - meta data finished buffering, meta data size is now: %d", ptr.Length()); |
|
734 currentPos += leftToRead; |
|
735 } |
|
736 } |
|
737 |
|
738 const TBool metaDataComplete = ( iMetaData->Length() == iMetaDataSize ); |
|
739 __LOG4("CPackageDataTransfer::DoSupplyDataL() - meta data complete?: %d ( %d bytes remaining out of total: %d with current length of: %d)", metaDataComplete, iMetaDataSize - iMetaData->Length(), iMetaDataSize, iMetaData->Length() ); |
|
740 |
|
741 if ( metaDataComplete ) |
|
742 { |
|
743 __LOG("CPackageDataTransfer::DoSupplyDataL() - Asking SWI to start a package..."); |
|
744 iState.iState = ESupply; |
|
745 iSWIRestore.StartPackageL(iPackageID, *iMetaData); |
|
746 __LOG("CPackageDataTransfer::DoSupplyDataL() - SWI StartPackageL() completed OK"); |
|
747 } |
|
748 } |
|
749 |
|
750 if ( iState.iState == ESupply ) |
|
751 { |
|
752 __LOG1("CPackageDataTransfer::DoSupplyDataL() - iState == ESupply, currentPos: %d", currentPos); |
|
753 |
|
754 // Now restore each file and commit the changes |
|
755 const TPtrC8 ptr( aBuffer.Mid( currentPos ) ); |
|
756 //__LOGDATA("CPackageDataTransfer::DoSupplyDataL() - for supplyFileData %S", ptr.Ptr(), Min( ptr.Length(), 1024 )); |
|
757 |
|
758 SupplyFileDataL(ptr, aLastSection); |
|
759 __LOG("CPackageDataTransfer::DoSupplyDataL() - SupplyFileDataL() completed OK"); |
|
760 |
|
761 if (aLastSection) |
|
762 { |
|
763 __LOG("CPackageDataTransfer::DoSupplyDataL() - aLastSection - asking SWI to commit package..."); |
|
764 // now we can finalise the restore |
|
765 iSWIRestore.CommitPackageL(); |
|
766 __LOG("CPackageDataTransfer::DoSupplyDataL() - Package commited OK"); |
|
767 iRestored = ETrue; |
|
768 iState.iState = ENone; |
|
769 |
|
770 Cleanup(); |
|
771 iSWIRestore.Close(); |
|
772 User::LeaveIfError(iSWIRestore.Connect()); |
|
773 } |
|
774 } |
|
775 |
|
776 __LOG("CPackageDataTransfer::DoSupplyDataL() - END"); |
|
777 } // SupplyDataL |
|
778 |
|
779 void CPackageDataTransfer::SupplySnapshotL(TDriveNumber aDriveNumber, const TDesC8& aBuffer, TBool aLastSection) |
|
780 /** Handles the actual supply of snapshot data |
|
781 |
|
782 @param aDriveNumber the drive the snapshot is for |
|
783 @param aBuffer the data that was supplied |
|
784 @param aLastSection was this the last section of data |
|
785 */ |
|
786 { |
|
787 __LOG("CPackageDataTransfer::SupplySnapshotL() - START"); |
|
788 TInt err = KErrNone; |
|
789 if (iBufferSnapshotReader == NULL) |
|
790 { |
|
791 CSnapshotHolder* snapshot = CSnapshotHolder::NewL(); |
|
792 delete iSnapshot; |
|
793 iSnapshot = snapshot; |
|
794 iSnapshot->iDriveNumber = aDriveNumber; |
|
795 iBufferSnapshotReader = CBufferSnapshotReader::NewL(iSnapshot->iSnapshots); |
|
796 |
|
797 TRAP(err, iBufferSnapshotReader->StartL(aBuffer, aLastSection)); |
|
798 } // if |
|
799 else |
|
800 { |
|
801 TRAP(err, iBufferSnapshotReader->ContinueL(aBuffer, aLastSection)); |
|
802 } |
|
803 |
|
804 if ((err != KErrNone) || aLastSection) |
|
805 { |
|
806 delete iBufferSnapshotReader; |
|
807 iBufferSnapshotReader = NULL; |
|
808 |
|
809 User::LeaveIfError(err); |
|
810 } // if |
|
811 __LOG("CPackageDataTransfer::SupplySnapshotL() - END"); |
|
812 } |
|
813 |
|
814 void CPackageDataTransfer::DoRequestDataL(TDriveNumber aDriveNumber, TPtr8& aBuffer, TBool& aLastSection) |
|
815 /** Handles the actual request for package data |
|
816 |
|
817 @param aDriveNumber the drive the data is from |
|
818 @param aBuffer the buffer to put the supplied data |
|
819 @param aLastSection has all the data been supplied. If all data is not |
|
820 supplied a further calls to the function will return the extra |
|
821 data. |
|
822 */ |
|
823 { |
|
824 __LOG3("CPackageDataTransfer::DoRequestDataL() - START - iState: %d, iMetaData length: %d, iMetaDataSize: %d", iState.iState, iMetaData->Length(), iMetaDataSize); |
|
825 |
|
826 if (iState.iState == ENone || iState.iState == EBuffer) |
|
827 { |
|
828 if (!IsDataOnDrive(aDriveNumber)) |
|
829 { |
|
830 aLastSection = ETrue; |
|
831 __LOG("CPackageDataTransfer::DoRequestDataL() - END - no data on drive"); |
|
832 //__LOGDATA("CPackageDataTransfer::DoRequestDataL() - %S", aBuffer.Ptr(), aBuffer.Length()); |
|
833 return; |
|
834 } |
|
835 |
|
836 |
|
837 // Now write the meta data to the buffer. |
|
838 const TInt KSizeOfTInt = sizeof(TInt); |
|
839 const TInt availableBuffer = aBuffer.MaxSize() - aBuffer.Size(); |
|
840 __LOG1("CPackageDataTransfer::DoRequestDataL() - available Buffer %d", availableBuffer); |
|
841 |
|
842 if (iState.iState == ENone) |
|
843 { |
|
844 if ((availableBuffer - KSizeOfTInt) >= iMetaDataSize) |
|
845 { |
|
846 __LOG("CPackageDataTransfer::DoRequestDataL() - iState = ENone - can write entire meta data in single pass..."); |
|
847 |
|
848 WriteData(&iMetaDataSize, aBuffer, KSizeOfTInt); |
|
849 aBuffer.Append(*iMetaData); |
|
850 |
|
851 __LOG1("CPackageDataTransfer::DoRequestDataL() - iState = ENone - Written Meta Data, size %d", iMetaDataSize); |
|
852 } |
|
853 else if (availableBuffer - KSizeOfTInt > 0) |
|
854 { |
|
855 // can we write metasize and something else? |
|
856 __LOG("CPackageDataTransfer::DoRequestDataL() - iState = ENone - have room for some meta data (not all)..."); |
|
857 |
|
858 WriteData(&iMetaDataSize, aBuffer, KSizeOfTInt); |
|
859 |
|
860 // Write as much meta data as we can (allowing for buffer size) in this pass. |
|
861 const TInt amountOfMetaDataToWrite = availableBuffer - KSizeOfTInt; |
|
862 aBuffer.Append(iMetaData->Left(amountOfMetaDataToWrite)); |
|
863 |
|
864 // need to get rid of KSizeOfTInt |
|
865 iMetaDataLeft = iMetaDataSize - amountOfMetaDataToWrite; |
|
866 aLastSection = EFalse; |
|
867 |
|
868 iState.iState = EBuffer; |
|
869 __LOG2("CPackageDataTransfer::DoRequestDataL() - END - iState = ENone - Written MetaData %d, left %d", amountOfMetaDataToWrite, iMetaDataLeft); |
|
870 return; |
|
871 } |
|
872 else |
|
873 { |
|
874 __LOG("CPackageDataTransfer::DoRequestDataL() - END - iState = ENone - not enough space to write MetaData, Return for more"); |
|
875 return; |
|
876 } |
|
877 }// if |
|
878 else if (iState.iState == EBuffer) |
|
879 { |
|
880 if (availableBuffer - iMetaDataLeft >= 0) |
|
881 { |
|
882 const TInt readPosition = iMetaDataSize - iMetaDataLeft; |
|
883 __LOG2("CPackageDataTransfer::DoRequestDataL() - iState = EBuffer - enough space for remaining meta data in this pass, size %d, readPos: %d", iMetaDataLeft, readPosition); |
|
884 aBuffer.Append(iMetaData->Mid(readPosition)); |
|
885 } |
|
886 else |
|
887 { |
|
888 // continute buffer |
|
889 const TInt readPosition = iMetaDataSize - iMetaDataLeft; |
|
890 __LOG2("CPackageDataTransfer::DoRequestDataL() - iState = EBuffer - Still buffering Meta Data, Left to write %d, readPos: %d", iMetaDataLeft, readPosition); |
|
891 |
|
892 aBuffer.Append(iMetaData->Mid(readPosition, availableBuffer)); |
|
893 iMetaDataLeft -= availableBuffer; |
|
894 aLastSection = EFalse; |
|
895 |
|
896 __LOG1("CPackageDataTransfer::DoRequestDataL() - iState = EBuffer - END - Still buffering Meta Data, Left to write %d", iMetaDataLeft); |
|
897 return; |
|
898 } |
|
899 } |
|
900 |
|
901 TUint count = iFiles.Count(); |
|
902 __LOG1("CPackageDataTransfer::DoRequestDataL() - No of fileNames: %d", count); |
|
903 |
|
904 if (count == 0) |
|
905 { |
|
906 aLastSection = ETrue; |
|
907 __LOG("CPackageDataTransfer::DoRequestDataL() - END - no files"); |
|
908 return; |
|
909 } |
|
910 |
|
911 CDesCArray* files = new (ELeave) CDesCArrayFlat(KDesCArrayGranularity); |
|
912 CleanupStack::PushL(files); |
|
913 for (TUint i = 0; i < count; i++) |
|
914 { |
|
915 files->AppendL(*iFiles[i]); |
|
916 } |
|
917 |
|
918 |
|
919 __LOG("CPackageDataTransfer::DoRequestDataL() - starting buffer file writer..."); |
|
920 CBufferFileWriter* bufferFileWriter = CBufferFileWriter::NewL(iFs, files); |
|
921 delete iBufferFileWriter; |
|
922 iBufferFileWriter = bufferFileWriter; |
|
923 |
|
924 iBufferFileWriter->StartL(aBuffer, aLastSection); |
|
925 iState.iState = ERequest; |
|
926 __LOG("CPackageDataTransfer::DoRequestDataL() - iState is now ERequest"); |
|
927 |
|
928 if (aLastSection) |
|
929 { |
|
930 delete iBufferFileWriter; |
|
931 iBufferFileWriter = NULL; |
|
932 iState.iState = ENone; |
|
933 } // if |
|
934 |
|
935 CleanupStack::Pop(files); |
|
936 } |
|
937 else if (iBufferFileWriter != NULL) |
|
938 { |
|
939 __LOG("CPackageDataTransfer::DoRequestDataL() - continuing buffer file writer from last time..."); |
|
940 iBufferFileWriter->ContinueL(aBuffer, aLastSection); |
|
941 if (aLastSection) |
|
942 { |
|
943 delete iBufferFileWriter; |
|
944 iBufferFileWriter = NULL; |
|
945 iState.iState = ENone; |
|
946 } |
|
947 } |
|
948 |
|
949 //__LOGDATA("CPackageDataTransfer::DoRequestDataL() - %S", aBuffer.Ptr(), aBuffer.Length()); |
|
950 __LOG("CPackageDataTransfer::DoRequestDataL() - END"); |
|
951 } // RequestDataL |
|
952 |
|
953 void CPackageDataTransfer::RequestSnapshotL(TDriveNumber aDriveNumber, TPtr8& aBuffer, TBool& aLastSection) |
|
954 /** Handles the request for snapshot data |
|
955 |
|
956 @param aDriveNumber the drive the data is from |
|
957 @param aBuffer the buffer to put the supplied data |
|
958 @param aLastSection has all the data been supplied. If all data is not |
|
959 supplied a further calls to the function will return the extra |
|
960 data. |
|
961 */ |
|
962 { |
|
963 __LOG("CPackageDataTransfer::RequestSnapshotL() - START"); |
|
964 if (iBufferSnapshotWriter == NULL) |
|
965 { |
|
966 if (!IsDataOnDrive(aDriveNumber)) |
|
967 { |
|
968 aLastSection = ETrue; |
|
969 return; |
|
970 } |
|
971 |
|
972 TUint count = iFiles.Count(); |
|
973 __LOG1("CPackageDataTransfer::RequestSnapshotL() - No of fileNames: %d", count); |
|
974 if (count > 0) |
|
975 { |
|
976 RSnapshots* snapshots = new(ELeave) RSnapshots(); |
|
977 TCleanupItem cleanup(CleanupRPointerArray, snapshots); |
|
978 CleanupStack::PushL(cleanup); |
|
979 |
|
980 while (count--) |
|
981 { |
|
982 TEntry entry; |
|
983 const TDesC& fileName = *(iFiles[count]); |
|
984 TInt err = iFs.Entry(fileName, entry); |
|
985 if (err != KErrNone) |
|
986 { |
|
987 continue; |
|
988 } |
|
989 CSnapshot* snapshot = CSnapshot::NewLC(entry.iModified.Int64(), fileName); |
|
990 snapshots->AppendL(snapshot); |
|
991 CleanupStack::Pop(snapshot); |
|
992 } |
|
993 |
|
994 // Create a buffer writer |
|
995 // Convert entries into RSnapshots |
|
996 // ownership transfer |
|
997 CBufferSnapshotWriter* bufferSnapshotWriter = CBufferSnapshotWriter::NewL(snapshots); |
|
998 CleanupStack::Pop(snapshots); |
|
999 delete iBufferSnapshotWriter; |
|
1000 iBufferSnapshotWriter = bufferSnapshotWriter; |
|
1001 |
|
1002 |
|
1003 iBufferSnapshotWriter->StartL(aBuffer, aLastSection); |
|
1004 |
|
1005 } // if |
|
1006 else |
|
1007 { |
|
1008 aLastSection = ETrue; |
|
1009 } // else |
|
1010 |
|
1011 } // if |
|
1012 else |
|
1013 { |
|
1014 iBufferSnapshotWriter->ContinueL(aBuffer, aLastSection); |
|
1015 } // else |
|
1016 |
|
1017 if (aLastSection) |
|
1018 { |
|
1019 delete iBufferSnapshotWriter; |
|
1020 iBufferSnapshotWriter = NULL; |
|
1021 } |
|
1022 __LOG("CPackageDataTransfer::RequestSnapshotL() - END"); |
|
1023 } |
|
1024 |
|
1025 |
|
1026 /** Cleanup of the internal data |
|
1027 */ |
|
1028 void CPackageDataTransfer::Cleanup() |
|
1029 { |
|
1030 delete iBufferFileWriter; |
|
1031 iBufferFileWriter = NULL; |
|
1032 delete iBufferSnapshotReader; |
|
1033 iBufferSnapshotReader = NULL; |
|
1034 delete iBufferSnapshotWriter; |
|
1035 iBufferSnapshotWriter = NULL; |
|
1036 delete iSnapshot; |
|
1037 iSnapshot = NULL; |
|
1038 delete iMetaData; |
|
1039 iMetaData = NULL; |
|
1040 } |
|
1041 |
|
1042 /** |
|
1043 Checks if there is any data on the specified drive |
|
1044 |
|
1045 @param aDrive the drive to check on |
|
1046 @return ETrue if there is any data |
|
1047 */ |
|
1048 TBool CPackageDataTransfer::IsDataOnDrive(TDriveNumber aDrive) |
|
1049 { |
|
1050 if (!iDriveList[aDrive]) |
|
1051 { |
|
1052 return EFalse; |
|
1053 } |
|
1054 else |
|
1055 { |
|
1056 return ETrue; |
|
1057 } |
|
1058 |
|
1059 } |
|
1060 |
|
1061 TCommonBURSettings CPackageDataTransfer::CommonSettingsL() |
|
1062 /** Get the common settings of the data owner |
|
1063 |
|
1064 @pre CPackageDataTransfer::ParseFilesL() must have been called |
|
1065 @return the common settings of the data owner |
|
1066 @leave KErrNotReady if CPackageDataTransfer::ParseFilesL() not called |
|
1067 */ |
|
1068 { |
|
1069 TCommonBURSettings settings = ENoOptions; |
|
1070 |
|
1071 __LOG1("CPackageDataTransfer::CommonSettingsL() - System Supported: %d", iSystemInformation.iSupported); |
|
1072 if (iSystemInformation.iSupported) |
|
1073 { |
|
1074 settings |= EHasSystemFiles; |
|
1075 } |
|
1076 |
|
1077 return settings; |
|
1078 } |
|
1079 |
|
1080 TPassiveBURSettings CPackageDataTransfer::PassiveSettingsL() |
|
1081 /** Get the passive settings of the data owner |
|
1082 |
|
1083 @pre CPackageDataTransfer::ParseFilesL() must have been called |
|
1084 @return the passive settings of the data owner |
|
1085 @leave KErrNotReady if CPackageDataTransfer::ParseFilesL() not called |
|
1086 */ |
|
1087 { |
|
1088 __LOG1("CPackageDataTransfer::CommonSettingsL() - Public Supported: %d", iPublicInformation.iSupported); |
|
1089 |
|
1090 TPassiveBURSettings settings = ENoPassiveOptions; |
|
1091 |
|
1092 if (iPublicInformation.iSupported) |
|
1093 { |
|
1094 settings |= EHasPublicFiles; |
|
1095 } // if |
|
1096 |
|
1097 |
|
1098 return settings; |
|
1099 } |
|
1100 |
|
1101 TActiveBURSettings CPackageDataTransfer::ActiveSettingsL() |
|
1102 /** Get the active settings of the data owner |
|
1103 |
|
1104 @pre CPackageDataTransfer::ParseFilesL() must have been called |
|
1105 @return the active settings of the data owner |
|
1106 @leave KErrNotReady if CPackageDataTransfer::ParseFilesL() not called |
|
1107 */ |
|
1108 { |
|
1109 TActiveBURSettings settings = ENoActiveOptions; |
|
1110 |
|
1111 return settings; |
|
1112 } |
|
1113 |
|
1114 /** Set the registration file for the package |
|
1115 @param aFileName path including filename of the registration file |
|
1116 */ |
|
1117 void CPackageDataTransfer::SetRegistrationFileL(const TDesC& aFileName) |
|
1118 { |
|
1119 delete iRegistrationFile; |
|
1120 iRegistrationFile = aFileName.AllocL(); |
|
1121 } |
|
1122 |
|
1123 /** Parses the package registration file |
|
1124 @pre CPackageDataTransfer::SetRegistrationFile() must have been called |
|
1125 */ |
|
1126 void CPackageDataTransfer::ParseL() |
|
1127 { |
|
1128 if ((*iRegistrationFile).FindF(KPrimaryBackupRegistrationFile) == KErrNotFound) |
|
1129 { |
|
1130 User::Leave(KErrNotReady); |
|
1131 } |
|
1132 |
|
1133 ipDataOwnerManager->ParserProxy().ParseL(*iRegistrationFile, *this); |
|
1134 } |
|
1135 |
|
1136 |
|
1137 void CPackageDataTransfer::GetRawPublicFileListL(TDriveNumber aDriveNumber, |
|
1138 RRestoreFileFilterArray& aRestoreFileFilter) |
|
1139 /** Gets the raw public file list |
|
1140 |
|
1141 @param aDriveNumber the drive to return the list for |
|
1142 @param aRestoreFileFilter on return the file filter |
|
1143 */ |
|
1144 { |
|
1145 // Convert drive number to letter |
|
1146 TChar drive; |
|
1147 User::LeaveIfError(iFs.DriveToChar(aDriveNumber, drive)); |
|
1148 |
|
1149 const TInt count = iPublicSelections.Count(); |
|
1150 for (TInt x = 0; x < count; x++) |
|
1151 { |
|
1152 CSelection* selection = iPublicSelections[x]; |
|
1153 TBool include = (selection->SelectionType() == EInclude); |
|
1154 TFileName filename; |
|
1155 |
|
1156 const TDesC& selectionName = selection->SelectionName(); |
|
1157 // Name |
|
1158 TBool add = false; |
|
1159 if ((selectionName.Length() > 1) && (selectionName[1] == KColon()[0])) |
|
1160 { |
|
1161 // It has a drive specified |
|
1162 TInt drive; |
|
1163 iFs.CharToDrive(selectionName[0], drive); |
|
1164 if (static_cast<TDriveNumber>(drive) == aDriveNumber) |
|
1165 { |
|
1166 add = true; |
|
1167 filename.Append(selectionName); |
|
1168 } // if |
|
1169 } // if |
|
1170 else if (selectionName[0] == KBackSlash()[0]) |
|
1171 { |
|
1172 add = true; |
|
1173 filename.Append(drive); |
|
1174 filename.Append(KColon); |
|
1175 filename.Append(selectionName); |
|
1176 } // if |
|
1177 else |
|
1178 { |
|
1179 filename.Append(drive); |
|
1180 filename.Append(KColon); |
|
1181 filename.Append(KBackSlash); |
|
1182 filename.Append(selectionName); |
|
1183 } // else |
|
1184 |
|
1185 if (add) |
|
1186 { |
|
1187 aRestoreFileFilter.AppendL(TRestoreFileFilter(include, filename)); |
|
1188 } // if |
|
1189 } // for x |
|
1190 } |
|
1191 |
|
1192 |
|
1193 void CPackageDataTransfer::GetPublicFileListL(TDriveNumber aDriveNumber, RFileArray& aFiles) |
|
1194 /** Gets the public file list |
|
1195 |
|
1196 Gets the public file list for the given drive |
|
1197 @param aDriveNumber the drive to retrieve the public files for |
|
1198 @param aFiles on return a list of public files |
|
1199 */ |
|
1200 { |
|
1201 _LIT(KDrive, "?:"); |
|
1202 _LIT(KDriveAndSlash, "?:\\"); |
|
1203 _LIT( KExclamationAsDrive, "!"); // Used to generic drives for public data as in .SIS file package |
|
1204 |
|
1205 // Split selections into include and exclude |
|
1206 RArray<TPtrC> include; |
|
1207 CleanupClosePushL(include); |
|
1208 RArray<TPtrC> exclude; |
|
1209 CleanupClosePushL(exclude); |
|
1210 TInt count = iPublicSelections.Count(); |
|
1211 |
|
1212 |
|
1213 __LOG("CPackageDataTransfer::GetPublicFileListL() - file selection listing...:"); |
|
1214 for (TInt x = 0; x < count; x++) |
|
1215 { |
|
1216 const TDesC& selectionName = iPublicSelections[x]->SelectionName(); |
|
1217 __LOG3("CPackageDataTransfer::GetPublicFileListL() - selection[%03d]: %S, type: %d", x, &selectionName, iPublicSelections[x]->SelectionType()); |
|
1218 if (iPublicSelections[x]->SelectionType() == EInclude) |
|
1219 { |
|
1220 include.AppendL(selectionName); |
|
1221 } // if |
|
1222 else |
|
1223 { |
|
1224 exclude.AppendL(selectionName); |
|
1225 } // else |
|
1226 } // for x |
|
1227 |
|
1228 // Loop through all includes |
|
1229 count = include.Count(); |
|
1230 __LOG("CPackageDataTransfer::GetPublicFileListL() - include listing...:"); |
|
1231 for (TInt x = 0; x < count; x++) |
|
1232 { |
|
1233 TFileName fileName; |
|
1234 TChar drive; |
|
1235 User::LeaveIfError(iFs.DriveToChar(aDriveNumber, drive)); |
|
1236 |
|
1237 const TPtrC includeEntry( include[x] ); |
|
1238 __LOG2("CPackageDataTransfer::GetPublicFileListL() - entry[%03d] is: %S", x, &includeEntry); |
|
1239 |
|
1240 // See if the drive is specified |
|
1241 if (include[x][0] == KBackSlash()[0]) |
|
1242 { |
|
1243 // Add the drive |
|
1244 fileName.Append(drive); |
|
1245 fileName.Append(KColon); |
|
1246 fileName.Append(include[x]); |
|
1247 } |
|
1248 else |
|
1249 { |
|
1250 // Handle the Exclamation (!) in Public data paths, if any. |
|
1251 // Exclamation mark in place of drive letter means that the path is to be checked in all available drives. |
|
1252 // And any dataowner can keep their public files in any drive and it can be mentioned in backup_registration file as below. |
|
1253 // <public_backup> |
|
1254 // <include_directory name="!:\mydatabases\" /> |
|
1255 // </public_backup> |
|
1256 |
|
1257 if ( includeEntry[0] == KExclamationAsDrive()[0]) |
|
1258 { |
|
1259 // Map public data path using current drive being backed up. |
|
1260 fileName.Zero(); |
|
1261 fileName.Append(drive); |
|
1262 fileName.Append( includeEntry.Mid(1) ); |
|
1263 } |
|
1264 else |
|
1265 if (static_cast<TChar>(includeEntry[0]).GetUpperCase() == drive.GetUpperCase()) |
|
1266 { |
|
1267 fileName.Copy(includeEntry); |
|
1268 } // else |
|
1269 |
|
1270 } // else |
|
1271 |
|
1272 __LOG2("CPackageDataTransfer::GetPublicFileListL() - entry[%03d] filename is therefore: %S", x, &fileName); |
|
1273 if (fileName.Length() > 0) |
|
1274 { |
|
1275 |
|
1276 // Check to see if fileName is just a drive(we cant get an entry) |
|
1277 TBool isDrive = EFalse; |
|
1278 if ((fileName.MatchF(KDrive) != KErrNotFound) || |
|
1279 (fileName.MatchF(KDriveAndSlash) != KErrNotFound)) |
|
1280 { |
|
1281 isDrive = ETrue; |
|
1282 __LOG("CPackageDataTransfer::GetPublicFileListL() - filename is a drive"); |
|
1283 } // if |
|
1284 |
|
1285 TEntry entry; |
|
1286 TBool isEntry = EFalse; |
|
1287 if (!isDrive) |
|
1288 { |
|
1289 TInt err = iFs.Entry(fileName, entry); |
|
1290 __LOG1("CPackageDataTransfer::GetPublicFileListL() - get entry error: %d", err); |
|
1291 entry.iName = fileName; |
|
1292 switch (err) |
|
1293 { |
|
1294 case KErrNone: |
|
1295 isEntry = ETrue; |
|
1296 break; |
|
1297 case KErrNotFound: |
|
1298 case KErrPathNotFound: |
|
1299 case KErrBadName: |
|
1300 break; |
|
1301 default: |
|
1302 User::Leave(err); |
|
1303 } // switch |
|
1304 } // if |
|
1305 |
|
1306 if (isDrive || (isEntry && entry.IsDir())) |
|
1307 { |
|
1308 __LOG("CPackageDataTransfer::GetPublicFileListL() - parsing directory..."); |
|
1309 ParseDirL(fileName, exclude, aFiles); |
|
1310 |
|
1311 #ifdef SBE_LOGGING_ENABLED |
|
1312 const TInt fNameCount = aFiles.Count(); |
|
1313 if (fNameCount) |
|
1314 { |
|
1315 for(TInt k=0; k<fNameCount; k++) |
|
1316 { |
|
1317 const TDesC& fileName = aFiles[k].iName; |
|
1318 __LOG2("CPackageDataTransfer::GetPublicFileListL() - directory entry[%03d] %S", k, &fileName); |
|
1319 } |
|
1320 } |
|
1321 |
|
1322 __LOG("CPackageDataTransfer::GetPublicFileListL() - end of parsing directory"); |
|
1323 #endif |
|
1324 } // if |
|
1325 else |
|
1326 { |
|
1327 if (isEntry) |
|
1328 { |
|
1329 const TBool isExcluded = IsExcluded(ETrue, fileName, exclude); |
|
1330 if (!isExcluded) |
|
1331 { |
|
1332 __LOG1("CPackageDataTransfer::GetPublicFileListL() - adding fully verified file: %S", &fileName); |
|
1333 // Add to list of files |
|
1334 aFiles.AppendL(entry); |
|
1335 } // if |
|
1336 else |
|
1337 { |
|
1338 __LOG("CPackageDataTransfer::GetPublicFileListL() - file is excluded!"); |
|
1339 } |
|
1340 } // if |
|
1341 } // else |
|
1342 } // if |
|
1343 } // for x |
|
1344 |
|
1345 CleanupStack::PopAndDestroy(&exclude); |
|
1346 CleanupStack::PopAndDestroy(&include); |
|
1347 __LOG("CPackageDataTransfer::GetPublicFileListL() - END"); |
|
1348 } |
|
1349 |
|
1350 void CPackageDataTransfer::ParseDirL(const TDesC& aDirName, const RArray<TPtrC>& aExclude, RFileArray& apFileEntries) |
|
1351 /** Parses a directory for files. |
|
1352 |
|
1353 Parses the given directory for files. The function is called recursivily if a directory is found. |
|
1354 |
|
1355 @param aDirName the directory to search |
|
1356 @param aExclude a list of directories or files to exclude |
|
1357 @param apFileEntries Array of file entries to populate |
|
1358 */ |
|
1359 { |
|
1360 CDir* pFiles = NULL; |
|
1361 |
|
1362 // This function requires a / on the end otherwise it does not work! |
|
1363 TFileName path = aDirName; |
|
1364 if (path[path.Length() - 1] != KBackSlash()[0]) |
|
1365 path.Append(KBackSlash); |
|
1366 |
|
1367 TInt err = iFs.GetDir(path, KEntryAttMatchMask, ESortNone, pFiles); |
|
1368 CleanupStack::PushL(pFiles); // Add to cleanup stack |
|
1369 |
|
1370 if ((err != KErrNone) && (err != KErrNotFound)) // Do we need to leave? |
|
1371 { |
|
1372 User::Leave(err); |
|
1373 } // if |
|
1374 |
|
1375 TUint count = pFiles->Count(); |
|
1376 while(count--) |
|
1377 { |
|
1378 TEntry entry = (*pFiles)[count]; |
|
1379 |
|
1380 // Build full path |
|
1381 TFileName filename = path; |
|
1382 filename.Append(entry.iName); |
|
1383 entry.iName = filename; |
|
1384 |
|
1385 if (!IsExcluded(ETrue, filename, aExclude)) |
|
1386 { |
|
1387 if (entry.IsDir()) |
|
1388 { |
|
1389 ParseDirL(filename, aExclude, apFileEntries); |
|
1390 } // if |
|
1391 else |
|
1392 { |
|
1393 // Add to list of files |
|
1394 apFileEntries.AppendL(entry); |
|
1395 } // else |
|
1396 } // if |
|
1397 } // for x |
|
1398 |
|
1399 // Cleanup |
|
1400 CleanupStack::PopAndDestroy(pFiles); |
|
1401 } |
|
1402 |
|
1403 void CPackageDataTransfer::GetDriveListL(TDriveList& aDriveList) |
|
1404 /** Get the drive list for the data owner |
|
1405 |
|
1406 @pre CDataOwner::ParseFilesL() must have been called |
|
1407 @return the active settings of the data owner |
|
1408 @leave KErrNotReady if CDataOwner::ParseFilesL() not called |
|
1409 */ |
|
1410 { |
|
1411 __LOG1("CPackageDataTransfer::GetDriveListL() - Begin - SID: 0x%08x", iPackageID.iUid); |
|
1412 |
|
1413 // We now no longer return the Z drive, it has been decided that the Z drive will always be the |
|
1414 // ROM. Backing up and restoring the ROM drive should not be possible, as what is the point |
|
1415 |
|
1416 // build package files |
|
1417 if (iMetaData == NULL) |
|
1418 { |
|
1419 iMetaData = iSWIBackup.GetMetaDataL(iPackageID, iFiles); |
|
1420 iMetaDataSize = iMetaData->Size(); |
|
1421 BuildPackageFileList(); |
|
1422 } |
|
1423 |
|
1424 TDriveList notToBackup = ipDataOwnerManager->Config().ExcludeDriveList(); |
|
1425 |
|
1426 for (TInt i = 0; i < KMaxDrives; i++) |
|
1427 { |
|
1428 if (notToBackup[i]) // if this drive is set |
|
1429 { |
|
1430 // don't include this drive |
|
1431 iDriveList[i] = EFalse; |
|
1432 } |
|
1433 } |
|
1434 |
|
1435 aDriveList = iDriveList; |
|
1436 __LOG1("CPackageDataTransfer::GetDriveListL() - end - SID: 0x%08x", iPackageID.iUid); |
|
1437 } |
|
1438 |
|
1439 TBool CPackageDataTransfer::IsExcluded(const TBool aIsPublic, const TDesC& aFileName, const RArray<TPtrC>& aExclude) |
|
1440 /** Checks to see if a given file is excluded |
|
1441 |
|
1442 Checks to see if the given file is not in a private directory or in the exclude list. |
|
1443 |
|
1444 @param aFileName file to check |
|
1445 @param aExclude list of excluded files |
|
1446 @return ETrue if excluded otherwise EFalse |
|
1447 */ |
|
1448 { |
|
1449 _LIT(KPrivateMatch, "?:\\private\\*"); |
|
1450 _LIT(KSystem, "?:\\system\\*"); |
|
1451 _LIT(KResource, "?:\\resource\\*"); |
|
1452 _LIT(KOther, "*\\..\\*"); |
|
1453 TBool ret = EFalse; |
|
1454 |
|
1455 // Check it is not in sys, resource, system or backwards path |
|
1456 ret = (!((aFileName.MatchF(KSystem) == KErrNotFound) && |
|
1457 (aFileName.MatchF(KResource) == KErrNotFound) && |
|
1458 (aFileName.MatchF(KSys) == KErrNotFound) && |
|
1459 (aFileName.MatchF(KOther) == KErrNotFound) |
|
1460 ) |
|
1461 ); |
|
1462 |
|
1463 // If this is public backup remove the private directory |
|
1464 if (!ret && aIsPublic) |
|
1465 { |
|
1466 ret = (!(aFileName.MatchF(KPrivateMatch) == KErrNotFound)); |
|
1467 } |
|
1468 |
|
1469 if (!ret) |
|
1470 { |
|
1471 // Is the file in the exclude list? |
|
1472 const TInt count = aExclude.Count(); |
|
1473 for (TInt x = 0; !ret && x < count; x++) |
|
1474 { |
|
1475 if (aExclude[x][0] == KBackSlash()[0]) |
|
1476 { |
|
1477 // Compare with out drive |
|
1478 _LIT(KQuestionMark, "?"); |
|
1479 TFileName compare = KQuestionMark(); |
|
1480 compare.Append(aExclude[x]); |
|
1481 ret = (!(aFileName.MatchF(compare) == KErrNotFound)); |
|
1482 } // if |
|
1483 else |
|
1484 { |
|
1485 // Normal compare |
|
1486 ret = (aFileName.CompareF(aExclude[x]) == 0); |
|
1487 } // else |
|
1488 } // for x |
|
1489 } // if |
|
1490 |
|
1491 __LOG2("CDataOwner::IsExcluded() - END - returns excluded: %d for file: %S", ret, &aFileName); |
|
1492 return ret; |
|
1493 } |
|
1494 |
|
1495 /** |
|
1496 Method will be used for Sort on RPointerArray |
|
1497 |
|
1498 @param aFirst CPackageDataTransfer& package id to compare |
|
1499 @param aSecond CPackageDataTransfer& package id to compare |
|
1500 |
|
1501 @see RArray::Sort() |
|
1502 */ |
|
1503 TInt CPackageDataTransfer::Compare(const CPackageDataTransfer& aFirst, const CPackageDataTransfer& aSecond) |
|
1504 { |
|
1505 if (aFirst.PackageId().iUid < aSecond.PackageId().iUid) |
|
1506 { |
|
1507 return -1; |
|
1508 } |
|
1509 else if (aFirst.PackageId().iUid > aSecond.PackageId().iUid) |
|
1510 { |
|
1511 return 1; |
|
1512 } |
|
1513 else |
|
1514 { |
|
1515 return 0; |
|
1516 } |
|
1517 } |
|
1518 |
|
1519 /** |
|
1520 Method will be used for Find on RPointerArray |
|
1521 |
|
1522 @param aFirst CPackageDataTransfer& package id to match |
|
1523 @param aSecond CPackageDataTransfer& package id to match |
|
1524 |
|
1525 @see RArray::Find() |
|
1526 */ |
|
1527 TBool CPackageDataTransfer::Match(const CPackageDataTransfer& aFirst, const CPackageDataTransfer& aSecond) |
|
1528 { |
|
1529 return (aFirst.PackageId().iUid == aSecond.PackageId().iUid); |
|
1530 } |
|
1531 |
|
1532 |
|
1533 // |
|
1534 // MContentHandler Implementaion // |
|
1535 // |
|
1536 |
|
1537 |
|
1538 |
|
1539 void CPackageDataTransfer::OnStartDocumentL(const RDocumentParameters& /*aDocParam*/, TInt aErrorCode) |
|
1540 /** MContentHandler::OnStartDocumentL() |
|
1541 */ |
|
1542 { |
|
1543 if (aErrorCode != KErrNone) |
|
1544 { |
|
1545 __LOG1("CPackageDataTransfer::OnStartDocumentL() - error = %d", aErrorCode); |
|
1546 User::Leave(aErrorCode); |
|
1547 } |
|
1548 } |
|
1549 |
|
1550 void CPackageDataTransfer::OnEndDocumentL(TInt aErrorCode) |
|
1551 /** MContentHandler::OnEndDocumentL() |
|
1552 */ |
|
1553 { |
|
1554 // just to satisfy UREL compiler |
|
1555 (void) aErrorCode; |
|
1556 __LOG1("CPackageDataTransfer::OnEndDocumentL() - error = %d", aErrorCode); |
|
1557 } |
|
1558 |
|
1559 void CPackageDataTransfer::OnStartElementL(const RTagInfo& aElement, |
|
1560 const RAttributeArray& aAttributes, |
|
1561 TInt aErrorCode) |
|
1562 /** MContentHandler::OnStartElementL() |
|
1563 |
|
1564 @leave KErrUnknown an unknown element |
|
1565 */ |
|
1566 { |
|
1567 if (aErrorCode != KErrNone) |
|
1568 { |
|
1569 __LOG1("CPackageDataTransfer::OnStartElementL() - error = %d", aErrorCode); |
|
1570 User::Leave(aErrorCode); |
|
1571 } |
|
1572 |
|
1573 TPtrC8 localName = aElement.LocalName().DesC(); |
|
1574 if (localName == KIncludeFile) |
|
1575 { |
|
1576 HandlePathL(EInclude, aAttributes, EFalse); |
|
1577 } |
|
1578 else if (!localName.CompareF(KIncludeDirectory)) |
|
1579 { |
|
1580 HandlePathL(EInclude, aAttributes, ETrue); |
|
1581 } |
|
1582 else if (!localName.CompareF(KExclude)) |
|
1583 { |
|
1584 HandlePathL(EExclude, aAttributes, EFalse); |
|
1585 } |
|
1586 else if (!localName.CompareF(KBackupRegistration)) |
|
1587 { |
|
1588 HandleBackupRegistrationL(aAttributes); |
|
1589 } |
|
1590 else if (!localName.CompareF(KPublicBackup)) |
|
1591 { |
|
1592 User::LeaveIfError(HandlePublicBackup(aAttributes)); |
|
1593 } |
|
1594 else if (!localName.CompareF(KSystemBackup)) |
|
1595 { |
|
1596 User::LeaveIfError(HandleSystemBackup(aAttributes)); |
|
1597 } |
|
1598 else |
|
1599 { |
|
1600 __LOG1("CPackageDataTransfer::OnStartElementL() - Unknown element while parsing 0x%08x", iPackageID.iUid); |
|
1601 } |
|
1602 |
|
1603 } |
|
1604 |
|
1605 |
|
1606 void CPackageDataTransfer::OnEndElementL(const RTagInfo& aElement, TInt aErrorCode) |
|
1607 /** MContentHandler::OnEndElementL() |
|
1608 */ |
|
1609 { |
|
1610 if (aErrorCode != KErrNone) |
|
1611 { |
|
1612 __LOG1("CPackageDataTransfer::OnEndElementL() - error = %d", aErrorCode); |
|
1613 User::Leave(aErrorCode); |
|
1614 } |
|
1615 |
|
1616 TPtrC8 localName = aElement.LocalName().DesC(); |
|
1617 if (!localName.CompareF(KPublicBackup)) |
|
1618 { |
|
1619 iCurrentElement = ENoElement; |
|
1620 } // if |
|
1621 } |
|
1622 |
|
1623 void CPackageDataTransfer::OnContentL(const TDesC8& /*aBytes*/, TInt /*aErrorCode*/) |
|
1624 /** MContentHandler::OnContentL() |
|
1625 */ |
|
1626 { |
|
1627 // Not handled |
|
1628 } |
|
1629 |
|
1630 void CPackageDataTransfer::OnStartPrefixMappingL(const RString& /*aPrefix*/, |
|
1631 const RString& /*aUri*/, TInt /*aErrorCode*/) |
|
1632 /** MContentHandler::OnStartPrefixMappingL() |
|
1633 */ |
|
1634 { |
|
1635 // Not handled |
|
1636 } |
|
1637 |
|
1638 void CPackageDataTransfer::OnEndPrefixMappingL(const RString& /*aPrefix*/, TInt /*aErrorCode*/) |
|
1639 /** MContentHandler::OnEndPrefixMappingL() |
|
1640 */ |
|
1641 { |
|
1642 // Not handled |
|
1643 } |
|
1644 |
|
1645 void CPackageDataTransfer::OnIgnorableWhiteSpaceL(const TDesC8& /*aBytes*/, TInt /*aErrorCode*/) |
|
1646 /** MContentHandler::OnIgnorableWhiteSpaceL() |
|
1647 */ |
|
1648 { |
|
1649 // Not handled |
|
1650 } |
|
1651 |
|
1652 void CPackageDataTransfer::OnSkippedEntityL(const RString& /*aName*/, TInt /*aErrorCode*/) |
|
1653 /** MContentHandler::OnSkippedEntityL() |
|
1654 */ |
|
1655 { |
|
1656 // Not handled |
|
1657 } |
|
1658 |
|
1659 void CPackageDataTransfer::OnProcessingInstructionL(const TDesC8& /*aTarget*/, |
|
1660 const TDesC8& /*aData*/, |
|
1661 TInt /*aErrorCode*/) |
|
1662 /** MContentHandler::OnProcessingInstructionL() |
|
1663 */ |
|
1664 { |
|
1665 // Not handled |
|
1666 } |
|
1667 |
|
1668 void CPackageDataTransfer::OnError(TInt aErrorCode) |
|
1669 /** MContentHandler::OnError() |
|
1670 |
|
1671 @leave aErrorCode |
|
1672 */ |
|
1673 { |
|
1674 (void)aErrorCode; |
|
1675 __LOG1("CPackageDataTransfer::OnError() - error = %d", aErrorCode); |
|
1676 } |
|
1677 |
|
1678 TAny* CPackageDataTransfer::GetExtendedInterface(const TInt32 /*aUid*/) |
|
1679 /** MContentHandler::OnEndPrefixMappingL() |
|
1680 */ |
|
1681 { |
|
1682 return NULL; |
|
1683 } |
|
1684 |
|
1685 void CPackageDataTransfer::HandleBackupRegistrationL(const RAttributeArray& aAttributes) |
|
1686 /** Handles the "backup_registration" element |
|
1687 |
|
1688 @param aAttributes the attributes for the element |
|
1689 @return KErrNone no errors |
|
1690 @return KErrUnknown unknown version |
|
1691 */ |
|
1692 { |
|
1693 _LIT8(KVersion, "1.0"); |
|
1694 |
|
1695 if (aAttributes.Count() == 1) |
|
1696 { |
|
1697 // Check the version is correct. |
|
1698 if (aAttributes[0].Value().DesC() != KVersion()) // Only version we know about |
|
1699 { |
|
1700 __LOG1("CDataOwner::HandleBackupRegistrationL() - Unknown version at SID(0x%08x)", iPackageID.iUid); |
|
1701 User::Leave(KErrNotSupported); |
|
1702 } // else |
|
1703 } // if |
|
1704 } |
|
1705 |
|
1706 |
|
1707 TInt CPackageDataTransfer::HandlePublicBackup(const RAttributeArray& aAttributes) |
|
1708 /** Handles the "public_backup" element |
|
1709 |
|
1710 @param aAttributes the attributes for the element |
|
1711 @return KErrNone |
|
1712 */ |
|
1713 { |
|
1714 iPublicInformation.iSupported = ETrue; |
|
1715 |
|
1716 if (aAttributes.Count() > 0) |
|
1717 { |
|
1718 const TBool deleteBeforeRestore = ( aAttributes[0].Value().DesC().CompareF(KYes) == 0 ); |
|
1719 iPublicInformation.iDeleteBeforeRestore = deleteBeforeRestore; |
|
1720 __LOG2("CPackageDataTransfer::HandlePublicBackup(0x%08x) - iPublicInformation.iDeleteBeforeRestore: %d", iPackageID.iUid, deleteBeforeRestore); |
|
1721 } // if |
|
1722 |
|
1723 iCurrentElement = EPublic; |
|
1724 |
|
1725 return KErrNone; |
|
1726 } |
|
1727 |
|
1728 TInt CPackageDataTransfer::HandleSystemBackup(const RAttributeArray& /*aAttributes*/) |
|
1729 /** Handles the "system_backup" element |
|
1730 |
|
1731 @param aAttributes the attributes for the element |
|
1732 @return KErrNone |
|
1733 */ |
|
1734 { |
|
1735 iSystemInformation.iSupported = ETrue; |
|
1736 __LOG2("CPackageDataTransfer::HandlePublicBackup(0x%08x) - iSystemInformation.iSupported: %d", iPackageID.iUid, iSystemInformation.iSupported); |
|
1737 |
|
1738 return KErrNone; |
|
1739 } |
|
1740 |
|
1741 |
|
1742 void CPackageDataTransfer::HandlePathL(const TSelectionType aType, |
|
1743 const RAttributeArray& aAttributes, |
|
1744 const TBool aDir) |
|
1745 /** Handles the "include_file", "include_directory" and "exclude" elements |
|
1746 |
|
1747 @param aType The selection type |
|
1748 @param aAttributes The attributes for the element |
|
1749 @param aDir The element was found in an <include_dir/> element? |
|
1750 */ |
|
1751 { |
|
1752 // Check we dont have a NULL string |
|
1753 if (aAttributes[0].Value().DesC().Length() > 0) |
|
1754 { |
|
1755 switch (iCurrentElement) |
|
1756 { |
|
1757 case EPublic: |
|
1758 { |
|
1759 TFileName selectionName; |
|
1760 if (KErrNone == ipDataOwnerManager->ParserProxy().ConvertToUnicodeL(selectionName, aAttributes[0].Value().DesC())) |
|
1761 { |
|
1762 // 2 because we expect drive leter and semicollon |
|
1763 if (selectionName.Length() > 2) |
|
1764 { |
|
1765 // Should we add a backslash |
|
1766 if (aDir && |
|
1767 (selectionName[selectionName.Length() - 1] != '\\')) |
|
1768 { |
|
1769 selectionName.Append(KBackSlash); |
|
1770 } // if |
|
1771 |
|
1772 if (selectionName[1] == ':') |
|
1773 { |
|
1774 CSelection* selection = CSelection::NewLC(aType, selectionName); |
|
1775 iPublicSelections.AppendL(selection); |
|
1776 CleanupStack::Pop(selection); |
|
1777 __LOG3("CPackageDataTransfer::HandlePathL(0x%08x) - Added selection: %S [type: %d]", iPackageID.iUid, &selectionName, aType); |
|
1778 } //if |
|
1779 }// if |
|
1780 else |
|
1781 { |
|
1782 __LOG3("CPackageDataTransfer::HandlePathL(0x%08x) - Wrong format: %S [type: %d]", iPackageID.iUid, &selectionName, aType); |
|
1783 } |
|
1784 } // if |
|
1785 else |
|
1786 { |
|
1787 __LOG1("CPackageDataTransfer::HandlePathL(0x%08x) - EPublic - Could not convert filename", iPackageID.iUid); |
|
1788 } // else |
|
1789 break; |
|
1790 }; |
|
1791 default: |
|
1792 { |
|
1793 __LOG1("CPackageDataTransfer::HandlePathL(0x%08x) - Private data is Not Supported", iPackageID.iUid); |
|
1794 } |
|
1795 break; |
|
1796 } // switch |
|
1797 } // if |
|
1798 else |
|
1799 { |
|
1800 __LOG1("CPackageDataTransfer::HandlePathL(0x%08x) - Path attribute error", iPackageID.iUid); |
|
1801 } // else |
|
1802 } |
|
1803 // // |
|
1804 // MContentHandler // |
|
1805 // |
|
1806 |
|
1807 |
|
1808 } // namespace |