include doszip/doszip.inc
include	time.inc
include	conio.inc
include dos.inc
include	io.inc
include string.inc
ifdef __ZIP__
 include unzip.inc
endif

	public	cmattrib

ID_RDONLY	equ	1*16
ID_HIDDEN	equ	2*16
ID_SYSTEM	equ	3*16
ID_ARCHIVE	equ	4*16
ID_CREATEDATE	equ	5*16
ID_CREATETIME	equ	6*16
ID_MODDATE	equ	7*16
ID_MODTIME	equ	8*16
ID_ACCESSDATE	equ	9*16
ID_ACCESSTIME	equ	10*16
ID_SET		equ	11*16
ID_CANCEL	equ	12*16

ifdef __ZIP__
_DATA	SEGMENT
format_zx label byte
	db	'%08lX',10
	db	'%04X',10
	db	'%04X',10
	db	'%04X',10
	db	'%04X',10
	db	'%04X',10
	db	'%08lX',10
	db	'%08lX',10
	db	'%08lX',10
	db	'%04X',10
	db	'%04X',10,10,10
	db	'%04X', 10
	db	'%08lX',10
	db	'%08lX',10
	db	'%08lX',10
	db	0
format_zu label byte
	db	'%16lu',10
	db	'%16lu',10
	db	'%16u',10
	db	'%16u',10
	db	0
_DATA	ENDS
endif ; __ZIP__

_DZIP	SEGMENT

FILEINFO_INIT PROC
	mov [bp-06],dx	; seg fblk
	mov [bp-08],bx	; off fblk
	mov [bp-10],ax	; off fblk.name
	mov [bp-12],cx	; fblk.flag
	mov si,dx
	mov di,ax
	invoke rsopen, IDD_DZFileAttributes
	mov [bp-2],dx
	mov [bp-4],ax
	.if ax
	    mov	al,_O_FLAGB
	    mov	dx,[bp-12]
	    .if	dl & _A_RDONLY
		or es:[bx+ID_RDONLY],al
	    .endif
	    .if	dl & _A_HIDDEN
		or es:[bx+ID_HIDDEN],al
	    .endif
	    .if	dl & _A_SYSTEM
		or es:[bx+ID_SYSTEM],al
	    .endif
	    .if	dl & _A_ARCH
		or es:[bx+ID_ARCHIVE],al
	    .endif
	    or ax,ax
    	.endif
	ret
FILEINFO_INIT ENDP

FILEINFO_NOLFN PROC	;------------------------ No LFN
	xor ax,ax
	mov scan_fblock.wf_timecreate,ax
	mov scan_fblock.wf_datecreate,ax
	mov scan_fblock.wf_timeaccess,ax
	mov scan_fblock.wf_dateaccess,ax
	les bx,[bp-8]
	mov ax,es:[bx]
	and ax,_A_FATTRIB
	mov scan_fblock.wf_attrib,ax
	mov ax,es:[bx.fb_date]
	mov scan_fblock.wf_datemodified,ax
	mov ax,es:[bx.fb_time]
	mov scan_fblock.wf_timemodified,ax
	les bx,[bp-4]
	mov ax,_O_STATE
	or es:[bx+ID_CREATEDATE],ax
	or es:[bx+ID_CREATETIME],ax
	or es:[bx+ID_ACCESSDATE],ax
	or es:[bx+ID_ACCESSTIME],ax
	ret
FILEINFO_NOLFN ENDP


FILEINFO_LFN PROC	;------------------------ Use LFN
  ifdef __LFN__
	push ax
	call wcloseff
	les bx,[bp-4]
	pushm es:[bx+ID_CREATEDATE+TO_ODATA]
	push scan_fblock.wf_datecreate
	pushm es:[bx+ID_CREATETIME+TO_ODATA]
	push scan_fblock.wf_timecreate
	pushm es:[bx+ID_ACCESSDATE+TO_ODATA]
	push scan_fblock.wf_dateaccess
	pushm es:[bx+ID_ACCESSTIME+TO_ODATA]
	push scan_fblock.wf_timeaccess
	call twtostr
	call dwtolstr
	call twtostr
	call dwtolstr
  endif
	ret
FILEINFO_LFN ENDP

FILEINFO_MODAL PROC	;------------------------ Get result
	les bx,[bp-4]
	pushm es:[bx].to_data[ID_MODDATE]
	push scan_fblock.wf_datemodified
	pushm es:[bx].to_data[ID_MODTIME]
	push scan_fblock.wf_timemodified
	call twtostr
	call dwtolstr
	invoke dlinit, [bp-4]
	invoke dlshow, [bp-4]
	mov bx,es:[bx+4]
	add bx,0213h
	mov cx,21
	mov ax,[bp-10]
	mov dx,[bp-6]
	call @scpath
	invoke dlevent, [bp-4]
	ret
FILEINFO_MODAL ENDP

FILEINFO_UPDATE	PROC ;------------------------ Update file
	mov al,_O_FLAGB
	xor dx,dx
	.if es:[bx+ID_RDONLY] & al
	    or dx,_A_RDONLY
    	.endif
	.if es:[bx+ID_HIDDEN] & al
	    or dx,_A_HIDDEN
	.endif
	.if es:[bx+ID_SYSTEM] & al
	    or dx,_A_SYSTEM
	.endif
	.if es:[bx+ID_ARCHIVE] & al
	    or dx,_A_ARCH
	.endif
	mov ax,[bp-12]
	and ax,_A_ARCH or _A_SYSTEM or _A_HIDDEN or _A_RDONLY
	.if ax != dx
	    mov ax,[bp-12]
	    .if ax & _A_SUBDIR
		mov [bp-12],dx
		invoke setfattr, si::di, 0
		or ax,ax
		jnz fi_update_06
		mov dx,[bp-12]
	    .endif
	    invoke setfattr, si::di, dx
	.endif
	les bx,[bp-4]
	pushm es:[bx.to_data+ID_MODTIME]
	invoke strtodw, es:[bx.to_data+ID_MODDATE]
	mov [bp-12],ax		; date modified
	call strtotw 		; time modified
  ifdef __LFN__
	cmp _ifsmgr,0
	je  fi_update_07
	invoke wsetwrdate, si::di, [bp-12], ax
	les bx,[bp-4]
	invoke strtodw, es:[bx.to_data+ID_ACCESSDATE]
	invoke wsetacdate, si::di, ax
	les bx,[bp-4]
	pushm es:[bx.to_data+ID_CREATEDATE]
	invoke strtotw, es:[bx.to_data+ID_CREATETIME]
	mov [bp-12],ax
	call strtodw
	invoke wsetcrdate, si::di, ax, [bp-12]
  else
	jmp fi_update_07
  endif
    fi_update_06:
	ret
    fi_update_07:
	xchg di,ax
	invoke osopen, si::ax, _A_NORMAL, M_RDONLY, A_OPEN
	.if ax != -1
	    push ax
	    invoke setfdate, ax, [bp-12], di
	    call close
	.endif
	jmp fi_update_06
FILEINFO_UPDATE ENDP

FILEINFO PROC PASCAL uses si di
local	buf[14]:byte
	call FILEINFO_INIT
	.if !ZERO?
      ifdef __LFN__
	    mov al,_ifsmgr
	    .if al
		push ax
		invoke wfindfirst, si::di, addr scan_fblock, 00FFh
		inc ax
		pop ax
		mov _ifsmgr,al
		.if ZERO?
		    invoke dlclose, [bp-4]
		    jmp @F
		.else
		    call FILEINFO_LFN
		.endif
	    .else
		call FILEINFO_NOLFN
	    .endif
      else
	    call FILEINFO_NOLFN
      endif
	    call FILEINFO_MODAL
	    .if !ZERO?
		call FILEINFO_UPDATE
		invoke dlclose, [bp-4]
		mov ax,cpanel
		call panel_reread
	    .else
		invoke dlclose, [bp-4]
	    .endif
	.endif
      @@:
	xor ax,ax
	ret
FILEINFO ENDP

ifdef __ZIP__

ZIPINFO PROC
	push si
	push di
	mov si,dx
	mov di,bx
	mov bx,cpanel
	.if cl & _A_SUBDIR
	    xor ax,ax
	    jmp @F
	.endif
	push cx
	invoke wsopenarch, [bx.pn_wsub]
	pop cx
	.if ax == -1
	    inc ax
	    jmp @F
	.endif
	push ax
	push cx
	push ax
	push ds
	push offset zip_local
	push SIZE S_LZIP
	push ax
	mov ax,di
	add ax,fb_name
	invoke strlen, si::ax
	add ax,SIZE S_FBLK
	add di,ax
	movmx zip_central.cz_crc,es:[di+4]
	movmx zip_central.cz_csize,es:[di+8]
	movmm zip_central.cz_off_local,es:[di]
	push dx
	push ax
	push SEEK_SET
	call lseek
	call osread
	pop cx
	.if ax == SIZE S_LZIP && \
	    word ptr zip_local.lz_zipid == ZIPLOCALID && \
	    word ptr zip_local.lz_pkzip == ZIPHEADERID
	    pop ax
	    mov di,cx
	    push ax
	    invoke osread, ax, addr entryname, zip_local.lz_fnsize
	    mov si,ax
	    call close
	    .if si == zip_local.lz_fnsize
		mov bx,offset entryname
		add bx,si
		mov byte ptr [bx],0
		invoke rsopen, IDD_DZZipAttributes
		.if ax
		    push dx
		    push ax
		    push dx
		    push ax
		    mov si,es:[bx+4]
		    invoke dlshow, dx::ax
		    mov bx,si
		    add bx,0104h
		    mov cx,54
		    mov ax,offset entryname
		    mov dx,ds
		    call @scpath
		    pushm zip_central.cz_crc
		    pushm zip_central.cz_csize
		    pushm zip_central.cz_off_local
		    and di,_A_FATTRIB
		    push di
		    add bx,0317h
		    mov cx,15
		    std
		    mov si,offset zip_local + size S_LZIP - 2
		    .while cx
			lodsw
			push ax
			dec cx
		    .endw
		    mov cx,88
		    mov ax,offset format_zx
		    call @scputf
		    add bx,0708h
		    mov ax,offset format_zu
		    add sp,18
		    call @scputf
		    add sp,26
		    add bx,0612h
		    mov cx,1
		    mov ax,'x'
		    .if di & _A_RDONLY
			call @scputw
		    .endif
		    inc bh
		    .if di & _A_HIDDEN
			call @scputw
		    .endif
		    inc bh
		    .if di & _A_SYSTEM
			call @scputw
		    .endif
		    inc bh
		    .if di & _A_ARCH
			call @scputw
		    .endif
		    call dlevent
		    call dlclose
		.endif
	    .else
		xor ax,ax
	    .endif
	.else
	    call close
	.endif
    @@:
	pop di
	pop si
	ret
ZIPINFO ENDP

endif

cmattrib PROC DIST
	mov ax,cpanel
	call panel_curobj
	jz cmattrib_end
      ifdef __ROT__
	test cx,_A_ROOTDIR
	jnz cmattrib_end
      endif
      ifdef __ARC__
	.if cx & _A_ARCHIVE
       ifdef __DLL__
	    .if cx & _A_ARCHEXT
		mov cx,bx
		mov bx,cpanel
		mov bx,word ptr [bx.pn_wsub]
		mov ah,_DLL_PROPERTY
		int DLL
		.if CARRY?
		    call notsup
		.endif
	ifdef __ZIP__
	    .else
		call ZIPINFO
	endif
	    .endif
	.else
	    call FILEINFO
       endif
	.endif
      else
	call FILEINFO
      endif
    cmattrib_end:
	ret
cmattrib ENDP

_DZIP	ENDS

	END

