|
1 /* |
|
2 * Copyright (c) 2006-2006 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: Stores element data and writes it to stream |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <s32strm.h> |
|
20 #include <s32file.h> |
|
21 #include <f32file.h> |
|
22 |
|
23 #include <bautils.h> |
|
24 #include <utf.h> |
|
25 |
|
26 |
|
27 #include "bsimportconstants.h" |
|
28 #include "cbsstoragemanager.h" |
|
29 #include "cbsstorage.h" |
|
30 #ifdef __WINSCW__ |
|
31 #include "cbsibywriter.h" |
|
32 #endif |
|
33 #include "cbsserver.h" |
|
34 #include "cbssession.h" |
|
35 #include "mbsupdater.h" |
|
36 //#include "importlogwriter.h" |
|
37 #include "debugtrace.h" |
|
38 |
|
39 |
|
40 // ======== MEMBER FUNCTIONS ======== |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 // CBSStorageManager::NewL |
|
44 // --------------------------------------------------------------------------- |
|
45 // |
|
46 CBSStorageManager* CBSStorageManager::NewL( CBSSession* aSession, const TDesC& aAppId ) |
|
47 { |
|
48 CBSStorageManager* self = NewLC( aSession, aAppId ); |
|
49 CleanupStack::Pop(); |
|
50 return self; |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // CBSStorageManager::NewLC |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 CBSStorageManager* CBSStorageManager::NewLC( CBSSession* aSession, const TDesC& aAppId ) |
|
58 { |
|
59 CBSStorageManager* self = |
|
60 new (ELeave) CBSStorageManager(); |
|
61 CleanupStack::PushL( self ); |
|
62 self->ConstructL( aSession, aAppId ); |
|
63 return self; |
|
64 } |
|
65 |
|
66 // --------------------------------------------------------------------------- |
|
67 // CBSStorageManager::ConstructL |
|
68 // --------------------------------------------------------------------------- |
|
69 // |
|
70 void CBSStorageManager::ConstructL( CBSSession* aSession, const TDesC& aAppId ) |
|
71 { |
|
72 TRACE( T_LIT( "CBSStorageManager::ConstructL begin aAppId[%S]"), &aAppId ); |
|
73 User::LeaveIfError( iFs.Connect() ); |
|
74 |
|
75 // RFs::ShareProtected() needs to be called for the session |
|
76 // used to open the handle that is going to be shared. |
|
77 // ShareProtected() was called to a wrong Fs-session in |
|
78 // CBSBrandHandler::GetFileL(). |
|
79 User::LeaveIfError( iFs.ShareProtected() ); |
|
80 |
|
81 iFs.CreatePrivatePath( EDriveC ); |
|
82 |
|
83 iSession = aSession; |
|
84 |
|
85 |
|
86 #ifdef __WINSCW__ |
|
87 if( !iWriter ) |
|
88 { |
|
89 iWriter = CBSIBYWriter::NewL(); |
|
90 } |
|
91 if( aAppId.Compare( KNullDesC ) ) |
|
92 { |
|
93 HBufC* temp = HBufC::NewL( KBSIbyDirectory().Length() + |
|
94 aAppId.Length() + |
|
95 KBSIbyExtension().Length() ); |
|
96 TPtr ptr( temp->Des() ); |
|
97 ptr.Append( KBSIbyDirectory ); |
|
98 ptr.Append( aAppId ); |
|
99 ptr.Append( KBSIbyExtension ); |
|
100 delete iIbyFile; |
|
101 iIbyFile = temp; |
|
102 iWriter->InitIbyFileL( iFs, *iIbyFile ); |
|
103 } |
|
104 #endif |
|
105 TRACE( T_LIT( "CBSStorageManager::ConstructL end") ); |
|
106 } |
|
107 |
|
108 // --------------------------------------------------------------------------- |
|
109 // CBSStorageManager::CBSStorageManager |
|
110 // --------------------------------------------------------------------------- |
|
111 // |
|
112 CBSStorageManager::CBSStorageManager() : |
|
113 iCurrent( KErrNotFound ) |
|
114 { |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // CBSStorageManager::~CBSStorageManager |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 CBSStorageManager::~CBSStorageManager() |
|
122 { |
|
123 TRACE( T_LIT( "CBSStorageManager::~CBSStorageManager begin") ); |
|
124 iStorages.ResetAndDestroy(); |
|
125 iFs.Close(); |
|
126 |
|
127 delete iAppId; |
|
128 delete iBrandId; |
|
129 delete iLanguageId; |
|
130 delete iFilename; |
|
131 |
|
132 #ifdef __WINSCW__ |
|
133 delete iWriter; |
|
134 #endif |
|
135 |
|
136 delete iIbyFile; |
|
137 TRACE( T_LIT( "CBSStorageManager::~CBSStorageManager end") ); |
|
138 } |
|
139 |
|
140 // --------------------------------------------------------------------------- |
|
141 // CBSStorageManager::InitTransactionL |
|
142 // --------------------------------------------------------------------------- |
|
143 // |
|
144 void CBSStorageManager::ConnectTransactionL(const TDesC& aAppId, |
|
145 const TDesC& aBrandId, |
|
146 TLanguage aLanguageId, |
|
147 TBool aAppending, /*= EFalse*/ |
|
148 TInt aReserved /*=0*/) |
|
149 { |
|
150 TRACE( T_LIT( "CBSStorageManager::ConnectTransactionL begin AppId[%S],BrandId[%S]"),&aAppId, &aBrandId ); |
|
151 if( iActive ) |
|
152 { |
|
153 TBool transactionOk = ETrue; |
|
154 |
|
155 transactionOk = iReserved == aReserved; |
|
156 |
|
157 if( transactionOk ) |
|
158 { |
|
159 transactionOk = iLanguageIdNum == aLanguageId; |
|
160 } |
|
161 |
|
162 if( transactionOk ) |
|
163 { |
|
164 transactionOk != iAppId->Compare( aAppId ); |
|
165 } |
|
166 |
|
167 if( transactionOk ) |
|
168 { |
|
169 transactionOk != iBrandId->Compare( aBrandId ); |
|
170 } |
|
171 |
|
172 if( !transactionOk ) |
|
173 { |
|
174 User::Leave( KErrArgument ); |
|
175 } |
|
176 // the same transaction as is ongoing |
|
177 return; |
|
178 } |
|
179 iActive = ETrue; |
|
180 |
|
181 HBufC* tmpAppId = aAppId.AllocL(); |
|
182 delete iAppId; |
|
183 iAppId = tmpAppId; |
|
184 |
|
185 HBufC* tmpBrandId = aBrandId.AllocL(); |
|
186 delete iBrandId; |
|
187 iBrandId = tmpBrandId; |
|
188 |
|
189 iLanguageIdNum = aLanguageId; |
|
190 |
|
191 TBuf<KLangBufLength> buffer; |
|
192 if( aLanguageId < 10 ) |
|
193 { |
|
194 // we want two digit languageid |
|
195 buffer.AppendNum( KLeadingZero ); |
|
196 } |
|
197 buffer.AppendNum( aLanguageId ); |
|
198 HBufC* tmp = buffer.AllocL(); |
|
199 delete iLanguageId; |
|
200 iLanguageId = tmp; |
|
201 |
|
202 iReserved = aReserved; |
|
203 |
|
204 HBufC* tempFile = ConstructFileNameL(); |
|
205 delete iFilename; |
|
206 iFilename = tempFile; |
|
207 |
|
208 iAppending = aAppending; |
|
209 TRACE( T_LIT( "CBSStorageManager::ConnectTransactionL end") ); |
|
210 } |
|
211 |
|
212 |
|
213 // --------------------------------------------------------------------------- |
|
214 // CBSStorageManager::CancelTransactionL |
|
215 // --------------------------------------------------------------------------- |
|
216 // |
|
217 void CBSStorageManager::CancelTransactionL() |
|
218 { |
|
219 TRACE( T_LIT( "CBSStorageManager::CancelTransactionL begin") ); |
|
220 if( !iActive ) |
|
221 { |
|
222 User::Leave( KErrNotFound ); |
|
223 } |
|
224 // this closes the transaction |
|
225 CleanupTransaction(); |
|
226 TRACE( T_LIT( "CBSStorageManager::CancelTransactionL end") ); |
|
227 } |
|
228 |
|
229 // --------------------------------------------------------------------------- |
|
230 // CBSStorageManager::ConstructFileNameL() |
|
231 // --------------------------------------------------------------------------- |
|
232 // |
|
233 HBufC* CBSStorageManager::ConstructFileNameL( TInt aReserved /* = 0 */ ) |
|
234 { |
|
235 HBufC* fileName = NULL; |
|
236 if( iAppId && iBrandId && iLanguageId ) |
|
237 { |
|
238 fileName = ConstructFileNameL( *iAppId, *iBrandId, iLanguageIdNum, aReserved ); |
|
239 } |
|
240 return fileName; |
|
241 } |
|
242 |
|
243 // --------------------------------------------------------------------------- |
|
244 // CBSStorageManager::ConstructFileNameL() |
|
245 // --------------------------------------------------------------------------- |
|
246 // |
|
247 HBufC* CBSStorageManager::ConstructFileNameL( const TDesC& aAppId, |
|
248 const TDesC& aBrandId, |
|
249 TLanguage aLanguage, |
|
250 TInt aReserved /* = 0 */ ) |
|
251 { |
|
252 HBufC* fileName = NULL; |
|
253 |
|
254 TBuf<KLangBufLength> langBuf; |
|
255 if (aLanguage >= 100) |
|
256 User::LeaveIfError (KErrNotFound); |
|
257 if( aLanguage < 10 ) |
|
258 { |
|
259 // we want two digit languageid |
|
260 langBuf.AppendNum( KLeadingZero ); |
|
261 } |
|
262 langBuf.AppendNum( aLanguage ); |
|
263 |
|
264 TInt length = aAppId.Length() + aBrandId.Length() + |
|
265 KDefFileName().Length() + KDirSeparator().Length() * 2 + |
|
266 langBuf.Length() + KDot().Length() * 3 + KMaxVersionLenght; |
|
267 fileName = HBufC::NewLC( length ); |
|
268 |
|
269 TPtr file( fileName->Des() ); |
|
270 |
|
271 // [application_id]\[brand_id]\[def_filename][language_id] |
|
272 // |
|
273 |
|
274 file.Append( aAppId ); |
|
275 file.Append( KDirSeparator ); |
|
276 file.Append( aBrandId ); |
|
277 file.Append( KDirSeparator ); |
|
278 iDir.Set( file.Left( file.Length() ) ); |
|
279 file.Append( KDefFileName ); |
|
280 file.Append( langBuf ); |
|
281 if( aReserved > 0 ) |
|
282 { |
|
283 TBuf<KMaxVersionLenght> versionBuffer; |
|
284 versionBuffer.AppendNum( aReserved ); |
|
285 file.Append( KDot() ); |
|
286 file.Append( versionBuffer ); |
|
287 } |
|
288 |
|
289 if( fileName ) |
|
290 { |
|
291 CleanupStack::Pop( fileName ); |
|
292 } |
|
293 return fileName; |
|
294 } |
|
295 |
|
296 // --------------------------------------------------------------------------- |
|
297 // CBSStorageManager::CreateStorageL |
|
298 // --------------------------------------------------------------------------- |
|
299 // |
|
300 void CBSStorageManager::CreateStorageL() |
|
301 { |
|
302 CBSStorage* tmp = CBSStorage::NewL(); |
|
303 iStorages.Append( tmp ); |
|
304 iCurrent = iStorages.Find( tmp ); |
|
305 } |
|
306 |
|
307 // --------------------------------------------------------------------------- |
|
308 // CBSStorageManager::StorageCount |
|
309 // --------------------------------------------------------------------------- |
|
310 // |
|
311 TInt CBSStorageManager::StorageCount() |
|
312 { |
|
313 return iStorages.Count(); |
|
314 } |
|
315 |
|
316 // --------------------------------------------------------------------------- |
|
317 // CBSStorageManager::Storage |
|
318 // --------------------------------------------------------------------------- |
|
319 // |
|
320 CBSStorage* CBSStorageManager::Storage( TInt aIndex ) |
|
321 { |
|
322 return iStorages[ aIndex ]; |
|
323 } |
|
324 |
|
325 // --------------------------------------------------------------------------- |
|
326 // CBSStorageManager::Storage |
|
327 // --------------------------------------------------------------------------- |
|
328 // |
|
329 CBSStorage* CBSStorageManager::Storage() |
|
330 { |
|
331 if( iStorages.Count() > 0 ) |
|
332 { |
|
333 return iStorages[ iCurrent ]; |
|
334 } |
|
335 return NULL; |
|
336 } |
|
337 |
|
338 // --------------------------------------------------------------------------- |
|
339 // CBSStorageManager::WriteStorageFilesL |
|
340 // --------------------------------------------------------------------------- |
|
341 // |
|
342 TInt CBSStorageManager::WriteStorageFilesL() |
|
343 { |
|
344 TRACE( T_LIT( "CBSStorageManager::WriteStorageFilesL begin") ); |
|
345 if( !iActive ) |
|
346 { |
|
347 User::Leave( KErrNotFound ); |
|
348 } |
|
349 TInt count = iStorages.Count(); |
|
350 for( TInt i = 0; i < count; i++ ) |
|
351 { |
|
352 // get the private path |
|
353 TBuf<KMaxPath> path; |
|
354 User::LeaveIfError( iFs.PrivatePath( path ) ); |
|
355 |
|
356 // construct absolute filename |
|
357 HBufC* fullname = FullFileNameLC( *iFilename, ETrue ); |
|
358 |
|
359 TParse filestorename; |
|
360 iFs.Parse( *fullname, filestorename ); |
|
361 |
|
362 RFileWriteStream outstream; |
|
363 |
|
364 TInt currentVersion = iReserved; |
|
365 TInt newVersion = iReserved; |
|
366 // check if the brand has any active clients |
|
367 TBool brandActive = ETrue; |
|
368 if( iSession ) |
|
369 { |
|
370 CBSServer* server = iSession->Server(); |
|
371 if( server ) |
|
372 { |
|
373 brandActive = server->MatchSessionL( *iAppId, *iBrandId, |
|
374 iLanguageIdNum, iSession, currentVersion ); |
|
375 } |
|
376 } |
|
377 |
|
378 if( BaflUtils::FileExists( iFs, filestorename.FullName() ) ) |
|
379 { |
|
380 currentVersion = ReadVersionL( filestorename.FullName() ); |
|
381 |
|
382 if( iReserved == KBSAutomaticVersionUpdate && brandActive ) |
|
383 { |
|
384 |
|
385 // the brand has active clients |
|
386 // check if there is already a versioned file for this version |
|
387 HBufC* fileName = FindAvailableVersionL( currentVersion + 1, newVersion ); |
|
388 CleanupStack::PushL( fileName); |
|
389 |
|
390 HBufC* newName = FullFileNameLC( *fileName, ETrue ); |
|
391 |
|
392 iFs.Parse( *newName, filestorename ); |
|
393 |
|
394 if( BaflUtils::FileExists( iFs, filestorename.FullName() ) ) |
|
395 { |
|
396 // the file already exists |
|
397 User::Leave( KErrAlreadyExists ); |
|
398 } |
|
399 CleanupStack::PopAndDestroy( 2, fileName ); // newName, fileName |
|
400 } |
|
401 |
|
402 else if( ( iReserved == currentVersion ) ) |
|
403 { |
|
404 // this version is already installed |
|
405 User::Leave( KErrAlreadyExists ); |
|
406 } |
|
407 |
|
408 else |
|
409 { |
|
410 // check if the current version brand is active |
|
411 brandActive = iSession->Server()->MatchSessionL( *iAppId, *iBrandId, |
|
412 iLanguageIdNum, iSession, currentVersion ); |
|
413 // new version |
|
414 if( brandActive ) |
|
415 { |
|
416 // brand is active |
|
417 // check if there is already a versioned file for this version |
|
418 HBufC* fileName = ConstructFileNameL( iReserved ); |
|
419 CleanupStack::PushL( fileName ); |
|
420 |
|
421 HBufC* newName = FullFileNameLC( *fileName, ETrue ); |
|
422 |
|
423 iFs.Parse( *newName, filestorename ); |
|
424 |
|
425 if( BaflUtils::FileExists( iFs, filestorename.FullName() ) ) |
|
426 { |
|
427 // the file already exists |
|
428 User::Leave( KErrAlreadyExists ); |
|
429 } |
|
430 CleanupStack::PopAndDestroy( 2, fileName ); // newName, fileName |
|
431 } |
|
432 } |
|
433 } |
|
434 |
|
435 |
|
436 // write a new brand file |
|
437 |
|
438 // Construct the output file & stream. |
|
439 iFs.MkDirAll( filestorename.DriveAndPath() ); |
|
440 |
|
441 TInt err = outstream.Replace( iFs, filestorename.FullName(), EFileWrite ); |
|
442 |
|
443 |
|
444 if( err ) |
|
445 { |
|
446 TRACE( T_LIT("ERROR: Cannot create branding file: '%S'"), fullname ); |
|
447 |
|
448 User::Leave( err ); |
|
449 } |
|
450 |
|
451 CleanupClosePushL( outstream ); |
|
452 |
|
453 if( iReserved == KBSAutomaticVersionUpdate ) |
|
454 { |
|
455 // set the next version |
|
456 iStorages[i]->SetVersion( newVersion ); |
|
457 iReserved = newVersion; |
|
458 } |
|
459 |
|
460 // Write data to file |
|
461 TRAPD( extError, iStorages[i]->ExternalizeL( outstream ) ); |
|
462 if( extError && !iAppending ) |
|
463 { |
|
464 // there was an error externalizing the data and we are installing |
|
465 // delete the file, since it's not complete |
|
466 iFs.Delete( filestorename.DriveAndPath() ); |
|
467 } |
|
468 User::LeaveIfError( extError ); |
|
469 |
|
470 |
|
471 #ifdef __WINSCW__ |
|
472 // Add to IBY file |
|
473 iWriter->SetFileItemL( *fullname, *fullname ); |
|
474 #endif |
|
475 |
|
476 CleanupStack::PopAndDestroy( 2 ); // fullname, outstream |
|
477 |
|
478 |
|
479 // existing brand modified --> inform server |
|
480 if( iSession ) |
|
481 { |
|
482 CBSServer* server = iSession->Server(); |
|
483 if( server ) |
|
484 { |
|
485 server->BrandUpdatedL( *iAppId, *iBrandId, |
|
486 iLanguageIdNum, iSession, iReserved ); |
|
487 } |
|
488 } |
|
489 } |
|
490 |
|
491 // this closes the transaction |
|
492 CleanupTransaction(); |
|
493 TRACE( T_LIT( "CBSStorageManager::WriteStorageFilesL end") ); |
|
494 return iReserved; |
|
495 } |
|
496 |
|
497 |
|
498 // --------------------------------------------------------------------------- |
|
499 // CBSStorageManager::ReadVersionL |
|
500 // --------------------------------------------------------------------------- |
|
501 // |
|
502 TInt CBSStorageManager::ReadVersionL( const TDesC& aFilename ) |
|
503 { |
|
504 RFile handle; |
|
505 User::LeaveIfError( handle.Open( iFs, aFilename, EFileRead ) ); |
|
506 CleanupClosePushL( handle ); |
|
507 RFileReadStream stream; |
|
508 stream.Attach( handle ); |
|
509 CleanupClosePushL( stream ); |
|
510 TInt version = stream.ReadInt16L(); |
|
511 CleanupStack::PopAndDestroy( 2 ); // stream, handle |
|
512 return version; |
|
513 } |
|
514 |
|
515 // --------------------------------------------------------------------------- |
|
516 // CBSStorageManager::FindAvailableVersionL |
|
517 // --------------------------------------------------------------------------- |
|
518 // |
|
519 HBufC* CBSStorageManager::FindAvailableVersionL( TInt /*aCurrentVersion*/, TInt& aNewVersion ) |
|
520 { |
|
521 HBufC* fileName = NULL; |
|
522 TInt newVersion = GetNewestVersionL( *iAppId, *iBrandId, iLanguageIdNum ); |
|
523 aNewVersion = newVersion++; |
|
524 fileName = ConstructFileNameL( aNewVersion ); |
|
525 |
|
526 return fileName; |
|
527 } |
|
528 |
|
529 |
|
530 // --------------------------------------------------------------------------- |
|
531 // CBSStorageManager::CleanupTransaction |
|
532 // --------------------------------------------------------------------------- |
|
533 // |
|
534 void CBSStorageManager::CleanupTransaction() |
|
535 { |
|
536 iActive = EFalse; |
|
537 delete iAppId; |
|
538 iAppId = NULL; |
|
539 delete iBrandId; |
|
540 iBrandId = NULL; |
|
541 delete iLanguageId; |
|
542 iLanguageId = NULL; |
|
543 delete iFilename; |
|
544 iFilename = NULL; |
|
545 |
|
546 iStorages.ResetAndDestroy(); |
|
547 } |
|
548 |
|
549 |
|
550 TInt CBSStorageManager :: isActualBrandInstalledL ( const TDesC& aAppId, const TDesC& aBrandId, TLanguage aLanguage) |
|
551 { |
|
552 TInt actualBrandInstalled = -1; |
|
553 HBufC *actualBrandFileName = ConstructFileNameL(aAppId, aBrandId, aLanguage); |
|
554 CleanupStack::PushL( actualBrandFileName ); |
|
555 HBufC* newName = FullFileNameLC( *actualBrandFileName , ETrue ); |
|
556 if (newName) |
|
557 { |
|
558 RFile handle; |
|
559 TInt err = handle.Open( iFs, *newName, EFileShareAny ); |
|
560 if (KErrNone == err) |
|
561 { |
|
562 actualBrandInstalled = 1; |
|
563 handle.Close (); |
|
564 } |
|
565 } |
|
566 |
|
567 CleanupStack::PopAndDestroy (2); |
|
568 return actualBrandInstalled; |
|
569 } |
|
570 // --------------------------------------------------------------------------- |
|
571 // CBSStorageManager::BrandHandleL |
|
572 // --------------------------------------------------------------------------- |
|
573 // |
|
574 void CBSStorageManager::BrandHandleL( const TDesC& aAppId, |
|
575 const TDesC& aBrandId, |
|
576 TLanguage aLanguageId, |
|
577 RFile& aFile, |
|
578 TInt aReserved ) |
|
579 { |
|
580 TRACE( T_LIT( "CBSStorageManager::BrandHandleL begin AppId[%S],BrandId[%S]"),&aAppId, &aBrandId ); |
|
581 TBuf<KLangBufLength> langBuf; |
|
582 if (aLanguageId >= 100) |
|
583 User::LeaveIfError( KErrNotFound ); |
|
584 if( aLanguageId < 10 ) |
|
585 { |
|
586 // we want two digit languageid |
|
587 langBuf.AppendNum( KLeadingZero ); |
|
588 } |
|
589 langBuf.AppendNum( aLanguageId ); |
|
590 |
|
591 TInt length = aAppId.Length() + aBrandId.Length() + |
|
592 KDefFileName().Length() + KDirSeparator().Length() * 2 + |
|
593 langBuf.Length(); |
|
594 |
|
595 HBufC* fileName = HBufC::NewLC( length ); |
|
596 |
|
597 TPtr filePtr( fileName->Des() ); |
|
598 |
|
599 // [application_id]\[brand_id]\[def_filename][language_id] |
|
600 // |
|
601 filePtr.Append( aAppId ); |
|
602 filePtr.Append( KDirSeparator ); |
|
603 filePtr.Append( aBrandId ); |
|
604 filePtr.Append( KDirSeparator ); |
|
605 |
|
606 TPtrC directory; |
|
607 directory.Set( filePtr.Left( filePtr.Length() ) ); |
|
608 |
|
609 filePtr.Append( KDefFileName ); |
|
610 filePtr.Append( langBuf ); |
|
611 |
|
612 HBufC* fullname = FullFileNameLC( filePtr ); |
|
613 |
|
614 RFile handle; |
|
615 |
|
616 TBool versioned = EFalse; |
|
617 |
|
618 TParse findname; |
|
619 iFs.Parse( *fullname, findname ); |
|
620 |
|
621 TFileName fullPtr = fullname->Des(); |
|
622 |
|
623 |
|
624 // seems like nearestlanguagefile is only |
|
625 // searching from z-drive by default, unless |
|
626 // some other drive is explicitely defined |
|
627 // for that reason we first try from |
|
628 // default drive and then force c-drive if |
|
629 // not found. |
|
630 BaflUtils::NearestLanguageFile( iFs, fullPtr ); |
|
631 |
|
632 TInt currentVersion = 0; |
|
633 TRAPD( err, currentVersion = ReadVersionL( fullPtr ) ); |
|
634 if( ( err == KErrNotFound ) || ( err == KErrPathNotFound ) ) |
|
635 { |
|
636 // not found, we try forcing c-drive |
|
637 HBufC* driveForced = FullFileNameLC( filePtr, ETrue ); |
|
638 TFileName forcedPtr = driveForced->Des(); |
|
639 BaflUtils::NearestLanguageFile( iFs, forcedPtr ); |
|
640 TRAP( err, currentVersion = ReadVersionL( forcedPtr ) ); |
|
641 |
|
642 if( err == KErrPathNotFound ) |
|
643 { |
|
644 // switching the error code to be more clear |
|
645 err = KErrNotFound; |
|
646 } |
|
647 User::LeaveIfError( err ); |
|
648 |
|
649 // this file was found, we can use this |
|
650 CleanupStack::Pop( driveForced ); |
|
651 CleanupStack::PopAndDestroy( fullname ); |
|
652 fullname = driveForced; |
|
653 CleanupStack::PushL( fullname ); |
|
654 } |
|
655 else |
|
656 { |
|
657 User::LeaveIfError( err ); |
|
658 } |
|
659 err = KErrNone; |
|
660 if( currentVersion != aReserved ) |
|
661 { |
|
662 // not the base version, check if we have a versioned file for this |
|
663 HBufC* versionedName = ConstructFileNameL( aAppId, aBrandId, |
|
664 aLanguageId, aReserved ); |
|
665 CleanupStack::PushL( versionedName ); |
|
666 HBufC* fullVersionedName = FullFileNameLC( *versionedName, ETrue ); |
|
667 |
|
668 err = handle.Open( iFs, *fullVersionedName, EFileShareAny ); |
|
669 CleanupStack::Pop( fullVersionedName ); |
|
670 CleanupStack::PopAndDestroy( versionedName ); |
|
671 CleanupStack::PopAndDestroy( fullname ); |
|
672 fullname = fullVersionedName; |
|
673 CleanupStack::PushL( fullname ); |
|
674 versioned = ETrue; |
|
675 } |
|
676 else |
|
677 { |
|
678 err = handle.Open( iFs, *fullname, EFileShareAny ); |
|
679 } |
|
680 |
|
681 if( err == KErrBadName ) |
|
682 { |
|
683 // change bad name to not found |
|
684 err = KErrNotFound; |
|
685 } |
|
686 User::LeaveIfError( err ); |
|
687 |
|
688 aFile = handle; |
|
689 |
|
690 if( iSession ) |
|
691 { |
|
692 CBSServer* server = iSession->Server(); |
|
693 if( server ) |
|
694 { |
|
695 server->RegisterFileForSessionL( iSession, *fullname, versioned ); |
|
696 } |
|
697 } |
|
698 |
|
699 CleanupStack::PopAndDestroy( 2, fileName ); // fullname, fileName |
|
700 TRACE( T_LIT( "CBSStorageManager::BrandHandleL end") ); |
|
701 } |
|
702 |
|
703 // --------------------------------------------------------------------------- |
|
704 // CBSStorageManager::FileElementHandleL |
|
705 // --------------------------------------------------------------------------- |
|
706 // |
|
707 void CBSStorageManager::FileElementHandleL( const TDesC& aAppId, |
|
708 const TDesC& aBrandId, |
|
709 const TDesC& aFileName, |
|
710 const TDesC& aLanguageBuf, |
|
711 RFile& aFile ) |
|
712 { |
|
713 TRACE( T_LIT( "CBSStorageManager::FileElementHandleL begin AppId[%S],BrandId[%S],Filename[%S]"),&aAppId, &aBrandId, &aFileName ); |
|
714 // Modified file name format: "r[n].filename.ext", |
|
715 // where "n" is the language code. |
|
716 // Format used to be "filename.ext.r[n]". |
|
717 HBufC* internalFn = HBufC::NewLC( aFileName.Length() |
|
718 + KBSFileLangSuffix().Length() |
|
719 + aLanguageBuf.Length() |
|
720 + KDot().Length() ); |
|
721 TPtr pInternalFn( internalFn->Des() ); |
|
722 pInternalFn.Append( KBSFileLangSuffix() ); |
|
723 pInternalFn.Append( aLanguageBuf ); |
|
724 pInternalFn.Append( KDot() ); |
|
725 pInternalFn.Append( aFileName ); |
|
726 |
|
727 TInt length = aAppId.Length() |
|
728 + aBrandId.Length() |
|
729 + pInternalFn.Length() |
|
730 + ( KDirSeparator().Length() * 3 ) |
|
731 + KFileElementStore().Length(); |
|
732 |
|
733 HBufC* fileName = HBufC::NewL( length ); // replaced NewLC with NewL |
|
734 |
|
735 TPtr filePtr( fileName->Des() ); |
|
736 |
|
737 // [application_id]\[brand_id]\files\[aFilename] |
|
738 // |
|
739 filePtr.Append( aAppId ); |
|
740 filePtr.Append( KDirSeparator ); |
|
741 filePtr.Append( aBrandId ); |
|
742 filePtr.Append( KDirSeparator ); |
|
743 filePtr.Append( KFileElementStore ); |
|
744 filePtr.Append( KDirSeparator ); |
|
745 filePtr.Append( pInternalFn ); |
|
746 |
|
747 CleanupStack::PopAndDestroy( internalFn ); |
|
748 internalFn = NULL; |
|
749 pInternalFn.Set( 0, 0, 0 ); |
|
750 |
|
751 CleanupStack::PushL( fileName ); |
|
752 HBufC* fullname = FullFileNameLC( filePtr ); |
|
753 |
|
754 // Make a TPtr instead of TFileName because after mod, "fullPtr" |
|
755 // does not need to be passed to BaflUtils::NearestLanguageFile() |
|
756 // old implementation: TFileName fullPtr = fullname->Des(); |
|
757 TPtr fullPtr( fullname->Des() ); |
|
758 |
|
759 |
|
760 // A few thoughts about language suffix of files: |
|
761 // NOTE: NOT about brand file (e.g. "brandfile.bin.r99" ), |
|
762 // but about other files which belong to the branding package, |
|
763 // since language suffix added by branding server to a |
|
764 // mif-file is not acceptable later when calling |
|
765 // AknIconUtils::CreateIconLC() on the mif-file. |
|
766 // Skipped call to BaflUtils::NearestLanguageFile() because "XSP MOD" |
|
767 // moves language code from suffix to prefix. |
|
768 // NearestLanguageFile()-call could be replaced by an op where |
|
769 // manager seeks a file only from c and z, or from all drives, |
|
770 // but does so only for file matching to current or requested |
|
771 // language. Meaning will not try to get the nearest language |
|
772 // file but the matching one. |
|
773 // If nearest language file is actually needed, then |
|
774 // manager could for example implement a seek-function similar to |
|
775 // BaflUtils::NearestLanguageFile(), but with the difference that |
|
776 // it will inspect file prefix instead of suffix. |
|
777 |
|
778 |
|
779 RFile handle; |
|
780 // RFs::ShareProtected() needs to be called for the Fs-session |
|
781 // used to open the handle that is about to be shared. |
|
782 // ShareProtected() was called to a wrong Fs session in |
|
783 // CBSBrandHandler::GetFileL()! |
|
784 TInt err = handle.Open( iFs, fullPtr, EFileShareReadersOnly ); |
|
785 if( err == KErrPathNotFound ) |
|
786 { |
|
787 // not found, we try forcing c-drive |
|
788 HBufC* driveForced = FullFileNameLC( filePtr, ETrue ); |
|
789 |
|
790 TFileName forcedPtr = driveForced->Des(); |
|
791 |
|
792 |
|
793 err = handle.Open( iFs, forcedPtr, EFileShareReadersOnly ); |
|
794 User::LeaveIfError( err ); |
|
795 // this file was found, we can use this |
|
796 CleanupStack::Pop( driveForced ); |
|
797 CleanupStack::PopAndDestroy( fullname ); |
|
798 fullname = driveForced; |
|
799 CleanupStack::PushL( fullname ); |
|
800 } |
|
801 else |
|
802 { |
|
803 User::LeaveIfError( err ); |
|
804 } |
|
805 |
|
806 CleanupStack::PopAndDestroy( 2, fileName ); // fullname, fileName |
|
807 aFile = handle; |
|
808 TRACE( T_LIT( "CBSStorageManager::FileElementHandleL end") ); |
|
809 } |
|
810 |
|
811 |
|
812 // --------------------------------------------------------------------------- |
|
813 // CBSStorageManager::FullFileNameLC |
|
814 // --------------------------------------------------------------------------- |
|
815 // |
|
816 HBufC* CBSStorageManager::FullFileNameLC( const TDesC& aFilename, TBool aForceCDrive /*= EFalse*/ ) |
|
817 { |
|
818 // get the private path |
|
819 TBuf<KMaxPath> path; |
|
820 User::LeaveIfError( iFs.PrivatePath( path ) ); |
|
821 |
|
822 // construct absolute filename |
|
823 HBufC* fullname = HBufC::NewLC( KBSCDrive().Length() + aFilename.Length() + path.Length() + |
|
824 KBSDataStore().Length() + KDirSeparator().Length() ); |
|
825 TPtr fullPtr( fullname->Des() ); |
|
826 fullPtr.Append( KBSCDrive ); |
|
827 fullPtr.Append( path ); |
|
828 fullPtr.Append( KBSDataStore ); |
|
829 fullPtr.Append( KDirSeparator ); |
|
830 fullPtr.Append( aFilename ); |
|
831 |
|
832 TParse filename; |
|
833 iFs.Parse( fullPtr, filename ); |
|
834 |
|
835 if( !aForceCDrive ) |
|
836 { |
|
837 // C-drive not explicitely requested |
|
838 if( !BaflUtils::FileExists( iFs, fullPtr ) ) |
|
839 { |
|
840 // the file does not exist in C-drive, so |
|
841 // we have to return a path to Z-drive |
|
842 fullPtr.Zero(); |
|
843 fullPtr.Append( KBSZDrive ); |
|
844 fullPtr.Append( path ); |
|
845 fullPtr.Append( KBSDataStore ); |
|
846 fullPtr.Append( KDirSeparator ); |
|
847 fullPtr.Append( aFilename ); |
|
848 } |
|
849 } |
|
850 |
|
851 return fullname; |
|
852 } |
|
853 |
|
854 // --------------------------------------------------------------------------- |
|
855 // CBSStorageManager::CleanupFileL |
|
856 // --------------------------------------------------------------------------- |
|
857 // |
|
858 void CBSStorageManager::CleanupFileL( const TDesC& aFileName ) |
|
859 { |
|
860 TRACE( T_LIT( "CBSStorageManager::CleanupFileL begin") ); |
|
861 // we have a versioned file we need to clean up |
|
862 // get the file name without the version information |
|
863 if( !IsBaseFileL( aFileName) ) |
|
864 { |
|
865 // this is not a basefile |
|
866 // we need to check if basefile should be replaced |
|
867 // with this one |
|
868 TPtrC baseFile = FilenameWithoutVersion( aFileName ); |
|
869 TInt version = ReadVersionL( aFileName ); |
|
870 TInt baseVersion = ReadVersionL( baseFile ); |
|
871 if( version > baseVersion ) |
|
872 { |
|
873 // newer version --> replace basefile |
|
874 TInt err = iFs.Replace( aFileName, baseFile); |
|
875 User::LeaveIfError( err ); |
|
876 } |
|
877 else |
|
878 { |
|
879 // same or older version --> delete |
|
880 TInt err = iFs.Delete( aFileName ); |
|
881 User::LeaveIfError( err ); |
|
882 } |
|
883 } |
|
884 else |
|
885 { |
|
886 // this is a basefile |
|
887 // we need to check if there are any newer versioned files |
|
888 // that are not in use |
|
889 |
|
890 TParse filename; |
|
891 iFs.Parse( aFileName, filename ); |
|
892 TPtrC driveAndPath = filename.DriveAndPath(); |
|
893 |
|
894 HBufC* nameWithDrive = HBufC::NewLC( aFileName.Length() + KBSCDrive().Length() ); |
|
895 TPtr nameWithDrivePtr = nameWithDrive->Des(); |
|
896 |
|
897 nameWithDrivePtr.Append( aFileName ); |
|
898 |
|
899 CDir* files = NULL; |
|
900 CDir* directories = NULL; |
|
901 |
|
902 User::LeaveIfError( iFs.GetDir( driveAndPath, KEntryAttNormal, ESortByName, files, directories ) ); |
|
903 |
|
904 TInt count = files->Count(); |
|
905 for( TInt i = 0; i < count; i++ ) |
|
906 { |
|
907 const TEntry file = (*files)[ i ]; |
|
908 TBufC<KMaxFileName> name = file.iName; |
|
909 |
|
910 HBufC* fullName = HBufC::NewLC( driveAndPath.Length() + name.Length() ); |
|
911 TPtr fullPtr = fullName->Des(); |
|
912 |
|
913 fullPtr.Append( driveAndPath ); |
|
914 fullPtr.Append( name ); |
|
915 |
|
916 TPtrC strippedName = FilenameWithoutVersion( *fullName ); |
|
917 |
|
918 if( 0 == strippedName.Compare( nameWithDrivePtr ) ) |
|
919 { |
|
920 // there is a versioned file, that might be newer |
|
921 // than the basefile |
|
922 TInt baseVersion = ReadVersionL( nameWithDrivePtr ); |
|
923 |
|
924 TInt versionedVersion = ReadVersionL( fullPtr ); |
|
925 if( versionedVersion > baseVersion ) |
|
926 { |
|
927 // versioned file newer than base file |
|
928 // check if the versioned file is still in use |
|
929 if( !iSession->Server()->FileStillInUse( iSession, fullPtr ) ) |
|
930 { |
|
931 // the file is not in use, we can replace the basefile |
|
932 // with the versioned file |
|
933 TInt err = iFs.Replace( fullPtr, nameWithDrivePtr ); |
|
934 User::LeaveIfError( err ); |
|
935 } |
|
936 } |
|
937 } |
|
938 CleanupStack::PopAndDestroy( fullName ); |
|
939 } |
|
940 CleanupStack::PopAndDestroy( nameWithDrive ); |
|
941 } |
|
942 TRACE( T_LIT( "CBSStorageManager::CleanupFileL end") ); |
|
943 } |
|
944 |
|
945 // --------------------------------------------------------------------------- |
|
946 // CBSStorageManager::FilenameWithoutVersionL |
|
947 // --------------------------------------------------------------------------- |
|
948 // |
|
949 TPtrC CBSStorageManager::FilenameWithoutVersion( const TDesC& aFileName ) |
|
950 { |
|
951 TParse filename; |
|
952 iFs.Parse( aFileName, filename ); |
|
953 TPtrC extension = filename.Ext(); |
|
954 TPtrC strippedName = aFileName.Left( aFileName.Length() - ( extension.Length() ) ); |
|
955 return strippedName; |
|
956 } |
|
957 |
|
958 |
|
959 // --------------------------------------------------------------------------- |
|
960 // CBSStorageManager::IsBaseFileL |
|
961 // --------------------------------------------------------------------------- |
|
962 // |
|
963 TBool CBSStorageManager::IsBaseFileL( const TDesC& aFileName ) |
|
964 { |
|
965 TBool returnValue = ETrue; |
|
966 TPtrC fileName = FilenameWithoutVersion( aFileName ); |
|
967 if( BaflUtils::FileExists( iFs, fileName ) ) |
|
968 { |
|
969 // file with one extension stripped out exists |
|
970 // --> the file was not a base file |
|
971 returnValue = EFalse; |
|
972 } |
|
973 return returnValue; |
|
974 } |
|
975 |
|
976 // --------------------------------------------------------------------------- |
|
977 // CBSStorageManager::InstallFile |
|
978 // --------------------------------------------------------------------------- |
|
979 // |
|
980 HBufC* CBSStorageManager::InstallFileLC( const TDesC& aFileName ) |
|
981 { |
|
982 TRACE( T_LIT( "CBSStorageManager::InstallFileLC begin") ); |
|
983 if( !iAppId || !iBrandId ) |
|
984 { |
|
985 User::Leave( KErrNotReady ); |
|
986 } |
|
987 TParse filename; |
|
988 iFs.Parse( aFileName, filename ); |
|
989 |
|
990 TInt length = iAppId->Length() + iBrandId->Length() + |
|
991 aFileName.Length() + KDirSeparator().Length() * 3 |
|
992 + KFileElementStore().Length() + iLanguageId->Length() |
|
993 + KDot().Length() + KBSFileLangSuffix().Length(); |
|
994 |
|
995 HBufC* fileName = HBufC::NewLC( length ); |
|
996 |
|
997 TPtr filePtr( fileName->Des() ); |
|
998 |
|
999 filePtr.Append( *iAppId ); |
|
1000 filePtr.Append( KDirSeparator ); |
|
1001 filePtr.Append( *iBrandId ); |
|
1002 filePtr.Append( KDirSeparator ); |
|
1003 filePtr.Append( KFileElementStore ); |
|
1004 filePtr.Append( KDirSeparator ); |
|
1005 filePtr.Append( KBSFileLangSuffix() ); |
|
1006 filePtr.Append( *iLanguageId ); |
|
1007 filePtr.Append( KDot() ); |
|
1008 filePtr.Append( filename.NameAndExt() ); |
|
1009 |
|
1010 HBufC* fullname = FullFileNameLC( filePtr, ETrue ); |
|
1011 |
|
1012 TParse directory; |
|
1013 iFs.Parse( *fullname, directory ); |
|
1014 TPtrC ptr = directory.DriveAndPath(); |
|
1015 TInt dirError = iFs.MkDirAll( directory.DriveAndPath() ); |
|
1016 if( dirError == KErrAlreadyExists ) |
|
1017 { |
|
1018 // ignore already exists |
|
1019 dirError = KErrNone; |
|
1020 } |
|
1021 User::LeaveIfError( dirError ); |
|
1022 |
|
1023 CFileMan* fileMan = CFileMan::NewL( iFs ); |
|
1024 CleanupStack::PushL( fileMan ); |
|
1025 |
|
1026 // copy the file, no overwriting |
|
1027 TInt err = fileMan->Copy( aFileName, *fullname, 1 ); |
|
1028 User::LeaveIfError( err ); |
|
1029 |
|
1030 #ifdef __WINSCW__ |
|
1031 // Add to IBY file |
|
1032 iWriter->SetFileItemL( *fullname, *fullname ); |
|
1033 #endif |
|
1034 |
|
1035 CleanupStack::PopAndDestroy( 3, fileName ); // fileMan, fullname, fileName |
|
1036 |
|
1037 |
|
1038 HBufC* returnValue = filename.NameAndExt().AllocLC(); |
|
1039 TRACE( T_LIT( "CBSStorageManager::InstallFileLC end") ); |
|
1040 return returnValue; |
|
1041 } |
|
1042 |
|
1043 |
|
1044 // --------------------------------------------------------------------------- |
|
1045 // CBSStorageManager::RemoveBrandL |
|
1046 // --------------------------------------------------------------------------- |
|
1047 // |
|
1048 void CBSStorageManager::RemoveBrandL( const TDesC& aAppId, |
|
1049 const TDesC& aBrandId, |
|
1050 TLanguage aLanguageId, |
|
1051 TInt aReserved ) |
|
1052 { |
|
1053 TRACE( T_LIT( "CBSStorageManager::RemoveBrandL begin") ); |
|
1054 HBufC* fileName = ConstructFileNameL( aAppId, |
|
1055 aBrandId, |
|
1056 aLanguageId, |
|
1057 aReserved ); |
|
1058 CleanupStack::PushL( fileName ); |
|
1059 |
|
1060 HBufC* fullname = FullFileNameLC( *fileName, ETrue ); |
|
1061 |
|
1062 TParse parseName; |
|
1063 iFs.Parse( *fullname, parseName ); |
|
1064 |
|
1065 TPtrC directory = parseName.DriveAndPath(); |
|
1066 |
|
1067 CFileMan* fileMan = CFileMan::NewL( iFs ); |
|
1068 CleanupStack::PushL( fileMan ); |
|
1069 |
|
1070 // delete all files under this brand and language |
|
1071 TInt err = fileMan->RmDir( directory ); |
|
1072 TRACE( T_LIT( "CBSStorageManager::RemoveBrandL dir='%S' err=%d "), &directory, err ); |
|
1073 |
|
1074 //in case the removal of the entire brand failed because the brand was |
|
1075 //in use, we set this brand as discarded (since parts of the package |
|
1076 //might have been removed) |
|
1077 if ( KErrInUse == err ) |
|
1078 { |
|
1079 MarkBrandAsDiscardedL( aAppId, aBrandId ); |
|
1080 } |
|
1081 |
|
1082 User::LeaveIfError( err ); |
|
1083 |
|
1084 CleanupStack::PopAndDestroy( 3, fileName ); |
|
1085 TRACE( T_LIT( "CBSStorageManager::RemoveBrandL end ") ); |
|
1086 } |
|
1087 |
|
1088 // --------------------------------------------------------------------------- |
|
1089 // CBSStorageManager::RemoveApplicationL |
|
1090 // --------------------------------------------------------------------------- |
|
1091 // |
|
1092 void CBSStorageManager::RemoveApplicationL( const TDesC& aAppId ) |
|
1093 { |
|
1094 TRACE( T_LIT( "CBSStorageManager::RemoveApplicationL begin") ); |
|
1095 TInt length = aAppId.Length() + |
|
1096 KDefFileName().Length() + KDirSeparator().Length(); |
|
1097 |
|
1098 |
|
1099 HBufC* fileName = HBufC::NewLC( length ); |
|
1100 |
|
1101 TPtr file( fileName->Des() ); |
|
1102 |
|
1103 file.Append( aAppId ); |
|
1104 file.Append( KDirSeparator ); |
|
1105 |
|
1106 HBufC* fullName = FullFileNameLC( *fileName, ETrue ); |
|
1107 |
|
1108 CFileMan* fileMan = CFileMan::NewL( iFs ); |
|
1109 CleanupStack::PushL( fileMan ); |
|
1110 |
|
1111 // delete all files under this brand and language |
|
1112 TInt err = fileMan->RmDir( *fullName ); |
|
1113 User::LeaveIfError( err ); |
|
1114 |
|
1115 CleanupStack::PopAndDestroy( 3, fileName ); |
|
1116 TRACE( T_LIT( "CBSStorageManager::RemoveApplicationL end") ); |
|
1117 } |
|
1118 |
|
1119 |
|
1120 // --------------------------------------------------------------------------- |
|
1121 // CBSStorageManager::NextAvailableVersionL |
|
1122 // --------------------------------------------------------------------------- |
|
1123 // |
|
1124 TInt CBSStorageManager::NextAvailableVersionL() |
|
1125 { |
|
1126 TRACE( T_LIT( "CBSStorageManager::NextAvailableVersionL begin") ); |
|
1127 TInt returnValue = 0; |
|
1128 |
|
1129 if( iAppId && iBrandId ) |
|
1130 { |
|
1131 TInt newVersion = 0; |
|
1132 TRAPD( err, newVersion = GetNewestVersionL( *iAppId, *iBrandId, iLanguageIdNum ) ); |
|
1133 if( err == KErrNotFound ) |
|
1134 { |
|
1135 // ignore not found -> we default to 1 |
|
1136 err = KErrNone; |
|
1137 returnValue = iReserved; |
|
1138 } |
|
1139 else |
|
1140 { |
|
1141 returnValue = newVersion + 1; |
|
1142 } |
|
1143 User::LeaveIfError( err ); |
|
1144 } |
|
1145 TRACE( T_LIT( "CBSStorageManager::NextAvailableVersionL end") ); |
|
1146 return returnValue; |
|
1147 } |
|
1148 |
|
1149 |
|
1150 // --------------------------------------------------------------------------- |
|
1151 // CBSStorageManager::NextAvailableVersionL |
|
1152 // --------------------------------------------------------------------------- |
|
1153 // |
|
1154 void CBSStorageManager::SetVersion( TInt aReserved ) |
|
1155 { |
|
1156 iReserved = aReserved; |
|
1157 } |
|
1158 |
|
1159 |
|
1160 // --------------------------------------------------------------------------- |
|
1161 // CBSStorageManager::GetCurrentVersionL |
|
1162 // --------------------------------------------------------------------------- |
|
1163 // |
|
1164 TInt CBSStorageManager::GetNewestVersionL( const TDesC& aAppId, |
|
1165 const TDesC& aBrandId, |
|
1166 TLanguage aLanguageId, |
|
1167 TPtr* aDrive /*= KNullDesC()*/ ) |
|
1168 { |
|
1169 TRACE( T_LIT( "CBSStorageManager::GetNewestVersionL begin") ); |
|
1170 HBufC* fileName = ConstructFileNameL( aAppId, aBrandId, aLanguageId ); |
|
1171 CleanupStack::PushL( fileName ); |
|
1172 |
|
1173 |
|
1174 // FullFileNameLC returns the file from C-drive if it exists there |
|
1175 // and if not, then from ROM |
|
1176 HBufC* fullFileName = FullFileNameLC( *fileName ); |
|
1177 |
|
1178 TParse parse; |
|
1179 iFs.Parse( *fullFileName, parse ); |
|
1180 TPtrC driveAndPath = parse.DriveAndPath(); |
|
1181 |
|
1182 CDir* files = NULL; |
|
1183 CDir* directories = NULL; |
|
1184 |
|
1185 TInt err = iFs.GetDir( driveAndPath, KEntryAttNormal, ESortByName, files, directories ); |
|
1186 if(KErrNone == err ) |
|
1187 { |
|
1188 if(aDrive) |
|
1189 { |
|
1190 (*aDrive).Copy(KBSZDrive); |
|
1191 } |
|
1192 |
|
1193 } |
|
1194 if( err == KErrPathNotFound ) |
|
1195 { |
|
1196 // not found from Z-drive, try from C-drive |
|
1197 CleanupStack::PopAndDestroy( fullFileName ); |
|
1198 fullFileName = FullFileNameLC( *fileName, ETrue ); |
|
1199 driveAndPath.Set( parse.DriveAndPath() ); |
|
1200 err = iFs.GetDir( driveAndPath, KEntryAttNormal, ESortByName, files, directories ); |
|
1201 if(KErrNone == err ) |
|
1202 { |
|
1203 if(aDrive) |
|
1204 { |
|
1205 (*aDrive).Copy(KBSCDrive); |
|
1206 } |
|
1207 } |
|
1208 if( err == KErrPathNotFound ) |
|
1209 { |
|
1210 // switching error code to make it more clear |
|
1211 err = KErrNotFound; |
|
1212 } |
|
1213 // as we are leaving here cleanup the stack |
|
1214 CleanupStack::PopAndDestroy( 2, fileName ); // fullFileName, fileName |
|
1215 User::LeaveIfError( err ); |
|
1216 } |
|
1217 |
|
1218 // get the base file version |
|
1219 TInt returnValue = ReadVersionL( *fullFileName ); |
|
1220 |
|
1221 TInt count = files->Count(); |
|
1222 for( TInt i = 0; i < count; i++ ) |
|
1223 { |
|
1224 const TEntry file = (*files)[ i ]; |
|
1225 TBufC<KMaxFileName> name = file.iName; |
|
1226 |
|
1227 HBufC* fullName = HBufC::NewLC( driveAndPath.Length() + name.Length() ); |
|
1228 TPtr fullPtr = fullName->Des(); |
|
1229 |
|
1230 fullPtr.Append( driveAndPath ); |
|
1231 fullPtr.Append( name ); |
|
1232 |
|
1233 TPtrC strippedName = FilenameWithoutVersion( *fullName ); |
|
1234 |
|
1235 if( 0 == strippedName.Compare( *fullFileName ) ) |
|
1236 { |
|
1237 // there is a versioned file, that might be newer |
|
1238 // than the basefile |
|
1239 TInt versionedVersion = ReadVersionL( fullPtr ); |
|
1240 if( versionedVersion > returnValue ) |
|
1241 { |
|
1242 // versioned file newer than base file |
|
1243 returnValue = versionedVersion; |
|
1244 } |
|
1245 } |
|
1246 CleanupStack::PopAndDestroy( fullName ); |
|
1247 } |
|
1248 |
|
1249 CleanupStack::PopAndDestroy( 2, fileName ); // fullFileName, fileName |
|
1250 |
|
1251 TRACE( T_LIT( "CBSStorageManager::GetNewestVersionL end") ); |
|
1252 return returnValue; |
|
1253 } |
|
1254 |
|
1255 |
|
1256 // --------------------------------------------------------------------------- |
|
1257 // CBSStorageManager::WriteIbyFiles |
|
1258 // --------------------------------------------------------------------------- |
|
1259 // |
|
1260 TInt CBSStorageManager::WriteIbyFiles() |
|
1261 { |
|
1262 TInt err = KErrNone; |
|
1263 #ifdef __WINSCW__ |
|
1264 if( !iWriter ) |
|
1265 { |
|
1266 return KErrNone; |
|
1267 } |
|
1268 |
|
1269 TRAP( err, iWriter->WriteIBYFileL( iFs, *iIbyFile ) ); |
|
1270 delete iIbyFile; |
|
1271 iIbyFile = NULL; |
|
1272 delete iWriter; |
|
1273 iWriter = NULL; |
|
1274 |
|
1275 #endif |
|
1276 return err; |
|
1277 } |
|
1278 |
|
1279 // --------------------------------------------------------------------------- |
|
1280 // CBSStorageManager::LockStorage |
|
1281 // --------------------------------------------------------------------------- |
|
1282 // |
|
1283 void CBSStorageManager::LockStorage() |
|
1284 { |
|
1285 TRACE( T_LIT( "CBSStorageManager::LockStorage begin") ); |
|
1286 // This will disable all filehandles, so that clients can't use them |
|
1287 iFs.Close(); |
|
1288 TRACE( T_LIT( "CBSStorageManager::LockStorage end") ); |
|
1289 } |
|
1290 |
|
1291 // --------------------------------------------------------------------------- |
|
1292 // CBSStorageManager::ReleaseLockL |
|
1293 // --------------------------------------------------------------------------- |
|
1294 // |
|
1295 void CBSStorageManager::ReleaseLockL() |
|
1296 { |
|
1297 TRACE( T_LIT( "CBSStorageManager::ReleaseLockL begin") ); |
|
1298 User::LeaveIfError( iFs.Connect() ); |
|
1299 TRACE( T_LIT( "CBSStorageManager::ReleaseLockL end") ); |
|
1300 } |
|
1301 |
|
1302 // --------------------------------------------------------------------------- |
|
1303 // CBSStorageManager::CheckBrandDiscarded |
|
1304 // --------------------------------------------------------------------------- |
|
1305 // |
|
1306 TBool CBSStorageManager::CheckBrandDiscarded(const TDesC& aAppId, |
|
1307 const TDesC& aBrandId) |
|
1308 { |
|
1309 TBool flag = EFalse ; |
|
1310 |
|
1311 HBufC *fileName = ConstructDiscardBrandFileNameL(aAppId, aBrandId) ; |
|
1312 CleanupStack::PushL(fileName); |
|
1313 HBufC *fullPath = FullDiscardBrandFileNameLC( *fileName ) ; |
|
1314 |
|
1315 // crate a flag file |
|
1316 RFile file; |
|
1317 TInt err = file.Open(iFs, *fullPath, EFileWrite); |
|
1318 if(err == KErrNone) |
|
1319 { |
|
1320 // file exists. |
|
1321 file.Close() ; |
|
1322 flag = ETrue ; |
|
1323 } |
|
1324 |
|
1325 CleanupStack::PopAndDestroy(fullPath) ; |
|
1326 CleanupStack::PopAndDestroy(fileName) ; |
|
1327 return flag ; |
|
1328 } |
|
1329 |
|
1330 // --------------------------------------------------------------------------- |
|
1331 // CBSStorageManager::ConstructDiscardBrandFileNameL |
|
1332 // --------------------------------------------------------------------------- |
|
1333 // |
|
1334 HBufC* CBSStorageManager::ConstructDiscardBrandFileNameL( const TDesC& aAppId, |
|
1335 const TDesC& aBrandId ) |
|
1336 { |
|
1337 HBufC* fileName = NULL; |
|
1338 |
|
1339 TInt length = aAppId.Length() + aBrandId.Length() + |
|
1340 KDiscardBrandFileName().Length() + KDirSeparator().Length() * 2 ; |
|
1341 fileName = HBufC::NewLC( length ); |
|
1342 |
|
1343 TPtr file( fileName->Des() ); |
|
1344 |
|
1345 // [application_id]\[brand_id]\discardedbrand.txt |
|
1346 file.Append( aAppId ); |
|
1347 file.Append( KDirSeparator ); |
|
1348 file.Append( aBrandId ); |
|
1349 file.Append( KDirSeparator ); |
|
1350 file.Append( KDiscardBrandFileName ); |
|
1351 |
|
1352 if( fileName ) |
|
1353 { |
|
1354 CleanupStack::Pop( fileName ); |
|
1355 } |
|
1356 |
|
1357 return fileName; |
|
1358 } |
|
1359 |
|
1360 // --------------------------------------------------------------------------- |
|
1361 // CBSStorageManager::FullDiscardBrandFileNameLC |
|
1362 // --------------------------------------------------------------------------- |
|
1363 // |
|
1364 HBufC* CBSStorageManager::FullDiscardBrandFileNameLC( TDesC& aFilename ) |
|
1365 { |
|
1366 // get the private path |
|
1367 TBuf<KMaxPath> path; |
|
1368 RFs fs ; |
|
1369 User::LeaveIfError( fs.Connect() ); |
|
1370 CleanupClosePushL(fs); |
|
1371 User::LeaveIfError( fs.PrivatePath( path ) ); |
|
1372 |
|
1373 // construct absolute filename |
|
1374 HBufC* fullname = HBufC::NewLC( KBSCDrive().Length() + aFilename.Length() + path.Length() + |
|
1375 KBSDataStore().Length() + KDirSeparator().Length() ); |
|
1376 TPtr fullPtr( fullname->Des() ); |
|
1377 fullPtr.Append( KBSCDrive ); |
|
1378 fullPtr.Append( path ); |
|
1379 fullPtr.Append( KBSDataStore ); |
|
1380 fullPtr.Append( KDirSeparator ); |
|
1381 fullPtr.Append( aFilename ); |
|
1382 |
|
1383 CleanupStack::Pop(); // fullname |
|
1384 CleanupStack::PopAndDestroy() ; //fs |
|
1385 CleanupStack::PushL(fullname) ; |
|
1386 |
|
1387 return fullname; |
|
1388 } |
|
1389 |
|
1390 // --------------------------------------------------------------------------- |
|
1391 // CBSStorageManager::MarkBrandAsDiscardedL |
|
1392 // --------------------------------------------------------------------------- |
|
1393 // |
|
1394 void CBSStorageManager::MarkBrandAsDiscardedL( const TDesC& aAppId, |
|
1395 const TDesC& aBrandId ) |
|
1396 { |
|
1397 TRACE( T_LIT( "CBSStorageManager::MarkBrandAsDiscardedL begin app='%S' brand='%S'"), &aAppId, &aBrandId ); |
|
1398 |
|
1399 HBufC *fileName = ConstructDiscardBrandFileNameL( aAppId, aBrandId ) ; |
|
1400 CleanupStack::PushL( fileName ); |
|
1401 HBufC *fullPath = FullDiscardBrandFileNameLC( *fileName ) ; |
|
1402 TRACE( T_LIT( "CBSStorageManager::MarkBrandAsDiscardedL discardedfile='%S'"), &fullPath ); |
|
1403 |
|
1404 // create flag file |
|
1405 RFile file; |
|
1406 TInt err = file.Replace( iFs, *fullPath, EFileWrite ); |
|
1407 TRACE( T_LIT( "CBSStorageManager::MarkBrandAsDiscardedL discarded file creation result='%d'"), err ); |
|
1408 file.Close(); |
|
1409 |
|
1410 CleanupStack::PopAndDestroy( fullPath ); |
|
1411 fullPath = NULL; |
|
1412 CleanupStack::PopAndDestroy( fileName ); |
|
1413 fileName = NULL; |
|
1414 |
|
1415 TRACE( T_LIT( "CBSStorageManager::MarkBrandAsDiscardedL begin") ); |
|
1416 } |
|
1417 |
|
1418 // End of file |