|
1 /* |
|
2 * Copyright (c) 2010 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: Library to handle resource loading when |
|
15 * CCoeEnv is not available. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include <barsread.h> |
|
21 #include <bautils.h> |
|
22 #include "basepluginresourceloader.h" |
|
23 |
|
24 EXPORT_C CResourceLoader* CResourceLoader::NewL( const TDesC& aName ) |
|
25 { |
|
26 CResourceLoader* temp = new( ELeave ) CResourceLoader(); |
|
27 CleanupStack::PushL( temp ); |
|
28 temp->ConstructL( aName ); |
|
29 CleanupStack::Pop( temp ); |
|
30 return temp; |
|
31 } |
|
32 |
|
33 CResourceLoader::CResourceLoader() |
|
34 { |
|
35 } |
|
36 |
|
37 void CResourceLoader::ConstructL( const TDesC& aFilename ) |
|
38 { |
|
39 User::LeaveIfError( iFs.Connect() ); |
|
40 TFileName aFile(aFilename); |
|
41 BaflUtils::NearestLanguageFile( iFs, aFile ); |
|
42 iResFile.OpenL( iFs, aFile ); |
|
43 iResFile.ConfirmSignatureL(); |
|
44 } |
|
45 |
|
46 EXPORT_C CResourceLoader::~CResourceLoader() |
|
47 { |
|
48 iResFile.Close(); |
|
49 iFs.Close(); |
|
50 } |
|
51 |
|
52 EXPORT_C RFs& CResourceLoader::Fs() |
|
53 { |
|
54 return iFs; |
|
55 } |
|
56 |
|
57 EXPORT_C HBufC* CResourceLoader::LoadLC(TInt aResourceId) |
|
58 { |
|
59 TResourceReader reader; |
|
60 HBufC8* readBuffer = CreateResourceReaderLC( reader, aResourceId ); |
|
61 TPtrC textdata = reader.ReadTPtrC(); |
|
62 |
|
63 HBufC16* textBuffer = HBufC16::NewL( textdata.Length() ); |
|
64 *textBuffer = textdata; |
|
65 CleanupStack::PopAndDestroy(readBuffer); |
|
66 CleanupStack::PushL( textBuffer ); |
|
67 return textBuffer; |
|
68 } |
|
69 |
|
70 EXPORT_C HBufC8* CResourceLoader::CreateResourceReaderLC(TResourceReader& aReader,TInt aResourceId) const |
|
71 { |
|
72 HBufC8* readBuffer = iResFile.AllocReadLC( aResourceId ); |
|
73 aReader.SetBuffer( readBuffer ); |
|
74 return readBuffer; |
|
75 } |
|
76 |