G4C ; <- Das muß immer in der ersten Zeile stehen!!!


;--------------------------------------
; $VER: AmiShutDown V1.22 (12.04.2002)
;--------------------------------------


WINBIG -1 -1 300 150 ""
WinFont xhelvetica.font 11 000
WinType 10000000
Screen Workbench


xOnLoad
	set margins 5/8/2

	palette get "*" tmpimg
	palette save tmpimg t:palette

	freeimage tmpimg

	prog = AmiShutDown
	ver  = 1
	rev  = 22
	date = 12.04.2002
	name = Nightshade
	mail = thenightshade@freenet.de

	reset = $$this.path\ColdReboot

	help = off

	ASK = NO
	QUITKEY = q

	ttget :$prog

	if $ASK = YES
		update #this 2 0
	else
		update #this 2 1
	endif

	update #this 1 2

	sd_mode = 2

	setwintitle #this "$prog V$ver\.$rev ($date)"

	gosub #this win_2_front

	guiload blankwin
	guiload as_abort

	guiopen blankwin

	GuiOpen #This


xonclose
	if $exec != 1
		guiclose blankwin
		guiquit #this
	endif


xOnQuit
	palette load t:palette tmpimg
	palette set tmpimg '*'

	freeimage tmpimg

	freeimage pic1
	freeimage pic2

	delete t:palette

	guiquit as_abort
	guiquit blankwin

	GuiQuit #This


xonreload
	gosub #this win_2_front


xroutine win_2_front
	guiscreen #Workbench front
	guiwindow #this front
	guiwindow #this on


xicon 12 24 :AmiShutdown
	if $help = off
		ifexists file env:.lastoption
			a = "$.lastoption"
		else
			flash
			a = "Keine Informationen verfügbar!"
		endif
	else
		a = "Zeigt die zuletzt ausgeführte Option an"
	endif
	guiwindow #this wait
		ezreq $a "Okay" ""
	guiwindow #this resume
	gadkey #32


BOX 0 0 0 0 out button


XTEXTBOX 60 24 225 84 "" ""
	attr tbox 2/1/0/ridge/in
	attr title "2/1/shadow/left/top/Bitte, den Rechner:"


xCycler 70 36 200 17 "" "sd_mode"
	CSTR "In Bereitschaft versetzten  " 0
	CSTR "Herunterfahren              " 1
	CSTR "Neustarten                  " 2
	CSTR "Neustarten im AmigaDOS Modus" 3
		gosub #this onhelp
			gadtitle right
				gadid 1


xCheckBox 70 84 20 15 "_Sofortige Ausführung" ASK 'NO' 'YES' off
	if $help = on
		guiwindow #this wait
			ezreq "Option wird sofort ausgeführt, wenn aktiviert" "Toll" ""
		guiwindow #this resume
	endif
		gadtitle right
			gadid 2


xroutine onhelp
	if $help = on
		docase $sd_mode
		  case = 0
					a = "Das schwarze Fenster bleibt eingeblendet,\n so lange bis die linke Maustaste gedrückt wird"
					break
		  case = 1
					a = "Fährt den Rechner herunter"
					break
		  case = 2
					a = "Startet den Rechner neu"
					break
		  case = 3
					a = "Startet den Rechner\nim AmigaDOS Modus neu"
					break
		endcase
		guiwindow #this wait
			ezreq $a "Achso" ""
		guiwindow #this resume
	else
		if $sd_mode = 0
			setgad #this 2 off
		else
			setgad #this 2 on
		endif
	endif


square 59 119 76 24 1 nofill


XBUTTON 60 120 75 23 "Okay"
	if $help = off
		exec = 1
		guiclose #this
		gosub blankwin execute
	else
		guiwindow #this wait
			ezreq "Führt die gewählte Option aus" "Gut" ""
		guiwindow #this resume
	endif
	gadkey #13


XBUTTON 140 120 75 23 "Abbrechen"
	if $help = off
		ifexists file ~env:.canceled
			guiclose #this
			gosub #this about
			.canceled = ""
		endif
		guiquit #this
	else
		guiwindow #this wait
			ezreq "Schiesst das Fenster..." "Ah ha!" ""
		guiwindow #this resume
	endif
	gadkey #27


XBUTTON 220 120 75 23 "_Hilfe"
	guiwindow #this wait
	if $help = off
		help = on
		ezreq "Die Hilfsfunktion wurde aktiviert!\n\nKlicke nun auf die Buttons um\ndie Erläuterungen zu erhalten.\n\nÜbrigens:\nDrück mal die Rechte Maustaste!" "Alles klar!" ""
	else
		help = off
		ezreq "Die Hilfsfunktion wurde deaktiviert!" "Zeige Tasten|Danke!" helpme
		if $helpme = 1
			ezreq "\nTasten in der Übersicht:\n\n[LEERTASTE] = Letzte Funtion \n[TAB] / [TAB+SHIFT] = Wechselt Modi\n[RETURN] / [ENTER] = Führt die gewählte Option aus\n[ESCAPE] = Schliesst Fenster\n" "Super" ""
		endif
	endif
	guiwindow #this resume


xonrmb
	gosub #this about


xroutine about
	guiwindow #this wait
		ezreq "$prog V$ver\.$rev ($date)\nEmailware ©2001/2002 by $name\n($mail)" "Nett" ""
	guiwindow #this resume


xhotkey "ctrl q" on
xhotkey "ctrl c" on
xonkey #5
xonkey #7
xonkey #8
xonkey #18


xonkey #9                  ; TAB
	if $sd_mode < 3
		++sd_mode
	else
		sd_mode = 0
	endif
	update #this 1 $sd_mode
	gosub #this onhelp


xonkey #R
	if $$RAWKEY.CODE = 66   ; SHIFT + TAB
		if $sd_mode > 0
			--sd_mode
		else
			sd_mode = 3
		endif
		update #this 1 $sd_mode
		gosub #this onhelp
	else
		stop
	endif



;-----------------
 newfile blankwin
;-----------------

WinBig -1 -1 0 0 ""
WinType 00001000
WinBackground Solid 1 0
VarPath AmiShutDown
Screen Workbench


xhotkey "ctrl q" on
xhotkey "ctrl c" on
xonkey #5
xonkey #7
xonkey #8
xonkey #18


xonkey #V
	if $$vankey.letter == $QUITKEY
		if $sd_mode = 1
			guiclose this
			guiquit AmiShutDown
		endif
	else
		stop
	endif

xonclick
	if $close != no
		guiquit $prog
	else
		gosub #this activate_abortwin
	endif


xondoubleclick
	gosub #this activate_abortwin


xroutine activate_abortwin
	ifexists window as_abort
		guiwindow as_abort on
		setpointer as_abort default
	elseifexists window $prog
		guiwindow $prog on
		setpointer as_abort default
	endif


xonclose
	setpointer #this default

xonopen
	close = no
	setpointer #this hide
	

xroutine execute
	if $sd_mode = 0
		close = yes
		stop
	else
		if $ASK = YES
			guiopen as_abort
		else
			gosub #this option
		endif
	endif


xroutine option
	loadimage $$this.path\LOGOW.SYS pic1 noremap

	palette set pic1 "*"

	changeimage blankwin 1 -1 -1 pic1

	if $sd_mode != 0
		.lastoption = "Zuletzt "

		if $sd_mode = 1
			append env:.lastoption "heruntergefahren\n"
		endif

		if $sd_mode = 2
		or $sd_mode = 3
			append env:.lastoption "neugestartet\n"
		endif

		append env:.lastoption "am $$SYS.DATE um $$SYS.TIME Uhr"

		if $sd_mode = 3
			append env:.lastoption "\nim AmigaDOS Modus"
		endif

		copy env:.lastoption envarc:
	endif

	if $sd_mode = 1
		delay 200
		loadimage $$this.path\LOGOS.SYS pic2 noremap
		palette set pic2 "*"
		changeimage #this 1 -1 -1 pic2
	endif

	if $sd_mode = 2
		delay 150
		cli $reset
	endif

	if $sd_mode = 3
		.DosBoot = ""
		copy Env:.DosBoot SYS:
		delay 80
		cli $reset
	endif


image 0 0 ""
	gadid 1



;------------------
  newfile as_abort
;------------------

WINBIG -1 -1 200 70 " "
WinType 00000000
WinBackground pattern 2 0
Screen Workbench
VarPath AmiShutDown


xhotkey "ctrl q" on
xhotkey "ctrl c" on
xonkey #5
xonkey #7
xonkey #8
xonkey #18


xonkey #13
	gosub #this stop


xonkey #27
	gosub #this stop


xOnOpen
	if $sd_mode = 1
		setwintitle #this "Fahre Rechner runter..."
	elseif $sd_mode = 2
	or $sd_mode = 3
		setwintitle #this "Neustart des Rechners..."
	endif

	cnt = 10
	p = 0

	txt = "...in $cnt Sekunden"

	update #this 2 $txt

	partredraw #this 0 0 0 0

	setgad #this 1 on
	

xtimer repeat 0:0:01 off
	if $cnt > 0
		--cnt
		txt = "...in $cnt Sekunden"
		update #this 2 $txt
		p = $($p + 10)
		update #this 4 $p
	else
		setgad #this 1 off
		setgad #this 3 off
		guiclose #this
		gosub blankwin option 
	endif
	partredraw #this 0 0 0 0
	gadid 1


XTEXTBOX -1 5 190 40 "" ""
	attr tbox 2/1/0/button/in


gauge -1 15 175 18 in button 3 0 0
	gadid 4


XTEXTBOX -1 15 175 18 "" ""
	attr tbstyle 2/1/shadow/center
	attr tbox 0/0/-1/none
		gadid 2


XBUTTON -1 50 86 17 "_Stopp"
	gosub #this stop
		gadfont xhelvetica.font 11 010
			gadid 3


xroutine stop
	if $cnt > 0
		update #this 2 "...Abgebrochen!"
		partredraw #this 0 0 0 0
		setgad #this 1 off
		delay 40
		guiclose #this
		guiquit $prog
	endif
