|
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: Minimal resourcereader for reading resources without CONE |
|
15 |
|
16 * facilities |
|
17 |
|
18 * |
|
19 */ |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 #include <bautils.h> |
|
25 |
|
26 #include <data_caging_path_literals.hrh> // KDC_RESOURCE_FILES_DIR |
|
27 |
|
28 |
|
29 |
|
30 #include "caminimalresourcereader.h" |
|
31 |
|
32 |
|
33 |
|
34 // ======== MEMBER FUNCTIONS ======== |
|
35 |
|
36 |
|
37 |
|
38 // --------------------------------------------------------------------------- |
|
39 |
|
40 // Constructor |
|
41 |
|
42 // --------------------------------------------------------------------------- |
|
43 |
|
44 // |
|
45 |
|
46 CAMinimalResourceReader::CAMinimalResourceReader() |
|
47 |
|
48 { |
|
49 |
|
50 } |
|
51 |
|
52 |
|
53 |
|
54 // --------------------------------------------------------------------------- |
|
55 |
|
56 // CAMinimalResourceReader::ConstructL() |
|
57 |
|
58 // --------------------------------------------------------------------------- |
|
59 |
|
60 // |
|
61 |
|
62 void CAMinimalResourceReader::ConstructL() |
|
63 |
|
64 { |
|
65 |
|
66 } |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 // --------------------------------------------------------------------------- |
|
73 |
|
74 // CAMinimalResourceReader::NewL() |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 |
|
78 // |
|
79 |
|
80 CAMinimalResourceReader* CAMinimalResourceReader::NewL() |
|
81 |
|
82 { |
|
83 |
|
84 CAMinimalResourceReader* self = CAMinimalResourceReader::NewLC(); |
|
85 |
|
86 CleanupStack::Pop( self ); |
|
87 |
|
88 return self; |
|
89 |
|
90 } |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 // --------------------------------------------------------------------------- |
|
97 |
|
98 // CAMinimalResourceReader::NewLC() |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 |
|
102 // |
|
103 |
|
104 CAMinimalResourceReader* CAMinimalResourceReader::NewLC() |
|
105 |
|
106 { |
|
107 |
|
108 CAMinimalResourceReader* self = new( ELeave ) CAMinimalResourceReader; |
|
109 |
|
110 CleanupStack::PushL( self ); |
|
111 |
|
112 self->ConstructL(); |
|
113 |
|
114 return self; |
|
115 |
|
116 } |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 |
|
124 // Destructor |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 |
|
128 // |
|
129 |
|
130 CAMinimalResourceReader::~CAMinimalResourceReader() |
|
131 |
|
132 { |
|
133 |
|
134 Release(); |
|
135 |
|
136 } |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 // ----------------------------------------------------------------------------- |
|
143 |
|
144 // CAMinimalResourceReader::ReadResourceLC() |
|
145 |
|
146 // ----------------------------------------------------------------------------- |
|
147 |
|
148 // |
|
149 |
|
150 HBufC* CAMinimalResourceReader::ReadTextResourceL( |
|
151 |
|
152 TInt aTextResourceId ) |
|
153 |
|
154 { |
|
155 |
|
156 // Own resource reader for UIP plug-in environment |
|
157 |
|
158 // (no CONE facilities available) |
|
159 |
|
160 |
|
161 |
|
162 //resource texts are hold in TBUFs |
|
163 |
|
164 //TBUF == "A utility struct that holds one non-zero-terminated string." |
|
165 |
|
166 //==> no lead bytes in resource string |
|
167 |
|
168 |
|
169 |
|
170 TInt plainResourceId = 0x00000fff & aTextResourceId; // Remove offset from id |
|
171 |
|
172 HBufC8* rawDataBuf = iResourceFile.AllocReadLC( plainResourceId ); |
|
173 |
|
174 |
|
175 |
|
176 //raw data buffer is actually unicode text ==> treat it so |
|
177 |
|
178 TPtrC16 rawData( ( TUint16* ) rawDataBuf->Ptr(), |
|
179 |
|
180 rawDataBuf->Length() / 2 ); |
|
181 |
|
182 |
|
183 |
|
184 HBufC16* resourceData = rawData.AllocL(); |
|
185 |
|
186 CleanupStack::PopAndDestroy( rawDataBuf ); //rawDataBuf |
|
187 |
|
188 |
|
189 |
|
190 return resourceData; |
|
191 |
|
192 } |
|
193 |
|
194 |
|
195 |
|
196 // ----------------------------------------------------------------------------- |
|
197 |
|
198 // CAMinimalResourceReader::OpenResourceFileLC() |
|
199 |
|
200 // ----------------------------------------------------------------------------- |
|
201 |
|
202 // |
|
203 |
|
204 void CAMinimalResourceReader::OpenResourceFileL( |
|
205 |
|
206 TDesC& aResourceName ) |
|
207 |
|
208 { |
|
209 |
|
210 TFileName resourceFileName; |
|
211 |
|
212 iRFs.Close(); |
|
213 |
|
214 User::LeaveIfError( iRFs.Connect() ); |
|
215 |
|
216 NearestForCurrentLanguage( resourceFileName, aResourceName ); |
|
217 |
|
218 iResourceFile.OpenL( iRFs, resourceFileName ); |
|
219 |
|
220 iResourceFile.ConfirmSignatureL(); |
|
221 |
|
222 } |
|
223 |
|
224 |
|
225 |
|
226 // ----------------------------------------------------------------------------- |
|
227 |
|
228 // CAMinimalResourceReader::Release() |
|
229 |
|
230 // ----------------------------------------------------------------------------- |
|
231 |
|
232 // |
|
233 |
|
234 void CAMinimalResourceReader::Release() |
|
235 |
|
236 { |
|
237 |
|
238 iRFs.Close(); |
|
239 |
|
240 iResourceFile.Close(); |
|
241 |
|
242 } |
|
243 |
|
244 |
|
245 |
|
246 // ----------------------------------------------------------------------------- |
|
247 |
|
248 // CAMinimalResourceReader::NearestForCurrentLanguage() |
|
249 |
|
250 // ----------------------------------------------------------------------------- |
|
251 |
|
252 // |
|
253 |
|
254 void CAMinimalResourceReader::NearestForCurrentLanguage( |
|
255 |
|
256 TFileName& aName, const TDesC& aResourceFile ) |
|
257 |
|
258 { |
|
259 |
|
260 aName.Zero(); |
|
261 |
|
262 { |
|
263 |
|
264 //artificial variable scope to ease the stack usage |
|
265 |
|
266 TFileName drivePath; |
|
267 |
|
268 Dll::FileName( drivePath ); |
|
269 |
|
270 aName.Append( TParsePtrC( drivePath ).Drive() ); |
|
271 |
|
272 aName.Append( KDC_RESOURCE_FILES_DIR() ); |
|
273 |
|
274 aName.Append( aResourceFile ); |
|
275 |
|
276 } |
|
277 |
|
278 |
|
279 |
|
280 if ( aName.Length() > 0 ) |
|
281 |
|
282 { |
|
283 |
|
284 // when baflutils gets an empty string, it returns "C:", |
|
285 |
|
286 // which breaks things |
|
287 |
|
288 BaflUtils::NearestLanguageFile( iRFs, aName ); |
|
289 |
|
290 } |
|
291 |
|
292 } |
|
293 |
|
294 |
|
295 |
|
296 // End of file |
|
297 |