

/** This function needs to be called before the first use of the installation library and after each installation.

@return 0 - "success"  -1 - error 
@author S. Schmeling
*/


int fwInstallation_init()
{
	dyn_string dataPointTypes;
	int dataPointTypeExists;
	int dpCreateResult;
	dyn_string 	dynPostInstallFiles_all; // all the postInstall init files to be executed
	dyn_string dynScripts;
	int i;
	int iReturn;
	dyn_float dreturnf;
	dyn_string dreturns;
	string testString;
	
	// get the dpts from the system	
	dataPointTypes = dpTypes();
	
	// check whether the _FwInstallationComponents dpt exists
	dataPointTypeExists = dynContains(dataPointTypes, "_FwInstallationComponents");
	
	
	if ( dataPointTypeExists > 0)
	{
		// if it exists
		
		// SMS: Perform a check if the new datapoint format has already been applied

		dpCreate("fw_InstallationProbing","_FwInstallationComponents");		
		if(!dpExists("fwInstallation_fwInstallationProbing.componentVersionString"))
		{
			// change the installation tool internal data points	
			_fwInstallation_createDataPointTypes(FALSE, dpCreateResult);
		}	
		dpDelete("fw_InstallationProbing");
		
		// check whether there are some postInstall init files to be executed

		
		if(dpExists("fwInstallationInfo"))
		{
			// get all the post install init files
			dpGet("fwInstallationInfo.postInstallFiles:_original.._value", dynPostInstallFiles_all);
			// for each post install init file
			for(i = 1; i <= dynlen(dynPostInstallFiles_all); i++)
			{
				DebugN("Executing post install init files ...");
				
				// execute the file	
				_fwInstallation_evalScriptFile(dynPostInstallFiles_all[i] , iReturn);
				
				// check the return value
				if(iReturn == -1)
				{
					DebugN("   Error executing : " + dynPostInstallFiles_all[i] + " file.");
				}
				else
				{
					DebugN("  " + dynPostInstallFiles_all[i] + " - OK ");

				}
					
			}
			
			// all the files were executed - if there were any errors the user has been informed
			// clearing the fwInstallationInfo.postInstallFiles:_original.._value
			
			dynClear(dynPostInstallFiles_all);
			
			dpSet("fwInstallationInfo.postInstallFiles:_original.._value", dynPostInstallFiles_all);
			
		}
	}
	else
	{
		//	Debug("\n The data point types for the installation tool do not exist");
		// starting the installatio tool for the first time
		
		DebugN("Starting the Installation Tool for the first time");
		DebugN("Importing the Data Point Types ... ");
	
		// create the installation tool internal data points	
		_fwInstallation_createDataPointTypes(TRUE, dpCreateResult);
		
		// check the result
		if (dpCreateResult == 0)
		{
			// display the info for the user
			DebugN("Internal data points for the installation tool created");
		}
		else
		{
			// display the error information
			DebugN("ERROR: in creating the internal data points. Please restart the application");
		}
		
		// check if fwScripts.lst exists
		// if not generate it and add an entry to it
				
		if(access(getPath(SCRIPTS_REL_PATH) + "fwScripts.lst", F_OK) == 0)
		{

		}
		else
		{
			// the file does not exist - create it
			dynAppend(dynScripts, "fwInstallationFakeScript.ctl");
			_fwInstallation_saveFile( dynScripts, getPath(SCRIPTS_REL_PATH) + "fwScripts.lst");
		}
	}
}

// **************************************************************************************************************
// **************************************************************************************************************
//
//
// Functions related to the handling of the config file
//
//
// **************************************************************************************************************
// **************************************************************************************************************



// **************************************************************************************************************
//
//
// Functions related to the handling of project paths
//
//
// **************************************************************************************************************

/** The function reads all project paths from the config file into a dyn_string.

@param projPaths: dyn_string which will be filled with the project paths from the config file
@return 0 - "success"  -1 - error   -2 - no prject paths in the config file (this should not happen)
@author S. Schmeling
*/

int fwInstallation_getProjPaths( dyn_string & projPaths )
{
	dyn_string configLines;
	
	dyn_string tempLines;
	string tempLine;
	int i,j;
	bool sectionFound = FALSE;
	
	if(_fwInstallation_getConfigFile(configLines) == 0)
	{
		for (i=1; i<=dynlen(configLines)-1; i++)
		{
			tempLine = strltrim(strrtrim(configLines[i]));
			tempLines = strsplit(tempLine,"=");
			if(strltrim(strrtrim(tempLines[1])) == "proj_path")
			{
				sectionFound = TRUE;
				dynAppend(projPaths, strltrim(strrtrim(tempLines[2])));
			}
		}			
		if(sectionFound == TRUE)
		{
			return 0;
		} else {
			return -2;
		}
	} else {
		return -1;
	}
}


/** This functions writes all project paths given in a dyn_string to the config file and overwrites existing paths exept the main project path.

@param projPaths: dyn_string with the project paths for the config file
@return 0 - "success"  -1 - error 
@author S. Schmeling
*/

int fwInstallation_setProjPaths( dyn_string projPaths )
{
	dyn_string configLines;
	
	dyn_int tempPositions;
	dyn_string tempLines;
	string tempLine;
	int i,j;
	bool sectionFound = FALSE;
	
	string configPath = getPath(CONFIG_REL_PATH);
	string configFile = configPath + "config";

	if(_fwInstallation_getConfigFile(configLines) == 0)
	{
		for (i=1; i<=dynlen(configLines); i++)
		{
			tempLine = configLines[i];
			if(strpos(tempLine, "proj_path") >= 0)
			{
				dynAppend(tempPositions,i);
			}
		}
		if(dynlen(tempPositions)>0)
		{
			sectionFound = TRUE;
			dynClear(tempLines);
			for (j=1; j<=dynlen(projPaths); j++)
			{
				tempLine = "proj_path = \"" + projPaths[j] + "\"";
				dynAppend(tempLines,tempLine);
			}
			for (j=dynlen(tempPositions); j>=1; j--)	
			{
				dynRemove(configLines,tempPositions[j]);
			}
			dynInsertAt(configLines,tempLines,tempPositions[1]);
		}
		if(sectionFound == TRUE)
		{
			return _fwInstallation_saveFile(configLines, configFile);
		} else {
			return -2;
		}
	} else {
		return -1;
	}
}


/** This function add a project path to the config file.

@param projPath: string that contains the project path to be added to the config file
@param position: position of the added path in the list (n = specified position, try 999 for last before main project path)
@return 0 - "success"  -1 - error  -2 - position out of range
@author S. Schmeling
*/

int fwInstallation_addProjPath( string projPath, int position )
{
	dyn_string configLines;
	
	dyn_int tempPositions;
	string tempLine;
	int i,j;
	bool sectionFound = FALSE;
	
	string configPath = getPath(CONFIG_REL_PATH);
	string configFile = configPath + "config";

	if(_fwInstallation_getConfigFile(configLines) == 0)
	{
		for (i=1; i<dynlen(configLines); i++)
		{
			tempLine = configLines[i];
			if(strpos(tempLine, "proj_path") >= 0)
			{
				dynAppend(tempPositions,i);
			}
		}
		if(dynlen(tempPositions)>0)
		{
			sectionFound = TRUE;
			tempLine = "proj_path = \"" + projPath + "\"";
			if(position > 0) 
			{
				if(position < dynlen(tempPositions))
				{
					dynInsertAt(configLines,tempLine,tempPositions[position]);
				} else {
					dynInsertAt(configLines,tempLine,tempPositions[dynlen(tempPositions)]);
				}
			}			
		}
		if(sectionFound == TRUE)
		{
			return _fwInstallation_saveFile(configLines, configFile);
		} else {
			return -2;
		}
	} else {
		return -1;
	}
}


/** This function removes the given project path from the config file.

@param projPath: string that contains the project path to be removed from the config file
@return 0 - "success"  -1 - general error   -2 - project path does not exist
@author S. Schmeling
*/

int fwInstallation_removeProjPath( string projPath )
{
	dyn_string configLines;
	
	dyn_int tempPositions;
	dyn_string tempLines;
	string tempLine;
	int i,j;
	bool sectionFound = FALSE;
	
	string configPath = getPath(CONFIG_REL_PATH);
	string configFile = configPath + "config";

	if(_fwInstallation_getConfigFile(configLines) == 0)
	{
		for (i=1; i<=dynlen(configLines); i++)
		{
			tempLine = configLines[i];
			if(strpos(tempLine, "proj_path") >= 0)
			{
				if(strpos(tempLine, projPath) >= 0)
				{
					dynAppend(tempPositions,i);
				}
			}
		}
		if(dynlen(tempPositions)>0)
		{
			sectionFound = TRUE;
			for (j=dynlen(tempPositions); j>=1; j--)	
			{
				dynRemove(configLines,tempPositions[j]);
			}
		}
		if(sectionFound == TRUE)
		{
			return _fwInstallation_saveFile(configLines, configFile);
		} else {
			return -2;
		}
	} else {
		return -1;
	}
}

// **************************************************************************************************************
//
//
// Functions related to the handling of libraries in the config file
//
//
// **************************************************************************************************************

/** This function adds a library entry to a specified section of the config file.

@param section: string to define the section where the library has to be added (will be created if not existing)
@param libraryName: dyn_string containing the library names to be added
@return 0 - "success"  -1 - error 
@author S. Schmeling
*/

int fwInstallation_addLibrary( string section, dyn_string libraryName )
{
	dyn_string configLines;
	
	dyn_int tempPositions;
	string tempLine;
	int i,j,k;
	bool sectionFound = FALSE;
	
	string configPath = getPath(CONFIG_REL_PATH);
	string configFile = configPath + "config";

	j = -1;

	if(dynlen(libraryName) > 0)
	{
		if(_fwInstallation_getConfigFile(configLines) == 0)
		{
			for (i=1; i<dynlen(configLines); i++)
			{
				tempLine = configLines[i];
				if(strpos(strltrim(strrtrim(tempLine)), "["+section+"]") = 0)
				{
					j = i;
					break;
				}
			}
			if(j > 0)
			{
				sectionFound = TRUE;
				for(k=dynlen(libraryName); k>0; k--)
				{
					tempLine = "LoadCtrlLibs = \"" + libraryName[k] + "\"";
					dynInsertAt(configLines,tempLine,j+1);
				}
			}
			if(sectionFound == TRUE)
			{
				return _fwInstallation_saveFile(configLines, configFile);
			} else {
				return -2;
			}
		} else {
			return -1;
		}
	}
}


// **************************************************************************************************************
//
//
// Functions related to the handling of sections
//
//
// **************************************************************************************************************

/** This function adds the given lines to a section in the config file.

@param section: string to define the section where the data has to be added (will be created if not existing)
@param configEntry: dyn_string containing the lines to be added
@return 0 - "success"  -1 - error 
@author S. Schmeling
*/

int fwInstallation_addToSection( string section, dyn_string configEntry )
{
	dyn_string configLines;
	
	dyn_int tempPositions;
	dyn_string tempLines;
	string tempLine;
	int i,j;
	bool sectionFound = FALSE;
	
	string configPath = getPath(CONFIG_REL_PATH);
	string configFile = configPath + "config";

	j = -1;

	if(_fwInstallation_getConfigFile(configLines) == 0)
	{
		for (i=1; i<dynlen(configLines); i++)
		{
			tempLine = configLines[i];
			if(strpos(strltrim(strrtrim(tempLine)), "["+section+"]") == 0)
			{
				j = i;
				break;
			}
		}
		if(j > 0)
		{
			tempLines = configEntry;
			dynInsertAt(configLines,tempLines,j+1);
		} else {
			tempLine = "[" + section + "]";
			dynInsertAt(tempLines,tempLine,1);
			dynAppend(configLines,tempLines);
		}
		return _fwInstallation_saveFile(configLines, configFile);
	} else {
		return -1;
	}
}





/** This function gets a specified section into a dyn_string

@param section: string to define the section 
@param configEntry: dyn_string that will contain the lines for the section
@return 0 - "success"  -1 - error  -2 - section does not exist
@author S. Schmeling
*/

int fwInstallation_getSection( string section, dyn_string & configEntry )
{
	dyn_string configLines;
	
	dyn_string tempLines;
	string tempLine;
	int i,j;
	bool sectionFound = FALSE;
	
	string configPath = getPath(CONFIG_REL_PATH);
	string configFile = configPath + "config";

	if(_fwInstallation_getConfigFile(configLines) == 0)
	{
		for (i=1; i<=dynlen(configLines); i++)
		{
			tempLine = configLines[i];
			if(strpos(strltrim(strrtrim(tempLine)), "["+section+"]") == 0)
			{
				if(sectionFound == FALSE)
				{
					sectionFound = TRUE;
				}
				j = 1;
				do
				{
					tempLine = configLines[i+j];
					if(strpos(strltrim(strrtrim(tempLine)),"[") != 0)
					{
						if(tempLine != "")
						{
							dynAppend(tempLines,tempLine);
						}
						j++;
					}
				}
				while ((strpos(strltrim(strrtrim(tempLine)),"[") != 0) && (i+j <=dynlen(configLines)));
				i += j-1;
			}
		}
		if(sectionFound == TRUE)
		{
			configEntry = tempLines;
			return 0;
		} else {
			return -2;
		}
	} else {
		return -1;
	}
}


/** This function sets a specified section from a dyn_string

@param section: string to define the section to where the data has to written
@param configEntry: dyn_string that contains the lines for the section
@return 0 - "success"  -1 - error
@author S. Schmeling
*/

int fwInstallation_setSection( string section, dyn_string configEntry )
{
	if(fwInstallation_clearSection( section ) != -1)
	{
		return fwInstallation_addToSection( section, configEntry );	
	} else {
		return -1;
	}
}


/** This function will delete all entries of the specified section as well as all but the first header.

@param section: string to define the section which will be cleared (first header will stay)
@return 0 - "success"  -1 - error  -2 - section does not exist
@author S. Schmeling
*/

int fwInstallation_clearSection( string section )
{
	dyn_string configLines;
	
	dyn_int tempPositions;
	dyn_string tempLines;
	string tempLine;
	int i,j;
	bool sectionFound = FALSE;
	
	string configPath = getPath(CONFIG_REL_PATH);
	string configFile = configPath + "config";

	if(_fwInstallation_getConfigFile(configLines) == 0)
	{
		for (i=1; i<=dynlen(configLines); i++)
		{
			tempLine = configLines[i];
			if(strpos(strltrim(strrtrim(tempLine)), "["+section+"]") == 0)
			{
				if(sectionFound == FALSE)
				{
					sectionFound = TRUE;
				} else {
					dynAppend(tempPositions,i);
				}
				j = 1;
				do
				{
					tempLine = configLines[i+j];
					if(strpos(strltrim(strrtrim(tempLine)),"[") != 0)
					{
						dynAppend(tempPositions,i+j);
						if(tempLine != "")
						{
							dynAppend(tempLines,tempLine);
						}
						j++;
					}
				}
				while ((strpos(strltrim(strrtrim(tempLine)),"[") != 0) && (i+j <=dynlen(configLines)));
				i += j-1;
			}
		}
		if(dynlen(tempPositions)>0)
		{
			for (i=dynlen(tempPositions); i>0; i--)
			{
				dynRemove(configLines, tempPositions[i]);
			}
		}			
		if(sectionFound == TRUE)
		{
			return _fwInstallation_saveFile(configLines, configFile);
		} else {
			return -2;
		}
	} else {
		return -1;
	}
}


/** This function will put together the specified section, that consists of several distributed parts.

@param section: string to define the section which will be compacted
@return 0 - "success"  -1 - error  -2 - section does not exist
@author S. Schmeling
*/

int fwInstallation_compactSection( string section )
{
	dyn_string configLines;
	int returnValue;
	returnValue = fwInstallation_getSection(section, configLines);
	if (returnValue == 0)
	{
		fwInstallation_clearSection(section);
		returnValue = fwInstallation_setSection(section, configLines);
		return returnValue;
	} else {
		return returnValue;
	}
	
}

// **************************************************************************************************************
// **************************************************************************************************************
//
//
// Functions related to the Component Installation
//
//
// **************************************************************************************************************
// **************************************************************************************************************


/** This function returns post install files that are scheduled to run

@param allPostInstallFiles:	dyn_string to contain the list of post install files
@return 0 - "success"  -1 - error 
@author S. Schmeling
*/
int fwInstallation_postInstallToRun(dyn_string & allPostInstallFiles)
{
	dyn_string dynPostInstallFiles_all;
	if(dpExists("fwInstallationInfo"))
	{
		// get all the post install init files
		dpGet("fwInstallationInfo.postInstallFiles:_original.._value", dynPostInstallFiles_all);
		allPostInstallFilles = dynPostInstallFiles_all;
		return 0;
	} else {
		dynClear(allPostInstallFiles);
		return -1;
	}
}







/** This function returns the following property of the installed component: list of files for this component

@param componentName: string with the name of the component 
@param componentProperty: name of the requested property
@param componentInfo: variable that contains the property of the component
@return 0 - "success"  -1 - error 
@author S. Schmeling
*/

int fwInstallation_getComponentInfo( string componentName, string componentProperty, dyn_anytype & componentInfo )
{
	string temp_componentProperty, temp_string;
	float temp_float;
	dyn_anytype temp_dyn_string;
	bool temp_bool;
	int i;
	
	temp_componentProperty = strtolower(componentProperty);
	
	switch(temp_componentProperty)
	{
		case "componentfiles": 
			i = dpGet("fwInstallation_"+strltrim(strrtrim(componentName))+".componentFiles:_original.._value", temp_dyn_string);
			dynAppend(componentInfo, temp_dyn_string);
			return i;
			break;
		case "configGeneral": 
			i = dpGet("fwInstallation_"+strltrim(strrtrim(componentName))+".configFiles.configGeneral:_original.._value", temp_dyn_string);
			dynAppend(componentInfo, temp_dyn_string);
			return i;
			break;
		case "configLinux": 
			i = dpGet("fwInstallation_"+strltrim(strrtrim(componentName))+".configFiles.configLinux:_original.._value", temp_dyn_string);
			dynAppend(componentInfo, temp_dyn_string);
			return i;
			break;
		case "configWindows": 
			i = dpGet("fwInstallation_"+strltrim(strrtrim(componentName))+".configFiles.configWindows:_original.._value", temp_dyn_string);
			dynAppend(componentInfo, temp_dyn_string);
			return i;
			break;
		case "initfiles": 
			i = dpGet("fwInstallation_"+strltrim(strrtrim(componentName))+".initFiles:_original.._value", temp_dyn_string);
			dynAppend(componentInfo, temp_dyn_string);
			return i;
			break;
		case "postinstallfiles": 
			i = dpGet("fwInstallation_"+strltrim(strrtrim(componentName))+".postInstallFiles:_original.._value", temp_dyn_string);
			dynAppend(componentInfo, temp_dyn_string);
			return i;
			break;
		case "dplistfiles": 
			i = dpGet("fwInstallation_"+strltrim(strrtrim(componentName))+".dplistFiles:_original.._value", temp_dyn_string);
			dynAppend(componentInfo, temp_dyn_string);
			return i;
			break;
		case "requiredcomponents": 
			i = dpGet("fwInstallation_"+strltrim(strrtrim(componentName))+".requiredComponents:_original.._value", temp_dyn_string);
			dynAppend(componentInfo, temp_dyn_string);
			return i;
			break;
		case "subcomponents": 
			i = dpGet("fwInstallation_"+strltrim(strrtrim(componentName))+".subComponents:_original.._value", temp_dyn_string);
			dynAppend(componentInfo, temp_dyn_string);
			return i;
			break;
		case "scriptfiles": 
			i = dpGet("fwInstallation_"+strltrim(strrtrim(componentName))+".scriptFiles:_original.._value", temp_dyn_string);
			dynAppend(componentInfo, temp_dyn_string);
			return i;
			break;
		case "date": 
			i = dpGet("fwInstallation_"+strltrim(strrtrim(componentName))+".date:_original.._value", temp_string);
			dynAppend(componentInfo, temp_string);
			return i;
			break;
		case "descfile": 
			i = dpGet("fwInstallation_"+strltrim(strrtrim(componentName))+".descFile:_original.._value", temp_string);
			dynAppend(componentInfo, temp_string);
			return i;
			break;
		case "installationdirectory": 
			i = dpGet("fwInstallation_"+strltrim(strrtrim(componentName))+".installationDirectory:_original.._value", temp_string);
			dynAppend(componentInfo, temp_string);
			return i;
			break;
		case "componentversion": 
		case "componentversionstring": 
			i = dpGet("fwInstallation_"+strltrim(strrtrim(componentName))+".componentVersionString:_original.._value", temp_string);
			if(temp_string == "")
			{
				i += dpGet("fwInstallation_"+strltrim(strrtrim(componentName))+".componentVersion:_original.._value", temp_float);
				if(temp_float == floor(temp_float))
				{
					sprintf(temp_string,"%2.1f",temp_float);
				} else {
					temp_string = temp_float;
				}
				dpSetWait("fwInstallation_" + componentName + ".componentVersionString:_original.._value", componentVersionString);
			}
			dynAppend(componentInfo, temp_string);
			return i;
			break;
		case "requiredinstalled": 
			i = dpGet("fwInstallation_"+strltrim(strrtrim(componentName))+".requiredInstalled:_original.._value", temp_bool);
			dynAppend(componentInfo, temp_bool);
			return i;
			break;
		case "isitsubcomponent": 
			i = dpGet("fwInstallation_"+strltrim(strrtrim(componentName))+".isItSubComponent:_original.._value", temp_bool);
			dynAppend(componentInfo, temp_bool);
			return i;
			break;
		default:
			dynAppend(componentInfo, "Property not known");
			return -1;
	}			
}


/** This function gets the information about all installed components into a dyn_dyn_string structure:
	[n][1] component name
	[n][2] component version
	[n][3] path to the installation

@param componentsInfo: dyn_dyn_string that will contain all installed components and their respective version numbers
@return 0 - "success"  -1 - error   -999999 - no components installed
@author S. Schmeling
*/

int fwInstallation_getInstalledComponents( dyn_dyn_string & componentsInfo )
{
	dyn_dyn_string tempAllInfo;	
	dyn_string componentDPs;
	int i,error;
	string componentVersionString, installationDirectory;
	float componentVersion;

	componentDPs = dpNames("fwInstallation_*");
	dynClear(tempAllInfo);
	
	error = 0;

	if(dynlen(componentDPs) == 0)
	{
		return -999999;
	} else {
		for (i=1; i<=dynlen(componentDPs); i++)
		{
			error += dpGet(componentDPs[i]+".componentVersionString:_original.._value",componentVersionString);
			error += dpGet(componentDPs[i]+".installationDirectory:_original.._value",installationDirectory);
			if(componentVersionString == "")
			{
				dpGet(componentDPs[i] + ".componentVersion:_original.._value", componentVersion);
				if(componentVersion == floor(componentVersion))
				{
					sprintf(componentVersionString,"%2.1f",componentVersion);
				} else {
					componentVersionString = componentVersion;
				}
				dpSetWait(componentDPs[i] + ".componentVersionString:_original.._value", componentVersionString);
			}
			dynAppend(tempAllInfo[i], substr(componentDPs[i],strlen(getSystemName())+15));
			dynAppend(tempAllInfo[i], componentVersionString);
			dynAppend(tempAllInfo[i], installationDirectory);
		}
		componentsInfo = tempAllInfo;
		return error;
	}
}


/** This function gets the information about all available components in the specified paths into a dyn_dyn_string structure:
	- component name
	- component version
	- subcomponent [yes/no]
	- path to the description file

@param componentPaths: dyn_string with the paths to description files
@param componentsInfo: dyn_dyn_string that will contain all installed components and their respective version numbers and their paths
@return 0 - "success"  -1 - error 
@author S. Schmeling, adapted from the panel function getInstalledComponents
*/

int fwInstallation_getAvailableComponents( dyn_string componentPaths, dyn_dyn_string & componentsInfo )
{
 	string dirCurrentValue;
	dyn_string dynAvailableDescriptionFiles;
	string componentFileName;
	string strComponentFile;
	string tagName;
	string tagValue;

	string componentName;
	float componentVersion;
	string componentVersionString;
	
	int result;
	
	bool	fileLoaded;
	bool isItSubComponent = false;
	
	int i, j, ii, iii;

	dyn_dyn_string tempAllInfo;
	dynClear(tempAllInfo);
	iii = 0;

	if(dynlen(componentPaths) == 0)
	{
		return -1;
	}

	for(ii=1; ii<=dynlen(componentPaths); ii++)
	{
		dirCurrentValue = componentPaths[ii];
		// it the directory name is empty
		if (dirCurrentValue != "")
		{
			// read the names of files that have the .xml extension in a directory specified by dirCurrentValue
			dynAvailableDescriptionFiles =  getFileNames( dirCurrentValue, "*.xml");
			
			// for each component description file, read the component name, version and display it in the graphic table
			
			for( i = 1; i <= dynlen(dynAvailableDescriptionFiles); i++)
			{
				// get the file name of an .xml description file
				componentFileName = dynAvailableDescriptionFiles[i];
				
				// load the description file
				fileLoaded = fileToString(dirCurrentValue + "/" + componentFileName, strComponentFile);
				
				if (! fileLoaded )
				{
					DebugN("fwInstallation: Cannot load " + componentFileName + " file for checking");	
				}
				else 
				{
					// the description file in now in string - strComponentFile
					
					// remove the root tag <component>
					
					strreplace(strComponentFile, "<component>", "");
					strreplace(strComponentFile, "</component>", "");
					
					// while there are some tags in the string - get the next tag		
					while( _fwInstallation_getTagFromString(tagName, tagValue, strComponentFile) == 1 )
					{
						switch(tagName)
						{
														// retrieve the component name
									case "name": 		componentName = tagValue;
														break;
														
														// retrieve the component version
									case "version" :	componentVersionString = tagValue;
														componentVersion = tagValue;
														break;
														
															// retrieve the information - is it subcomponent
									case "subComponent":	if((tagValue == "yes") || (tagValue == "Yes") || (tagValue == "YES"))
															{
																isItSubComponent = true;
															}
														break;
						}
					}
					
					// check whether the description file contains the component name
					
					if(componentName != "") 
					{
						iii++;
						dynAppend(tempAllInfo[iii], componentName);
						dynAppend(tempAllInfo[iii], componentVersionString);
						if(isItSubComponent)
						{
							dynAppend(tempAllInfo[iii], "yes");
						} else {
							dynAppend(tempAllInfo[iii], "no");
						}
						dynAppend(tempAllInfo[iii], dirCurrentValue + "/" + componentFileName);
					 	componentName = "";
						isItSubComponent = false;
					}
				
				}
				
			}
		}
	}
	componentsInfo = tempAllInfo;
	return 0;
}


/** This function will install the component named by the description file. No dependency checking is done!

@param componentPaths: string with the locations of the description files
@return 0 - "success"  -1 - error 
@author S. Schmeling
*/

int fwInstallation_installComponents( dyn_string componentPaths , string destinationDir )
{
	string componentsInfo;
	string descFilesInfo;
	string sourceDir;
	dyn_float dreturnf; // the return value of a child panel
	dyn_string dreturns; // the return value of a child panel
	
	dyn_string componentsNames;
	dyn_string componentFiles;
	dyn_string componentsVersions;
	dyn_string componentFilesInOrder;
	dyn_string dynNamesVersions;
	dyn_string tmpDynParamValue;
	bool componentInstalled = false;
	string strComponentFile;
	bool fileLoaded;
	
	string componentName, tagName, tagValue, componentVersionString;
	float componentVersion;
	int dpGetResult;
	
	string temp_string;
	dyn_string dynPostInstallFiles_all;	
	int i,error;

	// get all the post install init files
	dpGetResult = dpGet("fwInstallationInfo.postInstallFiles:_original.._value", dynPostInstallFiles_all);

	
	if(destinationDir == "")
	{	
		return -1;
	}
	else
	{

		dpSet("fwInstallationInfo.installationDirectoryPath:_original.._value", destinationDir);
		// retrieve the component names and the description files of the components to be installed
		for(  i = 1 ; i <= dynlen(componentPaths); i++)
		{
			temp_string = componentPaths[i];
			fileLoaded = fileToString(temp_string, strComponentFile);
			if (! fileLoaded )
			{
				DebugN("fwInstallation: Cannot load " + componentPaths[i] + " file ");	
				return -1;
			}
			else 
			{
				// the description file in now in string - strComponentFile
				// remove the root tag <component>
				strreplace(strComponentFile, "<component>", "");
				strreplace(strComponentFile, "</component>", "");
				// while there are some tags in the string - get the next tag		
				while( _fwInstallation_getTagFromString(tagName, tagValue, strComponentFile) == 1 )
				{
					switch(tagName)
					{
											// retrieve the component name
						case "name": 		componentName = tagValue;
											break;
											// retrieve the component version
						case "version" :	componentVersionString = tagValue;
//											componentVersion = tagValue;
											break;
												// retrieve the information - is it subcomponent
						case "subComponent":	if((tagValue == "yes") || (tagValue == "Yes") || (tagValue == "YES"))
												{
													isItSubComponent = true;
												}
		 										break;
					}
				}
				// check whether the description file contains the component name
				if(componentName != "") 
				{
					dynAppend(componentsNames, componentName);
					dynAppend(componentsVersions, componentVersionString);
					dynAppend(componentFiles, temp_string);
				}
			}
		}
		_fwInstallation_putComponentsInOrder_Install(componentsNames, componentsVersions, componentFiles, componentFilesInOrder);
		// install every component
		for (i =1; i <= dynlen(componentFilesInOrder); i++)
		{
			_fwInstallation_installComponent(componentFilesInOrder[i], false, componentName, componentInstalled, destinationDir, dynPostInstallFiles_all, error);
			if(error!=0)
			{
				return error;
			}
		}
	}
}

/** This function checks if the component is already installed. It checks the PVSSDB.

@param componentName: the name of a component to be checked
@param availableComponentVersion: the version of a component to be checked
@return 1 - "component installed"  0 - "component not installed"
@author M.Sliwinski
	    16.12.2002 Sascha Schmeling		extended for unlimited version number components
*/


fwInstallation_componentInstalled(string componentName, string requestedComponentVersion, int &result)
{
	string installedComponentVersion,dummy;
	float installedComponentVersionOld;
	
	// check whether the component data point exists - if it exists it is installed
	
	if(dpExists("fwInstallation_" + componentName))
	{
		// retrieve the version of installed component
		dpGet("fwInstallation_" + componentName + ".componentVersionString:_original.._value", installedComponentVersion);

		// Legacy
		if(installedComponentVersion == "")
		{
			DebugN("Correcting database of installed components for "+componentName);
			dpGet("fwInstallation_" + componentName + ".componentVersion:_original.._value", installedComponentVersionOld);
			sprintf(dummy,"%5.5f",installedComponentVersionOld);
			installedComponentVersion = strltrim(strrtrim(dummy,"0"));
			if(strpos(installedComponentVersion,".") == strlen(installedComponentVersion)-1)
			{
				installedComponentVersion += "0";
			}
			dpSet("fwInstallation_" + componentName + ".componentVersionString", installedComponentVersion);
		}

		result = (_fwInstallation_CompareVersions(installedComponentVersion,requestedComponentVersion));
	}
	else
	{
		// return the component is not installed
		result = 0;
	}
	
}











/* Internal functions start here!!!

	*** *   * ***** ***** ****  *   *  ***  *       ***** *   * *   *  ***  ***** ***  ***  *   *  ***
	 *  **  *   *   *     *   * **  * *   * *       *     *   * **  * *   *   *    *  *   * **  * *   *
	 *  **  *   *   *     *   * **  * *   * *       *     *   * **  * *       *    *  *   * **  * *   
     *  * * *   *   ****  ****  * * * ***** *       ****  *   * * * * *	      *    *  *   * * * *  ***
     *  *  **   *   *     *   * *  ** *   * *       *     *   * *  ** *       *    *  *   * *  **     *
     *  *  **   *   *     *   * *  ** *   * *       *     *   * *  ** *   *   *    *  *   * *  ** *   *
	*** *   *   *   ***** *   * *   * *   * *****   *      ***  *   *  ***    *   ***  ***  *   *  ***
	
*/


/** This function gets all entries from the config file into string structures

@param configLines: dyn_string containing the lines from the config file 

@author M. Sliwinski, adapted for library by S. Schmeling
*/
	
int _fwInstallation_getConfigFile(dyn_string & configLines)
{
	bool fileLoaded = false;
	string fileInString;
	string configPath = getPath(CONFIG_REL_PATH);
	string configFile = configPath + "config";
	
// load config file into dyn_string
	fileLoaded = fileToString(configFile, fileInString);
	if (! fileLoaded )
	{
		DebugN("fwInstallationLib: Cannot load config file");
		return -1;
	} else {
		configLines = strsplit(fileInString, "\n");
		return 0;
	}
}

/** this function saves the dyn_string  into PVSS project confg file

@param configLines: the dyn_string containing the lines from the  file
@param filename: the name of a file

@author M.Sliwinski
*/

int _fwInstallation_saveFile( dyn_string & configLines, string filename)
{
	int i;
	string strLinesToSave;
	

	file fileHdlConfig;
	
	int writeResult;

	// open the file for writing
	fileHdlConfig = fopen(filename, "w");
	// if the file is not opened
	if(fileHdlConfig == 0)
	{
		DebugN("fwInstallation: File " + filename + " could not be opened");
		return -1;
	}
	else
	{
		// copy each line from a dyn_string into string and separate the lines with newline character
		for(i = 1; i <= dynlen(configLines); i++)
		{
			strLinesToSave += configLines[i] + "\n";
		}
		// save the string into the file
		writeResult = fputs(strLinesToSave , fileHdlConfig);
		// check the result of writing to a file
		if (writeResult == 0)
		{
			DebugN("fwInstallation: File " + filename + " has been saved");
		}
		// close the file					
		fclose(fileHdlConfig);
		return 0;
	}
}



/** This function reads the xml tags from the component description file


@param tagName: the string with the tag name
@param tagValue: the string with the tag value
@param strComponentFile: the string with the XML info about the component
@param return: 1 it the tag was found, -1 - the tag was not found

@author M.Sliwinski
*/

int _fwInstallation_getTagFromString(string & tagName, string & tagValue, string & strComponentFile)
{
	int pos1; // contains the position of an opening tag start 
	int pos2; // contains the position of an opening tag end
	int pos3; // contains the position of a closing tag start
	int pos4; // contains the position of a closing tag end
		
				// get the position of an opening tag start
				pos1 = strpos(strComponentFile, "<");
				
				// get the position of an opening tag end		
				pos2 = strpos(strComponentFile, ">");
	
				//	get the tag name			
				tagName = substr(strComponentFile, pos1 + 1, pos2 - (pos1 + 1));
				
				// get the position of an closing tag start
				pos3 = strpos(strComponentFile, "</" + tagName + ">");
				
				// get the position of an closing tag end
				pos4 = pos3 + strlen("</" + tagName + ">");
				
				// get the tag value
				tagValue = substr(strComponentFile, pos2+1, pos3-(pos2+1));
				
				// remove the bland spaces
				tagValue = strrtrim(strltrim(tagValue));
				
				// remove the tag and the tag value from the string
				strComponentFile = substr(strComponentFile, pos4);
				
				
		if(pos1 >=0)
		{
			// return that the tag was found
			return 1;
		}
		else
		{
			// return that the tag was not found ( there are no more tags )	
			return -1;
		}				
}


/** This function puts the components to be installed in order in which they should be installed
The algorithm is similar to that used during deleting the components - look fwInstallation_putComponentsInOrder_Delete() function btn_ApplyDelete()
@param componentsNames: the names of the components to be installed
@param componentsVersions: the versions of components to be installed
@param componentFiles: the file names with the description of the components
@param componentFilesInOrder: the ordered file names with the description of the components

@author M.Sliwinski
*/

_fwInstallation_putComponentsInOrder_Install(dyn_string & componentsNames, dyn_string & componentsVersions, dyn_string & componentFiles, dyn_string & componentFilesInOrder)
{
	int i, j, k;
	dyn_dyn_string dependencies; //  first column - component name, next columns - components required by this component that will be installed later
	dyn_string tempDynRequired;
	dyn_string tempParamValue;
	dyn_string orderedComponentsNames;
	string tempRequiredName;
	string tempRequiredVersion;
	string tempComponentName;
	bool emptyListExists = true;
	
	// read the component requirements and fill the dependencies table
			
	for(i = 1; i <= dynlen(componentFiles); i++)
	{
		
		// put the components to be installed in 1st column of dependencies table
		dynAppend(dependencies[i] , componentsNames[i]);
		
		// get the list of components required by the component being installed
		_fwInstallation_readComponentRequirements(componentFiles[i], tempDynRequired);
		
		// for each components that are required by component being installed		
		for (j =1; j <= dynlen(tempDynRequired); j++)
		{
			tempParamValue = strsplit(tempDynRequired[j], "=");
			
			// get its name
			tempRequiredName = tempParamValue[1];
			
			if(dynlen(tempParamValue) > 1)
			{
				// get its version
				tempRequiredVersion = tempParamValue[2];
			}
			else
			{
				tempRequiredVersion = 0;
			}
			// the required component will be installed later
			k = dynContains(componentsNames, tempRequiredName);
			
			if(k > 0)
			{
				if(componentsVersions[k] >= tempRequiredVersion)
				{
					dynAppend(dependencies[i], tempRequiredName);
				}
			}
		}	
	}
	
	k = 0;
	
	// put the components in order
	
	while(emptyListExists)
	{	
		emptyListExists = false;
				
				for(i =1; i <= dynlen(componentsNames); i++)
				{
					
					// if the component does not require any components
					if((dynlen(dependencies[i]) == 1) && (dependencies[i][1] != "EMPTY"))
					{
						
						emptyListExists = true;
						
						tempComponentName = dependencies[i][1];
						
						// set the component name to empty
						dependencies[i][1] = "EMPTY";
						
						// append the component name to a list of ordered components		
						dynAppend(componentFilesInOrder, componentFiles[i]);
						dynAppend(orderedComponentsNames, tempComponentName);
												
						for(j = 1; j <= dynlen(componentsNames); j++)
						{
						
							// update the dependencies table
							k = dynContains(dependencies[j], tempComponentName);
							
							if(k > 0)
							{
								 dynRemove(dependencies[j], k);
							}
							
						}
					}
					else
					{
					}
				} 
	}
	
		// if there were unsolved dependencies components depending on each other 
		// copy them to the end
		
		for(i = 1; i <= dynlen(componentsNames); i++)
		{
			if(dependencies[i][1] != "EMPTY")
			{
				dynAppend(componentFilesInOrder, componentFiles[i]);
			}
		}
		
		DebugN("Components put in order: " + componentFilesInOrder);
}



/** This function reads the requirements from the component description file

@param descFile: the file with the description of a component 
@param requiredComponents: the dyn_string of requiredComponents
@author M.Sliwinski
*/

_fwInstallation_readComponentRequirements(string descFile, dyn_string & dynRequiredComponents)
{
	bool	fileLoaded;
	string strComponentFile;
	string tagName;
	string tagValue;
	int i;

	// clear the required components table
	dynClear(dynRequiredComponents);
	
	if(_WIN32)
	{
		strreplace(descFile, "/", "\\");
	}	
	
	// load the description file into strComponentFile string
		
	fileLoaded = fileToString(descFile, strComponentFile);
		
		
		if (! fileLoaded )
		{
		
			DebugN("Cannot load " + descFile + " file for requirements testing");
			
		}
		else 
		{
			// remove the root tag <component>
			
			strreplace(strComponentFile, "<component>", "");
			strreplace(strComponentFile, "</component>", "");
				
				
		// read the requirements tag

			// while there are tags in the string 		
			while( _fwInstallation_getTagFromString(tagName, tagValue, strComponentFile) == 1 )
			{

				switch(tagName)
				{
										//
										case "required":	tagValue = strltrim(tagValue); // remove the white characters
															tagValue = strrtrim(tagValue);
															dynAppend(dynRequiredComponents, tagValue);										
															break;
				}
			}
		}	
}


/** This function installs the component. It copies the files, imports the component DPs, DPTs, updates the project config file

@param descFile: the file with the description of a component 
@param sourceDir: the root directory with the component files
@param isItSubComponent: it is false - if it is the master component; it is true if it is the sub component
@param componentName: it is the return value - the name of the installed component
@author M.Sliwinski
*/

_fwInstallation_installComponent(string descFile, bool isItSubComponent, string & componentName, bool & componentInstalled, string destinationDir, 	dyn_string  & dynPostInstallFiles_all, int & returnValue)
{

	dyn_float dreturnf; // return value of a panel
	dyn_string dreturns; // return value of a panel
	
	string componentFileName; 
	string fileToCopy;
	string asciiManager;
	string infoFile;
	string logFile;
	string cmd;
	string strComponentFile, strTestFile; 
	string asciiFile;
	string result;
	string tmpResult;
	int dpCreated;
	int iReturn; // the return value of function fwInstallation_evalScriptFile;
	int errorInstallingComponent = 1; // has value -1 if there were any errors during the component installation, 1 if everything is OK
	dyn_string dynComponentFileLines;
	dyn_string dynFileNames;
	dyn_string dynComponentFiles;
	dyn_string dynPostInstallFiles_current;
	dyn_string dynPostInstallFiles;
	dyn_string dynConfigFiles_general;
	dyn_string dynConfigFiles_linux;
	dyn_string dynConfigFiles_windows;
	dyn_string dynInitFiles;
	dyn_string dynDplistFiles;
	dyn_string resultInLines;
	dyn_string dynScriptsToBeAdded; 

	// sub Components handling
	
	dyn_string dynSubComponents;
	
	// end sub Components handling

	string componentVersion;
	string date;
	string componentConfigFile = "";
	string dplistFile;
	bool requiredInstalled = true;
	
	// component dependencies
	
	dyn_string dynRequiredComponents;
	
	string strNotInstalledNames = "";
	

	float floatInstalledVersion;
	string strInstalledName; 
	dyn_string  dynNotProperlyInstalled;
	
	// end component dependencies
	
	string tagName;
	string tagValue;
	
	bool	fileLoaded;
	bool x;
	string err;
	string componentInitFile;
	
	int i, j, k;
	int pos1, pos2, pos3, pos4;
	int dpGetResult;
	int fileCopied;

	string temp_string = descFile;
	dyn_string tempPath = strsplit(temp_string, "/");
	string sourceDir = "";	

	int error, errorCounter;
	anytype tempReturn;

	asciiManager = PVSS_BIN_PATH + "PVSS00ascii";
   	infoFile = getPath(LOG_REL_PATH) + "PVSS00ascii_info.log";
   	logFile =  getPath(LOG_REL_PATH) + "PVSS00ascii_log.log";
   	
	// get the destination dir

			if(dynlen(tempPath) > 1)
			{
				for (i=1; i<dynlen(tempPath); i++)
				{
					temp_string = tempPath[i];
					sourceDir += temp_string +"/";
				}
			}

		// load the description file		
		temp_string = descFile;
		fileLoaded = fileToString(temp_string, strComponentFile);
		
		if (! fileLoaded )
		{
			DebugN("Cannot load " + descFile + " file for single installation");
			returnValue = -1;
			return;
		}
		else 
		{
			
			// add the description file to a dyn_string with file names to be copied
			dynAppend(dynFileNames, strrtrim(strltrim(tempPath[dynlen(tempPath)])));		

				

	// retrieving the values of the tags in xml file

		// delete the root tags: <component> and </component>
		
			strreplace(strComponentFile, "<component>", "");
			strreplace(strComponentFile, "</component>", "");
		
		// while the string strComponentFile contains more tags
					
		while( _fwInstallation_getTagFromString(tagName, tagValue, strComponentFile) == 1 )
		{
			
			// check the tagName
			
			switch(tagName)
			{
				case "file" : 		dynAppend(dynFileNames, tagValue);
									dynAppend(dynComponentFiles, tagValue);
									break;

				case "name": 		componentName = tagValue;
									break;
									
				case "version": 	componentVersion = tagValue;
									break;
									
				case "date": 		date = tagValue;
									break;
									
				case "required":	if(tagValue != "")
									dynAppend(dynRequiredComponents, tagValue);
									break;
				
				case "script": 		dynAppend(dynFileNames, tagValue);
									dynAppend(dynScriptsToBeAdded, tagValue);					
									break;
									
				case "config":		dynAppend(dynFileNames, tagValue);

									dynAppend(dynConfigFiles_general, tagValue);
									break;
									
				case "init": 		dynAppend(dynFileNames, tagValue);
									dynAppend(dynInitFiles, tagValue);
									break;
				case "postInstall": dynAppend(dynFileNames, tagValue);
								// this will be saved in a data point describing the component
									dynAppend(dynPostInstallFiles, tagValue);
									
									// save the full path to the init file
									tagValue = destinationDir + "/" + strltrim(tagValue, ".");
									
									// this will be saved in a data point with all the postInstall files to be run
									dynAppend(dynPostInstallFiles_current, tagValue);
									break;
									
				case "config_windows": 	dynAppend(dynFileNames, tagValue);
										dynAppend(dynConfigFiles_windows, tagValue);	
										break;
										
				case "config_linux" : 	dynAppend(dynFileNames, tagValue);
										dynAppend(dynConfigFiles_linux, tagValue);											
										break;
										
				case "dplist":		dynAppend(dynFileNames, tagValue);
									dynAppend(dynDplistFiles, tagValue);	
									break;
									
				case "includeComponent": 	strreplace(tagValue, "./", "");
											dynAppend(dynSubComponents, sourceDir + "/" + tagValue);
											break;
											
			} // end switch
			
		} // end while	


	// check the component dependencies
	// retrieve the component names that are required and not installed

	_fwInstallation_getNotInstalledComponentsFromRequiredComponents(dynRequiredComponents, strNotInstalledNames);
	
	// show the panel that asks if it should be installed
	
			if( strNotInstalledNames != "")
			{	
				DebugN("fwInstallation: Could not install "+ componentName +"!\n The following components are missing\n",strNotInstalledNames);
				returnValue = -1;
				return;
			}
// end check the component dependencies

//SMS check if all scripts all valid, and all directories are writeable

	errorCounter = 0;	


	if(dynlen(dynInitFiles) > 0)
	{
		for (k=1; k<=dynlen(dynInitFiles); k++)
		{
			fileLoaded = fileToString(sourceDir + dynInitFiles[k], strTestFile);
			if (! fileLoaded )
			{
				DebugN("Cannot load " + sourceDir + dynInitFiles[k] + " file for testing");
				errorCounter++;
			} else {
				error = evalScript(tempReturn, strTestFile, "", "");
				if(error!=0)
				{
					errorCounter++;
					DebugN("fwInstallation: init script "+sourceDir + dynInitFiles[k]+" of component "+componentName+" is not valid");
				}
			}
		}
	}

	if(dynlen(dynPostInstallFiles) > 0)
	{
		for (k=1; k<=dynlen(dynPostInstallFiles); k++)
		{
			fileLoaded = fileToString(sourceDir + dynPostInstallFiles[k], strTestFile);
			if (! fileLoaded )
			{
				DebugN("Cannot load " + sourceDir + dynPostInstallFiles[k] + " file for testing");
				errorCounter++;
			} else {
				error = evalScript(tempReturn, strTestFile, "", "");
				if(error!=0)
				{
					errorCounter++;
					DebugN("fwInstallation: post install script "+sourceDir + dynPostInstallFiles[k]+" of component "+componentName+" is not valid");
				}
			}
		}
	}


	if(dynlen(dynFileNames) > 0)
	{
		for (k=1; k<=dynlen(dynFileNames); k++)
		{
			error = access(_fwInstallation_baseDir(destinationDir + "/" + dynFileNames[k]),W_OK);
			if(error!=0)
			{
				errorCounter++;
				DebugN("fwInstallation: the folder "+ _fwInstallation_baseDir(destinationDir + "/" + dynFileNames[k]) +" is not write enabled");
			}
		}
	}


	if(errorCounter!=0)
	{
		DebugN("fwInstallation: error(s) found. Installation of "+componentName+" is aborted",errorCounter);
		return errorCounter;
		return;
	}

// install the 	component
		
		if(isItSubComponent)
		{
			DebugN("  Installing sub-component: " + componentName); 
		}
		else
		{
			DebugN("Installing the component: " + componentName); 
		}
// install the subcomponents if they exist

	for(i = 1; i <= dynlen(dynSubComponents); i++)
	{
		DebugN("     Installing sub Components ... ");
		_fwInstallation_installComponent(dynSubComponents[i], true, dynSubComponents[i], componentInstalled, destinationDir, dynPostInstallFiles_all, error);
	}

// end install the subcomponents if they exist
												
// copy all the files

			
			if(sourceDir == destinationDir)
			{

			}
			else
			{
				if(dynlen(dynFileNames) > 0)
				{
					DebugN("    Copying files ....");
					
					for (i=1; i <= dynlen(dynFileNames); i++)
					{
							temp_string = dynFileNames[i];
							fileToCopy = strltrim(temp_string, ".");
	
							fileCopied =  copyFile(sourceDir + fileToCopy, destinationDir + "/" + fileToCopy);
							
							
							if(!fileCopied) 
							{
								//...Error handling...; 
//SMS only print message if problems occurred
								DebugN("Error copying file - source: " + sourceDir + fileToCopy + " destination: " + destinationDir + "/" + fileToCopy);
//SMS why print success code
								errorInstallingComponent = -1;
							}
							else
							{
//SMS							DebugN(" OK", fileCopied); 
							}
					}
				}	
			}
// import the dplist files with the ASCII manager
		
		if(dynlen(dynDplistFiles) > 0)
		DebugN("    Importing dplist file: " + dplistFile + "...");
			
		
		for( i = 1; i <= dynlen(dynDplistFiles); i++)
		{	
			dplistFile = dynDplistFiles[i];

			fileToCopy = strltrim(dplistFile, ".");
					
			asciiFile = sourceDir + fileToCopy;
									
			if(asciiFile == "")
			{
					DebugN("    The " + asciiFile + 
					"file could not be found.\nCheck the path (proj_path) in your config file.\nAlso check if the file exists.");
			}
			else
			{
					cmd = asciiManager + " -in " + asciiFile + " -yes -log +stderr -log -file > "
							+ infoFile + " 2> " + logFile;								
					if (_WIN32) 
					{
							err = system("cmd /c " + cmd);
							if (err != 0)
							{
								DebugN("    Could not import properly the file " + asciiFile + " (Error number = " + err +")");
								errorInstallingComponent = -1;
							}
					}
					else  //LIN
					{
							err = system(cmd);
							if (err != 0)
							{
								DebugN("    Could not import properly the file " + asciiFile + " (Error number = " + err +")");
								errorInstallingComponent = -1;
							}
					}
									
							// Show result of the import of the current file in the log text field
							x = fileToString (logFile, result);
							resultInLines = strsplit (result, "\n");
//							DebugN(resultInLines);	
					}
		}
		
// end import the dplist files

// import config files for linux

		for(i = 1; i <= dynlen(dynConfigFiles_linux); i++)
		{
					if(! _WIN32)
					{
						DebugN("    Importing linux config file ... ");

						componentConfigFile = sourceDir + strltrim(dynConfigFiles_linux[i], ".");
						DebugN("componentConfigFile: " + componentConfigFile + "  componentName" +  componentName);
						_fwInstallation_AddComponentIntoConfig( componentConfigFile,  componentName);
					}
		}
// end import config files for linux

// import config files for windows
		
		for(i = 1; i <= dynlen(dynConfigFiles_windows); i++)
		{
					if(_WIN32)
					{
							
							DebugN("    Importing windows config file ... ");
							
							componentConfigFile = sourceDir + strltrim(dynConfigFiles_windows[i], ".");
							_fwInstallation_AddComponentIntoConfig( componentConfigFile,  componentName);
					}
		}
// end import config files for windows
		
// import config files

		if(dynlen(dynConfigFiles_general) > 0)
		DebugN("    Importing general config file ... ");
		
		for(i = 1; i <= dynlen(dynConfigFiles_general); i++)
		{			
					componentConfigFile = sourceDir + strltrim(dynConfigFiles_general[i], ".");
					_fwInstallation_AddComponentIntoConfig( componentConfigFile,  componentName);
		}
		
// end import config files	

// add scripts to the fwScripts.lst file

	if(dynlen(dynScriptsToBeAdded) > 0)
	{
		DebugN("    Updating the fwScripts.lst file ... ");
		_fwInstallation_addScriptsIntoFile(dynScriptsToBeAdded, componentName);
		
		// check if the progs file contains the fwScripts.lst file
		DebugN("checking the progs file ... if it contains fwScripts.lst");
		
		if(fwInstallation_fwScriptsAddedToProgsFile() == -1)
		{
			Debug("\n opening the fwInstallationScriptsAddedInfo.pnl");
		}
	}
	
// execute the init script
		if(dynlen(dynInitFiles) > 0)
		DebugN("    Executing the init file ... ");

		for(i =1; i <= dynlen(dynInitFiles); i++)
		{
			componentInitFile = sourceDir + strltrim(dynInitFiles[i], ".");
			// read the file and execute it
										
			_fwInstallation_evalScriptFile( componentInitFile , iReturn);
			
			if(iReturn == -1)
			{
				DebugN("    	Error: executing the init file: " + componentInitFile);
				
				errorInstallingComponent = -1;


			}
		}
// end execute the init script	

// begin store the postInstall files in a datapoint
			
			// append the name of the current component post install init files
			dynAppend(dynPostInstallFiles_all, dynPostInstallFiles_current);
			
			// store all the post install init files				
			dpSet("fwInstallationInfo.postInstallFiles:_original.._value", dynPostInstallFiles_all);			


// end store the postInstall files in a datapoint

				
			// save the component info into the PVSS database
					
			DebugN("    Saving the component info into the database: ");
						
			dpCreated = dpCreate("fwInstallation_" + componentName, "_FwInstallationComponents");
			
			if (dpCreated == 0 )
			{
				dpSet("fwInstallation_" + componentName + ".componentVersion:_original.._value", componentVersion);
				dpSet("fwInstallation_" + componentName + ".componentVersionString:_original.._value", componentVersion);
				dpSet("fwInstallation_" + componentName + ".descFile:_original.._value", descFile);

				if(date != "")		
				dpSet("fwInstallation_" + componentName + ".date:_original.._value", date);
				dpSet("fwInstallation_" + componentName + ".installationDirectory:_original.._value", destinationDir);
				
				if(dynlen(dynComponentFiles) > 0)
				dpSet("fwInstallation_" + componentName + ".componentFiles:_original.._value", dynComponentFiles);
				
				if(dynlen(dynConfigFiles_general) > 0)
				dpSet("fwInstallation_" + componentName + ".configFiles.configGeneral:_original.._value", dynConfigFiles_general);
				
				if(dynlen(dynConfigFiles_linux) > 0)
				dpSet("fwInstallation_" + componentName + ".configFiles.configLinux:_original.._value", dynConfigFiles_linux);			
				
				if(dynlen(dynConfigFiles_windows) > 0)
				dpSet("fwInstallation_" + componentName + ".configFiles.configWindows:_original.._value", dynConfigFiles_windows);						
				
				if(dynlen(dynInitFiles) > 0)
				dpSet("fwInstallation_" + componentName + ".initFiles:_original.._value", dynInitFiles);
				
				if(dynlen(dynPostInstallFiles) > 0)
				dpSet("fwInstallation_" + componentName + ".postInstallFiles:_original.._value", dynPostInstallFiles);
				
				if(dynlen(dynDplistFiles) > 0)
				dpSet("fwInstallation_" + componentName + ".dplistFiles:_original.._value", dynDplistFiles);
				
				if(dynlen(dynRequiredComponents) > 0)
				dpSet("fwInstallation_" + componentName + ".requiredComponents:_original.._value", dynRequiredComponents);
				
				dpSet("fwInstallation_" + componentName + ".requiredInstalled:_original.._value", requiredInstalled);
				
				if(dynlen(dynSubComponents) > 0)
				dpSet("fwInstallation_" + componentName + ".subComponents:_original.._value", dynSubComponents);
				
				dpSet("fwInstallation_" + componentName + ".isItSubComponent:_original.._value", isItSubComponent);
				
				if(dynlen(dynScriptsToBeAdded) > 0)
				dpSet("fwInstallation_" + componentName + ".scriptFiles:_original.._value", dynScriptsToBeAdded);
				
				

			}
			else
			{
				DebugN("    ERROR: The information cannot be saved into the database ");
				errorInstallingComponent = -1;
			}
			
			if(errorInstallingComponent == -1)
			{	
				DebugN("    Component installed with errors - check the log.");
			}				
			else
			{
		
		// the component has been installed - check whether it has corrected the broken dependencies
		
				_fwInstallation_getListOfNotProperlyInstalledComponents(dynNotProperlyInstalled);
				
				for(i = 1; i <= dynlen(dynNotProperlyInstalled); i++)
				{
					dynClear(dynRequiredComponents);
					
					dpGet("fwInstallation_" + dynNotProperlyInstalled[i] + ".requiredComponents:_original.._value", dynRequiredComponents);

					_fwInstallation_getNotInstalledComponentsFromRequiredComponents(dynRequiredComponents, strNotInstalledNames);
					
					if(strNotInstalledNames == "")
					{
						dpSet("fwInstallation_" + dynNotProperlyInstalled[i] + ".requiredInstalled:_original.._value", true);
					}	
				}
				DebugN("    Component installed.");
				componentInstalled = true;
			}
		}	
	
}

/** This function retrieves the list of components which were not properly installed - there was error in dependencies
and the user still wanted to install the component.

@param dynNotProperlyInstalled: the list of components which were installed with broken dependencies - .requiredInstalled:_original.._value is false
@author M.Sliwinski
*/

_fwInstallation_getListOfNotProperlyInstalledComponents(dyn_string & dynNotProperlyInstalled)
{
		dyn_string dynInstalledComponents;
		int i;
		bool requiredInstalled;
		
		// retrieve all installed components
		
		dynInstalledComponents =  dpNames("*", "_FwInstallationComponents");

		
		
		for(i = 1; i <= dynlen(dynInstalledComponents); i++)
		{	
			// cut the system name from the installed components
			dynInstalledComponents[i] = dpSubStr( dynInstalledComponents[i], DPSUB_DP );
			
			// delete the fwInstallation_ prefix
			strreplace(dynInstalledComponents[i], "fwInstallation_", "");
			
			dpGet("fwInstallation_" + dynInstalledComponents[i] + ".requiredInstalled:_original.._value", requiredInstalled);
			if(!requiredInstalled)
			{
				dynAppend(dynNotProperlyInstalled, dynInstalledComponents[i]);
			}

		}		
}

/** This function checks if all the required components are installed. It returns a string of components that are not
installed and required.

@param dynRequiredComponents: the name of a componentConfigFile
@param strNotInstalledNames: the name of a component
@author M.Sliwinski
*/

_fwInstallation_getNotInstalledComponentsFromRequiredComponents(dyn_string & dynRequiredComponents, string & strNotInstalledNames)
{
	int i;
	dyn_string dynInstalledComponents;
	dyn_string dynTmpNameVersion;
	string strRequiredName;
	string stringInstalledVersion;
	string stringRequiredVersion;

	float componentVersion;
		
	if (dynlen(dynRequiredComponents) > 0)
	{
	
	
		// retrieve all installed components
		
		dynInstalledComponents =  dpNames("*", "_FwInstallationComponents");

		
		for(i = 1; i <= dynlen(dynInstalledComponents); i++)
		{	
		
			// cut the system name from the installed components

			dynInstalledComponents[i] = dpSubStr( dynInstalledComponents[i], DPSUB_DP );
			
			// cut the fwInstallation_ prefix 
			
			strreplace(dynInstalledComponents[i], "fwInstallation_" , "");		
		}
				
		for( i = 1; i <= dynlen(dynRequiredComponents); i++)
		{
		
			// retrieve the name and version of the component
				
			dynTmpNameVersion = strsplit(dynRequiredComponents[i] , "=");
			
			strRequiredName = strltrim(strrtrim(dynTmpNameVersion[1]));
			
			if(dynlen(dynTmpNameVersion) > 1)
			{
				stringRequiredVersion = strltrim(strrtrim(dynTmpNameVersion[2]));
			}
			else
			{	
				stringRequiredVersion = "";
			}
			
			
			// check whether the required component is installed
			
			if(dynContains(dynInstalledComponents, strRequiredName))
			{
				// the required component is installed
				
				// checking the version of the installed component
				
				dpGet("fwInstallation_" + strRequiredName + ".componentVersionString:_original.._value", stringInstalledVersion);
/*				if(stringInstalledVersion == "")
				{
					dpGet("fwInstallation_" + strRequiredName + ".componentVersion:_original.._value", componentVersion);
					if(componentVersion == floor(componentVersion))
					{
						sprintf(stringInstalledVersion,"%2.1f",componentVersion);
					} else {
						stringInstalledVersion = componentVersion;
					}
					dpSetWait("fwInstallation_" + strRequiredName + ".componentVersionString:_original.._value", componentVersionString);
				}
*/				 
				 if(_fwInstallation_CompareVersions(stringInstalledVersion, stringRequiredVersion))
				 {
				 
				 	// the installed version of the component is greater than the required version - OK
				 }
				 else
				 {
				 	// the installed version is older than the required version
					
					strNotInstalledNames += strRequiredName + "=" + stringRequiredVersion + "|";

				 }
					
			}
			else
			{

				// the required component is not installed
				strNotInstalledNames += strRequiredName + "=" + stringRequiredVersion + "|";
				
			}
		}
	}
}

/** This function reads the information from the componentConfigFile and copies it into the project config file.

@param componentConfigFile: the name of a componentConfigFile
@param componentName: the name of a component
@author S.Schmeling
*/

_fwInstallation_AddComponentIntoConfig(string componentConfigFile, string componentName)
{
	dyn_string configLines; // this table contains the config file - each row contains one line from config file
	string configPath = getPath(CONFIG_REL_PATH);
	string configFile = configPath + "config";

	bool fileLoaded = false;
	dyn_string componentConfigLines;
	string componentConfigSection;
	dyn_string componentConfigSectionLines;
	string fileInString, tempLine;
	int i;
	
	componentConfigSection = "";
	dynClear(componentConfigSectionLines);

	if(_fwInstallation_getConfigFile(configLines) == 0)
	{

// load componentConfigFile
		fileLoaded = fileToString(componentConfigFile, fileInString);
		if (! fileLoaded )
		{
			DebugN("fwInstallationLib: Cannot load component config file " + componentConfigFile);
			return -1;
		} else {
			componentConfigLines = strsplit(fileInString, "\n");
		}
	
// first delete the component's configuration from the config file
		_fwInstallation_DeleteComponentFromConfig(componentName);

// add the component config lines into the appropriate sections	
		for(i=1; i<=dynlen(componentConfigLines); i++)
		{
			tempLine = strltrim(strrtrim(componentConfigLines[i]));
			if(strpos(tempLine, "[") == 0)
			{
				if(componentConfigSection == "")
				{
					componentConfigSection = strltrim(strrtrim(tempLine,"]"),"[");
					dynClear(componentConfigSectionLines);
					componentConfigSectionLines = makeDynString("#begin "+componentName,
																"#This should not be edited manually between begin and end");
				} else {
					dynAppend(componentConfigSectionLines,"#end "+componentName);
					j = fwInstallation_addToSection(componentConfigSection, componentConfigSectionLines);
					componentConfigSection = strltrim(strrtrim(tempLine,"]"),"[");
					dynClear(componentConfigSectionLines);
				}					
			} else {
				dynAppend(componentConfigSectionLines, tempLine);
			}
		}
// save the config file
		_fwInstallation_saveFile(configLines, configPath + "config");
	} else {
		return -1;
	}
}

/** This function deletes the information for the component from the project config file.

@param componentName: the name of a component
@author S.Schmeling
*/

_fwInstallation_DeleteComponentFromConfig(string componentName)
{
	dyn_string configLines; // this table contains the config file - each row contains one line from config file
	string configPath = getPath(CONFIG_REL_PATH);
	string configFile = configPath + "config";
	int i;
	bool insideComponentConfiguration = FALSE;

	if(_fwInstallation_getConfigFile(configLines) == 0)
	{
		for(i=1; i<=dynlen(configLines); i++)
		{		
			if(strltrim(strrtrim(configLines[i])) == "#begin " + componentName)
			{
				insideComponentConfiguration = TRUE;
			}
			if(strltrim(strrtrim(configLines[i])) == "#end " + componentName)
			{
				insideComponentConfiguration = FALSE;
				dynRemove(configLines, i);
				i--;
			}
			if(insideComponentConfiguration)
			{
				dynRemove(configLines, i);
				i--;
			}
		}
// save the config file
		_fwInstallation_saveFile(configLines, configPath + "config");
	} else {
		return -1;
	}
}

int _fwInstallation_CompareVersions(string installedComponentVersion, string requestedComponentVersion)
{
	dyn_uint installedComponentVersionLong,requestedComponentVersionLong;
	dyn_string installedComponentVersionStrings, requestedComponentVersionStrings;
	int result=1;
	int count,minCount,sameCount;

	requestedComponentVersionLong = strsplit(requestedComponentVersion,".");
	installedComponentVersionLong = strsplit(installedComponentVersion,".");

	if(dynlen(requestedComponentVersionLong) <= dynlen(installedComponentVersionLong))
	{
		minCount = dynlen(requestedComponentVersionLong);
		for(count=1;count<=minCount;count++)
		{
			if(installedComponentVersionLong[count] < requestedComponentVersionLong[count])
			{
				result = 0;
				break;
			}
			if(installedComponentVersionLong[count] > requestedComponentVersionLong[count])
			{
				break;
			}
		}
	} else {
		minCount = dynlen(installedComponentVersionLong);
		sameCount = 0;
		for(count=1;count<=minCount;count++)
		{
			if(installedComponentVersionLong[count] < requestedComponentVersionLong[count])
			{
				result = 0;
				break;
			}	
			if(installedComponentVersionLong[count] > requestedComponentVersionLong[count])
			{
				break;
			}
			if(installedComponentVersionLong[count] == requestedComponentVersionLong[count])
			{
				sameCount++;
			}
		}
		if((result == 1) && (sameCount == minCount))
		{
			result = 0;
		}
	}

	return result;

}		

/** This function creates the Installation Component DPT and DP

@param result: this is the return value  0 - "success"   -1 - "error"

@author M.Sliwinski, adapted by S. Schmeling
*/

_fwInstallation_createDataPointTypes(bool create, int & result)
{
	int n;
	dyn_dyn_string dynDynElements;
	dyn_dyn_int dynDynTypes;
	
	result = 0;
	
	dynDynElements[1] = makeDynString ("_FwInstallationComponents", "", "");
	dynDynElements[2] = makeDynString ("", "componentFiles", "");
	dynDynElements[3] = makeDynString ("", "configFiles", "");

	dynDynElements[4] = makeDynString ("", "", "configWindows");
	dynDynElements[5] = makeDynString ("", "", "configLinux");
	dynDynElements[6] = makeDynString ("", "", "configGeneral");

	dynDynElements[7] = makeDynString ("", "initFiles", "");
	dynDynElements[8] = makeDynString ("", "postInstallFiles", "");
	
	dynDynElements[9] = makeDynString ("", "dplistFiles", "");
	dynDynElements[10] = makeDynString ("", "componentVersion", "");
	dynDynElements[11] = makeDynString ("", "date", "");
	dynDynElements[12] = makeDynString ("", "descFile", "");
	dynDynElements[13] = makeDynString ("", "installationDirectory", "");
	dynDynElements[14] = makeDynString ("", "requiredComponents", "");
	dynDynElements[15] = makeDynString ("", "requiredInstalled", "");
	dynDynElements[16] = makeDynString ("", "subComponents", "");
	dynDynElements[17] = makeDynString ("", "isItSubComponent", "");
	dynDynElements[18] = makeDynString ("", "scriptFiles", "");
	dynDynElements[19] = makeDynString ("", "componentVersionString", "");
	
	dynDynTypes[1] = makeDynInt (DPEL_STRUCT);
	dynDynTypes[2] = makeDynInt (0, DPEL_DYN_STRING);
	dynDynTypes[3] = makeDynInt (0, DPEL_STRUCT);
	
	dynDynTypes[4] = makeDynInt (0, 0, DPEL_DYN_STRING);
	dynDynTypes[5] = makeDynInt (0, 0, DPEL_DYN_STRING);
	dynDynTypes[6] = makeDynInt (0, 0, DPEL_DYN_STRING);
	
	dynDynTypes[7] = makeDynInt (0, DPEL_DYN_STRING);
	dynDynTypes[8] = makeDynInt (0, DPEL_DYN_STRING);
	dynDynTypes[9] = makeDynInt (0, DPEL_DYN_STRING);
	dynDynTypes[10] = makeDynInt (0, DPEL_FLOAT);
	dynDynTypes[11] = makeDynInt (0, DPEL_STRING);
	dynDynTypes[12] = makeDynInt (0, DPEL_STRING);
	dynDynTypes[13] = makeDynInt (0, DPEL_STRING);
	dynDynTypes[14] = makeDynInt (0, DPEL_DYN_STRING);
	dynDynTypes[15] = makeDynInt (0, DPEL_BOOL);
	dynDynTypes[16] = makeDynInt (0, DPEL_DYN_STRING);
	dynDynTypes[17] = makeDynInt (0, DPEL_BOOL);
	dynDynTypes[18] = makeDynInt (0, DPEL_DYN_STRING);
	dynDynTypes[19] = makeDynInt (0, DPEL_STRING);
	
	// Create or change the datapoint type

	if(create)
	{
		n = dpTypeCreate(dynDynElements, dynDynTypes );
	} else {
		n = dpTypeChange(dynDynElements, dynDynTypes );
	}	
	// check the result of creating dpts
	if(n == -1)
	{
		result = -1;
	}

	
	dynClear(dynDynElements);
	dynClear(dynDynTypes);
	
	dynDynElements[1] = makeDynString ("_FwInstallationInformation" , "");
	dynDynElements[2] = makeDynString ("","installationDirectoryPath");
	dynDynElements[3] = makeDynString ("","postInstallFiles");

	dynDynTypes[1] = makeDynInt (DPEL_STRUCT);
	dynDynTypes[2] = makeDynInt (0, DPEL_STRING);
	dynDynTypes[3] = makeDynInt (0, DPEL_DYN_STRING);

	// create or change the datapoint type	
	if(create)
	{
		n = dpTypeCreate(dynDynElements, dynDynTypes );
	} else {
		n = dpTypeChange(dynDynElements, dynDynTypes );
	}		
	
	// check the result of creating dpts
	if(n == -1)
	{
		result = -1;
	}
}


string _fwInstallation_baseDir(string filePath)
{
	string temp_string = filePath;
	dyn_string tempPath = strsplit(temp_string, "/");
	string returnString = "";	
	int i;

	if(dynlen(tempPath) > 1)
	{
		for (i=1; i<dynlen(tempPath); i++)
		{
			temp_string = tempPath[i];
			returnString += temp_string +"/";
		}
	}
	return returnString;
}

/** This function executes a script from the component .init file

@param componentInitFile: the .init file with the functions to be executed
@param iReturn: sucess 0, in  the event of an error -1
@author M.Sliwinski
*/

_fwInstallation_evalScriptFile(string componentInitFile , int & iReturn)
{
	
	bool fileLoaded;
	string fileInString;
	anytype retVal;
	int result;
	
	fileLoaded = fileToString(componentInitFile, fileInString);
	
	if (! fileLoaded )
	{
	
		DebugN("fwInstallation: Cannot load " + componentInitFile);
		iReturn =  -1;
	}
	else 
	{
		
		// the evalScript 
		iReturn = evalScript(retVal, fileInString, makeDynString("$value:12345"));
		
	}
	

	
}


/** This function updates the fwScripts.lst file to be run by ctrl manager

@param dynScriptsToBeAdded: a dynamic string with file names of scripts to be added to fwScripts.lst file
@param strComponentName: the name of the component for which the scripts are added
@author M.Sliwinski
*/

_fwInstallation_addScriptsIntoFile(dyn_string & dynScriptsToBeAdded, string strComponentName)
{

		dyn_string dynLoadedScripts;   // all the scripts that were loaded from fwScripts.lst
		dyn_string dynScriptsFileLines;
		string strScriptsFileName = getPath(SCRIPTS_REL_PATH) + "fwScripts.lst";
		string scriptsFileInString;
		string strScriptsFileLine;
		dyn_string dynLinesToBeAdded;
		dyn_string dynTmpDirFile;
		int idxOfScriptName;
		int i;
		bool fileLoaded;
		int canAccessFile;
				
		canAccessFile = access(strScriptsFileName, F_OK);
		
		if(canAccessFile == 0)
		{
			
			fileLoaded = fileToString(strScriptsFileName, scriptsFileInString);

			if (! fileLoaded )
			{
			
				DebugN("fwInstallation: Error loading the file: " + strScriptsFileName);
				
			}
			else 
			{
				
				dynScriptsFileLines = strsplit(scriptsFileInString, "\n");
				
				for( i = 1; i <= dynlen(dynScriptsFileLines); i++)
				{
					strScriptsFileLine = strrtrim(strltrim(dynScriptsFileLines[i]));
					
					if(strScriptsFileLine == "")
					{
						// this is a blank line
					}
					else if( strtok(strScriptsFileLine, "#") == 0)
					{
						// this is a comment
					}
					else
					{
						// this is a script entry
						dynAppend(dynLoadedScripts, strScriptsFileLine);
					}

				}
				

			}
		}
		else
		{
			DebugN("fwInstallation: The file : " + strScriptsFileName + " does not exist");
		}
		
		// what should be added
		dynAppend(dynLinesToBeAdded, "#begin " + strComponentName);
		dynAppend(dynLinesToBeAdded, "# if this parametrisation is empty that means that the scripts were already defined in the file");
		dynAppend(dynLinesToBeAdded, "");
		
		for ( i = 1; i <= dynlen(dynScriptsToBeAdded); i++)
		{
			if(dynContains(dynLoadedScripts, dynScriptsToBeAdded[i]) > 0)
			{
				// the parametrisation is already done	
				DebugN("fwInstallation: The parametrisation is already done for: " + dynScriptsToBeAdded[i]);	
			}
			else 
			{
				// update the loaded scripts - the scripts that were loaded from the old file
				dynAppend(dynLoadedScripts, dynScriptsToBeAdded[i]);
				
				// add the script file names to - the lines to be added
				
				// get the script name from the relative path
				
				dynTmpDirFile = strsplit(dynScriptsToBeAdded[i], "/");
				
				// get the index of the script file name
				idxOfScriptName = dynlen(dynTmpDirFile);
				
				// append the script file name to the lines to be added
				dynAppend(dynLinesToBeAdded, dynTmpDirFile[idxOfScriptName]);
				DebugN("fwInstallation: Adding the parametrisation for: " + dynScriptsToBeAdded[i]);	
			}
		}
		
		dynAppend(dynLinesToBeAdded, "");
		dynAppend(dynLinesToBeAdded, "#end " + strComponentName);

		// add an empty line at the end of component definition - for readability
		dynAppend(dynLinesToBeAdded, "");		 
		
		// if the fwScripts.lst is empty the PVSS00ctl manager does not start
		// the fwInstallationFakeScript.ctl is added to correct this problem
		
		if(dynContains(dynLoadedScripts, "fwInstallationFakeScript.ctl"))
		{
		
		}
		else
		{
			dynAppend(dynLinesToBeAdded, "fwInstallationFakeScript.ctl");
		}
		
		// append the new lines to the dyn_string that contains lines from old file
		
		dynAppend(dynScriptsFileLines, dynLinesToBeAdded);
		
		_fwInstallation_saveFile( dynScriptsFileLines, strScriptsFileName);

}
