- NSIS Discussion
- using a plugin
Archive: using a plugin
teebird
31st December 2008 02:02 UTC
using a plugin
hello,
I want to use the PassDialog plugin with the NSIS installer. I can't figure out how. Here's what I've done so far...
1. Installed the NSIS installer
2. Used the NSIS installer successfully many times
3. Modified my xxx.nsi files successfully many times
4. downloaded the PassDialog.zip file
5. extracted the PassDialog files into a NSIS/password folder
6. Looked at the Password.nsi example file
I can't see how this file relates to my other .nsi files.
How do I use it?
It has lots of ## and ! characters, unlike my other .nsi files.
----------------
My goal is simply to have the NSIS installer ask the user for a password before installing a program.
Thanks very much for some help.
Animaether
31st December 2008 07:34 UTC
The ## stuff is just a comment field, the ! bits are commands and defines for various bits and pieces.
Here's a slightly cleaner example:
!include "WinMessages.nsh"
!addplugindir "."
OutFile "PassDialogTest.exe"
; Pages BEFORE your password check go here - e.g. a Welcome page
Page license
; Password check pages
Page Custom PasswordPageShow PasswordPageLeave
; Pages AFTER your password check go here - e.g. all the actual file installation, directory picking, etc. pages.
Page Components
Function PasswordPageShow
; Initialize the password dialog
PassDialog::InitDialog /NOUNLOAD Password /HEADINGTEXT "Please enter the password which you will find on the back of your DVD box" /GROUPTEXT "DVD box password... (the password is: password)"
; Get its handle off the stack
Pop $R0
; Get the password field control
GetDlgItem $R1 $R0 1211 ; 1211 is the control ID of the password field
; And change it to actually be a password field
SendMessage $R1 ${EM_SETPASSWORDCHAR} 178 0 ; EM_SETPASSWORDCHAR comes from WinMessages.nsh and defines a password field style
; Display the password dialog
PassDialog::Show
FunctionEnd
Function PasswordPageLeave
; Get the password the user entered off the stack
Pop $R0
; Compare the password to what it should be
StrCmp $R0 "Password" _passwordOK _passwordWRONG
; The password was incorrect
_passwordWRONG:
; display a warning message
MessageBox MB_OK|MB_ICONSTOP "PASSWORD INCORRECT"
; and call Abort to prevent the next page from showing
Abort
;The password was correct
_passwordOK:
; So just let things continue from here on
FunctionEnd
Section "Dummy Section"
; Just a dummy section so that the Components page displays something
SectionEnd
However, I think you may wish to look into nsDialogs - it gives you much more control over what the password page looks like and such; with the above example, you'll note it's got a lot of blank space due to the plugin accommodating multiple fields, but our only actually using one. It looks a bit odd :)
teebird
31st December 2008 14:06 UTC
Thanks, Animaether. My question is more basic. I don't know the process of using a plugin with NSIS.
I dragged each ".nsi" file to the NSIS compiler box, and each got an error.
Each plugin ".nsi" file says at the top that it will create a ".exe" file. I don't want another exe file, all I want is for my installer to ask for a password.
I'm reading through the tutorial and the documentation, and I don't see any level of help for me.
The documentation says "See NSIS\Examples\PassDialog\* for examples of use"... but that folder does not exist.
Thanks for some more help :)
Animaether
31st December 2008 16:35 UTC
ahh... okay, first thing to recognize is that .nsi files aren't plugins, but script files. The actual plugin is typically a .dll file.
The .dll file, as long as it is in one of the plugin folders, will automatically be recognized by name. In this case, by calling PassDialog::* in the script.
The PassDialog::* calls are the actual plugin calls..in the case of PassDialog, for example, PassDialog::InitDialog initializes the dialog that the plugin can create and PassDialog::Show displays that dialog.
Each plugin will have a different set of calls, and it is those calls that you should look up in their documentation (sometimes there is no documentation, and you have to look at the example files instead), so that you know how to use them in your own script.
So as per my above example, I included this tidbit...
; Pages BEFORE your password check go here - e.g. a Welcome page
Page license
; Password check pages
Page Custom PasswordPageShow PasswordPageLeave
; Pages AFTER your password check go here - e.g. all the actual file installation, directory picking, etc. pages.
Page Components
That should tell you how to integrate the plugin's use within your own script; simply place the "Page Custom PasswordPageShow PasswordPageLeave" line wherever you want in your own list of pages.
Not all plugins deal with pages, of course, some crunch numbers, other access O/S information, but they pretty much all find use as small bits of script code to call the plugin, which you would integrate into your own script.
This is jumping into the deep a slight bit, as it sounds like you're not entirely familiar with NSIS in general, so if you run into any problems - well, that's what the forum is for :)
teebird
31st December 2008 17:07 UTC
Thanks.
Here's the level I'm at...
I write C code all day long. I'm selling a product using the NSIS installer. It works great. Yet, I have no idea what you're talking about when you say "Pages". My nsi scripts have no pages. My installer asks the customer to install in a folder, it works, and my customers are happy.
I'm completely lost on how to use a plugin.
Do I need to re-compile the NSIS application as if I'm the developer? Do I need to compile the C code of each plugin I use?
I entered the line "Page Custom PasswordPageShow PasswordPageLeave" in my script and got an error.
The nsDialogs plugin shows on the NSIS application window, but not the PassDialog. Is that a clue to what I'm doing wrong?
Sorry, I'm so lame.
Animaether
1st January 2009 01:05 UTC
no worries :)
First, try placing the "PassDialog.dll" file that should be in the passdialog download in your <program files>\nsis\Plugins\ folder. That way you can be sure NSIS will find it.
Next - no, there's no recompilation or anything necessary.
You say that your installer script (your .nsi file) asks to install in a folder and then installs. That should, or at least typically does, mean that you have two pages already...
Page Directory
Page InstFiles
(if you are using MUI - Modern UI - then it may look more like..
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
)
Each 'Page' is one of the dialogs you see in an installer.. so when you start the installer you get one 'page', when you press Next you go to the next 'page', etc.
You would basically place the password line (Page Custom PasswordPageShow PasswordPageLeave) just before that directory 'page'.
The reason it throws an error is most likely either one of..
A. It not finding the plugin - the aforementioned should resolve that
B. It not finding the Functions "PasswordPageShow" and "PasswordPageLeave". If you check my earlier example, those Functions should be in there as well - make sure you copy those over ( and, of course, adjust them to your needs.. I can't imagine you want the password to be "password", for example =) )
I hope this helps, I know NSIS script looks pretty foreign compared to most languages (I know several and deem NSIS one of the quirkiest to learn), but if you get to grips with it, it's also very powerful.
teebird
1st January 2009 06:44 UTC
yes, it's New-Year's-Eve and I'm still trying to get this to work.
I have a section that looks like this...
Page components
Page directory
Page instfiles
and I made it look like this...
Page components
Page Custom PasswordPageShow PasswordPageLeave
Page directory
Page instfiles
here's the error...
Processed 1 file, writing output:
Error: resolving create-page function "PasswordPageShow" in install pages
Note:
the PassDialog.dll is in my Plugins folder, but its date is 5/6/2006 where-as the dates on my other DLLs are 3/29/2008.
Note2:
I compiled the first tutorial from the nsDialogs plugin, and it ran, but there was no dialog box, but it looked like it installed something, then when I clicked on "show details" it showed "hello world, Completed." I don't get it.
I'll be glad to use nsDialogs if I could just find a sample or tutorial that showed how to incorporate a dialog asking for a password with a software installer function. Why would I want to do just a dialog?
Do you know of any such examples?
Thanks Animaether, do you think I'll figure this out by 2009? I've got about an hour. Cheers!
Afrow UK
1st January 2009 17:18 UTC
You need to have a look at the examples. The 'hello world' script you compiled is just one of the many examples. Have a look at the code.
The error that you mention is pretty self explanatory - you haven't got a PasswordPageShow function defined in your script. Custom pages require you to have a show function where you call the plugin of choice for your custom page.
Stu
teebird
2nd January 2009 00:46 UTC
Afrow, thanks. I thought the error message meant that I didn't have a function defined in the DLL. I seem to have a password working now. I'll try it in my other software install scripts.