Potz
18th August 2006 19:29 UTC
changing text
I was wondering how I would change some text. Not really changing to much but more like adding to it. Here is an example of what I need to do.
The user would enter a word
Company
and the code would change it to
/C/o/m/p/a/n/y
I would know how to do this with something like java but I am still not to familiar with NSIS to be able to do this. I would appreciate any help... and some examples :) thanks
Comm@nder21
18th August 2006 19:54 UTC
you need to loop through the string:
StrCpy$0 "Company" # set your custom string
>StrCpy $1 "/" # set the character to insert
>StrLen $2 $0 # get the length of your string to loop through it
>StrCpy $3 "0" # init the loop counter
>StrCpy $4 "" # init output var
>loop: # begin of the loop
>StrCpy $5 $0 1 $3 # copy one character of your string to a temp var (offset $3 counts up)
>StrCpy $4 "$4$1$5" # add the character extracted and the one to insert everytime
>IntOp $3 $3 + 1 # increase counter/offset
>IntCmp $2 $3 end loop #stop the loop if end of string reached, else continue
>end:
># at this stage, $4 will be "/C/o/m/p/a/n/y"
Potz
18th August 2006 20:31 UTC
Awesome thanks a lot :) I do have one question though
I am having a problem running it twice in the same function. here is my code of what I am trying to do...
Function leaveRegEdit
ReadINIStr $6 "$PLUGINSDIR\Regedit.ini" "Field 1" "State"
ReadINIStr $7 "$PLUGINSDIR\Regedit.ini" "Field 2" "State"
StrCpy $0 "$6" # set your custom string
StrCpy $1 "/" # set the character to insert
StrLen $2 $0 # get the length of your string to loop through it
StrCpy $3 "0" # init the loop counter
StrCpy $4 "" # init output var
loop: # begin of the loop
StrCpy $5 $0 1 $3 # copy one character of your string to a temp var (offset $3 counts up)
StrCpy $4 "$4$1$5" # add the character extracted and the one to insert everytime
IntOp $3 $3 + 1 # increase counter/offset
IntCmp $2 $3 end loop #stop the loop if end of string reached, else continue
end:
# at this stage, $4 will be "/C/o/m/p/a/n/y"
Push "/I/I/M/S" #text to be replaced
Push $4 #replace with
Push all #replace all occurrences
Push all #replace all occurrences
Push "$INSTDIR\WARN\Dashboard\dashboard.properties" #file to replace in
Call AdvReplaceInFile
StrCpy $0 "$7" # set your custom string
StrCpy $1 "/" # set the character to insert
StrLen $2 $0 # get the length of your string to loop through it
StrCpy $3 "0" # init the loop counter
StrCpy $4 "" # init output var
loop: # begin of the loop
StrCpy $5 $0 1 $3 # copy one character of your string to a temp var (offset $3 counts up)
StrCpy $4 "$4$1$5" # add the character extracted and the one to insert everytime
IntOp $3 $3 + 1 # increase counter/offset
IntCmp $2 $3 end loop #stop the loop if end of string reached, else continue
end:
# at this stage, $4 will be "/C/o/m/p/a/n/y"
Push "/C/A/S/P/O/D" #text to be replaced
Push $4 #replace with
Push all #replace all occurrences
Push all #replace all occurrences
Push "$INSTDIR\WARN\Dashboard\dashboard.properties" #file to replace in
Call AdvReplaceInFile
FunctionEnd
Jnuw
18th August 2006 23:13 UTC
Change your second "loop:" to "loop2:" and your second "IntCmp $2 $3 end loop" to "IntCmp $2 $3 end loop2".
Hope this helps.
Jnuw
Comperio
19th August 2006 16:37 UTC
You'll also need to do the same with the end lables. (You can't have 2 lables named the same within your script.)
Other alternatives:
1) You could make each loop it's own function
2) You can use logiclib's ${do} and ${loop} commands instead of lables (To see how this is done, look at the logiclib.nsi in the ${NSISDIR}\examples folder)
Potz
21st August 2006 13:43 UTC
ok I decided to make them in there own functions... but the installer crashes when it gets to this function. I am trying to get this resolved today so any help would be verry much apreciated. Here is my code...
;show regEdit gui---------------------------
Function regEdit
!insertmacro MUI_HEADER_TEXT "Edit the Registry," "read instruction below for this step."
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "RegEditing.ini"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "RegEditing.ini"
FunctionEnd
;-----------------------------------------------------
;Edit Generic NBC Reg Key------------------------------
Function leaveRegEdit
Call Regedit1
Call Regedit2
FunctionEnd
Function Regedit1
ReadINIStr $6 "$PLUGINSDIR\Regedit.ini" "Field 1" "State"
StrCpy $0 "$6" # set your custom string
StrCpy $1 "/" # set the character to insert
StrLen $2 $0 # get the length of your string to loop through it
StrCpy $3 "0" # init the loop counter
StrCpy $4 "" # init output var
loop: # begin of the loop
StrCpy $5 $0 1 $3 # copy one character of your string to a temp var (offset $3 counts up)
StrCpy $4 "$4$1$5" # add the character extracted and the one to insert everytime
IntOp $3 $3 + 1 # increase counter/offset
IntCmp $2 $3 end loop #stop the loop if end of string reached, else continue
end:
# at this stage, $4 will be "/C/o/m/p/a/n/y"
Push "/I/I/M/S" #text to be replaced
Push $4 #replace with
Push all #replace all occurrences
Push all #replace all occurrences
Push "$INSTDIR\WARN\Dashboard\NBC\Generic NBC reg keys.reg" #file to replace in
Call AdvReplaceInFile
FunctionEnd
Function Regedit2
ReadINIStr $7 "$PLUGINSDIR\Regedit.ini" "Field 2" "State"
StrCpy $0 "$7" # set your custom string
StrCpy $1 "/" # set the character to insert
StrLen $2 $0 # get the length of your string to loop through it
StrCpy $3 "0" # init the loop counter
StrCpy $4 "" # init output var
loop1: # begin of the loop
StrCpy $5 $0 1 $3 # copy one character of your string to a temp var (offset $3 counts up)
StrCpy $4 "$4$1$5" # add the character extracted and the one to insert everytime
IntOp $3 $3 + 1 # increase counter/offset
IntCmp $2 $3 end loop1 #stop the loop if end of string reached, else continue
end:
# at this stage, $4 will be "/C/o/m/p/a/n/y"
Push "/C/A/S/P/O/D" #text to be replaced
Push $4 #replace with
Push all #replace all occurrences
Push all #replace all occurrences
Push "$INSTDIR\WARN\Dashboard\NBC\Generic NBC reg keys.reg" #file to replace in
Call AdvReplaceInFile
FunctionEnd
;------------------------------------------------------