;Install script for Hack Attack III update files
; 1997 Gerard Sweeney
;(v1.0)
;
;Install the main program
;


(procedure P_update_guide
;trim the @endnode out of the original and copy to T:

(set full_path (cat "ha3_dir:" #ha3_letter "/" #ha3_letter ".guide"))
(set temp_guide_path (cat "RAM:T/" #ha3_letter ".guide"))
(set temp_text_path (cat "temp/" #ha3_letter ".txt"))
(set new_temp_guide (cat "RAM:T/TEMP_" #ha3_letter ".guide"))
(set run_main (cat "replace " full_path " ram:t/ "))
(set run_command1 (cat run_main "@endnode  "))
(set run_command2 (cat run_main "@ENDNODE  "))
(set run_command3 (cat run_main "@EndNode  "))
(set run_command4 (cat run_main "@endnode  "))


(run run_command1)
(run run_command2)
(run run_command3)
(run run_command4)


(set Temp_HA3_Guide_Found (exists full_path (noreq)))
(set Temp_New_Guide_Found (exists temp_text_path (noreq)))
(set write_marker 9)


(if (= temp_ha3_guide_found 1)
 (

  (if (= temp_new_guide_found 1)
   (
    (set ha3_guide_found 1)
    (set write_marker 1)
   )
  )

  (if (= temp_new_guide_found 0)
   (
    if (= write_marker 9)
    (
     (set ha3_guide_found 3)
     (set write_marker 1)
    )
   )
  )
 )
)




(if (= temp_ha3_guide_found 0)
 (

  (if (= temp_new_guide_found 1)
   (
    (set ha3_guide_found 0)
    (set write_marker 1)
   )
  )

  (if (= temp_new_guide_found 0)
   (
    if (= write_marker 9)
    (
     (set ha3_guide_found 2)
     (set write_marker 1)
    )
   )
  )
 )
)





;ha3_guide_found = 0 > HA3 index not found, New index found
;ha3_guide_found = 1 > HA3 index found, New index found
;ha3_guide_found = 2 > HA3 index not found, New index not found
;ha3_guide_found = 3 > HA3 index found, New index not found


(if (= ha3_guide_found 1)
(
 (textfile
  (Prompt "Creating a test text file")
  (Help "Help me!!")
  (dest new_temp_guide)
  (include temp_guide_path)
  (append "\n@{B}Update by ")
  (append #hack_author)
  (append ". Version ")
  (append #hack_version)
  (append ". Released on ")
  (append #hack_date)
  (append "@{UB}\n\n\n")
  (include temp_text_path)
  (append "\n@endnode\n")
 )
)
)


(if (= ha3_guide_found 3)
(
 (textfile
  (Prompt "Creating a test text file")
  (Help "Help me!!")
  (dest new_temp_guide)
  (include temp_guide_path)
  (include temp_text_path)
  (append "\n@endnode\n")
 )
)
)


(if (= ha3_guide_found 0)
(
 (textfile
  (Prompt "Creating a test text file")
  (Help "Help me!!")
  (dest new_temp_guide)
  (append "@DATABASE ")
  (append '"')
  (append #ha3_letter)
  (append '"\n')
  (append '@NODE "MAIN" "SPECCY POKES - ')
  (append #ha3_letter)
  (append '"\n')
  (append '@TOC "MAIN"\n\n')
  (append "              HACK ATTACK III - STAND ALONE HACKS UPDATE - ")
  (append #ha3_letter)
  (append "\n\n")
  (append "                                @{U}PICK A GAME@{UU}\n\n")
  (append "\n@{B}Update by ")
  (append #hack_author)
  (append ". Version ")
  (append #hack_version)
  (append ". Released on ")
  (append #hack_date)
  (append "@{UB}\n\n\n")
  (include temp_text_path)
  (append "\n@endnode\n")
 )
)
)


(if (= ha3_guide_found 2)
(
 (textfile
  (Prompt "Creating a test text file")
  (Help "Help me!!")
  (dest new_temp_guide)
  (append "@DATABASE ")
  (append '"')
  (append #ha3_letter)
  (append '"\n')
  (append '@NODE "MAIN" "SPECCY POKES - ')
  (append #ha3_letter)
  (append '"\n')
  (append '@TOC "MAIN"\n\n')
  (append "              HACK ATTACK III - STAND ALONE HACKS UPDATE - ")
  (append #ha3_letter)
  (append "\n\n")
  (append "                           @{B}@{U}SORRY, NO HACKS HERE!@{UU}@{UB}")
  (append "\n@endnode\n")
 )
)
)


  (set copy_command (cat "copy " new_temp_guide " " full_path))
  (run copy_command)
  (delete temp_guide_path)
  (delete new_temp_guide)

)

;end of PROCEDURE P_update_guide




; ******************************************************************
;
; START OF MAIN PROGRAM
;
; ******************************************************************




;VARIABLES
;
;PUT YOUR OWN DETAILS HERE
;hack_author = Your name
;hack_version= The release number (ie. is this your 1st release, 2nd etc)
;hack_date= The date it was released on (I used DD-MM-YY here)

(set #hack_author "Gerard Sweeney")
(set #hack_version 1)
(set #hack_date "14-02-97")

; ******************************************************************
; END OF EDITABLE VARIABLES. DO NOT CHANGE ANYTHING FROM HERE ON
; ******************************************************************


(set #HA3_NOT_INSTALLED 9)
(set new_install 9)

(message "\nWelcome to the main installation program for the update to Hack Attack III.\n\n\nPOKES DETAILS\n\nAuthor:- "#hack_author"\nVersion:- "#hack_version"\nDate:- "#hack_date"\n\n\n\nClick Proceed when ready....")

(set #HA3_INSTALLED
	(askbool
		(prompt "Do you have the original Hack Attack III installed?")
		(help "This is primarily an update to the original Hack Attack III. However, it can also be installed as a stand-alone unit with just these POKEs set up.")
		(choices "No"
                         "Yes")
		(default 0)
        )
)
 

;HA3=0 -> HA3 is installed

(if (= #HA3_INSTALLED 0)
 (
(set #directory
	(askdir
		(prompt "Where do you keep the main Hack Attack III program?)")
		(help "This program has to know where the main Hack Attack III program is kept so that the new POKEs can be copied over, and the menus updated....\n\nNote that only the directories will show up on this requester.. In other words, you won't actually SEE the Hack Attack III file, you just have to know where it is (use a file manager if at all unsure).")
		(default "HA3:")
	)
)

(makeassign "HA3_Dir" #directory)
(set @default-dest #directory)


(set HA3_Found (exists "HA3_Dir:HACK_ATTACK_III.guide" (noreq)))

(if (= HA3_Found 1)
 (
 (set new_install 0)
 )
)


(if (= HA3_Found 0)
 (
 (set #HA3_NOT_Found
	(askbool
		(prompt "This program couldn't find the main Hack Attack III program.\nThis indicates that you have probably selected the wrong directory.\n\nHowever, if you are sure you have sleceted this directory correctly (like perhaps you have already renamed/erased/moved the old Hack Attack III file, it can continue and will just install this as a stand-alone product.\nSo, Are you SURE this is the correct directory?\n\nAnswer:-\n\nYES ..... Installation will continue....\nNO ...... Installation will abort (sorry).")
		(help "Just what it says there.\n\nI may as well take this time to say sorry I couldn't get it to jump back to the start.. I'm new at this script writing lark myself. Maybe if the Amiga had been shipped with a MANUAL for the installer program?!?!?")
		(choices "No. Stop here"
                         "Yes. Carry on regardless")
		(default 0)
        )
)


(if (= #HA3_NOT_Found 0)
 (
 (set INSTALL_GO 1)
 (set new_install 1)
 )
)

(if (= #HA3_NOT_Found 1)
 (
 (exit "Try running this installation program once you have verified where the file HACK ATTACI III is kept.\n\nIf you are convinced you are doing everything properly, run a file manager like DOpus and manually copy the files in the A-Z directories to the matching HA3 directories, and use a text editor to update the A-Z menus" (QUIET))
)
)
)
)
)
;end of "YES" option

(if (= #HA3_INSTALLED 1)
 (
(set #HA3_NOT_INSTALLED
	(askbool
		(prompt "This is an update to Hack Attack III. However, it can be used by iteslf (a sort of mini POKE guide with these POKEs. \n\nDo you want to continue and install this update by itself, or abort?\n\nAnswer:-\n\nYES ..... Installation will continue....\nNO ...... Installation will abort (sorry).")
		(help "Just what it says there.\n\nI may as well take this time to say sorry I couldn't get it to jump back to the start.. I'm new at this script writing lark myself. Maybe if the Amiga had been shipped with a MANUAL for the installer program?!?!?")
		(choices "No. Stop here"
                         "Yes. Install it")
		(default 0)

)
)
)
)
)

(if (= #HA3_NOT_INSTALLED 0)
 (
(set new_install 1)
(set #directory
	(askdir
		(prompt "Where do you want to install the POKE Guide?)")
		(help "Select somewhere you want to install the GUIDE?\n\nNote that only the directories will show up on this requester...")
		(default "HA3:")
)
)

(makeassign "HA3_Dir" #directory)
(set @default-dest #directory)

(run "copy temp/POKE_GUIDE.guide ha3_dir:")
(run "copy temp/POKE_GUIDE.guide.info ha3_dir:")
)
)

(if (= #HA3_NOT_INSTALLED 1)
 (
 (exit "You have aborted\n\nYou can either re-install this as a stand alone product, or install Hack Attack III and then re-run this installation program.\n\nYou can get Hack Attack III from Aminet under misc/emu/acs-ha3.lha. It's on Aminet 5" (QUIET))
 )
)

(makeassign "HA3_Dir" #directory)
(set @default-dest #directory)

;COPY THE FILES TO THE ASSIGNED DIRECTORY (JUST THE POKES JUST NOW)

(copyfiles
    (prompt "Copying New Hack Files")
    (help @copyfiles-help)
    (source "files")
    (dest "HA3_Dir:")
    (all)
    )

;Copy LIBS

(copylib
   (prompt "Copying REXXARP.Library to Libs:" )
   (help @copyfiles-help)
   (source "lib/rexxarplib.library")
   (dest "Libs:")
   (infos)
   (confirm)
)

(copylib
   (prompt "Copying SCREENSHARE.Library to Libs:" )
   (help @copyfiles-help)
   (source "lib/screenshare.library")
   (dest "Libs:")
   (infos)
   (confirm)
)


;copy the ZXAMRUN AREXX command

;ZXAMEXISTS.... 9=Does not exist - copy
;               1=Delete old version, set to 9
;               2=Rename old version
;               3=Rename old version, set to 9

(set zxamcopy 1)
(set #zxamexists 9)

(set zxamfound (exists "rexx:zxam_run.rexx" (noreq)))

(if (= zxamfound 1)
 (
 (set #zxamexists
	(askoptions
		(prompt "A script called ZXAM_RUN.DOPUS already exists in your REXX: directory!")
		(help "It could be that this is from a previous installation of the program, or it could be an earlier version of the script.\nIf you are really sure that you don't need the version currently installed in the REXX: directory on your HD, then tick the first option ('Copy installation version').\nIf you want to copy the installation version, but keep a backup copy of the original version currently installed on your HD, tick both boxes.\nIf you want to only keep the version on your HD, don't tick either box'")
		(choices "Install version from this installation."
                         "Rename current version of script.")
		(default 0)
        )
 )
)
)

;If both ticked, rename prog. Set flag to 1

(if (= #zxamexists 3)
(
                (rename "rexx:zxam_run.rexx" "rexx:zxam_run-backup.rexx")
                (delete "rexx:zxam_run.rexx")
                 (copyfiles
                 (prompt "copying")
                 (source "rexx")
                 (dest "rexx:")
                 (all)
                 (infos)
                 )
))

(if (= #zxamexists 2)
(
                (rename "rexx:zxam_run.rexx" "rexx:zxam_run-backup.rexx")
))


(if (= #zxamexists 1)
(
                (delete "rexx:zxam_run.rexx")
                 (copyfiles
                 (prompt "copying")
                 (source "rexx")
                 (dest "rexx:")
                 (all)
                 (infos)
                 )
))


(if (= #zxamexists 9)
(
                 (copyfiles
                 (prompt "copying")
                 (source "rexx")
                 (dest "rexx:")
                 (all)
                 (infos)
                 )
))


(if (= #zxamexists 0)
(
(message "The installer version of the script has not been copied")
;do absolutely nothing at all hehehe
))



;update the menu for each letter (this will be good!)

(if (= new_install 1)
 (
  (message "This program will now create new sub-index files in the directory you selected\n\nThis may take a few moments, so please be patient.")
 )
)


(if (= new_install 0)
 (
  (message "This program will now update the existing Hack Attack III sub-indexes by adding the new hacks to the bottom of them.\n\nThis may take a few moments, so please be patient.")
 )
)


(set #ha3_letter "A")
(P_update_guide)
(set #ha3_letter "B")
(P_update_guide)
(set #ha3_letter "C")
(P_update_guide)
(set #ha3_letter "D")
(P_update_guide)
(set #ha3_letter "E")
(P_update_guide)
(set #ha3_letter "F")
(P_update_guide)
(set #ha3_letter "G")
(P_update_guide)
(set #ha3_letter "H")
(P_update_guide)
(set #ha3_letter "I")
(P_update_guide)
(set #ha3_letter "J")
(P_update_guide)
(set #ha3_letter "K")
(P_update_guide)
(set #ha3_letter "L")
(P_update_guide)
(set #ha3_letter "M")
(P_update_guide)
(set #ha3_letter "N")
(P_update_guide)
(set #ha3_letter "O")
(P_update_guide)
(set #ha3_letter "P")
(P_update_guide)
(set #ha3_letter "Q")
(P_update_guide)
(set #ha3_letter "R")
(P_update_guide)
(set #ha3_letter "S")
(P_update_guide)
(set #ha3_letter "T")
(P_update_guide)
(set #ha3_letter "U")
(P_update_guide)
(set #ha3_letter "V")
(P_update_guide)
(set #ha3_letter "W")
(P_update_guide)
(set #ha3_letter "X")
(P_update_guide)
(set #ha3_letter "Y")
(P_update_guide)
(set #ha3_letter "Z")
(P_update_guide)
(set #ha3_letter "NUM")
(P_update_guide)

(set #HA3_ASSIGN 9)
(set exit_mess "Your updated HACK ATTACK III")
(set assign_stat "was NOT")

(if (= new_install 1)
 (
  (set exit_mess "Your new stand alone POKE GUIDE")
  (set #HA3_ASSIGN
	(askbool
		(prompt "Do you want an assign added to the USER-STARTUP file which points to the directory you have just installed the stand-alone POKE Guide to?\n\n** NOTE ** The assign is NOT required. The POKE Guide will work perfectly well without it - it is just for your convenience.")
		(help "Just adds a simple line to the S:USER-STARTUP file which points an assign to where you have just installed the stand-alone POKE Guide to. It just saves you having to trawl through directories.")
		(choices "No"
                         "Yes")
		(default 0)
        )
  )

  (if (= #HA3_ASSIGN 0)
   (
    (set #ASSIGN_NAME
     (askstring
      (prompt "Please enter the name of the assign you want. Be sure it does not clash with any other assigns!!\n\nIMPORTANT!!\n\nDo NOT put any colon (:) mark at the end. JUST the name....")
      (help "Enter the name of the assign you want to give for this directory.\n\n. Be careful you do not select a name which is already used elsewhere (like ENV for example)")
      (default "HA3_SA")
     )
    )
    (makeassign #assign_name #directory)    
    (set assign_line (cat "Assign " #ASSIGN_NAME ": " #directory "\n"))
    (set assign_stat "was")

    (startup "POKE Guide - STAND ALONE"
     (prompt "Updating USER-STARTUP")
     (help "Adding line to S:USER-STARTUP which will create an assign")
     (command assign_line)
    )
)
  )
 )
)

  (set Dameon_found_message " ")
  (set Dameon_end_message " ")
(set start_message "\n\n\nYou can now just double click its icon to start. Or you can read the guide docs file supplied")
;
;
;
; UPDATE TOOLS DAEMON MENU....

(set DAEMON_FOUND (exists "sys:wbstartup/toolsdaemon" (noreq)))

(set bye_bye (cat exit_mess " can be found in the directory\n" #directory "\n\nAn assign " assign_stat " added to S:USER-STARTUP\n\n\nYou can now just double click its icon to start, or you can read the guide docs file supplied"))

(if (= daemon_found 1)
 (
  (set Dameon_found_message "Your ToolsDaemon menu was ")
  (set #UPDATE_DAEMON
	(askbool
		(prompt "This progam has found Tools Daemon in your SYS:WBSTARTUP drawer.\n\nWould you like to add a menu pointing to the Guide?\n\n\n(Your old settings file will be backed up)")
		(help "The program found the file TOOLSDAEMON in your SYS:WBSTARTUP drawer, and can add a menu to your existing ToolsDaemon setup which will point to your newly installed Guide.\n\nNote. If you say yes, the change will not be apparent until you either reboot the Amiga, or go to the TOOLSPREFS option under TOOLS on Workbench, and select SAVE when the setup screen appears.")
		(choices "No"
                         "Yes")
		(default 0)
        )
  )

(set update_daemon_message "NOT")
(if (= #update_daemon 0)
(

(set start_message "\n\n\nYou can now just double click its icon or use the menu in your ToolsDaemon to start. Or you can read the guide docs file supplied")
(set daemon_run_main (cat "replace sys:s/ToolsDaemon.menu ram:t/ "))
(set daemon_run_command1 (cat daemon_run_main "END TITLEHACKERS|_ANONYMOUSPOKEHACKERS|_ANONYMOUSGUIDEHACKERS|_ANONYMOUSMENU\n"))
(run daemon_run_command1)

(set daemon_run_main (cat "replace ram:t/ToolsDaemon.menu ram:env/ "))
(set daemon_run_command1 (cat daemon_run_main 'HACKERS|_ANONYMOUS " "'))
(run daemon_run_command1)

(set #POKE_NAME "Hack Attack III")
(set #POKE_FILENAME "Hack_Attack_III.Guide")

(if (= new_install 1)
(
 (set #POKE_NAME "POKE Guide")
 (set #POKE_FILENAME "POKE_GUIDE.Guide")
)
)

;(message "UPDATING S:TOOLSDAEMON.Menu")

 (textfile
  (Prompt "Creating a test text file")
  (Help "Help me!!")
  (dest "RAM:T/ToolsDaemon.menu_TEMP")
  (include "ram:env/ToolsDaemon.menu")
  (append "	ITEM ")
  (append #POKE_NAME)
  (append "\n")
  (append '	(WB) "')
  (append #directory)
  (append "/")
  (append #POKE_FILENAME)
  (append '" []\nEND\n')
 )
(run "rename sys:s/ToolsDaemon.menu sys:s/toolsdaemon.menu_bak")
(run "copy ram:t/toolsdaemon.menu_temp sys:s/ToolsDaemon.Menu")
(message "\nTOOLSDAEMON UPDATED\n\nNote. The change to your ToolsDaemon will not be apparent until you either reboot the Amiga, or go to the TOOLSPREFS option under TOOLS on Workbench, and select SAVE when the setup screen appears.\n\n\nYour old settings have been saved as S:TOOLSDAEMON.MENU_BAK\n\nThis install utility will now try to load the PREFS program for ToolsDaemon. If successful, just click SAVE.")
(run "sys:prefs/toolsprefs")
)
)
)
(set DAEMON_END (cat daemon_found_message update_daemon_message " updated."))
)


(set bye_bye (cat exit_mess " can be found in the directory\n" #directory "\n\nAn assign " assign_stat " added to S:USER-STARTUP\n\n" daemon_end_message start_message))


;Clean up your mess young man!

(makeassign "HA3_Dir")
(run "delete RAM:T/TOOLS#?.#?")
(run "delete RAM:ENV/TOOLSDAEMON.MENU")
(exit bye_bye (QUIET))
