Archive: ConfigRead to remember radiobutton settings?


ConfigRead to remember radiobutton settings?
Can ConfigRead be used to remember a user's choices from several pages of radio buttons?

The goal is this:

An installer contains 12 custom pages, each with 3 to 5 radiobuttons or checkboxes. At present, each time the installer is run, the default selections for each page are ticked and these must be changed by the user every time. I would like the user's choices on each page to become the defaults the next time the installer is run.

Creating an extra file to hold the choices in the installation directory is fine, but I would like to avoid writing to the registry. Is ConfigRead what I want for this? How do I translate the values it reads into "states" for the radio button and checkbox pages?


ConfigRead and ConfigWrite are certainly two options. However, you could also just as well use ReadINIStr and WriteINIStr , reading from / writing to a .ini style file.

As for getting the values out to your actual dialogs - first things first.. do you use IntallOptions(2/Ex) or nsDialogs?

For the installOptions variety, write to the .ini file that specifies the custom page dialog, setting the State value of the appropriate radiobuttons/checkboxes based on what you read from the settings.

For nsDialogs, use the ${NSD_SetState} functionality.


Originally posted by Animaether
As for getting the values out to your actual dialogs - first things first.. do you use IntallOptions(2/Ex) or nsDialogs?
I'm using MUI with InstallOptions. I am using WriteIniStr in my custom pages like this:

WriteIniStr "$PLUGINSDIR\custom1b.ini" "field 2" "state" "0"


and then reading it back like this:

ReadINIStr $0 "$PLUGINSDIR\custom1b.ini" "field 2" "state"


but this only persists during single installation sessions. To make these choices persist between sessions, is the solution to use the same system as above, but instead of reading and writing to $PLUGINSDIR to write to a folder within the installation? Would replacing $PLUGINSDIR with something like $INSTDIR\cfg\ work?

yes, to both your questions, but I wouldn't really really use it in that fashion as the installation folder will then have the raw dialog settings.. I'd use parallel WriteIniStr's when saving a setting, and...
1. read from the installation folder ini once
2. read from the pluginsdir one after that.

so you would have something like...


WriteIniStr "$PLUGINSDIR\custom1b.ini" "field 2" "state" "0"
WriteIniStr "$INSTDIR\installsettings.ini" "main settings" "do something" "0"


and


${If} ${FileExists} "$PLUGINSDIR\custom1b.ini"
; if that file exists, we'll read from it
ReadINIStr $0 "$PLUGINSDIR\custom1b.ini" "main settings" "do something"
${Else}
; otherwise, we'll extract that file for future use
; do the MUI_INSTALLOPTIONS_EXTRACT bit here
; but we'll be reading from the file in the installation dir
; ( you'll want to make sure it exists, of course )
ReadINIStr $0 "$INSTDIR\installsettings.ini" "main settings" "do something"
${EndUnless}

off the top of my head - don't have NSIS here at the moment

Interesting! I will have to do some tests and try to figure this out. Thanks.


I have not been able to get this to work. Writing the ini file is very simple, but I don't understand how to read from it and then take action.

So, let me go through it step by step:

At the top of my file I begin with this (formatting lines removed for clarity):

Function .onInit
InitPluginsDir
WriteIniStr "$PLUGINSDIR\custom.ini" "settings" "numfields" "2"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 1" "state" "0"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 2" "state" "1"
FunctionEnd


Then in the page itself I have this:

section "Section 1" SEC01
ReadINIStr $0 "$PLUGINSDIR\custom.ini" "field 1" "state"
StrCmp $0 1 0 +4
[Commands to write a file are here]
WriteIniStr "$INSTDIR\cfg\installsettings.ini" "setting 1" "state" "1"
goto next
ReadINIStr $0 "$PLUGINSDIR\custom.ini" "field 2" "state"
StrCmp $0 1 0 +4
[Commands to write a file are here]
WriteIniStr "$INSTDIR\cfg\installsettings.ini" "setting 1" "state" "2"
next:
sectionend

function customcreate0
InstallOptions::Dialog "$PLUGINSDIR\custom.ini"
pop $0
functionend


Where do I perform the check on my installsettings.ini? Should it be within the Function .onInit?
Placing the comparison within the "Section 1" area would seem to force the installer to take the same action it took last time, which isn't the goal. I only want to show which of the two options was chosen before.

The comparison I am trying to use is this:

${If} ${FileExists} "$INSTDIR\cfg\installsettings.ini"
ReadINIStr $0 "$INSTDIR\cfg\installsettings.ini" "setting 1" "state"
StrCmp $0 1 0 +3
WriteIniStr "$PLUGINSDIR\custom.ini" "field 1" "state" "1"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 1" "state" "0"
${Else}
WriteIniStr "$PLUGINSDIR\custom.ini" "field 1" "state" "0"
${EndUnless}


I realise this comparison is in the opposite direction of the example suggested above, but doesn't it make more sense to make the PLUGINSDIR the default option and only change this if the installsettings.ini exists?

Any help would be greatly appreciated.

Your StrCmp is not correct. What if $0 is 1? Both your WriteINIStr statements will be executed. If $0 is not 1, neither will execute (+3 jumps over both).

Instead of using a StrCmp why not just use another nested If...Else...EndIf?

Stu


Originally posted by Afrow UK
Your StrCmp is not correct. What if $0 is 1? Both your WriteINIStr statements will be executed. If $0 is not 1, neither will execute (+3 jumps over both).

Instead of using a StrCmp why not just use another nested If...Else...EndIf?

Stu
Yes, that was all wrong. This, however, seems to work (4 radiobutton fields with field 2 checked as the default):

function customcreate0
${If} ${FileExists} "$INSTDIR\cfg\installsettings.ini"
ReadINIStr $0 "$INSTDIR\cfg\installsettings.ini" "setting 1" "state"
${If} $0 == "1"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 1" "state" "1"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 2" "state" "0"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 3" "state" "0"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 4" "state" "0"
${ElseIf} $0 == "3"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 1" "state" "0"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 2" "state" "0"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 3" "state" "1"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 4" "state" "0"
${ElseIf} $0 == "4"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 1" "state" "0"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 2" "state" "0"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 3" "state" "0"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 4" "state" "1"
${Else}
WriteIniStr "$PLUGINSDIR\custom.ini" "field 1" "state" "0"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 2" "state" "1"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 3" "state" "0"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 4" "state" "0"
${EndIf}
${Else}
WriteIniStr "$PLUGINSDIR\custom.ini" "field 1" "state" "0"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 2" "state" "1"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 3" "state" "0"
WriteIniStr "$PLUGINSDIR\custom.ini" "field 4" "state" "0"
${EndIf}
!insertmacro MUI_HEADER_TEXT $(INSTALL_PAGE_8) $(INSTALL_PAGE_8b)
InstallOptions::Dialog "$PLUGINSDIR\custom.ini"
pop $0
functionend


This reads from an ini file written by the installer as per my previous post. The missing piece was where to put the test that checks the previous settings, the answer being in the function that creates the page - not the section.