;COPYRIGHT Hewlett-Packard Company 1987, 1988, 1989
; Routines to install an application:
;
; welcome_init
; print_source
; need_win
; find_winini
; find_helpdir
; get_volume
; check_volume
; build_dirs
; file_copy
; expand_files
; get_info      
; get_response
; get_edit
; print_ins
; print_screen
; print_welcome
; stash_screen
; rebuild_screen
; get_winini
; get_app

goto skip_setutl
	
welcome_init

;This procedure initiates the installation and
;determines the source and destination drives.
;
;
;Outputs:
;  var003 - gets the source drive (and a colon).
;  var004 - gets the application destination drive (and a colon).
;  var005 - gets the application destination directory.
;  var070 - gets the MS Windows drive (and a colon).
;  var071 - gets the MS Windows directory.
;  var072 - gets the MW Windows win.ini drive (and a colon).
;  var073 - gets the MS Windows win.ini directory.
							     
					;Get source drive now
	onerror gosub floppy_out
	whichdrive var003
	strcat var003 colon
					;Go get drive info
	set var004 defdrive
	strcat var004 colon
	set var005 app_dir
	set var070 var004
	set var071 win_path
	set var072 var004
	set var073 win_path
	set var172 var004
	set var173 win_path
					;List source info
	gosub print_source
return
	
print_source

;This procedure will list all the disks required for installing the application.
;  Maximum 3 source discs are expected now.
;
;Inputs:			
;  var002 - application name.

	gosub print_welcome
	pos 0,4
	print app_instruct
	
	; 1st disk:
	pos 4,6
	diskette 1
	pos 22,7
	print app_name1 app_ext1
 	if app_name2 = "" goto print_source1

	; 2nd disk:
	pos 6,10
	diskette 1
	pos 24,11
	print app_name2 app_ext2
 	if app_name3 = "" goto print_source1

	; 3rd disk:
	pos 8,14
	diskette 1
	pos 26,15
	print app_name3 app_ext3
print_source1
	; KLP - 1/15/92
	; Add additional requirements to information screen
	pos 0,18
	print "   You will need " str_disk_space " MB of disk space for !2" cr cr
	gosub get_response

	; KLP - 1/23/92
	; Add another screen for additional requirements
	gosub print_welcome
	pos 0,3
	print "   You will also need to know the following:" cr
	print "      - The Network Protocol to use for !2" cr
	print "        (Either NetWare or TCP/IP) and the path to these files." cr
	print "      - The Path to " win_name cr
	print "      - The Path to " ov_name cr
     	gosub get_response

return

find_helpdir
		       
;This procedure looks for where help file should be installed.
;All help files should be installed in the same directory.
;For Openview applications, it will look in WIN.INI to find
;out where help files should be installed.

;Inputs:	 
;  var003 - application source drive
;  var072 - MS Windows WIN.INI disc drive.
;  var073 - MS Windows WIN.INI dir.
;
;Outputs:
;  var006 - help dir (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_win		;Skip if file is at root.
	strcat find_file bslash
root_win
	strcat find_file win_ini
	set section_str app_hdr
	strcat section_str app_hlptxt
	set find_hlp ""
	update find_file section_str 15 find_hlp

	if find_hlp = "" goto help_failed
	set var006 find_hlp
	strlen var006 len 
	sub 1 len
	mid var006 var006 1 len

return

get_volume

;This procedure will prompt for a new volume to be 
;   loaded and verify that the correct volume was loaded.
;
;Inputs:
;  var003 - source disc drive.
;  var050 - Name of the volume.
;  var051 - Volume label.

					;Check if volume already there
	onerror gosub floppy_out
 	set var052 ""	
	label var003 var052
 	if var052 = var051 return
					;Select mount volume message
	set var014 box_disc1
	set var015 box_disc2
	set var016 box_disc3
	set var017 box_disc4
					;Fill in the box's choices
 	set var022 2
					;Ask user to load the volume
	gosub print_screen
 	gosub rebuild_screen
					;Verify correct volume loaded
check_volume
	set var052 ""
	onerror gosub floppy_out
	label var003 var052
 	if var052 = var051 return
					;Wrong volume.  Ask again
	bell
	set var053 vol_there
	if var052 = "" set var053 vol_not
	if var052 = "" set var052 vol_nolabel

	set var014 vol_again1
	set var015 vol_again2
	set var016 vol_again3
	set var017 vol_again4

	gosub print_screen
 	gosub rebuild_screen
					;Verify the volume again
	goto check_volume	
	
;return

build_dirs
		
;This procedure builds the directory structure required by application.
;
;Inputs:
;  var004 - application drive.
;  var005 - application dir.
;  var006 - help dir (string in WIN.INI) without a slash at the end
;  var007 - application private dir
;  var032 - help dir build flag
;
;Outputs:	
;  var006 - application help destination path
;  var007 - application private destination path
;  var090 - application private destination path for hidden files
;  var091 - application private destination for MIB browser files
	
					;Print setting up disc message
	print cr cr makedir
					;Check & create application dir
	set var030 var004
	set var031 var004
	strcat var031 var005
					;Set drive to default check for a file

					;build \OV
build_dirs1
	onerror gosub app_drive_error
	changedrive var030
	cd \
	exist var031 status
	if status = 1 goto file_there
        if status = 2 goto build_dirs2
					;Create dir
	mkdir var031 status
	if status != 0 gosub md_failed
					;build \OV\APP
build_dirs2	  
	if app_prv = "" goto build_dirs3
 	set var007 var004
	strcat var007 var005  
 	strcat var007 app_prv
	set var030 var004
	set var031 var007

 	exist var031 status
	if status = 1 goto file_there
	if status = 2 goto build_dirs3

	mkdir var031 status
	if status != 0 gosub md_failed
					;build \OV\APP1 (for hidden files)
build_dirs3	  
	if app_prvhid = "" goto build_dirs31
 	set var090 var004
	strcat var090 var005  
 	strcat var090 app_prvhid
	set var030 var004
	set var031 var090

 	exist var031 status
	if status = 1 goto file_there
	if status = 2 goto build_dirs31

	mkdir var031 status
	if status != 0 gosub md_failed
					;build \OV\APP1 (for hidden files)
build_dirs31	  
	if app_mibsdir = "" goto build_dirs4
 	set var091 var004
	strcat var091 var005  
 	strcat var091 app_mibsdir
	set var030 var004
	set var031 var091

 	exist var031 status
	if status = 1 goto file_there
	if status = 2 goto build_dirs4

	mkdir var031 status
	if status != 0 gosub md_failed
					;build \OV\HELP
build_dirs4
					;Create help dir if need
	if var006 != "" goto build_dirs5
 	set var006 var004
	strcat var006 var005
 	strcat var006 app_hlp
build_dirs5
	if var032 = "" goto build_dirs6
	set var030 var004
	set var031 var006
 	exist var031 status
	if status = 1 goto file_there
	if status = 2 goto build_dirs6

	mkdir var031 status
	if status != 0 gosub md_failed
	goto build_dirs6
file_there	
					;Setup prompts for the box
	set var022 2		
					;Assign box instructions
	set var014 box_error1
	set var015 box_error2
	set var016 box_error3
	set var017 box_error4
					;Go tell the user
	gosub print_screen
 	gosub rebuild_screen
delete_it				;Delete the file & create the dir
	delete var031 status
        goto build_dirs1
build_dirs6

return	

file_copy
; This procedure controls copying all files from floppy to hard disk
        onerror gosub lharc_failed
        set copyprog var003
        strcat copyprog "\install\lharc.exe"
        set target var074
        strcat target var075
        set source var003
        strcat source bslash

        ; decompress libraries
        set var046 "libraries"
        set var042 target
        set var043 source
        strcat var043 "app.lzh"
        set always_copy 1
	set recursive 0
        gosub expand_files

	; Get Disk #2 in Source Drive
	set var050 app_name2
	set var051 app_label2
	gosub get_volume

        ; decompress executables
        set var046 "programs"
        set var042 target
        strcat var042 "\devmgr"
        set var043 source
        strcat var043 "devmgr.lzh"
        set always_copy 1
	set recursive 0
        gosub expand_files

	; Copy Libraries as appropriate for this installation
	gosub position_dlls

	; Get Disk #1 in Source Drive
	set var050 app_name1
	set var051 app_label1
	gosub get_volume

        ; decompress help
        set var046 "help"
	set var042 var006
        set var043 source
        strcat var043 "help.lzh"
        set always_copy 1
	set recursive 0
        gosub expand_files

        ; decompress symbol files (for symbols get WIN.INI pointer)
        set var046 "device symbol files"
        set ret_string ""
        set hkey_string app_hdr
        strcat hkey_string ov_symbol_key
        set var008 var072
        strcat var008 var073 bslash win_ini
        update var008 hkey_string 15 ret_string
        if ret_string = "" goto hksymbol_def
        strlen ret_string len
        sub 1 len
        mid var042 ret_string 1 len
        goto hkcopy_symbol
hksymbol_def
        set var042 target
        strcat var042 "\symbols"
hkcopy_symbol
        set var043 source
        strcat var043 "symbols.lzh"
        set always_copy 1
	set recursive 0
        gosub expand_files

        ; decompress AD files
        set var046 "sample files"
        set var042 target
        strcat var042 "\devmgr\files"
        set var043 source
        strcat var043 "files.lzh"
	; Before copying over these files, rename to IP/IPX naming convention
        gosub rename_config_files
        set always_copy 0
	set recursive 0
        gosub expand_files

        ; decompress MIBs
        set var046 "3rd-party object lists"
        set var042 target
        strcat var042 "\devmgr\mibs"
        set var043 source
        strcat var043 "mibs.lzh"
        set always_copy 0
	set recursive 1
        gosub expand_files

        if net_type = net_tcpip goto no_nw_files
        ; decompress NetWare Files
        if net_type != net_netware goto end_copyem
        set var046 "NetWare Files"
        set var042 var070
        strcat var042 var071 "\system"
        set var043 source
        strcat var043 "nwfiles.lzh"
        set always_copy 0
	set recursive 0
        gosub expand_files
     no_nw_files

        ; Install the Icon Group file to the WINDOWS directory
        set var042 var070
        strcat var042 var071
        set var043 source
        changedrive var043
        cd var043
	print "~~Installing " group_file " on !42 . . .~"
        copy group_file var042 status
        if status != 1 print "     Error copying " group_file " to !042." cr

end_copyem
return

; This function will copy the various versions of DLLs into the correct name
; for the installation being done.
; KLP - 01/15/92
;
; Variables on Input:
;    var042 - full path {drive:dir} to libraries
position_dlls
        print "~Positioning Libraries . . .~"
        ; Build full path to Libraries destination, in the OV directory
        set dest_dir var074
        strcat dest_dir var075 bslash

        ; Copy over correct version of NET.DLL
        set dest_file "NET.DLL"
        if net_type = net_netware goto ipx_dll
        set src_file "devmgr\netip.dll"
        if app_name = emulatr   set src_file "devmgr\netipe.dll"
        goto copy_net
     ipx_dll
        set src_file "devmgr\netipx.dll"
        if app_name = emulatr set src_file "devmgr\netipxe.dll"
     copy_net
        gosub copy_lib
        print dest_file " Created " cr 

        ; Create a backup copy of NETMGR.DLL with name NETMGRN.DLL
        set dest_file "NETMGR.DLL"
        set src_file "devmgr\netmgrn.dll"
        if app_name = emulatr set src_file "devmgr\netmgre.dll"
        gosub copy_lib
        print dest_file " Created " cr 
return

; This function will copy old versions of RACKS, NETWORKS, and GENSNMP files
; to the new naming convention.  Old RACKS is now RACKS.IP or RACKS.IPX ...
; KLP - 02/14/92
;
; Variables on Input:
;    var042 - full path {drive:dir} to FILES directory
rename_config_files
        print cr "Checking for old Manager Config Files . . ." cr
        ; Modify full path to FILES by adding bslash if necessary
        set dest_dir var042
        if dest_dir != "\" strcat dest_dir bslash

        ; if old RACKS file exists, copy it to RACKS.IP
        set src_file dest_dir
        strcat src_file "RACKS"
        set dest_file dest_dir
        strcat dest_file "RACKS.IP"
        exist src_file status
	if status = 1 print "   " src_file " renamed " dest_file cr
	if status = 1 rename src_file dest_file

        ; if old NETWORKS file exists, copy it to NETWORKS.IP
        set src_file dest_dir
        strcat src_file "NETWORKS"
        set dest_file dest_dir
        strcat dest_file "NETWORKS.IP"
        exist src_file status
	if status = 1 print "   " src_file " renamed " dest_file cr
	if status = 1 rename src_file dest_file

        ; if old GENSNMP file exists, copy it to GENSNMP.IP
        set src_file dest_dir
        strcat src_file "GENSNMP"
        set dest_file dest_dir
        strcat dest_file "GENSNMP.IP"
        exist src_file status
	if status = 1 print "   " src_file " renamed " dest_file cr
	if status = 1 rename src_file dest_file

        ; if old COMUNITY file exists, copy it to COMUNITY.IP
        set src_file dest_dir
        strcat src_file "COMUNITY"
        set dest_file dest_dir
        strcat dest_file "COMUNITY.IP"
        exist src_file status
	if status = 1 print "   " src_file " renamed " dest_file cr
	if status = 1 rename src_file dest_file
return

; This function will do the copy of DLLs and check the return code
; KLP - 01/15/92
;
; Variables on Input:
;    dest_dir  - full path {drive:dir} to libraries, including bslash
;    src_file  - name of source DLL
;    dest_file - name of destination DLL
copy_lib
        set dfile dest_dir
        strcat dfile dest_file
        set sfile dest_dir
        strcat sfile src_file
        set cp_prog var003			; Build full path to
        strcat cp_prog "\install\cp.exe"	; executable cp.exe
        runx cp_prog sfile dfile
        getexitcode exit_val
        if exit_val != 0 gosub dll_copy_error
return

; This function is the error routine for COPY_LIB
;
; KLP - 01/15/92
dll_copy_error
        print "File copy from " sfile " to " dfile " failed~"
        print "Make sure " dfile " is not write-protected~"
        mid drive target 1 2
        free drive space
        if space < 200 print "Drive " drive " may be full~"
        set status 0
        goto quit
;return

expand_files
;  Inputs:
;    var042 - destination directory on the hard disk
;    var043 - source file on the floppy
;    var046 - description of files being expanded
        ; verify volume

        ; display message
	print "~~Installing !46 on !42 . . .~"
        ; cd to target
	changedrive var042
	cd var042
	set copy_opts "x -mn"
	if always_copy = 1 strcat copy_opts "c"
	if recursive = 1 strcat copy_opts "r"
	run copyprog copy_opts var043
return
	
get_info      

;This procedure displays where an application should be installed
;and where the dependent system should be.  It displays edit line
;and sub-titles also.
;
;Inputs:		
;  var015 to var021 - titles and sub-titles to be displayed
;  var022 - edit control flag
;  var023 - edit line info

					;Print the title (instructions)
	gosub print_ins
					;Print the edit line
	pos box_left,box_editln
	use_pen main_pen
	print var023
	clear_pen
					;Print the sub-title (instructions)
	if var022 = 2 goto get_info1
	show_window subt_win
	use_pen info_pen
	pos box_left,box_stitle
	print var018 cr
	move box_left,0
	print var019 cr
	move box_left,0		    
	print var020 cr
	move box_left,0
	print var021 cr
	clear_pen
get_info1
	gosub print_window

return
	
get_response

;This procedure gets dummy response.

	pos 42,23
	use_pen main_pen
	print screen_instruct
	clear_pen
        echo off
	input 1 dummy
return
	
get_edit

;This procedure gets user input on edit line.
;
;Inputs:
;  var023 - default edit line info
;
;Outputs:
;  var023 - user edit line info

	set box_defx box_left
	set box_defy box_editln

	pos box_defx,box_defy

	echo on
	use_pen main_pen
	input 60 var023 var023
	clear_pen
	upshift var023

	mid cmd var023 2 1
	if cmd != colon bell
	if cmd != colon goto get_edit

return
	
print_ins

;This procedure displays titles only.
;
;Inputs:
;  var014 to var017 - titles to be displayed

	gosub stash_screen
	gosub print_welcome
					;Print the title (instructions)
	show_window info_win
	use_pen info_pen
	pos box_left,box_title
	print var014 cr
	move box_left,0
	print var015 cr
	move box_left,0		    
	print var016 cr
	move box_left,0
	print var017 cr	
	clear_pen

return
	
print_window
	set win_label main_label
     redo_get_edit
	gosub display_main_win

	if var022 = 1 goto l_ceq
	if var022 = 2 goto l_cq
	; expect that var022 is 3
	form_entry edit_val edit_str
	form_entry quit_val quit_str
   goto l_end_entries
l_ceq
	form_entry continue_val continue_str
	form_entry edit_val edit_str
	form_entry quit_val quit_str
   goto l_end_entries
l_cq
	form_entry continue_val continue_str
	form_entry quit_val quit_str
l_end_entries
	form_read val str
	clear_pen
	if val = quit_val goto quit0
	if val = continue_val goto end_prt_win
	if val = edit_val gosub get_edit
	if val = edit_val goto end_prt_win
	gosub restore_edit_area
	goto redo_get_edit
     end_prt_win
return

display_main_win
	show_window main_win
	use_pen main_pen
	pos label_pos box_top
	print win_label
	set form_x1 box_left
	set form_y1 box_top
	set form_x2 box_right
	set form_y2 box_end
	add 1 form_x1
	add 1 form_y1
	sub 1 form_x2
	sub 1 form_y2
	form_def form_x1 form_y1 form_x2 form_y2 1
return
	
print_screen

;This procedure displays titles and user selections.
;
		   
	gosub print_ins			       
	gosub print_window

return

print_welcome

;This procedure will clear the screen and print the title 
;  in the upper left corner.  An alternate entry point
;  (print_welcome1) will print the title without clearing 
;  the screen.
;
;Inputs:
;  var001 - application version.
;  var002 - application name.

	cls
print_welcome1
	set clear_ln "                                                                                "
	pos 0,0
	print clear_ln
	pos 0,1
	print clear_ln
	use_pen title_pen
	pos 0,0		 
	print clear_ln
	pos 0,0		 
	print welcome
	clear_pen

return

stash_screen

;This procedure will save the screen &
;cursor position into memory.
;
;Outputs:
;  save_x - save the original cursor
;  save_y - save the original cursor

					;Save the cursor
	cursor save_x,save_y
					;Save the screen lines
	set count 0
	saveloop
		pos 0 count
		savline line[count]
		add 1 count
	if count < 24 goto saveloop
	
					;Clear the screen
	goto print_welcome

return

rebuild_screen

;This procedure is the companion to stash_screen.  
;It will restore the screen & cursor.
;
;Inputs:
;  save_x - the original cursor
;  save_y - the original cursor
 
        gosub print_welcome 
					;Restore the screen
	set count 1
	restloop
		pos 0 count
		print line[count]
		add 1 count
	if count < 24 goto restloop
					;Restore the cursor position
	pos save_x,save_y

return	 
	
get_winini
	set win_file win_ini		; Looking for 'win.ini' file
	set var008 win_file		; Looking for 'win.ini' file
	gosub get_winfile		; get users input on where it is
	set var072 winfile_drv		; var072 gets drive of 'win.ini'
	set var073 winfile_dir		; var073 gets directory of 'win.ini'
return

get_sysini
	set win_file system_ini
	set var008 win_file
	gosub get_winfile
	set var172 winfile_drv
	set var173 winfile_dir
return

get_winfile
;This procedure gets the path to a WINDOWS file to update.
;

	set var022 1

	set var014 box_dep1f
	set var015 box_dep2
	set var016 box_dep3
	set var017 box_dep4
				; Edit mode user instructions.
 	set var018 box_stitle1	
 	set var019 box_stitle2
 	set var020 box_stitle3
 	set var021 box_stitle4

	set var023 var070
	strcat var023 var071
	gosub get_info		; Modify path to user's input.
	mid winfile_drv var023 1 2
	mid winfile_dir var023 3 62

	gosub find_winfile

return

find_winfile

;This procedure looks for the existence of MS Windows WIN.INI.
;
;Inputs:
;  winfile_drv - disc drive to MS Windows file to find.
;  winfile_dir - directory to MS Windows file to find.

	gosub print_welcome

	onerror gosub win_drive_error

	;Print "Looking for WINFILE" message
	print cr cr cr "Looking for MS Windows File "
	print win_file " on " winfile_drv  winfile_dir cr

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

	exist winfile_dir status	;If dir exists, go to that dir.
	if status != 2 goto need_winfile	
	cd winfile_dir
					
	set status 0					
	exist win_file status		
	if status = 1 goto find_winfile1	   ;Found WINFILE

need_winfile	
	move 0, -3

	set var022 3

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

        set var100 winfile_drv
        set var101 winfile_dir
	set var014 need_file1
	set var015 need_file2
	set var016 need_file3
	set var017 need_file4

				 ;Set expectant WINFILE path for user to edit.
	set var023 winfile_drv
	strcat var023 winfile_dir
	gosub get_info
	mid winfile_drv var023 1 2
	mid winfile_dir var023 3 62

	gosub rebuild_screen

	goto find_winfile

find_winfile1	  
changedrive var003
cd app_inst

return				
	
get_app
;This procedure gets the OpenView path which must be the path to Help.
;
;Sets (using the [Openview]helpdir entry in win.ini):
;  var004 = Drive to Openview w/colon
;  var005 = Directory to Openview w/o backslash
;
				; Set Help path to application path.
	set var006 var004
	strcat var006 var005
	strcat var006 app_hlp

   	if var032 = "" gosub find_helpdir	

					; Compare front of path.
	strlen app_hlp len1
	strlen var006 len
	sub len1 len
	mid var023 var006 1 len
		
	mid var004 var023 1 2
	mid var005 var023 3 62
		
return

skip_setutl

