secureswitools/swisistools/source/interpretsislib/sisregistry.cpp
branchRCL_3
changeset 62 5cc91383ab1e
parent 19 7ca52d38f8c3
child 65 7333d7932ef7
equal deleted inserted replaced
61:cd189dac02f7 62:5cc91383ab1e
     1 /*
     1 /*
     2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    49 #endif 
    49 #endif 
    50 
    50 
    51 // SisX Library Includes
    51 // SisX Library Includes
    52 #include "sisfiledescription.h"
    52 #include "sisfiledescription.h"
    53 #include "sisstring.h"
    53 #include "sisstring.h"
       
    54 #include "utility.h"
    54 
    55 
    55 // User Includes
    56 // User Includes
    56 #include "sisregistry.h"
    57 #include "sisregistry.h"
    57 #include "errors.h"
    58 #include "errors.h"
    58 #include "rommanager.h"
    59 #include "rommanager.h"
    62 #include "sisregistrypackage.h"
    63 #include "sisregistrypackage.h"
    63 #include "sisregistryobject.h"
    64 #include "sisregistryobject.h"
    64 #include "configmanager.h"
    65 #include "configmanager.h"
    65 
    66 
    66 // Constants
    67 // Constants
       
    68 #ifndef __TOOLS2_LINUX__
    67 const std::wstring SisRegistry::KPathToRegistry(L"\\sys\\install\\sisregistry/");
    69 const std::wstring SisRegistry::KPathToRegistry(L"\\sys\\install\\sisregistry/");
    68 const std::wstring SisRegistry::KPathToRomStubs(L"\\system\\install\\");
    70 const std::wstring SisRegistry::KPathToRomStubs(L"\\system\\install\\");
    69 const std::wstring SisRegistry::KPathToRegistryVersionMarker(L"\\system\\data\\");
    71 const std::wstring SisRegistry::KPathToRegistryVersionMarker(L"\\system\\data\\");
       
    72 #else
       
    73 const std::wstring SisRegistry::KPathToRegistry(L"/sys/install/sisregistry/");
       
    74 const std::wstring SisRegistry::KPathToRomStubs(L"/system/install/");
       
    75 const std::wstring SisRegistry::KPathToRegistryVersionMarker(L"/system/data/");
       
    76 #endif
    70 const std::wstring KRegistryEntry(L"00000000.reg");
    77 const std::wstring KRegistryEntry(L"00000000.reg");
    71 const std::wstring KControllerEntry(L"00000000_0000.ctl");
    78 const std::wstring KControllerEntry(L"00000000_0000.ctl");
    72 const std::wstring KBackupLst(L"backup.lst");
    79 const std::wstring KBackupLst(L"backup.lst");
    73 
    80 
    74 const int SisRegistry::KSisRegistryMajorVersion = 5;
    81 const int SisRegistry::KSisRegistryMajorVersion = 5;
    79 const std::wstring SisRegistry::KRegistryV40(L"sisregistry_4.0.txt");
    86 const std::wstring SisRegistry::KRegistryV40(L"sisregistry_4.0.txt");
    80 const std::wstring SisRegistry::KRegistryV51(L"sisregistry_5.1.txt");
    87 const std::wstring SisRegistry::KRegistryV51(L"sisregistry_5.1.txt");
    81 const std::wstring SisRegistry::KRegistryV52(L"sisregistry_5.2.txt");
    88 const std::wstring SisRegistry::KRegistryV52(L"sisregistry_5.2.txt");
    82 const std::wstring SisRegistry::KRegistryV53(L"sisregistry_5.3.txt");
    89 const std::wstring SisRegistry::KRegistryV53(L"sisregistry_5.3.txt");
    83 const std::wstring SisRegistry::KRegistryV54(L"sisregistry_5.4.txt");
    90 const std::wstring SisRegistry::KRegistryV54(L"sisregistry_5.4.txt");
       
    91 #ifndef __TOOLS2_LINUX__
    84 const std::wstring SisRegistry::KRomStubDir(L"z:\\system\\install\\");
    92 const std::wstring SisRegistry::KRomStubDir(L"z:\\system\\install\\");
    85 const std::wstring SisRegistry::KRomRegistryVersionMarker(L"z:\\system\\data\\");
    93 const std::wstring SisRegistry::KRomRegistryVersionMarker(L"z:\\system\\data\\");
    86 
    94 #else
       
    95 const std::wstring SisRegistry::KRomStubDir(L"z:/system/install/");
       
    96 const std::wstring SisRegistry::KRomRegistryVersionMarker(L"z:/system/data/");
       
    97 #endif
    87 const std::string SisRegistry::KRegistryV40string("4.0");
    98 const std::string SisRegistry::KRegistryV40string("4.0");
    88 const std::string SisRegistry::KRegistryV50string("5.0");
    99 const std::string SisRegistry::KRegistryV50string("5.0");
    89 const std::string SisRegistry::KRegistryV51string("5.1");
   100 const std::string SisRegistry::KRegistryV51string("5.1");
    90 const std::string SisRegistry::KRegistryV52string("5.2");
   101 const std::string SisRegistry::KRegistryV52string("5.2");
    91 const std::string SisRegistry::KRegistryV53string("5.3");
   102 const std::string SisRegistry::KRegistryV53string("5.3");
   543 	{
   554 	{
   544 	EntryMap::iterator it = iEntries.find(aUid);
   555 	EntryMap::iterator it = iEntries.find(aUid);
   545 	
   556 	
   546 	while(it != iEntries.end())
   557 	while(it != iEntries.end())
   547 	    {
   558 	    {
   548 		if (aUid == it->first &&
   559 		if (aUid == it->first && !wcscmp(aPackageName.c_str(), it->second->GetPackageName().c_str()) && aVendorName == it->second->GetVendorName() )
   549 			aPackageName == it->second->GetPackageName() &&
       
   550 			aVendorName == it->second->GetVendorName())
       
   551 			{
   560 			{
   552 			LINFO(L"Removing package \"" << it->second->GetPackageName() 
   561 			LINFO(L"Removing package \"" << it->second->GetPackageName() 
   553 					<< L"\" prior to re-installation");
   562 					<< L"\" prior to re-installation");
   554 
   563 
   555 			// Remove .reg file
   564 			// Remove .reg file
   946 
   955 
   947 bool SisRegistry::IsFileWideCard(const std::wstring& aFileName)
   956 bool SisRegistry::IsFileWideCard(const std::wstring& aFileName)
   948 	{
   957 	{
   949 	return (aFileName.find(L'?') != std::wstring::npos || 
   958 	return (aFileName.find(L'?') != std::wstring::npos || 
   950 			aFileName.find(L'*') != std::wstring::npos || 
   959 			aFileName.find(L'*') != std::wstring::npos || 
       
   960 			#ifndef __TOOLS2_LINUX__
   951 			aFileName[aFileName.length() - 1] == L'\\');
   961 			aFileName[aFileName.length() - 1] == L'\\');
       
   962 			#else
       
   963 			aFileName[aFileName.length() - 1] == L'/');
       
   964 			#endif
   952 	}
   965 	}
   953 
   966 
   954 
   967 
   955 void SisRegistry::GenerateStubRegistry()
   968 void SisRegistry::GenerateStubRegistry()
   956 	{
   969 	{
  1028 		{
  1041 		{
  1029 		if (c->find(L".reg",0) == std::wstring::npos)
  1042 		if (c->find(L".reg",0) == std::wstring::npos)
  1030 			continue;
  1043 			continue;
  1031 		
  1044 		
  1032 		std::fstream input;
  1045 		std::fstream input;
       
  1046 		#ifndef __TOOLS2_LINUX__
  1033 		std::wstring filename(aPath + L"\\" + *c);
  1047 		std::wstring filename(aPath + L"\\" + *c);
       
  1048 		#else
       
  1049 		std::wstring filename(aPath + L"/" + *c);
       
  1050 		#endif
  1034 		
  1051 		
  1035 		OpenFile(filename.c_str(), input, std::fstream::in | std::fstream::binary);
  1052 		OpenFile(filename.c_str(), input, std::fstream::in | std::fstream::binary);
  1036 		
  1053 		
  1037 		if (!input.good())
  1054 		if (!input.good())
  1038 			continue;
  1055 			continue;
  1039 		
  1056 		
  1040 		SisRegistryObject* obj = new SisRegistryObject(iConfigManager);
  1057 		SisRegistryObject* obj = new SisRegistryObject(iConfigManager);
  1041 					
  1058 					
  1042 		if (!obj)
  1059 		if (!obj)
  1043 			{
  1060 			{
  1044 			throw std::runtime_error("Cannot create SisRegistryObject for " + Ucs2ToUtf8(filename));
  1061 			throw std::runtime_error("Cannot create SisRegistryObject for " + wstring2string(filename));
  1045 			}
  1062 			}
  1046 		Deserialiser des(input);
  1063 		Deserialiser des(input);
  1047 		
  1064 		
  1048 		des >> *obj;
  1065 		des >> *obj;
  1049 		iEntries.insert(EntryMap::value_type(obj->GetUid(), obj));
  1066 		iEntries.insert(EntryMap::value_type(obj->GetUid(), obj));
  1239 				// No SisRegistry file found!!
  1256 				// No SisRegistry file found!!
  1240 				std::wstring msg = StringUtils::MakePathFromSID ( iParamList.SystemDrivePath()+L"\\", pkgUid );
  1257 				std::wstring msg = StringUtils::MakePathFromSID ( iParamList.SystemDrivePath()+L"\\", pkgUid );
  1241 				
  1258 				
  1242 				msg.append(L" does not have any SisRegistry file");
  1259 				msg.append(L" does not have any SisRegistry file");
  1243 				
  1260 				
  1244 				throw std::runtime_error( Ucs2ToUtf8(msg) );
  1261 				throw std::runtime_error( wstring2string(msg) );
  1245 				}
  1262 				}
  1246 
  1263 
  1247 			aObj.SetIndex( index );
  1264 			aObj.SetIndex( index );
  1248 
  1265 
  1249 			if ( !CheckSisRegistryDirPresent(iParamList.SystemDrivePath(), pkgUid) )
  1266 			if ( !CheckSisRegistryDirPresent(iParamList.SystemDrivePath(), pkgUid) )
  1251 				// c:\sys\install\sisregistry\<UID>\ directory not exist
  1268 				// c:\sys\install\sisregistry\<UID>\ directory not exist
  1252 				std::wstring msg = StringUtils::MakePathFromSID ( iParamList.SystemDrivePath()+L"\\", pkgUid );
  1269 				std::wstring msg = StringUtils::MakePathFromSID ( iParamList.SystemDrivePath()+L"\\", pkgUid );
  1253 				
  1270 				
  1254 				msg.append(L" directory NOT found");
  1271 				msg.append(L" directory NOT found");
  1255 
  1272 
  1256 				throw std::runtime_error( Ucs2ToUtf8(msg) );
  1273 				throw std::runtime_error( wstring2string(msg) );
  1257 				}
  1274 				}
  1258 			}    
  1275 			}    
  1259 		}
  1276 		}
  1260 
  1277 
  1261 	#ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
  1278 	#ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
  1274 				{
  1291 				{
  1275 				std::wstring msg = StringUtils::MakePathFromSID ( iParamList.SystemDrivePath()+L"\\", pkgUid );
  1292 				std::wstring msg = StringUtils::MakePathFromSID ( iParamList.SystemDrivePath()+L"\\", pkgUid );
  1276 				
  1293 				
  1277 				msg.append(L" directory NOT found");
  1294 				msg.append(L" directory NOT found");
  1278 
  1295 
  1279 				throw std::runtime_error( Ucs2ToUtf8(msg) );
  1296 				throw std::runtime_error( wstring2string(msg) );
  1280 				}
  1297 				}
  1281 			}    
  1298 			}    
  1282 		}
  1299 		}
  1283 
  1300 
  1284 	#endif //SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
  1301 	#endif //SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
  1327 			// No SIS controller file found!!
  1344 			// No SIS controller file found!!
  1328 			std::wstring msg = StringUtils::MakePathFromSID ( iParamList.SystemDrivePath()+L"\\", pkgUid );
  1345 			std::wstring msg = StringUtils::MakePathFromSID ( iParamList.SystemDrivePath()+L"\\", pkgUid );
  1329 		
  1346 		
  1330 			msg.append(L" does not have any Sis Controller file");
  1347 			msg.append(L" does not have any Sis Controller file");
  1331 
  1348 
  1332 			throw std::runtime_error( Ucs2ToUtf8(msg) );
  1349 			throw std::runtime_error( wstring2string(msg) );
  1333 			}
  1350 			}
  1334 		}
  1351 		}
  1335 
  1352 
  1336 	// Finally, externalise the new controller file
  1353 	// Finally, externalise the new controller file
  1337 	std::fstream ctlFile;
  1354 	std::fstream ctlFile;
  1445 		}
  1462 		}
  1446 	}
  1463 	}
  1447 
  1464 
  1448 void SisRegistry::UpdateInstallationInformation(XmlDetails::TScrPreProvisionDetail aScrPreProvisionDetail)
  1465 void SisRegistry::UpdateInstallationInformation(XmlDetails::TScrPreProvisionDetail aScrPreProvisionDetail)
  1449 	{
  1466 	{
  1450 	CXmlGenerator xmlgenerator;
  1467 	CXmlGenerator xmlGenerator;
  1451 	char* tmpFileName = tmpnam(NULL);
  1468 	char* tmpFileName = tmpnam(NULL);	
  1452 	std::wstring filename(string2wstring(tmpFileName));
  1469 	std::wstring filename(string2wstring(tmpFileName));
  1453 	
  1470 
  1454 	xmlgenerator.WritePreProvisionDetails(filename , aScrPreProvisionDetail);						
  1471 	int isRomApplication = 0;
  1455 						
  1472 	xmlGenerator.WritePreProvisionDetails(filename , aScrPreProvisionDetail, isRomApplication);
       
  1473 
       
  1474 	#ifdef __LINUX__
       
  1475 	std::string executable = "scrtool";
       
  1476 	#else
  1456 	std::string executable = "scrtool.exe";
  1477 	std::string executable = "scrtool.exe";
       
  1478 	#endif
       
  1479 
  1457 	std::string command;
  1480 	std::string command;
  1458 	command = executable + " -d " + GetDbPath() + " -p " + tmpFileName;
  1481 	command = executable + " -d " + GetDbPath() + " -p " + tmpFileName;
  1459 	
  1482 
  1460 	int error = system(command.c_str());
  1483 	int error = system(command.c_str());
  1461 	
  1484 
       
  1485 	int err = remove(tmpFileName);
       
  1486 	if(err != 0)
       
  1487 		LERROR(L"Temporary file removal failed.");
       
  1488 
  1462 	if(error != 0)
  1489 	if(error != 0)
  1463 		{
  1490 		{
  1464 		std::string err = "Scrtool failed to upload the database registry entry.";
  1491 		std::string err = "Scrtool failed to upload the database registry entry.";
  1465 		LERROR(L"Scrtool failed to upload the database registry entry.");
  1492 		LERROR(L"Scrtool failed to upload the database registry entry.");
  1466 		throw InterpretSisError(err, DATABASE_UPDATE_FAILED);
  1493 		throw InterpretSisError(err, DATABASE_UPDATE_FAILED);
  1467 		}
  1494 		}
  1468 		
       
  1469 	error = remove(tmpFileName);
       
  1470 
       
  1471 	if(error != 0)
       
  1472 		{
       
  1473 		LERROR(L"Temporary file removal failed.");
       
  1474 		}
       
  1475 	
       
  1476 	}
  1495 	}
  1477 
  1496 
  1478 std::string SisRegistry::GetDbPath()
  1497 std::string SisRegistry::GetDbPath()
  1479 	{
  1498 	{
  1480 	if	( 
  1499 	if	( 
  1481 		(iParamList.RomLogFileNames().size() != 0 && iParamList.RomDrivePath().size() == 0 ) ||
  1500 		(iParamList.RomLogFileNames().size() != 0 && iParamList.RomDrivePath().size() == 0 ) ||
  1482 		iParamList.IsFlagSet(CParameterList::EFlagsDisableZDriveChecksSet) 
  1501 		iParamList.IsFlagSet(CParameterList::EFlagsDisableZDriveChecksSet) 
  1483 		)
  1502 		)
  1484 		{
  1503 		{
       
  1504 		#ifndef __TOOLS2_LINUX__
  1485 		return wstring2string(iParamList.SystemDrivePath()) + "\\sys\\install\\scr\\scr.db";
  1505 		return wstring2string(iParamList.SystemDrivePath()) + "\\sys\\install\\scr\\scr.db";
  1486 		}
  1506 		#else
  1487 
  1507 		return wstring2string(iParamList.SystemDrivePath()) + "/sys/install/scr/scr.db";
       
  1508 		#endif
       
  1509 		}
       
  1510 	#ifndef __TOOLS2_LINUX__
  1488 	return wstring2string(iParamList.RomDrivePath()) + "\\sys\\install\\scr\\provisioned\\scr.db";
  1511 	return wstring2string(iParamList.RomDrivePath()) + "\\sys\\install\\scr\\provisioned\\scr.db";
       
  1512 	#else
       
  1513 	    return wstring2string(iParamList.RomDrivePath()) + "/sys/install/scr/provisioned/scr.db";
       
  1514 	#endif
  1489 	
  1515 	
  1490 	}
  1516 	}
  1491 
  1517 
  1492 std::string SisRegistry::GetEpocRoot()
  1518 std::string SisRegistry::GetEpocRoot()
  1493 	{
  1519 	{
  1817 	
  1843 	
  1818 	int algorithmId = aHashContainer.GetHashId();
  1844 	int algorithmId = aHashContainer.GetHashId();
  1819 	// The property is a concatenation of the algorithm id and the hash data
  1845 	// The property is a concatenation of the algorithm id and the hash data
  1820 	const std::string hashData = aHashContainer.GetData();
  1846 	const std::string hashData = aHashContainer.GetData();
  1821 		
  1847 		
  1822 	std::string encodedHashData = Util::Base64Encode(hashData);
  1848 	std::string encodedHashData = Util::Base64Encode(hashData);	
  1823 	std::wstring wideHashData = Utils::string2wstring(encodedHashData);
  1849 	std::wstring wideHashData = string2wstring(encodedHashData);
  1824 	AddComponentProperty( aComponent, DbConstants::CompControllerHashData, wideHashData, aCount, true);
  1850 	AddComponentProperty( aComponent, DbConstants::CompControllerHashData, wideHashData, aCount, true);
  1825 
  1851 
  1826 	}
  1852 	}
  1827 
  1853 
  1828 
  1854 
  2012 		}
  2038 		}
  2013 	// file hash data
  2039 	// file hash data
  2014 	if(!aFileDescription->GetHash().GetData().empty())
  2040 	if(!aFileDescription->GetHash().GetData().empty())
  2015 		{
  2041 		{
  2016 		std::string binHashData = Util::Base64Encode(aFileDescription->GetHash().GetData());
  2042 		std::string binHashData = Util::Base64Encode(aFileDescription->GetHash().GetData());
  2017 		std::wstring hashData = Utils::string2wstring(binHashData);
  2043 		std::wstring hashData = string2wstring(binHashData);
  2018 		AddFileProperty( aComponentFile, DbConstants::FileHashData, hashData, true);
  2044 		AddFileProperty( aComponentFile, DbConstants::FileHashData, hashData, true);
  2019 		}
  2045 		}
  2020 	}
  2046 	}
  2021 
  2047 
  2022 void SisRegistry::AddTrustStatus	(	XmlDetails::TScrPreProvisionDetail::TComponent& aComponent, 
  2048 void SisRegistry::AddTrustStatus	(	XmlDetails::TScrPreProvisionDetail::TComponent& aComponent,