appinstaller/AppinstUi/Daemon/Src/installationFailedAppsCache.cpp
branchRCL_3
changeset 66 8b7f4e561641
parent 65 7333d7932ef7
equal deleted inserted replaced
65:7333d7932ef7 66:8b7f4e561641
    21 #include <pathinfo.h>
    21 #include <pathinfo.h>
    22 
    22 
    23 #include "sisregistrysession.h"
    23 #include "sisregistrysession.h"
    24 #include "sisregistryentry.h"
    24 #include "sisregistryentry.h"
    25 #include "sisregistrypackage.h"
    25 #include "sisregistrypackage.h"
       
    26 
       
    27 using namespace Swi;
       
    28 
    26 #include "installationFailedAppsCache.h"
    29 #include "installationFailedAppsCache.h"
       
    30 
       
    31 _LIT(KInstFaildeApps, "c:\\private\\10202DCE\\instFailedAppsCache.dat");
       
    32 
    27 #include "SWInstDebug.h"
    33 #include "SWInstDebug.h"
    28 
       
    29 using namespace Swi;
       
    30 
       
    31 _LIT(KInstFaildeApps, "c:\\private\\10202DCE\\instFailedAppsCache.dat");
       
    32 
       
    33 
    34 
    34 // ----------------------------
    35 // ----------------------------
    35 // Borrowed from cleanuputils.h:-
    36 // Borrowed from cleanuputils.h:-
    36 /** 
    37 /** 
    37  * Template class CleanupResetAndDestroy to clean up the array
    38  * Template class CleanupResetAndDestroy to clean up the array
    72 	}
    73 	}
    73 
    74 
    74 // End of code from swi/inc/cleanuputils.h
    75 // End of code from swi/inc/cleanuputils.h
    75 
    76 
    76 
    77 
    77 // -----------------------------------------------------------------------
       
    78 // 
       
    79 // -----------------------------------------------------------------------
       
    80 //    
       
    81 CInstallationFailedAppsCache *CInstallationFailedAppsCache::NewL()
    78 CInstallationFailedAppsCache *CInstallationFailedAppsCache::NewL()
    82 	{
    79 	{
    83 	FLOG( _L("Daemon: CInstallationFailedAppsCache::NewL") ); 
    80 	FLOG( _L("Daemon: CInstallationFailedAppsCache::NewL") ); 
    84 	
    81 	
    85 	CInstallationFailedAppsCache *self = new(ELeave)CInstallationFailedAppsCache;
    82 	CInstallationFailedAppsCache *self = new(ELeave)CInstallationFailedAppsCache;
    87 	self->ConstructL();
    84 	self->ConstructL();
    88 	CleanupStack::Pop(self);
    85 	CleanupStack::Pop(self);
    89 	return self;
    86 	return self;
    90 	}
    87 	}
    91 
    88 
    92 // -----------------------------------------------------------------------
    89 
    93 // 
       
    94 // -----------------------------------------------------------------------
       
    95 //   
       
    96 CInstallationFailedAppsCache::~CInstallationFailedAppsCache()
    90 CInstallationFailedAppsCache::~CInstallationFailedAppsCache()
    97 	{
    91 	{
    98 	iUidsArray.Reset();
    92 	iUidsArray.Reset();
    99 	}
    93 	}
   100 
    94 
   101 // -----------------------------------------------------------------------
    95 
   102 // 
       
   103 // -----------------------------------------------------------------------
       
   104 //   
       
   105 void CInstallationFailedAppsCache::AddPackageUID( TUid aUid )
    96 void CInstallationFailedAppsCache::AddPackageUID( TUid aUid )
   106 	{
    97 	{
   107     FLOG( _L("Daemon: CInstallationFailedAppsCache::AddPackageUID") );
    98 	FLOG( _L("Daemon: CInstallationFailedAppsCache::AddPackageUID") );
   108     FLOG_1( _L("Daemon: AddPackageUID: Add UID = 0x%x"), aUid.iUid );
       
   109 	
    99 	
   110 	(void)iUidsArray.InsertInSignedKeyOrder( aUid );
   100 	(void)iUidsArray.InsertInSignedKeyOrder( aUid );
   111 	// New UID added to array. Let's write cache to disk.
   101 	// New UID added to array. Let's write cache to disk.
   112 	iNewUID = ETrue;		
   102 	iNewUID = ETrue;		
   113 	}
   103 	}
   114 
   104 
   115 // -----------------------------------------------------------------------
   105 
   116 // 
   106 TBool CInstallationFailedAppsCache::HasPreviousInstallationFailed( TUid aUid )
   117 // -----------------------------------------------------------------------
   107 	{
   118 //   
   108 	FLOG( _L("Daemon: CInstallationFailedAppsCache::HasPreviousInstallationFailed") );
   119 TBool CInstallationFailedAppsCache::HasPreviousInstallationFailed( 
       
   120         TUid aUid )
       
   121 	{
       
   122 	FLOG( _L("Daemon: FailedAppsCache::HasPreviousInstallationFailed") );
       
   123 	
   109 	
   124 	if ( iUidsArray.FindInSignedKeyOrder( aUid ) == KErrNotFound )
   110 	if ( iUidsArray.FindInSignedKeyOrder( aUid ) == KErrNotFound )
   125 		{
   111 		{
   126 		FLOG( _L("Daemon: UID not found. No previous install attempt") );
   112 		FLOG( _L("Daemon: UID not found. No previous install attempt") );
   127 		return EFalse;
   113 		return EFalse;
   129 	
   115 	
   130 	FLOG( _L("Daemon: UID found. Previous install attempt FAILED") );	
   116 	FLOG( _L("Daemon: UID found. Previous install attempt FAILED") );	
   131 	return ETrue;
   117 	return ETrue;
   132 	}
   118 	}
   133 
   119 
   134 // -----------------------------------------------------------------------
   120 
   135 // 
       
   136 // -----------------------------------------------------------------------
       
   137 //   
       
   138 CInstallationFailedAppsCache::CInstallationFailedAppsCache()
   121 CInstallationFailedAppsCache::CInstallationFailedAppsCache()
   139 	{
   122 	{
   140 	}
   123 	}
   141 
   124 
   142 // -----------------------------------------------------------------------
   125 
   143 // 
       
   144 // -----------------------------------------------------------------------
       
   145 //   
       
   146 void CInstallationFailedAppsCache::ConstructL()
   126 void CInstallationFailedAppsCache::ConstructL()
   147 	{
   127 	{
   148 	User::LeaveIfError( iFs.Connect() );
   128 	User::LeaveIfError( iFs.Connect() );
   149 	TInt drive = 0;
   129 	TInt drive = 0;
   150     iFs.CharToDrive( TParsePtrC( 
   130     iFs.CharToDrive( TParsePtrC( PathInfo::PhoneMemoryRootPath() ).Drive()[0], drive );
   151             PathInfo::PhoneMemoryRootPath() ).Drive()[0], drive );
       
   152     
       
   153     iFs.CreatePrivatePath( drive );
   131     iFs.CreatePrivatePath( drive );
   154     
   132     
   155     iNewUID = EFalse;
   133     iNewUID = EFalse;
   156 
   134 
   157 	// Read cache file
   135 	// Read cache file
   158 	TRAP_IGNORE( InitFromCacheFileL() );
   136 	TRAP_IGNORE( InitFromCacheFileL() );
   159 	}
   137 	}
   160 
   138 
   161 // -----------------------------------------------------------------------
   139 
   162 // 
       
   163 // -----------------------------------------------------------------------
       
   164 //   
       
   165 void CInstallationFailedAppsCache::InitFromCacheFileL()
   140 void CInstallationFailedAppsCache::InitFromCacheFileL()
   166 	{
   141 	{
   167 	FLOG( _L("Daemon: CInstallationFailedAppsCache::InitFromCacheFileL") );	
   142 	FLOG( _L("Daemon: CInstallationFailedAppsCache::InitFromCacheFileL") );	
   168 	
   143 	
   169 	// Read in existing cache file.
   144 	// Read in existing cache file.
   170 	RFile cacheFile;
   145 	RFile cacheFile;
   171 	
   146 	
   172 	TInt err = cacheFile.Open( iFs, 
   147 	TInt err = cacheFile.Open( iFs, KInstFaildeApps, EFileStream|EFileRead );
   173 	                           KInstFaildeApps, 
       
   174 	                           EFileStream|EFileRead );
       
   175 	
   148 	
   176 	if ( err != KErrNone )
   149 	if ( err != KErrNone )
   177 		{
   150 		{
   178 		FLOG( _L("Daemon: No existing cache file to read.") );
   151 		FLOG( _L("Daemon: No existing cache file to read.") );
   179 		return; // No existing cache file to read.
   152 		return; // No existing cache file to read.
   199 	
   172 	
   200 	CleanupStack::PopAndDestroy(&cacheReadStream);
   173 	CleanupStack::PopAndDestroy(&cacheReadStream);
   201 	CleanupStack::PopAndDestroy(&cacheFile);
   174 	CleanupStack::PopAndDestroy(&cacheFile);
   202     }
   175     }
   203 
   176 
   204 // -----------------------------------------------------------------------
   177 
   205 // 
       
   206 // -----------------------------------------------------------------------
       
   207 //   
       
   208 void CInstallationFailedAppsCache::FlushToDiskL()
   178 void CInstallationFailedAppsCache::FlushToDiskL()
   209 	{
   179 	{
   210     FLOG( _L("Daemon: CInstallationFailedAppsCache::FlushToDiskL") );		
   180     FLOG( _L("Daemon: CInstallationFailedAppsCache::FlushToDiskL") );		
   211 	
   181 	
   212 	// Write to disk if new UID is added to array. 
   182 	// Write to disk if new UID is added to array. 
   213 	if ( iNewUID )
   183 	if ( iNewUID )
   214     	{
   184     	{
   215     	FLOG( _L("Daemon: Write cache to disk") );
   185     	FLOG( _L("Daemon: Write cache to disk") );
   216     	RFile cacheFile;
   186     	RFile cacheFile;
   217     	TInt err = cacheFile.Open( iFs, 
   187     	TInt err = cacheFile.Open( iFs, KInstFaildeApps, EFileStream|EFileWrite );
   218     	                           KInstFaildeApps, 
       
   219     	                           EFileStream|EFileWrite );
       
   220     	
   188     	
   221     	// If cache was not found, create cache file.
   189     	// If cache was not found, create cache file.
   222     	if ( err != KErrNone )
   190     	if ( err != KErrNone )
   223     		{
   191     		{
   224     		FLOG( _L("Daemon: Create cache file.") );
   192     		FLOG( _L("Daemon: Create cache file.") );
   225     	    User::LeaveIfError( cacheFile.Create( iFs, 
   193     	    User::LeaveIfError( cacheFile.Create( iFs, KInstFaildeApps, EFileStream|EFileWrite ) );
   226     	                                          KInstFaildeApps, 
       
   227     	                                          EFileStream|EFileWrite ) );
       
   228     		}
   194     		}
   229     	
   195     	
   230     	CleanupClosePushL(cacheFile);
   196     	CleanupClosePushL(cacheFile);
   231 
   197 
   232     	// Truncate file.
   198     	// Truncate file.