; Install script for ModePro

(set path_wbstartup       ( expandpath "Sys:WBStartup") )
(set path_commodities     ( expandpath "Sys:Tools/Commodities") )
(set path_prefs           ( expandpath "Sys:Prefs") )
(set path_modepro         path_commodities)

( set ModePro "ModePro")
( set ModeProPrefs "ModeProPrefs" )

( set file_modepro_src       "ModePro")
( set file_modeproprefs_src  "ModeProPrefs" )
( set file_screentab         (tackon path_wbstartup "ScreenTab"))


(set catalog_1   "ÃeÓtina")
(set catalog_2   "dansk")
(set catalog_3   "deutsch")
(set catalog_4   "español")
(set catalog_5   "français")
(set catalog_6   "Hrvatski") 
(set catalog_7   "íslenska")
(set catalog_8   "italiano") 
(set catalog_9   "magyar") 
(set catalog_10   "norsk")
(set catalog_11  "polski")
(set catalog_12  "português-brasil")
(set catalog_13  "russian")
(set catalog_14  "srpski")
(set catalog_15  "svenska") 
(set catalog_16  "türkçe")

(set catalogs 16)

;#######################################################################
; If you want to translate this installer script, simply 
; translate the file "english.strings", then send me the 
; new file with the native language name as the file title.
;
; You don't need to do anything to the file other than 
; translate it and rename it.  I have a script compiler
; that handles all the logic needed (if (= language 'your language') ... 
;########################################################################

INSERT_STRINGS

;-------- BEGIN ----------

; Fix these strings
(set path_modepro_prompt  (path_modepro_prompt path_commodities))
(set path_mpprefs_prompt  (path_mpprefs_prompt path_prefs))


(if (exists file_screentab)
  (
    (set startup_prompt (cat startup_prompt startup_screentab))
    (set startup_help   (cat startup_help startup_screentab))
  )
)


;### Check to see if a previous version is installed ###

(if (exists (tackon path_commodities file_modepro_src))
  (
    (set path_mp_location path_commodities)
    (set found_install 1)
  )

  (if (exists (tackon path_wbstartup file_modepro_src))
    (
      (set path_mp_location path_wbstartup)
      (set found_install 1)
    )
  )
)

(if (exists (tackon path_prefs file_modeproprefs_src))
  (
    (set path_mpprefs_location path_prefs)
    (set found_install (+ found_install 1))
  )
)

(set quickupdate 1)

(debug path_mp_location path_mpprefs_location)

(if (= found_install 2)
  (
    (set quickupdate (askchoice (prompt quickupdate_prompt) 
                                (help quickupdate_help)
                                (default 0) 
                                (choices quickupdate_choice0 quickupdate_choice1) 
) ) )                )

(if (= quickupdate 1)
  ( ;### Full update ###
    (set startup_method (askchoice (prompt  startup_prompt)
                                   (help    startup_help)
                                   (choices startup_choice0 startup_choice1 startup_choice2)
                                   (default 2)
    )                   )
    
    
    (if (= startup_method 2) 
      (
        ( set path_delmodepro path_commodities)
        ( set path_modepro    path_wbstartup)
      )
      (
        ( set path_delmodepro path_wbstartup)
        ( set path_modepro (askdir (prompt  path_modepro_prompt)
                                   (help    path_modepro_help)
                                   (default path_commodities)
        )                  )
      )
    )
    
    ( set path_mpprefs (askdir (prompt  path_mpprefs_prompt)
                               (help    path_mpprefs_help)
                               (default path_prefs)
    )                  )
    
    
    
    ( set ModeProPrefsCommand (tackon ( path_mpprefs) 
                                       ( "ModeProPrefs") 
                              ) 
    )
    
    ( set tt_cxpopkey ( askstring (prompt tt_cxpopkey_prompt)
                                  (help tt_cxhelp)
                                  (default "lamiga p")
                   
    )                 )
    
    ( set tt_cxpri ("%ld" (asknumber (prompt tt_cxpri_prompt)
                                     (help tt_cxhelp)
                                     (default 5)
    )              )      ) 
    
    ( set tt_cxpopup (askchoice (prompt tt_cxpopup_prompt) 
                                (help tt_cxhelp)
                                (default 0) 
                                (choices No Yes) 
    )             )
    
    ( set tt_wbpromote (askchoice (prompt tt_wbpromote_prompt) 
                                (help tt_wbpromote_help)
                                (default 0) 
                                (choices No Yes) 
    )             )
    
    ( set tt_wbpromotable (select tt_wbpromote "(WBPROMOTABLE)" "WBPROMOTABLE") )
    
    
    ;**** ASK WHICH CATALOGS TO COPY ****
    (set  copy_catalogs (askoptions  (prompt  copycat_prompt)
                 (help    copycat_help)
                 (choices catalog_1 catalog_2 catalog_3 catalog_4 catalog_5 catalog_6 catalog_7 catalog_8 catalog_9 catalog_10 catalog_11 catalog_12 catalog_13 catalog_14 catalog_15)
                 (default 0)
    )                   )
    
    ;**** COPY CATALOGS ****
    (set optnumber 0)
    ( while ( < optnumber catalogs )
      (set flag (BITAND (shiftright copy_catalogs optnumber) 1) )
      (if flag
        (
          (set cat_name  ( select optnumber catalog_1 catalog_2 catalog_3 catalog_4 catalog_5 catalog_6 catalog_7 catalog_8 catalog_9 catalog_10 catalog_11 catalog_12 catalog_13 catalog_14 catalog_15) )
          (set srcpath (cat "catalogs/" cat_name ) )
          (set dstpath (cat "locale:catalogs/" cat_name ) )
          (makedir dstpath)
          (copyfiles  (prompt (installing_catalogs cat_name)) (help (installing_catalogs cat_name)) (source srcpath) (dest dstpath) (all))
        )
      )
      (set optnumber (+ optnumber 1) )
    )
    
    
    ;(copyfiles (prompt  copycat_prompt)
    ;           (help    copycat_help)
    ;           (source  "catalogs/")
    ;           (dest    "locale:catalogs/")
    ;           (infos)
    ;           (confirm)
    ;           (all)
    ;)
    
    ;**** DELETE THE ANY EXTRA COPY OF MODEPRO ****
    
    (set oldmodepro_file ( tackon (path_delmodepro) 
                         ("ModePro")
    )          )
    
    (if (exists oldmodepro_file)
      (
        (if (askchoice (prompt  (cat oldmodepro_prompt "\n" oldmodepro_file)) 
                       (help    oldmodepro_help) 
                       (default 1) 
                       (choices No Yes) 
            )
          (
            (delete oldmodepro_file (prompt oldmodepro_deleting))
            (delete (cat (oldmodepro_file) (".info") ) (prompt oldmodepro_deleting) )
          )
        ) 
      )
    )
    
    ;**** SET THE TOOLTYPES ****
    
    (tooltype (dest file_modepro_src)
              (settooltype "CX_POPKEY"    tt_cxpopkey)
              (settooltype "CX_POPUP"     (select tt_cxpopup No Yes) )
              (settooltype "CX_PRIORITY"  tt_cxpri )
              (settooltype "PREFSCOMMAND" ModeProPrefsCommand)
              (settooltype tt_wbpromotable "")
    )
    
    
    ;**** COPY FILES ****
        
    (copyfiles (prompt installing_modepro)
               (help   installing_modepro)
               (source file_modepro_src)
               (infos)
               (dest path_modepro)
    )
    
    (set @default-dest path_modepro)
    
    (copyfiles (prompt installing_modeproprefs)
               (help   installing_modeproprefs)
               (source file_modeproprefs_src)
               (infos)
               (dest path_mpprefs)
    )
    
    
    
    
    ;**** PROMPT TO MODIFY THE U-S FILE ****
    (if (= startup_method 1)
        ( 
            (startup "ModePro"
                     (prompt  usmodify_prompt )
                     (help    usmodify_help )
                     (command (cat "  If EXISTS "      (tackon path_modepro "ModePro")
                                   "\n    Run <>NIL: " (tackon path_modepro "ModePro")
                                   "\n  ENDIF\n" ) )
            )
        )
        (
           (startup "ModePro"
                     (prompt  usmodify_prompt )
                     (help    usmodify_help )
                     (command ";Don't run ModePro from User-Startup")
      
            )
        )
    )
  )   
  ; else quick update 
  (
    (copyfiles (prompt installing_modepro)
               (help   installing_modepro)
               (source file_modepro_src)
               (dest path_mp_location)
    )
    
    (copyfiles (prompt installing_modeproprefs)
               (help   installing_modeproprefs)
               (source file_modeproprefs_src)
               (dest path_mpprefs_location)
    )
     
  )
)
