; Laceless Icon set installer script
;
; $VER: Laceless Icons Installer 1.0 (27.11.96)
;
; Will install icons and back up old ones, or retrieve backed up old icons
; and disgard Laceless icons.
;
; Author : Gavin Dodds
;
; V1.0 : 27/11/96 : First release

(set old_level @user-level)

(user 2)

(set name         "Laceless"
     vers         "V1.0"
     utname       "ic"
     assig        (cat name ":")
     backdir      (tackon "Sys:Storage/Icons" (cat "Pre_" name) )
     sdir         (tackon (if (= 1 (exists @icon) )
                            (pathonly (expandpath @icon) )
                            (expandpath @icon)
                          ) "Icons"
                  )
    ddir          "Sys:"
    @default-dest ddir
    onoroff       (askbool (prompt "\n\nDo you want to install or remove "
                                   "the " name " icon set?")
                           (choices "Install" "Remove")
                           (help "Install or Remove?  It's not hard is it?")
                  )
    oldver        (if(exists "Env:LACELESS")
                      (getenv "LACELESS")
                      ("0.0")
                  )
    delstore      0
    savdir        "NONE"
    hasic         (run "which iconpos")
)

(user old_level)

(if (= onoroff 1)
  ( (if hasic
      ( (user 2)
        (set decis (askbool (prompt "\nYou do not appear to have the "
                                    "IconPos command on your system.\n\n"
                                    "This script uses IconPos to copy "
                                    "icon images, without disrupting the "
                                    "position of your icons or the sizes "
                                    "of your drawers.\n\n"
                                    "Without IconPos the script will use "
                                    "copy and your icons' extra information "
                                    "will become lost.\n\n"
                                    "Do you want to continue with the "
                                    "installation procedure?"
                            )
                            (Choices "Yes Continue" "No Abort")
                            (help "You can abort now and try and find "
                                  "IconPos, then attemp the installation "
                                  "again.  IconPos is usually found in the "
                                  "C drawer of the Install3.0 disk."
                            )
                   )
        )
        (if (NOT decis)
          (abort "\n\nIf you are looking for the IconPos utility, remember "
                 "it is usually found in the C drawer of your Workbench "
                 "install disk."
          )
        )
        (user old_level)
      )
    )
    (message "This script will install the " name " " vers " icon set onto "
             "your system.\n"
             "Your existing icons will be backed up into " backdir
             " first.\n\n"
             "This directory will be created if it doesn't already exist.\n"
    )
    (if (NOT (exists assig (noreq) ) )
      ( (user 2)
        (if (askbool (prompt "Would you like the " name " icon set "
                             "installed for easy access?\n\n"
                             "An assign will be added to "
                             "your user-startup file to allow the " utname
                             " utility to find the icons."
                     )
                     (choices "Yes" "No")
                     (help "If you choose yes, you will be asked to suppy "
                           "a directory for the " name " icons to be stored "
                           "in.\n\n"
                           "The icons can then be located using an assign "
                           "which will be added to your user-startup file."
                     )
            )
          (set savdir (tackon
                        (askdir (prompt "Please choose a drawer to install "
                                        "the " name " 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
                      )
          )
        ) ;if askbool
        (user old_level)
      )
      (set savdir assig) ;if old installation exists, update it
    ) ;if execute
    (set @default-dest savdir)
  )
  ( (message "This script will remove the " name " " oldver " icon set from "
             "your system.\n"
             "Your old icons will be retrieved up from " backdir ".\n\n"
             "This directory will then be deleted.\n"
    )
    (if (exists assig (noreq) )
      ( (user 2)
        (set delstore (askbool (prompt "Would you like the " name " icon "
                                       "set removed from your " 
                                       (expandpath assig) " drawer?"
                               )
                               (choices "Yes" "No")
                               (help "If you choose \"Yes\" the directory "
                                     (expandpath assig) " will be deleted."
                               )
                      )
        )
        (user old_level)
      )
    )
  )
)

(if (NOT (exists backdir) )
  (if (= onoroff 1)
    ( (complete 0)
      (makedir (pathonly (pathonly backdir) ) (infos) )
      (makedir (pathonly backdir) (infos) )
      (makedir backdir (infos) )
      (complete 2)
    )
    (abort "The backup directory " backdir " does not exist.  Either you "
           "have not installed the " name " icon set or you have deleted "
           "your old icon backups.\nEither way, this script can't continue."
    )
  )
)

(if (= onoroff 1)
  (working "Installing " name " Icons")
  (working "Removing " name " Icons")
)

(set n 0)
(while (set dirname (select n "Prefs"
                              "Prefs/Presets"
                              "System"
                              "Wbstartup"
                              "Devs"
                              "Devs/Datatypes"
                              "Devs/Printers"
                              "Devs/Keymaps"
                              "Devs/Monitors"
                              "Devs/DosDrivers"
                              "Storage"
                              "Storage/Datatypes"
                              "Storage/Printers"
                              "Storage/Keymaps"
                              "Storage/Monitors"
                              "Storage/DosDrivers"
                              "Expansion"
                              "Tools"
                              "Tools/Commodities"
                              "Utilities"
                              ""
                    )
       )
  (set iconame (cat dirname ".info" ) )
  (set destname (pathonly (tackon backdir dirname) ) )
  (if (= onoroff 1)
    ( (if (NOT (exists destname) )
        (makedir destname )
      )
      (if (NOT (exists (tackon backdir iconame) ) )
        ( (copyfiles (source (tackon ddir iconame) )
                   (dest destname)
          )
        )
      )
      (if (NOT hasic)
        (run (cat "iconpos " (tackon ddir iconame)
                  " IMAGE " (tackon sdir dirname)
             )
        )
        (copyfiles (source (tackon sdir iconame) )
                   (dest (pathonly (tackon ddir dirname) ) )
        )
      )
    )
    (copyfiles (source (tackon backdir iconame) )
               (dest (pathonly (tackon ddir dirname) ) )
    )
  )
  (complete (+ (* n 4) 13) )
  (set n (+ n 1) )
)

(if (= onoroff 1)
  (if (NOT (= savdir "NONE") )
    ( (copyfiles (source (pathonly sdir) ) (dest savdir) (all) )
      (copyfiles (source (cat (pathonly sdir) ".info") )
                 (dest (pathonly (expandpath savdir ) ) )
      )
      (if (NOT (exists assig (noreq) ) )
        ( (makeassign name savdir)
          (startup name
            (prompt "Adding assign to s:user-startup")
            (help "This will add the correct assign to your s:user-startup "
                  "file, so that the " utname " utility can find the icons."
            )
            ( (command (cat "assign " assig " " savdir ) )
            )
          )
        )
      )
    )
  )
  ( (message "\n\nDeleting the " backdir " directory.")
    (run (cat "delete " backdir " ALL") )
    (delete (cat backdir ".info") )
    (if (= delstore 1)
      ( (message "\n\nDeleting the " (expandpath assig) " directory.")
        (set deldir (expandpath assig) )
        (run "assign " assig " REMOVE")
        (if (exists assig (noreq) )
          (message "Assign removal didn't work!")
        )
        (run (cat "delete " deldir " ALL") )
        (delete (cat deldir ".info" ) )
        (message "\n\nYour " deldir " directory has been "
                 "deleted.\n"
                 "You will have to remove the " assig " assign from your "
                 "S:user-startup file yourself."
        )
      )
    )
  )
)

(complete 100)

(delete "Envarc:LACELESS")
(delete "Env:LACELESS")

(if (= onoroff 1)
  ( (textfile (dest "Envarc:LACELESS") (append vers ) )
    (textfile (dest "Env:LACELESS") (append vers) )
    (exit "The " name " Icon set can be removed and your old icons restored "
          "with this script."
    )
  )
  (exit "The " name " Icon set can be reinstalled and your old icons backed "
        "up with this script."
  )
)
