; Generic Extractor

(complete 0)
(set requiredKick 33)
(set arcSize 800000)
(set @default-dest "RAM:")
(set level @user-level)
(set finished 0)

(set hello            (cat "\n\n\nThis will extract the " @app-name" archive\nto your chosen location.\n\n\nSelect NOVICE to simply extract\n to RAM: or a floppy drive."))
(set wrongKick        (cat "\n\nWarning, you need at least Kickstart v" requiredKick " (" Kickversion ")\n\nto use " @app-name ".\n\n\nPress 'proceed' to continue anyway;\n\n\n\nBut you won't be able to run the program!"))
(set lowMem           (cat "\nSorry you only have " totalMem " bytes of RAM,\nand you need " arcSize " bytes, to be able\nto extract " @app-name " into RAM:.\n\n\nTry extracting to somewhere else."))
(set extractionError  (cat "lzx reported an error when extracting\n" @app-name " to the destination path " @default-dest ".\n\nThis could either be a problem with how your computer is setup or with the disk itself.\n\nIf problems persist ring 01595 696366 and ask for help." ))
(set noRoom           (cat " bytes free, and\n\n" @app-name " needs " arcSize " bytes."))
(set totalMem (+(dataBase "total-mem"))) ;get total free memory, AND, convert into a integer

;(set @app-name (substr (fileonly @icon) 0 (- (strlen (fileonly @icon)) 4)) ) ;get icon(archive) name minus the ".lzx"

(if (= @app-name "AmiTCP.lzx") ((set arcsize 800000) (set xInstall 1) ))
(if (= @app-name "jfif.lzx") ((set arcSize 150000) (set xInstall 1) ))

(procedure @getdefault-dest
  (set destination (askdir
                      (help @askdir-help)
                      (prompt "Where Do you want " @app-name " extracted to?")
                      (newpath)
                      (default @default-dest)
                     )
  )
  (set @default-dest destination)
)

(procedure @unarc
  (if (AND (= (getDevice @default-dest) "RAM") (> arcSize totalMem))
    (abort lowMem)
(if (AND (> arcSize (getDiskSpace @default-dest))
             (NOT (= (getDevice @default-dest) "RAM")) )
        (abort "\n\nSorry, but " @default-dest " only has\n" (getDiskSpace @default-dest) noRoom)
    )
  )
  (if (> (run unArc) 0) (abort extractionError))
)

(complete 10)
(@getdefault-dest)
(if (NOT (= (substr @default-dest (- (strlen @default-dest) 1) 1) ":")) (set @default-dest (cat @default-dest "/")))
(set unArc (cat "lzx x -m -x " @app-name " " @default-dest ))
(working "\n\n\n\nExtracting " @app-name " to " @default-dest ",\n\nplease wait....")
(@unarc)
(complete 100)

(if (= xInstall 1) (set xInstall (cat @app-name " should be installed from your chosen destination, otherwise it may not work correctly")) )
(message "Installation complete!\n\n\n\n" @app-name " has been successfully extracted,\nand can be found in " @default-dest ".\n\n\n" xInstall)

(exit (quiet)) ;don't use standard exit message
