24 #include <StartupItem.hrh> // EStartupItemExPolicyNone |
24 #include <StartupItem.hrh> // EStartupItemExPolicyNone |
25 #include <dscitem.h> // CDscItem |
25 #include <dscitem.h> // CDscItem |
26 #include <swi/sisregistrysession.h> // Swi::RSisRegistrySession |
26 #include <swi/sisregistrysession.h> // Swi::RSisRegistrySession |
27 #include <swi/sisregistrypackage.h> // Swi::CSisRegistryPackage |
27 #include <swi/sisregistrypackage.h> // Swi::CSisRegistryPackage |
28 #include <swi/sisregistryentry.h> // Swi::RSisRegistryEntry |
28 #include <swi/sisregistryentry.h> // Swi::RSisRegistryEntry |
|
29 #include <swi/sistruststatus.h> // Swi::TSisTrustStatus::IsTrusted |
29 |
30 |
30 _LIT( KImport, "import\\" ); |
31 _LIT( KImport, "import\\" ); |
31 _LIT( KDriveAndPathFormat, "%c:%S" ); |
32 _LIT( KDriveAndPathFormat, "%c:%S" ); |
32 _LIT( KResourceFileSpec, "c:*.rsc" ); |
33 _LIT( KResourceFileSpec, "c:*.rsc" ); |
33 _LIT( KExecutableExtension, ".exe" ); |
34 _LIT( KExecutableExtension, ".exe" ); |
308 executableName.Copy( reader.ReadTPtrC() ); |
309 executableName.Copy( reader.ReadTPtrC() ); |
309 TInt recoveryPolicy = reader.ReadUint16(); |
310 TInt recoveryPolicy = reader.ReadUint16(); |
310 |
311 |
311 CleanupStack::PopAndDestroy( buffer ); |
312 CleanupStack::PopAndDestroy( buffer ); |
312 |
313 |
313 if( recoveryPolicy == EStartupItemExPolicyNone ) |
314 if( versionInfo == 0 && recoveryPolicy == EStartupItemExPolicyNone ) |
314 { |
315 { |
315 // PKG files use '!' for drive letters that user can decide at installation time |
316 // PKG files use '!' for drive letters that user can decide at installation time |
316 if( executableName.Length() > 0 && executableName[ 0 ] == '!' ) |
317 if( executableName.Length() > 0 && executableName[ 0 ] == '!' ) |
317 { |
318 { |
318 executableName.Replace( 0, 1, KAsterisk ); |
319 executableName.Replace( 0, 1, KAsterisk ); |
319 |
320 |
320 TFindFile fileFinder( iFs ); |
321 TFindFile fileFinder( iFs ); |
321 CDir* executableDir; |
322 CDir* executableDir; // next FindWildByDir needs AllFiles capability |
322 TInt err = fileFinder.FindWildByDir( executableName, KNullDesC, executableDir ); |
323 TInt err = fileFinder.FindWildByDir( executableName, KNullDesC, executableDir ); |
323 if( !err ) |
324 if( !err ) |
324 { |
325 { |
325 CleanupStack::PushL( executableDir ); |
326 CleanupStack::PushL( executableDir ); |
326 executableName.Replace( 0, 1, fileFinder.File() ); |
327 executableName.Replace( 0, 1, fileFinder.File() ); |
327 CleanupStack::PopAndDestroy( executableDir ); |
328 CleanupStack::PopAndDestroy( executableDir ); |
328 } |
329 } |
329 } |
330 } |
330 |
331 |
331 TEntry entry; |
332 if( IsValidExecutableForStartupL( aResourceFile, executableName ) ) |
332 if( iFs.Entry( executableName, entry ) == KErrNone ) // needs AllFiles capability |
|
333 { |
333 { |
334 aExecutableArray.AppendL( executableName.AllocL() ); |
334 aExecutableArray.AppendL( executableName.AllocL() ); |
335 } |
335 } |
336 } |
336 } |
337 } |
337 } |
338 |
338 |
339 CleanupStack::PopAndDestroy( &resource ); |
339 CleanupStack::PopAndDestroy( &resource ); |
340 } |
340 } |
341 |
341 |
342 // --------------------------------------------------------------------------- |
342 // --------------------------------------------------------------------------- |
|
343 // CStartupListUpdater::IsValidExecutableForStartupL() |
|
344 // --------------------------------------------------------------------------- |
|
345 // |
|
346 TBool CStartupListUpdater::IsValidExecutableForStartupL( const TDesC& aResourceFile, |
|
347 const TDesC& aExecutableName ) |
|
348 { |
|
349 TBool isValid = EFalse; |
|
350 |
|
351 TEntry entry; |
|
352 if( iFs.Entry( aExecutableName, entry ) == KErrNone ) // needs AllFiles capability |
|
353 { |
|
354 isValid = ETrue; |
|
355 |
|
356 // Extract package UID from the resource file name |
|
357 // - allow both "[1234ABCD]" and "1234ABCD" formats |
|
358 // - allow possible "0x" prefix too |
|
359 TUid packageUid = KNullUid; |
|
360 TParsePtrC parse( aResourceFile ); |
|
361 TPtrC parseName = parse.Name(); |
|
362 TInt fileNameLength = parseName.Length(); |
|
363 if( !parse.IsNameWild() && fileNameLength > 0 ) |
|
364 { |
|
365 TPtr fileName( const_cast<TUint16*>( parseName.Ptr() ), |
|
366 fileNameLength, fileNameLength ); |
|
367 |
|
368 if( fileName[ 0 ] == '[' && fileName[ fileNameLength - 1 ] == ']' ) |
|
369 { |
|
370 const TInt KTwoCharsLength = 2; |
|
371 fileNameLength -= KTwoCharsLength; |
|
372 fileName = fileName.Mid( 1, fileNameLength ); |
|
373 } |
|
374 |
|
375 _LIT( KHexPrefix, "0x" ); |
|
376 const TInt KHexPrefixLength = 2; |
|
377 if( fileName.Left( KHexPrefixLength ) == KHexPrefix ) |
|
378 { |
|
379 fileNameLength -= KHexPrefixLength; |
|
380 fileName = fileName.Mid( KHexPrefixLength, fileNameLength ); |
|
381 } |
|
382 |
|
383 TLex lex( fileName ); |
|
384 TUint32 uidValue = 0; |
|
385 TInt lexError = lex.Val( uidValue, EHex ); |
|
386 if( !lexError ) |
|
387 { |
|
388 packageUid.iUid = uidValue; |
|
389 } |
|
390 } |
|
391 |
|
392 // Get package info from RSisRegistry, and check that |
|
393 // - the package contains the resource file |
|
394 // - the package is properly signed |
|
395 if( packageUid != KNullUid ) |
|
396 { |
|
397 Swi::RSisRegistrySession sisRegSession; |
|
398 User::LeaveIfError( sisRegSession.Connect() ); |
|
399 CleanupClosePushL( sisRegSession ); |
|
400 |
|
401 Swi::RSisRegistryEntry package; |
|
402 CleanupClosePushL( package ); |
|
403 TInt openError = package.Open( sisRegSession, packageUid ); |
|
404 if( !openError ) |
|
405 { |
|
406 TBool hasResourceFile = EFalse; |
|
407 |
|
408 RPointerArray<HBufC> files; |
|
409 CleanupResetAndDestroyPushL( files ); |
|
410 package.FilesL( files ); |
|
411 for( TInt index = 0; index < files.Count() && !hasResourceFile; ++index ) |
|
412 { |
|
413 hasResourceFile = ( aResourceFile.CompareF( *files[ index ] ) == 0 ); |
|
414 } |
|
415 |
|
416 if( hasResourceFile && package.TrustStatusL().IsTrusted() ) |
|
417 { |
|
418 isValid = ETrue; |
|
419 } |
|
420 |
|
421 CleanupStack::PopAndDestroy( &files ); |
|
422 } |
|
423 |
|
424 CleanupStack::PopAndDestroy( 2, &sisRegSession ); // package, sisRegSession |
|
425 } |
|
426 } |
|
427 |
|
428 return isValid; |
|
429 } |
|
430 |
|
431 // --------------------------------------------------------------------------- |
343 // CStartupListUpdater::GetInstalledAppsL() |
432 // CStartupListUpdater::GetInstalledAppsL() |
344 // --------------------------------------------------------------------------- |
433 // --------------------------------------------------------------------------- |
345 // |
434 // |
346 void CStartupListUpdater::GetInstalledAppsL( |
435 void CStartupListUpdater::GetInstalledAppsL( |
347 RPointerArray<HBufC>& aInstalledExecutableArray ) |
436 RPointerArray<HBufC>& aInstalledExecutableArray ) |