include doszip/doszip.inc
include dos.inc
include progress.inc
include stdlib.inc
include	conio.inc
include string.inc
include math.inc

	public	cmsubinfo
	public	cmasubinfo
	public	cmbsubinfo
	public	cmsubsize

_DATA	SEGMENT

cp_subsize	db "Directory Information",0
cp_bytesize	db "BKMGTPE",0
di_subdcount	dd ?
di_filecount	dd ?
qeax		dd ?
qedx		dd ?

_DATA	ENDS

_DZIP	SEGMENT

DI_CLEAR proc
      ifdef __386__
	xor eax,eax
	mov qeax,eax
	mov qedx,eax
	mov di_filecount,eax
	mov di_subdcount,eax
      else
	xor ax,ax
	mov word ptr qeax+2,ax
	mov word ptr qeax,ax
	mov word ptr qedx+2,ax
	mov word ptr qedx,ax
	mov word ptr di_filecount,ax
	mov word ptr di_filecount+2,ax
	mov word ptr di_subdcount,ax
	mov word ptr di_subdcount+2,ax
      endif
	ret
DI_CLEAR endp

DI_DOFILE proc DIST pascal directory:dword, wblk:dword
	incm di_filecount
	lodm directory
	.if dx
	    les bx,wblk
	    add bx,wf_name
	    .if !func(progress_set, es::bx, dx::ax, dx::ax)
		les bx,wblk
	      ifdef __386__
		mov eax,es:[bx.wf_sizeax]
		mov edx,es:[bx.wf_sizedx]
		add qeax,eax
		adc qedx,edx
	      else
		mov ax,word ptr es:[bx.wf_sizeax]
		mov dx,word ptr es:[bx.wf_sizeax+2]
		mov cx,word ptr es:[bx.wf_sizedx+2]
		mov bx,word ptr es:[bx.wf_sizedx]
		add word ptr qedx,bx
		adc word ptr qedx+2,cx
		add word ptr qeax,ax
		adc word ptr qeax+2,dx
		adc word ptr qedx,0
		adc word ptr qedx+2,0
	      endif
		sub ax,ax
	    .endif
	.endif
	ret
DI_DOFILE endp

DI_DOSUBD proc DIST pascal directory:dword
	invoke strlen, directory
	mov bx,word ptr directory
	add bx,ax
	mov ax,'\'
	dec bx
	.if [bx] == al
	    mov [bx],ah
	.endif
	.if !func(progress_set, 0, directory, 0)
	    incm di_subdcount
	    invoke scan_files, directory
	.endif
	ret
DI_DOSUBD endp

DI_SCANSUB proc	; DX:AX Subdir
	push 1
	push dx
	push ax
	invoke progress_open, addr cp_subsize, 0
	stoso fp_maskp,ds,offset cp_stdmask
	fpmov fp_fileblock,DI_DOFILE
	fpmov fp_directory,DI_DOSUBD
	call scan_directory
	call progress_close
	test ax,ax
	ret
DI_SCANSUB endp

DI_SUBINFO proc pascal uses si di s1:dword, s2:dword
	.if func(rsopen, IDD_DZSubInfo)
	    mov si,dx
	    mov di,ax
	    mov ch,0
	    mov cl,es:[di+6]
	    les bx,es:[di.dl_wp]
	    mov ax,[bp+4]
	    mov dx,ds
	    call @wctitle
	    invoke dlshow, si::di
	    mov bx,es:[di+4]
	    add bx,0205h
	    scputs@ bl, bh, ch, cl, ds, offset cstr("Location:")
	    add bl,10
	    scpath@ bl, bh, 20, dx, [bp+8]
	  ifdef __386__
	    mov eax,di_subdcount
	    dec eax
	    sub bl,11
	    inc bh
	    scputf@ bl, bh, ch, 0, \
		offset cstr(<"%10lu Files",10,"%10lu Directories">), \
		word ptr di_filecount, word ptr di_filecount+2, eax
	  else
	    lodm di_subdcount
	    sub ax,1
	    sbb dx,0
	    sub bl,11
	    inc bh
	    scputf@ bl, bh, ch, 0, \
		offset cstr(<"%10lu Files",10,"%10lu Directories">), \
		word ptr di_filecount, word ptr di_filecount+2, ax, dx
	  endif
	    invoke mkbstring, s1, qedx, qeax
	    mov es,si
	    mov bx,di
	    push si
	    push di
	    mov di,ax
	    mov si,dx
	    mov bx,es:[bx+4]
	    add bx,0606h
	    scputf@ bl,bh,0,0, offset cstr("total %s byte"), [bp+8], [bp+10]
	    .if di && si
		mov al,[si+cp_bytesize]
		add bx,0106h
		scputf@ bl, bh, ch, cl, offset cstr(" %lu%c"), di, 0, ax
	    .endif
	    call dlmodal
	.endif
	ret
DI_SUBINFO endp

DI_DOSELECTED proc pascal uses si di s1:dword
	incm di_subdcount
	mov bx,cpanel
	mov bx,word ptr [bx.pn_wsub]
	mov di,word ptr [bx.ws_fcb+2]
	xor si,si
	.repeat
	    mov ax,1
	    mov bx,cpanel
	    .break .if si >= [bx.pn_fcb_count]
	    mov es,di
	    mov bx,si
	    shl bx,2
	    add bx,4
	    mov dx,es:[bx+2]
	    mov bx,es:[bx]
	    mov es,dx
	    mov cx,es:[bx]
	    inc si
	    .continue .if !(cx &_A_SELECTED)
	    .if cx & _A_SUBDIR
		mov ax,bx
		mov bx,cpanel
		mov bx,word ptr [bx.pn_wsub]
		add ax,fb_name
		invoke strfcat, s1, [bx.ws_path], dx::ax
		.break .if func(DI_SCANSUB)
	    .else
	      ifdef __386__
		mov eax,es:[bx.fb_size]
		add qeax,eax
		adc qedx,0
		inc di_filecount
	      else
		lodm es:[bx.fb_size]
		add word ptr qeax,ax
		adc word ptr qeax+2,dx
		adc word ptr qedx,0
		adc word ptr qedx+2,0
		incm di_filecount
	      endif
	    .endif
	.until 0
	.if ax
	    mov bx,cpanel
	    mov bx,word ptr [bx.pn_wsub]
	    invoke strcpy, s1, [bx.ws_path]
	    invoke DI_SUBINFO, dx::ax, addr cstr("Selected Files")
	.endif
	ret
DI_DOSELECTED endp

DI_CMSUBINFO proc pascal uses si di panel:word
local path[WMAXPATH]:byte
	mov si,panel
	lea di,path
	mov ax,si
	.if func(panel_state)
	    mov bx,[si]
	    mov ax,[bx]
	    .if !(ax & _W_ARCHIVE or _W_ROOTDIR)
		call DI_CLEAR
		mov ax,si
		.if func(panel_findnext)
		    invoke DI_DOSELECTED, ss::di
		.else
		    mov bx,word ptr [si.pn_wsub]
		    invoke strcpy, ss::di, [bx.ws_path]
		    .if !func(DI_SCANSUB)
			invoke DI_SUBINFO, ss::di, addr cp_subsize
		    .endif
		.endif
	    .else
		sub ax,ax
	    .endif
	.endif
	ret
DI_CMSUBINFO endp

cmsubinfo proc DIST
	invoke DI_CMSUBINFO, cpanel
	ret
cmsubinfo endp

cmasubinfo proc DIST
	invoke DI_CMSUBINFO, panela
	ret
cmasubinfo endp

cmbsubinfo proc DIST
	invoke DI_CMSUBINFO, panelb
	ret
cmbsubinfo endp

cmsubsize proc DIST pascal
local path[WMAXPATH]:byte
	call DI_CLEAR
	mov ax,cpanel
	.if func(panel_curobj)
	    .if !(cx & _A_ARCHIVE or _A_UPDIR)
		mov bx,cpanel
		mov bx,word ptr [bx.pn_wsub]
		mov cx,ax
		invoke strfcat, addr path, [bx.ws_path], dx::cx
		.if !func(DI_SCANSUB)
		    invoke DI_SUBINFO, addr path, addr cp_subsize
		.endif
	    .endif
	.endif
	sub ax,ax
	ret
cmsubsize endp

_DZIP	ENDS

	END
