Archive: logib lib switch statement fails


logib lib switch statement fails
ok here is the code im using the $DBType is from a custom ini file using a listbox as the selector the field is correct and everything compiles ok but the switch case statement always picks the default no matter what the $DBType is set to?? dont understand why??

HELP PLEASE

;Get Database Type
!insertmacro MUI_INSTALLOPTIONS_READ $DBType "dbsettings" "Field4" "State"

${Switch} $DBType
${Case} "Oracle 10g Server"
;build for oracle DS xml file
ExecShell "open" "http://www.oracle.com/"
${Break}
${Case} "MySql Server"
;build for Mysql Server
ExecShell "open" "http://www.mysql.com/"
${Break}
${Case} "MS SQL Server 2005"
;build for MS SQLSERVER 2005 DS xml
ExecShell "open" "http://www.yahoo.com/"
${Break}
${Case} "MS SQL Server 2008"
;build for MS SQLSERVER 2008 ds xml
ExecShell "open" "http://www.microsoft.com/"
${Break}
${Default}
;build nothing just copy hypersonic ds xml default file
ExecShell "open" "http://www.riskdecisions.com/"
${Break}
${EndSwitch}


Remove those ${Break}'s. They're not needed.


Do not remove those breaks, Would not work properly if you do so.

Checkout your listbox, should be a typo or something because the following works fine for me.

Also checkout if it needs to ${TrimNewLines}.

outfile test.exe
showinstdetails show

!include logiclib.nsh

section
strcpy $R0 "ms sql server 2008"
${switch} $R0
${case} "oracle 10g server"
;build for oracle ds xml file
detailprint `"open" "http://www.oracle.com/"`
${break}
${case} "mysql server"
;build for mysql server
detailprint `"open" "http://www.mysql.com/"`
${break}
${case} "ms sql server 2005"
;build for ms sqlserver 2005 ds xml
detailprint `"open" "http://www.yahoo.com/"`
${break}
${case} "ms sql server 2008"
;build for ms sqlserver 2008 ds xml
detailprint `"open" "http://www.microsoft.com/"`
${break}
${default}
;build nothing just copy hypersonic ds xml default file
detailprint `"open" "http://www.riskdecisions.com/"`
${break}
${endswitch}
sectionend

ok here is the whole thing
thank for the reply
see below

Function .onInit
!insertmacro MUI_INSTALLOPTIONS_EXTRACT_AS "dbsettings.ini" "dbsettings"
FunctionEnd

;Function to get user data from custom page.
Function dbsettings
;Display the page.
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "dbsettings"

;Get the user entered values put then in variables.
!insertmacro MUI_INSTALLOPTIONS_READ $Address "dbsettings" "Field 1" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $Username "dbsettings" "Field 2" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $Password "dbsettings" "Field 3" "State"
!insertmacro MUI_INSTALLOPTIONS_READ $dbType "dbsettings" "Field 4" "State"

ExecShell "open" $dbType
${Switch} $dbType
${Case} "Oracle 10g Server"
;build for oracle DS xml file
ExecShell "open" "http://www.oracle.com/"
${Break}
${Case} "MySql Server"
;build for Mysql Server
ExecShell "open" "http://www.mysql.com/"
${Break}
${Case} "MS SQL Server 2005"
;build for MS SQLSERVER 2005 DS xml
ExecShell "open" "http://www.yahoo.com/"
${Break}
${Case} "MS SQL Server 2008"
;build for MS SQLSERVER 2008 ds xml
ExecShell "open" "http://www.microsoft.com/"
${Break}
${Default}
;build nothing just copy hypersonic ds xml default file
ExecShell "open" "http://www.riskdecisions.com/"
${Break}
${EndSwitch}
FunctionEnd

I have checked the .ini file and i can see no typo error at all. It seems like $dbType never gets assigned what ever is in the field ref of the ini file. Can you explain what TrimNewlines does, does the install_option_read function only return a string or is there something else added with it. I find it very difficult to see what the variables actually contain.

regards


Small mistake: you used ${Switch} instead of ${Select}. According to the logiclib.nsh docs (at the top of the file):

;       Select..{Case[2|3|4|5]}..[CaseElse|Default]..EndSelect
; - Executes one of several blocks of statements, depending on the value
; of an expression.
; Switch..{Case|CaseElse|Default}..EndSwitch
; - Jumps to one of several labels, depending on the value of an
; expression.

And the ${Break} is to exit a For, Do, or While loop. It isn't used in a Switch or Select statement.

That is not true. In a Switch statement it is necessary to prevent fall-through execution of proceeding cases:

${Switch} $R0
${Case} 0
MessageBox MB_OK `$R0 is 0!`
${Case} 1
MessageBox MB_OK `$R0 is 0 or 1!`
${EndSwitch}
Without a ${Break} after the first MessageBox, both will be displayed if $R0 is 0.

${Select} is the selection statement which does not require ${Break} (IIRC it is like VB).

Stu


i think there is a bit of confusion here as the logiclib has two versions one with switch and one with select, am i correct in using the switch statement with breaks as per the user documentation for logic lib.
Course i probably wrong about this.

Anyway....

is this happening because the switch is happening inside the page function and not when the page returns.

regards
bazza (has a headache)


Yes you are right to use Break (read my post above). Also yes you can't read from the INI file in the page's show function because the new user input isn't saved to the INI file until the leave function is called.

Stu


Hi Stu
Thought it was a code positioning fault, anyway i have put the switch statement into the .onInstSuccess function, is this the correct one to use, dont know how to set it any other way. Have also tried putting it into another custom page called dbsettingsleave that is called straight after the dbsettings page.

Both methods above result in the same webpage openening. I use the open webpage url to determine what the variable contains, i also tried writing it to a file and got nothing.

here is the ini file itself
; Ini file generated by the HM NIS Edit IO designer.
[Settings]
;InstallOptions Editor Metadata (DO NOT EDIT): guides=8|10#8|30#8|50#8|70#1|169#1|100
NumFields=8
Title="Database Connection Settings "

[Field 1]
;InstallOptions Editor Metadata (DO NOT EDIT): guides=1|0|-1
Type=Text
State=
Left=169
Right=292
Top=10
Bottom=23

[Field 2]
;InstallOptions Editor Metadata (DO NOT EDIT): guides=8|1|-1#1|0|-1
Type=Text
State=
Left=169
Right=292
Top=30
Bottom=43

[Field 3]
;InstallOptions Editor Metadata (DO NOT EDIT): guides=8|2|-1#1|0|-1
Type=Password
Left=169
Right=292
Top=50
Bottom=61

[Field 4]
;InstallOptions Editor Metadata (DO NOT EDIT): guides=8|3|-1#1|0|-1
Type=DropList
ListItems=Hypersonic|MS SQL 2005|MS SQL 2008|Oracle 10g|My SQL 5.0
Left=169
Right=292
Top=70
Bottom=163
State=Hypersonic

[Field 5]
;InstallOptions Editor Metadata (DO NOT EDIT): guides=8|0|-1#1|0|1
Type=Label
Text=Server Name / IP
Left=100
Right=169
Top=10
Bottom=23

[Field 6]
;InstallOptions Editor Metadata (DO NOT EDIT): guides=8|1|-1#1|0|1
Type=Label
Text=User Name
Left=100
Right=169
Top=30
Bottom=40

[Field 7]
;InstallOptions Editor Metadata (DO NOT EDIT): guides=8|2|-1#1|0|1
Type=Label
Text=User Password
Left=100
Right=169
Top=50
Bottom=61

[Field 8]
;InstallOptions Editor Metadata (DO NOT EDIT): guides=8|3|-1#1|1|-1
Type=Label
Text=Database Type
Left=100
Right=170
Top=70
Bottom=80

i just dont understand whats going on here?

regards


Attach your script. Custom page leave functions are set with Page:

Page Custom ShowFunction LeaveFunction

Also check the INI file at run time. It will be under a ns###.tmp folder in %TEMP%.

Stu


hi stu
here is the script part

Function .onInit
!insertmacro MUI_INSTALLOPTIONS_EXTRACT_AS "sdbselect.ini" "dbsettings"
FunctionEnd

Function dbsettings
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "dbsettings"

;Get Database Server ID
!insertmacro MUI_INSTALLOPTIONS_READ $ServerID "dbsettings" "Field1" "State"
;Get Database User ID
!insertmacro MUI_INSTALLOPTIONS_READ $UserID "dbsettings" "Field2" "State"
;Get Database User Password
!insertmacro MUI_INSTALLOPTIONS_READ $UserPass "dbsettings" "Field3" "State"
;Get Database Type
!insertmacro MUI_INSTALLOPTIONS_READ $DBType "dbsettings" "Field4" "State"
FunctionEnd

Function dbsettingsleave
${Switch} $DBType
${Case} "Oracle 10g Server"
;build for oracle DS xml file
ExecShell "open" "http://www.oracle.com/"
${Break}
${Case} "MySql Server"
;build for Mysql Server
ExecShell "open" "http://www.mysql.com/"
${Break}
${Case} "MS SQL Server 2005"
;build for MS SQLSERVER 2005 DS xml
ExecShell "open" "http://www.yahoo.com/"
${Break}
${Case} "MS SQL Server 2008"
;build for MS SQLSERVER 2008 ds xml
ExecShell "open" "http://www.microsoft.com/"
${Break}
${Default}
;build nothing just copy hypersonic ds xml default file
ExecShell "open" "http://www.riskdecisions.com/"
${Break}
${EndSwitch}
FunctionEnd

its called by this

page custom dbsettings dbsettingsleave

any ideas ?


yes the tmp stuff creates a directory NS###.tmp so that part works

dont know why the variable doesnt get assigned the value selected though.

regards


have checked the tmp ini file the installer created and the settings i chose where written to it correctly with all the HWND id as per below


[Field 1]
Type=Text
Left=114
Right=238
Top=33
Bottom=46
State="server"
HWND=1049724

[Field 2]
Type=Text
Left=114
Right=238
Top=52
Bottom=65
State="washere"
HWND=853042

[Field 3]
Type=Password
Left=114
Right=238
Top=72
Bottom=84
State="fuckinghell"
HWND=787540

[Field 4]
Type=Listbox
ListItems=Built in Database Server|Oracle 10g Server|MySql Server|MS SQL Server 2005|MS SQL Server 2008
Left=114
Right=238
Top=92
Bottom=184
State=MS SQL Server 2005
HWND=722120

so the custom script seems to be doing that ok its just when questying the value it dont work

baz


The 'leave' function gets called before the program comes back from the 'display' macro. You are setting $DBType and the other variables after you return from the display macro, so they are not yet set when you run through the 'leave' function.

Try moving the macros that read the variables into the top of the 'leave' function.


So you think i have to only have the dbsettings function to show the page then the leave function should have the MUI_INSTALL_OPTIONS_READ functions in there.

regards
bazza


Thanks guys but i have tried that as well and the dbtype variable never changes as i always get the Default website everytime.

regards.
baz


Could you try debug your script with message boxes?
After each "read" add a message box to checkout if everything goes right so far.


Its not the ligic lib switch statement that isnt working, the values entered into to custom ini file page are never retrieved from the ini file even though they exist at runtime. hope someone can help me
;----------------------------------------
;Include the Modern UI & MUI2 interface
!include "InstallOptions.nsh"
!include "MUI.nsh"
!include "MUI2.nsh"
!include "LogicLib.nsh"
;----------------------------------------
;General Stuff
;Name and File
Name "Predict! Version 4"
OutFile "SetupPR4.exe"
XPStyle on
AllowRootDirInstall true
;Default Installation folder
InstallDir "c:\pr4"
;Global Variables
Var ServerID
Var UserID
Var UserPass
Var DBType
;-----------------------------------------
;Load the custom page for database selection and assign page name.
Function .onInit
!insertmacro INSTALLOPTIONS_EXTRACT "sdbselect.ini"
FunctionEnd
Function dbsettings
!insertmacro INSTALLOPTIONS_DISPLAY "sdbselect.ini"
FunctionEnd
Function dbsettingsleave
;Get Database Server ID
!insertmacro INSTALLOPTIONS_READ $ServerID "sdbselect.ini" "Field1" "State"
MessageBox MB_OK $ServerID
;Get Database User ID
!insertmacro INSTALLOPTIONS_READ $UserID "sdbselect.ini" "Field2" "State"
MessageBox MB_OK $UserID
;Get Database User Password
!insertmacro INSTALLOPTIONS_READ $UserPass "sdbselect.ini" "Field3" "State"
MessageBox MB_OK $UserPass
;Get Database Type
!insertmacro INSTALLOPTIONS_READ $DBType "sdbselect.ini" "Field4" "State"
MessageBox MB_OK $DBType
${Switch} $DBType
${Case} "Oracle 10g Server"
;build for oracle DS xml file
MessageBox MB_OK $DBType
ExecShell "open" "http://www.oracle.com/"
${Break}
${Case} "MySql Server"
;build for Mysql Server
MessageBox MB_OK $DBType
ExecShell "open" "http://www.mysql.com/"
${Break}
${Case} "MS SQL Server 2005"
;build for MS SQLSERVER 2005 DS xml
MessageBox MB_OK $DBType
ExecShell "open" "http://www.yahoo.com/"
${Break}
${Case} "MS SQL Server 2008"
;build for MS SQLSERVER 2008 ds xml
MessageBox MB_OK $DBType
ExecShell "open" "http://www.microsoft.com/"
${Break}
${Default}
;build nothing just copy hypersonic ds xml default file
MessageBox MB_OK $DBType
ExecShell "open" "http://www.riskdecisions.com/"
${Break}
${EndSwitch}
FunctionEnd
;-----------------------------------------
;Interface Settings
!define MUI_ABORTWARNING
; MUI Settings / Icons
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\orange-install-nsis.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\orange-uninstall-nsis.ico"
; MUI Settings / Header
!define MUI_HEADERIMAGE
!define MUI_HEADERIMAGE_RIGHT
!define MUI_HEADERIMAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Header\orange-r-nsis.bmp"
!define MUI_HEADERIMAGE_UNBITMAP "${NSISDIR}\Contrib\Graphics\Header\orange-uninstall-r-nsis.bmp"
; MUI Settings / Wizard
!define MUI_WELCOMEFINISHPAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Wizard\orange-nsis.bmp"
!define MUI_UNWELCOMEFINISHPAGE_BITMAP "${NSISDIR}\Contrib\Graphics\Wizard\orange-uninstall-nsis.bmp"
;-----------------------------------------
;Pages that the installer uses
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "SoftwareLicense.txt"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
page custom dbsettings dbsettingsleave
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
;-------------------------------------------
;Languages
!insertmacro MUI_LANGUAGE "English"
;--------------------------------------------
;Installer Sections
Section "Java Install" SecJava
ExecWait "$EXEDIR\jdk-1_5_0_12-windows-i586-p.exe /S"
ReadRegStr $0 HKLM "SOFTWARE\JavaSoft\Java Development Kit\1.5" "JavaHome"
WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "JAVA_HOME" $0
SetOutPath "$INSTDIR"
SectionEnd
Section "Predict! Risk Controller" SecPRC
SetOutPath "$INSTDIR"
ReadRegDWORD $R0 HKLM "HARDWARE\DESCRIPTION\System\CentralProcessor\0" "~Mhz"
IntCmp $R0 1000 eq less more
eq:
Goto done
more:
Goto done
less:
Abort "System does not meet min. requirements, processor speed less than 1 Ghz."
done:
ClearErrors
ReadRegStr $R1 HKLM "SOFTWARE\Microsoft\Windows NT\CurrentVersion" "CurrentVersion"
StrCpy $R2 $R1 1
!if $R2 == 4
Abort "System does not meet minimum requirements, Operating System not supported."
!endif
IfErrors 0 +2
Abort "System does not meet minimum requirements, Operating System not supported."
ClearErrors
ReadRegStr $0 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "JAVA_HOME"
IfErrors 0 +2
Abort "Java not installed or JAVA_HOME environment variable not set."
CreateDirectory $INSTDIR\jboss-4.0.5.GA
CopyFiles /SILENT $EXEDIR\jboss-4.0.5.GA\*.* $INSTDIR\jboss-4.0.5.GA 189000
WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "JBOSS_HOME" "$INSTDIR\jboss-4.0.5.GA"
WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "JBOSS_PORT" "80"
WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "JBOSS_HOST" "localhost"
ReadRegStr $1 HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "JBOSS_HOME"
CopyFiles /SILENT $EXEDIR\login-config.xml $1\server\default\conf 10
CopyFiles /SILENT $EXEDIR\javaservice\*.* $1\bin 700
/*RMDir /r $1\server\default\data\hypersonic*/
CopyFiles /SILENT $EXEDIR\prc4.ear $1\server\default\deploy 48000
ExecWait '"$1\bin\JBossService.exe" -install JBoss "$0\jre\bin\client\jvm.dll" -Djava.class.path="$1\bin\run.jar;$0\lib\tools.jar" -Xms400M -Xmx512M -XX:MaxPermSize=80M -start org.jboss.Main -stop org.jboss.Main -method systemExit -out "$1\bin\out.log" -err "$1\bin\err.log" -current "$1\bin" -auto -overwrite -startup 6'
ExecWait "net start Jboss"
DetailPrint "waiting for service..."
Sleep 20000
CreateDirectory "$SMPROGRAMS\Predict! Risk Controller 4"
CopyFiles /SILENT $EXEDIR\PRC4.url "$SMPROGRAMS\Predict! Risk Controller 4" 1
/*CreateDirectory $INSTDIR\dbprep
CopyFiles /SILENT $EXEDIR\dbprep\*.* $INSTDIR\dbprep 22000
SetOutPath $INSTDIR\dbprep
ExecWait "$OUTDIR\dbprep.exe"*/
WriteUninstaller $INSTDIR\uninstallPRC4.exe
CreateShortCut "$SMPROGRAMS\Predict! Risk Controller 4\UninstallPRC4.lnk" "$INSTDIR\uninstallPRC4.exe" "" "$INSTDIR\uninstallPRC4.exe" 0
SectionEnd
Section "Predict! Risk Analyser" SecPRA
SetOutPath "$INSTDIR"
ClearErrors
ReadRegStr $0 HKLM "SOFTWARE\JavaSoft\Java Development Kit\1.5" "JavaHome"
IfErrors 0 +2
Abort "Java 1.5 not installed, quiting installation."
CreateDirectory $INSTDIR\pra4
CopyFiles /SILENT $EXEDIR\pra4\*.* $INSTDIR\PRA4 16000
CreateDirectory "$SMPROGRAMS\Predict! Risk Analyser 4"
SetOutPath $INSTDIR\pra4
CreateShortCut "$SMPROGRAMS\Predict! Risk Analyser 4\PRA4.lnk" "$INSTDIR\pra4\PRA4.exe" "" "$INSTDIR\pra4\PRA4.exe" 0 SW_SHOWMAXIMIZED
SectionEnd
;---------------------------------------------
;Descriptions of Sections
;Language strings
LangString DESC_SecJava ${LANG_ENGLISH} "Java JDK 1.5 is a requirement of Predict! If you already have java ensure that you deselect this item."
LangString DESC_SecPRC ${LANG_ENGLISH} "Risk Controller."
LangString DESC_SecPRA ${LANG_ENGLISH} "Risk Analyser."
;Assign language strings to sections
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SecJava} $(DESC_SecJava)
!insertmacro MUI_DESCRIPTION_TEXT ${SecPRC} $(DESC_SecPRC)
!insertmacro MUI_DESCRIPTION_TEXT ${SecPRA} $(DESC_SecPRA)
!insertmacro MUI_FUNCTION_DESCRIPTION_END
;-------------------------------------------------
;Uninstaller Section
Section "Uninstall"
ExecWait "net stop Jboss"
DeleteRegValue HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "JBOSS_HOME"
DeleteRegValue HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "JBOSS_PORT"
DeleteRegValue HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "JBOSS_HOST"
DeleteRegKey HKLM "SYSTEM\CurrentControlSet\Services\Jboss"
RMDir /r "$SMPROGRAMS\Predict! Risk Controller 4"
RMDir /r "$SMPROGRAMS\Predict! Risk Analyser 4"
RMDir /r $INSTDIR
Delete "$INSTDIR\Uninstall.exe"
RMDir "$INSTDIR"
SectionEnd


I guess you must use either MUI or MUI2, no both.


You are trying to read from "Field1" etc when it is "Field 1" etc.

Stu


Doh.........
thanks stu

yes i am a dumb ass


regards baz