Skip to content
⌘ NSIS Forum Archive

InstallOptions verses: Modern UI (Round 1, Fight!)

12 posts

Shorin#

InstallOptions verses: Modern UI (Round 1, Fight!)

I have had major issues with NSIS over the past few weeks, and many of them arise when I try to use either Modern UI and/or InstallOptions. Many of them are solved by simply moving functions to another place in the file, or moving this include before that include... and other not-so-obvious things.

Anyways, my presentation today is one of ambiguous functions that do not function identically.

Version one simply has a custom page that has a text box field on it (among other things), and displays the user-entered text in a messagebox upon leaving that page.
Version 1: (FUNCTIONS PROPERLY)
...(includes, INCLUDES MODERN UI stuff)
...(attributes, modern ui stuff)
...(.onInit)
...(Pages, modern ui pages):
Page custom Pre Post
...
... (Sections)
... (Functions):
Function Pre
Push $0
InstallOptions::dialog ".\master_slaveconfig.ini"
Pop $0
FunctionEnd

Function Post
Push $R0
ReadINIStr $R0 ".\master_slaveconfig.ini" "Field 6" "State" ; Field 6 is a text box
MessageBox MB_OK $R0
Pop $R0
FunctionEnd

Problems in Version 1: No problems.



Version 2 uses Modern UI calls to show the custom dialog. Modern UI asks you to INITDIALOG and also DISPLAY it, not just call InstallOptions::dialog. DISPLAY alone doesn't work.
Version 2:
... (other parts of file are the same as #1)
... (Functions):
Function Pre
Push $0
!insertmacro MUI_INSTALLOPTIONS_INITDIALOG "/NOUNLOAD .\master_slaveconfig.ini"
Pop $0
Push $0
!insertmacro MUI_INSTALLOPTIONS_DISPLAY ".\master_slaveconfig.ini"
Pop $0
FunctionEnd

Function Post
... exactly the same as #1
FunctionEnd

Problems in Version 2: Even if data is entered in to Field 6's text box, MessageBox shows $R0 as completely blank. If you edit the INI file and set "State" to something, MessageBox shows this instead of what the user wrote.



Now then, can anybody tell me why this happens? Is this a bug?
Afrow UK#
Why are you using INITDIALOG and DISPLAY?
You only use INITDIALOG if you need to modify controls on the dialog before it is shown, and even after that you use MUI_INSTALLOPTIONS_SHOW and not DISPLAY. I'm suprised it's even working at all!

You also have your Pop's wrong. InstallOptions pushes a value onto the stack, so you need two Pop's rather than just one.

Function Pre
Push $0
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "master_slaveconfig.ini"
Pop $0
Pop $0
FunctionEnd
Finally, with Modern UI you use MUI_INSTALLOPTIONS_READ to read values from the INI file. This is because with the MUI INSTALLOPPIONS macros, the INI file is always stored in $PLUGINSDIR.

-Stu
Shorin#
I knew it!

Ah! I knew it! The MUI documentation is out of date!

... well, I am not surprised, I hate spending all that time documenting stuff too.
Shorin#
so... now wat?

What do I use if I want to simulate
InstallOptions::dialog "..."
in MUI? (is it SHOW, DISPLAY...?)
Shorin#
o...

Oh, I see. MUI_INSTALLOPTIONS_DISPLAY does that.

Now what about MUI_INSTALLOPTIONS_READ?

This is all it does:
!macro MUI_INSTALLOPTIONS_READ VAR FILE SECTION KEY

!verbose push
!verbose ${MUI_VERBOSE}

ReadIniStr ${VAR} "$PLUGINSDIR\${FILE}" "${SECTION}" "${KEY}"

!verbose pop

!macroend

Which would be the same as calling
ReadINIStr $R0 "myfile.ini" "Field 1" "State"

Right?

Except that ....

!macro MUI_INSTALLOPTIONS_EXTRACT FILE

!verbose push
!verbose ${MUI_VERBOSE}

InitPluginsDir

File "/oname=$PLUGINSDIR\${FILE}" "${FILE}"

!insertmacro MUI_INSTALLOPTIONS_WRITE "${FILE}" "Settings" "RTL" "$(^RTL)"

!verbose pop

!macroend

And I'm afriad I did use that...
Afrow UK#
!insertmacro MUI_INSTALLOPTIONS_READ "master_slaveconfig.ini" "Field 6" "State"

You only need to specify the INI file name. No full path.

-Stu
Shorin#
Can anybody tell me when they'll fix the parsing problem in NSIS? I notice that alot of things don't work if you don't follow the unwritten code of the "mystical parsing order" (I mean that functions and sections have to be in specific places in the file for anything to work).
I'd do this myself, but I'm on company time right now, and honestly, I'm not getting paid to rewrite NSIS, I'm getting paid to use it.
Afrow UK#
It isn't a parsing problem at all. It is by design.
And it would be silly not to check the warnings that the compiler throws at you (literally).

The problems that you have had are most likely trying to use constants before they are created with the !define instruction (or perhaps Section index constants that are created with the Section or SectionGroup instructions).
Naturally, you can't use a constant value before you create it. Much like you can't use a variable before you create it!

-Stu
Shorin#
Well that may be right, but I was hoping you could actually find these things quickly (not having to spend 2-10 minutes reading the compile log).

I was wonding if you could suggest a good syntax-checking NSIS Dev environment...
Shorin#
And what about the documentation.. .is that really up to date or is there a version I don't have yet...
Afrow UK#
You can try Eclipse NSIS, which uses Sun's Eclipse Java development platform. There's a page on the Wiki. The manual distributed with the latest version of NSIS is the latest version.

-Stu