Archive: Newbie questions makensis.nsi ? +2, ifdef, RMDir /r


Newbie questions makensis.nsi ? +2, ifdef, RMDir /r
  Hi forum,
I like NSIS and my first installer runs fine.
I read a lot in old posts and in the documentation.
But anyhow, I have some questions :-)

In the makensis.nsi script I saw a lot of:
+2
+3
like in;
------------------------------------------------------------
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Do you want to deinstall?" IDYES +2
............

IfFileExists $INSTDIR\nsisconf.nsi "" +2
...........
StrCmp $R0 "NSISFile" 0 +2
.....
Function PageLeaveReinstall

${NSD_GetState} $R2 $R1

StrCmp $R0 "1" 0 +2
StrCmp $R1 "1" reinst_uninstall reinst_done

StrCmp $R0 "2" 0 +3
StrCmp $R1 "1" reinst_done reinst_uninstall
------------------------------------------------------------

As I understand and read in the doc, these are jumps.
But jumps to where?

2. NO_STARTMENUSHORTCUTS...

What is "NO_STARTMENUSHORTCUTS"?
I think this is an constant and with
!ifndef
we can check if this is defined?
But where is the constant defined and where will it be defined?

Same for
VER_MAJOR & VER_MINOR & VER_REVISION & VER_BUILD
Where are these defined?
-----------------------------------------------------------
!ifndef NO_STARTMENUSHORTCUTS
${MementoSection} "Start Menu and Desktop Shortcuts" SecShortcuts
....

!ifdef VER_MAJOR & VER_MINOR & VER_REVISION & VER_BUILD
-----------------------------------------------------------------

In lot of Posts you can read the warning of using

RMDir /r

But look at the end of the script.
You can see there a lot of lines with RMDir /r
Is this a bad example?

--------------------------------------------------------------------

RMDir /r $INSTDIR\Bin
RMDir /r $INSTDIR\Contrib
RMDir /r $INSTDIR\Docs
RMDir /r $INSTDIR\Examples
RMDir /r $INSTDIR\Include
RMDir /r $INSTDIR\Menu
RMDir /r $INSTDIR\Plugins
RMDir /r $INSTDIR\Stubs
------------------------------------------------------------------

thank a lot for any help and explanation

regards
hawk


Originally posted by hawkmaster
Hi forum,
In the makensis.nsi script I saw a lot of:
+2
+3
As I understand and read in the doc, these are jumps.
But jumps to where?
Lines relative to the line that contains that command.

i.e.
/* line 0 */ IfFileExists "c:\somefile" 0 +2
/* line +1 */ MessageBox MB_OK "c:\somefile exists!"
/* line +2 */
So if the file doesn't exist, the messagebox is skipped.
( note that using '0' is a special case and it always goes to the next line - otherwise it would get stuck in a loop. You could use either 0 or +1; coders tend to use '0' to indicate a "just continue with the code" to anybody reading the source )

I highly recommend using LogicLib instead, where this becomes:
${If} ${FileExists} "c:\somefile"
MessageBox MB_OK "c:\somefile exists!"
${EndIf}
The reason is that if you add a command after the messagebox, the LogicLib version will continue to work. The other version you would have to increase the +2 to +3 (or use a named label with all its perils if this is inside a macro).


Originally posted by hawkmaster
What is "NO_STARTMENUSHORTCUTS"?
I think this is an constant and with
!ifndef
we can check if this is defined?
Correct

Originally posted by hawkmaster
But where is the constant defined and where will it be defined?
They would be defined by you, the user. In the specific case of this define, it might get used by a Start Menu page. This will depend on the exact script you got that from.
This script...
http://steveprutz.wikidot.com/nsis
...uses it, for example.
You can see that he only includes the code for creating start menu shortcuts in his installer if 'NO_STARTMENUSHORTCUTS' is -not- defined.

Originally posted by hawkmaster
Same for
VER_MAJOR & VER_MINOR & VER_REVISION & VER_BUILD
Where are these defined?
Same applies there - they would be set by you, the user.

These are all defines that NSIS doesn't use, itself, directly - so their usage and what they do would depend on your installer script. They aren't required, though.

Originally posted by hawkmaster
In lot of Posts you can read the warning of using

RMDir /r

But look at the end of the script.
You can see there a lot of lines with RMDir /r
Is this a bad example?
Yes. It assumes that $INSTDIR is the location that was installed to. If $INSTDIR is blank, for any reason, it would then proceed to remove anything from e.g. "c:\Docs\". Although it's not likely that any of these folders exist in the root drive, it's still bad practice.
In addition - for this example script especially - if the user decided to write some of their own Include files and saved them in that Include folder thinking that would be appropriate, then the code given would also remove the Include files the user created. Typically not desired behavior.

I hope this helps :)

The compiler has a define command so VER_MAJOR etc can be defined and changed at compile time and not have to modify the script to change or update the version of the installer.

Defines are set in Tools -> Settings in MakeNSISW.


Thank's a lot for this good explanation.
It helps me.

What is still not really clear is the handling with constants and !ifdef:
In the script of http://steveprutz.wikidot.com/nsis or in makensis.nsi for example:
................................
!ifndef NO_STARTMENUSHORTCUTS
CreateShortCut "$SMPROGRAMS\NSIS.lnk" "$INSTDIR\NSIS.exe"
!endif
.................

What I am missing is something where the constant is set, like
NO_STARTMENUSHORTCUTS = "" or
NO_STARTMENUSHORTCUTS = yes
For my understanding the "CreateShortCut" is always done because the constant is never set?
Is "NO_STARTMENUSHORTCUTS" a fix name of NSIS ?
or can you write:
!ifndef NONE_SHORTCUTS_STARTMENU
..
is this the same?

perhaps I am thinking too much complicated :-)

regards
hawk


If the define is never defined, then yes, the createshortcut command is always compiled into the installer. It could be defined in some !include file somewhere, of course. But google finds this:
http://forums.winamp.com/showthread.php?postid=842561
So apparently the !ifndef was added to mute shortcut creation in automated NSIS installers.