banaman8d
27th May 2003 16:01 UTC
SetErrors in a plugin.
Hi,
I am writing a generic application update tool using
specially formatted .ini files and a plugin used to
fill in values specified in the ini files.
For example a valid ini entry would look like:
key={INSTDIR}\somedir
and I use the plugin to replace this with the value of $INSTDIR.
I am new to writing plugins for NSIS, and NSIS for that matter, but
after digging through the sources for a number of plugins I don't see where the plugin functions set any error flags. How would I do this?
What people seem to do now is just push thier own status values onto the stack, but they are undocumented. Since people rely on a sane stack for their installs to run correctly, this could break installs.
If anyone could set me straight on this I would greatly appreciate it.
Otherwise I'll stay looking like Igor -> :igor:
kichik
27th May 2003 16:10 UTC
Welcome to the forum.
Plug-ins can't set the error flag yet. You have to push it on the stack. Since the NSIS stack doesn't really use the stack but allocates memory using GlobalAlloc there shouldn't be any problem of the stack "running out".
BTW, why don't you use ReadIniStr and WriteIniStr instead of writing a plug-in?
banaman8d
27th May 2003 18:20 UTC
Thanks Kichik,
I am using the (Write|Read)Ini* functions to read and write values from the ini files. I am using the plugin for utility functions like interpolating NSIS variables into ini strings after they are read.
so,
{INSTDIR}\myfile
becomes:
C:\Program Files\MyApp\myfile
This simple task could be done by scripting, but I wanted to keep the functions together logically. Also, the scripts become cumbersome fast.
The only thing I can't figure out is how to access values like
$PROGRAMFILES from the plugin. The defines in the ExDLL example include INSTDIR and friends, but not others. Is there a way to do this?
Joost Verburg
27th May 2003 18:48 UTC
You can write the folders to a temporary location or detect 'em yourself (just a simple registry key).
Sunjammer
27th May 2003 23:00 UTC
Why not just have a plugin function which you call giving it the values (such as $PROGRAMFILES) from the script, a kind of initialisation function so that the plugin can do its work?
banaman8d
28th May 2003 14:55 UTC
Thanks for the suggestion SJ,
I decided to do just that. This is the general idea of what I am doing:
; Function to interpolate 'special' values into strings.
; input: $R0
; output: $R0
; error: none set
; This will probably change so that it uses the stack.
Function Interpolate
Push $R1
; Interpolate Program Files location into string
nsmys::SearchAndReplace $R0 "{PGMFILES}" "$PROGRAMFILES"
Pop $R1 ; Get value from SearchAndReplace
StrCmp $R1 "error" +2 0
StrCpy $R0 $R1 ; replace old string with interp'ed
; Interpolate Desktop values
nsmys::SearchAndReplace $R0 "{DESKTOP}" "$DESKTOP"
Pop $R1
StrCmp $R1 "error" +2 0
StrCpy $R0 $R1
.
. ; Do other interpolations
.
Pop $R1
FunctionEnd