include	clib.inc
include	wsub.inc
include	string.inc
include	dos.inc
include	io.inc
include	iost.inc

	extrn	configpath:byte

_TEXT	SEGMENT

wgetfile proc dist pascal public uses si di fmask:dword, flag:word
local	path[WMAXPATH]:byte
	mov si,flag
	mov di,word ptr fmask
	mov bx,di
	add bx,2
	invoke strfcat,addr path,addr configpath,ss::bx
	invoke filexist,dx::ax
	.if ax != 2
	    invoke wsmkdirlocal,addr path
	    inc ax
	    jz @F
	.endif
	invoke wdlgopen,addr path,ds::di,si
	jz @F
	.if si & 1
	    invoke openfile,dx::ax,M_RDONLY, A_OPEN
	.else
	    invoke ogetouth,dx::ax
	.endif
	inc ax
	jz @F
	dec ax
      @@:
    	ret
wgetfile endp

_TEXT	ENDS

	END
