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!