include doszip/doszip.inc
include dos.inc
include string.inc
include errno.inc
include	conio.inc
include progress.inc

	public	cmmove

init_copy proto pascal :dword, :word

_COPY_TOZIP	= 0004h
_COPY_TOARCHIVE	= _COPY_TOZIP

_DZIP	SEGMENT

move_initfiles proc pascal filename:dword
	invoke strfcat, addr __outfile, addr __outpath, filename
	invoke strfcat, addr __srcfile, addr __srcpath, filename
	ret
move_initfiles endp

move_deletefile proc pascal result:word, flag:word
	mov ax,result
	add ax,copy_jump
	.if ax
	    mov ax,result
	    .if !ax
		mov copy_jump,ax
		inc jmp_count
	    .endif
	.else
	    .if byte ptr flag & _A_RDONLY
		invoke setfattr, addr __srcfile, 0
	    .endif
	    invoke remove, addr __srcfile
	    mov ax,result
	.endif
	ret
move_deletefile endp

fp_movedirectory proc DIST pascal directory:dword
	.if !func(progress_set, 0, directory, 0)
	    invoke setfattr, directory, ax
	    .if func(rmdir, directory)
		sub ax,ax
		.if jmp_count == ax
		    lodm directory
		    call erdelete
		.endif
	    .endif
	.endif
	ret
fp_movedirectory endp

fp_movefile proc DIST pascal directory:dword, wfblk:dword
	invoke fp_copyfile, directory, wfblk
	les bx,wfblk
	invoke move_deletefile, ax, es:[bx.wf_attrib]
	ret
fp_movefile endp

fblk_movefile proc pascal fblk:dword
	les bx,fblk
	.if !func(progress_set, addr es:[bx.fb_name], addr __outpath, es:[bx.fb_size])
	    .if func(rename, addr __srcfile, addr __outfile)
		les bx,fblk
		invoke copyfile, es:[bx.fb_size], es:[bx.fb_date], \
			es:[bx.fb_time], es:[bx.fb_flag]
		les bx,fblk
		invoke move_deletefile, ax, es:[bx.fb_flag]
	    .endif
	.endif
	ret
fblk_movefile endp

fblk_movedirectory proc pascal uses si di fblk:dword
local path[WMAXPATH]:byte, fname:dword
	lodm fblk
	add ax,fb_name
	stom fname
	.if !func(progress_set, dx::ax, addr __outpath, 0)
	    invoke move_initfiles, fname
	    .if func(rename, dx::ax, addr __outfile)
		lea di,path
		invoke strfcat, addr path, addr __srcpath, fname
		fpmov fp_directory,fp_copydirectory
		.if func(scansub, addr path, addr cp_stdmask, 1)
		    mov ax,-1
		.else
		    .if copy_jump == ax
			fpmov fp_directory,fp_movedirectory
			invoke scansub, addr path, addr cp_stdmask, 0
		    .else
			mov copy_jump,ax
			inc jmp_count
		    .endif
		.endif
	    .endif
	.endif
	ret
fblk_movedirectory endp

cmmove proc DIST
	push si
	push di
	call cpanel_findfirst
	mov di,bx
	mov si,dx
	.if dx
	    .if cx & (_A_ARCHZIP or _A_UPDIR)
		jmp @F
	    .endif
	    .if func(init_copy, si::di, 0)
	      ifdef __DLL__
		.if copy_flag & _COPY_OEXTFILE
		    mov bx,panela
		    .if bx == cpanel
			mov bx,panelb
		    .endif
		    mov dx,word ptr [bx.pn_wsub]
		    mov bx,cpanel
		    mov bx,word ptr [bx.pn_wsub]
		    xchg dx,bx
		    mov es,si
		    mov cx,di
		    mov ah,_DLL_MOVE
		    int DLL
		.elseif !(copy_flag & _COPY_IARCHIVE or _COPY_OARCHIVE)
	      else
		.if !(copy_flag & _COPY_IARCHIVE or _COPY_OARCHIVE)
	      endif
		    mov jmp_count,0
		    fpmov fp_fileblock,fp_movefile
		    invoke progress_open, addr cp_move, addr cp_move
		    mov es,si
		    mov ax,es:[di]
		    .if ax & _A_SELECTED
			.repeat
			    .if ax & _A_SUBDIR
				invoke fblk_movedirectory, si::di
			    .else
				mov ax,di
				add ax,fb_name
				invoke move_initfiles, si::ax
				invoke fblk_movefile, si::di
			    .endif
			    .break .if ax
			    mov es,si
			    mov ax,not _A_SELECTED
			    and es:[di],ax
			    mov ax,cpanel
			    .break .if !func(panel_findnext)
			    mov di,bx
			    mov si,dx
			    mov ax,cx
			.until 0
		    .else
			push si
			push di
			.if ax & _A_SUBDIR
			    call fblk_movedirectory
			.else
			    call fblk_movefile
			.endif
		    .endif
		.else
		    jmp @F
		.endif
		call ret_update_AB
		mov ax,1
	    .endif
	.endif
      @@:
	pop di
	pop si
	ret
cmmove	endp

_DZIP	ENDS

_DATA	SEGMENT

jmp_count dw 0

_DATA	ENDS

	END
