; --------------------------------------------------------------------
; Skript zur Installation von FW_Sessions auf Festplatte.
;
; FW_Sessions wurde geschrieben von Wanja Pernath und ist FreeWare.
; Es darf/soll frei verteilt werden.
;
; Installations-Skript
; --------------------------------------------------------------------

; --------------------------------------------------------------------
; Texte
; --------------------------------------------------------------------

( SET #fw_welcome
	( CAT
									"\n\n"
									"Welcome to this very new\n"
									"ARexx implementation for FinalWriter\n"
									"Called:\n\n"
									"FW Sessions\n"
									"\n"
									"Written in 1997 by Wanja Pernath\n\n"
									"Status: FREEWARE\n"
	)
)

( SET #fw_defaultdir
	( CAT
									"Please select the main directory of FinalWriter."
	)
)

( SET #fw_macrodir
	( CAT
									"Please select the directory where your FinalWriter macros are."
	)
)

( SET #copy-lib-help
	( CAT
									"This library must be present if you want to use FW_Sessions.\n"
									"So please install it if there is none installed!\n\n"
									@copylib-help
	)
)

( SET #set-language
	( CAT
									"Sorry, but your language isn't yet translated.\n"
									"Please select one of the following languages.\n"
	)
)

( SET #set-language-help
	( CAT
									"Select your language."
	)
)

( SET #copy-script-1
	( CAT
									"Copy now FW_LoadSession.rexx"
	)
)

( SET #copy-script-2
	( CAT
									"Copy now FW_SaveSession.rexx"
	)
)

( SET #ask-session-dir
	( CAT
									"Where should the sessions be saved?\n"
									"A drawer called 'Sessions' will be created."
	)
)

( SET #make-session-dir
	( CAT
									"Creating directory for the sessions."
	)
)

( SET #fw-message
	( CAT
									"\n\n"
									"If you want to have most comfort in using FW_Sessions,\n"
									"you must install this two scripts into the menu of\n"
									"FinalWriter.\n"
									"\n"
									"NOTE: FW_Sessions is FREEWARE.\n"
									"Spread it around the world as much as you can.\n"
									"But please remember to swap the full archive.\n"
									"\n"
									"Use it on your own risk!\n"
									"For questions and bug reports send an email to:\n"
									"pernathw@cip.ub.uni-muenchen.de"
	)
)

; --------------------------------------------------------------------
; Variablen
; --------------------------------------------------------------------

( SET #fw-dir           @default-dest)
( SET #session-dir      "T:" )
( SET #session-name     "Sessions" )
( SET #script-dest      "FWMacros" )
( SET #script-source    @LANGUAGE )
( SET #lib-source       "libs/rexxreqtools.library")
( SET #script-def-lang  0)
( SET #script-1         "FW_LoadSession.rexx" )
( SET #script-2         "FW_SaveSession.rexx" )

; --------------------------------------------------------------------
; Programm-Code
; --------------------------------------------------------------------

; Print welcome-text

( MESSAGE #fw_welcome )

( COMPLETE 0 )

; Frage nach dem FW hauptverzeichnis

( SET #fw-dir
	( ASKDIR  ( PROMPT  #fw_defaultdir )
						( HELP    @askdir-help )
						( DEFAULT #fw-dir )
	)
)

(COMPLETE 5)

; Versuche das FWMacros Verzeichnis zu bestimmen.
; Wenn es nicht geht, dann Benutzer auffordern, es zu wählen.

( SET #fw-macros ( TACKON #fw-dir #script-dest ) )

( IF ( NOT ( EXISTS #fw-macros (noreq)))
	(SET #fw-macros
			 ( ASKDIR (PROMPT   #fw_macrodir )
								(HELP     @askdir-help )
								(DEFAULT  #fw-dir )
			 )
	)
)

(COMPLETE 10)


; Wenn die rexxreqtools.library noch nicht vorhanden ist, dann kopiere sie

( IF ( NOT (exists "LIBS:rexxreqtools.library" (noreq)))
	( COPYLIB (PROMPT       #copy-lib)
						(HELP         #copy-lib-help)
						(SOURCE       #lib-source)
						(CONFIRM )
						(DEST         "LIBS:")
	)
)

(COMPLETE 15 )

; Wähle die richtigen ARexx-Skripte aus: Momentan sind folgende Sprachen
; vorhanden: Deutsch/English

; Versuche über die Variable @language das richtige Verzeichnis zu bekommen

( IF (NOT (exists #script-source (noreq)))
	(
			(SET #script-def-lang
				( ASKCHOICE     ( PROMPT    #set-language )
												( HELP      #set-language-help )
												( CHOICES   "English"
																		"Deutsch"
																		"" )
				)
			)

			(SET #script-source ( SELECT #script-def-lang "english" "deutsch" "" ) )
	)
)

(complete 20 )

; Kopiere die beiden scripte aus dem Sprachenverzeichnis ins Zielverz.

( COPYFILES   ( PROMPT    #copy-script-1 )
							( SOURCE    (TACKON #script-source #script-1 ) )
							( DEST      #fw-macros )
							( INFOS )
							( NOPOSITION )
)

(complete 30 )

( COPYFILES   ( PROMPT    #copy-script-2 )
							( SOURCE    (TACKON #script-source #script-2 ) )
							( DEST      #fw-macros )
							( INFOS )
							( NOPOSITION )
)

(complete 40 )

; ---------------------------------------------
; Installiere ein Verzeichnis für die Sitzungen
; ---------------------------------------------

( SET #session-dir
	( ASKDIR      ( PROMPT      #ask-session-dir )
								( HELP        #ask-session-dir-help )
								( DEFAULT     #session-dir )
	)
)

( SET #session-path (TACKON #session-dir #session-name ) )

( MAKEDIR       #session-path
								( PROMPT      #make-session-dir )
								( HELP        #make-session-dir-help )
								( INFOS )
								( CONFIRM )
)

( COMPLETE 50 )

; ------------------------------------------------------
; Setze eine globale Variable (ENVARC:FWSessions), die
; den Namen des Verzeichnisses der Sitzungen enthält.
; ------------------------------------------------------

( TEXTFILE  ( DEST    "ENVARC:FWSessions" )
						( APPEND  #session-path )
)

( COMPLETE 60 )

; --------------------------------------------------------------
;
; Kreiere ein Textfile mit folgendem Inhalt:
;   CD #fw-dir
;   run FinalWriter
;   wait 4
;   rx #macros-dir/FW_LoadSession.rexx
; Sichere es unter #fw-dir/Final_Last
;
; ---------------------------------------------------------------

( SET #fw-textfile
	( CAT
					"CD " #fw-dir "\n"
					"run <>NIL: FinalWriter\n"
					"Wait 4\n"
					"rx " (TACKON #fw-macros "FW_LoadSession.rexx\n" )
	)
)

( TEXTFILE    ( PROMPT  #final-last )
							( HELP    #final-last-help )
							( DEST    (TACKON #fw-dir "Final_Last" ))
							( APPEND  #fw-textfile )
)

( COMPLETE 80 )

; Setze die protection-flags für Final_Last

( PROTECT     ( TACKON #fw-dir "Final_Last" ) "+s" )

( COMPLETE 100 )


; Hinweis ausgeben

( MESSAGE     ( ALL )
							#fw-message
)
