localisation/apparchitecture/apserv/apsnnappupdates.cpp
branchSymbian3
changeset 57 b8d18c84f71c
parent 6 c108117318cb
equal deleted inserted replaced
56:aa99f2208aad 57:b8d18c84f71c
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of the License "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     7 //
     8 // Initial Contributors:
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
     9 // Nokia Corporation - initial contribution.
    11 // Contributors:
    11 // Contributors:
    12 //
    12 //
    13 // Description:
    13 // Description:
    14 // Non-Native application registration functionality for the AppArc server session
    14 // Non-Native application registration functionality for the AppArc server session
    15 // 
    15 // 
       
    16 // apsnnappupdates.cpp
    16 //
    17 //
    17 
       
    18 
    18 
    19 #include "apsnnappupdates.h"
    19 #include "apsnnappupdates.h"
    20 
    20 
    21 #include <bautils.h>
    21 #include <bautils.h>
    22 #include <f32file.h>
    22 #include <f32file.h>
    23 #include <s32file.h>
    23 #include <s32file.h>
    24 
    24 
    25 #include "APAID.H"
    25 #include "APAID.H"
    26 #include "APGAPLST.H"
    26 #include "../aplist/aplapplistitem.h"
    27 #include "APSSERV.H"
    27 #include "apsserv.h"
    28 #include "APSSTD.H"
    28 #include "APSSTD.H"
    29 #include "../apfile/aprfndr.h"
    29 #include "../aplist/aplappregfinder.h"
    30 #include "../apgrfx/apprivate.h"
    30 #include "../apgrfx/apprivate.h"
    31 #include "apsnnapps.h"
    31 #include "apsnnapps.h"
    32 
    32 
    33 
    33 
    34 /**************************************************************************************************************
    34 /**************************************************************************************************************
   153 	{
   153 	{
   154 	__ASSERT_DEBUG(iState == EStateNull, Panic(ENonNativeAppsTFileDetailsCreateTempInBadState));
   154 	__ASSERT_DEBUG(iState == EStateNull, Panic(ENonNativeAppsTFileDetailsCreateTempInBadState));
   155 	__ASSERT_DEBUG(iTempPath == KNullDesC, Panic(ENonNativeAppsTFileDetailsCreateTempWithTempPathSet));
   155 	__ASSERT_DEBUG(iTempPath == KNullDesC, Panic(ENonNativeAppsTFileDetailsCreateTempWithTempPathSet));
   156 	RFile file;
   156 	RFile file;
   157 	CleanupClosePushL(file);
   157 	CleanupClosePushL(file);
   158 	// TODO: remove this hack if/when RFile::Temp is fixed by base
   158 	// NOTE: remove this workaround if/when RFile::Temp is fixed by base
   159 	TInt tempErr = KErrAlreadyExists;
   159 	TInt tempErr = KErrAlreadyExists;
   160 	/* RFile::Temp is a bit dodgy, at least on Winscw with the proxy FS */
   160 	/* RFile::Temp is a bit dodgy, at least on Winscw with the proxy FS */
   161 	for(TInt tries = 0; tempErr == KErrAlreadyExists && tries < 50; ++tries)
   161 	for(TInt tries = 0; tempErr == KErrAlreadyExists && tries < 50; ++tries)
   162 		{
   162 		{
   163 		tempErr = file.Temp(aFs, aDir, iTempPath, EFileShareExclusive|EFileStream|EFileWrite);
   163 		tempErr = file.Temp(aFs, aDir, iTempPath, EFileShareExclusive|EFileStream|EFileWrite);
   210 		if(err != KErrNone)
   210 		if(err != KErrNone)
   211 			{
   211 			{
   212 			return err;
   212 			return err;
   213 			}
   213 			}
   214 		}
   214 		}
   215 	//Check if file already exists, if it exists delete it because we might be trying to register an upgrade
   215 	//Check if file already exists, if it exists delete it because we might be trying to register an upgrade 
   216 	if(BaflUtils::FileExists(aFs, iPath))
   216 	if(BaflUtils::FileExists(aFs, iPath)) 
   217 		{
   217     	{ 
   218 		TInt err = BaflUtils::DeleteFile(aFs, iPath);
   218         TInt err = BaflUtils::DeleteFile(aFs, iPath); 
   219 		if(KErrNone != err)
   219         if(KErrNone != err) 
   220 			{
   220         	{ 
   221 			return err;
   221             return err; 
   222 			}
   222             } 
   223 		}
   223 		}
   224 	TInt err = iHandle.Rename(iPath);
   224 	TInt err = iHandle.Rename(iPath);
   225 	if(err != KErrNone)
   225 	if(err != KErrNone)
   226 		{
   226 		{
   227 		return err;
   227 		return err;
   242 	__ASSERT_DEBUG(iPath != KNullDesC, Panic(ENonNativeAppsTFileDetailsRenameToTempWithoutRealPathSet));
   242 	__ASSERT_DEBUG(iPath != KNullDesC, Panic(ENonNativeAppsTFileDetailsRenameToTempWithoutRealPathSet));
   243 	__ASSERT_DEBUG(iTempPath == KNullDesC, Panic(ENonNativeAppsTFileDetailsRenameToTempWithTempPathSet));
   243 	__ASSERT_DEBUG(iTempPath == KNullDesC, Panic(ENonNativeAppsTFileDetailsRenameToTempWithTempPathSet));
   244 	/* create a temp file and delete it to get an unused filename */
   244 	/* create a temp file and delete it to get an unused filename */
   245 	RFile file;
   245 	RFile file;
   246 	CleanupClosePushL(file);
   246 	CleanupClosePushL(file);
   247 	// TODO: remove this hack if/when RFile::Temp is fixed by base
   247 	// NOTE: remove this workaround if/when RFile::Temp is fixed by base
   248 	TInt tempErr = KErrAlreadyExists;
   248 	TInt tempErr = KErrAlreadyExists;
   249 	/* RFile::Temp is a bit dodgy, at least on Winscw with the proxy FS */
   249 	/* RFile::Temp is a bit dodgy, at least on Winscw with the proxy FS */
   250 	for(TInt tries = 0; tempErr == KErrAlreadyExists && tries < 50; ++tries)
   250 	for(TInt tries = 0; tempErr == KErrAlreadyExists && tries < 50; ++tries)
   251 		{
   251 		{
   252 		tempErr = file.Temp(aFs, aDir, iTempPath, EFileShareExclusive|EFileStream|EFileWrite);
   252 		tempErr = file.Temp(aFs, aDir, iTempPath, EFileShareExclusive|EFileStream|EFileWrite);
   704 void CApsRegisterNonNativeApplication::WriteLocalisableResourceFileL(const TDesC8& aData, const TDesC8* aDataPrefix)
   704 void CApsRegisterNonNativeApplication::WriteLocalisableResourceFileL(const TDesC8& aData, const TDesC8* aDataPrefix)
   705 	{
   705 	{
   706 	WriteResourceFileL(iLocalisableResourceFile, aData, aDataPrefix);
   706 	WriteResourceFileL(iLocalisableResourceFile, aData, aDataPrefix);
   707 	}
   707 	}
   708 
   708 
   709 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
   709 //
   710 
   710 
   711 /**
   711 /**
   712 Create a new file in a designated temporary-files directory
   712 Create a new file in a designated temporary-files directory
   713 */
   713 */
   714 void CApsRegisterNonNativeApplication::NewTemporaryFileL(TFileDetails& aFile)
   714 void CApsRegisterNonNativeApplication::NewTemporaryFileL(TFileDetails& aFile)
   780 	CleanupStack::PopAndDestroy(&targetStream);
   780 	CleanupStack::PopAndDestroy(&targetStream);
   781 	}
   781 	}
   782 
   782 
   783 void CApsRegisterNonNativeApplication::DoPerformUpdateL(RApsUpdateLog& aUpdateLog)
   783 void CApsRegisterNonNativeApplication::DoPerformUpdateL(RApsUpdateLog& aUpdateLog)
   784 	{
   784 	{
   785 	HBufC* hDrive = iDrive.AllocL();
   785 	TRAPD(err,aUpdateLog.DrivesAffected().InsertIsqL(iDrive, ECmpFolded));
   786 	TInt err = aUpdateLog.DrivesAffected().InsertInOrder(hDrive, TLinearOrder<HBufC>(CApaAppList::CompareStrings));
   786 	if (err != KErrAlreadyExists) // We silently ignore attempts to insert duplicates
   787 	if(err != KErrNone)
   787 		User::LeaveIfError(err);
   788 		{
       
   789 		delete hDrive;
       
   790 		}
       
   791 
       
   792 	if ((err != KErrNone) &&
       
   793 	    (err != KErrAlreadyExists)) // We silently ignore attempts to insert duplicates
       
   794 		{
       
   795 		User::Leave(err);
       
   796 		}
       
   797 	
   788 	
   798 	RWriteStream& stream = aUpdateLog.LogWriteStream();
   789 	RWriteStream& stream = aUpdateLog.LogWriteStream();
   799 
   790 
   800 	iResourceFile.RenameToRealL(iFs);
   791 	iResourceFile.RenameToRealL(iFs);
   801 
   792 
   812 		{
   803 		{
   813 		iIconFile.RenameToRealL(iFs);
   804 		iIconFile.RenameToRealL(iFs);
   814 		iResourceFile.ExternalizeContinuationL(stream, EIconFileUpdate);
   805 		iResourceFile.ExternalizeContinuationL(stream, EIconFileUpdate);
   815 		}
   806 		}
   816 	
   807 	
   817 	HBufC* hPath = iResourceFile.Path().AllocL();
   808 	TRAP(err,aUpdateLog.NewRegistrationFiles().InsertIsqL(iResourceFile.Path(), ECmpFolded));
   818 	err = aUpdateLog.NewRegistrationFiles().InsertInOrder(hPath, TLinearOrder<HBufC>(CApaAppList::CompareStrings));
   809 	if (err != KErrAlreadyExists) // We silently ignore attempts to insert duplicates
   819 	if(err != KErrNone)
   810 		User::LeaveIfError(err);
   820 		{
       
   821 		delete hPath;
       
   822 		}
       
   823 	
       
   824 	if ((err != KErrNone) &&
       
   825 	    (err != KErrAlreadyExists)) // We silently ignore attempts to insert duplicates
       
   826 		{
       
   827 		User::Leave(err);
       
   828 		}
       
   829 	}
   811 	}
   830 
   812 
   831 void CApsRegisterNonNativeApplication::DoRollbackUpdate(RApsUpdateLog& aUpdateLog)
   813 void CApsRegisterNonNativeApplication::DoRollbackUpdate(RApsUpdateLog& aUpdateLog)
   832 	{
   814 	{
   833 	RWriteStream& stream = aUpdateLog.LogWriteStream();
   815 	RWriteStream& stream = aUpdateLog.LogWriteStream();
   847 	iIconFile.Delete(iFs);
   829 	iIconFile.Delete(iFs);
   848 	iResourceFile.ExternalizeContinuation(stream, EIconFileUpdate);
   830 	iResourceFile.ExternalizeContinuation(stream, EIconFileUpdate);
   849 	}
   831 	}
   850 
   832 
   851 
   833 
   852 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
   834 //
   853 
   835 
   854 void CApsRegisterNonNativeApplication::ExternalizeL(RWriteStream& aStream)
   836 void CApsRegisterNonNativeApplication::ExternalizeL(RWriteStream& aStream)
   855 	{
   837 	{
   856 	/* write our initial state to the log stream */
   838 	/* write our initial state to the log stream */
   857 	aStream.WriteUint32L(iDrive.Length());
   839 	aStream.WriteUint32L(iDrive.Length());
   937 
   919 
   938 /**************************************************************************************************************
   920 /**************************************************************************************************************
   939  * CApsDeregisterNonNativeApplication
   921  * CApsDeregisterNonNativeApplication
   940  **************************************************************************************************************/
   922  **************************************************************************************************************/
   941 
   923 
   942 CApsDeregisterNonNativeApplication* CApsDeregisterNonNativeApplication::NewL(RFs& aFs, CApaAppListServer& aServ, TUid aUid, TState aState)
   924 CApsDeregisterNonNativeApplication* CApsDeregisterNonNativeApplication::NewL(RFs& aFs, CApaAppArcServer& aServ, TUid aUid, TState aState)
   943 	{
   925 	{
   944 	return new(ELeave)CApsDeregisterNonNativeApplication(aFs, aServ, aUid, aState);
   926 	return new(ELeave)CApsDeregisterNonNativeApplication(aFs, aServ, aUid, aState);
   945 	}
   927 	}
   946 
   928 
   947 CApsDeregisterNonNativeApplication::CApsDeregisterNonNativeApplication(RFs& aFs, CApaAppListServer& aServ, TUid aUid, TState aState) :
   929 CApsDeregisterNonNativeApplication::CApsDeregisterNonNativeApplication(RFs& aFs, CApaAppArcServer& aServ, TUid aUid, TState aState) :
   948 		CApsNonNativeApplicationsUpdate(aFs, aUid, aState, EDeregisterApplication),
   930 		CApsNonNativeApplicationsUpdate(aFs, aUid, aState, EDeregisterApplication),
   949 		iServ(aServ)
   931 		iServ(aServ)
   950 	{
   932 	{
   951 	}
   933 	}
   952 
   934 
   953 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
   935 //
   954 
   936 
   955 
   937 
   956 CApaAppData* CApsDeregisterNonNativeApplication::FindAppDataLC(RApsUpdateLog& aUpdateLog)
   938 CApaAppData* CApsDeregisterNonNativeApplication::FindAppDataLC(RApsUpdateLog& aUpdateLog)
   957 	{
   939 	{
   958 	/* search back through the list for a an update concerning the same Uid */
   940 	/* search back through the list for a an update concerning the same Uid */
   984 
   966 
   985 			User::LeaveIfError(iFs.Entry(entry.iFullName,fsEntry));
   967 			User::LeaveIfError(iFs.Entry(entry.iFullName,fsEntry));
   986 			entry.iUidType = fsEntry.iType;
   968 			entry.iUidType = fsEntry.iType;
   987 
   969 
   988 			appData = NULL;
   970 			appData = NULL;
   989 			#ifdef SYMBIAN_APPARC_APPINFO_CACHE
   971 			TRAP_IGNORE(appData = CApaAppData::NewL(entry,iFs));
   990  				TRAP_IGNORE(appData = CApaAppData::NewL(entry,iFs));
       
   991  			#else
       
   992  				{
       
   993  				// find the default icons (.mbm file) for applications, wrt current locale
       
   994  				TFileName* tempFileName = NULL;
       
   995  				tempFileName->Append(KDefaultAppIconMbm);
       
   996  				BaflUtils::NearestLanguageFile(iFs, *tempFileName); 
       
   997  				HBufC* defaultAppIcon = tempFileName->AllocL();
       
   998  				TRAP_IGNORE(appData = CApaAppData::NewL(entry,iFs,*defaultAppIcon));
       
   999  				}
       
  1000  			#endif //SYMBIAN_APPARC_APPINFO_CACHE
       
  1001 			if(appData != NULL)
   972 			if(appData != NULL)
  1002 				{
   973 				{
  1003 				CleanupStack::PushL(appData);
   974 				CleanupStack::PushL(appData);
  1004 				return appData;
   975 				return appData;
  1005 				}
   976 				}
  1012 	 */
   983 	 */
  1013 	CApaAppRegFinder* regFinder = CApaAppRegFinder::NewLC(iFs);
   984 	CApaAppRegFinder* regFinder = CApaAppRegFinder::NewLC(iFs);
  1014 	TBool found = EFalse;
   985 	TBool found = EFalse;
  1015 	TApaAppEntry appEntry;
   986 	TApaAppEntry appEntry;
  1016 
   987 
  1017 	regFinder->FindAllAppsL();
   988 	regFinder->FindAllAppsL(CApaAppRegFinder::EScanAllDrives);
  1018 	RPointerArray<HBufC>& forcedRegs = aUpdateLog.NewRegistrationFiles();
   989 	const CDesCArray& forcedRegs = aUpdateLog.NewRegistrationFiles();
  1019 
   990 
  1020 	while(regFinder->NextL(appEntry,forcedRegs))
   991 	while(regFinder->NextL(appEntry, forcedRegs))
  1021 		{
   992 		{
  1022 		if (appEntry.iUidType[2] == Uid())
   993 		if (appEntry.iUidType[2] == Uid())
  1023 			{
   994 			{
  1024 			found = ETrue;
   995 			found = ETrue;
  1025 			break;
   996 			break;
  1027 		}
   998 		}
  1028 	CleanupStack::PopAndDestroy(regFinder);
   999 	CleanupStack::PopAndDestroy(regFinder);
  1029 
  1000 
  1030 	if(found)
  1001 	if(found)
  1031 		{
  1002 		{
  1032 		#ifdef SYMBIAN_APPARC_APPINFO_CACHE
  1003 		appData = CApaAppData::NewL(appEntry, iFs);
  1033  			appData = CApaAppData::NewL(appEntry, iFs);
       
  1034  		#else
       
  1035 			{
       
  1036  			// find the default icons (.mbm file) for applications, wrt current locale
       
  1037  			TFileName* tempFileName = NULL;
       
  1038  			tempFileName->Append(KDefaultAppIconMbm);
       
  1039  			BaflUtils::NearestLanguageFile(iFs, *tempFileName); 
       
  1040  			HBufC* defaultAppIcon = tempFileName->AllocL();
       
  1041  			appData = CApaAppData::NewL(appEntry, iFs,*defaultAppIcon);	
       
  1042  			}
       
  1043  		#endif //SYMBIAN_APPARC_APPINFO_CACHE 
       
  1044 		CleanupStack::PushL(appData);
  1004 		CleanupStack::PushL(appData);
  1045 		return appData;
  1005 		return appData;
  1046 		}
  1006 		}
  1047 
  1007 
  1048 	CleanupStack::PushL(static_cast<CApaAppData*>(NULL));
  1008 	CleanupStack::PushL(static_cast<CApaAppData*>(NULL));
  1058 		{
  1018 		{
  1059 		// should really never happen
  1019 		// should really never happen
  1060 		User::Leave(KErrPathNotFound);
  1020 		User::Leave(KErrPathNotFound);
  1061 		}
  1021 		}
  1062 	TDriveName drive(parse.Drive());
  1022 	TDriveName drive(parse.Drive());
  1063 
  1023 	TRAPD(err, aUpdateLog.DrivesAffected().InsertIsqL(drive, ECmpFolded));
  1064 	HBufC* hDrive = drive.AllocL();
  1024 	if (err != KErrAlreadyExists) // We silently ignore attempts to insert duplicates
  1065 	TInt err = aUpdateLog.DrivesAffected().InsertInOrder(hDrive, TLinearOrder<HBufC>(CApaAppList::CompareStrings));
  1025 		User::LeaveIfError(err);
  1066 	if(err != KErrNone)
  1026 
  1067 		{
  1027 	const TFileName path(TemporaryFilePathL(drive));
  1068 		delete hDrive;
  1028 	aFile.RenameToTemporaryL(iFs, path);
  1069 		}
       
  1070 	
       
  1071 	TFileName path(TemporaryFilePathL(drive));
       
  1072 
       
  1073 	aFile.RenameToTemporaryL(iFs,path);
       
  1074 	}
  1029 	}
  1075 
  1030 
  1076 void CApsDeregisterNonNativeApplication::DoPerformUpdateL(RApsUpdateLog& aUpdateLog)
  1031 void CApsDeregisterNonNativeApplication::DoPerformUpdateL(RApsUpdateLog& aUpdateLog)
  1077 	{
  1032 	{
  1078 	CApaAppData* appData = FindAppDataLC(aUpdateLog);
  1033 	CApaAppData* appData = FindAppDataLC(aUpdateLog);