- NSIS Discussion
- Setting Custom Page Text Box State
Archive: Setting Custom Page Text Box State
shock_flights
18th November 2005 20:13 UTC
Setting Custom Page Text Box State
I created a custom page that asks the user for some input that will be written to an ini file, however I want to prepopulate that text box with any existing text if that ini file already exists and has somehting in it. So I'm doing a ReadINIStr to get the value (and that works fine - proven using MessageBox), but I can't place that value into the Text Box on the custom form in my installer. I tried WriteINIStr and MUI_INSTALLOPTIONS_WRITE, but no matter where I put it, I can't get my read text to appear in the custom form when I get there. I tried putting my code in the .onInit function, as well as at the top of the custom page function, but to no avail. Any ideas?
shock_flights
18th November 2005 22:19 UTC
Here is more background:
In my custom page (ClientInfo.ini below) I have multiple fields. The one in question is "Field 2". I am trying to read an existing ini file and then right after that writing it to the custom page ini file (or somehow stuffing it into the text box). Here is what I tried:
ReadINIStr $ProcessKey "$PROGRAMFILES\CompanyName\MyProg\MyProg.ini" "ID Keys" "Process Key"
WriteINIStr "ClientInfo.ini" "Field 2" "State" $ProcessKey
I also tried this (after reading using ReadINIStr):
;!insertmacro MUI_INSTALLOPTIONS_WRITE "ClientInfo.ini" "Field 2" "State" $ProcessKey
dandaman32
18th November 2005 22:39 UTC
Originally posted by shock_flights
ReadINIStr $ProcessKey "$PROGRAMFILES\CompanyName\MyProg\MyProg.ini" "ID Keys" "Process Key"
WriteINIStr "ClientInfo.ini" "Field 2" "State" $ProcessKey
Did you extract the file?
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "ClientInfo.ini"
Also, your mistake:
WriteINIStr "ClientInfo.ini" "Field 2" "State" $ProcessKey
>
should be:
WriteINIStr "$PLUGINSDIR\ClientInfo.ini" "Field 2" "State" $ProcessKey
>
-dandaman32
shock_flights
18th November 2005 22:44 UTC
Yes, I did the extraction. (My custom pages have been working. I'm just adding thsi new functionality now.) I even tried moving the write to before, after and in the .onInit functions.
I don't think your second comment is correct. It's not really a plug-in, but just a custom page. Also, I checked to make sure it can find the ClientInfo.ini file by using IfFileExists.
Any other ideas?
bhaelochon
18th November 2005 23:53 UTC
Make sure you extract the file in .onInit:
Function .onInit
!insertmacro MUI_INSTALLOPTIONS_EXTRACT "ClientInfo.ini"
FunctionEnd
Then, in your page init function:
Function InitClientInfo
!insertmacro MUI_HEADER_TEXT "Title" "Subtitle"
; init the dialog, but don't show it
!insertmacro MUI_INSTALLOPTIONS_INITDIALOG "ClientInfo.ini"
Pop $HWND ;HWND of dialog
; read the value that we want to put on our dialog
ReadINIStr $ProcessKey "$PROGRAMFILES\CompanyName\MyProg\MyProg.ini" "ID Keys" "Process Key"
; put the value on our dialog
!insertmacro MUI_INSTALLOPTIONS_WRITE "ClientInfo.ini" "Field 2" "State" $ProcessKey
; show the dialog, now that we've set the text
!insertmacro MUI_INSTALLOPTIONS_SHOW
FunctionEnd
And regarding the $PLUGINSDIR thing: What Dan is trying to say is if you're using MUI to extract the file, then you should specify $PLUGINSDIR when using WriteINIStr as opposed to MUI_INSTALLOPTIONS_WRITE--because that's where MUI puts the file. ;-)
shock_flights
19th November 2005 01:26 UTC
Thanks for the reply. I'll have to research some of those options. I tried it, but it's still not doing anything. Where am I supposed to be calling this new function (InitClientInfo) from? I cut out the code and stuck it in my ClientPage function as follows:
Page custom ClientPage
Is that correct? Is the InitClientPage a special 'init' function?
Afrow UK
19th November 2005 10:25 UTC
Page Custom InitClientPage
-Stu
bhaelochon
21st November 2005 16:53 UTC
shock_flights, you were correct to place the code from my InitClientInfo function into your ClientPage function. Sorry I wasn't more clear about that. :)
If you're still having problems, please upload your .nsi file so that we may troubleshoot it by trying to compile it ourselves. :)
shock_flights
21st November 2005 20:06 UTC
Test Script Files Attached
Still can't get it working. Attached is a test-script that shows what I'm doing (I cut out much, but not all, of the unnessary stuff.) To test it you might need to change some file paths, or fake some files.
Let me know if you get anywhere. Thanks.
bhaelochon
22nd November 2005 15:24 UTC
Okay. I misspoke before. I guess that's what I get for copy/pasting. :( Below is a modified version of the ClientPage function from your test .nsi file. The screen displays with "1137" in the Process Key box. Is that correct?
Function ClientPage
!insertmacro MUI_HEADER_TEXT \
"Client Specific Configuration" \
"Please enter the custom ids and setup information \
associated with this AcuFlash installation."
; init the dialog, but don't show it
; !insertmacro MUI_INSTALLOPTIONS_INITDIALOG "ClientInfo.ini"
; Pop $Hwnd
; StrCpy $IniFilePath "$PROGRAMFILES\AcuFlash\AcuFlash.ini"
StrCpy $IniFilePath "E:\_NSIS Scripts\test\AcuFlash.ini"
; read the value that we want to put on our dialog
ReadINIStr $ProcessKey $IniFilePath "ID Keys" "Process Key"
; put the value on our dialog
!insertmacro MUI_INSTALLOPTIONS_WRITE "ClientInfo.ini" "Field 2" "State" $ProcessKey
;MessageBox MB_OK "Process=$ProcessKey"
!insertmacro MUI_INSTALLOPTIONS_DISPLAY "ClientInfo.ini"
; show the dialog, now that we've set the text
; !insertmacro MUI_INSTALLOPTIONS_INITDIALOG "ClientInfo.ini"
; Pop $Hwnd
; !insertmacro MUI_INSTALLOPTIONS_SHOW
FunctionEnd
shock_flights
23rd November 2005 18:31 UTC
Hey, that did it. I guess I was close, but the key was the MUI_INSTALLOPTIONS_DISPLAY call? Thanks for taking the time to help out. I really appreciate it. Take care.