secureswitools/swisistools/source/interpretsislib/installer.cpp
branchRCL_3
changeset 81 42552535c1ac
parent 73 79647526f98c
equal deleted inserted replaced
73:79647526f98c 81:42552535c1ac
    19 #pragma warning (disable: 4786)
    19 #pragma warning (disable: 4786)
    20 
    20 
    21 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    21 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    22 
    22 
    23 #include "dbhelper.h" 
    23 #include "dbhelper.h" 
    24 #ifndef __TOOLS2_LINUX__
    24 
    25 #include <windows.h>
       
    26 #endif 
       
    27 #endif //SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    25 #endif //SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    28 #include <exception>
    26 #include <exception>
    29 #include <sstream>
    27 #include <sstream>
    30 #include <algorithm>
    28 #include <algorithm>
    31 #include <functional>
    29 #include <functional>
    54 #include "adornedutilities.h"
    52 #include "adornedutilities.h"
    55 
    53 
    56 // Constants
    54 // Constants
    57 const char KRomDriveLetter = 'z';
    55 const char KRomDriveLetter = 'z';
    58 const TUint32 KSwiDaemonUid = 0x10202DCE;
    56 const TUint32 KSwiDaemonUid = 0x10202DCE;
    59 #ifndef __TOOLS2_LINUX__
       
    60 const std::wstring KSysBinPath = L"\\sys\\bin\\";
    57 const std::wstring KSysBinPath = L"\\sys\\bin\\";
    61 #else
       
    62 const std::wstring KSysBinPath = L"/sys/bin/";
       
    63 #endif
       
    64 
    58 
    65 TInt CheckWildCard(TInt aVal, TInt aReplace)
    59 TInt CheckWildCard(TInt aVal, TInt aReplace)
    66 {
    60 {
    67 	return
    61 	return
    68 		aVal == -1
    62 		aVal == -1
   115 	{
   109 	{
   116 		std::wstring shortName(curr->iFileName);
   110 		std::wstring shortName(curr->iFileName);
   117 
   111 
   118 		// Ensure formatting is correct
   112 		// Ensure formatting is correct
   119 		if ( StringUtils::IsLastCharacter( shortName, KDirectorySeparator[ 0 ] ) ||
   113 		if ( StringUtils::IsLastCharacter( shortName, KDirectorySeparator[ 0 ] ) ||
   120 			 #ifndef __TOOLS2_LINUX__
       
   121              StringUtils::IsLastCharacter( shortName, L'/' ) )
   114              StringUtils::IsLastCharacter( shortName, L'/' ) )
   122              #else
       
   123 			 StringUtils::IsLastCharacter( shortName, L'\\' ) )
       
   124 			 #endif
       
   125 		{
   115 		{
   126 			shortName.erase(shortName.length()-1,1);
   116 			shortName.erase(shortName.length()-1,1);
   127 		}
   117 		}
   128 
   118 
   129 		if ( IsDirectory(shortName) )
   119 		if ( IsDirectory(shortName) )
   136 				if ((currStr->find(L".SIS",0) != std::wstring::npos)
   126 				if ((currStr->find(L".SIS",0) != std::wstring::npos)
   137 					|| (currStr->find(L".sis",0) != std::wstring::npos))
   127 					|| (currStr->find(L".sis",0) != std::wstring::npos))
   138 				{
   128 				{
   139 					InstallSISFile sisFileName(shortName + KDirectorySeparator + *currStr, 
   129 					InstallSISFile sisFileName(shortName + KDirectorySeparator + *currStr, 
   140 												curr->iTargetDrive, curr->iGenerateStub, 
   130 												curr->iTargetDrive, curr->iGenerateStub, 
   141 												curr->iNonRemovable, curr->iReadOnly, curr->iNotRegister, 
   131 												curr->iNonRemovable, curr->iReadOnly, curr->iNotRegister, curr->iSUFlag);
   142 												curr->iSUFlag, curr->iGenerateRomStub);
       
   143 
   132 
   144 					sisFiles.push_back(sisFileName);
   133 					sisFiles.push_back(sisFileName);
   145 				}
   134 				}
   146 			}
   135 			}
   147 
   136 
   152 		}
   141 		}
   153 		else if ((shortName.find(L".SIS",0) != std::wstring::npos)
   142 		else if ((shortName.find(L".SIS",0) != std::wstring::npos)
   154 				|| (shortName.find(L".sis",0) != std::wstring::npos))
   143 				|| (shortName.find(L".sis",0) != std::wstring::npos))
   155 		{
   144 		{
   156 			InstallSISFile sisFileName(shortName, curr->iTargetDrive, curr->iGenerateStub, 
   145 			InstallSISFile sisFileName(shortName, curr->iTargetDrive, curr->iGenerateStub, 
   157 										curr->iNonRemovable, curr->iReadOnly, curr->iNotRegister, 
   146 										curr->iNonRemovable, curr->iReadOnly, curr->iNotRegister, curr->iSUFlag);
   158 										curr->iSUFlag, curr->iGenerateRomStub);
       
   159 
   147 
   160 			sisFiles.push_back(sisFileName);
   148 			sisFiles.push_back(sisFileName);
   161 		}
   149 		}
   162 		else
   150 		else
   163 		{
   151 		{
   208 					result =  FILE_ERROR;
   196 					result =  FILE_ERROR;
   209 				}
   197 				}
   210 			catch  (InterpretSisError& e)
   198 			catch  (InterpretSisError& e)
   211 				{
   199 				{
   212 				LERROR(L"Failed installing " << (curr->iFileName));
   200 				LERROR(L"Failed installing " << (curr->iFileName));
   213 				LERROR(L"\t" << string2wstring(e.what()));
   201 				LERROR(L"\t" << Utf8ToUcs2(e.what()));
   214 				curr = sisFiles.erase(curr);
   202 				curr = sisFiles.erase(curr);
   215 				
   203 				
   216 				if (result == 0)
   204 				if (result == 0)
   217 					result =  e.GetErrorCode();
   205 					result =  e.GetErrorCode();
   218 				}
   206 				}
   338 	if (!DependenciesOk(file))
   326 	if (!DependenciesOk(file))
   339 	{
   327 	{
   340 		return MISSING_DEPENDENCY;
   328 		return MISSING_DEPENDENCY;
   341 	}
   329 	}
   342 
   330 
   343 	if (!IsValidUpgrade(file, aInstallSISFile.iSUFlag, aInstallSISFile.iNonRemovable, aInstallSISFile.iGenerateRomStub))
   331 	if (!IsValidUpgrade(file, aInstallSISFile.iSUFlag, aInstallSISFile.iNonRemovable))
   344 	{
   332 	{
   345 		return INVALID_UPGRADE;
   333 		return INVALID_UPGRADE;
   346 	}
   334 	}
   347 
   335 
   348 	InstallableFiles installable;
   336 	InstallableFiles installable;
   349 	GetInstallableFiles(file, installable, *iExpressionEvaluator, aInstallSISFile.iTargetDrive, 
   337 	GetInstallableFiles(file, installable, *iExpressionEvaluator, aInstallSISFile.iTargetDrive);
   350 									iParamList.SystemDriveLetter(), aInstallSISFile.iGenerateRomStub);
       
   351 
   338 
   352 	// Uninstall the same package (if found) prior to any installation
   339 	// Uninstall the same package (if found) prior to any installation
   353 	UninstallPkg(file, aInstallSISFile.iGenerateRomStub);
   340 	UninstallPkg(file);
   354 
   341 
   355 	CheckDestinations(file, installable, aInstallSISFile);
   342 	CheckDestinations(file, installable, aInstallSISFile);
   356 
   343 
   357 	InstallFiles(installable, iParamList.SystemDriveLetter(), aInstallSISFile.iGenerateRomStub);
   344 	InstallFiles(installable, iParamList.SystemDriveLetter());
   358 
   345 
   359 	UpdateRegistry(file, installable, aInstallSISFile, aInstallSISFile.iSUFlag);
   346 	UpdateRegistry(file, installable, aInstallSISFile, aInstallSISFile.iSUFlag);
   360 	
   347 	
   361 	if (aInstallSISFile.iGenerateStub)
   348 	if (aInstallSISFile.iGenerateStub)
   362 	{
   349 	{
   363 		CreateStubSisFile(aInstallSISFile, file);
   350 		CreateStubSisFile(aInstallSISFile, file);
   364 	}
       
   365 
       
   366 	if (aInstallSISFile.iGenerateRomStub)
       
   367 	{
       
   368 		CreateRomStubSisFile(aInstallSISFile, file);
       
   369 	}
   351 	}
   370 
   352 
   371 	FreeInstallableFiles(installable);
   353 	FreeInstallableFiles(installable);
   372 
   354 
   373 	return SUCCESS;
   355 	return SUCCESS;
   464 
   446 
   465 	// case c)
   447 	// case c)
   466 	return (stubExistsInRom && (romUpgradableSA || puInstall || spInstall));    	
   448 	return (stubExistsInRom && (romUpgradableSA || puInstall || spInstall));    	
   467 }
   449 }
   468 
   450 
   469 void Installer::UninstallPkg(const SisFile& aSis, const bool aGenerateRomStub)
   451 void Installer::UninstallPkg(const SisFile& aSis)
   470 {
   452 {
   471 	TUint32 uid = aSis.GetPackageUid();
   453 	TUint32 uid = aSis.GetPackageUid();
   472 	TUint32 installType = aSis.GetInstallType();
   454 	TUint32 installType = aSis.GetInstallType();
   473 
   455 
   474 	// Check to see the SA is installed, otherwise, RemovePkg() will throw an exception
   456 	// Check to see the SA is installed, otherwise, RemovePkg() will throw an exception
   475 	if (iRegistry.IsInstalled(uid) && (installType == CSISInfo::EInstInstallation))
   457 	if (iRegistry.IsInstalled(uid) && (installType == CSISInfo::EInstInstallation))
   476 	{
   458 	{
   477 		LINFO(L"Removing package \"" << aSis.GetPackageName().c_str() << L"\" prior to re-installation");
   459 		LINFO(L"Removing package \"" << aSis.GetPackageName() << L"\" prior to re-installation");
   478 
   460 
   479 		// Remove all installed files for this Uid's packages and all the SisRegistry Entries
   461 		// Remove all installed files for this Uid's packages and all the SisRegistry Entries
   480 		iRegistry.RemovePkg(uid, true);
   462 		iRegistry.RemovePkg(uid, true);
   481 	}
   463 	}
   482 
   464 
   483 	if (installType == CSISInfo::EInstAugmentation)
   465 	if (installType == CSISInfo::EInstAugmentation)
   484 	{
   466 	{
   485 		// Clean up the installed files from the specified SP package and the SisRegistry Entry
   467 		// Clean up the installed files from the specified SP package and the SisRegistry Entry
   486 		iRegistry.RemoveEntry(uid, aSis.GetPackageName().c_str(), aSis.GetVendorName().c_str());
   468 		iRegistry.RemoveEntry(uid, aSis.GetPackageName(), aSis.GetVendorName());
   487 	}
   469 	}
   488 
   470 
   489 	if(!aGenerateRomStub)
   471 	// Regenerate the ROM stub registry entries for eclipsing check later.
   490 	{
   472 	iRegistry.GenerateStubRegistry();
   491 		// Regenerate the ROM stub registry entries for eclipsing check later.
       
   492 		iRegistry.GenerateStubRegistry();
       
   493 	}
       
   494 	else
       
   495 	{
       
   496 		std::list<std::wstring> stubFileEntries;
       
   497 
       
   498 		iRegistry.GetStubFileEntries(uid, stubFileEntries);
       
   499 		if((!stubFileEntries.empty()))
       
   500 	    {
       
   501 			LINFO(L"Rom Stub Upgrade, removing \"" << iRegistry.GetRomStubFile() << L"\" prior to re-installation");
       
   502 			RemoveFile(iRegistry.GetRomStubFile());
       
   503 		
       
   504 			std::list<std::wstring>::const_iterator end = stubFileEntries.end();
       
   505 			for (std::list<std::wstring>::const_iterator curr = stubFileEntries.begin() ;
       
   506 			 curr != end; ++curr)
       
   507 			{
       
   508 				std::wstring file = *curr;
       
   509 				file[0]='z';
       
   510 				ConvertToLocalPath(file, iParamList.RomDrivePath());
       
   511 				RemoveFile(file);
       
   512 			}
       
   513 	 	}
       
   514 	}
       
   515 }
   473 }
   516 
   474 
   517 
   475 
   518 struct CheckDependencyMet
   476 struct CheckDependencyMet
   519 {
   477 {
   575 
   533 
   576 	return iMissing[aFile.GetPackageName()].size() == 0;
   534 	return iMissing[aFile.GetPackageName()].size() == 0;
   577 	}
   535 	}
   578 
   536 
   579 
   537 
   580 bool Installer::IsValidUpgrade(const SisFile& aFile, bool aSUFlag, bool aNonRemovable, bool aGenerateRomStub)
   538 bool Installer::IsValidUpgrade(const SisFile& aFile, bool aSUFlag, bool aNonRemovable)
   581 {
   539 {
   582 	TUint32 pkg = aFile.GetPackageUid();
   540 	TUint32 pkg = aFile.GetPackageUid();
   583 	TUint32 installFlags = aFile.GetInstallFlags();
   541 	TUint32 installFlags = aFile.GetInstallFlags();
   584 
   542 
   585 	if(aNonRemovable)
   543 	if(aNonRemovable)
   612 
   570 
   613 	TUint32 installType = aFile.GetInstallType();
   571 	TUint32 installType = aFile.GetInstallType();
   614 
   572 
   615 	if (iRegistry.IsInstalled(pkg))
   573 	if (iRegistry.IsInstalled(pkg))
   616 		{
   574 		{
   617 		if (aGenerateRomStub && (installType == CSISInfo::EInstAugmentation || installType == CSISInfo::EInstPartialUpgrade))
   575 		ValidateRegistry(aFile,pkg,installFlags,RUFlag,aNonRemovable);	
   618 			{
       
   619 			// Installing SP and PU to Rom (z) drive not allowed
       
   620 			std::stringstream err;
       
   621 			err << "Could not perform SP or PU upgrade for Rom (z) drive installation";
       
   622 			
       
   623 			throw InterpretSisError(err.str(), ATTEMPT_TO_UPGRADE_ROM_PKG);
       
   624 			}
       
   625 		else
       
   626 			{
       
   627 			ValidateRegistry(aFile,pkg,installFlags,RUFlag,aNonRemovable,aGenerateRomStub);	
       
   628 			}
       
   629 		}
   576 		}
   630 	else if (installType == CSISInfo::EInstAugmentation || installType == CSISInfo::EInstPartialUpgrade)
   577 	else if (installType == CSISInfo::EInstAugmentation || installType == CSISInfo::EInstPartialUpgrade)
   631 		{
   578 		{
   632 		if(iParamList.IsFlagSet(CParameterList::EFlagsRomInstallSet))
   579 		// Installing SP and PU without the base package
   633 			{
   580 		std::stringstream err;
   634 			// Installing SP and PU to Rom Drive is not supported.
   581 		err << "Could not perform upgrade - the base package 0x" << std::hex 
   635 			std::stringstream err;
   582 			<< pkg << " is missing";
   636 			err << "Installing SP and PU to Rom (z) Drive is not supported.";
   583 
   637 			throw InterpretSisError(err.str(), ATTEMPT_TO_UPGRADE_ROM_PKG);
   584 		throw InterpretSisError(err.str(), MISSING_BASE_PACKAGE);
   638 			}
       
   639 		else
       
   640 			{
       
   641 			// Installing SP and PU without the base package
       
   642 			std::stringstream err;
       
   643 			err << "Could not perform upgrade - the base package 0x" << std::hex 
       
   644 				<< pkg << " is missing";
       
   645 
       
   646 			throw InterpretSisError(err.str(), MISSING_BASE_PACKAGE);
       
   647 			}
       
   648 		}
   585 		}
   649 
   586 
   650 	return true;
   587 	return true;
   651 	}
   588 	}
   652 
   589 
   653 void Installer::ValidateRegistry(const SisFile& aFile, TUint32 aPckgUid, TUint32 aInstallFlags, 
   590 void Installer::ValidateRegistry(const SisFile& aFile, TUint32 aPckgUid, TUint32 aInstallFlags, bool aRUFlag, bool aNonRemovable)
   654 										bool aRUFlag, bool aNonRemovable, bool aGenerateRomStub)
       
   655 	{
   591 	{
   656 	bool isSisNonRemovable = aInstallFlags & CSISInfo::EInstFlagNonRemovable;
   592 	bool isSisNonRemovable = aInstallFlags & CSISInfo::EInstFlagNonRemovable;
   657 	bool isBaseRemovable = false;
   593 	bool isBaseRemovable = false;
   658 	bool inRom = false;
   594 	bool inRom = false;
   659 	bool isPreInstalled = false;
   595 	bool isPreInstalled = false;
   665 	// Check is this package has been installed before
   601 	// Check is this package has been installed before
   666 	TUint32 installType = aFile.GetInstallType();
   602 	TUint32 installType = aFile.GetInstallType();
   667 
   603 
   668 	if (installType == CSISInfo::EInstInstallation)
   604 	if (installType == CSISInfo::EInstInstallation)
   669 		{
   605 		{
   670 		if (inRom && !aRUFlag && !aGenerateRomStub)
   606 		if (inRom && !aRUFlag)
   671 			{
   607 			{
   672 			std::stringstream err;
   608 			std::stringstream err;
   673 			err << "Illegal SA upgrade to ROM package 0x" << std::hex << aPckgUid;
   609 			err << "Illegal SA upgrade to ROM package 0x" << std::hex << aPckgUid;
   674 			throw InterpretSisError(err.str(), ATTEMPT_TO_UPGRADE_ROM_PKG);
   610 			throw InterpretSisError(err.str(), ATTEMPT_TO_UPGRADE_ROM_PKG);
   675 			}
   611 			}
   676 		// This is not a ROM base package, check is there a SIS stub base package present
   612 		// This is not a ROM base package, check is there a SIS stub base package present
   677 		else if (iRegistry.IsRomStubPackage(aPckgUid) && !aRUFlag && !aGenerateRomStub)
   613 		else if (iRegistry.IsRomStubPackage(aPckgUid) && !aRUFlag)
   678 			{			
   614 			{			
   679 			std::stringstream err;
   615 			std::stringstream err;
   680 			err << "Indirect SA upgrade to ROM package 0x" << std::hex << aPckgUid
   616 			err << "Indirect SA upgrade to ROM package 0x" << std::hex << aPckgUid
   681 				<< " missing RU flag";
   617 				<< " missing RU flag";
   682 			throw InterpretSisError(err.str(), ATTEMPT_TO_UPGRADE_ROM_PKG);
   618 			throw InterpretSisError(err.str(), ATTEMPT_TO_UPGRADE_ROM_PKG);
   763 		}
   699 		}
   764 	#endif // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK	
   700 	#endif // SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK	
   765 	}
   701 	}
   766 
   702 
   767 bool Installer::GetInstallableFiles(const SisFile& aFile, InstallableFiles& aList, ExpressionEvaluator& aEvaluator, 
   703 bool Installer::GetInstallableFiles(const SisFile& aFile, InstallableFiles& aList, ExpressionEvaluator& aEvaluator, 
   768 									int aInstallingDrive, const int aSystemDrive, const bool aGenerateRomStub)
   704 									int aInstallingDrive)
   769 {
   705 {
   770 	return aFile.GetInstallableFiles(aList, aEvaluator, 
   706 	return aFile.GetInstallableFiles(aList, aEvaluator, 
   771 		iConfigManager.GetLocalDrivePath(aInstallingDrive), aInstallingDrive, aSystemDrive, aGenerateRomStub);
   707 		iConfigManager.GetLocalDrivePath(aInstallingDrive), aInstallingDrive);
   772 }
   708 }
   773 
   709 
   774 
   710 
   775 struct InstallFile
   711 struct InstallFile
   776 {
   712 {
   777 	InstallFile(const std::wstring& aCDrive, const int aSystemDrive, const bool aGenerateRomStub)
   713 	InstallFile(const std::wstring& aCDrive, const int aSystemDrive)
   778 		: iSystemDrivePath(aCDrive), iSystemDrive(aSystemDrive), iGenerateRomStub(aGenerateRomStub) {}
   714 		: iSystemDrivePath(aCDrive), iSystemDrive(aSystemDrive) {}
   779 
   715 
   780 	const std::wstring& iSystemDrivePath;
   716 	const std::wstring& iSystemDrivePath;
   781 	const int iSystemDrive;
   717 	const int iSystemDrive;
   782 	const bool iGenerateRomStub;
       
   783 
   718 
   784 	void operator()(const InstallableFile* aFile)
   719 	void operator()(const InstallableFile* aFile)
   785 	{
   720 	{
   786 		std::fstream output;
   721 		std::fstream output;
   787 		std::wstring target(aFile->GetTarget());
   722 		std::wstring target(aFile->GetTarget());
   794 			LINFO(L"Skipping file with empty destination filename");
   729 			LINFO(L"Skipping file with empty destination filename");
   795             }
   730             }
   796         else
   731         else
   797             {
   732             {
   798 			// Unicode characters can not be displayed on DOS prompt
   733 			// Unicode characters can not be displayed on DOS prompt
   799  			std::string temporary = wstring2string(target);
   734  			std::string temporary = Ucs2ToUtf8(target);
   800 			if(temporary[0]=='$')
   735 			std::wstring targetDisplay = Utf8ToUcs2( temporary );
   801 			{
       
   802 				temporary[0] = iSystemDrive;
       
   803 			}
       
   804 			std::wstring targetDisplay = string2wstring( temporary );
       
   805 		    LINFO(L"Installing file: " << targetDisplay);
   736 		    LINFO(L"Installing file: " << targetDisplay);
   806 
       
   807 			if(target[0]==L'$')
       
   808 			{
       
   809 				localTarget = target;
       
   810 				ConvertToLocalPath( localTarget, iSystemDrivePath );
       
   811 				target[0] = iSystemDrive;
       
   812 				aFile->SetTarget(target);
       
   813 			}
       
   814 
   737 
   815             std::wstring targetDirectory = localTarget.substr( 0, localTarget.rfind( KDirectorySeparator ) );    		
   738             std::wstring targetDirectory = localTarget.substr( 0, localTarget.rfind( KDirectorySeparator ) );    		
   816 			const unsigned char* buffer = NULL;
   739 			const unsigned char* buffer = NULL;
   817 			TUint32 len;
   740 			TUint32 len;
   818 
   741 
   827 			else // SA 
   750 			else // SA 
   828 			{
   751 			{
   829 				// if the FN option specified, leave the file creation
   752 				// if the FN option specified, leave the file creation
   830 				if (fileNullOption)
   753 				if (fileNullOption)
   831 				{
   754 				{
   832 					LINFO(L"File " << target.c_str() << L" contains \"Delete-File-On-Uninstall\" option." );
   755 					LINFO(L"File " << target << L" contains \"Delete-File-On-Uninstall\" option." );
   833 				}
   756 				}
   834 				else 
   757 				else 
   835 				{
   758 				{
   836 					if ( !MakeDir( targetDirectory ) )
   759 					if ( !MakeDir( targetDirectory ) )
   837 					{
   760 					{
   854 					}
   777 					}
   855 					CloseHandle(hFile);
   778 					CloseHandle(hFile);
   856 				}
   779 				}
   857 			}
   780 			}
   858 
   781 
   859 			if (aFile->IsExecutable() && !fileNullOption && !iGenerateRomStub)
   782 			if (aFile->IsExecutable() && !fileNullOption)
   860 			{
   783 			{
   861 				// register the hash
   784 				// register the hash
   862 				std::wstring basename = localTarget.substr( localTarget.rfind( KDirectorySeparator ) + 1 );
   785 				std::wstring basename = localTarget.substr( localTarget.rfind( KDirectorySeparator ) + 1 );
   863 				#ifndef __TOOLS2_LINUX__
   786 				std::wstring hashdir = iSystemDrivePath + L"\\sys\\hash\\";
   864 				// Remove the null character at the end and.
       
   865 				std::wstring tempStr = iSystemDrivePath.c_str();
       
   866 				std::wstring hashdir =  tempStr + L"\\sys\\hash\\";				
       
   867 				std::wstring reghashdir = L"$:\\sys\\hash\\";
   787 				std::wstring reghashdir = L"$:\\sys\\hash\\";
   868 				#else
       
   869 				std::wstring hashdir = iSystemDrivePath + L"/sys/hash/";
       
   870 				std::wstring reghashdir = L"$:/sys/hash/";
       
   871 				#endif
       
   872 
   788 
   873 				if ( !MakeDir( hashdir ) )
   789 				if ( !MakeDir( hashdir ) )
   874 				{
   790 				{
   875 					throw InterpretSisError(L"Directory Creation Error - "+hashdir,
   791 					throw InterpretSisError(L"Directory Creation Error - "+hashdir,
   876 													DIRECTORY_CREATION_ERROR);
   792 													DIRECTORY_CREATION_ERROR);
   877 				}
   793 				}
   878 
   794 
   879 				// hash file is always created on the system drive
   795 				// hash file is always created on the system drive
   880 				reghashdir[0] = iSystemDrive;
   796 				reghashdir[0] = iSystemDrive;
   881 
   797 
   882 				LINFO(L"\tCreating hash: " << reghashdir << basename.c_str());				
   798 				LINFO(L"\tCreating hash: " << reghashdir << basename);
       
   799 
   883 				std::wstring hash = hashdir + basename;
   800 				std::wstring hash = hashdir + basename;
   884 				HANDLE hFile = MakeSISOpenFile(hash.c_str(), GENERIC_WRITE, CREATE_ALWAYS);		
   801 				HANDLE hFile = MakeSISOpenFile(hash.c_str(), GENERIC_WRITE, CREATE_ALWAYS);		
   885 				if( INVALID_HANDLE_VALUE == hFile )
   802 				if( INVALID_HANDLE_VALUE == hFile )
   886 				{
   803 				{
   887 					throw InterpretSisError(L"FileOpenError - " + hashdir + basename, FILE_ERROR);
   804 					throw InterpretSisError(L"FileOpenError - " + hashdir + basename, FILE_ERROR);
   900         }
   817         }
   901 	}
   818 	}
   902 };
   819 };
   903 
   820 
   904 
   821 
   905 void Installer::InstallFiles(const InstallableFiles& aList, int aInstallDrive, const bool aGenerateRomStub)
   822 void Installer::InstallFiles(const InstallableFiles& aList, const int aInstallDrive)
   906 {
   823 {
   907 	if(aGenerateRomStub)
       
   908 		{
       
   909 		aInstallDrive = 'z'; //Rom Drive
       
   910 		}
       
   911 
       
   912 	std::wstring localTargetPath = iConfigManager.GetLocalDrivePath(aInstallDrive);
   824 	std::wstring localTargetPath = iConfigManager.GetLocalDrivePath(aInstallDrive);
   913 
   825 
   914 	std::for_each(aList.begin(), aList.end(), InstallFile(localTargetPath, aInstallDrive, aGenerateRomStub));
   826 	std::for_each(aList.begin(), aList.end(), InstallFile(localTargetPath, aInstallDrive));
   915 }
   827 }
   916 
   828 
   917 
   829 
   918 void Installer::UpdateRegistry(const SisFile& aFile, const InstallableFiles& aList, 
   830 void Installer::UpdateRegistry(const SisFile& aFile, const InstallableFiles& aList, 
   919 												   const InstallSISFile& aInstallSISFile, const bool aSUFlag)
   831 												   const InstallSISFile& aInstallSISFile, const bool aSUFlag)
   956 	FindAllAdornedVariants(searchNameWild, KSysBinPath, aAdornedFileNamesFound, driveMap);
   868 	FindAllAdornedVariants(searchNameWild, KSysBinPath, aAdornedFileNamesFound, driveMap);
   957 
   869 
   958 	// find all adorned variants in the ROM/ROFS logs
   870 	// find all adorned variants in the ROM/ROFS logs
   959 	if (iParamList.IsFlagSet(CParameterList::EFlagsRomRofsLogFilesSet))
   871 	if (iParamList.IsFlagSet(CParameterList::EFlagsRomRofsLogFilesSet))
   960 	{
   872 	{
   961 	#ifndef __TOOLS2_LINUX__
       
   962 		std::wstring romSearchNameWild = L"z:\\sys\\bin\\";
   873 		std::wstring romSearchNameWild = L"z:\\sys\\bin\\";
   963 	#else
       
   964 		std::wstring romSearchNameWild = L"z:/sys/bin/";
       
   965 	#endif
       
   966 		romSearchNameWild.append(searchNameWild);
   874 		romSearchNameWild.append(searchNameWild);
   967 		iRomManager.FindAllAdornedVariants(romSearchNameWild, aAdornedFileNamesFound);
   875 		iRomManager.FindAllAdornedVariants(romSearchNameWild, aAdornedFileNamesFound);
   968 	}
   876 	}
   969 }
   877 }
   970 
   878 
  1073 		}
   981 		}
  1074 		else if (disk == 'z') // case (2)
   982 		else if (disk == 'z') // case (2)
  1075 		{
   983 		{
  1076 			// we are eclipsing a ROM file, check if this is authorised:
   984 			// we are eclipsing a ROM file, check if this is authorised:
  1077 			// see implementation of IsEclipsable()
   985 			// see implementation of IsEclipsable()
  1078 			#ifndef __TOOLS2_LINUX__
       
  1079 			if (!IsEclipsable(searchNameUnadorned, aSUFlag))
   986 			if (!IsEclipsable(searchNameUnadorned, aSUFlag))
  1080 			#else
       
  1081 			if (!IsEclipsable(searchNameUnadorned, aSUFlag, localDir))
       
  1082 			#endif
       
  1083 			{
   987 			{
  1084 				result = false;
   988 				result = false;
  1085 				break;
   989 				break;
  1086 			}
   990 			}
  1087 		}
   991 		}
  1092 
   996 
  1093 		// now check to see whether the unadorned or the adorned filename found on 
   997 		// now check to see whether the unadorned or the adorned filename found on 
  1094 		// this drive should be added to iEclipsableOverwriteFiles.
   998 		// this drive should be added to iEclipsableOverwriteFiles.
  1095 		if (processEclipsingSuspectsFoundOnThisDrive && unadornedFound)
   999 		if (processEclipsingSuspectsFoundOnThisDrive && unadornedFound)
  1096 		{
  1000 		{
  1097 			iEclipsableOverwriteFiles.push_back(searchNameUnadorned.c_str());
  1001 			iEclipsableOverwriteFiles.push_back(searchNameUnadorned);
  1098 		}
  1002 		}
  1099 
  1003 
  1100 		if (processEclipsingSuspectsFoundOnThisDrive && adornedFound)
  1004 		if (processEclipsingSuspectsFoundOnThisDrive && adornedFound)
  1101 		{
  1005 		{
  1102 			nrOfAdornedFilenamesFound = adornedFileNamesFound.size();
  1006 			nrOfAdornedFilenamesFound = adornedFileNamesFound.size();
  1108 			{
  1012 			{
  1109 				std::wstring adornedFile = *index;
  1013 				std::wstring adornedFile = *index;
  1110 				int drive = tolower(adornedFile[0]);
  1014 				int drive = tolower(adornedFile[0]);
  1111 				if (drive == disk)
  1015 				if (drive == disk)
  1112 				{
  1016 				{
  1113 					iEclipsableOverwriteFiles.push_back(adornedFile.c_str());
  1017 					iEclipsableOverwriteFiles.push_back(adornedFile);
  1114 				}
  1018 				}
  1115 			}
  1019 			}
  1116 		}
  1020 		}
  1117 	}
  1021 	}
  1118 	// end of loop
  1022 	// end of loop
  1181       and we have z:\sys\bin\A.dll as an eclipsable file or any z:\sys\bin\A{????????}.dll
  1085       and we have z:\sys\bin\A.dll as an eclipsable file or any z:\sys\bin\A{????????}.dll
  1182       then we are allowed to eclipse.
  1086       then we are allowed to eclipse.
  1183  @param aRomFile fully qualified filename in ROM that is to be checked for eclipising (i.e: z:\sys\bin\some.dll)
  1087  @param aRomFile fully qualified filename in ROM that is to be checked for eclipising (i.e: z:\sys\bin\some.dll)
  1184  @param aSUFlag specifies if the installing SIS file has been signed by a SU certificate
  1088  @param aSUFlag specifies if the installing SIS file has been signed by a SU certificate
  1185 */
  1089 */
  1186 #ifndef __TOOLS2_LINUX__
       
  1187 bool Installer::IsEclipsable(std::wstring& aRomFile, bool aSUFlag)
  1090 bool Installer::IsEclipsable(std::wstring& aRomFile, bool aSUFlag)
  1188 #else
       
  1189 bool Installer::IsEclipsable(std::wstring& aRomFile, bool aSUFlag, const std::wstring& aDrivePath)
       
  1190 #endif
       
  1191 {
  1091 {
  1192 	// SA/SP/PU sis + RU flag + signed by SU root cert is allowed
  1092 	// SA/SP/PU sis + RU flag + signed by SU root cert is allowed
  1193 	if (aSUFlag)
  1093 	if (aSUFlag)
  1194 		return true;
  1094 		return true;
  1195 
  1095 
  1209 			isEclipsable = true;
  1109 			isEclipsable = true;
  1210 			break;
  1110 			break;
  1211 		}
  1111 		}
  1212 		else if (goesToSysBin) // case 2
  1112 		else if (goesToSysBin) // case 2
  1213 		{
  1113 		{
  1214 			#ifndef __TOOLS2_LINUX__
       
  1215 			if (IsAdornedVariationOf(eclipsableRomFile,aRomFile))
  1114 			if (IsAdornedVariationOf(eclipsableRomFile,aRomFile))
  1216 			#else
       
  1217 			if (IsAdornedVariationOf(eclipsableRomFile,aRomFile,aDrivePath))
       
  1218 			#endif
       
  1219 			{
  1115 			{
  1220 				isEclipsable = true;
  1116 				isEclipsable = true;
  1221 				break;
  1117 				break;
  1222 			}
  1118 			}
  1223 		}
  1119 		}
  1224 	}
  1120 	}
  1225 
  1121 
  1226 	return isEclipsable;
  1122 	return isEclipsable;
  1227 }
       
  1228 
       
  1229 /** This function handles file overwriting scenarios from Stub SIS files only and not from SISregistry.
       
  1230       (i.e: we are trying to install z:\somedir\somename.ext however it already exists)
       
  1231  @param aFile the SIS file to be installed
       
  1232  @param aTarget The fully qualified filename (full path and name)
       
  1233 */
       
  1234 void Installer::HandleRomFileOverwriting(const SisFile& aFile, const std::wstring& aTarget)
       
  1235 {
       
  1236 	// find out which Rom Stub this file belongs to
       
  1237 	TUint32 owningUid = 0;
       
  1238 	CSISController* sisController = iRegistry.GetStubControllerUid(aTarget);
       
  1239 
       
  1240 	if(sisController)
       
  1241 	{
       
  1242 		owningUid=sisController->UID1();
       
  1243 	}
       
  1244 
       
  1245 	// no package owns this file. Always allow orphaned file overwriting!
       
  1246 	if (owningUid == 0)
       
  1247 	{
       
  1248 		LWARN(aTarget << L" overwrites orphaned file");
       
  1249 	}
       
  1250 	else if (aFile.GetPackageUid() != owningUid)
       
  1251 	{
       
  1252 		std::wostringstream os;
       
  1253 		os << aTarget.c_str() << L" overwrites file from package 0x" << std::hex << owningUid << L" \"" << sisController->SISInfo().PackageName(0) << L"\"" << std::endl;
       
  1254 		iProblemFiles.append(os.str());
       
  1255 		iError = ECLIPSING_VIOLATION;
       
  1256 	}
       
  1257 	
       
  1258 	if(sisController)
       
  1259 	{
       
  1260 		delete sisController;	
       
  1261 	}
       
  1262 }
  1123 }
  1263 
  1124 
  1264 /** This function handles overwriting scenarios (i.e: we are trying to install c:\somedir\somename.ext however it already exists)
  1125 /** This function handles overwriting scenarios (i.e: we are trying to install c:\somedir\somename.ext however it already exists)
  1265  In this case we have 2 possibilities:
  1126  In this case we have 2 possibilities:
  1266  1) We are correctly overwriting the already present file (a PU)
  1127  1) We are correctly overwriting the already present file (a PU)
  1282 	if (owningUid == 0)
  1143 	if (owningUid == 0)
  1283 	{
  1144 	{
  1284 		// do not display a warning if the installing file is a PA. The user
  1145 		// do not display a warning if the installing file is a PA. The user
  1285 		// needs to copy the installing files to the installing directory
  1146 		// needs to copy the installing files to the installing directory
  1286 		// prior to installing the SIS file.
  1147 		// prior to installing the SIS file.
  1287 		std::string tempTarget = wstring2string(aTarget);
  1148 		std::string tempTarget = Ucs2ToUtf8(aTarget);
  1288   	  	std::wstring targetDisplay = string2wstring( tempTarget );
  1149   	  	std::wstring targetDisplay = Utf8ToUcs2( tempTarget );
  1289 		if (aFile.GetInstallType() == CSISInfo::EInstPreInstalledApp)
  1150 		if (aFile.GetInstallType() == CSISInfo::EInstPreInstalledApp)
  1290 		{
  1151 		{
  1291 			LINFO(targetDisplay << L" found for PA installation");
  1152 			LINFO(targetDisplay << L" found for PA installation");
  1292 		}
  1153 		}
  1293 		else
  1154 		else
  1299 	{
  1160 	{
  1300 		// SP can not overwrite a file in the base pkg
  1161 		// SP can not overwrite a file in the base pkg
  1301 		if (isSp)
  1162 		if (isSp)
  1302 		{
  1163 		{
  1303 			std::wostringstream os;
  1164 			std::wostringstream os;
  1304 			os << aTarget.c_str() << L" overwrites file from base package 0x" << std::hex << owningUid << L" \"" << owningObj->GetPackageName() << L"\"" << std::endl;
  1165 			os << aTarget << L" overwrites file from base package 0x" << std::hex << owningUid << L" \"" << owningObj->GetPackageName() << L"\"" << std::endl;
  1305 			iProblemFiles.append(os.str());
  1166 			iProblemFiles.append(os.str());
  1306 			iError = ECLIPSING_VIOLATION;
  1167 			iError = ECLIPSING_VIOLATION;
  1307 		}
  1168 		}
  1308 	}
  1169 	}
  1309 	else
  1170 	else
  1312 		// PU/SA can not overwrite a file belonging to a different base pkg unless it has been signed by
  1173 		// PU/SA can not overwrite a file belonging to a different base pkg unless it has been signed by
  1313 		// a SU cert
  1174 		// a SU cert
  1314 		if (isSp || (!aSUFlag && (isPu || isSa)))
  1175 		if (isSp || (!aSUFlag && (isPu || isSa)))
  1315 		{
  1176 		{
  1316 			std::wostringstream os;
  1177 			std::wostringstream os;
  1317 			os << aTarget.c_str() << L" overwrites file from base package 0x" << std::hex << owningUid << L" \"" << owningObj->GetPackageName() << L"\"" << std::endl;
  1178 			os << aTarget << L" overwrites file from base package 0x" << std::hex << owningUid << L" \"" << owningObj->GetPackageName() << L"\"" << std::endl;
  1318 			iProblemFiles.append(os.str());
  1179 			iProblemFiles.append(os.str());
  1319 			iError = ECLIPSING_VIOLATION;
  1180 			iError = ECLIPSING_VIOLATION;
  1320 		}
  1181 		}
  1321 		else
  1182 		else
  1322 		{
  1183 		{
  1323 		    LWARN(aTarget.c_str() << L" overwrites file from base package 0x" << std::hex << owningUid << L" \"" << owningObj->GetPackageName() << L"\"");
  1184 			LWARN(aTarget << L" overwrites file from base package 0x" << std::hex << owningUid << L" \"" << owningObj->GetPackageName() << L"\"");
  1324 		}
  1185 		}
  1325 	}
  1186 	}
  1326 }
  1187 }
  1327 
  1188 
  1328 void Installer::WarnEclipseOverWrite(const SisFile& aFile)
  1189 void Installer::WarnEclipseOverWrite(const SisFile& aFile)
  1338 		for ( ; curr != end; ++curr)
  1199 		for ( ; curr != end; ++curr)
  1339 		{
  1200 		{
  1340 			std::wstring eclipseFile(*curr);
  1201 			std::wstring eclipseFile(*curr);
  1341 
  1202 
  1342 			TUint32 owningUid = 0;
  1203 			TUint32 owningUid = 0;
  1343 			const SisRegistryObject* owningObj = iRegistry.OwningPackage(eclipseFile.c_str(), owningUid);
  1204 			const SisRegistryObject* owningObj = iRegistry.OwningPackage(eclipseFile, owningUid);
  1344 			
  1205 			
  1345 			// always allow orphaned file overwriting
  1206 			// always allow orphaned file overwriting
  1346 			if (owningUid == 0)
  1207 			if (owningUid == 0)
  1347 			{
  1208 			{
  1348 			    LWARN(eclipseFile.c_str() << L" eclipses orphaned file.");
  1209 				LWARN(eclipseFile << L" eclipses orphaned file.");
  1349 			}
  1210 			}
  1350 			else
  1211 			else
  1351 			{
  1212 			{
  1352 				// SP/PU can not overwrite a file belonging to a different base pkg or
  1213 				// SP/PU can not overwrite a file belonging to a different base pkg or
  1353 				// SP/PU can not eclipse a base package which is not in the ROM.
  1214 				// SP/PU can not eclipse a base package which is not in the ROM.
  1354 				std::wostringstream os;
  1215 				std::wostringstream os;
  1355 				os << eclipseFile.c_str() << L" eclipses file from package 0x"  << std::hex << owningUid << L" \"" << owningObj->GetPackageName().c_str() << L"\""<< std::endl;
  1216 				os << eclipseFile << L" eclipses file from package 0x" << std::hex << owningUid << L" \"" << owningObj->GetPackageName() << L"\"" << std::endl;
  1356 				iProblemFiles.append(os.str());
  1217 				iProblemFiles.append(os.str());
  1357 				iError = ECLIPSING_VIOLATION;
  1218 				iError = ECLIPSING_VIOLATION;
  1358 				continue;
  1219 				continue;
  1359 			}
  1220 			}
  1360 		}		
  1221 		}		
  1372 	iError = SUCCESS;
  1233 	iError = SUCCESS;
  1373 
  1234 
  1374 	Sids sids;
  1235 	Sids sids;
  1375 	GetSidsFromInstallable(aFiles, sids);
  1236 	GetSidsFromInstallable(aFiles, sids);
  1376 
  1237 
  1377 	#ifndef __TOOLS2_LINUX__
       
  1378 	const std::wstring privatePath = L":\\private\\";
  1238 	const std::wstring privatePath = L":\\private\\";
  1379 	const std::wstring sysPath = L":\\sys\\";
  1239 	const std::wstring sysPath = L":\\sys\\";
  1380 	const std::wstring sysBinPath = L":\\sys\\bin\\";
  1240 	const std::wstring sysBinPath = L":\\sys\\bin\\";
  1381 	const std::wstring resourcePath = L":\\resource\\";
  1241 	const std::wstring resourcePath = L":\\resource\\";
  1382 	#else
       
  1383 	const std::wstring privatePath = L":/private/";
       
  1384 	const std::wstring sysPath = L":/sys/";
       
  1385 	const std::wstring sysBinPath = L":/sys/bin/";
       
  1386 	const std::wstring resourcePath = L":/resource/";
       
  1387 	#endif
       
  1388 	const std::wstring exeType = L".exe";
  1242 	const std::wstring exeType = L".exe";
  1389 
  1243 
  1390     int num_of_files = aFiles.size();
  1244     int num_of_files = aFiles.size();
  1391 	TUint32 pkgUid = aFile.GetPackageUid();
  1245 	TUint32 pkgUid = aFile.GetPackageUid();
  1392 	TUint32 installType = aFile.GetInstallType();
  1246 	TUint32 installType = aFile.GetInstallType();
       
  1247 	std::list<std::wstring> stubFileEntries;
       
  1248 
       
  1249 	iRegistry.GetStubFileEntries(pkgUid, stubFileEntries);
  1393 
  1250 
  1394 	// if a base package exists, check to see if it chains back to a ROM stub. If so, populate
  1251 	// if a base package exists, check to see if it chains back to a ROM stub. If so, populate
  1395 	// iEclipsableRomFiles with the files owned by the ROM stub. Only ROM files can be eclipsed.
  1252 	// iEclipsableRomFiles with the files owned by the ROM stub. Only ROM files can be eclipsed.
  1396 	//
  1253 	//
  1397 	// if the package has been signed by a SU cert, then there is no need to generate the eclipsable
  1254 	// if the package has been signed by a SU cert, then there is no need to generate the eclipsable
  1406 	{   
  1263 	{   
  1407 		const InstallableFile* file = aFiles[ ii ];
  1264 		const InstallableFile* file = aFiles[ ii ];
  1408         const CSISFileDescription* sisDescription = file->FileDescription();
  1265         const CSISFileDescription* sisDescription = file->FileDescription();
  1409 
  1266 
  1410 		// file to be installed
  1267 		// file to be installed
  1411 		std::wstring target( file->GetTarget().c_str() );
  1268 		std::wstring target( file->GetTarget() );
  1412 
  1269 
  1413 		if (sisDescription->Operation() == CSISFileDescription::EOpText)
  1270 		if (sisDescription->Operation() == CSISFileDescription::EOpText)
  1414 			break;
  1271 			break;
  1415 		if (sisDescription->Operation() == CSISFileDescription::EOpNull)
  1272 		if (sisDescription->Operation() == CSISFileDescription::EOpNull)
  1416 			{
  1273 			{
  1417 			// a FN file can not remove a file from \sys or \resource
  1274 			// a FN file can not remove a file from \sys or \resource
  1418 			if ((target.find(sysPath,0) != std::wstring::npos) || (target.find(resourcePath,0) != std::wstring::npos))
  1275 			if ((target.find(sysPath,0) != std::wstring::npos) || (target.find(resourcePath,0) != std::wstring::npos))
  1419 				{
  1276 				{
  1420 				// eclipsing problem
  1277 				// eclipsing problem
  1421 				std::wostringstream os;
  1278 				std::wostringstream os;
  1422 				os << L"FN file \"" << target.c_str() << L"\" can not remove a file from \\sys or \\resource" << std::endl;
  1279 				os << L"FN file \"" << target << L"\" can not remove a file from \\sys or \\resource" << std::endl;
  1423 				iProblemFiles.append(os.str());
  1280 				iProblemFiles.append(os.str());
  1424 				iError = DATA_CAGE_VIOLATION;
  1281 				iError = DATA_CAGE_VIOLATION;
  1425 				continue;
  1282 				continue;
  1426 				}
  1283 				}
  1427 			}
  1284 			}
  1428         else 
  1285         else 
  1429             {
  1286             {
  1430 			std::wstring realTarget(file->GetLocalTarget().c_str());
  1287 			std::wstring realTarget(file->GetLocalTarget());
  1431 
  1288 
  1432 		    std::wstring romTarget(target);
  1289 		    std::wstring romTarget(target);
  1433 			romTarget[0] = KRomDriveLetter;
  1290 			romTarget[0] = KRomDriveLetter;
  1434 
  1291 
  1435 			// check to see if we are legally allowed to eclipse a ROM file 
  1292 			// check to see if we are legally allowed to eclipse a ROM file 
  1437 			{
  1294 			{
  1438 				if (!ValidEclipse(aFile, target, *file, suFlag))
  1295 				if (!ValidEclipse(aFile, target, *file, suFlag))
  1439 				{
  1296 				{
  1440 					// eclipsing problem
  1297 					// eclipsing problem
  1441 					std::wostringstream os;
  1298 					std::wostringstream os;
  1442 					os << target.c_str() << L" eclipses file from ROM" << std::endl;
  1299 					os << target << L" eclipses file from ROM" << std::endl;
  1443 					iProblemFiles.append(os.str());
  1300 					iProblemFiles.append(os.str());
  1444 					iError = ECLIPSING_VIOLATION;
  1301 					iError = ECLIPSING_VIOLATION;
  1445 					continue;
  1302 					continue;
  1446 				}
       
  1447 			}
       
  1448 
       
  1449 			if(aInstallSISFile.iGenerateRomStub)
       
  1450 			{
       
  1451 				bool isOverwrite = FileExists(file->GetLocalTarget());
       
  1452 				// To check if We are incorrectly overwriting the file present.
       
  1453 				if (isOverwrite)
       
  1454 				{
       
  1455 					HandleRomFileOverwriting(aFile, target);
       
  1456 				}
  1303 				}
  1457 			}
  1304 			}
  1458 			
  1305 			
  1459 			// additional platsec checks
  1306 			// additional platsec checks
  1460 			if (target.find(privatePath) != std::wstring::npos)
  1307 			if (target.find(privatePath) != std::wstring::npos)
  1499 						// this package is trying to write to a SID's private directory 
  1346 						// this package is trying to write to a SID's private directory 
  1500 						// which does not belong to this package
  1347 						// which does not belong to this package
  1501 
  1348 
  1502 						const int KUidStringLength = 8;
  1349 						const int KUidStringLength = 8;
  1503 						std::wstring importPath = privatePath;
  1350 						std::wstring importPath = privatePath;
  1504 						#ifndef __TOOLS2_LINUX__
  1351 
  1505 						importPath.append( uidStr.str() + L"\\import" );
  1352 						importPath.append( uidStr.str() + L"\\import" );
  1506 						#else
       
  1507 						importPath.append( uidStr.str() + L"/import" );
       
  1508 						#endif
       
  1509 
  1353 
  1510 						if ((target.find(importPath,0) == std::wstring::npos) && !suFlag)
  1354 						if ((target.find(importPath,0) == std::wstring::npos) && !suFlag)
  1511 						{
  1355 						{
  1512 							// only SA with RU + SU and PU with RU + SU flag can override other private directory
  1356 							// only SA with RU + SU and PU with RU + SU flag can override other private directory
  1513 							std::wostringstream os;
  1357 							std::wostringstream os;
  1514 							os << target.c_str() << L" cannot be written to a private directory which "
  1358 							os << target << L" cannot be written to a private directory which "
  1515 								<< L"does not belong to any exe in this package" << std::endl;
  1359 								<< L"does not belong to any exe in this package" << std::endl;
  1516 							iProblemFiles.append(os.str());
  1360 							iProblemFiles.append(os.str());
  1517 							iError = DATA_CAGE_VIOLATION;
  1361 							iError = DATA_CAGE_VIOLATION;
  1518 							continue;
  1362 							continue;
  1519 						}
  1363 						}
  1579 					
  1423 					
  1580 					if (!allowSidEclipse)
  1424 					if (!allowSidEclipse)
  1581 					{
  1425 					{
  1582 						std::wostringstream os;
  1426 						std::wostringstream os;
  1583 										
  1427 										
  1584 						os << L"The existing file " << owningSidFile.c_str() << L" already has the SID 0x" << std::hex << sid
  1428 						os << L"The existing file " << owningSidFile << L" already has the SID 0x" << std::hex << sid
  1585 						   << std::dec << L", cannot install " << target.c_str() << std::endl;
  1429 						   << std::dec << L", cannot install " << target << std::endl;
  1586 						iProblemFiles.append(os.str());
  1430 						iProblemFiles.append(os.str());
  1587 						iError = DUPLICATE_SID;
  1431 						iError = DUPLICATE_SID;
  1588 						continue;
  1432 						continue;
  1589 					}
  1433 					}
  1590 				}
  1434 				}
  1604 							sisController->InstallBlock().GetFileList(fileDesList);
  1448 							sisController->InstallBlock().GetFileList(fileDesList);
  1605 							for(TFileDescListConstIter iter = fileDesList.begin(); iter != fileDesList.end(); ++iter)
  1449 							for(TFileDescListConstIter iter = fileDesList.begin(); iter != fileDesList.end(); ++iter)
  1606 							{
  1450 							{
  1607 								const CSISFileDescription* fD = *iter;
  1451 								const CSISFileDescription* fD = *iter;
  1608 
  1452 
  1609 								std::wstring romStubTarget(fD->Target().GetString().c_str());
  1453 								std::wstring romStubTarget(fD->Target().GetString());
  1610 
  1454 
  1611 								if (StringUtils::WildcardCompare(romStubTarget,romFileWithDuplicateSid))
  1455 								if (StringUtils::WildcardCompare(romStubTarget,romFileWithDuplicateSid))
  1612 								{
  1456 								{
  1613 									ownedByRomStub = true;
  1457 									ownedByRomStub = true;
  1614 									break;
  1458 									break;
  1625 					if (!allowSidEclipse && !ownedByRomStub)
  1469 					if (!allowSidEclipse && !ownedByRomStub)
  1626 					{
  1470 					{
  1627 						std::wostringstream os;
  1471 						std::wostringstream os;
  1628 											
  1472 											
  1629 						os << L"A ROM file already has the SID 0x" << std::hex << file->Sid()
  1473 						os << L"A ROM file already has the SID 0x" << std::hex << file->Sid()
  1630 						   << std::dec << L", cannot install " << target.c_str() << std::endl;
  1474 						   << std::dec << L", cannot install " << target << std::endl;
  1631 						iProblemFiles.append(os.str());
  1475 						iProblemFiles.append(os.str());
  1632 						iError = DUPLICATE_SID;
  1476 						iError = DUPLICATE_SID;
  1633 						continue;
  1477 						continue;
  1634 					}
  1478 					}
  1635 				}
  1479 				}
  1636 		    }
  1480 		    }
  1637 		    else if (realTarget.find(sysBinPath) != std::wstring::npos)
  1481 		    else if (realTarget.find(sysBinPath) != std::wstring::npos)
  1638 		    {
  1482 		    {
  1639 				std::wostringstream os;
  1483 				std::wostringstream os;
  1640 				os << target.c_str() << L" cannot be installed to a data caged area" << std::endl;
  1484 				os << target << L" cannot be installed to a data caged area" << std::endl;
  1641 				iProblemFiles.append(os.str());
  1485 				iProblemFiles.append(os.str());
  1642 				iError = DATA_CAGE_VIOLATION;
  1486 				iError = DATA_CAGE_VIOLATION;
  1643 				continue;
  1487 				continue;
  1644 		    }
  1488 		    }
  1645         }
  1489         }
  1651 	iEclipsableOverwriteFiles.clear();
  1495 	iEclipsableOverwriteFiles.clear();
  1652 	iEclipsableRomFiles.clear();
  1496 	iEclipsableRomFiles.clear();
  1653 
  1497 
  1654 	if (!iProblemFiles.empty())
  1498 	if (!iProblemFiles.empty())
  1655 	{
  1499 	{
  1656 		std::string x = wstring2string(iProblemFiles);
  1500 		std::string x;
  1657 		throw InvalidSis("", x, iError);
  1501 		throw InvalidSis("", Ucs2ToUtf8(iProblemFiles,x), iError);
  1658 	}
  1502 	}
  1659 }
  1503 }
  1660 
  1504 
  1661 void Installer::SetupExpressionEnvironment(const SisFile& aFile, const SisRegistry& aSisRegistry, RomManager& aRomManager )
  1505 void Installer::SetupExpressionEnvironment(const SisFile& aFile, const SisRegistry& aSisRegistry, RomManager& aRomManager )
  1662 {
  1506 {
  1686 		 }
  1530 		 }
  1687 	}
  1531 	}
  1688 }
  1532 }
  1689 
  1533 
  1690 
  1534 
  1691 void Installer::CreateRomStubSisFile(const InstallSISFile& aInstallSISFile, SisFile& aSis)
  1535 void Installer::CreateStubSisFile(const InstallSISFile& aInstallSISFile, SisFile& aSis)
  1692 {
  1536 {
  1693 
       
  1694 	int targetDrive = aInstallSISFile.iTargetDrive;
  1537 	int targetDrive = aInstallSISFile.iTargetDrive;
  1695 	std::wstring drivePath = iConfigManager.GetLocalDrivePath(targetDrive);
  1538 	std::wstring drivePath = iConfigManager.GetLocalDrivePath(targetDrive);
  1696 
  1539 	
  1697 	#ifndef __TOOLS2_LINUX__
       
  1698 	drivePath.append(L"\\system\\install\\");
       
  1699 	#else
       
  1700 	drivePath.append(L"/system/install/");
       
  1701 	#endif
       
  1702 
       
  1703 	// build Rom Stub Pathname
       
  1704 	if ( !MakeDir( drivePath ) )
       
  1705 	{
       
  1706 		throw InterpretSisError(L"Directory Creation Error - "+drivePath, DIRECTORY_CREATION_ERROR);
       
  1707 	}
       
  1708 
       
  1709 	size_t found;
       
  1710   	found=aInstallSISFile.iFileName.find_last_of(L"/\\");
       
  1711 	std::wstring sisFile = aInstallSISFile.iFileName.substr(found+1);
       
  1712 	std::wstring sisFilename = sisFile.substr(0,sisFile.length()-4);
       
  1713 	drivePath.append(sisFilename);
       
  1714 	drivePath.append(L"_");
       
  1715 	std::wstringstream sUid;
       
  1716 	sUid << std::hex << aSis.GetPackageUid();
       
  1717 	drivePath.append(sUid.str());
       
  1718 	drivePath.append(L".sis");
       
  1719 
       
  1720 	// Display the target SIS file. Format the stub SIS file string so it displays correctly.
       
  1721 	std::wstring ctrlDrive(L"z:");
       
  1722 	std::wstring ctrlTarget = drivePath.substr(iConfigManager.GetLocalDrivePath(targetDrive).length(),drivePath.length());
       
  1723 	ctrlDrive.append(ctrlTarget);
       
  1724 
       
  1725 	LINFO(L"\tCreating ROM stub: " << ctrlDrive);
       
  1726 	aSis.MakeSISRomStub(drivePath);
       
  1727 	// If the NR flag is set, change the file attribute to RO
       
  1728 }
       
  1729 
       
  1730 void Installer::CreateStubSisFile(const InstallSISFile& aInstallSISFile, SisFile& aSis)
       
  1731 {
       
  1732 	int targetDrive = aInstallSISFile.iTargetDrive;
       
  1733 	std::wstring drivePath = iConfigManager.GetLocalDrivePath(targetDrive);
       
  1734 	#ifndef __TOOLS2_LINUX__
       
  1735 	drivePath.append(L"\\private\\");
  1540 	drivePath.append(L"\\private\\");
  1736 	#else
       
  1737 	drivePath.append(L"/private/");
       
  1738 	#endif
       
  1739 
  1541 
  1740 	// build SwiDaemon Pathname
  1542 	// build SwiDaemon Pathname
  1741 	std::wstring ctrl = StringUtils::MakePathFromSID(drivePath, KSwiDaemonUid);
  1543 	std::wstring ctrl = StringUtils::MakePathFromSID(drivePath, KSwiDaemonUid);
  1742 
  1544 
  1743 	if ( !MakeDir( ctrl ) )
  1545 	if ( !MakeDir( ctrl ) )
  1747 
  1549 
  1748 	std::wstringstream s;
  1550 	std::wstringstream s;
  1749 	s << std::hex << aSis.GetPackageUid();
  1551 	s << std::hex << aSis.GetPackageUid();
  1750 
  1552 
  1751 	ctrl.append(s.str());
  1553 	ctrl.append(s.str());
       
  1554 
  1752 
  1555 
  1753 	switch(aSis.GetInstallType())
  1556 	switch(aSis.GetInstallType())
  1754     {
  1557     {
  1755 	case CSISInfo::EInstInstallation:
  1558 	case CSISInfo::EInstInstallation:
  1756 	case CSISInfo::EInstPreInstalledApp:
  1559 	case CSISInfo::EInstPreInstalledApp: