Hi,
I'd like to update a properties file with the [SourceDir] sometime after install. What's the best way to do this?
You can achieve this by using a VBS script that search and replace text in your file. Here how to do this:
Add the file where you want to searches and replaces text in "Files and Folders" page. Switch to "Custom Actions" page and add "New Attached Custom Action" under the "InstallFinalize" standard action (if the "InstallFinalize" standard action is not visible make it visible by right clicking on "InstallExecuteSequence" and choosing "Show Standard Action->BeforeFinalize->InstallFinalize").
Use following options for the custom action:
1. Function Name: main.
2. Execute Properties: Synchronous execution, check return code.
3. Execution Options: Immediate execution.
4. Scheduling Options: Always Execute.
5. Execution Condition: Not Installed.
Here is the VBS script:
Code: Select all
Function main()
appPath = Session.property("APPDIR")
filePath = Session.property("APPDIR") + "yourfile.txt"
'replace "[SourceDir]" with appPath
ReplaceInFile( filePath), "[SourceDir]", appPath
End function
Function ReplaceInFile(strFileToUse, strOldText, strNewText)
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFileToUse, ForReading)
strText = ""
strFile = ""
strText = objFile.ReadAll
objFile.Close
strFile = Replace(strText, strOldText, strNewText)
Set objFile = objFSO.OpenTextFile(strFileToUse, ForWriting)
objFile.WriteLine strFile
objFile.Close
End Function
Note that [APPDIR] property gives you the path where the application is installed and the [SourceDir] property gives you the path from where the application is installing. This script searches in the file given by the filePath variable for the "[SourceDir]" text and replaces it with the text given by the appPath variable. Change the VBS script to fit your needs.
In your file change log4j.appender.A2.File=[SourceDir]\logfile.log text with log4j.appender.A2.File=[SourceDir]logfile.log because the [APPDDIR] or [SourceDir] properties already finish with a '\'.
Regards,
Gigi
________________
Gheorghe Rada
Advanced Installer Team
http://www.advancedinstaller.com