Archive: custom page issue


custom page issue
Below is the NSIS script I am working on.
For it to run it would require a file called SideGroup.txt to be in c:\NSISFiles and
the file would have the format of:
a
b
c

Now to my problem.

I have create three cutom pages.
The first queries the user as to the type of database they are using.
The Second will either get a access database or the SQL server info needed to make a connection.

The third is conditional based on if the 'Section "Install Desktop Shortcut for Training Database" AppTraining' is selected. By default it is off.

When this selection is made and the install button clicked, it displays this screen and allows
a training database to be selected.... but no further action is possible. All buttons on this screen are disabled and the only way to get out of it is to kill the task manually via task manager.

So.... what am I doing wrong here? (And 'everything' might be an acceptable answer.)

Many thanks for any help provided.

#---------------------------------
#App Installer
#
# v-Install Process Options-v
#
# -- Determine what type of database the user is using with pave
#
# -- Query the user as to the Access database location or the SQl server info
#
# -- Unload the Java side group program and JRE
#
# -- Execute the Java side group program
#
# -- Retreive the side groups from the file produced by the side group program
#
# -- Delete the side group program, JRE and side group file
#
# Note: if no side groups are found the following step need not be performed
#
# ---- Build side group startup.bat files for install.
#
#
# -- install App
# -- install App training
# --
#
# -(Start menu icons)
# --install start menu icons (all short cuts)
#
# -(desktop)
# --install player sides icons (desktop)
# --install editor icons
# --install playback icons
# --install whitecell icons
# --install training icon (if training is being installed)
#
#
;---------------------------------
;Includes.
!include "Sections.nsh"


!include "StrFunc.nsh"
${StrLoc}
${StrRep}
${StrTrimNewLines}
!include "MUI2.nsh"
!include "LogicLib.nsh"
!include "nsDialogs.nsh"


;--------------------------------
;General.

;Name and file
Name "App"
OutFile "AppInstaller.exe"

;Default installation folder
InstallDir "$PROGRAMFILES32\App"

;Request application privileges for Windows Vista
RequestExecutionLevel user



;Query the user for the database type and then the database.
;Once we have the database, we need to retreive the sides from the database
;so we can build the startup.bat files for each side.

Page Custom getDatabaseTypeToUse

Page custom getDatabaseToReadFrom checkForValidEntries

;This page is supposed to be conditional.
;But it won't go away once a file is selected.
Page custom getTrainingDatabaseToReadFrom ; <-problem child

Var Dialog
var hwnd

Var databaseType
Var databaseSelected
Var serverName
Var appInstalled
Var parameters
Var traningDatabaseSelected

Var header
Var Get_BrowseButton
Var IsTraining






;--------------------------------
;Icon files

;!define MUI_ICON installerImages\orange-install.ico
;!define MUI_UNICON installerImages\orange-uninstall.ico


;--------------------------------
;Pages.
; APP Installation directory Page


!insertmacro MUI_PAGE_COMPONENTS

;!define MUI_PAGE_CUSTOMFUNCTION_LEAVE CheckDirectoryPermission
;!insertmacro MUI_PAGE_DIRECTORY

!insertmacro MUI_PAGE_INSTFILES

!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES


;--------------------------------
;Languages.

!insertmacro MUI_LANGUAGE "English"



;--------------------------------
;App install sections.


Section "Install App" App



SetOutPath $INSTDIR

;Copy files to install directory
;File /r distBin\App\*
; File /r \*

;Create uninstaller
; WriteUninstaller $INSTDIR\Uninstall.exe

;Build startup files
; Delete $INSTDIR\startupWhiteCell.bat

ClearErrors

; FileOpen $0 $INSTDIR\startupWhiteCell.bat w

IfErrors done

StrCpy $appInstalled "true"

; FileWrite $0 "set APP_PATH=$INSTDIR"
; FileWrite $0 "$\r$\n"
; FileWrite $0 "jre7\bin\java.exe -Xms512m -Xmx512m -classpath %APP_PATH%;%APP_PATH%/lib/jh.jar src/application.Main"
; FileClose $0

;need some kind of loop to figure out what sides are available from the database to create the bat files.


done:

SectionEnd


Section "Install Desktop Shortcut for Training Database" AppTraining

${If} $appInstalled == "true"

Call getTrainingDatabaseToReadFrom

MessageBox MB_OK " value(1) $traningDatabaseSelected"

${StrLoc} $0 $traningDatabaseSelected ".accdb" ">"

${If} $traningDatabaseSelected != ""
${AndIF} $traningDatabaseSelected != "*.accdb"
${AndIf} $0 != ""
MessageBox MB_OK "value(2) $traningDatabaseSelected $0"
call installTrainingSideGroupFiles

${EndIf}

${EndIf}

SectionEnd

;--------------------------------
;This section creates a desktop shortcut for the full version.

Section "Install Desktop Shortcut For Sides" DesktopShortCuts


Call installSideGroupFiles


SectionEnd


;--------------------------------
;This section creates start menu shortcuts.

Section "Install Start Menu Shortcuts" StartMenu

CreateDirectory $SMPROGRAMS\App

CreateShortCut $SMPROGRAMS\App\App-WhiteCell.lnk $INSTDIR\startupWhiteCell.bat ;"" ${MUI_DESKTOP_ICON_G}

CreateShortCut $SMPROGRAMS\App\Uninstall-App.lnk $INSTDIR\uninstall.exe

SectionEnd



;--------------------------------
;Create descriptions of each component.

LangString DESC_App ${LANG_ENGLISH} "Installs the App application."

LangString DESC_AppTraining ${LANG_ENGLISH} "Install the App Training startup files. Requires App to be installed and a Training database."

LangString DESC_StartMenu ${LANG_ENGLISH} "Place shortcuts for running and uninstalling App in the Start Menu."

LangString DESC_DesktopShortCuts ${LANG_ENGLISH} "Place shortcuts for running App on the desktop."


!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${App} $(DESC_App)
!insertmacro MUI_DESCRIPTION_TEXT ${AppTraining} $(DESC_AppTraining)
!insertmacro MUI_DESCRIPTION_TEXT ${StartMenu} $(DESC_StartMenu)
!insertmacro MUI_DESCRIPTION_TEXT ${DeskTopShortCuts} $(DESC_DesktopShortCuts)
!insertmacro MUI_FUNCTION_DESCRIPTION_END




#
# Note: .onInit has to come after all defined section if you want to reference a section for
# conditional processing.
#
Function .onInit

StrCpy $databaseType "Access"
StrCpy $databaseSelected ""
StrCpy $serverName ""
StrCpy $appInstalled "false"
StrCpy $traningDatabaseSelected ""
StrCpy $IsTraining "false"

;default this section to off so it is conditional
SectionGetFlags ${AppTraining} $0
IntOp $0 $0 & ${SECTION_OFF}
SectionSetFlags ${AppTraining} $0


;These are not the droids I was looking for.....
;SectionSetFlags ${AppTraining} 17 ; this forces it to be checked and unselectable by the user
;SectionSetFlags ${AppTraining} 16 ; this forces it to be unchecked and unselectable by the user
;SectionSetFlags ${AppTraining} 15 ; this forces it to be unchecked and unselectable by the user - but all other sections are in a sub tree and selected
;SectionSetFlags ${AppTraining} 14 ; this forces it to be unchecked and unselectable by the user - but all other sections are in a sub tree and unselected
;SectionSetFlags ${AppTraining} 13 ; this forces it to be unchecked and selectable by the user - but not all sections availible
;SectionSetFlags ${AppTraining} 12 ; this forces it to be checked and selectable by the user - but not all sections availible - almost worked



FunctionEnd


#############################################
#
# Additional functions and sections used in processing the install
#
#############################################


#####################################################################################
# Depending on the option selected, either get the access database or
# the SQL Server parameters needed.
#####################################################################################
Function getDatabaseToReadFrom

${If} $databaseType == "Access"
Strcpy $header "Please select an $databaseType database."

StrCpy $IsTraining "false"
!insertmacro MUI_HEADER_TEXT $header " "

nsDialogs::Create /NOUNLOAD 1018
Pop $Dialog

${If} $Dialog == error
Abort
${EndIf}

${NSD_CreateFileRequest} 10 120 85% 20 ""
;Pop $hwnd
Pop $databaseSelected

${NSD_CreateBrowseButton} 89% 120 7% 20 ...
Pop $Get_BrowseButton

GetFunctionAddress $0 OnCLick_Get_BrowseButton
nsDialogs::OnClick /NOUNLOAD $Get_BrowseButton $0

nsDialogs::Show

${Else}

Strcpy $header "Please provided $databaseType database information."
!insertmacro MUI_HEADER_TEXT $header " "
nsDialogs::Create /NOUNLOAD 1018
Pop $Dialog

${If} $Dialog == error
Abort
${EndIf}

${NSD_CreateLabel} 0 0 100u 12u "Please enter SQl Server Name:"
Pop $hwnd

${NSD_CreateText} 101u 0 100u 12u ""
Pop $0


${NSD_CreateLabel} 0 14u 100u 12u "Please enter database name:"
Pop $hwnd

${NSD_CreateText} 101u 14u 100u 12u ""
Pop $1

nsDialogs::Show

${EndIf}


FunctionEnd


Function getTrainingDatabaseToReadFrom

SectionGetFlags ${AppTraining} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
IntCmp $R0 ${SF_SELECTED} okToShow

Abort

okToShow:


Strcpy $header "Please select an Access training database."

StrCpy $IsTraining "true"
!insertmacro MUI_HEADER_TEXT $header " "


nsDialogs::Create /NOUNLOAD 1018
Pop $Dialog

${If} $Dialog == error
Abort
${EndIf}

${NSD_CreateFileRequest} 10 120 85% 20 ""
;Pop $hwnd
Pop $traningDatabaseSelected

${NSD_CreateBrowseButton} 89% 120 7% 20 ...

Pop $Get_BrowseButton

GetFunctionAddress $0 OnCLick_Get_BrowseButton
nsDialogs::OnClick /NOUNLOAD $Get_BrowseButton $0

nsDialogs::Show

FunctionEnd


Function OnCLick_Get_BrowseButton

#Show the file input dialog to the user so they can select an access database

nsDialogs::SelectFileDialog /NOUNLOAD open "$INSTDIR\*.accdb" "Access DB|*.accdb|All Files|*.*"
Pop $0

${If} $0 != ""
${if} $IsTraining == "false"
${NSD_SetText} $databaseSelected $0
${Else}
${NSD_SetText} $traningDatabaseSelected $0
${EndIf}
${EndIf}

;MessageBox MB_OK $0

${if} $IsTraining == "false"
StrCpy $databaseSelected $0
${Else}
StrCpy $traningDatabaseSelected $0
${EndIf}

;MessageBox MB_OK $databaseSelected


FunctionEnd



#####################################################################################
#
# This will verify that the input provided by the user meets the min requirements
# of need for the database type selected....
# has a file or sqlServer name have been supplyed, it is an access database(ends with .accdb)
#
#####################################################################################

Function checkForValidEntries

${If} $databaseType == "Access"


#odd how this silly function works - or it could just be me,
#but it doesn't really return a true location, just that the substring
#is in the search string, exists.

${StrLoc} $0 $databaseSelected ".accdb" ">"



${If} $databaseSelected != ""
${AndIF} $databaseSelected != "*.accdb"
${AndIf} $0 != ""
;MessageBox MB_OK $databaseSelected

${Else}
MessageBox MB_OK "No Access database provided"
Abort
${EndIf}


${Else}
#not sure why it needs to be done this way
#but this is the only way I can get the variables assigned with the proper values
Var /Global sn ;servername
Var /Global ds ;database

${NSD_GetText} $0 $sn
${NSD_GetText} $1 $ds

StrCpy $serverName $sn
StrCpy $databaseSelected $ds


${If} $databaseSelected != "DatabaseName"
${AndIF} $databaseSelected != ""

${if} $serverName != "ServerName"
${AndIF} $serverName != ""

${Else}
MessageBox MB_OK "No SQL serve name provided"
Abort
${EndIf}

${Else}
MessageBox MB_OK "No SQL database provided $databaseSelected"
Abort
${EndIf}

${EndIf}

FunctionEnd


#####################################################################################
#
# Retreive the database type that the user has. Access or SQL Server
#
#####################################################################################

Function getDatabaseTypeToUse
!insertmacro MUI_HEADER_TEXT "Please select the database type you are using." " "

nsDialogs::Create 1018
Pop $dialog

${NSD_CreateRadioButton} 0 0 40% 6% "Access Database"
Pop $hwnd
${NSD_AddStyle} $hwnd ${WS_GROUP}

${If} $databaseType == "Access"
${NSD_SetState} $hwnd ${BST_CHECKED}
${EndIF}

${NSD_OnClick} $hwnd AccessDatabaseSelected

${NSD_CreateRadioButton} 0 12% 40% 6% "SQL Server Database"
Pop $hwnd

${If} $databaseType == "SQLServer"
${NSD_SetState} $hwnd ${BST_CHECKED}
${EndIF}

${NSD_OnClick} $hwnd SQLServerDatabaseSelected

nsDialogs::Show

FunctionEnd

Function AccessDatabaseSelected
#set the database type selected
Pop $hwnd
StrCpy $databaseType "Access"
FunctionEnd

Function SQLServerDatabaseSelected
#set the database type selected
Pop $hwnd
StrCpy $databaseType "SQLServer"
FunctionEnd



#####################################################################################
#
#####################################################################################


Function installTrainingSideGroupFiles

SetOutPath "C:\NSISFiles"

;InstallDir "C:\NSISFiles"

FileOpen $0 "C:\NSISFiles\SideGroup.txt" r

;SQLSERVER
; -dbType sqlServer
; -s serverName
; -d databasename ;sqlserver no path

;Access
; -d path/databasename
; -t true ;training mode

StrCpy $parameters " -d $traningDatabaseSelected -t true"

loop:
FileRead $0 $1
IfErrors done ; end of file
${StrRep} $2 $1 " " "_" ; get rid of any spaces
StrCpy $3 "Startup_$2.bat" ; create the file name to use
${StrTrimNewLines} $4 $1 ; remove the newline from the end
StrCpy $6 '"$4"' ; quote the side group name

;open the new side group startup bat file for writting

CreateShortCut $DESKTOP\$2.lnk "C:\NSISFiles\$3" "" ${MUI_DESKTOP_ICON}

FileOpen $5 "C:\NSISFiles\$3" w


;write to the file
FileWrite $5 "set APP_PATH=$INSTDIR"
FileWrite $5 "$\r$\n"
FileWrite $5 "jre7\bin\java.exe -Xms512m -Xmx512m -classpath %APP_PATH%;%APP_PATH%/lib/jh.jar src/application.Main -g $6 $parameters"

FileClose $5
goto loop

done:
FileClose $0

FunctionEnd

Function installSideGroupFiles

SetOutPath "C:\Users\Mark.Strein\Desktop\NSISFiles"

;InstallDir "C:\Users\Mark.Strein\Desktop\NSISFiles"

FileOpen $0 "C:\Users\Mark.Strein\Desktop\NSISFiles\SideGroup.txt" r


;SQLSERVER
; -dbType sqlServer
; -s serverName
; -d databasename ;sqlserver no path

;Access
; -d path/databasename
; -t true ;training mode

${If} $databaseType == "Access"
StrCpy $parameters " -d $databaseSelected"
${Else}
StrCpy $parameters " -dbType sqlServer -s $serverName -d $databaseSelected"
${EndIF}

loop:
FileRead $0 $1
IfErrors done ; end of file
${StrRep} $2 $1 " " "_" ; get rid of any spaces
StrCpy $3 "Startup_$2.bat" ; create the file name to use
${StrTrimNewLines} $4 $1 ; remove the newline from the end
StrCpy $6 '"$4"' ; quote the side group name

;open the new side group startup bat file for writting

CreateShortCut $DESKTOP\$2.lnk "C:\Users\Mark.Strein\Desktop\NSISFiles\$3" "" ${MUI_DESKTOP_ICON}

FileOpen $5 "C:\Users\Mark.Strein\Desktop\NSISFiles\$3" w


;write to the file
FileWrite $5 "set APP_PATH=$INSTDIR"
FileWrite $5 "$\r$\n"
FileWrite $5 "jre7\bin\java.exe -Xms512m -Xmx512m -classpath %APP_PATH%;%APP_PATH%/lib/jh.jar src/application.Main -g $6 $parameters"

FileClose $5
goto loop

done:
FileClose $0

FunctionEnd



#####################################################################################
#
#####################################################################################

;--------------------------------
;This function checks if the user has permissions to write to the selected directory.

Function CheckDirectoryPermission

ClearErrors
SetOutPath $INSTDIR
FileOpen $R0 $INSTDIR\tmp.dat w
FileClose $R0
Delete $INSTDIR\tmp.dat

${If} ${Errors}
MessageBox MB_OK "You do not have permission to write to directory $INSTDIR. Please select another directory."
Abort
${EndIf}

FunctionEnd





;--------------------------------
;Uninstaller Section

Section "Uninstall"

;Database directory
RMDir /r $INSTDIR

;Remove start menu and desktop shortcuts
RMDir /r $SMPROGRAMS\App

;this works for other app, but for App it can have dynamic links built for each side
;need to figure out how to make that happen

Delete $DESKTOP\OtherApp-Full.lnk
Delete $DESKTOP\OtherApp-Functions.lnk
Delete $DESKTOP\OtherApp-Dependencies.lnk
Delete $DESKTOP\OtherApp-DM.lnk

SectionEnd

Please edit your post so the code is a file attachment. It is far too much code for a snippet. Your error is that you are trying to show the custom page from a section. You cannot do this. You can only call nsDialogs from a Page Custom show function. Therefore you must add a custom page after your components page and only show the page if your section is selected.

Stu