Reputation: 499
Just started using NSIS for my first installer. Found everything that i need apart from one thing only. I found how to write and create a txt file but couldn't find any info whether it is possible or not to allow the user to do some input (open a form in the installer) and then write the inserted data into a txt file.
Right now i'm able to write an input from an nsDialog, this is the code:
nsDialogs::Create 1018
Pop $Dialog
${NSD_CreateText} 10% 20u 80% 12u "Insert the API KEY"
Pop $Text
nsDialogs::Show
${NSD_GetText} $Text $0
MessageBox MB_OK "You typed:$\n$\n$0"
FileOpen $0 "$DESKTOP\Hello_world.txt" w
FileWrite $0 $Text
FileClose $0
However, the problem is that the data that is being written in the Hello_world.txt are some random digits, right now i'm not really understanding what are these numbers, shouldn't $Text be a String?
Upvotes: 1
Views: 496
Reputation: 101736
The dialog (and its child controls) only exists between nsDialogs::Create
and nsDialogs::Show
. You get random information because you are trying to read from something that no longer exists. Also, in your example $Text
is the edit control handle (HWND), not the text, your text would be in $0
in your case.
To finalize and display the dialog you must call
nsDialogs::Show
. This function will not return until the user clicks Next, Back or Cancel.
You should read user input in the leave callback of a page:
Page Custom MyPageCreate MyPageLeave
Page Directory
Page InstFiles
Var MyTextControlHandle
Function MyPageCreate
nsDialogs::Create 1018
Pop $0
${NSD_CreateText} 10% 20u 80% 12u "Insert the API KEY"
Pop $MyTextControlHandle
nsDialogs::Show
; $MyTextControlHandle is no longer valid here
FunctionEnd
Function MyPageLeave
${NSD_GetText} $MyTextControlHandle $0 ; Get text from $MyTextControlHandle and store in $0
MessageBox MB_OK "You typed:$\n$\n$0"
; Save $0 somewhere if desired
FunctionEnd
Upvotes: 2