201 // CPreviouslyInstalledAppsCache::ConstructL |
199 // CPreviouslyInstalledAppsCache::ConstructL |
202 // ----------------------------------------------------------------------- |
200 // ----------------------------------------------------------------------- |
203 // |
201 // |
204 void CPreviouslyInstalledAppsCache::ConstructL() |
202 void CPreviouslyInstalledAppsCache::ConstructL() |
205 { |
203 { |
206 User::LeaveIfError(iFs.Connect()); |
204 User::LeaveIfError(iFs.Connect()); |
207 TInt drive = 0; |
205 TInt drive = 0; |
208 iFs.CharToDrive( |
206 iFs.CharToDrive( |
209 TParsePtrC( PathInfo::PhoneMemoryRootPath() ).Drive()[0], |
207 TParsePtrC( PathInfo::PhoneMemoryRootPath() ).Drive()[0], |
210 drive ); |
208 drive ); |
211 |
209 |
212 iFs.CreatePrivatePath( drive ); |
210 iFs.CreatePrivatePath( drive ); |
213 |
211 |
214 // Read cache file |
212 // Read cache file |
215 TRAP_IGNORE( InitFromCacheFileL() ); |
213 TRAP_IGNORE(InitFromCacheFileL()); |
216 |
214 |
217 TRAPD( err, UpdateAllL() ); |
215 TRAPD( err, UpdateAllL() ); |
218 |
216 if(err == KErrNone) |
219 if( err == KErrNone ) |
|
220 { |
217 { |
221 // If we managed to scan the registry, and update the cache, |
218 // If we managed to scan the registry, and update the cache, flush to disk. |
222 // flush to disk. |
|
223 TRAP_IGNORE(FlushToDiskL()); |
219 TRAP_IGNORE(FlushToDiskL()); |
224 } |
220 } |
225 |
221 |
226 } |
222 } |
227 |
223 |
228 // ----------------------------------------------------------------------- |
224 // ----------------------------------------------------------------------- |
229 // CPreviouslyInstalledAppsCache::InitFromCacheFileL |
225 // CPreviouslyInstalledAppsCache::InitFromCacheFileL |
230 // ----------------------------------------------------------------------- |
226 // ----------------------------------------------------------------------- |
231 // |
227 // |
232 void CPreviouslyInstalledAppsCache::InitFromCacheFileL() |
228 void CPreviouslyInstalledAppsCache::InitFromCacheFileL() |
233 { |
229 { |
234 // Read in existing cache file. |
230 // Read in existing cache file. |
235 RFile cacheFile; |
231 RFile cacheFile; |
236 TInt err = cacheFile.Open( iFs, |
232 TInt err = cacheFile.Open( iFs, |
237 KPreInstalledApps, |
233 KPreInstalledApps, |
238 EFileStream|EFileRead); |
234 EFileStream|EFileRead); |
239 if ( err != KErrNone ) |
235 if ( err != KErrNone ) |
240 { |
236 { |
241 return; // No existing cache file to read. |
237 return; // No existing cache file to read. |
242 } |
238 } |
243 CleanupClosePushL( cacheFile ); |
239 CleanupClosePushL( cacheFile ); |
244 |
240 |
245 // Now read the cache |
241 // Now read the cache |
246 RFileReadStream cacheReadStream( cacheFile ); |
242 RFileReadStream cacheReadStream( cacheFile ); |
247 cacheReadStream.PushL(); |
243 cacheReadStream.PushL(); |
248 |
244 |
249 iPrevPkgUids.Reset(); |
245 iPrevPkgUids.Reset(); |
250 TInt32 count( cacheReadStream.ReadInt32L() ); |
246 TInt32 count( cacheReadStream.ReadInt32L() ); |
251 |
247 |
252 for ( TInt i = 0; i < count; i++ ) |
248 for ( TInt i = 0; i < count; i++ ) |
253 { |
249 { |
254 TUid packageId; |
250 TUid packageId; |
255 packageId.iUid = cacheReadStream.ReadInt32L(); |
251 packageId.iUid = cacheReadStream.ReadInt32L(); |
256 (void)iPrevPkgUids.InsertInSignedKeyOrder( packageId ); |
252 (void)iPrevPkgUids.InsertInSignedKeyOrder( packageId ); |
257 } |
253 } |
258 |
254 |
259 CleanupStack::PopAndDestroy(&cacheReadStream); |
255 CleanupStack::PopAndDestroy(&cacheReadStream); |
260 CleanupStack::PopAndDestroy(&cacheFile); |
256 CleanupStack::PopAndDestroy(&cacheFile); |
261 } |
257 } |
262 |
258 |
263 // ----------------------------------------------------------------------- |
259 // ----------------------------------------------------------------------- |
264 // CPreviouslyInstalledAppsCache::FlushToDiskL |
260 // CPreviouslyInstalledAppsCache::FlushToDiskL |
265 // ----------------------------------------------------------------------- |
261 // ----------------------------------------------------------------------- |
266 // |
262 // |
267 void CPreviouslyInstalledAppsCache::FlushToDiskL() |
263 void CPreviouslyInstalledAppsCache::FlushToDiskL() |
268 { |
264 { |
269 // Write to disk |
265 // Write to disk |
270 RFile cacheFile; |
266 RFile cacheFile; |
271 TInt err = cacheFile.Open( iFs, |
267 TInt err = cacheFile.Open(iFs, KPreInstalledApps, EFileStream|EFileWrite); |
272 KPreInstalledApps, |
268 if(err != KErrNone) |
273 EFileStream|EFileWrite ); |
269 { |
274 if ( err != KErrNone ) |
270 User::LeaveIfError(cacheFile.Create(iFs, KPreInstalledApps, EFileStream|EFileWrite)); |
275 { |
271 } |
276 User::LeaveIfError( cacheFile.Create( iFs, |
272 CleanupClosePushL(cacheFile); |
277 KPreInstalledApps, |
273 |
278 EFileStream|EFileWrite) ); |
274 // Truncate file. |
279 } |
275 User::LeaveIfError(cacheFile.SetSize(0)); |
280 CleanupClosePushL( cacheFile ); |
276 |
281 |
277 // Now write the cache |
282 // Truncate file. |
278 RFileWriteStream cacheWriteStream(cacheFile); |
283 User::LeaveIfError( cacheFile.SetSize(0) ); |
279 cacheWriteStream.PushL(); |
284 |
280 |
285 // Now write the cache |
281 TInt32 count(iPrevPkgUids.Count()); |
286 RFileWriteStream cacheWriteStream( cacheFile ); |
282 cacheWriteStream.WriteInt32L(count); |
287 cacheWriteStream.PushL(); |
283 |
288 |
284 for (TInt i = 0; i < count; i++) |
289 TInt32 count( iPrevPkgUids.Count() ); |
285 { |
290 cacheWriteStream.WriteInt32L(count); |
286 cacheWriteStream.WriteInt32L(iPrevPkgUids[i].iUid); |
291 |
287 } |
292 for ( TInt i = 0; i < count; i++ ) |
288 |
293 { |
289 cacheWriteStream.CommitL(); |
294 cacheWriteStream.WriteInt32L( iPrevPkgUids[i].iUid ); |
290 CleanupStack::PopAndDestroy(&cacheWriteStream); |
295 } |
291 CleanupStack::PopAndDestroy(&cacheFile); |
296 |
|
297 cacheWriteStream.CommitL(); |
|
298 CleanupStack::PopAndDestroy( &cacheWriteStream ); |
|
299 CleanupStack::PopAndDestroy( &cacheFile ); |
|
300 } |
292 } |
301 |
293 |
302 // End of file |
294 // End of file |