|
1 /* |
|
2 * Copyright (c) 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: CNcdProviderUtils implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <s32file.h> |
|
20 #include <bautils.h> |
|
21 #include "ncdproviderutils.h" |
|
22 #include "catalogsdebug.h" |
|
23 #include "ncdengineconfigurationimpl.h" |
|
24 #include "ncddeviceinteractionfactory.h" |
|
25 #include "ncddeviceserviceimpl.h" |
|
26 #include "ncdinstallationserviceimpl.h" |
|
27 #include "catalogsutils.h" |
|
28 #include "ncdproviderdefines.h" |
|
29 #include "catalogsstringmanager.h" |
|
30 #include "ncdhttputils.h" |
|
31 |
|
32 #ifdef CATALOGS_BUILD_CONFIG_DEBUG |
|
33 #include "ncdtestconfig.h" |
|
34 _LIT( KTestConfigFile, "c:\\data\\others\\ncdtestnetwork.cfg" ); |
|
35 #endif |
|
36 |
|
37 |
|
38 RFs CNcdProviderUtils::iFs; |
|
39 CNcdEngineConfiguration* CNcdProviderUtils::iConfig = NULL; |
|
40 MNcdDeviceService* CNcdProviderUtils::iDeviceService = NULL; |
|
41 MNcdInstallationService* CNcdProviderUtils::iInstallationService = NULL; |
|
42 |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 // --------------------------------------------------------------------------- |
|
46 // |
|
47 CNcdProviderUtils* CNcdProviderUtils::NewL( const TDesC& aFilename ) |
|
48 { |
|
49 CNcdProviderUtils* self = new( ELeave ) CNcdProviderUtils(); |
|
50 CleanupStack::PushL( self ); |
|
51 self->ConstructL( aFilename ); |
|
52 CleanupStack::Pop( self ); |
|
53 return self; |
|
54 } |
|
55 |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // Destructor |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 CNcdProviderUtils::~CNcdProviderUtils() |
|
62 { |
|
63 delete iConfig; |
|
64 delete iDeviceService; |
|
65 delete iInstallationService; |
|
66 iFs.Close(); |
|
67 CCatalogsStringManager::Delete(); |
|
68 } |
|
69 |
|
70 |
|
71 // --------------------------------------------------------------------------- |
|
72 // File session getter |
|
73 // --------------------------------------------------------------------------- |
|
74 // |
|
75 RFs& CNcdProviderUtils::FileSession() |
|
76 { |
|
77 return iFs; |
|
78 } |
|
79 |
|
80 |
|
81 // --------------------------------------------------------------------------- |
|
82 // Engine configuration getter |
|
83 // --------------------------------------------------------------------------- |
|
84 // |
|
85 MNcdEngineConfiguration& CNcdProviderUtils::EngineConfig() |
|
86 { |
|
87 DASSERT( iConfig ); |
|
88 return *iConfig; |
|
89 } |
|
90 |
|
91 |
|
92 // --------------------------------------------------------------------------- |
|
93 // Installation service getter |
|
94 // --------------------------------------------------------------------------- |
|
95 // |
|
96 MNcdInstallationService& CNcdProviderUtils::InstallationServiceL() |
|
97 { |
|
98 if ( !iInstallationService ) |
|
99 { |
|
100 iInstallationService = |
|
101 NcdDeviceInteractionFactory::CreateInstallationServiceL(); |
|
102 } |
|
103 return *iInstallationService; |
|
104 } |
|
105 |
|
106 |
|
107 // --------------------------------------------------------------------------- |
|
108 // Device service getter |
|
109 // --------------------------------------------------------------------------- |
|
110 // |
|
111 MNcdDeviceService& CNcdProviderUtils::DeviceService() |
|
112 { |
|
113 DASSERT( iDeviceService ); |
|
114 return *iDeviceService; |
|
115 } |
|
116 |
|
117 |
|
118 |
|
119 // --------------------------------------------------------------------------- |
|
120 // Temp path getter |
|
121 // --------------------------------------------------------------------------- |
|
122 // |
|
123 HBufC* CNcdProviderUtils::TempPathLC( const TDesC& aClientId ) |
|
124 { |
|
125 DASSERT( iConfig ); |
|
126 return iConfig->ClientDataPathLC( aClientId, ETrue ); |
|
127 } |
|
128 |
|
129 |
|
130 |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 // --------------------------------------------------------------------------- |
|
134 // |
|
135 void CNcdProviderUtils::ReadDatabaseVersionsL( |
|
136 const TDesC& aRootPath, |
|
137 TUint32& aGeneralVersion, |
|
138 TUint32& aPurchaseHistoryVersion ) |
|
139 { |
|
140 DLTRACEIN(("")); |
|
141 |
|
142 RBuf path; |
|
143 AppendPathsLC( |
|
144 path, |
|
145 aRootPath, |
|
146 NcdProviderDefines::KNcdDatabaseVersionFile ); |
|
147 |
|
148 |
|
149 RFileReadStream stream; |
|
150 CleanupClosePushL( stream ); |
|
151 User::LeaveIfError( stream.Open( FileSession(), |
|
152 path, EFileRead ) ); |
|
153 aGeneralVersion = stream.ReadUint32L(); |
|
154 aPurchaseHistoryVersion = stream.ReadUint32L(); |
|
155 CleanupStack::PopAndDestroy( 2, &path ); // stream, path |
|
156 DLTRACEOUT(("Versions, general: %d, purchase history: %d", |
|
157 aGeneralVersion, aPurchaseHistoryVersion )); |
|
158 } |
|
159 |
|
160 |
|
161 // --------------------------------------------------------------------------- |
|
162 // |
|
163 // --------------------------------------------------------------------------- |
|
164 // |
|
165 void CNcdProviderUtils::WriteDatabaseVersionsL( |
|
166 const TDesC& aRootPath, |
|
167 TUint32 aGeneralVersion, |
|
168 TUint32 aPurchaseHistoryVersion ) |
|
169 { |
|
170 DLTRACEIN(("Writing versions, general: %d, purchase history: %d", |
|
171 aGeneralVersion, aPurchaseHistoryVersion )); |
|
172 |
|
173 RBuf path; |
|
174 |
|
175 AppendPathsLC( |
|
176 path, |
|
177 aRootPath, |
|
178 NcdProviderDefines::KNcdDatabaseVersionFile ); |
|
179 |
|
180 RFileWriteStream stream; |
|
181 CleanupClosePushL( stream ); |
|
182 User::LeaveIfError( stream.Replace( FileSession(), |
|
183 path, EFileWrite ) ); |
|
184 stream.WriteUint32L( aGeneralVersion ); |
|
185 stream.WriteUint32L( aPurchaseHistoryVersion ); |
|
186 CleanupStack::PopAndDestroy( 2, &path ); |
|
187 DLTRACEOUT(("Versions successfully written")); |
|
188 } |
|
189 |
|
190 |
|
191 // --------------------------------------------------------------------------- |
|
192 // |
|
193 // --------------------------------------------------------------------------- |
|
194 // |
|
195 TInt CNcdProviderUtils::UpdateShutdownFileL( |
|
196 const TDesC& aRootPath ) |
|
197 { |
|
198 DLTRACEIN(("")); |
|
199 |
|
200 RBuf path; |
|
201 |
|
202 AppendPathsLC( |
|
203 path, |
|
204 aRootPath, |
|
205 NcdProviderDefines::KNcdProviderShutdownFile ); |
|
206 |
|
207 BaflUtils::EnsurePathExistsL( FileSession(), aRootPath ); |
|
208 |
|
209 // Try to read the value from the file if it exists, otherwise create a |
|
210 // new file. |
|
211 RFile file; |
|
212 CleanupClosePushL( file ); |
|
213 TInt previousStartups = 0; |
|
214 |
|
215 TInt err = file.Open( FileSession(), path, EFileWrite ); |
|
216 if ( err == KErrNone ) |
|
217 { |
|
218 HBufC8* data = ReadFileL( file ); |
|
219 if ( data->Length() ) |
|
220 { |
|
221 previousStartups = Des8ToInt( *data ); |
|
222 DLTRACE(("Previous startups without good shutdown: %d", |
|
223 previousStartups )); |
|
224 } |
|
225 delete data; |
|
226 data = NULL; |
|
227 User::LeaveIfError( file.Seek( ESeekStart, err ) ); |
|
228 } |
|
229 else |
|
230 { |
|
231 DLTRACE(("No shutdown file, creating")); |
|
232 User::LeaveIfError( file.Replace( FileSession(), path, EFileWrite ) ); |
|
233 } |
|
234 |
|
235 // Update new count to the file |
|
236 previousStartups++; |
|
237 HBufC8* newData = IntToDes8LC( previousStartups ); |
|
238 User::LeaveIfError( file.Write( *newData ) ); |
|
239 |
|
240 CleanupStack::PopAndDestroy( 3, &path ); // newData, file, path |
|
241 DLTRACEOUT(("Wrote previousStartups as: %d", previousStartups)); |
|
242 return previousStartups; |
|
243 } |
|
244 |
|
245 |
|
246 // --------------------------------------------------------------------------- |
|
247 // Removes the shutdown file |
|
248 // --------------------------------------------------------------------------- |
|
249 // |
|
250 void CNcdProviderUtils::RemoveShutdownFileL( const TDesC& aRootPath ) |
|
251 { |
|
252 DLTRACEIN(("")); |
|
253 |
|
254 RBuf path; |
|
255 AppendPathsLC( |
|
256 path, |
|
257 aRootPath, |
|
258 NcdProviderDefines::KNcdProviderShutdownFile() ); |
|
259 |
|
260 User::LeaveIfError( BaflUtils::DeleteFile( FileSession(), path ) ); |
|
261 CleanupStack::PopAndDestroy( &path ); |
|
262 } |
|
263 |
|
264 |
|
265 |
|
266 // --------------------------------------------------------------------------- |
|
267 // Checks if the application with the given uid is installed |
|
268 // --------------------------------------------------------------------------- |
|
269 // |
|
270 TNcdApplicationStatus CNcdProviderUtils::IsApplicationInstalledL( |
|
271 const TUid& aUid, const TDesC& aVersion ) |
|
272 { |
|
273 DLTRACEIN(( _L("Uid: %x, version: %S"), aUid.iUid, &aVersion )); |
|
274 |
|
275 TCatalogsVersion version; |
|
276 TRAPD( err, TCatalogsVersion::ConvertL( version, aVersion ) ); |
|
277 LeaveIfNotErrorL( err, KErrArgument, KErrGeneral ); |
|
278 |
|
279 return InstallationServiceL().IsApplicationInstalledL( aUid, version ); |
|
280 } |
|
281 |
|
282 |
|
283 // --------------------------------------------------------------------------- |
|
284 // |
|
285 // --------------------------------------------------------------------------- |
|
286 // |
|
287 TInt CNcdProviderUtils::CompareVersionsL( |
|
288 const TDesC& aLeft, |
|
289 const TDesC& aRight ) |
|
290 { |
|
291 DLTRACEIN(( _L("Left: %S, right: %S"), &aLeft, &aRight )); |
|
292 |
|
293 TCatalogsVersion leftVersion; |
|
294 TCatalogsVersion::ConvertL( leftVersion, aLeft ); |
|
295 |
|
296 TCatalogsVersion rightVersion; |
|
297 TCatalogsVersion::ConvertL( rightVersion, aRight ); |
|
298 |
|
299 if ( leftVersion > rightVersion ) |
|
300 { |
|
301 return 1; |
|
302 } |
|
303 else if ( leftVersion == rightVersion ) |
|
304 { |
|
305 return 0; |
|
306 } |
|
307 return -1; |
|
308 } |
|
309 |
|
310 |
|
311 |
|
312 |
|
313 // --------------------------------------------------------------------------- |
|
314 // Constructor |
|
315 // --------------------------------------------------------------------------- |
|
316 // |
|
317 CNcdProviderUtils::CNcdProviderUtils() |
|
318 { |
|
319 } |
|
320 |
|
321 |
|
322 // --------------------------------------------------------------------------- |
|
323 // |
|
324 // --------------------------------------------------------------------------- |
|
325 // |
|
326 void CNcdProviderUtils::ConstructL( const TDesC& aFilename ) |
|
327 { |
|
328 DLTRACEIN(("")); |
|
329 User::LeaveIfError( iFs.Connect() ); |
|
330 |
|
331 // This creates the string manager to its own static variable |
|
332 CCatalogsStringManager::SetStringManager( |
|
333 CCatalogsStringManager::NewL() ); |
|
334 |
|
335 iDeviceService = NcdDeviceInteractionFactory::CreateDeviceServiceL(); |
|
336 |
|
337 // Read test configuration for device service |
|
338 #ifdef CATALOGS_BUILD_CONFIG_DEBUG |
|
339 |
|
340 TRAP_IGNORE( |
|
341 { |
|
342 // Leaves if the parsing fails for any reason |
|
343 CNcdTestConfig* testConfig = CNcdTestConfig::NewL( |
|
344 FileSession(), KTestConfigFile() ); |
|
345 |
|
346 DLINFO(("Setting test network config")); |
|
347 // Ownership is transferred |
|
348 iDeviceService->SetTestConfig( testConfig ); |
|
349 }); |
|
350 |
|
351 #endif // CATALOGS_BUILD_CONFIG_DEBUG |
|
352 |
|
353 |
|
354 iConfig = CNcdEngineConfiguration::NewL( *iDeviceService ); |
|
355 |
|
356 TRAPD( err, |
|
357 iConfig->ReadConfigurationL( aFilename ) ); |
|
358 if ( err != KErrNone && err != KErrNotFound ) |
|
359 { |
|
360 User::Leave( err ); |
|
361 } |
|
362 } |
|
363 |
|
364 |
|
365 |