Archive: How to compare two files in NSIS?


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?.


What is the format of your property files? Can you use ConfigRead/ConfigWrite?

Stu


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.


Please upload an example property file to pastebin.com .


#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.


Use ConfigRead/ConfigWrite. It's in the NSIS manual.

Stu


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 ?


ConfigRead may not trim new-line characters. Use TrimNewLines on the value before writing it.

Stu


yes.I have tried same function.but i have used after written.Now its working.Thanks.