FileRequest through section or function: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Updated author links.)
m (Added category links.)
Line 146: Line 146:


-Stu
-Stu
[[{{ns:14}}:Disk, Path & File Functions]]

Revision as of 21:35, 30 April 2005

Author: Afrow UK (talk, contrib)


Description

Here is a function to open up the standard Windows File Save/Open dialog. This can be called from a Section or Function "forcing" the user to Save/Open a file before the installation continues.

Usage

Push "0xA01800" ;flags (see below) separated by commas [,]
Push "open" ;use "open" or "save"
Push "Zip Files (*.zip)|*.zip" ;file type 1
Push "All Files (*.*)|*.*" ;file type 2
Push "Select Zip file to install" ;dialog title
 Call FileRequest
Pop $R0

$R0 = Selected file or "error" for cancelled

The Function

Function FileRequest
Exch $0 ;title
Exch
Exch $1 ;sort type 1
Exch 2
Exch $2 ;sort type 2
Exch 2
Exch 3
Exch $R4 ;save/open
Exch 3
Exch 4
Exch $R5 ;flag
Exch 4
Push $3
Push $4
Push $5 ;type 1 / 1
Push $6 ;tupe 1 / 2
Push $7 ;type 2 / 1
Push $8 ;type 2 / 2
Push $9
Push $R0 ;len 1 / 1
Push $R1 ;len 1 / 2
Push $R2 ;len 2 / 1
Push $R3 ;len 2 / 2
 
StrCmp $R5 "" 0 +2
 StrCpy $R5 0xA01800
 
StrCpy $9 $0 ;title
 
StrCpy $3 0
loop1:
 IntOp $3 $3 - 1
  StrCpy $4 $2 1 $3
 StrCmp $4 "" error
 StrCmp $4 "|" 0 loop1
StrCpy $5 $2 $3
 IntOp $3 $3 + 1
StrCpy $6 $2 "" $3
 
StrCpy $3 0
loop2:
 IntOp $3 $3 - 1
  StrCpy $4 $1 1 $3
 StrCmp $4 "" error
 StrCmp $4 "|" 0 loop2
StrCpy $7 $1 $3
 IntOp $3 $3 + 1
StrCpy $8 $1 "" $3
 
StrLen $R0 $5
 IntOp $R0 $R0 + 1
StrLen $R1 $6
 IntOp $R1 $R1 + 1
StrLen $R2 $7
 IntOp $R2 $R2 + 1
StrLen $R3 $8
 IntOp $R3 $R3 + 1
 
 StrCpy $4 '(&l4, i, i 0, i, i 0, i 0, i 0, t, i ${NSIS_MAX_STRLEN}, t, i ${NSIS_MAX_STRLEN}, t, t, i, &i2, &i2, t, i 0, i 0, i 0) i'
 
 System::Call '*(&t$R0 "$5" , &t$R1 "$6", &t$R2 "$7", &t$R3 "$8", &i1 0) i.r0'
 
 System::Call '*$4(, $HWNDPARENT,, r0,,,,"",,"",, i 0, "$9", $R5,,,,,,) .r1'
 
 System::Call 'comdlg32::Get$R4FileNameA(i r1) i .r2'
 System::Call '*$1$4(,,,,,,,.r3)'
 System::Free $1
 System::Free $0
 
StrCmp $2 0 0 +2
error:
 StrCpy $3 error
StrCpy $0 $3
 
Pop $R4
Pop $R3
Pop $R2
Pop $R1
Pop $R0
Pop $9
Pop $8
Pop $7
Pop $6
Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Exch $0
FunctionEnd

Flags

  • OFN_READONLY 0x00000001
  • OFN_OVERWRITEPROMPT 0x00000002
  • OFN_HIDEREADONLY 0x00000004
  • OFN_NOCHANGEDIR 0x00000008
  • OFN_SHOWHELP 0x00000010
  • OFN_ENABLEHOOK 0x00000020
  • OFN_ENABLETEMPLATE 0x00000040
  • OFN_ENABLETEMPLATEHANDLE 0x00000080
  • OFN_NOVALIDATE 0x00000100
  • OFN_ALLOWMULTISELECT 0x00000200
  • OFN_EXTENSIONDIFFERENT 0x00000400
  • OFN_PATHMUSTEXIST 0x00000800
  • OFN_FILEMUSTEXIST 0x00001000
  • OFN_CREATEPROMPT 0x00002000
  • OFN_SHAREAWARE 0x00004000
  • OFN_NOREADONLYRETURN 0x00008000
  • OFN_NOTESTFILECREATE 0x00010000
  • OFN_NONETWORKBUTTON 0x00020000
  • OFN_NOLONGNAMES 0x00040000 ; force no long names for 4.x modules
  • OFN_EXPLORER 0x00080000 ; new look commdlg
  • OFN_NODEREFERENCELINKS 0x00100000
  • OFN_LONGNAMES 0x00200000 ; force long names for 3.x modules
  • OFN_ENABLEINCLUDENOTIFY 0x00400000 ; send include message to callback
  • OFN_ENABLESIZING 0x00800000
  • OFN_DONTADDTORECENT 0x02000000
  • OFN_FORCESHOWHIDDEN 0x10000000 ; Show All files including System and hidden files

Thanks brainsucker and Kichik for help.

-Stu