- NSIS Discussion
- Function and section
Archive: Function and section
rxs2k5
14th February 2007 12:46 UTC
Function and section
Hi all pros,
I have a question.
example I have a function page
Function PageLeave
## Pop password & username from stack
Pop $R0
Pop $R1
## Get MD5 string for username
MD5DLL::GetMD5String $R0
Pop $R0
## Get MD5 string for password
MD5DLL::GetMD5String $R1
Pop $R1
## A bit of validation
StrCmp $R0 '${Username1MD5}' 0 +2
StrCmp $R1 '${Password1MD5}' Good Bad
StrCmp $R0 '${Username3MD5}' 0 +2
StrCmp $R1 '${Password3MD5}' Die Bad
Bad:
IntOp $R3 $R3 + 1
MessageBox MB_OK|MB_ICONEXCLAMATION "blah blah blah"
StrCmp $R3 2 +2
Abort
Quit
Good:
Goto Test
Die:
Goto Destroy
FunctionEnd
Here's how it goes
Die:
Goto Destroy
The Destroy is actually in another sections which means I have a main and a secondary.
In the main section, I have Test:
In the secondary section, I have Destory:
How can I make the Function to obey or recongise my label ?
Die:
Goto Destroy
Which will actually know that I have a secondary section, and have Destory: in it ??
I asking this because I got this error
Error: could not resolve label "Destroy" in function "passwordPageLeave"
Error - aborting creation process
Red Wine
14th February 2007 17:36 UTC
Generally you can't jump from a function to a section's label, but why you're making things such complicated, is there any particular reason?
I guess would be easier and accurate as well, if the destroy condition resides into the passwordPageLeave function.
rxs2k5
15th February 2007 00:53 UTC
I trying to make these because I was thinking is it possible, coz example I have an master access and client access rights in these password, it will work separate ways.
So what solution do u recommend for making such complicated access rights
Red Wine
15th February 2007 08:47 UTC
What I'm able to understand from your code is that label destroy pops up a message and terminates the installer.
You don't need to add it in a section while sections executed in order within InstFiles page.
You could make a separate function named destroy which performs specific actions and terminates the installer, that you may call when die condition is true, e.g.
Die:
Call Destroy
rxs2k5
15th February 2007 12:11 UTC
Hmm...
Just need to know more about Function, If you do not mind Redwine.
I been playing around with sections for some times but never got a chance to understand Function.
Maybe you have some little example of what can function can do or may do to allow a task like another installer to install sliently or maybe a priorty access rights...
Just anything you can think of a solution to my case because I dun quite understand Function , creating a new Page Custom Destroy so and so can help me fufill my task
Red Wine
15th February 2007 22:01 UTC
That it might need to be said more than the NSIS documentation, is that taking a tour to wiki where there are tons of examples, would help you understand everything much better than any possible example I could provide here.
http://nsis.sourceforge.net/Developer_Center
rxs2k5
16th February 2007 08:01 UTC
Hi Redwine,
I want to know more about this script u made during runtime
"Managing Sections on Runtime"
http://nsis.sourceforge.net/Managing...ons_on_Runtime
Is it possible to make function to change the sections?
example.
!include Sections.nsh
!include "myheader.nsh"
Function passwordPageLeave
1............ good bad
2............ die bad
bad:
.....
good:
Goto exit
die:
Call Destroy
exit:
FunctionEnd
Function Destroy
${UnSelectSection} ${SEC0000}
${SelectSection} ${SEC001}
FunctionEnd
Section main SEC0000
.........
........
........
SectionEnd
Section Destory SEC001
........
.......
.......
SectionEnd
This is the problem when I key in username and password for 1, it goes to
good then it jump directly into Function Destroy. I do not want it to jump to Function Destroy. Because it is for
die. When I key in username and password for 2, it work.
Do you know how can I good and die work separately and obey to activate the selected or unselected sections to use ?
Red Wine
16th February 2007 18:56 UTC
Provided that 1 and 2 comparisons both jump to the right label as expected, it is the section destroy which executed not the function destroy.
The section destroy is executed because it is selected by default, actually the function destroy when called removes the selection of section main.
You could solve it either by adding the code that section destroy contains into function destroy and remove the mentioned section from the script, or by making this section optional so could select it within the function destroy. e.g.
Section /o Destory SEC001
rxs2k5
17th February 2007 04:47 UTC
Hi Red Wine,
I followed ur instructions but its seems the same
when I input username and password on 1 in the previous Quoted script, it will run Section main , when I input username and password on 2, it didn't call Destroy even though the Function Destroy is being set, it runs Section main.
I think the Function Destroy
${UnSelectSection} ${SEC0000}
${SelectSection} ${SEC001}
is not even working....
by the way I changed the Section Destroy SEC001 to Section /o Destroy SEC001.
Plus I am getting this warnings
4 warnings:
unknown variable/constant "{SEC0000}" detected, ignoring (macro:SecUnSelect:3)
unknown variable/constant "{SEC0000}" detected, ignoring (macro:SecUnSelect:4)
unknown variable/constant "{SEC001}" detected, ignoring (macro:SecSelect:3)
unknown variable/constant "{SEC001}" detected, ignoring (macro:SecSelect:4)
I think its gotta do with the modified header that I had modified.
## HEADER PART BEGINS HERE
!define SF_USELECTED1 0
!define SF_SELECTED1 1
###############################
!macro SecSelect SecId
Push $0
IntOp $0 ${SF_SELECTED1} | ${SF_RO}
SectionSetFlags ${SecId} $0
SectionSetInstTypes ${SecId} 1
Pop $0
!macroend
!define SelectSection '!insertmacro SecSelect'
#################################
!macro SecUnSelect SecId
Push $0
IntOp $0 ${SF_USELECTED1} | ${SF_RO}
SectionSetFlags ${SecId} $0
SectionSetText ${SecId} ""
Pop $0
!macroend
!define UnSelectSection '!insertmacro SecUnSelect'
###################################
## HEADER PART ENDS HERE
one last thing do I have to include this
Function .onSelChange ???
Red Wine
17th February 2007 08:56 UTC
Not knowing what exactly you're trying to achieve is hard to help, but I don't think the header you're using could be helpful for your case.
I hope following example would offer some direction.
!define CUSTINI "$PLUGINSDIR\custom.ini"
!include Sections.nsh
outfile test.exe
InstallDir "$PROGRAMFILES\test"
ShowInstDetails show
Page Custom CreateCustom LeaveCustom
Page InstFIles
Section "main" sec1
MessageBox MB_OK "Simulating Case GOOD"
SetOutPath "$INSTDIR"
DetailPrint "Simulating Case GOOD"
SectionEnd
Section /o "destroy" sec2
MessageBox MB_OK "Simulating Case DESTROY"
SetOutPath "$INSTDIR"
DetailPrint "Simulating Case DESTROY"
SectionEnd
Function CreateCustom
push $0
InstallOptions::Dialog "${CUSTINI}"
pop $0
pop $0
FunctionEnd
Function LeaveCustom
ReadINIStr $0 "${CUSTINI}" "field 1" "state"
StrCmp $0 1 end
!insertmacro ReverseSection ${sec1}
!insertmacro ReverseSection ${sec2}
end:
FunctionEnd
Function .onInit
InitPluginsDir
WriteINIStr "${CUSTINI}" "Settings" "NumFields" "2"
WriteINIStr "${CUSTINI}" "field 1" "type" "radiobutton"
WriteINIStr "${CUSTINI}" "field 1" "text" "simulate case good"
WriteINIStr "${CUSTINI}" "field 1" "left" "10"
WriteINIStr "${CUSTINI}" "field 1" "right" "-10"
WriteINIStr "${CUSTINI}" "field 1" "top" "10"
WriteINIStr "${CUSTINI}" "field 1" "bottom" "22"
WriteINIStr "${CUSTINI}" "field 1" "state" "1"
WriteINIStr "${CUSTINI}" "field 1" "flags" "GROUP"
WriteINIStr "${CUSTINI}" "field 2" "type" "radiobutton"
WriteINIStr "${CUSTINI}" "field 2" "text" "simulate case destroy"
WriteINIStr "${CUSTINI}" "field 2" "left" "10"
WriteINIStr "${CUSTINI}" "field 2" "right" "-10"
WriteINIStr "${CUSTINI}" "field 2" "top" "26"
WriteINIStr "${CUSTINI}" "field 2" "bottom" "38"
WriteINIStr "${CUSTINI}" "field 2" "state" "0"
FunctionEnd
rxs2k5
17th February 2007 16:41 UTC
Hi Red Wine
You almost hit the solution I needed, I need a little more help.
Function LeaveCustom
ReadINIStr $0 "${CUSTINI}" "field 1" "state"
StrCmp $0 1 end
!insertmacro ReverseSection ${sec1}
!insertmacro ReverseSection ${sec2}
1.How can I make this implementation without using CUSTINI ?
Can you implement the above to select only 1 section in this code
Function passwordPageLeave
1............ good bad
2............ die bad
bad:
.....
good:
Goto exit
die:
[ insert an implementation in here, I only want Section Destroy to be selected and not Section Main ]
exit:
FunctionEnd
I know there's a way but its seems I cannot get the idea.
Red Wine
17th February 2007 22:21 UTC
I'm afraid I can't help it furthermore, sorry...