; GavDocks Dock Icon set installer script
;
; $VER: GavDocks Dock Icons Installer 1.0 (27.11.96)
;
; Will install dock icons or delete previous icon installation
;
; Author : Gavin Dodds
;
; V1.0 : 8/1/97 : First release

(set old_level @user-level)

(user 2)

(set name         "GavDocks"
     vers         "V1.0"
     envfile      "GAVDOCKS"
     assig        (cat name ":")
     sdir         (if (= 1 (exists @icon) )
                    (pathonly (expandpath @icon) )
                    (expandpath @icon)
                  )
    onoroff       (askbool (prompt "\n\nDo you want to install or remove "
                                   "the " name " dock icon set?")
                           (choices "Install" "Remove")
                           (help "Install or Remove?  It's not hard is it?")
                  )
    oldver        (if(exists (tackon "Env:" envfile) )
                    (getenv envfile)
                    ("0.0")
                  )
)

(user old_level)

(delete (tackon "Envarc:" envfile) )
(delete (tackon "Env:" envfile) )

(if (= onoroff 1)
  ( (message "This script will install the " name " " vers " dock icon set "
             "onto your system.\n"
    )
    (if (NOT (exists assig (noreq) ) )
      ( (user 2)
        (set savdir (tackon
                      (askdir (prompt "Please choose a drawer to install "
                                      "the " name " dock icon set into."
                              )
                              (default sdir)
                              (help "Come on it's not that hard is it?\n\n"
                                    "A drawer called " name " will be "
                                    "created in your chosen drawer."
                              )
                      ) name
                    )
        )
        (user old_level)
      )
      (set savdir assig) ;if old installation exists, update it
    ) ;if not exists
    (set @default-dest savdir)
    (copyfiles (source sdir)
               (dest savdir)
               (all)
    )
    (copyfiles (source (cat sdir ".info") )
               (dest (pathonly savdir) )
    )
    (textfile (dest (tackon "Envarc:" envfile) ) (append vers ) )
    (textfile (dest (tackon "Env:" envfile) ) (append vers) )
    (startup name
      (prompt "\n\nAdding an assign to your user-startup to enable "
              "the " name " dock icon set to be found more easily."
      )
      (help "The assign will set " assig " to point to "
            (expandpath savdir) "."
      )
      (command (cat "assign " assig " " (expandpath savdir) ) )
    )
    (makeassign name (expandpath savdir) )
    (exit "The " name " dock icon set can be removed with this script.")
  )
  ( (message "This script will remove the " name " " oldver " dock icon set "
             "from your system.\n"
    )
    (if (exists assig (noreq) )
      ( (working (cat "Removing " name " dock icon set") )
        (set savdir (expandpath assig) )
        (run (cat "assign " assig " REMOVE") )
        (run (cat "delete " savdir " ALL") )
        (delete (cat savdir ".info") )
        (exit "The " name " dock icon set can be reinstalled with this "
              "script."
        )
      )
      ( (abort "You don't appear to have the " assig " assign set up.\n"
              "Either the " name " dock icon set has not been installed or "
              "you have removed the assign, either way this script can't "
              "continue."
        )
      )
    )
  )
)
