Old 29th February 2016, 18:36   #1
pkonduru
Member
 
Join Date: Jul 2015
Posts: 62
Remove Filerequest prompt to create new file

Hi All,

In my installer, one of my custom dialogs prompts the user to browse for a file with .lic extension. I am using nsDialogs with CoolSoft NSIS Designer.
After clicking on the browse button, my file browse window only displays files with .lic extension. If the user types in any random say "test.lic" in the Filename area, the file browse window prompts for "test.lic does not exist. Do you want to create it?".
How can I disable this ? Use should be able to only browse for files that exist.

Appreciate any responses.

--Pavan
pkonduru is offline   Reply With Quote
Old 29th February 2016, 20:50   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,277
nsDialogs always passes the flag that makes this happen, you have to call GetOpenFileName with the system plugin to have control over the dialog: http://forums.winamp.com/showthread.php?t=171553

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 1st March 2016, 18:45   #3
pkonduru
Member
 
Join Date: Jul 2015
Posts: 62
Thanks for your reply Anders. This is what I have in my code for the file request:

${NSD_CreateButton} 247.49u 100.31u 19.75u 12.31u "..."
Pop $hCtl_FoundationDialog_FileRequest1_Btn
${NSD_OnClick} $hCtl_FoundationDialog_FileRequest1_Btn onClickfn

Function onClickfn
Pop $R0
${If} $R0 == $hCtl_FoundationDialog_FileRequest1_Btn
${NSD_GetText} $hCtl_FoundationDialog_FileRequest1_Txt $R0
nsDialogs::SelectFileDialog open "$R0" "Lic File|*.lic"
Pop $R0
${If} "$R0" != ""
${NSD_SetText} $hCtl_FoundationDialog_FileRequest1_Txt "$R0"
${EndIf}
${EndIf}
FunctionEnd

So should I put a call for the GetOpenFileName with system plugin in the function onClickfn?

I saw the thread you mentioned in your post. I compiled the example given by eccles. That installer launches a file browse window but still allows me to type in a file that doesn't exist.
System::Call "comdlg32::GetOpenFileNameA(ir0) i.r9"
what does the above do?

--Pavan
pkonduru is offline   Reply With Quote
Old 1st March 2016, 20:19   #4
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,277
You would have to look at some of the flags for the OPENFILENAME struct on MSDN, there should be one that requires the file to exist. I can write a example for you tomorrow...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 1st March 2016, 21:18   #5
pkonduru
Member
 
Join Date: Jul 2015
Posts: 62
Thanks Anders!!
On MSDN it says that this is the property that is used:
OFN_CREATEPROMPT
So I need to disable this flag I guess?

Thank you for looking into this and will wait for the response tomorrow.

--Pavan
pkonduru is offline   Reply With Quote
Old 1st March 2016, 21:40   #6
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,277
Quote:
Originally Posted by pkonduru View Post
So I need to disable this flag I guess?
You want OFN_FILEMUSTEXIST...

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 2nd March 2016, 14:08   #7
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,277
PHP Code:
!define OFN_ENABLESIZING 0x00800000
!define OFN_NOCHANGEDIR 0x00000008
!define OFN_HIDEREADONLY 0x00000004
!define OFN_FILEMUSTEXIST 0x00001000
!define OFN_EXPLORER 0x00080000
!if "${NSIS_PTR_SIZE}<= 4
!define OPENFILENAME_SIZE_VERSION_400 76
!define OPENFILENAME 'i,i,i,i,i,i,i,i,i,i,i,i,i,i,&i2,&i2,i,i,i,i'
!endif

Page Custom MyPage
Page InstFiles

Var MyPathInput
!include nsDialogs.nsh
!include LogicLib.nsh

Function MyBrowseForFileHandler
Pop 
$; Throw away parameter
System
::Call '*(&t${NSIS_MAX_STRLEN})i.s' Allocate OPENFILENAME.lpstrFile buffer
System
::Call '*(${OPENFILENAME})i.r0' Allocate OPENFILENAME struct
System
::Call '*$0(${OPENFILENAME})(${OPENFILENAME_SIZE_VERSION_400},$hwndparent,,,,,,sr1,${NSIS_MAX_STRLEN},,,,t"Dialog title goes here",${OFN_HIDEREADONLY}|${OFN_FILEMUSTEXIST}|${OFN_ENABLESIZING}|${OFN_EXPLORER}|${OFN_NOCHANGEDIR})'
${NSD_GetText$MyPathInput $2
System
::Call "*$1(&t${NSIS_MAX_STRLEN}r2)" Set lpstrFile to the old path (if any)
System::Call 'COMDLG32::GetOpenFileName(ir0)i.r2'
${If} $<> 0
    System
::Call "*$1(&t${NSIS_MAX_STRLEN}.r2)"
    
${NSD_SetText$MyPathInput $2
${EndIf}
System::Free $1
System
::Free $0
FunctionEnd


Function MyPage
nsDialogs
::Create 1018
Pop 
$0
${NSD_CreateText0 10u -40u 12u ""
Pop $MyPathInput
${NSD_CreateBrowseButton} -38u 10u 35u 12u "..."
Pop $0
${NSD_OnClick} $0 MyBrowseForFileHandler
nsDialogs
::Show
FunctionEnd 

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 2nd March 2016, 15:42   #8
pkonduru
Member
 
Join Date: Jul 2015
Posts: 62
Really appreciate it Anders!!!A big thank you
pkonduru is offline   Reply With Quote
Old 2nd March 2016, 16:24   #9
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,277
I'd like to point out that removing this prompt is not much of a roadblock. The user can just right-click in the open dialog and create a new file.

If you don't want the user to choose a empty file you should verify the file content and/or size in the page leave callback function.

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 2nd March 2016, 22:56   #10
pkonduru
Member
 
Join Date: Jul 2015
Posts: 62
Hi Anders,

That is true. I never realized that. I will probably convince the people involved in this project to get this requirement put off, as it is not really a critical issue. We don't validate any content from that file as of now, when we get that requirement it would probably make sense to do a validation on the file content itself.

Thanks again!

--Pavan
pkonduru is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump