Archive: I am confused with reading ini value


I am confused with reading ini value
On my custom page has two checkboxes which are checked by default.
code Like these:

ReserveFile "ConfigurationPage.ini"
Page custom ShowConfigurationPage ValidateConfigurationPage
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS


Function .onInit
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "ConfigurationPage.ini"
!insertmacro MUI_INSTALLOPTIONS_WRITE 'ConfigurationPage.ini' 'Field 2' 'Text' "' Allow all user.'"
!insertmacro MUI_INSTALLOPTIONS_WRITE 'ConfigurationPage.ini' 'Field 3' 'Text' "' Automatically install upgrades'"
FuctionEnd


Function ShowConfigurationPage
strcpy $EnableFlag 1
!insertmacro MUI_HEADER_TEXT "$(PRODUCT_CONFIGURATION_TITLE)" "$(PRODUCT_CONFIGURATION_SUBTITLE)"
!insertmacro MUI_INSTALLOPTIONS_INITDIALOG "ConfigurationPage.ini"
!insertmacro MUI_INSTALLOPTIONS_SHOW
FunctionEnd

Function ValidateConfigurationPage
!insertmacro MUI_INSTALLOPTIONS_READ $ChooseOption "ConfigurationPage.ini" "Settings" "State"
${if} $ChooseOption == 2
; !insertmacro MUI_INSTALLOPTIONS_READ $op2 "ConfigurationPage.ini" "Field 2" "State"
ReadIniStr $op2 '$PLUGINSDIR\ConfigurationPage.ini' 'Field 2' 'State'
${if} $op2 == "0"
; !insertmacro MUI_INSTALLOPTIONS_WRITE 'ConfigurationPage.ini' 'Field 2' 'State' '0'
WriteIniStr '$PLUGINSDIR\ConfigurationPage.ini' 'Field 2' 'State' '1'
${else}
; !insertmacro MUI_INSTALLOPTIONS_WRITE 'ConfigurationPage.ini' 'Field 2' 'State' '1'
WriteIniStr '$PLUGINSDIR\ConfigurationPage.ini' 'Field 2' 'State' '0'
${endif}
abort
${elseif} $ChooseOption == 3
ReadIniStr $op3 '$PLUGINSDIR\ConfigurationPage.ini' 'Field 3' 'State'
;!insertmacro MUI_INSTALLOPTIONS_READ $op3 'ConfigurationPage.ini' 'Field 3' 'State'
${if} $op3 == "0"
; !insertmacro MUI_INSTALLOPTIONS_WRITE 'ConfigurationPage.ini' 'Field 3' 'State' '0'
WriteIniStr '$PLUGINSDIR\ConfigurationPage.ini' 'Field 3' 'State' '1'
MessageBox MB_OK|MB_ICONEXCLAMATION "If you disable this service, the performance of ${PRODUCT_NAME} will degrade, $\nand upgrades to the software will be disabled." /SD IDOK
${else}
;!insertmacro MUI_INSTALLOPTIONS_WRITE 'ConfigurationPage.ini' 'Field 3' 'State' '1'
WriteIniStr '$PLUGINSDIR\ConfigurationPage.ini' 'Field 3' 'State' '0'
${endif}
abort
${endif}
FunctionEnd

My ini file:
[Settings]
NumFields=4

[Field 1]
Type=GroupBox
Text=Settings
Left=1
Right=289
Top=25
Bottom=83

[Field 2]
Type=CheckBox
Left=10
Right=213
Top=44
Bottom=52
State=1
Flags=NOTIFY
Text=

[Field 3]
Type=CheckBox
Left=10
Right=204
Top=60
Bottom=68
State=1
Flags=NOTIFY
Text=


[Field 4]
Type=Label
Text=Note: It is highly recommended.
Left=0
Right=295
Top=3
Bottom=17


Questions:
1. since the the checkboxes are checked by default, how come the state I read on "page Leave" function (ValidateConfigurationPage) is always 0, it's supposed to be 1?????
2. !insertmacro MUI_INSTALLOPTIONS_WRITE and ReadInistr : they are equivalent???? or something different between them?
3. if user unchecked the checkbox, should I write the value back to ini file, I found I can read the value correctly no matter i write(didn't) value back to ini file, what's going on when write the ini file? it will write to the ini file under $PLUGINSDIR\myinifile.ini or something else?
4. is anything wrong with my code?

your answer is appreciated!


  1. I'm not sure I can answer your question specifically, but I can see one problem:
    In the page's leave function, you are setting the INI value different to the page's actual state. If you are going to change the INI file, you should also set the state of the control to match using a SendMessage command. (But, I'm not real sure that's what you want in this example. In looking at the logic in your code, I'm not real clear about what it is you are really trying to accomplish.)
  2. AFAIK, the 2 functions are the same, but for consistency, it's best to use one or the other. (I'd use the MUI functions just because it seems more appropriate.)
  3. you don't need to write anything; the InstallOptions.DLL takes care of that for you. All you need to do is read the value to find out what the user picked. (The only excpetion to this would be if you are trying to control one page control based on an event. See the example script ${NSISDIR}\Examples\InstallOptions\testnotify.nsi to see how this is done.)
  4. see my first comment.

thanks a lot. that's helpful.


MUI_INSTALLOPTIONS_READ/WRITE just prefix $PLUGINSDIR onto the INI file name to make it a full path whereas you must specify $PLUGINSDIR with Read/WriteINIStr.

Stu