Go Back   Winamp Forums > Developer Center > NSIS Discussion

Reply
Thread Tools Search this Thread Display Modes
Old 17th April 2003, 00:39   #1
merahul94538
Junior Member
 
Join Date: Mar 2003
Posts: 6
Question XML editing,code from archives but not working

Code is from Archive.What I need to do it to call this script from my main installer file to make changes in my 2 XML files.
This is code in my main installer file but it's not working,i am doing something wrong but can't figure out
In WriteXML I get script,StringA,StringB value coorect but file.name and filnenew.xml comes as null.Please help.
Code attached.
What I need is that I should be able to send sourcefile name,destination file name,string to be replaced,new string from my main installer file to Writexml and get the final output in destination file name. Thank in advance

push "StringA"
push "StringB"
push "file.xml"
push "filenew.xml"


; Some code to adjust settings in XML file.
;
; By Hendri Adriaens.
; HendriAdriaens@hotmail.com
!define TEMP1 $R0 ;Temp variable
!define TEMP2 $R1 ;Temp variable
!define TEMP3 $R2 ;Temp variable
!define TEMP4 $R3 ;Temp variable
;outfile WriteXML.exe
;name WriteXML
; push sourcefile
; push destfile
; push search string
; push new string

function ParseXML
;MessageBox MB_YESNO "This will modify studio.txt and put output to temp.tmp.$\r$\nContinue?" IdNo Quiting

Exch $0 ;newString
MessageBox MB_OK $0
Exch
Exch $1 ;search string
MessageBox MB_OK $1
Exch
Exch $2 ;source file
MessageBox MB_OK $2
Exch
Exch $3 ;destfile
MessageBox MB_OK $3


FileOpen $R0 "$3" "r"
FileOpen $R1 "$4" "w"
MessageBox MB_OK $R0
MessageBox MB_OK $R1


Loop:
FileRead $R0 $R2
StrCmp $R2 "" ExitLoop
push $R2
push $1
Call StrStrH
Pop $R3
StrCmp $R3 $R2 NotFound
FileWrite $R1 '$R3"$1" value="$2" />$\r$\n'
GoTo Loop
NotFound:
FileWrite $R1 $R2
Goto Loop
ExitLoop:
FileClose $R0
FileClose $R1
Quiting:
Quit
functionend

Function StrStrH
;Modified StrStr function from functions.htm
Exch $1
Exch
Exch $2
Push $3
Push $4
Push $5
StrLen $3 $1
StrCpy $4 0
loop:
StrCpy $5 $2 $3 $4
StrCmp $5 $1 done
StrCmp $5 "" done
IntOp $4 $4 + 1
Goto loop
done:
StrCpy $1 $2 $4
Pop $5
Pop $4
Pop $3
Pop $2
Exch $1
FunctionEnd

section
sectionend
merahul94538 is offline   Reply With Quote
Old 17th April 2003, 05:05   #2
iceman_k
NSIS Dev
 
iceman_k's Avatar
 
Join Date: Feb 2003
Location: Boston, MA, U.S.A.
Posts: 455
In the first place, you seem to be pushing your arguments in the wrong order.
The documentation for the script says:

code:

; push sourcefile
; push destfile
; push search string
; push new string



So you should push in that order.

Secondly, the ParseXML function seems to be extracting the arguments incorrectly.
It should be doing:

code:

Exch $0 ;newString
MessageBox MB_OK $0
Exch
Exch $1 ;search string
MessageBox MB_OK $1
Exch
Exch 2
Exch $2 ;dest file
Exch
Exch 2
Exch 3
Exch $3 ;source file



Please correct me if I am wrong.

Cheers,
Iceman_K

EclipseNSIS - An NSIS IDE for the Eclipse Platform | My contributions to the wiki
iceman_k is offline   Reply With Quote
Old 17th April 2003, 05:54   #3
merahul94538
Junior Member
 
Join Date: Mar 2003
Posts: 6
Exclamation XML editing..............................

I put that documentation in and I think stack is LAST IN FIRST OUT, correct me if I am wrong. That's what I assume and I get the valye for STRINGA and STRINGB correct in the function but just not the 2 files. It could be the extraction problem,I will look into it more.Anybody else ?
Thanks for your reply
merahul94538 is offline   Reply With Quote
Old 17th April 2003, 09:18   #4
virtlink
Major Dude
 
virtlink's Avatar
 
Join Date: Sep 2002
Location: At [4C69:6E6B]
Posts: 561
I think that you should use Pop to get the value on the stack instead of Exch. Exch exchanges the top value on the stack with the value in the variable. Pop moves the value on the stack to the variable, so that the next value on the stack becomes the top value:

PHP Code:
push "StringA"
push "StringB"
push "file.xml"
push "filenew.xml" 
The stack contains:
code:
filenew.xml
file.xml
StringB
StringA



Then, using Pop:
PHP Code:
Pop $0
MessageBox MB_OK 
$
The stack contains:
code:
file.xml
StringB
StringA


And the message box should show: filenew.xml

Then pop again, and so on.

I'm not sure about the order in which the items come on the stack and leave stack. But I think that Push puts the item on top of the stack, and Pop takes the top item of the stack.

"I'll quote you when you say something memorable."
- Claudia Pelsmaeker
virtlink is offline   Reply With Quote
Old 17th April 2003, 11:26   #5
iceman_k
NSIS Dev
 
iceman_k's Avatar
 
Join Date: Feb 2003
Location: Boston, MA, U.S.A.
Posts: 455
If Pop is used to get the values from the stack, you lose the current values in the registers- which could have bad consequences later.
Another problem I noticed with ParseXML is that it is not restoring the register values when it completes.

Cheers,
Iceman_K

EclipseNSIS - An NSIS IDE for the Eclipse Platform | My contributions to the wiki
iceman_k is offline   Reply With Quote
Old 17th April 2003, 11:48   #6
kichik
M.I.A.
[NSIS Dev, Mod]
 
kichik's Avatar
 
Join Date: Oct 2001
Location: Israel
Posts: 11,336
The stack operations in this function are wrong. Where did you take it from? I can't find it in the archive...

Please attach large scripts next time.

NSIS FAQ | NSIS Home Page | Donate $
"I hear and I forget. I see and I remember. I do and I understand." -- Confucius
kichik is offline   Reply With Quote
Reply
Go Back   Winamp Forums > Developer Center > NSIS Discussion

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