; crummy multiArchive extractor : By Neil Mohr 
; $VER: crummy multilzx extractor v1.0b (15:08 28 Jan 1996)
; Modified by Vark for Vark 14, cos I'm a lazy bastard
; It's too hot today anyway :)
;all specified archives must be in the same directory, with lha
;start with file1, file2 .. don't intersperse entries

(complete 0)
(welcome)

(if (OR (= (getDevice @icon) "DF0") (= (getDevice @icon) "DF1") (= (getDevice @icon) "DF2"))
    (set originalDisc (getAssign (getDevice @icon) "d")) )
(set @default-dest "")
(set @app-name "")
(set counter 0)
(foreach "" "#?.lha" (set counter (+ counter 1)) )
(set completeVal (+ counter 1))
(set destPrompt "Where do you want the archives extracting?")

(user 2)
(message "\n\n\nTo use this installer properly you need\na hard drive, or at "
         "least, plenty of free memory.\n\n\nAlso this icon should be in the same "
         "directory as the archives, and LHA in c: otherwise it will not work!")

(set file1  "AB3DIIED.Lha")
(set file2  "FrontierTrek1.1.Lha")
(set file3  "Gloom_Deluxe.Lha")
(set file4  "IsharIII.Lha")
(set file5  "SWOSEdV1.3.Lha")
(set file6  "Tower_Assault.Lha")
(set file7  "Tower-Assault.Lha")
(set file8  "UFO-Cheat.Lha")
(set file9  "UFO-FXCheat.Lha")

(while (OR (= (getAssign (getDevice @default-dest) "d") originalDisc )
           (= originalDisc "") )
  (set destination
    (askdir (help @askdir-help) (prompt destPrompt)
    (newpath)
    (default "RAM:")
  ))
(set destPrompt "Where do you want the archives extracting?\nBut please don't pick the coverdisc!")
(set @default-dest destination)
)


(if (NOT (= (substr @default-dest (- (strlen @default-dest) 1) 1) ":")) (set @default-dest (cat @default-dest "/")))

(if (= (getDevice @default-dest) "RAM")
  (if (< (+(dataBase "total-mem")) 1000000) (message "\n\n\nYou may not have enough memory.\n\nPress proceed to try anyway."))
  (if (< (getDiskSpace @default-dest)) 1000000 (message "\n\n\nYou may not have enough disc space.\n\nPress proceed to try anyway."))
)

(set response (askoptions (prompt "Pick which archives to extract.") (help @askoptions-help) (choices

file1
file2
file3
file4
file5
file6
file7
file8
file9

)) )

(set counter (- counter 1))

(until (= counter -1)

  (if (IN response counter) ((set @app-name file9)  (set response (- response 256)) ))
  (if (IN response counter) ((set @app-name file8)  (set response (- response 128)) ))
  (if (IN response counter) ((set @app-name file7)  (set response (- response 64)) ))
  (if (IN response counter) ((set @app-name file6)  (set response (- response 32)) ))
  (if (IN response counter) ((set @app-name file5)  (set response (- response 16)) ))
  (if (IN response counter) ((set @app-name file4)  (set response (- response 8)) ))
  (if (IN response counter) ((set @app-name file3)  (set response (- response 4)) ))
  (if (IN response counter) ((set @app-name file2)  (set response (- response 2)) ))
  (if (IN response counter) ((set @app-name file1)  (set response (- response 1)) ))

  (if (NOT (= @app-name ""))
    ( (complete (* (- completeVal counter ) (/ 100 completeVal)) )
      (working "\n\n\nI am now extracting " @app-name " to " @default-dest ".\n\nPlease Wait.")
      (set unArc (cat "c:lha x -m -x \"" @app-name "\" \"" @default-dest "\""))
      (if (> (run unArc) 0)  (message "lha reported an error when extracting\n" @app-name " to the destination path " @default-dest ".\n\nThis could either be a problem with how\nyour computer is setup or with the disk itself.\nTry running the HD-Setup Icon, and make sure you are running MultiExtract from the cover disk, it may be the destination " @default-dest " does not have enought room.\n\nIf problems persist ring 01625 878888 and ask for Amiga Computing Technical Help.\n\nPress Proceed To Continue." ))
    )
  )

  (set counter (- counter 1))
  (set @app-name "")

)

(complete 100)
(message "\n\n\n\nHopefully all your chosen files\nhave been extracted correctly!\n\nand can be found in " @default-dest)

(exit (quiet))
