(complete 0)
(set @default-dest "Work:")

(message (cat "\n\nWelcome to the Audio Evolution installation utility!\n\n\n"
              "Note that Audio Evolution requires AHI V4 or higher.\n\n")
)
(welcome)


(set dest_dir
   (askdir (prompt "Where would you like Audio Evolution to be installed?\n"
                    "A new drawer will be created there.")
           (help @askdir-help)
           (default @default-dest)
           (newpath))
)

(set @default-dest (tackon dest_dir "AudioEvolution"))
(makedir @default-dest)
(makedir (tackon @default-dest "samples"))
(makedir (tackon @default-dest "filters"))
(makedir (tackon @default-dest "projects"))
(makedir (tackon @default-dest "eventlists"))
(makedir (tackon @default-dest "PlugIns"))


(set processor 0)
(if (= (run "c:cpu check 68881") 0) (set processor 1))
(if (= (run "c:cpu check 68040") 0) (set processor 1))
(set processor
     (askchoice (prompt "Select your processor")
                (help (cat "Select the kind of processor you have in your machine:\n\n"
                      "68020: Select this if you have an '020 or '030 without FPU\n\n"
                      "68020 + FPU: Select this if you have an '020 or '030 with FPU or an 68040 (not 68EC040!)\n\n"
                      "68060: Select this if you have an 68060"
                      )
                )
                (choices "68020" "68020 + FPU" "68060")
                (default processor)
     )
)

(if (= processor 0) ((set SourceName "AudioEvolution.020") (set SourceNameInfo "AudioEvolution.020.info")) )
(if (= processor 1) ((set SourceName "AudioEvolution.020fpu") (set SourceNameInfo "AudioEvolution.020fpu.info")) )
(if (= processor 2) ((set SourceName "AudioEvolution.060") (set SourceNameInfo "AudioEvolution.060.info")) )

(copyfiles (prompt ("Copying Audio Evolution to %s.\n" @default-dest))
                              (source SourceName)
                              (dest @default-dest)
                              (confirm)
                              (infos)
                              (help "\nThis will copy the main Audio Evolution file.")
)

(rename (tackon @default-dest SourceName) (tackon @default-dest "AudioEvolution") )
(rename (tackon @default-dest SourceNameInfo) (tackon @default-dest "AudioEvolution.info") )


(complete 60)

(copyfiles (prompt ("Copying AudioEvolution.guide to %s.\n" @default-dest))
                              (source "AudioEvolution.guide")
                              (dest @default-dest)
                              (confirm)
                              (infos)
                              (help "\nThis will copy the Audio Evolution documentation.")
)


(copyfiles (prompt ("Copying VersionInfo to %s.\n" @default-dest))
                              (source "VersionInfo")
                              (dest @default-dest)
                              (confirm)
                              (infos)
                              (help "\nThis will copy the version-info file.")
)

(complete 65)

(set InstallPTool 0)
(set InstallPTool
     (askchoice (prompt "Do you wish to install the Bars&Pipes synchronisation tool?")
                (help (cat "The Bars&Pipes synchronisation tool is a 'ptool' to \n"
                      "synchronize the start of Audio Evolution with B&P."
                      )
                )
                (choices "Yes" "No")
                (default InstallPTool)
     )
)

(if (= InstallPTool 0)
 (
   (set bpdir
      (askdir (prompt "Where would you like the B&P tool to be installed?\n")
            (default "Work:")
            (help "\nChoose the Bars&Pipes/Tools directory\n")
            (disk)
      )
   )

   (copyfiles (prompt ("Copying AudioEvolutionTool.ptool to %s.\n" bpdir) )
                              (source "AudioEvolutionTool.ptool")
                              (dest bpdir)
                              (confirm)
                              (help "\nThis will copy the B&P-ptool file.")
   )
 )
)




(complete 70)

(copyfiles (prompt ("Copying filters to %s.\n" (tackon @default-dest "filters") ))
                              (source "filters")
                              (dest (tackon @default-dest "filters"))
                              (all)
                              (help "\nThis will copy some example FIR-filter files.")
)


(complete 80)

(copyfiles (prompt ("Copying plug-ins to %s.\n" (tackon @default-dest "PlugIns") ))
                              (source "PlugIns")
                              (dest (tackon @default-dest "PlugIns"))
                              (all)
                              (help "\nThis will copy some realtime PPC effects.")
)


(complete 90)


(copyfiles (prompt "Audio Evolution needs some fonts in the FONTS: directory.\n")
           (source "fonts/")
           (dest "FONTS:")
           (all)
           (confirm)
           (help "\nThis will copy the Trinomic and AudioEvolutionDigital fonts.")
)


(set vernumInstalled (getversion "libs:popupmenu.library"))
(set ver (/ vernumInstalled 65536))
(set rev (- vernumInstalled (* ver 65536) ) )

(set vernumToInstall (getversion "libs/popupmenu.library"))
(set ver2 (/ vernumToInstall 65536))
(set rev2 (- vernumToInstall (* ver2 65536) ) )


(if (< vernumInstalled vernumToInstall)

   (copyfiles (prompt ( cat ("Popupmenu.library:\n")
                            ("\nVersion to install : %ld.%ld\n" ver2 rev2)
                            ("Version found : %ld.%ld" ver rev) 
                      ))
                      (source "libs/popupmenu.library")
                      (dest "libs:")
                      (confirm)
                      (help "\nThe popupmenu library is required to run Audio Evolution!")
   )
)


(complete 100)

(set installed "YES")         

(if (= installed "YES") 
   (exit ("\n\nThank you for installing Audio Evolution!"))
   (exit)
)   
