View Single Post
Old 22nd February 2018, 18:37   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,539
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:

PHP Code:
!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 enoughthere 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} $<> 0
    System
::Call "*$1(&t${NSIS_MAX_STRLEN}.r2)" Get directory single file
    StrLen 
$$2
    
#IntOp $0 $0 + 1 ; For \0 but should not be required because a directory cannot be chosen as a file
    
${If} $< $0
      MessageBox mb_ok 
"Single file: $2"
    
${Else}
      
StrCpy $5 0
      StrCpy 
$$1
      StrCpy 
$$2
loop
StrLen $$0
      System
::Call "*$3(&t$0,&t1,&t${NSIS_MAX_STRLEN}.r4)"
      
!if ${NSIS_CHAR_SIZE} > 1
      IntOp 
$$* ${NSIS_CHAR_SIZE}
      !endif
      ${
IntPtrOp} $$+ $0
      
${IntPtrOp} $$+ ${NSIS_CHAR_SIZE} ; \0
      
${If} $!= ""
        
StrCpy $"$2\$4"
        
IntOp $$1
        MessageBox mb_ok 
"File #$5: $0"
        
StrCpy $$4
        
Goto loop
      
${EndIf}
    ${EndIf}
${EndIf}
System::Free $

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote