vbgunz
16th March 2005 19:56 UTC
How Do You Make !Macro's Accept Dynamic Parameters?
I am trying to create a macro in which the parameters are unknown. There could be 1 or there could be 20. The problem with macros outright is it seems they need to know the exact number of parameters in which I in turn need to be dynamic.
!macro operation parameter1
...
!insertmacro operation parameter1 parameter2 parameter3 parameter4
How do I tell the macro that there could be more parameters without getting the following error:
!insertmacro: macro "operation " requires 1 parameter(s), passed 4!
In a real world scenario heres the deal. I have a zipup operation which zips up a file. I sometimes need only 1 OR 20+ files zipped up. Instead of creating a new !insertmacro for every file HOW do I create one !insertmacro and pass all the files to it?
Instead of this:
!insertmacro operation "file1"
!insertmacro operation "file2"
!insertmacro operation "file3"
!insertmacro operation "file4"
!insertmacro operation "file5"
!insertmacro operation "file6"
To This:
!insertmacro operation "file1" "file2" "file3" "file4" "file5" "file6"
Thanks for any tips, tricks and any help on this!
Afrow UK
16th March 2005 20:27 UTC
This is possible, but it's a bit messy and will take I'd say 30 minutes of your time.
Your macro should take the list of files as one paramater, then writes it to a file like so:
!macro operation FileList
!system "${FileList} >list.tmp"
Then you want to create another installer which reads from list.tmp, and with some string functions in it, parses the list of files and writes some more NSIS code involving each file to say list.nsh.
You then use !include list.nsh under the above !system call, and finally use !system "del list.tmp" and !system "del list.nsh" to delete the temporary files.
It probably sounds easier to use !insertmacro for each one.
You could shorten !insertmacro MyMacro to:
!define MyMacro "!insertmacro MyMacro" and thus ${MyMacro} serves as the same purpose.
-Stu
vbgunz
16th March 2005 21:15 UTC
whoa, I had no idea creating a looping dynamic parameter macro would require so much work. Sounds easier in theory ;)
Major thanks Afrow, but that technique seems like it isn't worth the trouble Vs simply listing more !insertmacros.
I'll take your word on the last bit of your advice :)
Thanks Afrow!
kichik
17th March 2005 17:54 UTC
There's no need for an external application in this case. You can simply use:
!macro op args
untgz::extractV -i ${args} --
!macroend
!insertmacro op 'file file2 "file with spaces" another_one'
This will be translated into:
untgz::extractV -i file file2 "file with spaces" another_one --
vbgunz
19th March 2005 08:16 UTC
Thanks for pointing that out Kichik! Thanks Afrow for making the wheels spin ;)