Winamp & Shoutcast Forums

Winamp & Shoutcast Forums (http://forums.winamp.com/index.php)
-   NSIS Discussion (http://forums.winamp.com/forumdisplay.php?f=65)
-   -   Remove Filerequest prompt to create new file (http://forums.winamp.com/showthread.php?t=389969)

pkonduru 29th February 2016 18:36

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

Anders 29th February 2016 20:50

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

pkonduru 1st March 2016 18:45

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

Anders 1st March 2016 20:19

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...

pkonduru 1st March 2016 21:18

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

Anders 1st March 2016 21:40

Quote:

Originally Posted by pkonduru (Post 3050825)
So I need to disable this flag I guess?

You want OFN_FILEMUSTEXIST...

Anders 2nd March 2016 14:08

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 


pkonduru 2nd March 2016 15:42

Really appreciate it Anders!!!A big thank you

Anders 2nd March 2016 16:24

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.

pkonduru 2nd March 2016 22:56

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


All times are GMT. The time now is 18:02.

Copyright © 1999 - 2010 Nullsoft. All Rights Reserved.