secureswitools/swisistools/source/rscparser/dirparse.cpp
branchRCL_3
changeset 26 8b7f4e561641
parent 25 7333d7932ef7
child 27 e8965914fac7
equal deleted inserted replaced
25:7333d7932ef7 26:8b7f4e561641
     1 // Copyright (c) 2009 - 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description: File to Parse Resource File for Class AppRegistrationInfo and Create Input for
       
    14 //			 XML Generator.
       
    15 //
       
    16 
       
    17 
       
    18 #include "parameterlist.h"
       
    19 #include "stringutils.h"
       
    20 #include "is_utils.h"
       
    21 #include "dirparse.h"
       
    22 #include "barsc2.h"
       
    23 #include "commontypes.h"
       
    24 #include "sisregistry.h"
       
    25 #include "errors.h"
       
    26 #include "dbconstants.h"
       
    27 #include "parse.h"
       
    28 #include "utility_interface.h"
       
    29 
       
    30 using namespace std;
       
    31 
       
    32 /**
       
    33 @internalTechnology
       
    34 */
       
    35 std::wstring AppResourceFileExtension = L".rsc";
       
    36 
       
    37 /**
       
    38  * Identify if input file is a Registration Resource File.
       
    39  @ Param : aRegistrationFileName - File name to be scanned.
       
    40  */
       
    41 TInt FindRegistrationResourceFileL(std::string& aRegistrationFileName)
       
    42 {
       
    43 	CResourceFile* registrationFile = NULL;
       
    44 	try {
       
    45 			registrationFile = new CResourceFile(aRegistrationFileName, 0, 0);
       
    46 			if(NULL==registrationFile)
       
    47 			{
       
    48 				std::cout<<"Failed : Error in Reading File. Memory Allocation Failed"<<std::endl;
       
    49 				return 1;
       
    50 			}
       
    51 			else
       
    52 			{
       
    53 				TUid iAppUid = registrationFile->ReadFileUidL();
       
    54 				if(KUidAppRegistrationResourceFile == iAppUid.GetUid())
       
    55 				{
       
    56 					delete registrationFile;
       
    57 					return 0;
       
    58 				}
       
    59 			}
       
    60 		}
       
    61 		catch(const CResourceFileException& aObject)
       
    62 		{
       
    63 			if(registrationFile)
       
    64 				delete registrationFile;
       
    65 			return 1;
       
    66 		}
       
    67 	
       
    68 	delete registrationFile;
       
    69 	return 1;
       
    70 }
       
    71 
       
    72 
       
    73 /**
       
    74  * Creates Class TAppDataType for XML Parsing
       
    75  */
       
    76 
       
    77 std::wstring Ptr8_2_Wstring(const Ptr8* aBuf)
       
    78 {
       
    79 	std::wstring str2(aBuf->GetLength(), L'\0'); // Make room for characters
       
    80 
       
    81 	TUint8* temp = aBuf->GetPtr();
       
    82 	std::copy(temp,temp+aBuf->GetLength(),str2.begin());
       
    83 
       
    84 	return str2;
       
    85 }
       
    86 
       
    87 
       
    88 void CreateAppDataType(XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppServiceInfo& aAppDataType, 
       
    89 								const TDataTypeWithPriority* aTemp)
       
    90 {
       
    91 	XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TDataType componentDataType;
       
    92 
       
    93 	componentDataType.iPriority = aTemp->iPriority;
       
    94 	componentDataType.iType = Ptr8_2_Wstring(aTemp->iDataType.GetDataType());
       
    95 
       
    96 	aAppDataType.iDataType.push_back(componentDataType);
       
    97 }
       
    98 
       
    99 /**
       
   100  * Creates Class TViewData for XML Parsing
       
   101  */
       
   102 void CreateViewDataL(XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppLocalizableInfo& aLocalizableAttribute, 
       
   103 							const CAppLocalizableInfo* aAppInfoReader)
       
   104 {
       
   105 	std::wstring sStr1;
       
   106 	std::wstring sStr;
       
   107 
       
   108 	std::vector<CAppViewData*>* viewDataArray = aAppInfoReader->GetViewDataArray();
       
   109 
       
   110 	if(viewDataArray)
       
   111 	{
       
   112 		for(TInt i = 0; i<viewDataArray->size(); i++)
       
   113 		{
       
   114 
       
   115 			XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppLocalizableInfo::TViewData ViewData;
       
   116 			CAppViewData *temp = viewDataArray->at(i);
       
   117 	
       
   118 			sStr = DbConstants::CompUID;
       
   119 			TUid ID = temp->Uid();
       
   120 			sStr1 = Utils::IntegerToWideString(ID.GetUid());
       
   121 			CreateViewDataAttributes(ViewData,sStr,sStr1,true,false);
       
   122 	
       
   123 			sStr = DbConstants::CompScreenMode;
       
   124 			TInt SMode = temp->GetScreenMode();
       
   125 	
       
   126 			sStr1 = Utils::IntegerToWideString(SMode);
       
   127 			CreateViewDataAttributes(ViewData,sStr,sStr1,true,false);
       
   128 			
       
   129 			sStr = DbConstants::CompCaption;
       
   130 			Ptr16* caption = temp->GetCaption();
       
   131 			if(caption)
       
   132 				sStr1 = Ptr16ToWstring(caption);
       
   133 			else
       
   134 				sStr1=L'\0';		
       
   135 			CreateViewDataAttributes(ViewData,sStr,sStr1,false,false);
       
   136 			
       
   137 			sStr = DbConstants::CompNumberOfIcons;
       
   138 			TInt IconNum = temp->GetNumOfViewIcons();
       
   139 			sStr1 = Utils::IntegerToWideString(IconNum);
       
   140 			CreateViewDataAttributes(ViewData,sStr,sStr1,true,false);
       
   141 	
       
   142 			sStr = DbConstants::CompIconFile;
       
   143 			Ptr16* IconName = temp->GetIconFileName();
       
   144 			if(IconName)
       
   145 				sStr1 = Ptr16ToWstring(IconName);
       
   146 			else
       
   147 				sStr1=L'\0';
       
   148 			CreateViewDataAttributes(ViewData,sStr,sStr1,false,false);
       
   149 
       
   150 			aLocalizableAttribute.iViewData.push_back(ViewData);
       
   151 		}
       
   152 	}
       
   153 }
       
   154 
       
   155 void CreateViewDataAttributes(XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppLocalizableInfo::TViewData& aViewData, 
       
   156 							const std::wstring& aName,const std::wstring& aValue, 
       
   157 							const bool aIsIntValue, const int aIsStr8Bit)
       
   158 {
       
   159 	XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppLocalizableInfo::TViewData::TViewDataAttributes ViewDataAttributes;
       
   160 
       
   161 	ViewDataAttributes.iName = aName;
       
   162 	ViewDataAttributes.iValue = aValue;
       
   163 	ViewDataAttributes.iIsIntValue = aIsIntValue;
       
   164 	ViewDataAttributes.iIsStr8Bit = aIsStr8Bit;
       
   165 
       
   166 	aViewData.iViewDataAttributes.push_back(ViewDataAttributes);
       
   167 }
       
   168 
       
   169 /**
       
   170  * Creates Class TLocalizableAttribute for XML Parsing
       
   171  */
       
   172 
       
   173 void CreateLocalizableAttribute(XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppLocalizableInfo& aLocalizableAttribute, 
       
   174 										const std::wstring& aName, const std::wstring& aValue, 
       
   175 										const bool aIsIntValue, const int aIsStr8Bit)
       
   176 {
       
   177 	XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppLocalizableInfo::TLocalizableAttribute LocalizableAttribute;
       
   178 
       
   179 	LocalizableAttribute.iName = aName;
       
   180 	LocalizableAttribute.iValue = aValue;
       
   181 	LocalizableAttribute.iIsIntValue = aIsIntValue;
       
   182 	LocalizableAttribute.iIsStr8Bit = aIsStr8Bit;
       
   183 
       
   184 	aLocalizableAttribute.iLocalizableAttribute.push_back(LocalizableAttribute);
       
   185 }
       
   186 
       
   187 /**
       
   188  * Creates Class TAppLocalizableInfo for XML Parsing
       
   189  */
       
   190 void CreateLocalizableInfoL(XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo& aAppLocalizableInfo, 
       
   191 									const CAppLocalizableInfo* aInfoReader)
       
   192 {
       
   193 		XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppLocalizableInfo componentLocalizableInfo;
       
   194 
       
   195 		Ptr16* shortCaption = aInfoReader->GetShortCaption();
       
   196 		std::wstring sStr = DbConstants::CompShortCaption;
       
   197 		std::wstring sStr1;
       
   198 		
       
   199 		if(shortCaption)
       
   200 			sStr1 = Ptr16ToWstring(shortCaption);
       
   201 		else
       
   202 			sStr1=L'\0';
       
   203 		CreateLocalizableAttribute(componentLocalizableInfo,sStr,sStr1,false,false);	
       
   204 
       
   205 		Ptr16* caption = aInfoReader->GetCaption();
       
   206 		sStr = DbConstants::CompCaption;
       
   207 		if(caption)
       
   208 			sStr1 = Ptr16ToWstring(caption);
       
   209 		else
       
   210 			sStr1=L'\0';
       
   211 		CreateLocalizableAttribute(componentLocalizableInfo,sStr,sStr1,false,false);
       
   212 		
       
   213 		TInt  iNumOfAppIcons = aInfoReader->GetNumOfAppIcons();
       
   214 		sStr = DbConstants::CompNumberOfIcons;
       
   215 		sStr1 = Utils::IntegerToWideString(iNumOfAppIcons);
       
   216 		CreateLocalizableAttribute(componentLocalizableInfo,sStr,sStr1,true,false);
       
   217 
       
   218 		TInt  iLocale = aInfoReader->GetLocale();
       
   219 		sStr = DbConstants::CompLocale;
       
   220 		sStr1 = Utils::IntegerToWideString(iLocale);
       
   221 		CreateLocalizableAttribute(componentLocalizableInfo,sStr,sStr1,true,false);
       
   222 
       
   223 		Ptr16* iIconFileName = aInfoReader->GetIconFileName();
       
   224 		sStr = DbConstants::CompIconFile;
       
   225 		if(iIconFileName)
       
   226 			sStr1 = Ptr16ToWstring(iIconFileName);
       
   227 		else
       
   228 			sStr1=L'\0';
       
   229 		CreateLocalizableAttribute(componentLocalizableInfo,sStr,sStr1,false,false);
       
   230 
       
   231 		Ptr16* iGroupName = aInfoReader->GetGroupName();
       
   232 		sStr = DbConstants::CompGroupName;
       
   233 		if(iGroupName)
       
   234 			sStr1 = Ptr16ToWstring(iGroupName);
       
   235 		else
       
   236 			sStr1=L'\0';
       
   237 		CreateLocalizableAttribute(componentLocalizableInfo,sStr,sStr1,false,false);
       
   238 
       
   239 		CreateViewDataL(componentLocalizableInfo,aInfoReader);
       
   240 
       
   241 		aAppLocalizableInfo.iApplicationLocalizableInfo.push_back(componentLocalizableInfo);
       
   242 }
       
   243 
       
   244 
       
   245 /**
       
   246  * Creates Class TAppServiceInfo for XML Parsing
       
   247  */
       
   248 
       
   249 void CreateAppServiceInfo(XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo& aAppServiceInfo, 
       
   250 									const TUid& aUid, const std::vector<TDataTypeWithPriority*>& aDataType) 
       
   251 {
       
   252 		XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppServiceInfo componentServiceInfo;
       
   253 
       
   254 		componentServiceInfo.iUid = aUid.GetUid();
       
   255 		for(TInt ii = 0; ii<aDataType.size(); ii++)
       
   256 		{
       
   257 			TDataTypeWithPriority *temp = aDataType.at(ii);
       
   258 			CreateAppDataType(componentServiceInfo,temp);
       
   259 		}
       
   260 	
       
   261 		aAppServiceInfo.iApplicationServiceInfo.push_back(componentServiceInfo);
       
   262 }
       
   263 
       
   264 /**
       
   265  * Creates Class TAppAttribute for XML Parsing
       
   266  */
       
   267 
       
   268 void CreateAppAttribute(XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo& aAppAttribute, 
       
   269 								const std::wstring& aName,const std::wstring& aValue, 
       
   270 								const bool aIsIntValue, const int aIsStr8Bit )
       
   271 {
       
   272 	XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppAttribute componentAttribute;
       
   273 
       
   274 	componentAttribute.iName = aName;
       
   275 	componentAttribute.iValue = aValue;
       
   276 	componentAttribute.iIsIntValue = aIsIntValue;
       
   277 	componentAttribute.iIsStr8Bit = aIsStr8Bit;
       
   278 
       
   279 	aAppAttribute.iApplicationAttribute.push_back(componentAttribute);
       
   280 }
       
   281 
       
   282 /**
       
   283  * Creates Class TAppAttribute for XML Parsing
       
   284  */
       
   285 
       
   286 void CreateAppProperty(XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo& aAppProperty, 
       
   287 								const std::wstring& aStrValue, const int aLocale,
       
   288 								const int aServiceUid, const bool aIsStr8Bit )
       
   289 {
       
   290 	XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TAppProperty componentproperty;
       
   291 
       
   292 	componentproperty.iName = DbConstants::CompOpaqueData;
       
   293 	componentproperty.iLocale = aLocale;
       
   294 	componentproperty.iServiceUid = aServiceUid;
       
   295 	componentproperty.iIntValue = 0;
       
   296 	componentproperty.iStrValue = aStrValue;
       
   297 	componentproperty.iIsStr8Bit = aIsStr8Bit;
       
   298 
       
   299 	aAppProperty.iApplicationProperty.push_back(componentproperty);
       
   300 }
       
   301 
       
   302 /**
       
   303  * Creates Class TOpaqueDataType for XML Parsing
       
   304  */
       
   305 
       
   306 void CreateOpaqueDataType(XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo& aAppOpaqueData, 
       
   307 								const std::wstring& aStrValue, const int aLocale, const int aServUid)
       
   308 {
       
   309 	XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo::TOpaqueDataType componentData;
       
   310 
       
   311 	componentData.iLocale = aLocale;
       
   312 	componentData.iServiceUid = aServUid;
       
   313 
       
   314 	/* 
       
   315 	 * Under LINUX : The OpaqueData which is read from the resource file will be in UTF-16 format contained
       
   316 	 *               in a std::wstring. So, we need to convert it back to UTF-32 format which is the format
       
   317 	 *               of LINUX specific std::wstring.
       
   318      * 
       
   319 	 * Under WINDOWS : Nothing needs to be done and this is taken care of by XercesStringToWString()
       
   320 	 *				   which is platform specific.	
       
   321 	 */
       
   322 	 componentData.iOpaqueData = XercesStringToWString(reinterpret_cast<const XMLCh*>(aStrValue.c_str()));
       
   323 	 aAppOpaqueData.iOpaqueDataType.push_back(componentData);
       
   324 }
       
   325 
       
   326 /**
       
   327  * Get the path of Database "scr.db"
       
   328  */
       
   329 
       
   330 std::string GetDbPath(const CParameterList* aParamList)
       
   331 {
       
   332 	if	( 
       
   333 		(aParamList->RomLogFileNames().size() != 0 && aParamList->RomDrivePath().size() == 0 ) ||
       
   334 		aParamList->IsFlagSet(CParameterList::EFlagsDisableZDriveChecksSet) 
       
   335 		)
       
   336 		{
       
   337 			#ifdef __LINUX__
       
   338 			return wstring2string(aParamList->SystemDrivePath()) + "/sys/install/scr/scr.db";
       
   339 			#else
       
   340 			return wstring2string(aParamList->SystemDrivePath()) + "\\sys\\install\\scr\\scr.db";
       
   341 			#endif
       
   342 		}
       
   343 
       
   344 	#ifdef __LINUX__
       
   345 	return wstring2string(aParamList->RomDrivePath()) + "/sys/install/scr/provisioned/scr.db";
       
   346 	#else
       
   347 	return wstring2string(aParamList->RomDrivePath()) + "\\sys\\install\\scr\\provisioned\\scr.db";
       
   348 	#endif
       
   349 }
       
   350 
       
   351 /**
       
   352  * Update Installation Information in Database using SRCTOOL
       
   353  */
       
   354 
       
   355 void UpdateInstallationInformation_xml(const CParameterList* aParamList,
       
   356 												XmlDetails::TScrPreProvisionDetail aScrPreProvisionDetail)
       
   357 {
       
   358 	CXmlGenerator xmlGenerator;
       
   359 
       
   360 	#ifndef __TOOLS2_LINUX__
       
   361 		char* tmpFileName = tmpnam(NULL);	
       
   362 	#else
       
   363 		char tmpFileName[] = "/tmp/interpretsis_preprovision_XXXXXX";	
       
   364 		int temp_fd;
       
   365 		temp_fd=mkstemp(tmpFileName); 
       
   366 		fclose(fdopen(temp_fd,"w"));
       
   367 	#endif
       
   368 
       
   369 	std::wstring filename(string2wstring(tmpFileName));
       
   370 
       
   371 	int isRomApplication = 1;
       
   372 	xmlGenerator.WritePreProvisionDetails(filename , aScrPreProvisionDetail, isRomApplication);						
       
   373 
       
   374 	#ifdef __LINUX__
       
   375 	std::string executable = "scrtool";
       
   376 	#else 
       
   377 	std::string executable = "scrtool.exe";
       
   378 	#endif
       
   379 
       
   380 	std::string command;
       
   381 
       
   382 	command = executable + " -d " + GetDbPath(aParamList) + " -p " + tmpFileName;
       
   383 
       
   384 	cout << "Updating DB : " << command << endl;
       
   385 
       
   386 	int error = system(command.c_str());
       
   387 	
       
   388 	if(error != 0)
       
   389 	{
       
   390 		LERROR(L"Scrtool failed to upload the database registry entry.");
       
   391 	}
       
   392 		
       
   393 	error = remove(tmpFileName);
       
   394 
       
   395 	if(error != 0)
       
   396 	{
       
   397 		LERROR(L"Temporary file removal failed.");
       
   398 	}	
       
   399 }
       
   400 
       
   401 /**
       
   402  * Creates Class TApplicationRegistrationInfo for XML Parsing
       
   403  */
       
   404 
       
   405 
       
   406 void CreateApplicationRegistrationInfoL(XmlDetails::TScrPreProvisionDetail::TComponent& aComponent, 
       
   407 												const CAppInfoReader* aAppInfoReader)
       
   408 {
       
   409 	XmlDetails::TScrPreProvisionDetail::TApplicationRegistrationInfo atemp;
       
   410 
       
   411 	Ptr16* iAppBinaryFullName = aAppInfoReader->AppBinaryFullName();
       
   412 	std::wstring sStr = DbConstants::CompAppFile;
       
   413 	std::wstring sStr1 = Ptr16ToWstring(iAppBinaryFullName);
       
   414 	CreateAppAttribute(atemp,sStr,sStr1,false,false);
       
   415 
       
   416 	TUidType iAppBinaryUidType = aAppInfoReader->AppBinaryUidType();;
       
   417 	sStr = DbConstants::CompAppUid;
       
   418 	TUid Uid = iAppBinaryUidType[2];
       
   419 	sStr1 = Utils::IntegerToWideString(Uid.GetUid());
       
   420 	CreateAppAttribute(atemp,sStr,sStr1,true,false);
       
   421 
       
   422 	sStr = DbConstants::CompTypeId;
       
   423 	TInt TypeId = -1367772926;
       
   424 	sStr1 = Utils::IntegerToWideString(TypeId);
       
   425 	CreateAppAttribute(atemp,sStr,sStr1,true,false);
       
   426 
       
   427 	TAppCapability iCapability;
       
   428 	aAppInfoReader->Capability(iCapability);
       
   429 
       
   430  	sStr = DbConstants::CompAttributes;
       
   431 	sStr1 = Utils::IntegerToWideString(iCapability.iAttributes);
       
   432 	CreateAppAttribute(atemp,sStr,sStr1,true,false);
       
   433 
       
   434 	sStr = DbConstants::CompHidden;
       
   435 	sStr1 = Utils::IntegerToWideString(iCapability.iAppIsHidden);
       
   436 	CreateAppAttribute(atemp,sStr,sStr1,true,false);
       
   437 
       
   438 	sStr = DbConstants::CompEmbeddable;
       
   439 	sStr1 = Utils::IntegerToWideString(iCapability.iEmbeddability);
       
   440 	CreateAppAttribute(atemp,sStr,sStr1,true,false);
       
   441 
       
   442 	sStr = DbConstants::CompNewfile;
       
   443 	sStr1 = Utils::IntegerToWideString(iCapability.iSupportsNewFile);
       
   444 	CreateAppAttribute(atemp,sStr,sStr1,true,false);
       
   445 
       
   446 	sStr = DbConstants::CompLaunch;
       
   447 	sStr1 = Utils::IntegerToWideString(iCapability.iLaunchInBackground);
       
   448 	CreateAppAttribute(atemp,sStr,sStr1,true,false);
       
   449 
       
   450 	sStr = DbConstants::CompGroupName;
       
   451 	if(iCapability.iGroupName)
       
   452 		sStr1 = Ptr16ToWstring(iCapability.iGroupName);
       
   453 	else
       
   454 		sStr1=L'\0';
       
   455 	CreateAppAttribute(atemp,sStr,sStr1,false,false);
       
   456 
       
   457 	TUint iDefaultScreenNumber = aAppInfoReader->DefaultScreenNumber();
       
   458 	sStr = DbConstants::CompDefaultScreenNumber;
       
   459 	sStr1 = Utils::IntegerToWideString(iDefaultScreenNumber);
       
   460 	CreateAppAttribute(atemp,sStr,sStr1,true,false);
       
   461 
       
   462 	std::vector<Ptr16*>* ownedFileArray = aAppInfoReader->OwnedFiles();
       
   463 	if(ownedFileArray)
       
   464 	{
       
   465 		for(TInt ii = 0; ii<ownedFileArray->size(); ii++)
       
   466 		{
       
   467 			Ptr16 *temp = ownedFileArray->at(ii);
       
   468 			if(temp)
       
   469 				sStr = Ptr16ToWstring(temp);
       
   470 			else
       
   471 				sStr=L'\0';
       
   472 			atemp.iFileOwnershipInfo.push_back(sStr);
       
   473 		}
       
   474 	}
       
   475 
       
   476 	TInt iIndexOfFirstOpenService;
       
   477 	std::vector<TAppServiceInfo*>* iServiceArray = aAppInfoReader->ServiceArray(iIndexOfFirstOpenService);
       
   478 	if(iServiceArray)
       
   479 	{
       
   480 		for(TInt i = 0; i<iServiceArray->size(); i++)
       
   481 		{
       
   482 			TAppServiceInfo* temp = iServiceArray->at(i);
       
   483 			TUid iUid = temp->GetUid();
       
   484 			std::vector<TDataTypeWithPriority*> iData = temp->GetDataType();
       
   485 			CreateAppServiceInfo(atemp,iUid,iData);
       
   486 
       
   487 			int servUid = iUid.GetUid();
       
   488 			std::vector<CAppLocalOpaqueDataInfo*> opaqueDataArray = aAppInfoReader->GetOpaqueDataArray();
       
   489 			for(TInt i = 0; i<opaqueDataArray.size(); i++)
       
   490 			{
       
   491 				CAppLocalOpaqueDataInfo* tp = opaqueDataArray.at(i);
       
   492 			
       
   493 				TUint32 serviceUid = tp->GetServiceUid();
       
   494 				if(servUid == serviceUid)
       
   495 				{
       
   496 					Ptr8*	opaqueData = tp->GetOpaqueData();
       
   497 					if(opaqueData)
       
   498 						sStr1 = Ptr8ToWstring(opaqueData);
       
   499 					else
       
   500 						sStr1=L'\0';
       
   501 				
       
   502 					TInt locale = tp->GetLocale();
       
   503 					CreateOpaqueDataType(atemp,sStr1,locale,serviceUid);
       
   504 				}
       
   505 			}
       
   506 		}
       
   507 	}
       
   508 
       
   509 	std::vector<CAppLocalizableInfo*> aAppLocalizable = aAppInfoReader->LocalizableInfo();
       
   510 
       
   511 	for(TInt i = 0; i<aAppLocalizable.size(); i++)
       
   512 	{
       
   513 		CAppLocalizableInfo* tp = aAppLocalizable.at(i);
       
   514 		CreateLocalizableInfoL(atemp,tp);
       
   515 	}
       
   516 
       
   517 	std::vector<CAppLocalOpaqueDataInfo*> opaqueDataArray = aAppInfoReader->GetOpaqueDataArray();
       
   518 	for(TInt i = 0; i<opaqueDataArray.size(); i++)
       
   519 	{
       
   520 		CAppLocalOpaqueDataInfo* tp = opaqueDataArray.at(i);
       
   521 
       
   522 		TUint32 serviceUid = tp->GetServiceUid();
       
   523 		if(0 == serviceUid)
       
   524 		{
       
   525 			Ptr8* 	opaqueData = tp->GetOpaqueData();
       
   526 			if(opaqueData)
       
   527 				sStr1 = Ptr8ToWstring(opaqueData);
       
   528 			else
       
   529 				sStr1=L'\0';
       
   530 		
       
   531 			TInt locale = tp->GetLocale();
       
   532 			CreateOpaqueDataType(atemp,sStr1,locale,serviceUid);
       
   533 		}
       
   534 	}
       
   535 
       
   536 	aComponent.iApplicationRegistrationInfo.push_back(atemp);
       
   537 }
       
   538 
       
   539 
       
   540 /**
       
   541  * Get the path of Localizefile.
       
   542  */
       
   543 
       
   544 std::string GetLocalizeFilePath(const std::string& aFileName, const CParameterList* aParamList)
       
   545 {
       
   546 	if(aParamList->IsFlagSet(CParameterList::EFlagsResourceFilePathSet))
       
   547 	{
       
   548 		size_t found;
       
   549 		std::string folder;
       
   550 		#ifdef __LINUX__
       
   551 		found=aFileName.find("private/10003a3f/");
       
   552 		#else
       
   553 		found=aFileName.find("private\\10003a3f\\");
       
   554 		#endif
       
   555 
       
   556 		if( found != string::npos )
       
   557 			folder = aFileName.substr(0,found);
       
   558 		else
       
   559 		{
       
   560 				#ifdef __LINUX__
       
   561 				std::string errMsg= "Failed : Resource File Path should contain /private/10003a3f/";
       
   562 				#else
       
   563 				std::string errMsg= "Failed : Resource File Path should contain \\private\\10003a3f\\";
       
   564 				#endif
       
   565 				throw CResourceFileException(errMsg);
       
   566 		}
       
   567 
       
   568 		return folder;
       
   569 	}
       
   570 	else
       
   571 		return wstring2string(aParamList->RomDrivePath());
       
   572 }
       
   573 
       
   574 
       
   575 /**
       
   576  * Generate XML for Class AppInfoReader and call the function to Update Installation Information in Database using SRCTOOL
       
   577  */
       
   578 void ReadApplicationInformationFromResourceFilesL(XmlDetails::TScrPreProvisionDetail& aScrPreProvisionDetail, 
       
   579 															const std::string& aFileName,const CParameterList* aParamList, 
       
   580 															const CInterpretSIS& aInterpretSis, int& aNewFileFlag)
       
   581 {
       
   582 
       
   583 	std::string LocalizePath = GetLocalizeFilePath(aFileName, aParamList);
       
   584 	
       
   585 	CAppInfoReader* appInfoReader = NULL;
       
   586 	appInfoReader = CAppInfoReader::NewL(aFileName, NullUid, LocalizePath);	
       
   587 	if (!appInfoReader)
       
   588 	{
       
   589 		std::string errMsg= "Failed : Error in Reading File. Memory Allocation Failed";
       
   590 		throw CResourceFileException(errMsg);
       
   591 	}
       
   592 	else
       
   593 	{
       
   594 		TBool readSuccessful=EFalse;
       
   595 
       
   596 		readSuccessful= appInfoReader->ReadL();
       
   597 
       
   598 		if (readSuccessful)
       
   599 		{
       
   600 			const SisRegistry* SisReg( aInterpretSis.GetSisRegistry());
       
   601 			const DbHelper* dbHelper( SisReg->GetDbHelper());
       
   602 				
       
   603 			TUid aAppUid = appInfoReader->AppUid();
       
   604 			int val = dbHelper->IsAppUidInstalled(aAppUid.GetUid());
       
   605 			if(!val)
       
   606 			{
       
   607 				aNewFileFlag = 1;
       
   608 				// for sis file entries the software type would always be Native.
       
   609 				aScrPreProvisionDetail.iSoftwareTypeName = L"native";;
       
   610 						
       
   611 				XmlDetails::TScrPreProvisionDetail::TComponent component;
       
   612 				CreateApplicationRegistrationInfoL(component,appInfoReader);
       
   613 				aScrPreProvisionDetail.iComponents.push_back(component);
       
   614 			}
       
   615 			else
       
   616 			{
       
   617 				std::cout<<",Ignoring : AppUid "<<hex<<aAppUid.iUid<<" already present in SCR.";
       
   618 			}
       
   619 		}
       
   620 		else
       
   621 		{
       
   622 			delete appInfoReader;
       
   623 			std::string errMsg= "Reading Resource File failed.";
       
   624 			throw CResourceFileException(errMsg);
       
   625 		}
       
   626 		delete appInfoReader;
       
   627 	}
       
   628 
       
   629 }
       
   630 
       
   631 /**
       
   632  * Parse the Directory for resource file.
       
   633  */
       
   634 
       
   635 void ParseResourceDir(const CParameterList* aParamList, const CInterpretSIS& aInterpretSis)
       
   636 {
       
   637 	std::wstring aFilePath;
       
   638 	int iNewFileFlag = 0;
       
   639 
       
   640 	if ( aParamList->IsFlagSet(CParameterList::EFlagsResourceFilePathSet)) 
       
   641 	{
       
   642 	 	aFilePath = aParamList->ResourceFilePath();
       
   643 	}
       
   644 	else
       
   645 	{
       
   646 		 aFilePath = aParamList->RomDrivePath();
       
   647 		 #ifdef __LINUX__
       
   648 		 aFilePath.append(L"/private/10003a3f/apps");
       
   649 		 #else
       
   650 		 aFilePath.append(L"\\private\\10003a3f\\apps");
       
   651 		 #endif
       
   652 	}
       
   653 
       
   654 	int iCount = 0;
       
   655 	std::list<std::wstring> regDirs;
       
   656 	GetDirContents( aFilePath, regDirs );
       
   657 
       
   658 	// store the object in registry database
       
   659 	XmlDetails::TScrPreProvisionDetail scrPreProvisionDetail;
       
   660 
       
   661 	std::list<std::wstring>::iterator curr = regDirs.begin();
       
   662 	for( curr = regDirs.begin(); curr != regDirs.end(); ++curr )
       
   663 	{
       
   664 		try
       
   665 		{
       
   666 			if (curr->find(AppResourceFileExtension,0) != std::wstring::npos)
       
   667 			{
       
   668 				iCount++;
       
   669 			    std::string fName;
       
   670 		        fName = wstring2string( *curr );
       
   671 				std::string FilePath = wstring2string(aFilePath);
       
   672 				#ifdef __LINUX__				
       
   673 				FilePath.append("/");
       
   674 				#else
       
   675 				FilePath.append("\\");
       
   676 				#endif
       
   677 
       
   678 				FilePath.append(fName);
       
   679 				std::cout<<"Parsing - "<<fName<<" ";
       
   680 				ReadApplicationInformationFromResourceFilesL(scrPreProvisionDetail,FilePath,aParamList,aInterpretSis,iNewFileFlag);
       
   681 				std::cout<<" "<<std::endl;
       
   682 			}
       
   683 		}
       
   684 		catch(const CResourceFileException& aObject)
       
   685 		{
       
   686 			//LERROR(L"Resource File Parsing Error - ");
       
   687 			//aObject.Display();
       
   688 		}
       
   689 	}
       
   690 
       
   691 	if(iNewFileFlag)
       
   692 		UpdateInstallationInformation_xml(aParamList,scrPreProvisionDetail);
       
   693 	
       
   694 	if(!iCount)
       
   695 		LINFO(L"No Resource File in the Directory Specified - ");
       
   696 }
       
   697 
       
   698 /**
       
   699  * Backup hash files for re-installation (SA over SA or PU over PU)
       
   700  */
       
   701 void BackupHashForFile(const std::wstring& aFile, const int aDriveLetter, const std::wstring& aPath)
       
   702 {
       
   703 	#ifdef __LINUX__
       
   704 	std::wstring hashdir = L"$:/sys/hash/";
       
   705 	#else
       
   706 	std::wstring hashdir = L"$:\\sys\\hash\\";
       
   707 	#endif
       
   708 
       
   709 	std::wstring basename = aFile.substr( aFile.rfind( KDirectorySeparator ) + 1) ;
       
   710 	if (basename.size() == 0)
       
   711 	{
       
   712 		#ifdef __LINUX__
       
   713 		basename = aFile.substr(aFile.rfind(L"/"));
       
   714 		#else
       
   715 		basename = aFile.substr(aFile.rfind(L"\\"));
       
   716 		#endif
       
   717 	}
       
   718 
       
   719 	hashdir[0] = aDriveLetter;
       
   720 	#ifdef __LINUX__
       
   721 	std::wstring hashFile = aPath + L"/sys/hash/" + basename;
       
   722 	#else
       
   723 	std::wstring hashFile = aPath + L"\\sys\\hash\\" + basename;
       
   724 	#endif
       
   725 
       
   726 	if (FileExists(hashFile))
       
   727 	{
       
   728 		std::string iLocalFile = wstring2string(hashFile);
       
   729 		std::string iBackupFile = wstring2string(hashFile);
       
   730 		iBackupFile.append("_backup");
       
   731 
       
   732 		int err=FileCopyA(iLocalFile.c_str(),iBackupFile.c_str(),0);
       
   733 		if (err != 0)
       
   734 			LERROR(L"Failed to Backup hash file ");
       
   735 	}
       
   736 }
       
   737 
       
   738 /**
       
   739  * Restore hash files for re-installation (SA over SA or PU over PU)
       
   740  */
       
   741 void RestoreHashForFile(const std::wstring& aFile, const int aDriveLetter, const std::wstring& aPath)
       
   742 {
       
   743 	#ifdef __LINUX__
       
   744 	std::wstring hashdir = L"$:/sys/hash/";
       
   745 	#else
       
   746 	std::wstring hashdir = L"$:\\sys\\hash\\";
       
   747 	#endif
       
   748 	std::wstring basename = aFile.substr( aFile.rfind( KDirectorySeparator ) + 1) ;
       
   749 	if (basename.size() == 0)
       
   750 	{
       
   751 		#ifdef __LINUX__
       
   752 		basename = aFile.substr(aFile.rfind(L"/"));
       
   753 		#else
       
   754 		basename = aFile.substr(aFile.rfind(L"\\"));
       
   755 		#endif
       
   756 	}
       
   757 
       
   758 	hashdir[0] = aDriveLetter;
       
   759 	#ifdef __LINUX__
       
   760 	std::wstring hashFile = aPath + L"/sys/hash/" + basename;
       
   761 	#else
       
   762 	std::wstring hashFile = aPath + L"\\sys\\hash\\" + basename;
       
   763 	#endif	
       
   764 	std::wstring LocalFile(hashFile);
       
   765 	hashFile.append(L"_backup");
       
   766 
       
   767 	if (FileExists(hashFile))
       
   768 	{
       
   769 		std::string iLocalFile = wstring2string(LocalFile);
       
   770 		std::string iBackupFile = wstring2string(hashFile);
       
   771 
       
   772 		int err = FileMoveA(iBackupFile.c_str(),iLocalFile.c_str());
       
   773 		if (err != 0)
       
   774 		    LERROR(L"Failed to Restore hash file ");
       
   775 	}
       
   776 }
       
   777 
       
   778 /**
       
   779  * Returns the size of the first occurance of an invalid directory separator.
       
   780  * @param aPath Path to be validated.
       
   781  * @param aIndex index from which the search begin. On function return this 
       
   782  * 				index will point to the illegal directory separator. 
       
   783  * @return 0 if path is valid. Else the number of character to be replaced.
       
   784  * e.g. /sys/bin/ should be replaced with \sys\bin\
       
   785  * and //sys//bin// should be replaced with \sys\bin\
       
   786  */ 
       
   787 
       
   788 // Constants
       
   789 #ifdef __LINUX__
       
   790 const std::wstring KSisDirectorySeparatortap( L"/" );
       
   791 #else
       
   792 const std::wstring KSisDirectorySeparatortap( L"\\" );
       
   793 #endif
       
   794 
       
   795 
       
   796 int FirstInvalidDirSeparatorSizetap(std::wstring& aPath, std::wstring::size_type& aIndex)
       
   797 	{
       
   798 	// If path semantics is correct (as needed by sisx library)
       
   799 	// then the function will return 0
       
   800 	int ret = 0; 
       
   801 	int pos = 0;
       
   802 	#ifdef __LINUX__
       
   803 	if((pos = aPath.find(L"\\\\", aIndex)) != std::wstring::npos)
       
   804 	#else
       
   805 	if((pos = aPath.find(L"//", aIndex)) != std::wstring::npos)
       
   806 	#endif
       
   807 		{
       
   808 		ret = 2;
       
   809 		}
       
   810 	#ifdef __LINUX__
       
   811 	else if((pos = aPath.find(L"\\", aIndex)) != std::wstring::npos)
       
   812 	#else
       
   813 	else if((pos = aPath.find(L"/", aIndex)) != std::wstring::npos)
       
   814 	#endif
       
   815 		{
       
   816 		ret = 1;
       
   817 		}
       
   818 	aIndex = pos;
       
   819 	return ret;
       
   820 	}
       
   821 
       
   822 std::wstring FixPathDelimiterstap( const std::wstring& aString )
       
   823     {
       
   824     std::wstring ret = aString;
       
   825 	std::wstring::size_type idx = 0;
       
   826     int len = 0;
       
   827 	while(len = FirstInvalidDirSeparatorSizetap(ret, idx))
       
   828         {
       
   829 		ret.replace( idx, len, KSisDirectorySeparatortap );
       
   830         }
       
   831     return ret;
       
   832     }