;escapequit(TRUE)
curdir=getcurrentdirectory() t=getversion() ver=t.platform systlang=getsystemlanguage() language=0 examples=1 target$="SYS:"
If systlang=1 then language=1
If systlang=4 then language=2
If systlang=7 then language=3
If systlang=11 then language=4
If systlang=5 then language=5

@brush 10,"tbimages:drawer",{loadalpha=TRUE}
@brush 11,"tbimages:cancel",{loadalpha=TRUE}
@brush 12,"tbimages:ok",{loadalpha=TRUE}
@brush 13,"tbimages:jump_next",{loadalpha=TRUE}
@BRUSH 120,"Data:Entwicklung/ArtBase/Data1/Install-Logo.png",{LoadAlpha=TRUE} 


@DISPLAY 1,{x=#CENTER,y=#CENTER,sizeable=FALSE,NoModeSwitch=TRUE, Borderless=TRUE,hidden=false}
hidedisplay()
ct$={}
;default language: English
ct$[2]="Target directory:"
ct$[3]="Language for online-help:"
ct$[4]="Install exampleprojects:"
ct$[5]="Cancel"
ct$[6]="Install"
ct$[7]="Welcome to the"
ct$[8]="ArtBase Installation"
ct$[9]={"english","german","french","polish","swedish","spanish"}
ct$[10]="Do you really want to cancel the installation?"
ct$[11]="Yes"
ct$[12]="No"
ct$[13]="A drawer called ArtBase will be created automatically..."
ct$[14]="Select the language for your Documentation..."
ct$[15]="Do you want to install the exampleprojects?"
ct$[16]="This will cancel the installation..."
ct$[17]="Start the installationprocess..."
ct$[18]="Installing ArtBase..."
ct$[19]="Installation finished successfully."
ct$[20]="Do you want to start ArtBase now?"
ct$[21]="ArtBase requires at least "
;deutsch
If systlang=1
	ct$[2]="Zielverzeichnis:"
	ct$[3]="Sprache für Online-Hilfe:"
	ct$[4]="Beispielprojekte installieren:"
	ct$[5]="Abbrechen"
	ct$[6]="Installieren"
	ct$[7]="Willkommen zur"
	ct$[8]="ArtBase Installation"
	ct$[9]={"english","deutsch","französisch","polnisch","schwedisch","spanish"}
	ct$[10]="Möchten Sie die Installation wirklich abbrechen?"
	ct$[11]="Ja"
	ct$[12]="Nein"
	ct$[13]="Ein Verzeichnis namens ArtBase wird automatisch erstellt..."
	ct$[14]="Wählen Sie die Sprache für die Dokumentatin aus..."
	ct$[15]="Möchten Sie die Beispielprojekte installieren?"
	ct$[16]="Installation abbrechen..."
	ct$[17]="Installationsprozess starten..."
	ct$[18]="Installiere ArtBase..."
	ct$[19]="Installation erfolgreich beendet."
	ct$[20]="Möchten Sie ArtBase jetzt starten?"
	ct$[21]="ArtBase benötigt mindestens "
EndIF

;polnisch
If systlang=11
	ct$[2]="Katalog docelowy:"
	ct$[3]="Jezyk pomocy podrecznej:"
	ct$[4]="Zainstaluj przykladowe projekty:"
	ct$[5]="Anuluj"
	ct$[6]="Instaluj"
	ct$[7]="Witaj w"
	ct$[8]="instalator ArtBase"
	ct$[9]={"angielski","niemiecki","francuski","polski","szwedzki","hiszpanski"}
	ct$[10]="Czy na pewno chcesz przerwac instalacje?"
	ct$[11]="Tak"
	ct$[12]="Nie"
	ct$[13]="Katalog o nazwie ArtBase zostanie utworzony automatycznie..."
	ct$[14]="Wybierz jezyk dokumentacji..."
	ct$[15]="Czy chcesz zainstalowac przykladowe projekty?"
	ct$[16]="Ta czynnosc przerwie instalacje..."
	ct$[17]="Rozpoczynanie procesu instalacji..."
	ct$[18]="Instalowanie ArtBase..."
	ct$[19]="Instalacja zakonczona powodzeniem."
	ct$[20]="Czy chcesz teraz uruchomic ArtBase?"
	ct$[21]="ArtBase wymaga przynajmniej "
EndIF

;schwedisch
If systlang=7
	ct$[2]="Målkatalog:"
	ct$[3]="Språk för online-hjälp:"
	ct$[4]="Installera exampleprojects:"
	ct$[5]="Avbryt"
	ct$[6]="Installera"
	ct$[7]="Välkommen till"
	ct$[8]="ArtBase installation"
	ct$[9]={"engelska","tyska","franska","polska","svenska","spanska"}
	ct$[10]="Vill du verkligen avbryta installationen?"
	ct$[11]="Ja"
	ct$[12]="Nej"
	ct$[13]="En låda kallad ArtBase kommer att skapas automatiskt..."
	ct$[14]="Välj språk för din dokumentation..."
	ct$[15]="Vill du installera exampleprojects?"
	ct$[16]="Detta kommer avbryta installationen..."
	ct$[17]="Starta installationsprocessen..."
	ct$[18]="Installerar ArtBase..."
	ct$[19]="Installationen slutfördes utan fel."
	ct$[20]="Vill du starta ArtBase nu?"
	ct$[21]="ArtBase kräver minst  "
EndIF
;französisch
If systlang=4
	ct$[2]="Répertoire de destination:"
	ct$[3]="Langue de l'aide en ligne:"
	ct$[4]="Installer les projets d'exemple:"
	ct$[5]="Annuler"
	ct$[6]="Installer"
	ct$[7]="Bienvenu dans"
	ct$[8]="l'installation d'ArtBase"
	ct$[9]={"anglais","allemand","français","polonais","suédois"}
	ct$[10]="Voulez-vous réellement annuler l'installation?"
	ct$[11]="Oui"
	ct$[12]="Non"
	ct$[13]="Un répertoire nommé ArtBase sera crée automatiquement..."
	ct$[14]="Choisissez la langue de votre documentation..."
	ct$[15]="Voulez-vous installer les projets d'exemple?"
	ct$[16]="Ceci annulera l'installation..."
	ct$[17]="Démarrage du processus d'installation..."
	ct$[18]="Installation d'ArtBase..."
	ct$[19]="Installation terminée"
	ct$[20]="Voulez-vous démarrez ArtBase maintenant?"
	ct$[21]="ArtBase nécessite au moins "
EndIF

;spanisch
If systlang=5
	ct$[2]="Directorio destino:"
	ct$[3]="Idioma para ayuda en linea:"
	ct$[4]="Instalar proyectos de ejemplo:"
	ct$[5]="Cancelar"
	ct$[6]="Instalar"
	ct$[7]="Bienvenido a la"
	ct$[8]="instalación de ArtBase"
	ct$[9]={"inglés","alemán","francés","polaco","sueco","español"}
	ct$[10]="¿Realmente quieres cancelar la instalación?"
	ct$[11]="Si"
	ct$[12]="No"
	ct$[13]="Un directorio llamado ArtBase será creado automáticamente..."
	ct$[14]="Selecciona el lenguaje para la documentación..."
	ct$[15]="¿Quieres instalar los proyectos de ejemplo?"
	ct$[16]="Esto va a cancelar la instalación..."
	ct$[17]="Comenzar el proceso de instalación..."
	ct$[18]="Instalando ArtBase..."
	ct$[19]="La instalación ha concluido con éxito."
	ct$[20]="¿Quieres instalar ArtBase ya?"
	ct$[21]="ArtBase requiere al menos "
EndIF


req$={"mui:libs/muimaster.library",3.9,"MUI V3.9"};,"libs:hollywood/muiroyale.hwp",1.2,"MUI-Royale V1.3"}
result=0 str$=ct$[21].."\n"
for tt=0 to listitems(req$)/3-1
	m$="" m=0
	if exists (req$[tt*3])=TRUE
		execute ("version >t:ab.tmp "..req$[tt*3]) openfile(1,"t:ab.tmp",#MODE_READ) m$=readline(1) Closefile(1) deletefile("t:ab.tmp")
		m$=unrightstr(m$,strlen(filepart(req$[tt*3]))+1)
		m=val(m$)
	EndIF
	if m<req$[tt*3+1]
		result=result+1 str$=str$..req$[tt*3+2].."\n"
	EndIF
Next
if result>0
	systemrequest("ArtBase",str$,"ok") end()
EndIF

showdisplay()
doclang$={"english","german","french","swedish"}
CreateGradientbrush (1,640,480,#linear,0,0,0,{colors={$7592d,0,$14FE80,0.5,$7592d,1}})
CreateGradientbrush (2,200,50,#linear,0,0,0,{colors={$222222,0,$777777,0.5,$222222,1}})

CreateGradientbrush (15,540,30,#linear,0,0,0,{colors={$124210,0,$7592d,0.5,$124210,1}})
CreateGradientBrush (14,540,30,#Linear,0,0,0,{colors={$222222,0,$888888,0.5,$222222,1}})

copybrush (2,3)
SetFont(#SANS,20) SetFontColor(#white) SetFontStyle (#bold|#antialias)
CreateTextobject(1,ct$[5]) SelectBrush(2) Displaytextobject(1,#CENTER,#CENTER) EndSelect
CreateTextobject(1,ct$[6]) SelectBrush (3) Displaytextobject(1,#CENTER,#CENTER) EndSelect()
selectbrush (1) displaybrush (120,#center,0) endselect()
Displaybrush (1,0,0)
displaybrush(2,50,400) Displaybrush (3,390,400)
displaybrush(14,50,365)
maxw=0
setfont (#SANS,30) SetFontColor (#BLACK) SetFontStyle (#bold|#antialias)
createtextobject (1,ct$[7]) Displaytextobject (1,#CENTER,150)
createtextobject (1,ct$[8]) Displaytextobject (1,#CENTER,190)
setfont (#SANS,20) SetFontColor (#WHITE) SetFontStyle (#bold|#antialias)

for t=2 to 4
	createtextobject (1,ct$[t])
	Displaytextobject (1,20,200+t*30)
	maxw=max(maxw,getattribute(#textobject,1,#attrwidth))
Next

displaybrush (10,maxw+40,260) displaybrush (13,maxw+40,290)
SetFont (#SANS,20) SetFontColor(#BLACK) SetFontStyle (#bold|#antialias)
Createtextobject (1,"SYS:") CreateSprite (1,#textobject,1) Displaysprite (1,maxw+80,260)
Createtextobject (1,ct$[9][language]) CreateSprite (2,#textobject,1) Displaysprite (2,maxw+80,290)
Createsprite (3,#brush,12) Displaysprite (3,maxw+40,320)

Function p_drawevo(perc)
	displaybrushpart (15,0,0,50,365,perc/100*540,30)
EndFunction

Function p_event(msg)
Switch msg.id
	Case 1
		target$=pathrequest ("ct$[2]",#REQ_NORMAL,"SYS:")
		if isdirectory(target$)=FALSE or target$="" then target$="SYS:"
		ttarget$=target$
		SetFont (#SANS,20) SetFontStyle (#BOLD|#ANTIALIAS) SetFontColor(#BLACK) CreateTextobject(1,ttarget$)
		while getattribute(#textobject,1,#attrwidth)>620-maxw-80 
			ttarget$="..."..unrightstr(ttarget$,4) Createtextobject(1,ttarget$)
		WEND
 	CreateSprite (1,#textobject,1) Displaysprite (1,maxw+80,260)

	Case 2
		language=language+1 If language>1 then language=0
		SetFont (#SANS,20) SetFontColor(#BLACK) SetFontStyle (#bold|#antialias)
		CreateTextobject (1,ct$[9][language]) Createsprite (2,#textobject,1) Displaysprite (2,maxw+80,290)

	Case 3
		examples=1-examples CreateSprite(3,#brush,11+examples) Displaysprite (3,maxw+40,320)

	Case 4
		if systemrequest ("Cancel",ct$[10],ct$[11].."|"..ct$[12])=1 then end()
	Case 5
		p_install()
EndSwitch
Endfunction

Function p_message(msg)
Switch msg.id
	Case 1 p_msg (ct$[13])
	Case 2 p_msg (ct$[14])
	Case 3 p_msg (ct$[15])
	Case 4 p_msg (ct$[16])
	Case 5 p_msg (ct$[17])

EndSwitch
EndFunction


Function p_msg(nr)
	SetFont(#SANS,18) SetFontColor(#WHITE) SetFontStyle (#ANTIALIAS|BOLD)
	CreateTextobject(1,nr) CreateSprite(6,#textobject,1) Displaysprite (6,#CENTER,370)
EndFunction

Function p_remmsg()
	freesprite(6)
EndFunction

Function p_install()
	for t=1 to 5 do deletebutton(t)
	p_msg(ct$[18])
	t$="ArtBase" if rightstr(target$,1)<>":" and rightstr(target$,1)<>"/" then t$="/"..t$ 
;Create ArtBase:
	changedirectory(target$)
	makedirectory ("ArtBase")
	execute ("Assign ArtBase: \""..target$..t$.."\"")
	changedirectory(curdir)
	p_drawevo(5)
;Create Directories
	makedirectory ("ArtBase:Docs")	
	makedirectory ("ArtBase:Projects")	
	makedirectory ("ArtBase:Cache")	
	makedirectory ("ArtBase:Images")	
	makedirectory ("ArtBase:Designs")	
;Edit User-Startup
	openfile(1,"s:user-startup",#MODE_READ)
	Openfile(2,"t:user-startup",#MODE_WRITE)
	while eof(1)=FALSE
		result=FALSE
		t1$=readline(1)
		if findstr(lowerstr(t1$),"begin artbase")>-1 then result=TRUE
		if findstr(lowerstr(t1$),"assign artbase:")>-1 then result=TRUE
		if findstr(lowerstr(t1$),"end artbase")>-1 then result=TRUE
		if result=FALSE then writeline(2,t1$)
	WEND()
	Writeline(2,";Begin ArtBase")
	Writeline(2,"  Assign ArtBase: "..target$..t$)
	Writeline(2,";End ArtBase")
	Closefile(1) Closefile(2)
	Deletefile ("s:user-startup") Copyfile ("t:user-startup","s:") Deletefile ("t:user-startup")
p_drawevo(10)
;Copy Icons
	Copyfile("Icons/Docs.info","ArtBase:")
	Copyfile("Icons/Projects.info","ArtBase:")
	Copyfile("Icons/ArtBase.info","ArtBase:")
	Copyfile("Icons/ArtBase_dir.info",target$,"ArtBase.info")
;Copy libs
	if exists("Libs:hollywood/MuiRoyale.hwp")=1
		execute ("c:Version >t:MRV Libs:Hollywood/MuiRoyale.hwp")
		openfile(1,"t:MRV",#MODE_READ)
		line$=readline(1) closefile(1) Deletefile("t:MRV")
		line$=replacestr(line$,"muiroyale.hwp ","")
		MRV=val(line$)
		if mrv<1.3 then Copyfile ("External/"..ver,"libs:Hollywood","",NIL,NIL,"*")	
		gsl$=filetostring("libs:hollywood/muiroyale.hwc")
		If findstr(gsl$,ver)=-1 then Copyfile ("External/"..ver,"libs:Hollywood","",NIL,NIL,"*")
	Else
		makedirectory ("Libs:Hollywood")
		Copyfile ("External/"..ver,"libs:Hollywood","",NIL,NIL,"*")	
	EndIF
p_drawevo(20)
;Copy configs
	Copyfile ("Configs/ArtBase.cfg","ENV:") Copyfile ("Configs/ArtBase.cfg","ENVARC:")
	If examples=1
		Copyfile("Configs/ArtBaseUsed","ENV:") Copyfile("Configs/ArtBaseUsed","ENVARC:")
	EndIf
;Copy catalogs
	f$={} d$={}
	readdirectory("sys:locale/catalogs",f$,d$)
	dirs$=";"..concat(d$,";")..";"
	if findstr(dirs$,"german")>-1 then copyfile("catalogs/german/artbase.catalog","sys:locale/catalogs/german")
	if findstr(dirs$,"french")>-1 then copyfile("catalogs/french/artbase.catalog","sys:locale/catalogs/french")
	if findstr(dirs$,"polish")>-1 then copyfile("catalogs/polish/artbase.catalog","sys:locale/catalogs/polish")
	if findstr(dirs$,"swedish")>-1 then copyfile("catalogs/swedish/artbase.catalog","sys:locale/catalogs/swedish")
;	if findstr(dirs$,"spanish")>-1 then copyfile("catalogs/spanish/artbase.catalog","sys:locale/catalogs/spanish")

	if findstr(dirs$,"deutsch")>-1 then copyfile("catalogs/german/artbase.catalog","sys:locale/catalogs/deutsch")
	if findstr(dirs$,"français")>-1 then copyfile("catalogs/french/artbase.catalog","sys:locale/catalogs/français")
	if findstr(dirs$,"svenska")>-1 then copyfile("catalogs/swedish/artbase.catalog","sys:locale/catalogs/svenska")
	if findstr(dirs$,"polski")>-1 then copyfile("catalogs/polish/artbase.catalog","sys:locale/catalogs/polski")
;	if findstr(dirs$,"español")>-1 then copyfile("catalogs/spanish/artbase.catalog","sys:locale/catalogs/español")
p_drawevo(30)
;Copy binaries
	Copyfile ("Binaries/ArtBase_"..ver,"ArtBase:","ArtBase")
p_drawevo(50)
;Copy Manual
	copyfile ("Docs/"..doclang$[language],"ArtBase:Docs")
p_drawevo(80)
;Copy Designs, Images and projects
	copyfile ("Designs","ArtBase:Designs")
p_drawevo(90)
	copyfile ("Images","ArtBase:Images")
	If examples=1 then copyfile ("Projects","ArtBase:Projects")
p_drawevo(100)
	p_msg(ct$[19])
	result=systemrequest(ct$[19],ct$[19].." "..ct$[20],ct$[11].."|"..ct$[12])
	if result=1 then run("ArtBase:ArtBase")
	end()

EndFunction

;nprint (systlang)

event={onmouseup=p_event, onmousedown=p_event}
for t=1 to 3 DO makebutton(t,#SIMPLEBUTTON,maxw+40,230+t*30,24,24,{onmouseup=p_event,onmouseover=p_message,onmouseout=p_remmsg})
makebutton(4,#SIMPLEBUTTON,50,400,200,50, {onmouseup=p_event, onmouseover=p_message,onmouseout=p_remmsg})
makebutton(5,#SIMPLEBUTTON,390,400,200,50, {onmouseup=p_event, onmouseover=p_message,onmouseout=p_remmsg})

repeat
	waitevent()
forever