;   -----------------------------------
;   Update BancaBase 1.3 to 1.3a script
;   -----------------------------------
;   Description:
;
;   Commodore Installer Script for patch
;   BancaBase V 1.3 to 1.3a
;   $VER: 1.01 (c) 1997 by Stefano Dardari
; ENGLISH VERSION


; some useful variables
	(set 
		newline 		"\n"
        #prg            "BancaBase"
        #prgnew         "BancaBase.new"
        #prgold         "BancaBase.old"
		#bbprogname 	"BancaBase13pch.lha"
        #bb3-path       "BancaBase/"
        #catalogsname   "catalogs/"
        #docsname       "docs/"
        #examplename    "examples.lha"
		#patternsname 	"Patterns.lha"
        #soundsname     "Sounds.lha"
        #registername   "Register.lha"
        #bb3-dest       "SYS:"
        #bb3-key        "BBase.key"
        #bb3-prefs      "BancaBase.prefs"
        #bb3-readme     "ReadMe.doc"
        #bb3-readme-ita "Leggimi.doc"
        #bb3-icon-MWB   "Icons/MagicWB/"
        #bb3-icon-NI    "Icons/NewIcon/"
        #bb3-icon-STD   "Icons/Standard/"
        #STDTYPE        0
        #NITYPE         1
        #MWBTYPE        2
        #iconpattern    "#?.info"
        #bb3-lang-eng   "english"
        #bb3-lang-deu   "deutsch"
        #bb3-lang-ita   "italiano"
        #bb3-lang-fra   "français"
        #bb3-lang-rus   "russian"
        #ENG            0
        #DEU            1
        #ITA            2
        #FRA            3
        #RUS            4
        #BB3size        337984
	)

; some strings
(set #omp (cat "\nOne moment please..." newline))

(set #installtext (cat "Welcome to the BancaBase UPGRADE script.\n\nBancaBase3 V 1.3a (C) 1997/98 by Stefano Dardari\nAll rights reserved\n\nUPDATE script V 1.1\n"))
(set #BB3dest-prompt "Please select the directory where BancaBase V 1.3 program executable is installed.\n(See help for more details)")
(set #BB3dest-help (cat "You must select the complete path where is currently installed version 1.3 REGISTERED of BancaBase program.\n\nINPORTANT: this upgrade can be applied on the 1.3 REGISTERED version only, correcly installed on Hard Disk."))
(set #BB3lang-prompt "Select desired language (from availables) that program must use for menus and gadgets.")
(set #BB3lang-help "Selecting one of the listed languages, corresponding catalogs files will be copied. If the selected languages is ENGLISH, no files are copied, because it's the default built-in language.")
(set #BB3docs-prompt "Select desired language (from avaialbes) for the documentation amiga guide format files.")
(set #BB3docs-help "It's possible to select the language (from listed) for the documentation files. If you don't found your language translation install the English version now, but write to the author.")
(set #BB3patt-prompt "\n\n\nDo you want to install some pretty patterns to use with the GUI ?\nNOTE: you can use it, only with an WorkBench 3.0 or better.")
(set #BB3patt-help (cat "The backdrop patterns are to be considere as add-on.\nBancaBase work well also without them, but are very nice if used with the program's GUI.\n\nNote that program uses the Datatypes to load picture files\nso if you don't have an V39 (or better) kickstart ... choose the NO gadget."))
(set #BB3end (cat "Update complete. Read the readme file before start."))
(set #BB3icon-prompt "\nSelect from available the ICON set to install :")
(set #BB3icon-help "Select desired type of icon-set to install for BancaBase and all the tools.\nIf for example your WorkBench use the MagicWB icons, you must select MagicWB.\nSame thing for the other types.")
(set #copyng-icon-prompt "Please wait ... icon installation running.")
(set #msgpchfailed "WARNING !!!\n\nThis Patch was not applied succesfully because one error occurred.\n\nYou may be sure to apply this patch on the 1.3 REGISTERED version only of BancaBase, with any other relase this patch can't be applied.\nIf you have an 1.3 REGISTERED version of BancaBase and this patch don't work, then contact the author.")

(welcome #installtext)

(procedure set_icon
   (set #def-icon
      (askchoice
         (prompt #BB3icon-prompt)
         (help   #bb3icon-help)
         (choices "Standard Icon" "NewIcon Icon" "MagicWB Icon")
         (default 0)
      )
   )
)

(procedure set_lang_catalogs
   (set #def-lang
      (askchoice
         (prompt #BB3lang-prompt)
         (help   #bb3lang-help)
         (choices "English (built in)" "Deutsch" "Italiano" "Français" "Russian")
         (default #ENG)
      )
   )
)

(procedure set_lang_docs
    (if (> #def-lang #ITA)
        (set #def-lang #ENG)
    )
   (set #def-lang
      (askchoice
         (prompt #BB3docs-prompt)
         (help   #bb3docs-help)
         (choices "English" "Deutsch" "Italiano")
         (default #def-lang)
      )
   )
)

(procedure set_dir
   (set #bb3-dest
      (askdir
         (prompt #BB3dest-prompt)
         (help #BB3dest-help)
         (default #bb3-dest)
         (newpath)
      )
   )
)

(set_dir)
(set #dest-path #bb3-dest)
(set @default-dest #dest-path)


(if (= 0 (exists #dest-path (noreq)))
   (
      (set #file-exist (cat "Sorry but the directory " #dest-path " does not exist.\n\nPlease, select the directory containing version 1.3 of BancaBase.\n"))
      (message #file-exist)
      (set_dir)
      (set #dest-path #bb3-dest)
      (set @default-dest #dest-path)
   )
)

(complete 10)

(set #dst-path #dest-path)
(set #dst (tackon #dest-path #prg))

(if (exists #dst)
    (
    (set size (getsize #dst))
    (if (= size #BB3size)
       (message ("\n\nFound %s (%ld bytes)\n\nThis patch is applicable." #dst size))
       )
    )
)

(if (not(= size #BB3size))
    (abort #msgpchfailed)
    )

(working #omp (cat "\n\nUnpacking patch file ...\n" #dest-path))

(run ("lha -x x "#bbprogname" "#dest-path))

(complete 20)

(working #omp "\n\n\nNow executing program update ...\nplease wait ...")

(set #pchcommand (cat "spatch -o" (tackon #dest-path #prgnew) " " #dst))
; (message #pchcommand)

(set a (run #pchcommand))
; (message ("\nIl patch ritorna :%ld" a))

(if (not(= a 0))
    (abort #msgpchfailed)
    )

(delete (tackon #dest-path #prg))
(rename (tackon #dest-path #prgnew) (tackon #dest-path #prg))

(complete 30)
(set_lang_catalogs)
(if (= #def-lang #ENG)
    (set #lang #bb3-lang-eng)
    )
(if (= #def-lang #DEU)
    (set #lang #bb3-lang-deu)
    )
(if (= #def-lang #ITA)
    (set #lang #bb3-lang-ita)
    )
(if (= #def-lang #FRA)
    (set #lang #bb3-lang-fra)
    )
(if (= #def-lang #RUS)
    (set #lang #bb3-lang-rus)
    )

(set #src-path (tackon "Catalogs" #lang))
(set #dst-path (tackon #dst-path #catalogsname))
(set #dst-path (tackon #dst-path #lang))

(if (exists #src-path (noreq))
       (
          (if (not (exists #dst-path))
            (
            (makedir #dst-path (infos))
            )
          )
          (working #omp "Now coping localized catalog files.")
          (copyfiles
      		(source #src-path)
   		    (dest #dst-path)
            (files)
            (all)
          )
          (if (exists (cat #catalogsname "BancaBase.cd"))
             (copyfiles
          		(source (cat #catalogsname "BancaBase.cd"))
    		    (dest #dst-path)
                (files)
	          )
          )        
          (if (exists (cat #catalogsname "SDBase.cd"))
             (copyfiles
                (source (cat #catalogsname "SDBase.cd"))
    	        (dest #dst-path)
                (files)
             )
	      )

       )
)

(complete 40)

(set_lang_docs)
(if (= #def-lang #ENG)
    (set #lang #bb3-lang-eng)
    )
(if (= #def-lang #DEU)
    (set #lang #bb3-lang-deu)
    )
(if (= #def-lang #ITA)
    (set #lang #bb3-lang-ita)
    )

(set #src-path (tackon "Docs" #lang))
(set #dst-path (tackon #dest-path #docsname))

(if (exists #src-path (noreq))
       (
          (if (not (exists #dst-path))
            (
              (makedir #dst-path (infos))
            )
          )
          (working #omp "Now coping documentation files.")
          (copyfiles
      		(source #src-path)
   		    (dest #dst-path)
            (files)
            (all)
          )
       )
)


(complete 50)
(set #dest-path @default-dest)

(if (exists #registername (noreq))
       (
          (delete (tackon #dest-path "Register")
              (all)
              (infos)
          )
          (makedir (tackon #dest-path "Register"))
          (working #omp "Unpacking and coping registration docs files.")
          (run "lha -x x "#registername" "(cat #dest-path "/"))
       )
)

(if (exists #bb3-readme (noreq))
	(copyfiles
        (prompt #omp "Coping information files.")
		(source #bb3-readme)
		(dest #dest-path)
        (files)
	)
)

(complete 60)
(if (exists #patternsname (noreq))
   (
      (if (askbool (prompt #BB3patt-prompt) (help #BB3patt-help) (default 1))
          (
             (working #omp "UnPacking and coping patterns files.")
             (run "lha -x x "#patternsname" "(cat #dest-path "/"))
          )
      )
   )
)

(complete 70)
(set_icon)
(if (= #def-icon #STDTYPE)
    (set #src-icon #bb3-icon-STD)
    )
(if (= #def-icon #NITYPE)
    (set #src-icon #bb3-icon-NI)
    )
(if (= #def-icon #MWBTYPE)
    (set #src-icon #bb3-icon-MWB)
    )

(copyfiles
   (prompt #copyng-icon-prompt)
   (source #src-icon)
   (dest  #dest-path)
   (pattern #iconpattern)
   (noposition)
)

(set #src-path (tackon #src-icon "Docs"))
(set #dst-path (tackon #dest-path "Docs"))

(copyfiles
   (prompt #copyng-icon-prompt)
   (source #src-path)
   (dest  #dst-path)
   (all)
   (noposition)
)

(set #src-path (tackon #src-icon "Register"))
(set #dst-path (tackon #dest-path "Register"))

(copyfiles
   (prompt #copyng-icon-prompt)
   (source #src-path)
   (dest  #dst-path)
   (all)
   (noposition)
)

(complete 80)

(if (exists #soundsname (noreq))
       (
          (working #omp "UnPacking and coping sound files.")
          (run "lha -x x "#soundsname" "(cat #dest-path "/"))
       )
)


(complete 90)

(if (exists #bb3-prefs (noreq))
	(copyfiles
        (prompt #omp "Coping prefs file.")
		(source #bb3-prefs)
		(dest #dest-path)
        (files)
	)
)


(complete 100)


; The last message
	(set end_text (cat "Hope you like BancaBase!\n"
                   "Don't hesitate to send me comments, bugreports and suggestions.\n\n"
                   "Registrations are also WELCOME !!!! :))"))

; the end
(set @default-dest #dest-path)
    (exit end_text)
;EOF
