;**************************************************************************
; Patch - RayStorm patch script
;
; Copyright © 1998 Andreas Heumann
;
; $Id: Patch,v 1 10/22/1998
;
;     Installer and Installer project icon
;     (c) Copyright 1991-93 Commodore-Amiga, Inc.  All Rights Reserved.
;     Reproduced and distributed under license from Commodore.
;
;     INSTALLER SOFTWARE IS PROVIDED "AS-IS" AND SUBJECT TO CHANGE;
;     NO WARRANTIES ARE MADE.  ALL USE IS AT YOUR OWN RISK.  NO LIABILITY
;     OR RESPONSIBILITY IS ASSUMED.
;
;**************************************************************************
(welcome "Welcome to the " @app-name " patch.\n")

(set #old-vers "2.2")
(set #new-vers "2.22")

; The source directory name
(set #source-dir
 (if (= 1 (exists @icon))
  (pathonly (expandpath @icon))
  (expandpath @icon)
 )
)

;**************************************************************************
; Select directory where RayStorm is installed.
;**************************************************************************
(procedure P_select-directory
 (transcript "Selecting " @app-name ".")
 (set @default-dest
  (askdir
   (prompt "Select directory where " @app-name "is installed.\n")
   (help "Here you have to specify location where " @app-name "is installed.\n")
   (newpath)
   (default #source-dir)
  )
 )
)

;**************************************************************************
; ask if the old file should be saved
;**************************************************************************
(procedure P_save-old
 (if (= 1 (exists (tackon @default-dest "libs/raystormppc.library")))
  (if(askbool
   (prompt "Shall I save the old files?\n")
   (help "The files are saved in the directory 'old_" #old-vers "', if\n."
    "you select no, the old files are deleted.\n"
   )
   (default 0))
   (
    (makedir (tackon @default-dest (cat "old_" #old-vers)))
    (copyfiles
     (source (tackon @default-dest "libs/raystormppc.library"))
     (dest (tackon @default-dest (cat "old_" #old-vers)))
    )
   )
  )
 )
)

;**************************************************************************
; Installatation sequence
;**************************************************************************
(message "This script patches RayStorm version " #old-vers " to version " #new-vers ".\n")

(complete 00)
(transcript "On patching " @app-name " " #old-vers ".")
(P_select-directory)

(complete 10)
(set #choice
 (askchoice
  (prompt "Please select which CPU version you want to patch.\n")
  (help "The patch is only working if you select the correct version.\n")
  (choices "020/881" "040" "060" "PowerPC")
 )
)
(if (= 0 #choice)
 (
  (set #filename "raystorm.library")
  (set #patch "patch881")
 )
)
(if (= 1 #choice)
 (
  (set #filename "raystorm.library")
  (set #patch "patch040")
 )
)
(if (= 2 #choice)
 (
  (set #filename "raystorm.library")
  (set #patch "patch060")
 )
)
(if (= 3 #choice)
 (
  (set #filename "raystormppc.library")
  (set #patch "patchppc")
 )
)

(complete 15)
(P_save-old)

(complete 20)
(working "Patching " (cat "libs/" #filename))
(if (> 0 (run (cat "gpatch " (tackon @default-dest (cat "libs/" #filename)) " " #patch " " (tackon "t:" #filename))))
 (abort "Patch failed! Maybe you tried to patch the wrong version.")
)
(copyfiles
 (source (tackon "t:" #filename))
 (dest (tackon @default-dest "libs"))
)
(delete (tackon "t:" #filename))

(complete 100)
(message "Successfully finished patching of " @app-name ".\n")

;;; All done!

; EOF
