secureswitools/swisistools/source/rscparser/dirparse.cpp
changeset 60 245df5276b97
parent 33 8110bf1194d1
child 76 f36d4ce8961e
--- a/secureswitools/swisistools/source/rscparser/dirparse.cpp	Tue Jul 06 14:23:31 2010 +0300
+++ b/secureswitools/swisistools/source/rscparser/dirparse.cpp	Wed Aug 18 09:55:45 2010 +0300
@@ -310,9 +310,17 @@
 
 	componentData.iLocale = aLocale;
 	componentData.iServiceUid = aServUid;
-	componentData.iOpaqueData = aStrValue;
 
-	aAppOpaqueData.iOpaqueDataType.push_back(componentData);
+	/* 
+	 * Under LINUX : The OpaqueData which is read from the resource file will be in UTF-16 format contained
+	 *               in a std::wstring. So, we need to convert it back to UTF-32 format which is the format
+	 *               of LINUX specific std::wstring.
+     * 
+	 * Under WINDOWS : Nothing needs to be done and this is taken care of by XercesStringToWString()
+	 *				   which is platform specific.	
+	 */
+	 componentData.iOpaqueData = XercesStringToWString(reinterpret_cast<const XMLCh*>(aStrValue.c_str()));
+	 aAppOpaqueData.iOpaqueDataType.push_back(componentData);
 }
 
 /**
@@ -326,10 +334,18 @@
 		aParamList->IsFlagSet(CParameterList::EFlagsDisableZDriveChecksSet) 
 		)
 		{
+			#ifdef __LINUX__
+			return wstring2string(aParamList->SystemDrivePath()) + "/sys/install/scr/scr.db";
+			#else
 			return wstring2string(aParamList->SystemDrivePath()) + "\\sys\\install\\scr\\scr.db";
+			#endif
 		}
 
+	#ifdef __LINUX__
+	return wstring2string(aParamList->RomDrivePath()) + "/sys/install/scr/provisioned/scr.db";
+	#else
 	return wstring2string(aParamList->RomDrivePath()) + "\\sys\\install\\scr\\provisioned\\scr.db";
+	#endif
 }
 
 /**
@@ -340,13 +356,27 @@
 												XmlDetails::TScrPreProvisionDetail aScrPreProvisionDetail)
 {
 	CXmlGenerator xmlGenerator;
-	char* tmpFileName = tmpnam(NULL);
+
+	#ifndef __TOOLS2_LINUX__
+		char* tmpFileName = tmpnam(NULL);	
+	#else
+		char tmpFileName[] = "/tmp/interpretsis_preprovision_XXXXXX";	
+		int temp_fd;
+		temp_fd=mkstemp(tmpFileName); 
+		fclose(fdopen(temp_fd,"w"));
+	#endif
+
 	std::wstring filename(string2wstring(tmpFileName));
 
 	int isRomApplication = 1;
 	xmlGenerator.WritePreProvisionDetails(filename , aScrPreProvisionDetail, isRomApplication);						
 
+	#ifdef __LINUX__
+	std::string executable = "scrtool";
+	#else 
 	std::string executable = "scrtool.exe";
+	#endif
+
 	std::string command;
 
 	command = executable + " -d " + GetDbPath(aParamList) + " -p " + tmpFileName;
@@ -517,13 +547,21 @@
 	{
 		size_t found;
 		std::string folder;
+		#ifdef __LINUX__
+		found=aFileName.find("private/10003a3f/");
+		#else
 		found=aFileName.find("private\\10003a3f\\");
+		#endif
 
 		if( found != string::npos )
 			folder = aFileName.substr(0,found);
 		else
 		{
+				#ifdef __LINUX__
+				std::string errMsg= "Failed : Resource File Path should contain /private/10003a3f/";
+				#else
 				std::string errMsg= "Failed : Resource File Path should contain \\private\\10003a3f\\";
+				#endif
 				throw CResourceFileException(errMsg);
 		}
 
@@ -606,7 +644,11 @@
 	else
 	{
 		 aFilePath = aParamList->RomDrivePath();
+		 #ifdef __LINUX__
+		 aFilePath.append(L"/private/10003a3f/apps");
+		 #else
 		 aFilePath.append(L"\\private\\10003a3f\\apps");
+		 #endif
 	}
 
 	int iCount = 0;
@@ -625,9 +667,14 @@
 			{
 				iCount++;
 			    std::string fName;
-		        fName = Ucs2ToUtf8( *curr );
+		        fName = wstring2string( *curr );
 				std::string FilePath = wstring2string(aFilePath);
+				#ifdef __LINUX__				
+				FilePath.append("/");
+				#else
 				FilePath.append("\\");
+				#endif
+
 				FilePath.append(fName);
 				std::cout<<"Parsing - "<<fName<<" ";
 				ReadApplicationInformationFromResourceFilesL(scrPreProvisionDetail,FilePath,aParamList,aInterpretSis,iNewFileFlag);
@@ -645,7 +692,7 @@
 		UpdateInstallationInformation_xml(aParamList,scrPreProvisionDetail);
 	
 	if(!iCount)
-		LERROR(L"Failed : No Resource File in the Directory Specified - ");
+		LINFO(L"No Resource File in the Directory Specified - ");
 }
 
 /**
@@ -653,15 +700,28 @@
  */
 void BackupHashForFile(const std::wstring& aFile, const int aDriveLetter, const std::wstring& aPath)
 {
+	#ifdef __LINUX__
+	std::wstring hashdir = L"$:/sys/hash/";
+	#else
 	std::wstring hashdir = L"$:\\sys\\hash\\";
+	#endif
+
 	std::wstring basename = aFile.substr( aFile.rfind( KDirectorySeparator ) + 1) ;
 	if (basename.size() == 0)
 	{
+		#ifdef __LINUX__
+		basename = aFile.substr(aFile.rfind(L"/"));
+		#else
 		basename = aFile.substr(aFile.rfind(L"\\"));
+		#endif
 	}
 
 	hashdir[0] = aDriveLetter;
+	#ifdef __LINUX__
+	std::wstring hashFile = aPath + L"/sys/hash/" + basename;
+	#else
 	std::wstring hashFile = aPath + L"\\sys\\hash\\" + basename;
+	#endif
 
 	if (FileExists(hashFile))
 	{
@@ -670,7 +730,7 @@
 		iBackupFile.append("_backup");
 
 		int err=FileCopyA(iLocalFile.c_str(),iBackupFile.c_str(),0);
-		if (err == 0)
+		if (err != 0)
 			LERROR(L"Failed to Backup hash file ");
 	}
 }
@@ -680,15 +740,27 @@
  */
 void RestoreHashForFile(const std::wstring& aFile, const int aDriveLetter, const std::wstring& aPath)
 {
+	#ifdef __LINUX__
+	std::wstring hashdir = L"$:/sys/hash/";
+	#else
 	std::wstring hashdir = L"$:\\sys\\hash\\";
+	#endif
 	std::wstring basename = aFile.substr( aFile.rfind( KDirectorySeparator ) + 1) ;
 	if (basename.size() == 0)
 	{
+		#ifdef __LINUX__
+		basename = aFile.substr(aFile.rfind(L"/"));
+		#else
 		basename = aFile.substr(aFile.rfind(L"\\"));
+		#endif
 	}
 
 	hashdir[0] = aDriveLetter;
+	#ifdef __LINUX__
+	std::wstring hashFile = aPath + L"/sys/hash/" + basename;
+	#else
 	std::wstring hashFile = aPath + L"\\sys\\hash\\" + basename;
+	#endif	
 	std::wstring LocalFile(hashFile);
 	hashFile.append(L"_backup");
 
@@ -698,9 +770,8 @@
 		std::string iBackupFile = wstring2string(hashFile);
 
 		int err = FileMoveA(iBackupFile.c_str(),iLocalFile.c_str());
-
-		if (err == 0)
-			LERROR(L"Failed to Restore hash file ");
+		if (err != 0)
+		    LERROR(L"Failed to Restore hash file ");
 	}
 }
 
@@ -715,7 +786,12 @@
  */ 
 
 // Constants
+#ifdef __LINUX__
+const std::wstring KSisDirectorySeparatortap( L"/" );
+#else
 const std::wstring KSisDirectorySeparatortap( L"\\" );
+#endif
+
 
 int FirstInvalidDirSeparatorSizetap(std::wstring& aPath, std::wstring::size_type& aIndex)
 	{
@@ -723,11 +799,19 @@
 	// then the function will return 0
 	int ret = 0; 
 	int pos = 0;
+	#ifdef __LINUX__
+	if((pos = aPath.find(L"\\\\", aIndex)) != std::wstring::npos)
+	#else
 	if((pos = aPath.find(L"//", aIndex)) != std::wstring::npos)
+	#endif
 		{
 		ret = 2;
 		}
+	#ifdef __LINUX__
+	else if((pos = aPath.find(L"\\", aIndex)) != std::wstring::npos)
+	#else
 	else if((pos = aPath.find(L"/", aIndex)) != std::wstring::npos)
+	#endif
 		{
 		ret = 1;
 		}