The Glimmerman
21st July 2006 10:56 UTC
Variables and userinput (Arrays)
:igor: noob warning :D
Hi there.
I'm a little bit confused here. :)
I have a custompage with +/- 15 userinput boxes and checkboxes. After filling in the info and clicking next the info must be checked and executed. (username,computername, password etc etc) I now have a lot of
ReadINIStr $var1
ReadINIStr $var2
ReadINIStr $var3
and a lot of functions when de variables are declared. I've read something about arrays (NSISArray.dll). But i try to understand (the logica)how it works. Is it even possible to get all the userinput (state) in on array and how to implement it with the variables and functions.
I hope someone will and can explain me how it works
Thanks in advance
CancerFace
21st July 2006 12:12 UTC
Create an array (using the Array Plugin) then read each value from your INI file to the NSIS stack and feed the value to the array, for example using a macro:
!macro ReadINIValues ARRAY NUMBER_OF_VALUES
!define Index "Line${__LINE__}"
NSISArray::New /NOUNLOAD ${ARRAY} ${NUMBER_OF_VALUES} 2
StrCpy $0 1
StrCpy $9 ${NUMBER_OF_VALUES}
IntOp $9 $9 + 1
${Index}_Start:
StrCmp $0 $9 ${Index}_End
ReadINIStr $1 "<your_ini_file>" "<your_section>" "<your_field_$0>"
NSISArray::Write /NOUNLOAD ${ARRAY} $0 "$1"
IntOp $0 $0 + 1
Goto ${Index}_Start
${Index}_End:
NSISArray::FreeUnusedMem /NOUNLOAD
!undef Index
!macroEnd
Call the macro using for example
!insertmacro ReadINIValues UserValues 10
in order to feed values to the array.
To read values from the array, use their index number. For example
NSISArray::Read /NOUNLOAD UserValues 5
Pop $0
will read the 5th value from the array and place it in $0. You can then use the value in any of your other functions/sections.
Don't forget to delete the array object when you're done:
NSISArray:: Delete /NOUNLOAD UserValues
Hope this helps
CF
The Glimmerman
21st July 2006 14:38 UTC
Thanx CF
I hope you or someone else can help me with one thing.
I got this
ReadINIStr $1 "test.ini" "State" "Field $0"
and then this to test
!insertmacro ReadINIValues UserValues 10
NSISArray::Debug /NOUNLOAD UserValues
NSISArray::Read /NOUNLOAD UserValues 1
Pop $0
MessageBox MB_OK "$0"
NSISArray::Read /NOUNLOAD UserValues 2
Pop $1
MessageBox MB_OK "$1"
The last code is in a function (leave)
But there is nothing in the array.
CancerFace
21st July 2006 14:45 UTC
Your ReadINIStr syntax is wrong. Should be
ReadINIStr $1 "test.ini" "Field $0" "State"
CF
The Glimmerman
21st July 2006 16:26 UTC
:o
Last time I hope.
What am I doing wrong
!include "LogicLib.nsh"
!include "MUI.nsh"
OutFile "Test.exe"
Var FieldName
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
!macro ReadINIValues ARRAY NUMBER_OF_VALUES
!define Index "Line${__LINE__}"
NSISArray::New /NOUNLOAD ${ARRAY} ${NUMBER_OF_VALUES} 2
StrCpy $0 1
StrCpy $9 ${NUMBER_OF_VALUES}
IntOp $9 $9 + 1
${Index}_Start:
StrCmp $0 $9 ${Index}_End
ReadINIStr $1 "$PLUGINSDIR\test.ini" "Field $0" "State"
NSISArray::Write /NOUNLOAD ${ARRAY} $0 "$1"
; MessageBox MB_OK "$1"
IntOp $0 $0 + 1
Goto ${Index}_Start
${Index}_End:
NSISArray::FreeUnusedMem /NOUNLOAD
!undef Index
!macroEnd
Page custom GetSettings SetSettings
Function .onInit
InitPluginsDir
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "test.ini"
FunctionEnd
Section "-hidden section"
SectionEnd
Function GetSettings
InstallOptionsEx::initDialog /NOUNLOAD "$PLUGINSDIR\test.ini"
InstallOptionsEx::Show
FunctionEnd
Function SetSettings
!insertmacro ReadINIValues UserValues 5
NSISArray::Read /NOUNLOAD UserValues 3
Pop $0
Strcpy $FieldName $0
MessageBox MB_OK "$FieldName or $0"
FunctionEnd
I attached the files
CancerFace
21st July 2006 18:30 UTC
Actually, my bad: We feed data to the array starting at Index 1 but we should start at Index 0. This should work:
!include "LogicLib.nsh"
!include "MUI.nsh"
OutFile "Test.exe"
Var FieldName
!insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS
!macro ReadINIValues ARRAY NUMBER_OF_VALUES
!define Index "Line${__LINE__}"
NSISArray::New /NOUNLOAD "${ARRAY}" ${NUMBER_OF_VALUES} 2
StrCpy $0 1
StrCpy $2 0
StrCpy $9 ${NUMBER_OF_VALUES}
IntOp $9 $9 + 1
${Index}_Start:
StrCmp $0 $9 ${Index}_End
ReadINIStr $1 "$PLUGINSDIR\test.ini" "Field $0" "State"
NSISArray::Write /NOUNLOAD ${ARRAY} $2 "$1"
IntOp $0 $0 + 1
IntOp $2 $2 + 1
Goto ${Index}_Start
${Index}_End:
NSISArray::FreeUnusedMem /NOUNLOAD
!undef Index
!macroend
Page custom GetSettings SetSettings
Function .onInit
InitPluginsDir
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "test.ini"
FunctionEnd
Section "-hidden section"
SectionEnd
Function GetSettings
InstallOptionsEx::initDialog /NOUNLOAD "$PLUGINSDIR\test.ini"
InstallOptionsEx::Show
FunctionEnd
Function SetSettings
!insertmacro ReadINIValues "UserValues" "5"
NSISArray::Read /NOUNLOAD UserValues 3
Pop $0
Strcpy $FieldName $0
MessageBox MB_OK "$FieldName or $0"
FunctionEnd
CF
The Glimmerman
21st July 2006 19:31 UTC
:up:
It worked. Thx CF.
I'm gonna implement this in my script.