Archive: File Request Return Value in nsdialogs


File Request Return Value in nsdialogs
I'm using a custom dialog with nsdialogs to get the user to select a file. Im using a file request text box with a browse button for this. Im also using a variable to hold and remember the state of the text box with the user selects a file using the browse button. My problem occurs when the user cancels browsing for the file instead of selecting it. In this case it's supposed to return a blank value "". But instead it returns a random number sometimes. Here are the relevant parts of the script ...


Function InstallSelect
nsDialogs::Create /NOUNLOAD 1018
Pop $PathForInstallDialog

${If} $PathForInstallDialog == error
MessageBox MB_ICONSTOP|MB_OK "Error drawing dialog. Please try Setup again." /SD IDOK
Quit
${EndIf}

; Create Controls
${NSD_CreateGroupBox} 0 0 100% 100% ""
Pop $PathForInstallGroupBox

${NSD_CreateLabel} 10u 17u 280u 24u "Please select the install file, and click next to continue"
Pop $PathForInstallLabel

${NSD_CreateFileRequest} 10u 86u 260u 12u $PathForInstallFileRequestState
Pop $PathForInstallFileRequest

${NSD_CreateBrowseButton} 275u 86u 15u 12u "..."
Pop $PathForInstallFileBrowse
GetFunctionAddress $0 OnBrowseForFile
nsDialogs::OnClick /NOUNLOAD $PathForInstallFileBrowse $0

nsDialogs::Show ;Display the dialog
FunctionEnd


Function OnBrowseForFile

nsDialogs::SelectFileDialog /NOUNLOAD "open" "" "All files (*.*)|*.*"
Pop $0
StrCpy $PathForInstallFileRequestState $0
${NSD_SetText} $PathForInstallFileRequest $PathForInstallFileRequestState

FunctionEnd


Yes the problem is that when the file request is canceled nsDialogs doesn't push anything on the stack. The random numbers you get is the next value from the stack (probably a HWND of some control).

You can workaround this problem by using something like this...

Function OnBrowseForFile

; Push something on the stack.
Push ?
nsDialogs::SelectFileDialog /NOUNLOAD "open" "" "All files (*.*)|*.*"
Pop $0
; if "?" is still on the top of the stack file request was canceled and we skip the rest of the code.
StrCmp $0 ? canceled
StrCpy $PathForInstallFileRequestState $0
${NSD_SetText} $PathForInstallFileRequest $PathForInstallFileRequestState
; nsDialogs pushed something on the stack so we still need to pop the "?" of the stack.
Pop $0
canceled:

FunctionEnd


Ah, silly of me not to realize that. Thanks!


That'd be a bug and should be properly reported.