secureswitools/swisistools/source/interpretsislib/sisregistry.cpp
branchRCL_3
changeset 26 8b7f4e561641
parent 25 7333d7932ef7
equal deleted inserted replaced
25:7333d7932ef7 26:8b7f4e561641
    21 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    21 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    22 
    22 
    23 #include "dbhelper.h"
    23 #include "dbhelper.h"
    24 #include "dblayer.h"
    24 #include "dblayer.h"
    25 #include "dbconstants.h"
    25 #include "dbconstants.h"
       
    26 #include "is_utils.h"
    26 #include "xmlgenerator.h"
    27 #include "xmlgenerator.h"
    27 #include "xmlparser.h"
    28 #include "xmlparser.h"
    28 #include "util.h"
    29 #include "util.h"
    29 #include <algorithm>
    30 #include <algorithm>
    30 #include <iostream>
    31 #include <iostream>
    31 #include <stdexcept>
    32 #include <stdexcept>
    32 #include <iostream>
    33 #include <iostream>
    33 #include "dirparse.h"
    34 
    34 #include "parse.h"
       
    35 #endif //SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    35 #endif //SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    36 
       
    37 // constants 
    36 // constants 
    38 #define IGNORE_FORMATTING -1
    37 #define IGNORE_FORMATTING -1
    39 #define ENABLE 1
    38 #define ENABLE 1
    40 #define DISABLE 0
    39 #define DISABLE 0
    41 // System Includes
    40 // System Includes
  1464 	}
  1463 	}
  1465 
  1464 
  1466 void SisRegistry::UpdateInstallationInformation(XmlDetails::TScrPreProvisionDetail aScrPreProvisionDetail)
  1465 void SisRegistry::UpdateInstallationInformation(XmlDetails::TScrPreProvisionDetail aScrPreProvisionDetail)
  1467 	{
  1466 	{
  1468 	CXmlGenerator xmlGenerator;
  1467 	CXmlGenerator xmlGenerator;
  1469 
  1468 	char* tmpFileName = tmpnam(NULL);	
  1470 	#ifndef __TOOLS2_LINUX__
       
  1471 		char* tmpFileName = tmpnam(NULL);	
       
  1472 	#else
       
  1473 		char tmpFileName[] = "/tmp/interpretsis_XXXXXX";	
       
  1474 		int temp_fd;
       
  1475 		temp_fd=mkstemp(tmpFileName); 
       
  1476 		fclose(fdopen(temp_fd,"w"));
       
  1477 	#endif
       
  1478 
       
  1479 	std::wstring filename(string2wstring(tmpFileName));
  1469 	std::wstring filename(string2wstring(tmpFileName));
  1480 
  1470 
  1481 	int isRomApplication = 0;
  1471 	int isRomApplication = 0;
  1482 	xmlGenerator.WritePreProvisionDetails(filename , aScrPreProvisionDetail, isRomApplication);
  1472 	xmlGenerator.WritePreProvisionDetails(filename , aScrPreProvisionDetail, isRomApplication);
  1483 
  1473 
  1484 	#ifdef __TOOLS2_LINUX__
  1474 	#ifdef __LINUX__
  1485 	std::string executable = "scrtool";
  1475 	std::string executable = "scrtool";
  1486 	#else
  1476 	#else
  1487 	std::string executable = "scrtool.exe";
  1477 	std::string executable = "scrtool.exe";
  1488 	#endif
  1478 	#endif
  1489 
  1479 
  1495 	int err = remove(tmpFileName);
  1485 	int err = remove(tmpFileName);
  1496 	if(err != 0)
  1486 	if(err != 0)
  1497 		LERROR(L"Temporary file removal failed.");
  1487 		LERROR(L"Temporary file removal failed.");
  1498 
  1488 
  1499 	if(error != 0)
  1489 	if(error != 0)
  1500 	{
  1490 		{
  1501 		std::string err = "Scrtool failed to upload the database registry entry.";
  1491 		std::string err = "Scrtool failed to upload the database registry entry.";
  1502 		LERROR(L"Scrtool failed to upload the database registry entry.");
  1492 		LERROR(L"Scrtool failed to upload the database registry entry.");
  1503 		throw InterpretSisError(err, DATABASE_UPDATE_FAILED);
  1493 		throw InterpretSisError(err, DATABASE_UPDATE_FAILED);
  1504 	}
  1494 		}
  1505 	}
  1495 	}
  1506 
  1496 
  1507 std::string SisRegistry::GetDbPath()
  1497 std::string SisRegistry::GetDbPath()
  1508 	{
  1498 	{
  1509 	if	( 
  1499 	if	( 
  1525 	
  1515 	
  1526 	}
  1516 	}
  1527 
  1517 
  1528 std::string SisRegistry::GetEpocRoot()
  1518 std::string SisRegistry::GetEpocRoot()
  1529 	{
  1519 	{
  1530 	const char* epocRoot = getenv("EPOCROOT");	
  1520 	const char* epocRoot = getenv("EPOCROOT");
  1531 	if(NULL == epocRoot)
  1521 	if(NULL == epocRoot)
  1532 		{
  1522 		{
  1533 		std::string err = "EPOCROOT environment variable not specified. Please specify it as part of your environment variable." \
  1523 		std::string err = "EPOCROOT environment variable not specified. Please specify it as part of your environment variable." \
  1534 		"It should point uptil the start of the epoc32 directory.";
  1524 		"It should point uptil the start of the epoc32 directory.";
  1535 		LERROR(L"EPOCROOT environment variable not specified. Please specify it as part of your environment variable." \
  1525 		LERROR(L"EPOCROOT environment variable not specified. Please specify it as part of your environment variable." \
  1548 #ifdef _MSC_VER
  1538 #ifdef _MSC_VER
  1549 		swprintf(textGlobalId,L"%08x",aUid);
  1539 		swprintf(textGlobalId,L"%08x",aUid);
  1550 #else		
  1540 #else		
  1551 		swprintf(textGlobalId,20,L"%08x",aUid);
  1541 		swprintf(textGlobalId,20,L"%08x",aUid);
  1552 #endif
  1542 #endif
  1553 		
  1543 	
  1554 
       
  1555 	std::wstring globalId = textGlobalId;
  1544 	std::wstring globalId = textGlobalId;
  1556 	
  1545 	
  1557 	if( aInstallType == CSISInfo::EInstAugmentation || aInstallType == CSISInfo::EInstPreInstalledPatch )
  1546 	if( aInstallType == CSISInfo::EInstAugmentation || aInstallType == CSISInfo::EInstPreInstalledPatch )
  1558 		{
  1547 		{
  1559 		if(aPackageName.empty())
  1548 		if(aPackageName.empty())
  1608 	// Remove all .ctl files in the system drive for this package
  1597 	// Remove all .ctl files in the system drive for this package
  1609 	while (currFile != regDirFiles.end())
  1598 	while (currFile != regDirFiles.end())
  1610 	    {
  1599 	    {
  1611 		if (*currFile != L"." && *currFile != L"..")
  1600 		if (*currFile != L"." && *currFile != L"..")
  1612 		    {
  1601 		    {
  1613 			#ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK	
  1602 			RemoveFile(path + *currFile);
  1614 				int pos = 0;
       
  1615 				if((pos = currFile->find(L".ctl_backup", 0)) == std::wstring::npos)
       
  1616 			#endif
       
  1617 					RemoveFile(path + *currFile);
       
  1618 		    }
  1603 		    }
  1619 
  1604 
  1620 		++currFile;
  1605 		++currFile;
  1621 	    }
  1606 	    }
  1622 
  1607 
  1643 			// Remove all the .ctl files for this package
  1628 			// Remove all the .ctl files for this package
  1644 			while (currFile != regDirFiles.end())
  1629 			while (currFile != regDirFiles.end())
  1645 				{
  1630 				{
  1646 				if (*currFile != L"." && *currFile != L"..")
  1631 				if (*currFile != L"." && *currFile != L"..")
  1647 					{
  1632 					{
  1648 					#ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK	
  1633 					RemoveFile(path + *currFile);
  1649 						int pos = 0;
       
  1650 						if((pos = currFile->find(L".ctl_backup", 0)) == std::wstring::npos)
       
  1651 					#endif
       
  1652 							RemoveFile(path + *currFile);
       
  1653 					}
  1634 					}
  1654 				++currFile;
  1635 				++currFile;
  1655 				}
  1636 				}
  1656 
  1637 
  1657 			// This iterator's object has the same Uid as aUid
  1638 			// This iterator's object has the same Uid as aUid
  1662 			}
  1643 			}
  1663 		// remove the application from database
  1644 		// remove the application from database
  1664 		iDbHelper->RemoveEntry(*compIter);
  1645 		iDbHelper->RemoveEntry(*compIter);
  1665 		}
  1646 		}
  1666 	}
  1647 	}
  1667 
       
  1668 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
  1669 void SisRegistry::BackupCtl(TUint32 aUid)
       
  1670 {
       
  1671 	std::list<std::wstring> regDirFiles;
       
  1672 	std::wstring path = GetRegistryDir( iParamList.SystemDrivePath(), aUid );
       
  1673     GetDirContents(path, regDirFiles);
       
  1674 	std::list<std::wstring>::iterator currFile = regDirFiles.begin();
       
  1675 
       
  1676 	std::wstring  path1 = FixPathDelimiterstap(path);
       
  1677 	// Backup all .ctl files in the system drive for this package
       
  1678 	while (currFile != regDirFiles.end())
       
  1679 	{
       
  1680 		if (*currFile != L"." && *currFile != L"..")
       
  1681 	    {
       
  1682 			std::string ifile = wstring2string(path1 +*currFile);
       
  1683 			std::string ibackupfile(ifile);
       
  1684 			ibackupfile.append("_backup");
       
  1685 
       
  1686 			int err=FileCopyA(ifile.c_str(),ibackupfile.c_str(),0);
       
  1687 			if (err != 0)
       
  1688 				LERROR(L"Failed to Backup .ctl ");
       
  1689 		}
       
  1690 		++currFile;
       
  1691     }
       
  1692 }
       
  1693 
       
  1694 void SisRegistry::RestoreCtl(TUint32 aUid, TBool& aBackupFlag)
       
  1695 {
       
  1696 	std::list<std::wstring> regDirFiles;
       
  1697 	std::wstring path = GetRegistryDir( iParamList.SystemDrivePath(), aUid );
       
  1698     GetDirContents(path, regDirFiles);
       
  1699 	std::list<std::wstring>::iterator currFile = regDirFiles.begin();
       
  1700 
       
  1701 	// Restore all .ctl files in the system drive for this package
       
  1702 	while (currFile != regDirFiles.end())
       
  1703 	{
       
  1704 		if (*currFile != L"." && *currFile != L"..")
       
  1705 	    {
       
  1706 			if(aBackupFlag)
       
  1707 			{
       
  1708 				int pos =0;
       
  1709 				if((pos = currFile->find(L".ctl_backup", 0)) == std::wstring::npos)
       
  1710 				{
       
  1711 					std::string ifile = wstring2string(path +*currFile);
       
  1712 					std::string ibackupfile(ifile);
       
  1713 					ibackupfile.append("_backup");
       
  1714 
       
  1715 					RemoveFile(path + *currFile);
       
  1716 				 	int err = FileMoveA(ibackupfile.c_str(),ifile.c_str());
       
  1717 					if (err != 0)
       
  1718 						LERROR(L"Failed to Restore .ctl ");
       
  1719 				}
       
  1720 			}
       
  1721 			else
       
  1722 			{
       
  1723 				RemoveFile(path + *currFile);
       
  1724 			}
       
  1725 		}
       
  1726 		++currFile;
       
  1727     }
       
  1728 }
       
  1729 
       
  1730 void SisRegistry::RemoveCtlBackup(TUint32 aUid)
       
  1731 {
       
  1732 	std::list<std::wstring> regDirFiles;
       
  1733 	std::wstring path = GetRegistryDir( iParamList.SystemDrivePath(), aUid );
       
  1734     GetDirContents(path, regDirFiles);
       
  1735 	std::list<std::wstring>::iterator currFile = regDirFiles.begin();
       
  1736 	
       
  1737 	// Remove all .ctl backup files in the system drive for this package
       
  1738 	while (currFile != regDirFiles.end())
       
  1739 	{
       
  1740 		if (*currFile != L"." && *currFile != L"..")
       
  1741 	    {
       
  1742 			std::wstring ifile(path +*currFile);
       
  1743 			ifile.append(L"_backup");
       
  1744 			
       
  1745 			if (FileExists(ifile))
       
  1746 				RemoveFile(ifile);
       
  1747 		}
       
  1748 		++currFile;
       
  1749     }
       
  1750 }
       
  1751 #endif
       
  1752 
  1648 
  1753 TUint32 SisRegistry::GetUid(TUint32 aSid) const
  1649 TUint32 SisRegistry::GetUid(TUint32 aSid) const
  1754 	{
  1650 	{
  1755 	return iDbHelper->GetUid(aSid);
  1651 	return iDbHelper->GetUid(aSid);
  1756 	}
  1652 	}
  1783 
  1679 
  1784 	AddComponentDependencies(component, aSisRegistryObject);
  1680 	AddComponentDependencies(component, aSisRegistryObject);
  1785 	AddEmbeddedPackages(component, aSisRegistryObject.GetEmbeddedPackages());
  1681 	AddEmbeddedPackages(component, aSisRegistryObject.GetEmbeddedPackages());
  1786 	AddProperties(component, aSisRegistryObject.GetProperties());
  1682 	AddProperties(component, aSisRegistryObject.GetProperties());
  1787 	AddFileDescription(component, aSisRegistryObject.GetFileDescriptions());
  1683 	AddFileDescription(component, aSisRegistryObject.GetFileDescriptions());
  1788 	#ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
  1789 	AddApplicationRegistrationInfoL(component, aSisRegistryObject.GetFileDescriptions(), aSisRegistryObject.GetInRom());
       
  1790 	#endif //SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
  1791 	
  1684 	
  1792 	// inROM
  1685 	// inROM
  1793 	if(DbConstants::KDefaultIsInRom != aSisRegistryObject.GetInRom())
  1686 	if(DbConstants::KDefaultIsInRom != aSisRegistryObject.GetInRom())
  1794 		AddComponentProperty(component, DbConstants::CompInRom, aSisRegistryObject.GetInRom(), IGNORE_FORMATTING );
  1687 		AddComponentProperty(component, DbConstants::CompInRom, aSisRegistryObject.GetInRom(), IGNORE_FORMATTING );
  1795 
  1688 
  2090 			}
  1983 			}
  2091 
  1984 
  2092 		// add the location in the component files table
  1985 		// add the location in the component files table
  2093 		XmlDetails::TScrPreProvisionDetail::TComponentFile componentFile;
  1986 		XmlDetails::TScrPreProvisionDetail::TComponentFile componentFile;
  2094 		componentFile.iLocation = (*filedesIter)->GetTarget();
  1987 		componentFile.iLocation = (*filedesIter)->GetTarget();
  2095 
       
  2096 		AddFileDescriptionAsFileProperty(componentFile, *filedesIter);
  1988 		AddFileDescriptionAsFileProperty(componentFile, *filedesIter);
  2097 		aComponent.iComponentFiles.push_back(componentFile);
  1989 		aComponent.iComponentFiles.push_back(componentFile);
  2098 		}
  1990 		}
  2099 
  1991 
  2100 	if (DbConstants::KDefaultWildCardFileCount != wildcardFileCount)
  1992 	if (DbConstants::KDefaultWildCardFileCount != wildcardFileCount)
  2101 		AddComponentProperty(aComponent, DbConstants::CompWildCardFileCount, wildcardFileCount, IGNORE_FORMATTING);	
  1993 		AddComponentProperty(aComponent, DbConstants::CompWildCardFileCount, wildcardFileCount, IGNORE_FORMATTING);	
  2102 	}
  1994 	}
  2103 
       
  2104 
       
  2105 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
  2106 void SisRegistry::AddApplicationRegistrationInfoL(XmlDetails::TScrPreProvisionDetail::TComponent& aComponent, const std::vector<FileDescription*>& aFileDescription, int aInRom )
       
  2107 {
       
  2108 	std::vector<FileDescription*>::const_iterator filedesIter;
       
  2109 	std::wstring iLocalFile;
       
  2110 	std::string RegistrationFileName;
       
  2111 	
       
  2112 	//Find Registration File from list of filelist
       
  2113 	for(filedesIter = aFileDescription.begin() ; filedesIter != aFileDescription.end(); ++filedesIter)
       
  2114 	{
       
  2115 		// if it has wild card characters then donot process. Continue.
       
  2116 		if( IsFileWideCard((*filedesIter)->GetLocalFile()) )
       
  2117 		{
       
  2118 			continue;
       
  2119 		}
       
  2120 
       
  2121 		iLocalFile = (*filedesIter)->GetLocalFile();
       
  2122 		RegistrationFileName = wstring2string(iLocalFile);
       
  2123 
       
  2124 		std::string iRomPath = wstring2string(iParamList.RomDrivePath());
       
  2125 		if(aInRom)
       
  2126 		{
       
  2127 			std::string localpath = FullNameWithoutDrive(RegistrationFileName);
       
  2128 			RegistrationFileName = iRomPath + localpath;
       
  2129 		}
       
  2130 
       
  2131 		size_t found=RegistrationFileName.rfind(".rsc");
       
  2132 		if(found==string::npos)
       
  2133 			continue;
       
  2134 
       
  2135 		//Return 0 for Registration file else 1
       
  2136 		TInt err = FindRegistrationResourceFileL(RegistrationFileName);
       
  2137 
       
  2138 		if(err)
       
  2139 			continue;
       
  2140 
       
  2141 		std::string folder;
       
  2142 		#ifdef __LINUX__
       
  2143 		const char *privateFolder = "private/10003a3f/";
       
  2144 		#else
       
  2145 		const char *privateFolder = "private\\10003a3f\\";
       
  2146 		#endif
       
  2147 
       
  2148 		found=RegistrationFileName.find(privateFolder);
       
  2149 
       
  2150 		if( found != string::npos ) 
       
  2151 			folder = RegistrationFileName.substr(0,found); 
       
  2152 		else
       
  2153 			folder = RegistrationFileName; 
       
  2154 
       
  2155 		CAppInfoReader* appInfoReader = NULL;
       
  2156 		appInfoReader = CAppInfoReader::NewL(RegistrationFileName, NullUid, folder); 
       
  2157 		if (!appInfoReader)
       
  2158 		{
       
  2159 			std::string errMsg= "Error in Reading File. Memory Allocation Failed";
       
  2160 			throw CResourceFileException(errMsg);
       
  2161 		}
       
  2162 		else
       
  2163 		{
       
  2164 			TBool readSuccessful=EFalse;
       
  2165 
       
  2166 			readSuccessful= appInfoReader->ReadL(aFileDescription, iRomPath, aInRom);
       
  2167 		
       
  2168 			if (readSuccessful)
       
  2169 			{
       
  2170 				CreateApplicationRegistrationInfoL(aComponent,appInfoReader);
       
  2171 			}
       
  2172 			else
       
  2173 			{
       
  2174 				delete appInfoReader;
       
  2175 				std::string errMsg= "Reading Resource File failed.";
       
  2176 				throw CResourceFileException(errMsg);
       
  2177 			}
       
  2178 		}
       
  2179 		delete appInfoReader;
       
  2180 	}
       
  2181 }
       
  2182 #endif //SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
  2183 
  1995 
  2184 void SisRegistry::AddFileDescriptionAsFileProperty	(	XmlDetails::TScrPreProvisionDetail::TComponentFile& aComponentFile, 
  1996 void SisRegistry::AddFileDescriptionAsFileProperty	(	XmlDetails::TScrPreProvisionDetail::TComponentFile& aComponentFile, 
  2185 												const FileDescription* aFileDescription
  1997 												const FileDescription* aFileDescription
  2186 										)
  1998 										)
  2187 	{
  1999 	{