secureswitools/swisistools/source/interpretsislib/installer.cpp
branchRCL_3
changeset 24 5cc91383ab1e
parent 17 741e5bba2bd1
child 25 7333d7932ef7
--- a/secureswitools/swisistools/source/interpretsislib/installer.cpp	Thu Jul 15 18:47:04 2010 +0300
+++ b/secureswitools/swisistools/source/interpretsislib/installer.cpp	Thu Aug 19 10:02:49 2010 +0300
@@ -21,7 +21,9 @@
 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
 
 #include "dbhelper.h" 
-
+#ifndef __TOOLS2_LINUX__
+#include <windows.h>
+#endif 
 #endif //SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
 #include <exception>
 #include <sstream>
@@ -54,7 +56,11 @@
 // Constants
 const char KRomDriveLetter = 'z';
 const TUint32 KSwiDaemonUid = 0x10202DCE;
+#ifndef __TOOLS2_LINUX__
 const std::wstring KSysBinPath = L"\\sys\\bin\\";
+#else
+const std::wstring KSysBinPath = L"/sys/bin/";
+#endif
 
 TInt CheckWildCard(TInt aVal, TInt aReplace)
 {
@@ -111,7 +117,11 @@
 
 		// Ensure formatting is correct
 		if ( StringUtils::IsLastCharacter( shortName, KDirectorySeparator[ 0 ] ) ||
+			 #ifndef __TOOLS2_LINUX__
              StringUtils::IsLastCharacter( shortName, L'/' ) )
+             #else
+			 StringUtils::IsLastCharacter( shortName, L'\\' ) )
+			 #endif
 		{
 			shortName.erase(shortName.length()-1,1);
 		}
@@ -198,7 +208,7 @@
 			catch  (InterpretSisError& e)
 				{
 				LERROR(L"Failed installing " << (curr->iFileName));
-				LERROR(L"\t" << Utf8ToUcs2(e.what()));
+				LERROR(L"\t" << string2wstring(e.what()));
 				curr = sisFiles.erase(curr);
 				
 				if (result == 0)
@@ -465,7 +475,7 @@
 	if (installType == CSISInfo::EInstAugmentation)
 	{
 		// Clean up the installed files from the specified SP package and the SisRegistry Entry
-		iRegistry.RemoveEntry(uid, aSis.GetPackageName(), aSis.GetVendorName());
+		iRegistry.RemoveEntry(uid, aSis.GetPackageName().c_str(), aSis.GetVendorName().c_str());
 	}
 
 	// Regenerate the ROM stub registry entries for eclipsing check later.
@@ -731,8 +741,8 @@
         else
             {
 			// Unicode characters can not be displayed on DOS prompt
- 			std::string temporary = Ucs2ToUtf8(target);
-			std::wstring targetDisplay = Utf8ToUcs2( temporary );
+ 			std::string temporary = wstring2string(target);
+			std::wstring targetDisplay = string2wstring( temporary );
 		    LINFO(L"Installing file: " << targetDisplay);
 
             std::wstring targetDirectory = localTarget.substr( 0, localTarget.rfind( KDirectorySeparator ) );    		
@@ -783,8 +793,15 @@
 			{
 				// register the hash
 				std::wstring basename = localTarget.substr( localTarget.rfind( KDirectorySeparator ) + 1 );
-				std::wstring hashdir = iSystemDrivePath + L"\\sys\\hash\\";
+				#ifndef __TOOLS2_LINUX__
+				// Remove the null character at the end and.
+				std::wstring tempStr = iSystemDrivePath.c_str();
+				std::wstring hashdir =  tempStr + L"\\sys\\hash\\";				
 				std::wstring reghashdir = L"$:\\sys\\hash\\";
+				#else
+				std::wstring hashdir = iSystemDrivePath + L"/sys/hash/";
+				std::wstring reghashdir = L"$:/sys/hash/";
+				#endif
 
 				if ( !MakeDir( hashdir ) )
 				{
@@ -795,8 +812,7 @@
 				// hash file is always created on the system drive
 				reghashdir[0] = iSystemDrive;
 
-				LINFO(L"\tCreating hash: " << reghashdir << basename);
-
+				LINFO(L"\tCreating hash: " << reghashdir << basename.c_str());				
 				std::wstring hash = hashdir + basename;
 				HANDLE hFile = MakeSISOpenFile(hash.c_str(), GENERIC_WRITE, CREATE_ALWAYS);		
 				if( INVALID_HANDLE_VALUE == hFile )
@@ -870,7 +886,11 @@
 	// find all adorned variants in the ROM/ROFS logs
 	if (iParamList.IsFlagSet(CParameterList::EFlagsRomRofsLogFilesSet))
 	{
+	#ifndef __TOOLS2_LINUX__
 		std::wstring romSearchNameWild = L"z:\\sys\\bin\\";
+	#else
+		std::wstring romSearchNameWild = L"z:/sys/bin/";
+	#endif
 		romSearchNameWild.append(searchNameWild);
 		iRomManager.FindAllAdornedVariants(romSearchNameWild, aAdornedFileNamesFound);
 	}
@@ -983,7 +1003,11 @@
 		{
 			// we are eclipsing a ROM file, check if this is authorised:
 			// see implementation of IsEclipsable()
+			#ifndef __TOOLS2_LINUX__
 			if (!IsEclipsable(searchNameUnadorned, aSUFlag))
+			#else
+			if (!IsEclipsable(searchNameUnadorned, aSUFlag, localDir))
+			#endif
 			{
 				result = false;
 				break;
@@ -998,7 +1022,7 @@
 		// this drive should be added to iEclipsableOverwriteFiles.
 		if (processEclipsingSuspectsFoundOnThisDrive && unadornedFound)
 		{
-			iEclipsableOverwriteFiles.push_back(searchNameUnadorned);
+			iEclipsableOverwriteFiles.push_back(searchNameUnadorned.c_str());
 		}
 
 		if (processEclipsingSuspectsFoundOnThisDrive && adornedFound)
@@ -1014,7 +1038,7 @@
 				int drive = tolower(adornedFile[0]);
 				if (drive == disk)
 				{
-					iEclipsableOverwriteFiles.push_back(adornedFile);
+					iEclipsableOverwriteFiles.push_back(adornedFile.c_str());
 				}
 			}
 		}
@@ -1087,7 +1111,11 @@
  @param aRomFile fully qualified filename in ROM that is to be checked for eclipising (i.e: z:\sys\bin\some.dll)
  @param aSUFlag specifies if the installing SIS file has been signed by a SU certificate
 */
+#ifndef __TOOLS2_LINUX__
 bool Installer::IsEclipsable(std::wstring& aRomFile, bool aSUFlag)
+#else
+bool Installer::IsEclipsable(std::wstring& aRomFile, bool aSUFlag, const std::wstring& aDrivePath)
+#endif
 {
 	// SA/SP/PU sis + RU flag + signed by SU root cert is allowed
 	if (aSUFlag)
@@ -1111,7 +1139,11 @@
 		}
 		else if (goesToSysBin) // case 2
 		{
+			#ifndef __TOOLS2_LINUX__
 			if (IsAdornedVariationOf(eclipsableRomFile,aRomFile))
+			#else
+			if (IsAdornedVariationOf(eclipsableRomFile,aRomFile,aDrivePath))
+			#endif
 			{
 				isEclipsable = true;
 				break;
@@ -1145,8 +1177,8 @@
 		// do not display a warning if the installing file is a PA. The user
 		// needs to copy the installing files to the installing directory
 		// prior to installing the SIS file.
-		std::string tempTarget = Ucs2ToUtf8(aTarget);
-  	  	std::wstring targetDisplay = Utf8ToUcs2( tempTarget );
+		std::string tempTarget = wstring2string(aTarget);
+  	  	std::wstring targetDisplay = string2wstring( tempTarget );
 		if (aFile.GetInstallType() == CSISInfo::EInstPreInstalledApp)
 		{
 			LINFO(targetDisplay << L" found for PA installation");
@@ -1162,7 +1194,7 @@
 		if (isSp)
 		{
 			std::wostringstream os;
-			os << aTarget << L" overwrites file from base package 0x" << std::hex << owningUid << L" \"" << owningObj->GetPackageName() << L"\"" << std::endl;
+			os << aTarget.c_str() << L" overwrites file from base package 0x" << std::hex << owningUid << L" \"" << owningObj->GetPackageName() << L"\"" << std::endl;
 			iProblemFiles.append(os.str());
 			iError = ECLIPSING_VIOLATION;
 		}
@@ -1175,13 +1207,13 @@
 		if (isSp || (!aSUFlag && (isPu || isSa)))
 		{
 			std::wostringstream os;
-			os << aTarget << L" overwrites file from base package 0x" << std::hex << owningUid << L" \"" << owningObj->GetPackageName() << L"\"" << std::endl;
+			os << aTarget.c_str() << L" overwrites file from base package 0x" << std::hex << owningUid << L" \"" << owningObj->GetPackageName() << L"\"" << std::endl;
 			iProblemFiles.append(os.str());
 			iError = ECLIPSING_VIOLATION;
 		}
 		else
 		{
-			LWARN(aTarget << L" overwrites file from base package 0x" << std::hex << owningUid << L" \"" << owningObj->GetPackageName() << L"\"");
+		    LWARN(aTarget.c_str() << L" overwrites file from base package 0x" << std::hex << owningUid << L" \"" << owningObj->GetPackageName() << L"\"");
 		}
 	}
 }
@@ -1201,19 +1233,19 @@
 			std::wstring eclipseFile(*curr);
 
 			TUint32 owningUid = 0;
-			const SisRegistryObject* owningObj = iRegistry.OwningPackage(eclipseFile, owningUid);
+			const SisRegistryObject* owningObj = iRegistry.OwningPackage(eclipseFile.c_str(), owningUid);
 			
 			// always allow orphaned file overwriting
 			if (owningUid == 0)
 			{
-				LWARN(eclipseFile << L" eclipses orphaned file.");
+			    LWARN(eclipseFile.c_str() << L" eclipses orphaned file.");
 			}
 			else
 			{
 				// SP/PU can not overwrite a file belonging to a different base pkg or
 				// SP/PU can not eclipse a base package which is not in the ROM.
 				std::wostringstream os;
-				os << eclipseFile << L" eclipses file from package 0x" << std::hex << owningUid << L" \"" << owningObj->GetPackageName() << L"\"" << std::endl;
+				os << eclipseFile.c_str() << L" eclipses file from package 0x"  << std::hex << owningUid << L" \"" << owningObj->GetPackageName().c_str() << L"\""<< std::endl;
 				iProblemFiles.append(os.str());
 				iError = ECLIPSING_VIOLATION;
 				continue;
@@ -1235,10 +1267,17 @@
 	Sids sids;
 	GetSidsFromInstallable(aFiles, sids);
 
+	#ifndef __TOOLS2_LINUX__
 	const std::wstring privatePath = L":\\private\\";
 	const std::wstring sysPath = L":\\sys\\";
 	const std::wstring sysBinPath = L":\\sys\\bin\\";
 	const std::wstring resourcePath = L":\\resource\\";
+	#else
+	const std::wstring privatePath = L":/private/";
+	const std::wstring sysPath = L":/sys/";
+	const std::wstring sysBinPath = L":/sys/bin/";
+	const std::wstring resourcePath = L":/resource/";
+	#endif
 	const std::wstring exeType = L".exe";
 
     int num_of_files = aFiles.size();
@@ -1265,7 +1304,7 @@
         const CSISFileDescription* sisDescription = file->FileDescription();
 
 		// file to be installed
-		std::wstring target( file->GetTarget() );
+		std::wstring target( file->GetTarget().c_str() );
 
 		if (sisDescription->Operation() == CSISFileDescription::EOpText)
 			break;
@@ -1276,7 +1315,7 @@
 				{
 				// eclipsing problem
 				std::wostringstream os;
-				os << L"FN file \"" << target << L"\" can not remove a file from \\sys or \\resource" << std::endl;
+				os << L"FN file \"" << target.c_str() << L"\" can not remove a file from \\sys or \\resource" << std::endl;
 				iProblemFiles.append(os.str());
 				iError = DATA_CAGE_VIOLATION;
 				continue;
@@ -1284,7 +1323,7 @@
 			}
         else 
             {
-			std::wstring realTarget(file->GetLocalTarget());
+			std::wstring realTarget(file->GetLocalTarget().c_str());
 
 		    std::wstring romTarget(target);
 			romTarget[0] = KRomDriveLetter;
@@ -1296,7 +1335,7 @@
 				{
 					// eclipsing problem
 					std::wostringstream os;
-					os << target << L" eclipses file from ROM" << std::endl;
+					os << target.c_str() << L" eclipses file from ROM" << std::endl;
 					iProblemFiles.append(os.str());
 					iError = ECLIPSING_VIOLATION;
 					continue;
@@ -1348,14 +1387,17 @@
 
 						const int KUidStringLength = 8;
 						std::wstring importPath = privatePath;
-
+						#ifndef __TOOLS2_LINUX__
 						importPath.append( uidStr.str() + L"\\import" );
+						#else
+						importPath.append( uidStr.str() + L"/import" );
+						#endif
 
 						if ((target.find(importPath,0) == std::wstring::npos) && !suFlag)
 						{
 							// only SA with RU + SU and PU with RU + SU flag can override other private directory
 							std::wostringstream os;
-							os << target << L" cannot be written to a private directory which "
+							os << target.c_str() << L" cannot be written to a private directory which "
 								<< L"does not belong to any exe in this package" << std::endl;
 							iProblemFiles.append(os.str());
 							iError = DATA_CAGE_VIOLATION;
@@ -1425,8 +1467,8 @@
 					{
 						std::wostringstream os;
 										
-						os << L"The existing file " << owningSidFile << L" already has the SID 0x" << std::hex << sid
-						   << std::dec << L", cannot install " << target << std::endl;
+						os << L"The existing file " << owningSidFile.c_str() << L" already has the SID 0x" << std::hex << sid
+						   << std::dec << L", cannot install " << target.c_str() << std::endl;
 						iProblemFiles.append(os.str());
 						iError = DUPLICATE_SID;
 						continue;
@@ -1450,7 +1492,7 @@
 							{
 								const CSISFileDescription* fD = *iter;
 
-								std::wstring romStubTarget(fD->Target().GetString());
+								std::wstring romStubTarget(fD->Target().GetString().c_str());
 
 								if (StringUtils::WildcardCompare(romStubTarget,romFileWithDuplicateSid))
 								{
@@ -1471,7 +1513,7 @@
 						std::wostringstream os;
 											
 						os << L"A ROM file already has the SID 0x" << std::hex << file->Sid()
-						   << std::dec << L", cannot install " << target << std::endl;
+						   << std::dec << L", cannot install " << target.c_str() << std::endl;
 						iProblemFiles.append(os.str());
 						iError = DUPLICATE_SID;
 						continue;
@@ -1481,7 +1523,7 @@
 		    else if (realTarget.find(sysBinPath) != std::wstring::npos)
 		    {
 				std::wostringstream os;
-				os << target << L" cannot be installed to a data caged area" << std::endl;
+				os << target.c_str() << L" cannot be installed to a data caged area" << std::endl;
 				iProblemFiles.append(os.str());
 				iError = DATA_CAGE_VIOLATION;
 				continue;
@@ -1497,8 +1539,8 @@
 
 	if (!iProblemFiles.empty())
 	{
-		std::string x;
-		throw InvalidSis("", Ucs2ToUtf8(iProblemFiles,x), iError);
+		std::string x = wstring2string(iProblemFiles);
+		throw InvalidSis("", x, iError);
 	}
 }
 
@@ -1536,8 +1578,11 @@
 {
 	int targetDrive = aInstallSISFile.iTargetDrive;
 	std::wstring drivePath = iConfigManager.GetLocalDrivePath(targetDrive);
-	
+	#ifndef __TOOLS2_LINUX__
 	drivePath.append(L"\\private\\");
+	#else
+	drivePath.append(L"/private/");
+	#endif
 
 	// build SwiDaemon Pathname
 	std::wstring ctrl = StringUtils::MakePathFromSID(drivePath, KSwiDaemonUid);
@@ -1552,7 +1597,6 @@
 
 	ctrl.append(s.str());
 
-
 	switch(aSis.GetInstallType())
     {
 	case CSISInfo::EInstInstallation: