21 |
21 |
22 #include "syslangutil.h" |
22 #include "syslangutil.h" |
23 #include "syslangutiltrace.h" |
23 #include "syslangutiltrace.h" |
24 #include "ssmmapperutilitystatic.h" |
24 #include "ssmmapperutilitystatic.h" |
25 #include "syslangutilprivatecrkeys.h" |
25 #include "syslangutilprivatecrkeys.h" |
|
26 #include "ssmcommonlocale.h" |
|
27 #include <CommonEngineDomainCRKeys.h> |
26 |
28 |
27 const TInt KReadBufSize = 10; |
29 const TInt KReadBufSize = 10; |
28 const TInt KLangArraySize = 20; |
30 const TInt KLangArraySize = 10; |
|
31 //Maximum number of retries for starting cenrep transaction. |
|
32 const TInt KMaxCountForReiteration = 5; |
29 |
33 |
30 // R&D support: Use language file in Starters internal directory for module |
34 // R&D support: Use language file in Starters internal directory for module |
31 // testing purposes. |
35 // testing purposes. |
32 #ifdef __STARTER_MODULE_TEST_SUPPORT__ |
36 #ifdef __STARTER_MODULE_TEST_SUPPORT__ |
33 _LIT( KLanguagesIni, "C:\\private\\100059C9\\languages.txt" ); |
37 _LIT( KLanguagesIni, "C:\\private\\100059C9\\languages.txt" ); |
|
38 _LIT( KRegionsIni, "C:\\private\\100059C9\\regions.txt" ); |
|
39 _LIT( KCollationsIni, "C:\\private\\100059C9\\collations.txt" ); |
|
40 |
34 #else // __STARTER_MODULE_TEST_SUPPORT__ |
41 #else // __STARTER_MODULE_TEST_SUPPORT__ |
35 _LIT( KLanguagesIni, "z:\\resource\\bootdata\\languages.txt" ); |
42 _LIT( KLanguagesIni, "z:\\resource\\bootdata\\languages.txt" ); |
|
43 _LIT( KRegionsIni, "z:\\resource\\bootdata\\regions.txt" ); |
|
44 _LIT( KCollationsIni, "z:\\resource\\bootdata\\collations.txt" ); |
36 #endif // __STARTER_MODULE_TEST_SUPPORT__ |
45 #endif // __STARTER_MODULE_TEST_SUPPORT__ |
37 |
46 |
38 // ============================ MEMBER FUNCTIONS =============================== |
47 // ============================ MEMBER FUNCTIONS =============================== |
39 |
48 |
40 // ----------------------------------------------------------------------------- |
49 // ----------------------------------------------------------------------------- |
349 aErr = KErrNone; |
358 aErr = KErrNone; |
350 |
359 |
351 FUNC_EXIT_TRACE; |
360 FUNC_EXIT_TRACE; |
352 return aRFs; |
361 return aRFs; |
353 } |
362 } |
|
363 |
|
364 // ----------------------------------------------------------------------------- |
|
365 // SysLangUtil::ChangeLanguage |
|
366 // |
|
367 // ----------------------------------------------------------------------------- |
|
368 // |
|
369 EXPORT_C TInt SysLangUtil::ChangeLanguage(const TInt aLanguageCode) |
|
370 { |
|
371 API_FUNC_ENTRY_TRACE; |
|
372 TRAPD( errorCode, LoadDllL( KGSDisplayTxtLang,aLanguageCode, KLanguageDllNameBase ) ); |
|
373 FUNC_EXIT_RET_TRACE( errorCode ); |
|
374 return errorCode; |
|
375 } |
|
376 |
|
377 |
|
378 // ----------------------------------------------------------------------------- |
|
379 // SysLangUtil::ChangeRegion |
|
380 // |
|
381 // ----------------------------------------------------------------------------- |
|
382 // |
|
383 EXPORT_C TInt SysLangUtil::ChangeRegion(const TInt aRegionCode) |
|
384 { |
|
385 API_FUNC_ENTRY_TRACE; |
|
386 TRAPD( errorCode, LoadDllL( KGSRegion, aRegionCode, KRegionDllNameBase ) ); |
|
387 FUNC_EXIT_RET_TRACE( errorCode ); |
|
388 return errorCode; |
|
389 } |
|
390 |
|
391 // ----------------------------------------------------------------------------- |
|
392 // SysLangUtil::ChangeCollation |
|
393 // |
|
394 // ----------------------------------------------------------------------------- |
|
395 // |
|
396 EXPORT_C TInt SysLangUtil::ChangeCollation(const TInt aCollationCode) |
|
397 { |
|
398 API_FUNC_ENTRY_TRACE; |
|
399 TRAPD( errorCode, LoadDllL( KGSCollation, aCollationCode, KCollationDllNameBase ) ); |
|
400 FUNC_EXIT_RET_TRACE( errorCode ); |
|
401 return errorCode; |
|
402 } |
|
403 |
|
404 |
|
405 // ----------------------------------------------------------------------------- |
|
406 // SysLangUtil::GetInstalledRegions |
|
407 // |
|
408 // ----------------------------------------------------------------------------- |
|
409 // |
|
410 EXPORT_C TInt SysLangUtil::GetInstalledRegions(CArrayFixFlat<TInt>*& aRegions, RFs* aFileServerSession ) |
|
411 { |
|
412 API_FUNC_ENTRY_TRACE; |
|
413 TRAPD(err, ReadFileL(aRegions, KRegionsIni, aFileServerSession )); |
|
414 FUNC_EXIT_RET_TRACE( err ); |
|
415 return err; |
|
416 } |
|
417 |
|
418 // ----------------------------------------------------------------------------- |
|
419 // SysLangUtil::GetInstalledCollations |
|
420 // |
|
421 // ----------------------------------------------------------------------------- |
|
422 // |
|
423 EXPORT_C TInt SysLangUtil::GetInstalledCollations(CArrayFixFlat<TInt>*& aCollations, RFs* aFileServerSession ) |
|
424 { |
|
425 API_FUNC_ENTRY_TRACE; |
|
426 TRAPD(err, ReadFileL(aCollations, KCollationsIni, aFileServerSession )); |
|
427 FUNC_EXIT_RET_TRACE( err ); |
|
428 return err; |
|
429 } |
|
430 |
|
431 void SysLangUtil::LoadDllL( const TUint32 aCategory,const TInt aCode, const TDesC& aDllNameBase ) |
|
432 { |
|
433 CRepository* cenrep = NULL; |
|
434 TUint32 keyInfo; |
|
435 cenrep = CRepository::NewLC( KCRUidCommonEngineKeys ); |
|
436 |
|
437 // Re-iterate through StartTransaction, if errorCode returned is KErrLocked |
|
438 TInt errorCode = KErrLocked; |
|
439 //Counter to restrict re-iteration. |
|
440 TInt counter = KMaxCountForReiteration; |
|
441 while ( KErrLocked == errorCode && counter > 0 ) |
|
442 { |
|
443 errorCode = cenrep->StartTransaction(CRepository::EConcurrentReadWriteTransaction); |
|
444 --counter; |
|
445 } |
|
446 User::LeaveIfError(errorCode); |
|
447 cenrep->CleanupCancelTransactionPushL(); |
|
448 User::LeaveIfError(cenrep->Set( aCategory, aCode)); |
|
449 |
|
450 TBuf<KMaxDllExtensionLength> extension; |
|
451 extension.Format( KDllExtensionFormat, aCode ); |
|
452 |
|
453 // Padd ".1" to ".001" for compatibility. |
|
454 for( ; extension.Length() < KMinDllExtensionLength ;) |
|
455 { |
|
456 extension.Insert( KDllExtensionPaddingPosition, |
|
457 KDllExtensionPadding ); |
|
458 } |
|
459 |
|
460 TBuf<KMaxDllNameLength> dllName( aDllNameBase ); |
|
461 dllName.Append( extension ); |
|
462 |
|
463 //Loading DLL |
|
464 TExtendedLocale extLocale; |
|
465 extLocale.LoadSystemSettings(); |
|
466 errorCode = extLocale.LoadLocaleAspect( dllName ); |
|
467 ERROR_TRACE_2( "LoadLocaleAspect returned error %d while loading dll %S" ,errorCode, &dllName ); |
|
468 User::LeaveIfError(errorCode); |
|
469 |
|
470 User::LeaveIfError(extLocale.SaveSystemSettings()); |
|
471 errorCode = cenrep->CommitTransaction(keyInfo); |
|
472 if ( KErrNone != errorCode ) |
|
473 { |
|
474 ERROR_TRACE_2( "CommitTransaction() error: Key Info %d for setting Category %d", keyInfo, aCategory ); |
|
475 User::Leave(errorCode); |
|
476 } |
|
477 CleanupStack::PopAndDestroy();// for CleanupCancelTransactionPushL() |
|
478 CleanupStack::PopAndDestroy(cenrep); |
|
479 User::LeaveIfError(TLocale().Set()); |
|
480 } |
|
481 |
|
482 void SysLangUtil::ReadFileL(CArrayFixFlat<TInt>*& aArray, const TDesC& aFilePath, RFs* aFileServerSession ) |
|
483 { |
|
484 TBool hadFS = EFalse; |
|
485 TInt err = KErrNone; |
|
486 if ( aArray ) |
|
487 { |
|
488 delete aArray; |
|
489 aArray = NULL; |
|
490 } |
|
491 aArray = new(ELeave) CArrayFixFlat<TInt>( KLangArraySize ); |
|
492 |
|
493 aFileServerSession = CheckFS( aFileServerSession, hadFS, err ); |
|
494 User::LeaveIfError(err); |
|
495 RFile file; |
|
496 CleanupClosePushL(file); |
|
497 err = file.Open(*aFileServerSession, aFilePath, EFileStream | EFileRead | EFileShareReadersOnly ); |
|
498 ERROR_TRACE_2( "SysLangUtil::ReadFileL() : Opening the file : %S failed with error : %d", &aFilePath, err) ; |
|
499 User::LeaveIfError(err); |
|
500 |
|
501 // Prepare Reader |
|
502 TFileText reader; |
|
503 reader.Set( file ); |
|
504 err = reader.Seek( ESeekStart ); |
|
505 if ( !err ) |
|
506 { |
|
507 TBuf<KReadBufSize> readBuf; |
|
508 for ( TInt i = 0; !reader.Read( readBuf ) && readBuf.Length(); ++i ) |
|
509 { |
|
510 TLex lex( readBuf ); |
|
511 lex.SkipSpace(); |
|
512 TInt value; |
|
513 err = lex.Val( value ); |
|
514 if ( err ) |
|
515 { |
|
516 break; |
|
517 } |
|
518 // IGNORE the Leave |
|
519 TRAP_IGNORE( aArray->AppendL( value )); |
|
520 readBuf.Zero(); |
|
521 } |
|
522 } |
|
523 CleanupStack::PopAndDestroy(&file); |
|
524 if ( !hadFS ) |
|
525 { |
|
526 aFileServerSession->Close(); |
|
527 delete aFileServerSession; |
|
528 aFileServerSession = NULL; |
|
529 } |
|
530 } |
|
531 |