|
|
#1 |
|
Junior Member
Join Date: Apr 2005
Location: Oklahoma, USA
Posts: 4
|
Global Variable Init
Hi! I'm a real newbie (been pouring over NSIS for about 12 hours). And I've finally stumped myself.
![]() I understand all variables are global. Var statements are fine outside Sections. Now I'd like to specify variable's value once, then use it in several sections. What's the best way to go about this? Adding code like StrCpy $VarName "Value" doesn't work outside a section. Can I create a section that always executes? Is there another way? Thanks! P.S. !define seems to do the job, if the value is static. But sometimes the value must be determined at runtime. |
|
|
|
|
|
#2 |
|
Major Dude
Join Date: Feb 2004
Location: Moscow, Russia
Posts: 1,222
|
.onInit function may be a good place to set variable value. After this you can use it in any section.
NSIS Documentation, 4.7.2.1.2 .onInit |
|
|
|
|
|
#3 | |
|
Junior Member
Join Date: Apr 2005
Location: Oklahoma, USA
Posts: 4
|
Quote:
If so, I'd have to duplicate my code in the .onInit and un.OnInit functions, something I'd like to avoid. What I'm hoping to find is a way to set my values in one "easy to maintain" location, so I don't have to rely on my old brain to tell me to reproduce each change in another location.
|
|
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Sep 2004
Location: Mogilev (Belarus)
Posts: 372
|
You can remove your code into !macro. And include
in .onInit and un.onInit functions.code: EDIT: or somewhere else. |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Jan 2002
Location: Berlin
Posts: 172
|
Create a function where you store every instruction you want to "re-use". Than call this function in the OnInit and un.OnInit Function.
|
|
|
|
|
|
#6 | |
|
Senior Member
Join Date: Sep 2004
Location: Mogilev (Belarus)
Posts: 372
|
Quote:
|
|
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Jan 2002
Location: Berlin
Posts: 172
|
you're right - sorry for the wrong posting.
The docs says that it is not possible for the installer to call an uninstaller function vice-versa |
|
|
|
|
|
#8 | |
|
Junior Member
Join Date: Apr 2005
Location: Oklahoma, USA
Posts: 4
|
Quote:
![]() For now, I have two functions, AppInit and un.AppInit. They contain identical contents. So far, I haven't found any way to breach the wall between the Install and Uninstall sides, except via !defines. (BTW, just curious -- what's the significance of the ! in front of define and insertmacro?) |
|
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Jan 2002
Location: Berlin
Posts: 172
|
i guess to differ compile-time and run-time commands
|
|
|
|
|
|
#10 |
|
Moderator
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
|
! declares that it is a compile-time command (just a way of breaking up the code and making it more user-friendly).
Just use a !macro (as glory_man has already suggested)... code: If you are worried about it taking up more memory, then don't because it really doesn't take up a more noticeable amount. -Stu |
|
|
|
|
|
#11 | |
|
Junior Member
Join Date: Apr 2005
Location: Oklahoma, USA
Posts: 4
|
Quote:
That seems like the best solution. Off to implement it ... |
|
|
|
|
|
|
#12 |
|
Guest
Posts: n/a
|
global vars
Hi
What if I would like use my global vars not in the section? And How can I use it in File? Do I have to put my funcion and call to function in the section or just !insertmacro "setVars" and how can I do it not in the section? for example <code> Var "pkgname" !macro setVars StrCpy $pkgname "mojapaczka" !macroend Name "$pkgname" InstallDir "c:\$pkgname\$pkgname" Section "install" !insertmacro setVars SetOutPath $INSTDIR File /a /r c:\packages\$pkgname\* SectionEnd </code> =cut Any advice would be appreciated. |
|
|
|
#13 |
|
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,449
|
File needs the path at compile time, use a !define
IntOp $PostCount $PostCount + 1 |
|
|
|
|
|
#14 |
|
Guest
Posts: n/a
|
global vars
THX for advice
![]() but I still can't find the way to write it properly. <code> !define $pkgname "mysoft234" !define $soft "monday" Name $pkgname OutFile d:\nsis\$pkgname-bedzie.exe Section "ins" SetOutPath $INSTDIR File /r "D:\nsis\${soft}\${pkgname}\*" SectionEnd I assume that this is wrong, is't it? maybe: my $var="value"; ![]() Can I ask for anather prompt please. |
|
|
|
#15 |
|
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,449
|
everything that uses pkgname must use ${} (Name,OutFile etc)
IntOp $PostCount $PostCount + 1 |
|
|
|
|
|
#16 |
|
Guest
Posts: n/a
|
still won't work
thx for reply
but still it seems to be a problem. Compiler just ignore my vars, said that File is missing and my OutFile have ${var} in name instead of myname-name.exe <code> ; eh kurwa... Var pkgname ; !system $pkgname "dup" Name ${pkgname} OutFile d:\nsis\${pkgname}bedzie.exe InstallDir "d:\kupa" Section "install" SetOutPath $INSTDIR ;StrCpy ${pkgname} "dup" '' '' File /r "D:\nsis\${pkgname" SectionEnd </code> |
|
|
|
#17 |
|
NSIS Dev
Join Date: Feb 2003
Location: Boston, MA, U.S.A.
Posts: 455
|
Var is runtime. !system is compiletime.
How do you expect them to work together? What do expect to accomplish with: code: Instead try this: code: Then call MakeNSIS.exe with /Dpkgname=dup option. Incidentally, if your outfile is going to d:\nsis\${pkgname}\bedzie.exe, then everytime you build the installer, File /r "D:\nsis\${pkgname}" is going to pick up the previous build. |
|
|
|
|
|
#18 |
|
Guest
Posts: n/a
|
THX
Thank You
![]() Now see my misteke. Regards |
|
![]() |
|
|||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|