ilaiyaraja
28th March 2013 05:42 UTC
How to compare two files in NSIS?
I have created exe file using nsis.Installer working both ways silent and non-silent mode.If the user run second time i will take backup old property values and compare new property values.If mismatches i will write old property value into new property.
In the following code compare two and copy into temp file mismatched values.
Function compare
StrCpy $R0 "$INSTDIR\old.properties"
StrCpy $R1 "$INSTDIR\new.properties"
GetTempFileName $R2
FileOpen $R3 $R2 w
${TextCompare} "$R0" "$R1" "FastDiff" "Example2"
IfErrors 0 +2
MessageBox MB_OK "Error" IDOK +2
Exec "notepad.exe $R2"
FunctionEnd
Function Example2
FileWrite $R3 '$9'
Push $0
FunctionEnd
Problem:
In the temp File[$R3] have mismatched values.I want to replace mismatched values into new property.
How to achieve this?.
Afrow UK
28th March 2013 12:58 UTC
What is the format of your property files? Can you use ConfigRead/ConfigWrite?
Stu
ilaiyaraja
28th March 2013 13:32 UTC
I dont understand what is the format of your property file?.In my code i have put .properties.
Also how to use config read in this file comparison?
Problem:
compare two property files named old and new.if any string value mismatches that value should be replaced in new property.
MSG
28th March 2013 14:58 UTC
Please upload an example property file to pastebin.com .
ilaiyaraja
1st April 2013 11:07 UTC
#DEFAULT - PATH
DIRECTORY=C:/programfile/myproject
INDEXFILE=C:/programfile/myproject/index.xml
Temp INDEXFILE=C:/programfile/myprojec/temp.xml
DAYS=3
.........
........
In the above are sample values in property file.Also i have put in pastebin.com.
Afrow UK
1st April 2013 13:31 UTC
Use ConfigRead/ConfigWrite. It's in the NSIS manual.
Stu
ilaiyaraja
1st April 2013 14:01 UTC
thanks.I have used configwrite for writing mismatched values.but it will raised another problem.
If i use ${ConfigWrite} it will enter
${ConfigWrite} "$INSTDIR\conf.properties" "$R0" " $R1" $R3
$R0 -variable
$R1-value
After writing property file it will add new line every written.e.g
#DEFAULT - PATH
DIRECTORY=C:/programfile/myproject
INDEXFILE=C:/programfile/myproject/index.xml
Temp INDEXFILE=C:/programfile/myprojec/temp.xml
DAYS=3
I dont know why this new line added for every writing.How erase this new line ?
Afrow UK
1st April 2013 18:46 UTC
ConfigRead may not trim new-line characters. Use TrimNewLines on the value before writing it.
Stu
ilaiyaraja
2nd April 2013 07:20 UTC
yes.I have tried same function.but i have used after written.Now its working.Thanks.