Old 28th March 2013, 04:42   #1
ilaiyaraja
Member
 
Join Date: Sep 2012
Posts: 81
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?.
ilaiyaraja is offline   Reply With Quote
Old 28th March 2013, 11:58   #2
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
What is the format of your property files? Can you use ConfigRead/ConfigWrite?

Stu
Afrow UK is offline   Reply With Quote
Old 28th March 2013, 12:32   #3
ilaiyaraja
Member
 
Join Date: Sep 2012
Posts: 81
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.
ilaiyaraja is offline   Reply With Quote
Old 28th March 2013, 13:58   #4
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
Please upload an example property file to pastebin.com .
MSG is offline   Reply With Quote
Old 1st April 2013, 11:07   #5
ilaiyaraja
Member
 
Join Date: Sep 2012
Posts: 81
#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.
ilaiyaraja is offline   Reply With Quote
Old 1st April 2013, 13:31   #6
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Use ConfigRead/ConfigWrite. It's in the NSIS manual.

Stu
Afrow UK is offline   Reply With Quote
Old 1st April 2013, 14:01   #7
ilaiyaraja
Member
 
Join Date: Sep 2012
Posts: 81
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 ?
ilaiyaraja is offline   Reply With Quote
Old 1st April 2013, 18:46   #8
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
ConfigRead may not trim new-line characters. Use TrimNewLines on the value before writing it.

Stu
Afrow UK is offline   Reply With Quote
Old 2nd April 2013, 07:20   #9
ilaiyaraja
Member
 
Join Date: Sep 2012
Posts: 81
yes.I have tried same function.but i have used after written.Now its working.Thanks.
ilaiyaraja is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Tags
java, nsis

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump