secureswitools/swisistools/source/interpretsislib/installer.cpp
changeset 25 98b66e4fb0be
parent 24 84a16765cd86
child 33 8110bf1194d1
equal deleted inserted replaced
24:84a16765cd86 25:98b66e4fb0be
    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 
    24 #include "dirparse.h"
       
    25 #ifndef __TOOLS2_LINUX__
       
    26 #include <windows.h>
       
    27 #endif 
    25 #endif //SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    28 #endif //SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
    26 #include <exception>
    29 #include <exception>
    27 #include <sstream>
    30 #include <sstream>
    28 #include <algorithm>
    31 #include <algorithm>
    29 #include <functional>
    32 #include <functional>
   281 	}
   284 	}
   282 
   285 
   283 	InstallableFiles installable;
   286 	InstallableFiles installable;
   284 	GetInstallableFiles(file, installable, *iExpressionEvaluator, aInstallSISFile.iTargetDrive);
   287 	GetInstallableFiles(file, installable, *iExpressionEvaluator, aInstallSISFile.iTargetDrive);
   285 
   288 
       
   289 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   290 	TBool iBackupFlag = false;
       
   291 	Backup(file, installable, iBackupFlag);
       
   292 #endif
       
   293 
   286 	// Uninstall the same package (if found) prior to any installation
   294 	// Uninstall the same package (if found) prior to any installation
   287 	UninstallPkg(file);
   295 	UninstallPkg(file);
   288 
   296 
   289 	CheckDestinations(file, installable, aInstallSISFile);
   297 	CheckDestinations(file, installable, aInstallSISFile);
   290 
   298 
   291 	InstallFiles(installable, iParamList.SystemDriveLetter());
   299 	InstallFiles(installable, iParamList.SystemDriveLetter());
   292 
   300 
       
   301 #ifndef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
   293 	UpdateRegistry(file, installable, aInstallSISFile, aInstallSISFile.iSUFlag);
   302 	UpdateRegistry(file, installable, aInstallSISFile, aInstallSISFile.iSUFlag);
   294 	
   303 #else
       
   304 	try {
       
   305 
       
   306 		UpdateRegistry(file, installable, aInstallSISFile, aInstallSISFile.iSUFlag);
       
   307 	}
       
   308 	catch  (...)
       
   309 	{//Update Registry Failed. UnInstall the files.
       
   310 		InstallableFiles::const_iterator filedesIter; 
       
   311 		std::wstring itargetLocalFile;
       
   312 
       
   313 		for(filedesIter = installable.begin() ; filedesIter != installable.end(); ++filedesIter)
       
   314 		{
       
   315 		    itargetLocalFile = (*filedesIter)->GetLocalTarget();
       
   316 			
       
   317 			if (FileExists(itargetLocalFile))
       
   318 			{
       
   319 				RemoveFile(itargetLocalFile);
       
   320 				RemoveHashForFile(itargetLocalFile, iParamList.SystemDriveLetter(), iParamList.SystemDrivePath());
       
   321 			}
       
   322 		}
       
   323 		Restore(file, installable, iBackupFlag);
       
   324 		FreeInstallableFiles(installable);
       
   325 		return RSC_PARSING_ERROR;
       
   326 	}
       
   327 
       
   328 	if(iBackupFlag)
       
   329 		RemoveBackup(file, installable);
       
   330 #endif
       
   331 
   295 	if (aInstallSISFile.iGenerateStub)
   332 	if (aInstallSISFile.iGenerateStub)
   296 	{
   333 	{
   297 		CreateStubSisFile(aInstallSISFile, file);
   334 		CreateStubSisFile(aInstallSISFile, file);
   298 	}
   335 	}
   299 
   336 
   417 
   454 
   418 	// Regenerate the ROM stub registry entries for eclipsing check later.
   455 	// Regenerate the ROM stub registry entries for eclipsing check later.
   419 	iRegistry.GenerateStubRegistry();
   456 	iRegistry.GenerateStubRegistry();
   420 }
   457 }
   421 
   458 
       
   459 #ifdef SYMBIAN_UNIVERSAL_INSTALL_FRAMEWORK
       
   460 // Backup all installed files for this Uid's packages and all the SisRegistry Entries
       
   461 void Installer::Backup(const SisFile& aFile, InstallableFiles& aInstallable, TBool& aBackupFlag)
       
   462 {
       
   463 	TUint32 uid = aFile.GetPackageUid();
       
   464 	TUint32 installType = aFile.GetInstallType();
       
   465 
       
   466 	// Check to see the SA is installed, else backup is not required.
       
   467 	if (iRegistry.IsInstalled(uid) && ((installType == CSISInfo::EInstInstallation) || (installType == CSISInfo::EInstPartialUpgrade)))
       
   468 	{
       
   469 		aBackupFlag = true;
       
   470 		int err = 0;
       
   471 		LINFO(L"Backup package \"" << aFile.GetPackageName() << L"\" prior to re-installation");
       
   472 
       
   473 		// Backup all installed files for this Uid's packages and all the SisRegistry Entries
       
   474 		iRegistry.BackupCtl(uid);
       
   475 
       
   476 		//Backup SCR DB
       
   477 		std::string DbPath = iRegistry.GetDbPath();
       
   478 		if (FileExists(string2wstring(DbPath)))
       
   479 		{	
       
   480 			std::string BackupDb(DbPath);
       
   481 			BackupDb.append("_backup");
       
   482 
       
   483 		 	err=FileCopyA(DbPath.c_str(),BackupDb.c_str(),0);
       
   484 			if (err == 0)
       
   485 				LERROR(L"Failed to Backup Database scr.db ");
       
   486 		}
       
   487 
       
   488 		// Backup all installed files for this Uid's packages and all the SisRegistry Entries
       
   489 		InstallableFiles::const_iterator filedesIter; 
       
   490 		//Backup files
       
   491 		for(filedesIter = aInstallable.begin() ; filedesIter != aInstallable.end(); ++filedesIter)
       
   492 		{
       
   493 			std::wstring itargetLocalFile = (*filedesIter)->GetLocalTarget();
       
   494 			if (FileExists(itargetLocalFile))
       
   495 			{
       
   496 				std::wstring itargetBackupFile = (*filedesIter)->GetLocalTarget();
       
   497 				itargetBackupFile.append(L"_backup");
       
   498 				int pos =0;
       
   499 				if((pos = itargetBackupFile.find(L"\\sys\\bin\\", 0)) != std::wstring::npos)
       
   500 				{
       
   501 					BackupHashForFile(itargetLocalFile, iParamList.SystemDriveLetter(), iParamList.SystemDrivePath());
       
   502 				}
       
   503 
       
   504 				std::string iLocalFile = wstring2string(itargetLocalFile);
       
   505 				std::string iBackupFile = wstring2string(itargetBackupFile);
       
   506 
       
   507 				err=FileCopyA(iLocalFile.c_str(),iBackupFile.c_str(),0);
       
   508 				if (err == 0)
       
   509 					LERROR(L"Failed to Backup installable file ");
       
   510 			}
       
   511 		}
       
   512 	}
       
   513 }
       
   514 
       
   515 // Remove Backup of all installed files for this Uid's packages and all the SisRegistry Entries
       
   516 void Installer::RemoveBackup(const SisFile& aFile, InstallableFiles& aInstallable)
       
   517 {
       
   518 	TUint32 uid = aFile.GetPackageUid();
       
   519 	TUint32 installType = aFile.GetInstallType();
       
   520 
       
   521 	// Check to see the SA is installed, else backup is not required.
       
   522 	if (iRegistry.IsInstalled(uid) && ((installType == CSISInfo::EInstInstallation) || (installType == CSISInfo::EInstPartialUpgrade)))
       
   523 	{
       
   524 		LINFO(L"Remove Backup of package \"" << aFile.GetPackageName() << L"\" after re-installation success");
       
   525 		// Remove all installed files for this Uid's packages and all the SisRegistry Entries
       
   526 		iRegistry.RemoveCtlBackup(uid);
       
   527 
       
   528 		//Remove Backup SCR DB
       
   529 		std::string DbPath = iRegistry.GetDbPath();
       
   530 		std::string BackupDb(DbPath);
       
   531 		BackupDb.append("_backup");
       
   532 		std::wstring DbBackup = string2wstring(BackupDb);
       
   533 
       
   534 		if (FileExists(DbBackup))
       
   535 			RemoveFile(DbBackup);
       
   536 	
       
   537 		// Remove all installed files for this Uid's packages and all the SisRegistry Entries
       
   538 		InstallableFiles::const_iterator filedesIter; 
       
   539 		std::wstring itargetLocalFile;
       
   540 		std::wstring itargetBackupFile;
       
   541 
       
   542 		for(filedesIter = aInstallable.begin() ; filedesIter != aInstallable.end(); ++filedesIter)
       
   543 		{
       
   544 		    itargetLocalFile = (*filedesIter)->GetLocalTarget();
       
   545 			itargetBackupFile = (*filedesIter)->GetLocalTarget();
       
   546 			itargetBackupFile.append(L"_backup");
       
   547 			
       
   548 			if (FileExists(itargetBackupFile))
       
   549 			{
       
   550 				RemoveFile(itargetBackupFile);
       
   551 				RemoveHashForFile(itargetBackupFile, iParamList.SystemDriveLetter(), iParamList.SystemDrivePath());
       
   552 			}
       
   553 		}
       
   554 	}
       
   555 }
       
   556 
       
   557 // Restore all installed files for this Uid's packages and all the SisRegistry Entries
       
   558 void Installer::Restore(const SisFile& aFile, InstallableFiles& aInstallable, TBool& aBackupFlag)
       
   559 {
       
   560 	TUint32 uid = aFile.GetPackageUid();
       
   561 	TUint32 installType = aFile.GetInstallType();
       
   562 
       
   563 	// Check to see the SA is installed, else backup is not required.
       
   564 	if((installType == CSISInfo::EInstInstallation) || (installType == CSISInfo::EInstPartialUpgrade))
       
   565 	{
       
   566 		LINFO(L"Restoring Installed Package ");
       
   567 
       
   568 		// Restore all .ctl file for this Uid's packages and all the SisRegistry Entries
       
   569 		iRegistry.RestoreCtl(uid, aBackupFlag);
       
   570 
       
   571 		// Restore all installed files for this Uid's packages and all the SisRegistry Entries
       
   572 		InstallableFiles::const_iterator filedesIter; 
       
   573 		for(filedesIter = aInstallable.begin() ; filedesIter != aInstallable.end(); ++filedesIter)
       
   574 		{
       
   575 			std::wstring itargetLocalFile = (*filedesIter)->GetLocalTarget();
       
   576 			std::wstring itargetBackupFile = (*filedesIter)->GetLocalTarget();
       
   577 			itargetBackupFile.append(L"_backup");
       
   578 			if (FileExists(itargetBackupFile))
       
   579 			{
       
   580 				int pos =0;
       
   581 				if((pos = itargetBackupFile.find(L"\\sys\\bin\\", 0)) != std::wstring::npos)
       
   582 				{
       
   583 					RestoreHashForFile(itargetLocalFile, iParamList.SystemDriveLetter(), iParamList.SystemDrivePath());
       
   584 				}
       
   585 
       
   586 				std::string iLocalFile = wstring2string(itargetLocalFile);
       
   587 				std::string iBackupFile = wstring2string(itargetBackupFile);
       
   588 				
       
   589 				int err = FileMoveA(iBackupFile.c_str(),iLocalFile.c_str());
       
   590 
       
   591 				if (err == 0)
       
   592 					LERROR(L"Failed to Restore file ");
       
   593 			}
       
   594 		}
       
   595 	}
       
   596 }
       
   597 #endif
   422 
   598 
   423 struct CheckDependencyMet
   599 struct CheckDependencyMet
   424 {
   600 {
   425 	CheckDependencyMet(
   601 	CheckDependencyMet(
   426 		Installer& aInstaller,
   602 		Installer& aInstaller,