secureswitools/swisistools/source/interpretsislib/sisregistry.cpp
changeset 76 f36d4ce8961e
parent 60 245df5276b97
equal deleted inserted replaced
72:a0dc14075813 76:f36d4ce8961e
   550 
   550 
   551 
   551 
   552 void SisRegistry::RemoveEntry(const TUint32 aUid, const std::wstring& aPackageName, const std::wstring& aVendorName)
   552 void SisRegistry::RemoveEntry(const TUint32 aUid, const std::wstring& aPackageName, const std::wstring& aVendorName)
   553     {
   553     {
   554 	if(iParamList.RegistryVersionExists())
   554 	if(iParamList.RegistryVersionExists())
   555 	{
   555 		{
   556 	EntryMap::iterator it = iEntries.find(aUid);
   556 		EntryMap::iterator it = iEntries.find(aUid);
   557 	
   557 	
   558 	while(it != iEntries.end())
   558 		while(it != iEntries.end())
   559 	    {
   559 	    	{
   560 		if (aUid == it->first && !wcscmp(aPackageName.c_str(), it->second->GetPackageName().c_str()) && aVendorName == it->second->GetVendorName() )
   560 			if (aUid == it->first && !wcscmp(aPackageName.c_str(), it->second->GetPackageName().c_str()) && aVendorName == it->second->GetVendorName() )
   561 			{
   561 				{
   562 			LINFO(L"Removing package \"" << it->second->GetPackageName() 
   562 				LINFO(L"Removing package \"" << it->second->GetPackageName() 
   563 					<< L"\" prior to re-installation");
   563 						<< L"\" prior to re-installation");
   564 
   564 
   565 			// Remove .reg file
   565 				// Remove .reg file
   566 			std::wstring registryPath = it->second->GetRegistryDir( iParamList.SystemDrivePath() );
   566 				std::wstring registryPath = it->second->GetRegistryDir( iParamList.SystemDrivePath() );
   567 			RemoveFile(registryPath + StringUtils::BuildSisRegistryFileName( it->second->GetIndex() ));
   567 				RemoveFile(registryPath + StringUtils::BuildSisRegistryFileName( it->second->GetIndex() ));
   568 			
   568 				
   569 			// Remove .ctl file
   569 				// Remove .ctl file
   570 			int drive = tolower(it->second->GetSelectedDrive());
   570 				int drive = tolower(it->second->GetSelectedDrive());
   571 			std::wstring localTargetPath = iConfigManager.GetLocalDrivePath(drive);
   571 				std::wstring localTargetPath = iConfigManager.GetLocalDrivePath(drive);
   572 			registryPath = it->second->GetRegistryDir( localTargetPath );
   572 				registryPath = it->second->GetRegistryDir( localTargetPath );
   573 			RemoveFile(registryPath + StringUtils::BuildControllerFileName( it->second->GetIndex(), 0 ));
   573 				RemoveFile(registryPath + StringUtils::BuildControllerFileName( it->second->GetIndex(), 0 ));
   574 			
   574 				
   575 			// Remove the installed files for this SisRegistryObject
   575 				// Remove the installed files for this SisRegistryObject
   576 			const FileDescriptions& files = it->second->GetFileDescriptions();
   576 				const FileDescriptions& files = it->second->GetFileDescriptions();
   577 
   577 
   578 			RemoveInstalledFiles(files, localTargetPath);
   578 				RemoveInstalledFiles(files, localTargetPath);
   579 
   579 
   580 			// Clean up the SisRegistryObject
   580 				// Clean up the SisRegistryObject
   581 			delete it->second;
   581 				delete it->second;
   582 			iEntries.erase(it);
   582 				iEntries.erase(it);
   583 
   583 
   584 			return;
   584 				return;
   585 			}
   585 				}
   586 		++it;
   586 			++it;
   587 	    }
   587 	    	}
   588     }
   588     	}
   589 	#ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   589 	#ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   590 	else
   590 	else
   591 		{
   591 		{
   592 
   592 
   593 		// the vendor name here is the unique vendore name
   593 		// the vendor name here is the unique vendore name
   613 		iDbHelper->RemoveEntry(componentId);
   613 		iDbHelper->RemoveEntry(componentId);
   614 
   614 
   615 		}
   615 		}
   616 	#endif // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   616 	#endif // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   617     }
   617     }
       
   618 
   618 void  SisRegistry::RemovePkg(const TUint32& aUid, bool aSkipRomStub)
   619 void  SisRegistry::RemovePkg(const TUint32& aUid, bool aSkipRomStub)
   619     {
   620     {
   620 	if(iParamList.RegistryVersionExists())
   621 	if(iParamList.RegistryVersionExists())
   621     	{
   622     	{
   622 		RemovePkgLegacy(aUid,aSkipRomStub);
   623 		RemovePkgLegacy(aUid,aSkipRomStub);
   724     std::wstring ret = StringUtils::MakePathFromSID( aDrivePath + L"/sys/install/sisregistry/", aUid );
   725     std::wstring ret = StringUtils::MakePathFromSID( aDrivePath + L"/sys/install/sisregistry/", aUid );
   725 	return ret;
   726 	return ret;
   726 	}
   727 	}
   727 
   728 
   728 void SisRegistry::RemoveInstalledFiles(const FileDescriptions& aFileDes, std::wstring& aLocalPath)
   729 void SisRegistry::RemoveInstalledFiles(const FileDescriptions& aFileDes, std::wstring& aLocalPath)
   729 {
   730 	{
   730 	FileDescriptions::const_iterator curr = aFileDes.begin();
   731 	FileDescriptions::const_iterator curr = aFileDes.begin();
   731 	FileDescriptions::const_iterator end  = aFileDes.end();
   732 	FileDescriptions::const_iterator end  = aFileDes.end();
   732 
   733 
   733 	for ( ; curr != end ; ++curr)
   734 	for ( ; curr != end ; ++curr)
   734 	{
   735 		{
   735 		std::wstring target((*curr)->GetTarget());
   736 		std::wstring target((*curr)->GetTarget());
   736 	
   737 	
   737 		ConvertToLocalPath(target, aLocalPath);
   738 		ConvertToLocalPath(target, aLocalPath);
   738 		RemoveFile(target);
   739 		RemoveFile(target);
   739 		RemoveHashForFile(target, iParamList.SystemDriveLetter(), iParamList.SystemDrivePath());
   740 		RemoveHashForFile(target, iParamList.SystemDriveLetter(), iParamList.SystemDrivePath());
   740 	}
   741 		}
   741 }
   742 	}
   742 
   743 
   743 
   744 
   744 void SisRegistry::AddRegistryEntry( const SisFile& aSis, const InstallableFiles& aFiles,
   745 void SisRegistry::AddRegistryEntry( const SisFile& aSis, const InstallableFiles& aFiles,
   745 								   const InstallSISFile& aInstallSISFile )
   746 								   const InstallSISFile& aInstallSISFile )
   746     {
   747     {
   766 		// to be removed and then readded based on the updated registry object which is 
   767 		// to be removed and then readded based on the updated registry object which is 
   767 		// in memory. In case of file based registry update this is done is a separate
   768 		// in memory. In case of file based registry update this is done is a separate
   768 		// way, it reads the existing registry entry and store it in memory, and updates the same 
   769 		// way, it reads the existing registry entry and store it in memory, and updates the same 
   769 		// entry in memory and then over-writes the old registry entry with the update entry.
   770 		// entry in memory and then over-writes the old registry entry with the update entry.
   770 		TInt32 componentId = iDbHelper->GetComponentId(obj->GetUid(), obj->GetInstallType() );
   771 		TInt32 componentId = iDbHelper->GetComponentId(obj->GetUid(), obj->GetInstallType() );
       
   772 
   771 		if(componentId != DbHelper::Absent)
   773 		if(componentId != DbHelper::Absent)
   772 			{
   774 			{
       
   775 			std::wstring strStubFile = iDbHelper->GetStubFileName(componentId);
       
   776 			if(strStubFile.length())
       
   777 				{
       
   778 				obj->SetStubFileName(strStubFile);
       
   779 				}
       
   780 			
   773 			iDbHelper->RemoveEntry(componentId);
   781 			iDbHelper->RemoveEntry(componentId);
   774 			}
   782 			}
       
   783 
   775 		obj->SetValidationStatus(iParamList.OriginVerificationStatus());
   784 		obj->SetValidationStatus(iParamList.OriginVerificationStatus());
   776 		GenerateDbRegistryEntry(*obj, iParamList.OriginVerificationStatus());
   785 		GenerateDbRegistryEntry(*obj, iParamList.OriginVerificationStatus());
   777 		}
   786 		}
   778 	#endif // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   787 	#endif // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   779 	}
   788 	}
   780 
   789 
   781 void SisRegistry::UpdateRegistryEntry(const SisFile& aSis,
   790 void SisRegistry::UpdateRegistryEntry(const SisFile& aSis,
   782 		const InstallableFiles& aFiles,	const InstallSISFile& aInstallSISFile)
   791 		const InstallableFiles& aFiles,	const InstallSISFile& aInstallSISFile)
   783 {
   792 	{
   784 	TUint32 pkg = aSis.GetPackageUid();
   793 	TUint32 pkg = aSis.GetPackageUid();
   785 
   794 
   786 	SisRegistryObject* obj = GetRegistryObjectPtr(pkg);
   795 	SisRegistryObject* obj = GetRegistryObjectPtr(pkg);
   787 	obj->UpgradeEntry(aSis, aFiles, aInstallSISFile.iTargetDrive, aInstallSISFile.iSUFlag, aInstallSISFile.iNonRemovable, iConfigManager);
   796 	obj->UpgradeEntry(aSis, aFiles, aInstallSISFile.iTargetDrive, aInstallSISFile.iSUFlag, aInstallSISFile.iNonRemovable, iConfigManager);
   788 
   797 
   791 	#ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   800 	#ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   792 	
   801 	
   793 	if(!iParamList.RegistryVersionExists())
   802 	if(!iParamList.RegistryVersionExists())
   794 		{
   803 		{
   795 		TUint32 componentId = iDbHelper->GetComponentId(pkg);
   804 		TUint32 componentId = iDbHelper->GetComponentId(pkg);
       
   805 		std::wstring strStubFile = iDbHelper->GetStubFileName(componentId);
       
   806 		if(strStubFile.length())
       
   807 			{
       
   808 			obj->SetStubFileName(strStubFile);
       
   809 			}
       
   810 		
   796 		// remove the application from database
   811 		// remove the application from database
   797 		iDbHelper->RemoveEntry(componentId);
   812 		iDbHelper->RemoveEntry(componentId);
   798 
   813 
   799 	    obj->SetValidationStatus(iParamList.OriginVerificationStatus());
   814 	    obj->SetValidationStatus(iParamList.OriginVerificationStatus());
   800 		GenerateDbRegistryEntry(*obj, iParamList.OriginVerificationStatus());
   815 		GenerateDbRegistryEntry(*obj, iParamList.OriginVerificationStatus());
   801 		}
   816 		}
   802 
   817 
   803 	#endif //SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   818 	#endif //SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   804 }
   819 	}
   805 	
   820 	
   806 const SisRegistryObject* SisRegistry::OwningPackage( const std::wstring& aFilename, TUint32& aUid ) const
   821 const SisRegistryObject* SisRegistry::OwningPackage( const std::wstring& aFilename, TUint32& aUid ) const
   807 {
   822 	{
   808 	if(iParamList.RegistryVersionExists())
   823 	if(iParamList.RegistryVersionExists())
   809 		{
   824 		{
   810 	// Loop through iEntries, then loop through file desc for spec UID, then return the obj
   825 		// Loop through iEntries, then loop through file desc for spec UID, then return the obj
   811 	for (EntryMap::const_iterator curr = iEntries.begin() ;
   826 		for (EntryMap::const_iterator curr = iEntries.begin() ;
   812 		 curr != iEntries.end() ;
   827 			 curr != iEntries.end() ;
   813 		 ++curr)
   828 			 ++curr)
   814 		{
   829 			{
   815 			 // Get the file descriptions
   830 			 // Get the file descriptions
   816 			 if (curr->second->GetFile(aFilename) != 0)
   831 			 if (curr->second->GetFile(aFilename) != 0)
   817 			 {
   832 				 {
   818 				 aUid = curr->first;
   833 				 aUid = curr->first;
   819 				 return curr->second;
   834 				 return curr->second;
   820 			 }
   835 				 }
   821 		}
   836 			}
   822 		}
   837 		}
   823 	#ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   838 	#ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   824 	else
   839 	else
   825 		{
   840 		{
   826 		aUid = iDbHelper->GetUidFromFileName(aFilename);
   841 		aUid = iDbHelper->GetUidFromFileName(aFilename);
   880 			{
   895 			{
   881 			// Has already been upgraded
   896 			// Has already been upgraded
   882 			continue;
   897 			continue;
   883 			}
   898 			}
   884 
   899 
       
   900 		std::wstring stubFileName = L"z:";
       
   901 		stubFileName.append(KPathToRomStubs);
       
   902 		stubFileName.append(*curr);
       
   903 
   885 		SisRegistryObject* aObj = new SisRegistryObject(*sisController, iRomManager,
   904 		SisRegistryObject* aObj = new SisRegistryObject(*sisController, iRomManager,
   886 														iParamList.RegistryMajorVersion(), 
   905 														iParamList.RegistryMajorVersion(), 
   887 														iParamList.RegistryMinorVersion(), 
   906 														iParamList.RegistryMinorVersion(), 
   888 														iConfigManager);
   907 														iConfigManager, stubFileName);
   889 		GenerateStubRegistry(aObj,sisController.get());	
   908 		GenerateStubRegistry(aObj,sisController.get());	
   890 		    
   909 		    
   891 		} // for
   910 		} // for
   892     }
   911     }
   893 
   912 
  1153 	return NULL;
  1172 	return NULL;
  1154 	}
  1173 	}
  1155 
  1174 
  1156 
  1175 
  1157 CSISController* SisRegistry::GetStubControllerInDir( const std::wstring& aDirectory, const TUint32 aUid)
  1176 CSISController* SisRegistry::GetStubControllerInDir( const std::wstring& aDirectory, const TUint32 aUid)
  1158 {
  1177 	{
  1159     // Make sure the directory name is properly terminated.
  1178     // Make sure the directory name is properly terminated.
  1160     std::wstring basePath = StringUtils::EnsureDirectoryTerminated( aDirectory );
  1179     std::wstring basePath = StringUtils::EnsureDirectoryTerminated( aDirectory );
  1161 
  1180 
  1162 	std::list<std::wstring> stubDirs;
  1181 	std::list<std::wstring> stubDirs;
  1163 	GetDirContents( basePath, stubDirs );
  1182 	GetDirContents( basePath, stubDirs );
  1164 
  1183 
  1165 	std::list<std::wstring>::iterator curr;
  1184 	std::list<std::wstring>::iterator curr;
  1166 	for (curr = stubDirs.begin(); curr != stubDirs.end() ; ++curr)
  1185 	for (curr = stubDirs.begin(); curr != stubDirs.end() ; ++curr)
  1167 	{
  1186 		{
  1168 		std::wstring stubPath ( basePath + *curr );
  1187 		std::wstring stubPath ( basePath + *curr );
  1169 		int dotIndex = stubPath.rfind(L".");
  1188 		int dotIndex = stubPath.rfind(L".");
  1170 		if(dotIndex == std::wstring::npos)
  1189 		if(dotIndex == std::wstring::npos)
  1171 			continue;
  1190 			continue;
  1172 		
  1191 		
  1181         
  1200         
  1182 		if (!sisController)
  1201 		if (!sisController)
  1183 			continue;
  1202 			continue;
  1184 		
  1203 		
  1185 		if (sisController->UID1() == aUid)
  1204 		if (sisController->UID1() == aUid)
  1186 		{
  1205 			{
  1187 			return sisController;
  1206 			return sisController;
  1188 		}
  1207 			}
  1189 		delete sisController;	
  1208 		delete sisController;	
  1190 	}
  1209 		}
  1191 	return NULL;
  1210 	return NULL;
  1192 }
  1211 	}
  1193 
  1212 
  1194 
  1213 
  1195 CSISController* SisRegistry::ReadStubController( const wchar_t* aFileName )
  1214 CSISController* SisRegistry::ReadStubController( const wchar_t* aFileName )
  1196 	{
  1215 	{
  1197 	const bool isSisFile = CSISContents::IsSisFile(aFileName);
  1216 	const bool isSisFile = CSISContents::IsSisFile(aFileName);
  1401 		}
  1420 		}
  1402 	}
  1421 	}
  1403 
  1422 
  1404 
  1423 
  1405 int SisRegistry::GetAugmentationsNumber(TUint32 aUid)
  1424 int SisRegistry::GetAugmentationsNumber(TUint32 aUid)
  1406 {
  1425 	{
  1407 	int num = 0;
  1426 	int num = 0;
  1408 	if(iParamList.RegistryVersionExists())
  1427 	if(iParamList.RegistryVersionExists())
  1409 		{
  1428 		{
  1410 	EntryMap::const_iterator x = iEntries.begin();
  1429 		EntryMap::const_iterator x = iEntries.begin();
  1411 		
  1430 			
  1412 	for (;x != iEntries.end(); ++x)
  1431 		for (;x != iEntries.end(); ++x)
  1413 	    {
  1432 		    {
  1414 		if (x->first == aUid && x->second->GetIndex() != 0 )
  1433 			if (x->first == aUid && x->second->GetIndex() != 0 )
  1415 			++num;
  1434 				++num;
  1416 	    }
  1435 		    }
  1417 		}
  1436 		}
  1418 	#ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
  1437 	#ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
  1419 	else
  1438 	else
  1420 		{
  1439 		{
  1421 		TInt32 componentId = iDbHelper->GetComponentId(aUid);
  1440 		TInt32 componentId = iDbHelper->GetComponentId(aUid);
  1423 		if( index != DbHelper::Absent )
  1442 		if( index != DbHelper::Absent )
  1424 			num = ++index;
  1443 			num = ++index;
  1425 		}
  1444 		}
  1426 	#endif //SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
  1445 	#endif //SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
  1427 	return num;
  1446 	return num;
  1428 }
  1447 	}
       
  1448 
  1429 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
  1449 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
  1430 
  1450 
  1431 std::wstring SisRegistry::FormatVersionToString( const Version& aVersion )
  1451 std::wstring SisRegistry::FormatVersionToString( const Version& aVersion )
  1432 	{
  1452 	{
  1433 	std::wstringstream versionText;
  1453 	std::wstringstream versionText;
  1495 	int err = remove(tmpFileName);
  1515 	int err = remove(tmpFileName);
  1496 	if(err != 0)
  1516 	if(err != 0)
  1497 		LERROR(L"Temporary file removal failed.");
  1517 		LERROR(L"Temporary file removal failed.");
  1498 
  1518 
  1499 	if(error != 0)
  1519 	if(error != 0)
  1500 	{
  1520 		{
  1501 		std::string err = "Scrtool failed to upload the database registry entry.";
  1521 		std::string err = "Scrtool failed to upload the database registry entry.";
  1502 		LERROR(L"Scrtool failed to upload the database registry entry.");
  1522 		LERROR(L"Scrtool failed to upload the database registry entry.");
  1503 		throw InterpretSisError(err, DATABASE_UPDATE_FAILED);
  1523 		throw InterpretSisError(err, DATABASE_UPDATE_FAILED);
  1504 	}
  1524 		}
  1505 	}
  1525 	}
  1506 
  1526 
  1507 std::string SisRegistry::GetDbPath()
  1527 std::string SisRegistry::GetDbPath()
  1508 	{
  1528 	{
  1509 	if	( 
  1529 	if	( 
  1516 		#else
  1536 		#else
  1517 		return wstring2string(iParamList.SystemDrivePath()) + "/sys/install/scr/scr.db";
  1537 		return wstring2string(iParamList.SystemDrivePath()) + "/sys/install/scr/scr.db";
  1518 		#endif
  1538 		#endif
  1519 		}
  1539 		}
  1520 	#ifndef __TOOLS2_LINUX__
  1540 	#ifndef __TOOLS2_LINUX__
  1521 	return wstring2string(iParamList.RomDrivePath()) + "\\sys\\install\\scr\\provisioned\\scr.db";
  1541 		return wstring2string(iParamList.RomDrivePath()) + "\\sys\\install\\scr\\provisioned\\scr.db";
  1522 	#else
  1542 	#else
  1523 	    return wstring2string(iParamList.RomDrivePath()) + "/sys/install/scr/provisioned/scr.db";
  1543 	    return wstring2string(iParamList.RomDrivePath()) + "/sys/install/scr/provisioned/scr.db";
  1524 	#endif
  1544 	#endif
  1525 	
  1545 	
  1526 	}
  1546 	}
  1543 
  1563 
  1544 std::wstring SisRegistry::GetGlobalId( TUint32 aUid , TInt aInstallType, std::wstring aPackageName)
  1564 std::wstring SisRegistry::GetGlobalId( TUint32 aUid , TInt aInstallType, std::wstring aPackageName)
  1545 	{
  1565 	{
  1546 	wchar_t textGlobalId[20];
  1566 	wchar_t textGlobalId[20];
  1547 	
  1567 	
  1548 #ifdef _MSC_VER
  1568 	#ifdef _MSC_VER
  1549 		swprintf(textGlobalId,L"%08x",aUid);
  1569 		swprintf(textGlobalId,L"%08x",aUid);
  1550 #else		
  1570 	#else		
  1551 		swprintf(textGlobalId,20,L"%08x",aUid);
  1571 		swprintf(textGlobalId,20,L"%08x",aUid);
  1552 #endif
  1572 	#endif
  1553 		
  1573 		
  1554 
  1574 
  1555 	std::wstring globalId = textGlobalId;
  1575 	std::wstring globalId = textGlobalId;
  1556 	
  1576 	
  1557 	if( aInstallType == CSISInfo::EInstAugmentation || aInstallType == CSISInfo::EInstPreInstalledPatch )
  1577 	if( aInstallType == CSISInfo::EInstAugmentation || aInstallType == CSISInfo::EInstPreInstalledPatch )
  1665 		}
  1685 		}
  1666 	}
  1686 	}
  1667 
  1687 
  1668 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
  1688 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
  1669 void SisRegistry::BackupCtl(TUint32 aUid)
  1689 void SisRegistry::BackupCtl(TUint32 aUid)
  1670 {
  1690 	{
  1671 	std::list<std::wstring> regDirFiles;
  1691 	std::list<std::wstring> regDirFiles;
  1672 	std::wstring path = GetRegistryDir( iParamList.SystemDrivePath(), aUid );
  1692 	std::wstring path = GetRegistryDir( iParamList.SystemDrivePath(), aUid );
  1673     GetDirContents(path, regDirFiles);
  1693     GetDirContents(path, regDirFiles);
  1674 	std::list<std::wstring>::iterator currFile = regDirFiles.begin();
  1694 	std::list<std::wstring>::iterator currFile = regDirFiles.begin();
  1675 
  1695 
  1676 	std::wstring  path1 = FixPathDelimiterstap(path);
  1696 	std::wstring  path1 = FixPathDelimiterstap(path);
  1677 	// Backup all .ctl files in the system drive for this package
  1697 	// Backup all .ctl files in the system drive for this package
  1678 	while (currFile != regDirFiles.end())
  1698 	while (currFile != regDirFiles.end())
  1679 	{
  1699 		{
  1680 		if (*currFile != L"." && *currFile != L"..")
  1700 		if (*currFile != L"." && *currFile != L"..")
  1681 	    {
  1701 	   	 	{
  1682 			std::string ifile = wstring2string(path1 +*currFile);
  1702 			std::string ifile = wstring2string(path1 +*currFile);
  1683 			std::string ibackupfile(ifile);
  1703 			std::string ibackupfile(ifile);
  1684 			ibackupfile.append("_backup");
  1704 			ibackupfile.append("_backup");
  1685 
  1705 
  1686 			int err=FileCopyA(ifile.c_str(),ibackupfile.c_str(),0);
  1706 			int err=FileCopyA(ifile.c_str(),ibackupfile.c_str(),0);
  1687 			if (err != 0)
  1707 			if (err != 0)
  1688 				LERROR(L"Failed to Backup .ctl ");
  1708 				LERROR(L"Failed to Backup .ctl ");
  1689 		}
  1709 			}
  1690 		++currFile;
  1710 			++currFile;
  1691     }
  1711     	}
  1692 }
  1712 	}
  1693 
  1713 
  1694 void SisRegistry::RestoreCtl(TUint32 aUid, TBool& aBackupFlag)
  1714 void SisRegistry::RestoreCtl(TUint32 aUid, TBool& aBackupFlag)
  1695 {
  1715 	{
  1696 	std::list<std::wstring> regDirFiles;
  1716 	std::list<std::wstring> regDirFiles;
  1697 	std::wstring path = GetRegistryDir( iParamList.SystemDrivePath(), aUid );
  1717 	std::wstring path = GetRegistryDir( iParamList.SystemDrivePath(), aUid );
  1698     GetDirContents(path, regDirFiles);
  1718     GetDirContents(path, regDirFiles);
  1699 	std::list<std::wstring>::iterator currFile = regDirFiles.begin();
  1719 	std::list<std::wstring>::iterator currFile = regDirFiles.begin();
  1700 
  1720 
  1701 	// Restore all .ctl files in the system drive for this package
  1721 	// Restore all .ctl files in the system drive for this package
  1702 	while (currFile != regDirFiles.end())
  1722 	while (currFile != regDirFiles.end())
  1703 	{
  1723 		{
  1704 		if (*currFile != L"." && *currFile != L"..")
  1724 		if (*currFile != L"." && *currFile != L"..")
  1705 	    {
  1725 	    	{
  1706 			if(aBackupFlag)
  1726 			if(aBackupFlag)
  1707 			{
  1727 				{
  1708 				int pos =0;
  1728 				int pos =0;
  1709 				if((pos = currFile->find(L".ctl_backup", 0)) == std::wstring::npos)
  1729 				if((pos = currFile->find(L".ctl_backup", 0)) == std::wstring::npos)
  1710 				{
  1730 					{
  1711 					std::string ifile = wstring2string(path +*currFile);
  1731 					std::string ifile = wstring2string(path +*currFile);
  1712 					std::string ibackupfile(ifile);
  1732 					std::string ibackupfile(ifile);
  1713 					ibackupfile.append("_backup");
  1733 					ibackupfile.append("_backup");
  1714 
  1734 
  1715 					RemoveFile(path + *currFile);
  1735 					RemoveFile(path + *currFile);
  1716 				 	int err = FileMoveA(ibackupfile.c_str(),ifile.c_str());
  1736 				 	int err = FileMoveA(ibackupfile.c_str(),ifile.c_str());
  1717 					if (err != 0)
  1737 					if (err != 0)
  1718 						LERROR(L"Failed to Restore .ctl ");
  1738 						LERROR(L"Failed to Restore .ctl ");
       
  1739 					}
  1719 				}
  1740 				}
  1720 			}
       
  1721 			else
  1741 			else
  1722 			{
  1742 				{
  1723 				RemoveFile(path + *currFile);
  1743 				RemoveFile(path + *currFile);
  1724 			}
  1744 				}
  1725 		}
  1745 			}
  1726 		++currFile;
  1746 			++currFile;
  1727     }
  1747     	}
  1728 }
  1748 	}
  1729 
  1749 
  1730 void SisRegistry::RemoveCtlBackup(TUint32 aUid)
  1750 void SisRegistry::RemoveCtlBackup(TUint32 aUid)
  1731 {
  1751 	{
  1732 	std::list<std::wstring> regDirFiles;
  1752 	std::list<std::wstring> regDirFiles;
  1733 	std::wstring path = GetRegistryDir( iParamList.SystemDrivePath(), aUid );
  1753 	std::wstring path = GetRegistryDir( iParamList.SystemDrivePath(), aUid );
  1734     GetDirContents(path, regDirFiles);
  1754     GetDirContents(path, regDirFiles);
  1735 	std::list<std::wstring>::iterator currFile = regDirFiles.begin();
  1755 	std::list<std::wstring>::iterator currFile = regDirFiles.begin();
  1736 	
  1756 	
  1737 	// Remove all .ctl backup files in the system drive for this package
  1757 	// Remove all .ctl backup files in the system drive for this package
  1738 	while (currFile != regDirFiles.end())
  1758 	while (currFile != regDirFiles.end())
  1739 	{
  1759 		{
  1740 		if (*currFile != L"." && *currFile != L"..")
  1760 		if (*currFile != L"." && *currFile != L"..")
  1741 	    {
  1761 	   		{
  1742 			std::wstring ifile(path +*currFile);
  1762 			std::wstring ifile(path +*currFile);
  1743 			ifile.append(L"_backup");
  1763 			ifile.append(L"_backup");
  1744 			
  1764 			
  1745 			if (FileExists(ifile))
  1765 			if (FileExists(ifile))
  1746 				RemoveFile(ifile);
  1766 				RemoveFile(ifile);
  1747 		}
  1767 			}
  1748 		++currFile;
  1768 			++currFile;
  1749     }
  1769     	}
  1750 }
  1770 	}
  1751 #endif
  1771 #endif
  1752 
  1772 
  1753 TUint32 SisRegistry::GetUid(TUint32 aSid) const
  1773 TUint32 SisRegistry::GetUid(TUint32 aSid) const
  1754 	{
  1774 	{
  1755 	return iDbHelper->GetUid(aSid);
  1775 	return iDbHelper->GetUid(aSid);
  1789 	AddApplicationRegistrationInfoL(component, aSisRegistryObject.GetFileDescriptions(), aSisRegistryObject.GetInRom());
  1809 	AddApplicationRegistrationInfoL(component, aSisRegistryObject.GetFileDescriptions(), aSisRegistryObject.GetInRom());
  1790 	#endif //SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
  1810 	#endif //SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
  1791 	
  1811 	
  1792 	// inROM
  1812 	// inROM
  1793 	if(DbConstants::KDefaultIsInRom != aSisRegistryObject.GetInRom())
  1813 	if(DbConstants::KDefaultIsInRom != aSisRegistryObject.GetInRom())
  1794 		AddComponentProperty(component, DbConstants::CompInRom, aSisRegistryObject.GetInRom(), IGNORE_FORMATTING );
  1814 		AddComponentProperty(component, DbConstants::CompInRom, aSisRegistryObject.GetInRom(), IGNORE_FORMATTING);
  1795 
  1815 
  1796 	// isSigned
  1816 	// isSigned
  1797    	if(DbConstants::KDefaultIsSigned != aSisRegistryObject.GetSigned()) 
  1817    	if(DbConstants::KDefaultIsSigned != aSisRegistryObject.GetSigned()) 
  1798 		AddComponentProperty(component, DbConstants::CompIsSigned, aSisRegistryObject.GetSigned(), IGNORE_FORMATTING);
  1818 		AddComponentProperty(component, DbConstants::CompIsSigned, aSisRegistryObject.GetSigned(), IGNORE_FORMATTING);
  1799 
  1819 
  1805 	if(DbConstants::KDefaultIsDeletablePreInstalled != aSisRegistryObject.GetPreInstalled())
  1825 	if(DbConstants::KDefaultIsDeletablePreInstalled != aSisRegistryObject.GetPreInstalled())
  1806 		AddComponentProperty(component, DbConstants::CompDeletablePreinstalled, aSisRegistryObject.GetPreInstalled(), IGNORE_FORMATTING);
  1826 		AddComponentProperty(component, DbConstants::CompDeletablePreinstalled, aSisRegistryObject.GetPreInstalled(), IGNORE_FORMATTING);
  1807 
  1827 
  1808 	// iTrust
  1828 	// iTrust
  1809 	if(DbConstants::KDefaultTrustValue != aSisRegistryObject.GetTrust())
  1829 	if(DbConstants::KDefaultTrustValue != aSisRegistryObject.GetTrust())
  1810 		AddComponentProperty(component, DbConstants::CompTrust, aSisRegistryObject.GetTrust(), IGNORE_FORMATTING );
  1830 		AddComponentProperty(component, DbConstants::CompTrust, aSisRegistryObject.GetTrust(), IGNORE_FORMATTING);
  1811 	
  1831 	
  1812 	// iRemoveWithLastDependent
  1832 	// iRemoveWithLastDependent
  1813 	if(DbConstants::KDefaultRemoveWithLastDependent != aSisRegistryObject.GetRemoveWithLastDependent())
  1833 	if(DbConstants::KDefaultRemoveWithLastDependent != aSisRegistryObject.GetRemoveWithLastDependent())
  1814 		AddComponentProperty(component, DbConstants::CompIsRemoveWithLastDependent, aSisRegistryObject.GetRemoveWithLastDependent(), IGNORE_FORMATTING );
  1834 		AddComponentProperty(component, DbConstants::CompIsRemoveWithLastDependent, aSisRegistryObject.GetRemoveWithLastDependent(), IGNORE_FORMATTING);
  1815 
  1835 
  1816 	// iTrustTimeStamp will be deprecated
  1836 	// iTrustTimeStamp will be deprecated
  1817 	// 64 bit value
  1837 	// 64 bit value
  1818 	std::wstring strTimeStamp = Utils::Int64ToWideString(aSisRegistryObject.GetTrustTimeStamp());
  1838 	std::wstring strTimeStamp = Utils::Int64ToWideString(aSisRegistryObject.GetTrustTimeStamp());
  1819 	AddComponentProperty(component, DbConstants::CompTrustTimeStamp, strTimeStamp, IGNORE_FORMATTING, false );
  1839 	AddComponentProperty(component, DbConstants::CompTrustTimeStamp, strTimeStamp, IGNORE_FORMATTING, false);
  1820 
  1840 
       
  1841 	std::wstring strStubFileName = aSisRegistryObject.GetStubFileName();
       
  1842 	if(strStubFileName.length())
       
  1843 		{
       
  1844 		AddComponentProperty(component, DbConstants::CompStubFileName, strStubFileName, IGNORE_FORMATTING, false);
       
  1845 		}
  1821 	// iTrustStatus
  1846 	// iTrustStatus
  1822 	AddTrustStatus(component, aSisRegistryObject.GetTrustStatus() );
  1847 	AddTrustStatus(component, aSisRegistryObject.GetTrustStatus());
  1823 
  1848 
  1824 	// installChainIndices
  1849 	// installChainIndices
  1825 	AddInstallChainIndices(component, aSisRegistryObject.GetInstallChainIndices() );
  1850 	AddInstallChainIndices(component, aSisRegistryObject.GetInstallChainIndices());
  1826 
  1851 
  1827 	// iIsRemovable
  1852 	// iIsRemovable
  1828 	if(aSisRegistryObject.GetIsRemovable() )
  1853 	if(aSisRegistryObject.GetIsRemovable())
  1829 		{
  1854 		{
  1830 		component.iComponentDetails.iIsRemovable = 1;
  1855 		component.iComponentDetails.iIsRemovable = 1;
  1831 		}
  1856 		}
  1832 	else
  1857 	else
  1833 		{
  1858 		{
  1834 		component.iComponentDetails.iIsRemovable = 0;
  1859 		component.iComponentDetails.iIsRemovable = 0;
  1835 		}
  1860 		}
  1836 
  1861 
  1837 	// iIsHidden
  1862 	// iIsHidden
  1838 	if(aSisRegistryObject.GetIsHidden() )
  1863 	if(aSisRegistryObject.GetIsHidden())
  1839 		{
  1864 		{
  1840 		component.iComponentDetails.iIsHidden = 1;
  1865 		component.iComponentDetails.iIsHidden = 1;
  1841 		}
  1866 		}
  1842 	else
  1867 	else
  1843 		{
  1868 		{
  2102 	}
  2127 	}
  2103 
  2128 
  2104 
  2129 
  2105 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
  2130 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
  2106 void SisRegistry::AddApplicationRegistrationInfoL(XmlDetails::TScrPreProvisionDetail::TComponent& aComponent, const std::vector<FileDescription*>& aFileDescription, int aInRom )
  2131 void SisRegistry::AddApplicationRegistrationInfoL(XmlDetails::TScrPreProvisionDetail::TComponent& aComponent, const std::vector<FileDescription*>& aFileDescription, int aInRom )
  2107 {
  2132 	{
  2108 	std::vector<FileDescription*>::const_iterator filedesIter;
  2133 	std::vector<FileDescription*>::const_iterator filedesIter;
  2109 	std::wstring iLocalFile;
  2134 	std::wstring iLocalFile;
  2110 	std::string RegistrationFileName;
  2135 	std::string RegistrationFileName;
  2111 	
  2136 	
  2112 	//Find Registration File from list of filelist
  2137 	//Find Registration File from list of filelist
  2113 	for(filedesIter = aFileDescription.begin() ; filedesIter != aFileDescription.end(); ++filedesIter)
  2138 	for(filedesIter = aFileDescription.begin() ; filedesIter != aFileDescription.end(); ++filedesIter)
  2114 	{
  2139 		{
  2115 		// if it has wild card characters then donot process. Continue.
  2140 		// if it has wild card characters then donot process. Continue.
  2116 		if( IsFileWideCard((*filedesIter)->GetLocalFile()) )
  2141 		if( IsFileWideCard((*filedesIter)->GetLocalFile()) )
  2117 		{
  2142 			{
  2118 			continue;
  2143 			continue;
  2119 		}
  2144 			}
  2120 
  2145 
  2121 		iLocalFile = (*filedesIter)->GetLocalFile();
  2146 		iLocalFile = (*filedesIter)->GetLocalFile();
  2122 		RegistrationFileName = wstring2string(iLocalFile);
  2147 		RegistrationFileName = wstring2string(iLocalFile);
  2123 
  2148 
  2124 		std::string iRomPath = wstring2string(iParamList.RomDrivePath());
  2149 		std::string iRomPath = wstring2string(iParamList.RomDrivePath());
  2125 		if(aInRom)
  2150 		if(aInRom)
  2126 		{
  2151 			{
  2127 			std::string localpath = FullNameWithoutDrive(RegistrationFileName);
  2152 			std::string localpath = FullNameWithoutDrive(RegistrationFileName);
  2128 			RegistrationFileName = iRomPath + localpath;
  2153 			RegistrationFileName = iRomPath + localpath;
  2129 		}
  2154 			}
  2130 
  2155 
  2131 		size_t found=RegistrationFileName.rfind(".rsc");
  2156 		size_t found=RegistrationFileName.rfind(".rsc");
  2132 		if(found==string::npos)
  2157 		if(found==string::npos)
  2133 			continue;
  2158 			continue;
  2134 
  2159 
  2153 			folder = RegistrationFileName; 
  2178 			folder = RegistrationFileName; 
  2154 
  2179 
  2155 		CAppInfoReader* appInfoReader = NULL;
  2180 		CAppInfoReader* appInfoReader = NULL;
  2156 		appInfoReader = CAppInfoReader::NewL(RegistrationFileName, NullUid, folder); 
  2181 		appInfoReader = CAppInfoReader::NewL(RegistrationFileName, NullUid, folder); 
  2157 		if (!appInfoReader)
  2182 		if (!appInfoReader)
  2158 		{
  2183 			{
  2159 			std::string errMsg= "Error in Reading File. Memory Allocation Failed";
  2184 			std::string errMsg= "Error in Reading File. Memory Allocation Failed";
  2160 			throw CResourceFileException(errMsg);
  2185 			throw CResourceFileException(errMsg);
  2161 		}
  2186 			}
  2162 		else
  2187 		else
  2163 		{
  2188 			{
  2164 			TBool readSuccessful=EFalse;
  2189 			TBool readSuccessful=EFalse;
  2165 
  2190 
  2166 			readSuccessful= appInfoReader->ReadL(aFileDescription, iRomPath, aInRom);
  2191 			readSuccessful= appInfoReader->ReadL(aFileDescription, iRomPath, aInRom);
  2167 		
  2192 		
  2168 			if (readSuccessful)
  2193 			if (readSuccessful)
  2169 			{
  2194 				{
  2170 				CreateApplicationRegistrationInfoL(aComponent,appInfoReader);
  2195 				CreateApplicationRegistrationInfoL(aComponent,appInfoReader);
  2171 			}
  2196 				}
  2172 			else
  2197 			else
  2173 			{
  2198 				{
  2174 				delete appInfoReader;
  2199 				delete appInfoReader;
  2175 				std::string errMsg= "Reading Resource File failed.";
  2200 				std::string errMsg= "Reading Resource File failed.";
  2176 				throw CResourceFileException(errMsg);
  2201 				throw CResourceFileException(errMsg);
  2177 			}
  2202 				}
  2178 		}
  2203 			}
  2179 		delete appInfoReader;
  2204 		delete appInfoReader;
  2180 	}
  2205 		}
  2181 }
  2206 	}
  2182 #endif //SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
  2207 #endif //SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
  2183 
  2208 
  2184 void SisRegistry::AddFileDescriptionAsFileProperty	(	XmlDetails::TScrPreProvisionDetail::TComponentFile& aComponentFile, 
  2209 void SisRegistry::AddFileDescriptionAsFileProperty	(	XmlDetails::TScrPreProvisionDetail::TComponentFile& aComponentFile, 
  2185 												const FileDescription* aFileDescription
  2210 												const FileDescription* aFileDescription
  2186 										)
  2211 										)