;COPYRIGHT Hewlett-Packard Company 1987, 1988, 1989, 1990, 1991
; Routines to install an application:
;  save_backup_file
;  delete_files
;  copy_spec_files
;  find_bkgrdir
;  find_neededfile	
;  install_bkground

;	macro setvar
goto skip_moreutl
	
save_backup_file
; Backup given file so user can retrieve old file in case problems arise.
; Input:
;   var066 - drive of var068
;   var067 - directory of var068
;   var068 - file that is to be backed up
;   var069 - backup copy of var068 (generally filename.BKP)

	if var066 != null changedrive var066
	cd \
	if var067 != null cd var067
	copys var068 var069 status null null

	if status != 0 print bkup_failed
	if status != 0 goto quit1

return

		
delete_files
		    
;This procedure will delete group of files from the hard disk.
;Inputs:
;  var074	Drive for given file(s).
;  var075	Directory for given file(s).     
;  var076	Given file(s) to delete.		

	changedrive var074		;Go to directory where file is.
	cd \
	cd var075	

	echo off
	set status 0	
				;Verify atleast one file exists.
	if app_del_test != NULL exist app_del_test status
	if status != 1 goto delete_file2  ;Skip delete if file not there.
	delete var076 

delete_file2
return
		
copy_spec_files

;This procedure is the same as copyb_files except the copy statement
;  restricts the copy to files specified by spec_files variable.
;
;Inputs:
;  var040 	The text of the message to be displayed during the copy.
;  var041	Number of files to be copied.		     
;  var042	Destination drive & directory on hard disk.
;  var043	Source directory on floppy disk.
;  spec_files  Filename types to copy.
		
					;Verify the correct volume
	gosub get_volume		       
      					;set source directory
	onerror goto copy_failed
	cd var043
					;Print copy message
	if var040 != null print cr cr var040 cr
					;Scroll if necessary
;A.05	cursor old_x,old_y
;	gosub print_welcome1
;A.05	pos old_x,old_y
	set status 1
					;Copy the files
	if var040 != null fcount 0			
	if var040 != null copyb spec_files var042 status var041 
 	if var040 = null move move_x,0
	if var040 = null copyb spec_files status var041 noredraw
	if status != 1 goto copy_failed
return


find_bkgrdir
		       
;This procedure looks for where bkground files should be installed.
;All background files should be installed in the same directory.
;It will look in WIN.INI to find full path.  If OV is being installed,
;user may edit path.
;Inputs:	 
;  var003 - application source drive
;  var072 - MS Windows WIN.INI disk drive.
;  var073 - MS Windows WIN.INI dir.
;
;Outputs:
;  var091 - bkground drive
;  var092 - bkground directory
;  var093 - full bkground path (string in WIN.INI) without a slash at the end

	onerror gosub floppy_out
	changedrive var003
        cd app_inst

	set find_file var072			;Find Win.ini file.
	strcat find_file var073
	if var073 = "\" goto root_winbk		;Skip if file is at root.
	strcat find_file bslash
root_winbk			
	strcat find_file win_ini
	set find_bkgr null
	envstr find_bkgr
	run mdini.exe "getlabelinfo" app_hdr app_bkgrtxt find_file
	if find_bkgr = null goto helpsym_failed
	if find_bkgr = null return		:OV doesn't require path.

	mid var091 find_sym 1 2
	mid var092 find_sym 3 62

	set var093 find_bkgr
	strlen var093 len 
	sub 1 len
	mid var093 var093 1 len

return


find_neededfile	
		  
;This procedure looks for the existence of given file
;If file is not found, then it will recycle until user quits.
;This routine can be fooled by multiple versions of windows, or
;existence of non windows programs of the same name.
;
;Inputs:
;  var074 - expected disk drive
;  var075 - expected directory				
;  needed_file - file trying to find
;  needed_file2 - second file trying to find
;Outputs:
;  var074 - actual disk drive
;  var075 - actual directory

	gosub print_welcome

	print cr cr cr filelook	  	     ;Print 'Looking for file' message

	set status 0			;If drive exists, go to that drive.
	size var074 status
	if status = 0 goto need_file
	changedrive var074
	cd \

	exist var075 status		    ;If dir exists, go to that dir.
	if status != 2 goto need_file
	cd var075
				
	exist needed_file status		;Check for file1.
	if status != 1 goto need_file
	if needed_file2 = null goto find_needfile1   ;Don't check another file.
	exist needed_file2 status	       	;Check file2 in the same path.

	if status = 1 goto find_needfile1	;File(s) verified.

need_file

	move 0, -3   
		
	set var022 3

 	set var018 box_stitle1
 	set var019 box_stitle2
 	set var020 box_stitle3
 	set var021 box_stitle4

	set var014 need_file1
	set var015 need_file2
	set var016 need_file3
	set var017 need_file4

	set var023 var074		;Set default path for user to edit.
	strcat var023 var075
	gosub get_info
	mid var074 var023 1 2
	mid var075 var023 3 62
	
	goto find_neededfile

find_needfile1
return

install_bkground
		    
;This procedure copies background files into the Bkground directory 

; change to the second disk to pick up the background files.

	set var042 var093		; set copy destination

	set var043 app_app		; set copy source
        strcat var043 app_bkgr

	set var076 bkgr_files		; message text parameter

	set var085 bkarc_file		; archive name

	gosub uncomp_files

return

uncomp_files
		    
;This procedure copies background files into the Bkground directory 
;	       
;Inputs: 			
;  var003 - application source disk drive.
;  var093 - full qualified path where application help will be installed.

; change to the second disk to pick up the background files.

	onerror gosub floppy_out
	changedrive var003
	cd \

        set var040 cp_arch5
	gosub copy_files	  ;If copy one file, do not display bar.

	print cr cr ucomp_warn1 cr
	print ucomp_warn2 cr
	print ucomp_warn3 cr cr
	
	changedrive var004
	cd var042
	run var085		  ; execute self extracting archive
	delete var085
return


skip_moreutl
