include doszip/doszip.inc
include	conio.inc
include io.inc
include iost.inc
include errno.inc
include tinfo.inc

	public	config_read
	public	config_save
	public	cmsavesetup	; Shift-F10

_DZIP	SEGMENT

config_read PROC
	push	si
	call	getcfgfile
	invoke	osopen, dx::ax, _A_NORMAL, M_RDONLY, A_OPEN
	inc	ax
	jz	configread_error
	dec	ax
	mov	si,ax
	invoke	osread, si, addr config, 2
	cmp	ax,2
	jne	configread_fail
	mov	ax,config
	mov	config,VERSION
	cmp	ax,VERSION
	ja	configread_fail
	cmp	ax,MINVERS
	jb	configread_fail
	invoke	osread, si, addr cflag, S_CONFIG-2
	push	ax
	invoke	close, si
	pop	ax
	cmp	ax,size S_CONFIG-2
	mov	ax,1
	je	configread_end
	dec	ax
    configread_end:
	pop	si
	ret
    configread_fail:
	invoke	close, si
    configread_error:
	xor	ax,ax
	jmp	configread_end
config_read ENDP

config_save PROC
	push si
	call getcfgfile
	invoke osopen, dx::ax, _A_NORMAL, M_WRONLY, A_CREATE or A_TRUNC
	mov si,ax
	inc ax
	.if ax
	    invoke oswrite, si, addr config, size S_CONFIG
	    xchg ax,si
	    invoke close, ax
	    .if si == SIZE S_CONFIG
		mov ax,1
	    .else
		xor ax,ax
	    .endif
	.endif
	or ax,ax
	pop si
	ret
config_save ENDP

cmsavesetup PROC DIST
	invoke	rsmodal, IDD_DZSaveSetup
	or	ax,ax
	jz	savesetup_00
	call	config_save
	jz	savesetup_01
	mov	ax,1
    savesetup_00:
	ret
    savesetup_01:
	call	getcfgfile
	call	eropen
	inc	ax
	jmp	savesetup_00
cmsavesetup ENDP

_DZIP	ENDS

	END
