'********************************************************************
'* 
'* Function updateAgentLogging
'*
'********************************************************************
Public Function updateAgentLogging(ByVal DataPath, byVal ProgramPath)

'	WScript.Echo "****************************"
'	WScript.Echo "updateAgentLogging"

	Set FileToUpdate = objFSO.GetFile(ProgramPath + "\Agent\FastSimAgentLogger.properties")
	' remove the readonly attribute if necessary
	If (FileToUpdate.attributes AND 1) Then
		FileToUpdate.attributes = FileToUpdate.attributes - 1
	End If

	If objFSO.FileExists(FileToUpdate) Then
		Set objFile = objFSO.OpenTextFile(FileToUpdate, 1)
		Set objFileNew = objFSO.CreateTextFile(ProgramPath + "\Agent\FastSimAgentLogger.properties.New", 1)
	
		Do While Not objFile.AtEndOfStream 
			strline = objFile.ReadLine
			If ( InStr(strline, "java.util.logging.FileHandler.pattern") > 0) Then
				outline = "java.util.logging.FileHandler.pattern = " + DataPath + "/FSAgent%g.log"
				' for java we need to replace backslashes with forward slashes
				objFileNew.WriteLine(Replace(outline,"\","/"))
'				WScript.Echo "  found java.util.logging.FileHandler.pattern = FSAgent%g.log"
'				WScript.Echo "  replacing with : " & outline				
			Else
				objFileNew.WriteLine(strline)
			End If
		Loop	
	
		objFile.Close()
		objFileNew.Close()
		
		' copy over to original file
		Set tmpFile = objFSO.GetFile(ProgramPath + "\Agent\FastSimAgentLogger.properties.New")
		tmpFile.Copy(ProgramPath + "\Agent\FastSimAgentLogger.properties")
		tmpFile.Delete
	
	End If
	
End Function 'updateAgentLogging

'********************************************************************
'* 
'* Function SlashOff
'*
'* Remove the trailing slash
'*
'********************************************************************
Public Function SlashOff(byVal aPath)

	If Mid(aPath, Len(aPath), 1) = "\" Then
		SlashOff = Mid(aPath, 1, Len(aPath) - 1)
	Else
		SlashOff = aPath
	End If
  
End Function

'********************************************************************
'********************************************************************
'********************************************************************
'	WScript.Echo "Starting File Updater"

	paths=Session.Property("CustomActionData")
    tokens=Split(paths,"|")

	DataPath = SlashOff(tokens(0))
	ProgramPath = SlashOff(tokens(1))
	
	Set objFSO = CreateObject("Scripting.FileSystemObject")
		
	updateAgentLogging DataPath, ProgramPath 
		
