|
1 /* |
|
2 * Copyright (c) 2003-2005 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: Implementation of alternator. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CAlternatorImp.h" |
|
22 #include "ChatDebugPrint.h" |
|
23 #include "CCABrandInstallerImp.h" |
|
24 #include <eikenv.h> |
|
25 #include <bautils.h> |
|
26 #include <s32strm.h> // load/save |
|
27 #include <s32file.h> |
|
28 #include <eikapp.h> |
|
29 #include <bautils.h> |
|
30 #include <bldvariant.hrh> |
|
31 #include <e32std.h> |
|
32 #include <badesca.h> |
|
33 |
|
34 |
|
35 // CONSTANTS |
|
36 _LIT( KRsc, ".RSC" ); |
|
37 _LIT( KRscWild, ".R*" ); |
|
38 _LIT( KDirSeparator, "\\" ); |
|
39 _LIT( KRelativeBrandPath, "branding\\" ); |
|
40 |
|
41 // ============================ MEMBER FUNCTIONS =============================== |
|
42 |
|
43 |
|
44 // ----------------------------------------------------------------------------- |
|
45 // CAlternatorImp::CAlternatorImp |
|
46 // C++ default constructor can NOT contain any code, that |
|
47 // might leave. |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 CAlternatorImp::CAlternatorImp() |
|
51 // :iResFiles( 1 ) // usually just one, |
|
52 { |
|
53 } |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // CAlternatorImp::ConstructL |
|
57 // Symbian 2nd phase constructor can leave. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 void CAlternatorImp::ConstructL( const TDesC& aBrandRoot ) |
|
61 { |
|
62 CHAT_DP( D_CHAT_LIT( "CAlternatorImp::ConstructL brand root is:%S" ) , |
|
63 &aBrandRoot ); |
|
64 iBrandRoot = HBufC::NewL( KMaxPath ); |
|
65 TPtr myPtr = iBrandRoot->Des(); |
|
66 myPtr = aBrandRoot; |
|
67 |
|
68 CHAT_DP( D_CHAT_LIT( "CAlternatorImp::ConstructL ourbrand root is:%S" ), |
|
69 &myPtr ); |
|
70 |
|
71 iEikEnv = CEikonEnv::Static(); |
|
72 |
|
73 //Start procedure to install sis installed brands |
|
74 iBrandInstaller = CCABrandInstallerImp::NewL(); |
|
75 if ( !( iBrandInstaller->ImportFolderExistsL() ) ) |
|
76 { |
|
77 iBrandInstaller->CreateImportFolderL(); |
|
78 } |
|
79 if ( iBrandInstaller->IsNewBrandAvailableL() ) |
|
80 { |
|
81 iBrandInstaller->InstallNewBrandL(); |
|
82 } |
|
83 } |
|
84 |
|
85 // ----------------------------------------------------------------------------- |
|
86 // CAlternatorImp::NewL |
|
87 // Two-phased constructor. |
|
88 // ----------------------------------------------------------------------------- |
|
89 // |
|
90 |
|
91 CAlternatorImp* CAlternatorImp::NewL( const TDesC& aBrandRoot ) |
|
92 { |
|
93 CAlternatorImp* self = new( ELeave ) CAlternatorImp(); |
|
94 |
|
95 CleanupStack::PushL( self ); |
|
96 self->ConstructL( aBrandRoot ); |
|
97 CleanupStack::Pop( self ); |
|
98 |
|
99 return self; |
|
100 } |
|
101 |
|
102 // Destructor |
|
103 CAlternatorImp::~CAlternatorImp() |
|
104 { |
|
105 delete iBrandRoot; |
|
106 delete iBrandInstaller; |
|
107 } |
|
108 |
|
109 |
|
110 // constructs current bitmap file full path |
|
111 const TDesC& CAlternatorImp::CurrentBitmapFileL( const TDesC& aModuleId, |
|
112 const TDesC& aAlternative, |
|
113 const TDesC& aBitmapFileName ) |
|
114 { |
|
115 // if the path is not ok, set bitmap path as empty |
|
116 TInt ret( ConstructCompletePathAndCheck( iCurrentBitmap, aModuleId, |
|
117 aAlternative, |
|
118 aBitmapFileName ) ); |
|
119 if ( ret != KErrNone ) |
|
120 { |
|
121 if ( ret == KErrNoMemory ) |
|
122 { |
|
123 User::Leave( ret ); |
|
124 } |
|
125 iCurrentBitmap.Zero(); |
|
126 } |
|
127 CHAT_DP( D_CHAT_LIT( "CAlternatorImp::CurrentBitmapFileL :%S" ), |
|
128 &iCurrentBitmap ); |
|
129 |
|
130 return iCurrentBitmap; |
|
131 } |
|
132 |
|
133 |
|
134 // changes resource |
|
135 TInt CAlternatorImp::ChangeResourceL( const TDesC& aModuleId, |
|
136 const TDesC& aAlternative, |
|
137 const TDesC& aResFileName, |
|
138 TInt& aResOffset ) |
|
139 { |
|
140 TInt err = LoadResourceFileL( aModuleId, aAlternative, aResFileName, |
|
141 aResOffset ); |
|
142 return err; |
|
143 } |
|
144 |
|
145 // changes bitmap file |
|
146 TInt CAlternatorImp::ChangeBitmapFileL( const TDesC& aModuleId, |
|
147 const TDesC& aAlternative, |
|
148 const TDesC& aBitmapFileName ) |
|
149 { |
|
150 // iCurrentBitmap contains the path if ok |
|
151 iCurrentBitmap.Zero(); |
|
152 TInt ret( ConstructCompletePathAndCheck( iCurrentBitmap, aModuleId, |
|
153 aAlternative, aBitmapFileName ) ); |
|
154 if ( ret == KErrNoMemory ) |
|
155 { |
|
156 User::Leave( ret ); |
|
157 } |
|
158 if ( ret != KErrNone ) |
|
159 { |
|
160 return KErrNotFound; |
|
161 } |
|
162 // the new bitmap path is in iCurrentBitmap |
|
163 return KErrNone; |
|
164 } |
|
165 |
|
166 void CAlternatorImp::GetCurrentResourceFileL( const TDesC& aModuleId, |
|
167 const TDesC& aAlternative, |
|
168 const TDesC& aResFileName, |
|
169 TDes& aFullPath ) |
|
170 { |
|
171 TInt ret( ConstructCompletePathAndCheck( aFullPath, aModuleId, |
|
172 aAlternative, aResFileName ) ); |
|
173 if ( ret == KErrNoMemory ) |
|
174 { |
|
175 User::Leave( ret ); |
|
176 } |
|
177 if ( ret != KErrNone ) |
|
178 { |
|
179 aFullPath.Zero(); |
|
180 } |
|
181 |
|
182 CHAT_DP( D_CHAT_LIT( "CAlternatorImp::GetCurrentResourceFileL :%S" ), |
|
183 &aFullPath ); |
|
184 |
|
185 // otherwise the current resource file path is in aFullPath |
|
186 } |
|
187 |
|
188 void CAlternatorImp::SetBrandRoot( const TDesC& aBrandRoot ) |
|
189 { |
|
190 CHAT_DP( D_CHAT_LIT( "CAlternatorImp::SetBrandRoot %S" ), &aBrandRoot ); |
|
191 |
|
192 TPtr myPtr = iBrandRoot->Des(); |
|
193 myPtr = aBrandRoot; |
|
194 } |
|
195 |
|
196 // loads resource file |
|
197 TInt CAlternatorImp::LoadResourceFileL( const TDesC& aModuleId, |
|
198 const TDesC& aAlternative, |
|
199 const TDesC& aResFileName, |
|
200 TInt& aResOffSet ) |
|
201 { |
|
202 |
|
203 TFileName resFilePath; |
|
204 TInt ret( ConstructCompletePathAndCheck( resFilePath, aModuleId, |
|
205 aAlternative, aResFileName ) ); |
|
206 if ( ret == KErrNoMemory ) |
|
207 { |
|
208 User::Leave( ret ); |
|
209 } |
|
210 if ( ret != KErrNone ) |
|
211 { |
|
212 #ifdef _DEBUG |
|
213 RDebug::Print( _L( "path not found" ) ); |
|
214 #endif |
|
215 return KErrNotFound; |
|
216 } |
|
217 |
|
218 TEntry entry; |
|
219 User::LeaveIfError( iEikEnv->FsSession().Entry( resFilePath, entry ) ); |
|
220 TInt fileSize( entry.iSize ); |
|
221 // test if there's enough heap available, this one leaves if not and |
|
222 // resources won't get changed |
|
223 HBufC8* allocTest = HBufC8::NewL( fileSize ); |
|
224 delete allocTest; |
|
225 |
|
226 |
|
227 // if path ok, then make the change, first delete the previous one |
|
228 iEikEnv->DeleteResourceFile( aResOffSet ); |
|
229 |
|
230 RFs& fs = iEikEnv->FsSession(); |
|
231 |
|
232 if ( resFilePath.Length() != 0 ) |
|
233 { |
|
234 BaflUtils::NearestLanguageFile( fs, resFilePath ); |
|
235 } |
|
236 |
|
237 TRAPD( err, aResOffSet = iEikEnv->AddResourceFileL( resFilePath ) ); |
|
238 if ( err == KErrNoMemory ) |
|
239 { |
|
240 User::Leave( KErrNoMemory ); |
|
241 } |
|
242 |
|
243 |
|
244 #ifdef _DEBUG |
|
245 RDebug::Print( _L( "ADDED resource file:" ) ); |
|
246 RDebug::Print( resFilePath ); |
|
247 #endif |
|
248 |
|
249 return err; |
|
250 } |
|
251 |
|
252 |
|
253 TBool CAlternatorImp::IsPathOk( const TDesC& aCheckThis ) const |
|
254 { |
|
255 CHAT_DP( D_CHAT_LIT( "CAlternatorImp::IsPathOk %S" ), &aCheckThis ); |
|
256 |
|
257 return BaflUtils::FileExists( iEikEnv->FsSession(), aCheckThis ); |
|
258 } |
|
259 |
|
260 TInt CAlternatorImp::ConstructCompletePathAndCheck( TDes& aResult, |
|
261 const TDesC& aModuleId, |
|
262 const TDesC& aAlternative, |
|
263 const TDesC& aFileName ) |
|
264 { |
|
265 aResult.Zero(); |
|
266 aResult.Append( *iBrandRoot ); |
|
267 |
|
268 aResult.Append( KRelativeBrandPath() ); |
|
269 aResult.Append( aModuleId ); |
|
270 aResult.Append( KDirSeparator ); |
|
271 aResult.Append( aAlternative ); |
|
272 aResult.Append( KDirSeparator ); |
|
273 |
|
274 TBool resourceFile( EFalse ); |
|
275 TFileName file( aFileName ); |
|
276 |
|
277 TInt rscPos( aFileName.FindC( KRsc ) ); |
|
278 if ( rscPos != KErrNotFound ) |
|
279 { |
|
280 // replace the ".RSC" with ".R*" |
|
281 file.Copy( aFileName.Left( rscPos ) ); |
|
282 file.Append( KRscWild ); |
|
283 resourceFile = ETrue; |
|
284 } |
|
285 else |
|
286 { |
|
287 file.Copy( aFileName ); |
|
288 } |
|
289 |
|
290 CHAT_DP( D_CHAT_LIT( "CAlternatorImp::ConstructCompletePathAndCheck \ |
|
291 trying to find %S%S" ) |
|
292 , &aResult, &file ); |
|
293 |
|
294 // Find the actual file |
|
295 CDir* files = NULL; |
|
296 TFindFile fileFinder( iEikEnv->FsSession() ); |
|
297 TInt err( fileFinder.FindWildByDir( file, aResult, files ) ); |
|
298 delete files; |
|
299 |
|
300 // If file was found, then take the first appearance of it |
|
301 // (order is correct aready) |
|
302 if ( err == KErrNone ) |
|
303 { |
|
304 aResult.Zero(); |
|
305 if ( resourceFile ) |
|
306 { |
|
307 // change the ".R*" back to ".RSC" |
|
308 TParsePtrC parse( fileFinder.File() ); |
|
309 file.Copy( parse.DriveAndPath() ); |
|
310 file.Append( parse.Name() ); |
|
311 file.Append( KRsc ); |
|
312 |
|
313 CHAT_DP( D_CHAT_LIT( "CAlternatorImp::ConstructCompletePathAndCheck \ |
|
314 finding nearest language file for %S" ), &file ); |
|
315 |
|
316 if ( file.Length() != 0 ) |
|
317 { |
|
318 BaflUtils::NearestLanguageFile( iEikEnv->FsSession(), file ); |
|
319 } |
|
320 |
|
321 aResult.Copy( file ); |
|
322 } |
|
323 else |
|
324 { |
|
325 aResult.Append( fileFinder.File() ); |
|
326 } |
|
327 } |
|
328 |
|
329 CHAT_DP( D_CHAT_LIT( "CAlternatorImp::ConstructCompletePathAndCheck \ |
|
330 TFindFile returned %d for %S" ), |
|
331 err, &aResult ); |
|
332 |
|
333 // return was the file found or not |
|
334 return err; |
|
335 } |
|
336 |
|
337 // End of File |