My understanding to date - Basic Installer
I hope this info can potentially help someone who is starting out. It's a culmination of help from many sources, including Cheryll, RedWine, and AfrowUK. Thanks to the other guys as well :) I'm bound to perhaps misrepresent a feature or element somehow, so please just post away with the correction, as the edit feature will not allow for late edits to the OP.
------------------------------------------------------
This is a list of functions that I think people will be able to make use of when trying to learn NSIS.
1.) User Account Type Check.
Function .onInitThis is obviously an NSIS function that will check the current user account type. Use the working example to check if the user is allowed to mess with your installer/uninstaller.
UserInfo::GetAccountType
Pop $0
StrCmp $0 "Admin" 0 +3 ;
;MessageBox MB_OK 'You seem to be an admin!'
Goto done
StrCmp $0 "Power" 0 +3
MessageBox MB_OK 'You must be logged in as Administrator!'
Quit ;
StrCmp $0 "User" 0 +3
MessageBox MB_OK 'You must be logged in as Administrator!'
Quit ;
StrCmp $0 "Guest" 0 +3
MessageBox MB_OK 'You must be logged in as Administrator!'
Quit ;
MessageBox MB_OK "Unknown error (Perhaps unknown account type?)"
Quit ;
Win9x:
# This one means you don't need to care about admin or
# not admin because Windows 9x doesn't either
MessageBox MB_OK "(Checking Account Type) Error! This DLL can't run under Windows 9x!"
done:
This should really go in your initialisation, note the example doesn't close the function, and that's simply because you'll want to put some other things in your initialisation too.
2.) Custom Page (Login Details)
!insertmacro MUI_INSTALLOPTIONS_EXTRACT_AS "Custom.ini" "Custom"This is actually the section cut after the last. So the Functionend is the end of the initialisation.
Functionend
LangString CUSTOM_TITLE ${LANG_ENGLISH} "Enter your Login Details."
LangString CUSTOM_SUBTITLE ${LANG_ENGLISH} " "
Page custom CustomPage MyCustomLeave
#==================================
Function CustomPage
!insertmacro MUI_HEADER_TEXT "$(CUSTOM_TITLE)" "$(CUSTOM_SUBTITLE)"
# Display the page.
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "Custom"
FunctionEnd
This example assumes that you want your custom page to appear before your main sections. Notice that the 'Page custom' wants to run two functions, 'CustomPage' and 'MyCustomLeave'. The CustomPage function simply adds info to the header text and of course, displays the page (renders your .ini file).
Function MyCustomLeaveI don't know everything (anything? ^^) about how the .ini files work, but it would seem that the .ini file can be read for the state of a button which is automatically added by NSIS, the next button.
ReadINIStr $0 "Custom.ini" "Settings" "State"
StrCmp $0 0 extract ; Next button?
;Abort
extract:
# Get the user entered values. ---------------==============================
!insertmacro MUI_INSTALLOPTIONS_READ $Username "Custom" "Field 1" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $Password "Custom" "Field 2" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $Server "Custom" "Field 3" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $Autoupdate "Custom" "Field 4" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $AUpdatePath "Custom" "Field 5" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $DatabaseName "Custom" "Field 6" "State"
done:
FunctionEnd
The Leave function simply wants to do stuff when you continue past the page, which is the same as saying that you click the next button. The details that user's have input on our custom page now get extracted to variables.
WriteRegStr HKCU "Software\VB and VBA Program Settings\${PRODUCT_NAME}\Main" "MySQLUser" $Username ;As per install instruction file.This writing to registry is placed in the main section, which in install time, is just after the last file is copied. The logic ${If} statements assume that you have included the Logic library (!include 'LogicLib.nsh').
WriteRegStr HKCU "Software\VB and VBA Program Settings\${PRODUCT_NAME}\Main" "MySQLPass" $Password
WriteRegStr HKCU "Software\VB and VBA Program Settings\${PRODUCT_NAME}\Main" "MySQLADDR" $Server
WriteRegStr HKCU "Software\VB and VBA Program Settings\${PRODUCT_NAME}\Main" "AutoUpdatePath" $AUpdatePath
WriteRegStr HKCU "Software\VB and VBA Program Settings\${PRODUCT_NAME}\Main" "MySQLDBName" $DatabaseName
WriteRegStr HKCU "Software\VB and VBA Program Settings\${PRODUCT_NAME}\Main" "DBAccessMode" "1"
WriteRegStr HKCU "Software\VB and VBA Program Settings\${PRODUCT_NAME}\Main" "Status" "1"
;MessageBox MB_OK '0 is off and 1 is on! :: $Autoupdate' -====== Check!
${If} $Autoupdate == "1" ;control was selected
WriteRegStr HKCU "Software\VB and VBA Program Settings\${PRODUCT_NAME}\Main" "AutoUpdateEnable" "1"
${EndIf}
${If} $Autoupdate == "0"
WriteRegStr HKCU "Software\VB and VBA Program Settings\${PRODUCT_NAME}\Main" "AutoUpdateEnable" "0"
${EndIf}
You'll notice a message box line that is commented out. Remember to use these to check on the different stages of install of certain elements.
3.) Uninstaller Planning(a)
WriteRegStr HKLM "Software\VB and VBA Program Settings\${PRODUCT_NAME}\Main" "InstPathHere" "$INSTDIR"When using the uninstaller, to correctly identify the install path, we cannot use $INSTDIR if our uninstaller is not placed in the $INSTDIR at install time. This suggests and means that the $INSTDIR used in the uninstaller is based on the location of the uninst.exe or whatever your uninstaller is called.
4.) Deleting Files(risky)
RMDIR /r "$R0"Firstly, this is not recommended by the majority here it seems, so I shan't encourage it much, but rather offer how and why and when it can be useful.
Having taken steps similar to the previous, the correct install path will remain in the registry and be able to be extracted accurately and used UNLESS a user:
1) changes that registry
2) renames the install folder manually
3) or steps to a similar effect.
Therefore, when using remove directory /r with your install path, the folder and everything in it will be deleted properly. Because this is potentially risky, given that the user takes to changing details which shouldn't matter a whole lot (usually appropriate naming prevents needs to rename, and messing with the registry is never a good idea unless one knows exactly what they want) you can use the preferred NSIS method of deleting all files within a folder, and then removing the directory without the '/r' parameter. The reason I don't use this, is because users are much more likely to add or subtract files from the INSTDIR than do any other changes, and also when there are updates, certain files will be added which may become part of the application while not becoming part of the uninstaller, which will by default only remove the files it knows should be there. Leaving you with a not-quite-uninstalled application.
---------------------
And that's all :)