Skip to content
⌘ NSIS Forum Archive

select multiple files with dialog open

2 posts

r2du-soft#

select multiple files with dialog open

how can select multiple files in dialog box in nsis?
i try with:

Dialogs::Open

DialogsEx (${OpenBox} "Search for a java files" "java files (*.java)|*.java||" 1 "$EXEDIR" 3 ${VAR_6})

nsDialogs::SelectFileDialog /NOUNLOAD open "" "Java Files|*.java|All Files|*.*"

with that's plugins just can select one file but i want to select multiple files...

after select files i want use this
ExecDos::exec '"$JavaExePatch" "$0"'

to convert *.java files to .class files
Anders#
The Windows open/save dialogs are badly designed and if you want to support a selection of "unlimited" number of files you need 3 separate codepaths in your application, one for 95/98/ME, one for NT4/2000/XP/2003 and one for Vista+ and I'm not going to code all that for you.

Here is a limited version but should be enough for most uses:

!include LogicLib.nsh
!include Util.nsh
!ifndef IntPtrOp
!define IntPtrOp IntOp
!endif
!ifndef NSIS_CHAR_SIZE
!define NSIS_CHAR_SIZE 1
!endif
!define OFN_ENABLESIZING 0x00800000
!define OFN_HIDEREADONLY 0x00000004
!define OFN_ALLOWMULTISELECT 0x00000200
!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'
!else
!error TODO
!endif
!define MYMULTISELCCH 42000 ; Hopefully large enough, there is no way to know how many files the user will select
System::Call '*(&t${MYMULTISELCCH})i.s' ; Allocate OPENFILENAME.lpstrFile buffer
System::Call '*(${OPENFILENAME})i.r0' ; Allocate OPENFILENAME struct
System::Call '*$0(${OPENFILENAME})(${OPENFILENAME_SIZE_VERSION_400},$hwndparent,,,,,,sr1,${MYMULTISELCCH},,,,t"Dialog title goes here",${OFN_HIDEREADONLY}|${OFN_FILEMUSTEXIST}|${OFN_ENABLESIZING}|${OFN_EXPLORER}|${OFN_ALLOWMULTISELECT})'
System::Call '*$1(&t${NSIS_MAX_STRLEN} "$InstDir")' ; Initial path (This is optional)
System::Call 'COMDLG32::GetOpenFileName(ir0)i.r2'
System::Call '*$0(${OPENFILENAME})(,,,,,,,,,,,,,,&i2.r3)'
System::Free $0
${If} $2 <> 0
    System::Call "*$1(&t${NSIS_MAX_STRLEN}.r2)" ; Get directory / single file
    StrLen $0 $2
    #IntOp $0 $0 + 1 ; For \0 but should not be required because a directory cannot be chosen as a file
    ${If} $3 < $0
      MessageBox mb_ok "Single file: $2"
    ${Else}
      StrCpy $5 0
      StrCpy $3 $1
      StrCpy $0 $2
loop: StrLen $0 $0
      System::Call "*$3(&t$0,&t1,&t${NSIS_MAX_STRLEN}.r4)"
      !if ${NSIS_CHAR_SIZE} > 1
      IntOp $0 $0 * ${NSIS_CHAR_SIZE}
      !endif
      ${IntPtrOp} $3 $3 + $0
      ${IntPtrOp} $3 $3 + ${NSIS_CHAR_SIZE} ; \0
      ${If} $4 != ""
        StrCpy $0 "$2\$4"
        IntOp $5 $5 + 1
        MessageBox mb_ok "File #$5: $0"
        StrCpy $0 $4
        Goto loop
      ${EndIf}
    ${EndIf}
${EndIf}
System::Free $1