appinstaller/AppinstUi/Daemon/Src/installationFailedAppsCache.cpp
changeset 0 ba25891c3a9e
child 25 7333d7932ef7
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2009 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: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <f32file.h>
       
    20 #include <s32file.h>
       
    21 #include <pathinfo.h>
       
    22 
       
    23 #include "sisregistrysession.h"
       
    24 #include "sisregistryentry.h"
       
    25 #include "sisregistrypackage.h"
       
    26 
       
    27 using namespace Swi;
       
    28 
       
    29 #include "installationFailedAppsCache.h"
       
    30 
       
    31 _LIT(KInstFaildeApps, "c:\\private\\10202DCE\\instFailedAppsCache.dat");
       
    32 
       
    33 #include "SWInstDebug.h"
       
    34 
       
    35 // ----------------------------
       
    36 // Borrowed from cleanuputils.h:-
       
    37 /** 
       
    38  * Template class CleanupResetAndDestroy to clean up the array
       
    39  * of implementation information from the cleanup stack.
       
    40  * @released
       
    41  * @publishedPartner
       
    42  *
       
    43  */
       
    44 
       
    45 template <class T>
       
    46 class CleanupResetAndDestroy
       
    47 	{
       
    48 public:
       
    49 	inline static void PushL(T& aRef);
       
    50 private:
       
    51 	static void ResetAndDestroy(TAny *aPtr);
       
    52 	};
       
    53 	
       
    54 template <class T>
       
    55 inline void CleanupResetAndDestroyPushL(T& aRef);
       
    56 
       
    57 template <class T>
       
    58 inline void CleanupResetAndDestroy<T>::PushL(T& aRef)
       
    59 	{
       
    60 	CleanupStack::PushL(TCleanupItem(&ResetAndDestroy,&aRef));
       
    61 	}
       
    62 
       
    63 template <class T>
       
    64 void CleanupResetAndDestroy<T>::ResetAndDestroy(TAny *aPtr)
       
    65 	{
       
    66 	static_cast<T*>(aPtr)->ResetAndDestroy();
       
    67 	}
       
    68 
       
    69 template <class T>
       
    70 inline void CleanupResetAndDestroyPushL(T& aRef)
       
    71 	{
       
    72 	CleanupResetAndDestroy<T>::PushL(aRef);
       
    73 	}
       
    74 
       
    75 // End of code from swi/inc/cleanuputils.h
       
    76 
       
    77 
       
    78 CInstallationFailedAppsCache *CInstallationFailedAppsCache::NewL()
       
    79 	{
       
    80 	FLOG( _L("Daemon: CInstallationFailedAppsCache::NewL") ); 
       
    81 	
       
    82 	CInstallationFailedAppsCache *self = new(ELeave)CInstallationFailedAppsCache;
       
    83 	CleanupStack::PushL(self);
       
    84 	self->ConstructL();
       
    85 	CleanupStack::Pop(self);
       
    86 	return self;
       
    87 	}
       
    88 
       
    89 
       
    90 CInstallationFailedAppsCache::~CInstallationFailedAppsCache()
       
    91 	{
       
    92 	iUidsArray.Reset();
       
    93 	}
       
    94 
       
    95 
       
    96 void CInstallationFailedAppsCache::AddPackageUID( TUid aUid )
       
    97 	{
       
    98 	FLOG( _L("Daemon: CInstallationFailedAppsCache::AddPackageUID") );
       
    99 	
       
   100 	(void)iUidsArray.InsertInSignedKeyOrder( aUid );
       
   101 	// New UID added to array. Let's write cache to disk.
       
   102 	iNewUID = ETrue;		
       
   103 	}
       
   104 
       
   105 
       
   106 TBool CInstallationFailedAppsCache::HasPreviousInstallationFailed( TUid aUid )
       
   107 	{
       
   108 	FLOG( _L("Daemon: CInstallationFailedAppsCache::HasPreviousInstallationFailed") );
       
   109 	
       
   110 	if ( iUidsArray.FindInSignedKeyOrder( aUid ) == KErrNotFound )
       
   111 		{
       
   112 		FLOG( _L("Daemon: UID not found. No previous install attempt") );
       
   113 		return EFalse;
       
   114 		}
       
   115 	
       
   116 	FLOG( _L("Daemon: UID found. Previous install attempt FAILED") );	
       
   117 	return ETrue;
       
   118 	}
       
   119 
       
   120 
       
   121 CInstallationFailedAppsCache::CInstallationFailedAppsCache()
       
   122 	{
       
   123 	}
       
   124 
       
   125 
       
   126 void CInstallationFailedAppsCache::ConstructL()
       
   127 	{
       
   128 	User::LeaveIfError( iFs.Connect() );
       
   129 	TInt drive = 0;
       
   130     iFs.CharToDrive( TParsePtrC( PathInfo::PhoneMemoryRootPath() ).Drive()[0], drive );
       
   131     iFs.CreatePrivatePath( drive );
       
   132     
       
   133     iNewUID = EFalse;
       
   134 
       
   135 	// Read cache file
       
   136 	TRAP_IGNORE( InitFromCacheFileL() );
       
   137 	}
       
   138 
       
   139 
       
   140 void CInstallationFailedAppsCache::InitFromCacheFileL()
       
   141 	{
       
   142 	FLOG( _L("Daemon: CInstallationFailedAppsCache::InitFromCacheFileL") );	
       
   143 	
       
   144 	// Read in existing cache file.
       
   145 	RFile cacheFile;
       
   146 	
       
   147 	TInt err = cacheFile.Open( iFs, KInstFaildeApps, EFileStream|EFileRead );
       
   148 	
       
   149 	if ( err != KErrNone )
       
   150 		{
       
   151 		FLOG( _L("Daemon: No existing cache file to read.") );
       
   152 		return; // No existing cache file to read.
       
   153 		}
       
   154 		
       
   155 	CleanupClosePushL(cacheFile);
       
   156 	
       
   157 	// Now read the cache
       
   158 	RFileReadStream cacheReadStream(cacheFile);
       
   159 	cacheReadStream.PushL();
       
   160 
       
   161 	iUidsArray.Reset();
       
   162 	
       
   163 	TInt32 count( cacheReadStream.ReadInt32L() );	
       
   164 
       
   165 	for ( TInt i = 0; i < count; i++ )
       
   166 		{		
       
   167 		TUid packageId;
       
   168 		packageId.iUid = cacheReadStream.ReadInt32L();
       
   169 		
       
   170 		(void)iUidsArray.InsertInSignedKeyOrder( packageId );
       
   171 		}	
       
   172 	
       
   173 	CleanupStack::PopAndDestroy(&cacheReadStream);
       
   174 	CleanupStack::PopAndDestroy(&cacheFile);
       
   175     }
       
   176 
       
   177 
       
   178 void CInstallationFailedAppsCache::FlushToDiskL()
       
   179 	{
       
   180     FLOG( _L("Daemon: CInstallationFailedAppsCache::FlushToDiskL") );		
       
   181 	
       
   182 	// Write to disk if new UID is added to array. 
       
   183 	if ( iNewUID )
       
   184     	{
       
   185     	FLOG( _L("Daemon: Write cache to disk") );
       
   186     	RFile cacheFile;
       
   187     	TInt err = cacheFile.Open( iFs, KInstFaildeApps, EFileStream|EFileWrite );
       
   188     	
       
   189     	// If cache was not found, create cache file.
       
   190     	if ( err != KErrNone )
       
   191     		{
       
   192     		FLOG( _L("Daemon: Create cache file.") );
       
   193     	    User::LeaveIfError( cacheFile.Create( iFs, KInstFaildeApps, EFileStream|EFileWrite ) );
       
   194     		}
       
   195     	
       
   196     	CleanupClosePushL(cacheFile);
       
   197 
       
   198     	// Truncate file.
       
   199     	User::LeaveIfError( cacheFile.SetSize(0) );
       
   200     	
       
   201     	// Now write the cache 
       
   202     	RFileWriteStream cacheWriteStream( cacheFile );
       
   203     	cacheWriteStream.PushL();
       
   204 
       
   205     	TInt32 count( iUidsArray.Count() );
       
   206     	cacheWriteStream.WriteInt32L( count );
       
   207 
       
   208     	for ( TInt i = 0; i < count; i++ )
       
   209     		{    		
       
   210     		cacheWriteStream.WriteInt32L( iUidsArray[i].iUid );
       
   211     		}	
       
   212     	
       
   213     	cacheWriteStream.CommitL();
       
   214     	FLOG( _L("Daemon: Commit cache file.") );
       
   215     	
       
   216     	CleanupStack::PopAndDestroy(&cacheWriteStream);
       
   217     	CleanupStack::PopAndDestroy(&cacheFile);
       
   218     	
       
   219     	// Ok, UIDs are written to disk, set boolen to false.
       
   220     	iNewUID = EFalse;	    
       
   221     	}
       
   222 	}
       
   223 
       
   224 // End of file