|
1 /* |
|
2 * Copyright (c) 2003 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: Logger manager with read access to history files. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <SysUtil.h> |
|
21 #include <bautils.h> |
|
22 #include <s32file.h> |
|
23 |
|
24 #include "CCALoggerManager.h" |
|
25 #include "CCALoggerWriter.h" |
|
26 #include "MCALoggerMessageHeader.h" |
|
27 #include "MCALoggerMessageFactory.h" |
|
28 #include "MCALoggerMessage.h" |
|
29 |
|
30 #ifdef RD_MULTIPLE_DRIVE |
|
31 #include <centralrepository.h> |
|
32 #include <IMPSServiceSettingsUINGInternalCRKeys.h> |
|
33 #include <E32std.h> |
|
34 #include <EIKAPP.H> |
|
35 #include <eikappui.h> |
|
36 #include <eikenv.h> |
|
37 #include <eikbtgpc.h> |
|
38 #include <driveinfo.h> |
|
39 #include <StringLoader.h> // StringLoader |
|
40 #include "IMDialogUtils.h" |
|
41 #include <CAknMemorySelectionDialogMultiDrive.h> |
|
42 #include <rsfwmountman.h> |
|
43 #endif |
|
44 #include <chatNG.rsg> |
|
45 |
|
46 //for debug |
|
47 #include "ChatDebugPrint.h" |
|
48 |
|
49 //CONSTANTS |
|
50 const TInt KLengthOfPathEnd = 1; |
|
51 const TInt KArrayBegin = 0; |
|
52 |
|
53 //Max length for number is 10 |
|
54 const TInt KMaxNumberLength = 10; |
|
55 |
|
56 // ================= MEMBER FUNCTIONS ======================= |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CCALoggerManager::~CCALoggerManager |
|
60 // destructor |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 CCALoggerManager::~CCALoggerManager() |
|
64 { |
|
65 CHAT_DP_TXT( "CCALoggerManager::~CCALoggerManager" ); |
|
66 |
|
67 //Close filesession |
|
68 iFileSession.Close(); |
|
69 |
|
70 //reset toc array |
|
71 iFileTocArray.ResetAndDestroy(); |
|
72 |
|
73 //reset temp toc array |
|
74 iFileTempTocArray.ResetAndDestroy(); |
|
75 |
|
76 //reset write array |
|
77 for ( TInt a = 0; a < iWriteFileArray.Count(); ++a ) |
|
78 { |
|
79 //CCALoggerManager owns iFile in TFileRelation struct, but not the key |
|
80 delete iWriteFileArray[a].iFile; |
|
81 } |
|
82 |
|
83 iWriteFileArray.Close(); |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CCALoggerManager::NewL |
|
88 // Two phase constructor. |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 CCALoggerManager* CCALoggerManager::NewL() |
|
92 { |
|
93 CHAT_DP_TXT( "CCALoggerManager::NewL" ); |
|
94 |
|
95 CCALoggerManager* lm = new ( ELeave ) CCALoggerManager(); |
|
96 CleanupStack::PushL( lm ); |
|
97 lm->ConstructL(); |
|
98 User::LeaveIfError( Dll::SetTls( static_cast< TAny* >( lm ) ) ); |
|
99 CleanupStack::Pop( lm ); |
|
100 return lm; |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CCALoggerManager::CCALoggerManager |
|
105 // Constructor |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 CCALoggerManager::CCALoggerManager() |
|
109 { |
|
110 CHAT_DP_TXT( "CCALoggerManager::CCALoggerManager" ); |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CCALoggerManager::ConstructL |
|
115 // Initialization of CCALoggerManager |
|
116 // ----------------------------------------------------------------------------- |
|
117 // |
|
118 void CCALoggerManager::ConstructL() |
|
119 { |
|
120 CHAT_DP_TXT( "CCALoggerManager::ConstructL" ); |
|
121 |
|
122 User::LeaveIfError( iFileSession.Connect() ); |
|
123 |
|
124 TBuf< KMaxPath > pathTemp; |
|
125 iFileSession.PrivatePath( pathTemp ); |
|
126 pathTemp.Append( KCAHistoryDirectory ); |
|
127 |
|
128 //Ensure, that there is no file named IMHistory beforehand. Ignore errors |
|
129 iFileSession.Delete( pathTemp.Left( pathTemp.Length() - KLengthOfPathEnd ) ); |
|
130 |
|
131 //Create directories which are needed by IM Logger |
|
132 iFileSession.MkDirAll( pathTemp ); |
|
133 |
|
134 iFileSession.PrivatePath( pathTemp ); |
|
135 pathTemp.Append( KCAHistoryDataDirectory ); |
|
136 |
|
137 //Ensure, that there is no file named IMHistory beforehand. Ignore errors |
|
138 iFileSession.Delete( pathTemp.Left( pathTemp.Length() - KLengthOfPathEnd ) ); |
|
139 |
|
140 //Create directories which are needed by IM Logger |
|
141 iFileSession.MkDirAll( pathTemp ); |
|
142 } |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // CCALoggerManager::InstanceL |
|
146 // Singleton instance of CCALoggerManager |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 CCALoggerManager* CCALoggerManager::InstanceL( |
|
150 MCALoggerMessageFactory* aMessageFactory, |
|
151 TBool aCreate , TBool aFirstTime ) |
|
152 { |
|
153 CHAT_DP_TXT( "CCALoggerManager::InstanceL" ); |
|
154 |
|
155 CCALoggerManager* lm = static_cast< CCALoggerManager* > ( Dll::Tls() ); |
|
156 |
|
157 //If instance of CCALoggerManager is not created yet. Create it. |
|
158 if ( ! lm ) |
|
159 { |
|
160 if ( !aCreate ) |
|
161 { |
|
162 return NULL; |
|
163 } |
|
164 lm = NewL(); |
|
165 } |
|
166 |
|
167 //If aMessageFactory is passed to instance, change it. |
|
168 |
|
169 if ( aMessageFactory ) |
|
170 { |
|
171 lm->SetLoggerMessageFactory( aMessageFactory ); |
|
172 } |
|
173 |
|
174 //if toc file is not yet read, try to read it. |
|
175 if ( ( ! lm->iTocFileRead ) ) |
|
176 { |
|
177 // here it's application booting up time..then don't show the error note.. |
|
178 // check whether this call during application boot up or not.... |
|
179 |
|
180 lm->ReadTocFileL( aFirstTime ) ;// this first time, we are reading..so we can ignore errors while reading... |
|
181 } |
|
182 |
|
183 return lm; |
|
184 } |
|
185 |
|
186 // ----------------------------------------------------------------------------- |
|
187 // CCALoggerManager::SuitableLogFileNameL |
|
188 // Get first possible filename (number) |
|
189 // ----------------------------------------------------------------------------- |
|
190 // |
|
191 void CCALoggerManager::SuitableLogFileNameL() |
|
192 { |
|
193 CHAT_DP_TXT( "CCALoggerManager::SuitableLogFileNameL" ); |
|
194 |
|
195 //If suitable log filename is already checked just use it. |
|
196 if ( iWeHaveLatestFileNameNumber ) |
|
197 { |
|
198 iLatestFileNameNumber++; |
|
199 } |
|
200 else //Check next suitable log filename |
|
201 { |
|
202 //Sort does not help us, because numbers cannot be sorted like letters. |
|
203 //10 is before 2 and so on. So we have to go through all files to get |
|
204 //right ones. |
|
205 |
|
206 // Get all the files in the directory |
|
207 // These are named as 1, 2, 5 i.e. numbers |
|
208 CDir* directoryFiles; |
|
209 |
|
210 //TODOMD: get the correct path name here... |
|
211 |
|
212 TBuf< KMaxPath > pathTemp; |
|
213 |
|
214 #ifndef RD_MULTIPLE_DRIVE |
|
215 iFileSession.PrivatePath( pathTemp ); |
|
216 #else |
|
217 TBuf< KMaxPath > defaultDrive; |
|
218 TBuf< KMaxPath > pathTempWithoutDrive; |
|
219 TBuf< KMaxPath > driveAndPath; |
|
220 |
|
221 CRepository* cenrep = CRepository::NewL( KWVSettingsCenRepUid ); |
|
222 TInt err = KErrNone; |
|
223 TRAP( err, |
|
224 CleanupStack::PushL( cenrep ); |
|
225 err = cenrep->Get( KIMPSCRIMDefaultMemoryDrive, defaultDrive ); |
|
226 CleanupStack::PopAndDestroy( cenrep ); |
|
227 ); // TRAP |
|
228 cenrep = NULL; |
|
229 |
|
230 driveAndPath.Append( defaultDrive.Left( 2 ) ); // append the drive root here |
|
231 iFileSession.PrivatePath( pathTempWithoutDrive ); // copy the private path info here.. |
|
232 driveAndPath.Append( pathTempWithoutDrive ); // append the private path to root folder... |
|
233 pathTemp.Copy( driveAndPath ); // copy this new path into tocfile... |
|
234 |
|
235 #endif |
|
236 |
|
237 pathTemp.Append( KCAHistoryDataDirectory ); |
|
238 |
|
239 User::LeaveIfError( iFileSession.GetDir( pathTemp, |
|
240 KEntryAttNormal, |
|
241 ESortNone, |
|
242 directoryFiles ) ); |
|
243 |
|
244 //If directoryFiles success and is files, last will be noticed and |
|
245 //next free number chosen. If there is not files, |
|
246 //zero is first one to go. |
|
247 CleanupStack::PushL( directoryFiles ); |
|
248 TLex lexer; |
|
249 TInt latestNumber; |
|
250 for ( TInt a = 0; a < directoryFiles->Count(); ++a ) |
|
251 { |
|
252 lexer.Assign( ( *directoryFiles )[ a ].iName ); |
|
253 if ( lexer.Val( latestNumber ) == KErrNone ) |
|
254 { |
|
255 if ( latestNumber >= iLatestFileNameNumber ) |
|
256 { |
|
257 iLatestFileNameNumber = latestNumber + 1; |
|
258 } |
|
259 } |
|
260 } |
|
261 |
|
262 CleanupStack::PopAndDestroy( directoryFiles ); |
|
263 iWeHaveLatestFileNameNumber = ETrue; |
|
264 } |
|
265 } |
|
266 #ifdef RD_MULTIPLE_DRIVE |
|
267 |
|
268 // --------------------------------------------------------------------------- |
|
269 // CCALoggerManager::DriveStatus |
|
270 // --------------------------------------------------------------------------- |
|
271 // |
|
272 |
|
273 TBool CCALoggerManager::GetDriveStatusL( const TDriveNumber aDriveNumber ) |
|
274 { |
|
275 |
|
276 |
|
277 RFs& fs = CCoeEnv::Static()->FsSession(); |
|
278 _LIT( KFat, "Fat" ); |
|
279 |
|
280 // Check if the drive is already mounted |
|
281 TFullName fsName; |
|
282 TInt error( fs.FileSystemName( fsName, aDriveNumber ) ); |
|
283 if ( error ) |
|
284 { |
|
285 return EFalse; |
|
286 } |
|
287 |
|
288 // check if MMC already mounted |
|
289 if ( fsName.Length() == 0 ) |
|
290 { |
|
291 // MMC drive isnt mounted at present, so try it now.... |
|
292 error = fs.MountFileSystem( KFat, aDriveNumber ); |
|
293 |
|
294 // If it's a locked MMC and the password is already known it'll be |
|
295 // unlocked automatically when it's mounted., otherwise the mount will |
|
296 // return with KErrLocked..... |
|
297 switch ( error ) |
|
298 { |
|
299 case KErrNone: |
|
300 case KErrLocked: |
|
301 { |
|
302 break; |
|
303 } |
|
304 default: |
|
305 { |
|
306 return EFalse; |
|
307 } |
|
308 } |
|
309 } |
|
310 TDriveInfo driveInfo; |
|
311 error = fs.Drive( driveInfo, aDriveNumber ); |
|
312 if ( error ) |
|
313 { |
|
314 return EFalse; |
|
315 } |
|
316 |
|
317 // MMC is in slot |
|
318 if ( driveInfo.iMediaAtt & KMediaAttLocked ) |
|
319 { |
|
320 return EFalse; |
|
321 } |
|
322 |
|
323 TVolumeInfo volumeInfo; |
|
324 error = fs.Volume( volumeInfo, aDriveNumber ); |
|
325 if ( error ) |
|
326 { |
|
327 return EFalse; |
|
328 } |
|
329 |
|
330 // If type is remote drive and aConnectionState is required |
|
331 if ( driveInfo.iDriveAtt & KDriveAttRemote ) |
|
332 { |
|
333 TChar driveLetter; |
|
334 fs.DriveToChar( aDriveNumber, driveLetter ); |
|
335 // This statement migth cause leave.. to be solved |
|
336 CRsfwMountMan* mountMgr = CRsfwMountMan::NewL( 0, NULL ); |
|
337 TRsfwMountInfo mountInfo; |
|
338 error = mountMgr->GetMountInfo( driveLetter, mountInfo ); |
|
339 delete mountMgr; |
|
340 |
|
341 if ( error ) |
|
342 { |
|
343 return EFalse; |
|
344 } |
|
345 } |
|
346 return ETrue; |
|
347 } |
|
348 |
|
349 #endif |
|
350 // ----------------------------------------------------------------------------- |
|
351 // CCALoggerManager::ReadTocFile |
|
352 // Read toc file for headers. |
|
353 // ----------------------------------------------------------------------------- |
|
354 // |
|
355 void CCALoggerManager::ReadTocFileL( TBool aNotFirstTime /*ETrue*/ ) |
|
356 { |
|
357 CHAT_DP_TXT( "CCALoggerManager::ReadTocFileL" ); |
|
358 |
|
359 TBuf< KMaxPath > tocFile; |
|
360 TBuf< KMaxPath > tempTocFile; |
|
361 #ifndef RD_MULTIPLE_DRIVE |
|
362 iFileSession.PrivatePath( tocFile ); |
|
363 #else |
|
364 TBuf< KMaxPath > defaultDrive; |
|
365 TBuf< KMaxPath > pathTempWithoutDrive; |
|
366 TBuf< KMaxPath > driveAndPath; |
|
367 |
|
368 CRepository* cenrep = NULL; |
|
369 TRAPD( err, cenrep = CRepository::NewL( KWVSettingsCenRepUid ) ); |
|
370 |
|
371 if ( err != KErrNone ) |
|
372 { |
|
373 // creation of cenrep failed -> use default path to save the conversation |
|
374 iFileSession.PrivatePath( driveAndPath ); |
|
375 } |
|
376 else |
|
377 { |
|
378 |
|
379 TRAP( err, |
|
380 CleanupStack::PushL( cenrep ); |
|
381 err = cenrep->Get( KIMPSCRIMDefaultMemoryDrive, defaultDrive ); |
|
382 CleanupStack::PopAndDestroy( cenrep ); |
|
383 ); // TRAP |
|
384 cenrep = NULL; |
|
385 |
|
386 ///////////// end of reading from cenrep |
|
387 |
|
388 TInt driveNo = 0; |
|
389 err = RFs::CharToDrive( defaultDrive[0], driveNo ); |
|
390 TDriveNumber driveNumber = TDriveNumber( driveNo ); |
|
391 |
|
392 |
|
393 // Check drive's media status |
|
394 TBool isDriveOk = GetDriveStatusL( driveNumber ); |
|
395 if ( !isDriveOk )// drive is not ready yet..... |
|
396 { |
|
397 if ( !aNotFirstTime ) |
|
398 { |
|
399 HBufC* prompt = StringLoader::LoadLC( R_CHAT_SAVED_NOT_AVAILABLE ); |
|
400 IMDialogUtils::DisplayErrorNoteL( *prompt ); |
|
401 CleanupStack::PopAndDestroy( prompt ); // prompt |
|
402 } |
|
403 return; // return from here as there is an |
|
404 } |
|
405 |
|
406 /////// start atppend this info to complete path //////////////////////////////// |
|
407 |
|
408 driveAndPath.Append( defaultDrive.Left( 2 ) ); // append the drive root here |
|
409 iFileSession.PrivatePath( pathTempWithoutDrive ); // copy the private path info here.. |
|
410 driveAndPath.Append( pathTempWithoutDrive ); // append the private path to root folder... |
|
411 tocFile.Copy( driveAndPath ); // copy this new path into tocfile... |
|
412 } |
|
413 #endif |
|
414 |
|
415 tempTocFile.Copy( tocFile ); |
|
416 tocFile.Append( KCAHistoryTocFile ); |
|
417 tempTocFile.Append( KCAHistoryTocTempFile ); |
|
418 |
|
419 //Cannot create headers without factory |
|
420 //This is not error. Just return to caller. |
|
421 if ( ! iMessageFactory ) |
|
422 { |
|
423 return; |
|
424 } |
|
425 #ifdef RD_MULTIPLE_DRIVE |
|
426 |
|
427 PopulateTocArrayL( iFileTocArray, tocFile, aNotFirstTime ); |
|
428 PopulateTocArrayL( iFileTempTocArray, tempTocFile, aNotFirstTime ); // we no need to show the error dialog again. |
|
429 |
|
430 #else |
|
431 PopulateTocArrayL( iFileTocArray, tocFile ); |
|
432 PopulateTocArrayL( iFileTempTocArray, tempTocFile ); // we no need to show the error dialog again. |
|
433 |
|
434 |
|
435 #endif |
|
436 TBool onlyTempTocFlag( EFalse ); |
|
437 if ( iFileTocArray.Count() + iFileTempTocArray.Count() == 0 ) |
|
438 { |
|
439 iTocFileRead = ETrue; |
|
440 return; |
|
441 } |
|
442 else if ( iFileTocArray.Count() == 0 ) |
|
443 { |
|
444 onlyTempTocFlag = ETrue; |
|
445 } |
|
446 |
|
447 // Merge temp toc to real toc if needed. |
|
448 TInt arrayCount( iFileTempTocArray.Count() ); |
|
449 for ( TInt b( arrayCount - 1 ); b >= 0; --b ) |
|
450 { |
|
451 // Check if real toc have header temp is offering. |
|
452 TInt arrayCount2( iFileTocArray.Count() ); |
|
453 TBool newOne( ETrue ); |
|
454 for ( TInt a( 0 ); a < arrayCount2 && newOne; ++a ) |
|
455 { |
|
456 if ( iFileTempTocArray[ b ]->FilenameL().CompareC( |
|
457 iFileTocArray[ a ]->FilenameL() ) == 0 ) |
|
458 { |
|
459 newOne = EFalse; |
|
460 } |
|
461 } |
|
462 // If header is newOne, then add it to real toc. |
|
463 if ( newOne ) |
|
464 { |
|
465 User::LeaveIfError( iFileTocArray.Insert( iFileTempTocArray[ b ], |
|
466 KArrayBegin ) ); |
|
467 iFileTempTocArray.Remove( b ); |
|
468 } |
|
469 } |
|
470 |
|
471 //Next save the toc file without those headers which are not valid anymore. |
|
472 //This is easily done, because only valid headers were appended to array. |
|
473 //Just make sure, that old header information does not lose in anycase. |
|
474 if ( !onlyTempTocFlag ) |
|
475 { |
|
476 iFileSession.Delete( tempTocFile ); |
|
477 User::LeaveIfError( iFileSession.Rename( tocFile, tempTocFile ) ); |
|
478 } |
|
479 |
|
480 RFileWriteStream fileWriteStream; |
|
481 TInt error( fileWriteStream.Create( iFileSession, |
|
482 tocFile, |
|
483 EFileWrite ) ); |
|
484 if ( error != KErrNone ) |
|
485 { |
|
486 iFileSession.Delete( tocFile ); |
|
487 User::LeaveIfError( iFileSession.Rename( tempTocFile, tocFile ) ); |
|
488 User::Leave( error ); |
|
489 } |
|
490 CleanupClosePushL( fileWriteStream ); |
|
491 |
|
492 //Write headers and if file write fails trap leave because we want to |
|
493 //change old file back. |
|
494 // Write the array from end to start order to the file to keep |
|
495 // order correct (from oldest to newest). |
|
496 TInt maxIndex = iFileTocArray.Count() - 1; |
|
497 for ( TInt a = maxIndex; a >= 0; --a ) |
|
498 { |
|
499 if ( CheckMemoryL( iFileTocArray[a]->MessageSizeInBytesL() ) ) |
|
500 { |
|
501 TRAPD( err, iFileTocArray[a]->ExternalizeL( fileWriteStream ) ); |
|
502 if ( err != KErrNone ) |
|
503 { |
|
504 CleanupStack::PopAndDestroy( 1 ); // fileWriteStream |
|
505 iFileSession.Delete( tocFile ); |
|
506 User::LeaveIfError( iFileSession.Rename( tempTocFile, tocFile ) ); |
|
507 User::Leave( err ); |
|
508 } |
|
509 } |
|
510 else |
|
511 { |
|
512 CleanupStack::PopAndDestroy( 1 ); // fileWriteStream |
|
513 iFileSession.Delete( tocFile ); |
|
514 User::LeaveIfError( iFileSession.Rename( tempTocFile, tocFile ) ); |
|
515 User::Leave( KErrDiskFull ); |
|
516 } |
|
517 } |
|
518 |
|
519 CHAT_DP( D_CHAT_LIT( " ignore %d" ), aNotFirstTime ); |
|
520 |
|
521 CleanupStack::PopAndDestroy( 1 ); // fileWriteStream |
|
522 |
|
523 //Delete old file. |
|
524 iFileSession.Delete( tempTocFile ); |
|
525 |
|
526 //Now toc file is read. |
|
527 iTocFileRead = ETrue; |
|
528 } |
|
529 |
|
530 // ----------------------------------------------------------------------------- |
|
531 // CCALoggerManager::WriteTocFileL |
|
532 // |
|
533 // ----------------------------------------------------------------------------- |
|
534 // |
|
535 void CCALoggerManager::WriteTocFileL( MCALoggerMessageHeader& aHeader, |
|
536 TBool aTemporary /*= EFalse*/ ) |
|
537 { |
|
538 // incase of multidrive, write the header into the user selected drive itself.. |
|
539 CHAT_DP_TXT( "CCALoggerManager::WriteTocFileL" ); |
|
540 |
|
541 TBuf< KMaxPath > tocFile; |
|
542 TBuf< KMaxPath > tempTocFile; |
|
543 |
|
544 #ifndef RD_MULTIPLE_DRIVE |
|
545 iFileSession.PrivatePath( tocFile ); |
|
546 #else |
|
547 TBuf< KMaxPath > defaultDrive; |
|
548 TBuf< KMaxPath > pathTempWithoutDrive; |
|
549 TBuf< KMaxPath > driveAndPath; |
|
550 |
|
551 CRepository* cenrep = NULL; |
|
552 TRAPD( err, cenrep = CRepository::NewL( KWVSettingsCenRepUid ) ); |
|
553 |
|
554 if ( err != KErrNone ) |
|
555 { |
|
556 // creation of cenrep failed -> use default path to save the conversation |
|
557 iFileSession.PrivatePath( driveAndPath ); |
|
558 } |
|
559 else |
|
560 { |
|
561 |
|
562 TRAP( err, |
|
563 CleanupStack::PushL( cenrep ); |
|
564 err = cenrep->Get( KIMPSCRIMDefaultMemoryDrive, defaultDrive ); |
|
565 CleanupStack::PopAndDestroy( cenrep ); |
|
566 ); // TRAP |
|
567 cenrep = NULL; |
|
568 |
|
569 /////// start atppend this info to complete path //////////////////////////////// |
|
570 driveAndPath.Append( defaultDrive.Left( 2 ) ); // append the drive root here |
|
571 //check whether this is in mmc card and card was protected with pwd or not |
|
572 iFileSession.PrivatePath( pathTempWithoutDrive ); // copy the private path info here.. |
|
573 driveAndPath.Append( pathTempWithoutDrive ); // append the private path here... |
|
574 } |
|
575 // copy this new path into tocfile... |
|
576 tocFile.Copy( driveAndPath ); |
|
577 |
|
578 #endif |
|
579 tempTocFile.Copy( tocFile ); |
|
580 tocFile.Append( KCAHistoryTocFile ); |
|
581 tempTocFile.Append( KCAHistoryTocTempFile ); |
|
582 |
|
583 RFileWriteStream fileStream; |
|
584 TInt error = fileStream.Open( iFileSession, !aTemporary ? tocFile : |
|
585 tempTocFile, EFileWrite ); |
|
586 |
|
587 //if file does not exist.. create it |
|
588 if ( error == KErrNotFound ) |
|
589 { |
|
590 User::LeaveIfError( fileStream.Create( iFileSession, !aTemporary ? |
|
591 tocFile : tempTocFile, EFileWrite ) ); |
|
592 } |
|
593 else |
|
594 { |
|
595 User::LeaveIfError( error ); |
|
596 } |
|
597 |
|
598 CleanupClosePushL( fileStream ); |
|
599 |
|
600 //Seek end of file. |
|
601 fileStream.Sink()->SeekL( RFileBuf::EWrite, EStreamEnd ); |
|
602 |
|
603 if ( CheckMemoryL( aHeader.MessageSizeInBytesL() ) ) |
|
604 { |
|
605 aHeader.ExternalizeL( fileStream ); |
|
606 } |
|
607 else |
|
608 { |
|
609 User::Leave( KErrDiskFull ); |
|
610 } |
|
611 |
|
612 CleanupStack::PopAndDestroy( 1 ); // fileStream |
|
613 } |
|
614 |
|
615 // ----------------------------------------------------------------------------- |
|
616 // CCALoggerManager::ReadMessageFileL |
|
617 // Read messages to array |
|
618 // ----------------------------------------------------------------------------- |
|
619 // |
|
620 void CCALoggerManager::ReadMessageFileL( |
|
621 RPointerArray< MCALoggerMessage >& aMessageArray, |
|
622 MCALoggerMessageHeader& aKey ) |
|
623 { |
|
624 CHAT_DP_TXT( "CCALoggerManager::ReadMessageFileL" ); |
|
625 |
|
626 if ( ! iMessageFactory ) |
|
627 { |
|
628 User::Leave( KErrNotReady ); |
|
629 } |
|
630 |
|
631 RFileReadStream fileStream; |
|
632 User::LeaveIfError( fileStream.Open( iFileSession, |
|
633 aKey.FilenameL(), |
|
634 EFileRead ) ); |
|
635 CleanupClosePushL( fileStream ); |
|
636 |
|
637 MCALoggerMessage* newMessage; |
|
638 |
|
639 //Go through whole stream. |
|
640 while ( fileStream.Source()->SizeL() != |
|
641 fileStream.Source()->TellL( RFileBuf::ERead ).Offset() ) |
|
642 { |
|
643 newMessage = iMessageFactory->CreateLoggerMessageL( fileStream ); |
|
644 CleanupDeletePushL( newMessage ); |
|
645 newMessage->InternalizeL( fileStream ); |
|
646 User::LeaveIfError( aMessageArray.Append( newMessage ) ); |
|
647 CleanupStack::Pop( newMessage ); |
|
648 } |
|
649 |
|
650 CleanupStack::PopAndDestroy( 1 ); // fileStream |
|
651 } |
|
652 |
|
653 // ----------------------------------------------------------------------------- |
|
654 // CCALoggerManager::ReadInstanceL |
|
655 // Return pointer to read interface |
|
656 // ----------------------------------------------------------------------------- |
|
657 // |
|
658 MCALoggerReadInterface* CCALoggerManager::ReadInstanceL( |
|
659 MCALoggerMessageFactory* aMessageFactory, TBool aFirstTime ) |
|
660 { |
|
661 CHAT_DP_TXT( "CCALoggerManager::ReadInstanceL" ); |
|
662 |
|
663 CCALoggerManager* lm = InstanceL( aMessageFactory , ETrue, aFirstTime ); |
|
664 |
|
665 return lm; |
|
666 } |
|
667 |
|
668 // ----------------------------------------------------------------------------- |
|
669 // CCALoggerManager::WriteInstanceL |
|
670 // Create write interface and return it. |
|
671 // ----------------------------------------------------------------------------- |
|
672 // |
|
673 MCALoggerWriteInterface* CCALoggerManager::WriteInstanceL( |
|
674 MCALoggerMessageFactory* aMessageFactory ) |
|
675 { |
|
676 CHAT_DP_TXT( "CCALoggerManager::WriteInstanceL" ); |
|
677 |
|
678 CCALoggerManager* lm = InstanceL( aMessageFactory ); |
|
679 |
|
680 return CCALoggerWriter::NewL( *lm, lm->iFileSession ); |
|
681 } |
|
682 |
|
683 |
|
684 // ----------------------------------------------------------------------------- |
|
685 // CCALoggerManager::ReleaseInstanceL |
|
686 // Create write interface and return it. |
|
687 // ----------------------------------------------------------------------------- |
|
688 // |
|
689 void CCALoggerManager::ReleaseInstanceL() |
|
690 { |
|
691 CHAT_DP_TXT( "CCALoggerManager::ReleaseInstanceL" ); |
|
692 |
|
693 CCALoggerManager* lm = InstanceL( NULL ); |
|
694 delete lm; |
|
695 lm = NULL; |
|
696 Dll::SetTls( NULL ); |
|
697 } |
|
698 |
|
699 |
|
700 // ================= INHERITED FUNCTIONS ======================= |
|
701 |
|
702 // FROM MCALoggerWriteObserver |
|
703 |
|
704 // ----------------------------------------------------------------------------- |
|
705 // CCALoggerManager::AddFileL |
|
706 // Add new file to write array |
|
707 // ----------------------------------------------------------------------------- |
|
708 // |
|
709 void CCALoggerManager::AddFileL( TFileRelation aFile ) |
|
710 { |
|
711 CHAT_DP_TXT( "CCALoggerManager::AddFile" ); |
|
712 |
|
713 CleanupDeletePushL( aFile.iFile ); |
|
714 //Removes old file to this writer from iWriteFileArray if exists. |
|
715 //This has been done in iWriter, but after this we can be sure of it. |
|
716 RemoveFileL( *aFile.iWriter ); |
|
717 |
|
718 CleanupStack::Pop( aFile.iFile ); |
|
719 TInt err = iWriteFileArray.Append( aFile ); |
|
720 if ( err != KErrNone ) |
|
721 { |
|
722 delete aFile.iFile; |
|
723 User::Leave( err ); |
|
724 } |
|
725 |
|
726 //Write header information to temporary toc file. |
|
727 WriteTocFileL( *aFile.iFile, ETrue ); |
|
728 } |
|
729 |
|
730 // ----------------------------------------------------------------------------- |
|
731 // CCALoggerManager::RemoveFileL |
|
732 // Remove used file from write array and add it to toc. |
|
733 // ----------------------------------------------------------------------------- |
|
734 // |
|
735 void CCALoggerManager::RemoveFileL( MCALoggerWriteInterface& aWriter ) |
|
736 { |
|
737 CHAT_DP_TXT( "CCALoggerManager::RemoveFileL" ); |
|
738 |
|
739 for ( TInt a = 0; a < iWriteFileArray.Count(); ++a ) |
|
740 { |
|
741 if ( iWriteFileArray[ a ].iWriter == &aWriter ) |
|
742 { |
|
743 TFileRelation relation( iWriteFileArray[ a ] ); |
|
744 |
|
745 //Recorded chat version will add file to toc array. |
|
746 User::LeaveIfError( iFileTocArray.Insert( relation.iFile, |
|
747 KArrayBegin ) ); |
|
748 |
|
749 //Both versions will remove file from write array. |
|
750 iWriteFileArray.Remove( a ); |
|
751 |
|
752 //Trigger footer information for history header |
|
753 relation.iFile->EndLogging(); |
|
754 |
|
755 //Write header information to toc file. |
|
756 WriteTocFileL( *relation.iFile ); |
|
757 return; |
|
758 } |
|
759 } |
|
760 } |
|
761 |
|
762 |
|
763 void CCALoggerManager::LeaveIfDiskFull( TInt aErrorCode ) |
|
764 { |
|
765 if ( aErrorCode == KErrDiskFull ) |
|
766 { |
|
767 User::LeaveIfError( KErrDiskFull ); |
|
768 } |
|
769 } |
|
770 |
|
771 |
|
772 |
|
773 #ifdef RD_MULTIPLE_DRIVE |
|
774 // ----------------------------------------------------------------------------- |
|
775 // CCALoggerManager::CreateNewFilenameL |
|
776 // New actual filename for new history file. |
|
777 // ----------------------------------------------------------------------------- |
|
778 // |
|
779 HBufC* CCALoggerManager::CreateNewFilenameMDL() |
|
780 { |
|
781 CHAT_DP_TXT( "CCALoggerManager::CreateNewFilenameMDL" ); |
|
782 |
|
783 ///////// read settings from cenrep /////////////// |
|
784 |
|
785 TBuf< KMaxPath > defaultDrive; |
|
786 TBuf< KMaxPath > pathTempWithoutDrive; |
|
787 TBuf< KMaxPath > driveAndPath; |
|
788 |
|
789 CRepository* cenrep = NULL; |
|
790 TRAPD( err, cenrep = CRepository::NewL( KWVSettingsCenRepUid ) ); |
|
791 |
|
792 if ( err == KErrNone ) |
|
793 { |
|
794 // creation of cenrep OK |
|
795 CleanupStack::PushL( cenrep ); |
|
796 err = cenrep->Get( KIMPSCRIMDefaultMemoryDrive, defaultDrive ); |
|
797 if ( err != KErrNone ) |
|
798 { |
|
799 CleanupStack::PopAndDestroy( cenrep ); |
|
800 cenrep = NULL; |
|
801 User::Leave( err ); |
|
802 }///////////// end of reading from cenrep |
|
803 |
|
804 // we need to check whether do we have access rights of this root drive or not.. |
|
805 // 1. Check whether this is write protected or not |
|
806 |
|
807 //2. check whether this is in mmc card and card was protected with pwd or not |
|
808 |
|
809 TInt driveNo = 0; |
|
810 err = RFs::CharToDrive( defaultDrive[0], driveNo ); |
|
811 TDriveNumber driveNumber = TDriveNumber( driveNo ); |
|
812 |
|
813 driveAndPath.Append( defaultDrive.Left( 2 ) ); // append the drive root here |
|
814 CleanupStack::PopAndDestroy( cenrep ); |
|
815 cenrep = NULL; |
|
816 |
|
817 // added LeaveIfDiskFull() function call |
|
818 LeaveIfDiskFull( iFileSession.CreatePrivatePath( driveNumber ) ); // create the private default drive info here... |
|
819 |
|
820 iFileSession.PrivatePath( pathTempWithoutDrive ); // copy the private path info here.. |
|
821 |
|
822 driveAndPath.Append( pathTempWithoutDrive ); // append the private path here... |
|
823 driveAndPath.Append( KCAHistoryDirectory );// apend imhistory/data folder here... |
|
824 |
|
825 // now check whether this path was created or not. |
|
826 // if not create the new path now..... |
|
827 |
|
828 // Ensure, that there is no file named IMHistory beforehand. |
|
829 iFileSession.Delete( driveAndPath.Left( driveAndPath.Length() - KLengthOfPathEnd ) ); |
|
830 |
|
831 // Create directories which are needed by IM Logger |
|
832 // added LeaveIfDiskFull() function call |
|
833 LeaveIfDiskFull( iFileSession.MkDirAll( driveAndPath ) ); // create IMHistory directory here... |
|
834 driveAndPath.Append( KCADataDirectory ); |
|
835 |
|
836 // Ensure, that there is no file named IMHistory beforehand. |
|
837 iFileSession.Delete( driveAndPath.Left( driveAndPath.Length() - KLengthOfPathEnd ) ); |
|
838 |
|
839 // Create directories which are needed by IM Logger |
|
840 // added LeaveIfDiskFull() function call |
|
841 LeaveIfDiskFull( iFileSession.MkDirAll( driveAndPath ) );// create data directory here... |
|
842 |
|
843 |
|
844 }// end of cenrep error |
|
845 |
|
846 |
|
847 |
|
848 HBufC* logFile = HBufC::NewL( KMaxNumberLength + driveAndPath.Length() ); |
|
849 |
|
850 CleanupStack::PushL( logFile ); |
|
851 |
|
852 SuitableLogFileNameL(); |
|
853 |
|
854 TPtr ptrPath( logFile->Des() ); |
|
855 ptrPath.Append( driveAndPath ); |
|
856 ptrPath.AppendNum( iLatestFileNameNumber ); |
|
857 |
|
858 CleanupStack::Pop( logFile ); |
|
859 |
|
860 return logFile; |
|
861 |
|
862 } |
|
863 |
|
864 #endif |
|
865 |
|
866 |
|
867 // ----------------------------------------------------------------------------- |
|
868 // CCALoggerManager::CreateNewFilenameL |
|
869 // New actual filename for new history file. |
|
870 // ----------------------------------------------------------------------------- |
|
871 // |
|
872 HBufC* CCALoggerManager::CreateNewFilenameL() |
|
873 { |
|
874 |
|
875 #ifndef RD_MULTIPLE_DRIVE |
|
876 |
|
877 CHAT_DP_TXT( "CCALoggerManager::CreateNewFilenameL" ); |
|
878 |
|
879 TBuf< KMaxPath > pathTemp; |
|
880 iFileSession.PrivatePath( pathTemp ); |
|
881 pathTemp.Append( KCAHistoryDataDirectory ); |
|
882 |
|
883 HBufC* logFile = HBufC::NewL( KMaxNumberLength + pathTemp.Length() ); |
|
884 |
|
885 CleanupStack::PushL( logFile ); |
|
886 |
|
887 SuitableLogFileNameL(); |
|
888 |
|
889 TPtr ptrPath( logFile->Des() ); |
|
890 ptrPath.Append( pathTemp ); |
|
891 ptrPath.AppendNum( iLatestFileNameNumber ); |
|
892 |
|
893 CleanupStack::Pop( logFile ); |
|
894 |
|
895 return logFile; |
|
896 #else |
|
897 return CreateNewFilenameMDL(); |
|
898 #endif |
|
899 } |
|
900 |
|
901 // ----------------------------------------------------------------------------- |
|
902 // CCALoggerManager::CheckMemoryL |
|
903 // New actual filename for new history file. |
|
904 // ----------------------------------------------------------------------------- |
|
905 // |
|
906 TBool CCALoggerManager::CheckMemoryL( TInt aMemoryRequired ) |
|
907 { |
|
908 CHAT_DP_TXT( "CCALoggerManager::CheckMemory" ); |
|
909 |
|
910 #ifndef RD_MULTIPLE_DRIVE |
|
911 if ( ! SysUtil::FFSSpaceBelowCriticalLevelL( &iFileSession, |
|
912 aMemoryRequired ) ) |
|
913 { |
|
914 return ETrue; |
|
915 } |
|
916 return EFalse; |
|
917 |
|
918 #else |
|
919 TBuf< KMaxPath > defaultDrive; |
|
920 |
|
921 CRepository* cenrep = CRepository::NewL( KWVSettingsCenRepUid ); |
|
922 |
|
923 TInt err = cenrep->Get( KIMPSCRIMDefaultMemoryDrive, defaultDrive ); |
|
924 |
|
925 delete cenrep; |
|
926 cenrep = NULL; |
|
927 if ( err != KErrNone ) |
|
928 { |
|
929 User::Leave( err ); |
|
930 }///////////// end of reading from cenrep |
|
931 TInt driveNo = 0; |
|
932 err = RFs::CharToDrive( defaultDrive[0], driveNo ); |
|
933 if ( err != KErrNone ) |
|
934 { |
|
935 User::Leave( err ); |
|
936 } |
|
937 |
|
938 TDriveNumber driveNumber = TDriveNumber( driveNo ); |
|
939 |
|
940 if ( ! SysUtil::DiskSpaceBelowCriticalLevelL( &iFileSession, |
|
941 aMemoryRequired, driveNumber ) ) |
|
942 { |
|
943 return ETrue; |
|
944 } |
|
945 |
|
946 return EFalse; |
|
947 |
|
948 #endif |
|
949 } |
|
950 |
|
951 // ----------------------------------------------------------------------------- |
|
952 // CCALoggerManager::GetLoggerMessageHeaderArray |
|
953 // Pass pointer to toc array to client. |
|
954 // ----------------------------------------------------------------------------- |
|
955 // |
|
956 void CCALoggerManager::GetLoggerMessageHeaderArray( |
|
957 RPointerArray< MCALoggerMessageHeader >*& aHeaderArray ) |
|
958 { |
|
959 CHAT_DP_TXT( "CCALoggerManager::GetLoggerMessageHeaderArray" ); |
|
960 |
|
961 aHeaderArray = &iFileTocArray; |
|
962 } |
|
963 |
|
964 // ----------------------------------------------------------------------------- |
|
965 // CCALoggerManager::CreateLoggerMessagesL |
|
966 // Check that file is found from toc array |
|
967 // ----------------------------------------------------------------------------- |
|
968 // |
|
969 void CCALoggerManager::CreateLoggerMessagesL( |
|
970 RPointerArray< MCALoggerMessage >& aMessageArray, |
|
971 MCALoggerMessageHeader& aKey ) |
|
972 { |
|
973 CHAT_DP_TXT( "CCALoggerManager::CreateLoggerMessagesL" ); |
|
974 |
|
975 for ( TInt a = 0; a < iFileTocArray.Count(); ++a ) |
|
976 { |
|
977 if ( iFileTocArray[a] == &aKey ) |
|
978 { |
|
979 //Read the file |
|
980 ReadMessageFileL( aMessageArray, aKey ); |
|
981 return; |
|
982 } |
|
983 } |
|
984 |
|
985 //if header is missing |
|
986 User::Leave( KErrNotFound ); |
|
987 } |
|
988 |
|
989 // ----------------------------------------------------------------------------- |
|
990 // CCALoggerManager::DeleteHistoryFileL |
|
991 // If header is in toc array. Remove and delete it. |
|
992 // ----------------------------------------------------------------------------- |
|
993 // |
|
994 void CCALoggerManager::DeleteHistoryFileL( MCALoggerMessageHeader& aKey ) |
|
995 { |
|
996 CHAT_DP_TXT( "CCALoggerManager::DeleteHistoryFileL" ); |
|
997 |
|
998 for ( TInt a = 0; a < iFileTocArray.Count(); ++a ) |
|
999 { |
|
1000 if ( iFileTocArray[a] == &aKey ) |
|
1001 { |
|
1002 //Remove header from array |
|
1003 iFileTocArray.Remove( a ); |
|
1004 |
|
1005 //delete file from storage space |
|
1006 iFileSession.Delete( aKey.FilenameL() ); |
|
1007 |
|
1008 |
|
1009 // Get the toc file path string |
|
1010 TBuf< KMaxPath > tocFile; |
|
1011 TBuf< KMaxPath > tempTocFile; |
|
1012 |
|
1013 #ifndef RD_MULTIPLE_DRIVE |
|
1014 iFileSession.PrivatePath( tocFile ); |
|
1015 #else |
|
1016 TBuf< KMaxPath > defaultDrive; |
|
1017 TBuf< KMaxPath > pathTempWithoutDrive; |
|
1018 TBuf< KMaxPath > driveAndPath; |
|
1019 |
|
1020 CRepository* cenrep = NULL; |
|
1021 TRAPD( err, cenrep = CRepository::NewL( KWVSettingsCenRepUid ) ); |
|
1022 |
|
1023 if ( err != KErrNone ) |
|
1024 { |
|
1025 // creation of cenrep failed -> use default path to save the conversation |
|
1026 iFileSession.PrivatePath( driveAndPath ); |
|
1027 } |
|
1028 else |
|
1029 { |
|
1030 |
|
1031 TRAP( err, |
|
1032 CleanupStack::PushL( cenrep ); |
|
1033 err = cenrep->Get( KIMPSCRIMDefaultMemoryDrive, defaultDrive ); |
|
1034 CleanupStack::PopAndDestroy( cenrep ); |
|
1035 ); // TRAP |
|
1036 cenrep = NULL; |
|
1037 |
|
1038 /////// start atppend this info to complete path //////////////////////////////// |
|
1039 driveAndPath.Append( defaultDrive.Left( 2 ) ); // append the drive root here |
|
1040 //check whether this is in mmc card and card was protected with pwd or not |
|
1041 iFileSession.PrivatePath( pathTempWithoutDrive ); // copy the private path info here.. |
|
1042 driveAndPath.Append( pathTempWithoutDrive ); // append the private path here... |
|
1043 } |
|
1044 // copy this new path into tocfile... |
|
1045 tocFile.Copy( driveAndPath ); |
|
1046 |
|
1047 #endif |
|
1048 |
|
1049 tempTocFile.Copy( tocFile ); |
|
1050 tocFile.Append( KCAHistoryTocFile ); |
|
1051 tempTocFile.Append( KCAHistoryTocTempFile ); |
|
1052 |
|
1053 User::LeaveIfError( iFileSession.Rename( tocFile, tempTocFile ) ); |
|
1054 |
|
1055 // Filewritestream |
|
1056 RFileWriteStream fileWriteStream; |
|
1057 TInt error( fileWriteStream.Create( iFileSession, |
|
1058 tocFile, |
|
1059 EFileWrite ) ); |
|
1060 if ( error != KErrNone ) |
|
1061 { |
|
1062 iFileSession.Delete( tocFile ); |
|
1063 User::LeaveIfError( iFileSession.Rename( tempTocFile, tocFile ) ); |
|
1064 User::Leave( error ); |
|
1065 } |
|
1066 CleanupClosePushL( fileWriteStream ); |
|
1067 |
|
1068 //Write headers and if file write fails trap leave because we want to |
|
1069 //change old file back. |
|
1070 // Write the array from end to start order to the file to keep |
|
1071 // order correct (from oldest to newest). |
|
1072 TInt maxIndex = iFileTocArray.Count() - 1; |
|
1073 for ( TInt a = maxIndex; a >= 0; --a ) |
|
1074 { |
|
1075 if ( CheckMemoryL( iFileTocArray[a]->MessageSizeInBytesL() ) ) |
|
1076 { |
|
1077 TRAPD( err, iFileTocArray[a]->ExternalizeL( fileWriteStream ) ); |
|
1078 if ( err != KErrNone ) |
|
1079 { |
|
1080 iFileSession.Delete( tocFile ); |
|
1081 User::LeaveIfError( iFileSession.Rename( tempTocFile, tocFile ) ); |
|
1082 User::Leave( err ); |
|
1083 } |
|
1084 } |
|
1085 else |
|
1086 { |
|
1087 iFileSession.Delete( tocFile ); |
|
1088 User::LeaveIfError( iFileSession.Rename( tempTocFile, tocFile ) ); |
|
1089 User::Leave( KErrDiskFull ); |
|
1090 } |
|
1091 } |
|
1092 |
|
1093 // Delete the temp toc file |
|
1094 iFileSession.Delete( tempTocFile ); |
|
1095 |
|
1096 CleanupStack::PopAndDestroy( 1 ); // fileWriteStream |
|
1097 |
|
1098 |
|
1099 //release memory from key. |
|
1100 delete &aKey; |
|
1101 return; |
|
1102 } |
|
1103 } |
|
1104 |
|
1105 //if header is missing |
|
1106 User::Leave( KErrNotFound ); |
|
1107 } |
|
1108 |
|
1109 // ----------------------------------------------------------------------------- |
|
1110 // CCALoggerManager::SetLoggerMessageFactory |
|
1111 // Set message factory |
|
1112 // ----------------------------------------------------------------------------- |
|
1113 // |
|
1114 void CCALoggerManager::SetLoggerMessageFactory( |
|
1115 MCALoggerMessageFactory* aMessageFactory ) |
|
1116 { |
|
1117 CHAT_DP_TXT( "CCALoggerManager::SetLoggerMessageFactory" ); |
|
1118 |
|
1119 iMessageFactory = aMessageFactory; |
|
1120 } |
|
1121 |
|
1122 // ----------------------------------------------------------------------------- |
|
1123 // CCALoggerManager::CheckIfHeaderExists |
|
1124 // Checks if header already exists in array. |
|
1125 // ----------------------------------------------------------------------------- |
|
1126 // |
|
1127 TBool CCALoggerManager::CheckIfHeaderExistsL( MCALoggerMessageHeader& aHeader ) |
|
1128 { |
|
1129 for ( TInt a = 0; a < iFileTocArray.Count(); ++a ) |
|
1130 { |
|
1131 if ( aHeader.FilenameL().CompareC( iFileTocArray[ a ]->FilenameL() ) |
|
1132 == 0 ) |
|
1133 { |
|
1134 return ETrue; |
|
1135 } |
|
1136 } |
|
1137 return EFalse; |
|
1138 } |
|
1139 |
|
1140 // ----------------------------------------------------------------------------- |
|
1141 // CCALoggerManager::PopulateTocArray |
|
1142 // |
|
1143 // ----------------------------------------------------------------------------- |
|
1144 // |
|
1145 void CCALoggerManager::PopulateTocArrayL( RPointerArray< MCALoggerMessageHeader >& aArray, |
|
1146 const TDesC& aTocFilename |
|
1147 #ifdef RD_MULTIPLE_DRIVE |
|
1148 , TBool aNotFirstTime /*ETrue*/ |
|
1149 #endif |
|
1150 ) |
|
1151 { |
|
1152 RFileReadStream fileReadStream; |
|
1153 TInt error = fileReadStream.Open( iFileSession, |
|
1154 aTocFilename, |
|
1155 EFileWrite ); |
|
1156 //if file does not exists, there is no headers. just return from method |
|
1157 #ifndef RD_MULTIPLE_DRIVE |
|
1158 if ( error == KErrNotFound ) |
|
1159 { |
|
1160 return; |
|
1161 } |
|
1162 else |
|
1163 { |
|
1164 User::LeaveIfError( error ); |
|
1165 } |
|
1166 #else |
|
1167 if ( aNotFirstTime ) |
|
1168 { |
|
1169 if ( error ) |
|
1170 { |
|
1171 return; |
|
1172 } |
|
1173 } |
|
1174 else |
|
1175 { |
|
1176 if ( error == KErrNotFound || error == KErrPathNotFound ) |
|
1177 { |
|
1178 return; |
|
1179 } |
|
1180 else |
|
1181 { |
|
1182 User::LeaveIfError( error ); |
|
1183 } |
|
1184 } |
|
1185 #endif |
|
1186 |
|
1187 CleanupClosePushL( fileReadStream ); |
|
1188 |
|
1189 MCALoggerMessageHeader* newHeader; |
|
1190 |
|
1191 //Go through whole stream. |
|
1192 while ( fileReadStream.Source()->SizeL() != |
|
1193 fileReadStream.Source()->TellL( RFileBuf::ERead ).Offset() ) |
|
1194 { |
|
1195 newHeader = iMessageFactory->CreateLoggerMessageHeaderL(); |
|
1196 CleanupDeletePushL( newHeader ); |
|
1197 newHeader->InternalizeL( fileReadStream ); |
|
1198 |
|
1199 //if file for header exists, append it to iFileTocArray. |
|
1200 if ( BaflUtils::FileExists( iFileSession, newHeader->FilenameL() ) && |
|
1201 !CheckIfHeaderExistsL( *newHeader ) ) |
|
1202 { |
|
1203 User::LeaveIfError( aArray.Insert( newHeader, KArrayBegin ) ); |
|
1204 CleanupStack::Pop( newHeader ); |
|
1205 } |
|
1206 else |
|
1207 { |
|
1208 CleanupStack::PopAndDestroy( newHeader ); |
|
1209 } |
|
1210 } |
|
1211 |
|
1212 CleanupStack::PopAndDestroy( 1 ); // fileReadStream |
|
1213 } |
|
1214 |
|
1215 //end of file |