#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=GUIs Bilder\Icon.ico
#AutoIt3Wrapper_outfile=Office Starter 2010.exe
#AutoIt3Wrapper_UseX64=n
#AutoIt3Wrapper_Res_Comment=Neue Office 2010 Version.
#AutoIt3Wrapper_Res_Description=Office Starter mit Word, Excel, PowerPoint und Outlook, bald kommt auch OneNote
#AutoIt3Wrapper_Res_Fileversion=2.2.0.0
#AutoIt3Wrapper_Res_LegalCopyright=(c) Johannes Emich
#AutoIt3Wrapper_Res_Language=1031
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Date.au3>
#include <ProgressConstants.au3>

If FileExists(@AppDataDir & "\OfficeStarter\UpdateTool.exe") Then FileDelete(@AppDataDir & "\OfficeStarter\UpdateTool.exe")
DirCreate(@AppDataDir & "\OfficeStarter\")
;Überprüfung, ob der O S das erst mal gestartet wird. Bei erstmaligem Start erscheint eine Information zur Konfiguration
$wert = IniRead(@AppDataDir & "\OfficeStarter\config.cfg", "Start", "FirstStart", "0")
If $wert = 0 Then
	$answer = MsgBox(65, "Office Starter", 'Das ist ihr erster Start des Office Starters. Bitte gehen sie in die Einstellungen und konfigurieren sie den Office Starter oder laden sie eine alte Konfigurationsdatei im BackUp Menü. Um Updates zu laden, gehen sie in die Einstellungen un klicken sie auf "Update suchen".')
	If $answer = 2 Then
		Exit
	Else
		IniWrite(@AppDataDir & "\OfficeStarter\config.cfg", "Start", "FirstStart", "1")

	EndIf
EndIf
;-----------------------------------------------------------------------------
IniWrite(@AppDataDir & "\OfficeStarter\config.cfg", "ScriptDir", "ScriptDir", @ScriptDir)
;Lesen
$name_word = IniRead(@AppDataDir & "\OfficeStarter\config.cfg", "Buttons", "word", "Textdokument")
$name_excel = IniRead(@AppDataDir & "\OfficeStarter\config.cfg", "Buttons", "excel", "Tabelle")
$name_powerpnt = IniRead(@AppDataDir & "\OfficeStarter\config.cfg", "Buttons", "powerpnt", "Präsentation")
$name_outlook = IniRead(@AppDataDir & "\OfficeStarter\config.cfg", "Buttons", "outlook", "E-Mail")
$pfad_word = IniRead(@AppDataDir & "\OfficeStarter\config.cfg", "Pfade", "word", "")
$pfad_excel = IniRead(@AppDataDir & "\OfficeStarter\config.cfg", "Pfade", "excel", "")
$pfad_powerpnt = IniRead(@AppDataDir & "\OfficeStarter\config.cfg", "Pfade", "powerpnt", "")
$pfad_outlook = IniRead(@AppDataDir & "\OfficeStarter\config.cfg", "Pfade", "outlook", "")


;HauptGUI des O S
#Region ### START Koda GUI section ### Form=C:\Users\Johannes Emich\Documents\AutoIt Projekte\Beste Programme\Office Launcher\Heimanwender\Version 2\office2.kxf
$prog = GUICreate("Office Starter 2010", 502, 303, 416, 185)
GUISetIcon(-1)
$Button1 = GUICtrlCreateButton($name_word, 376, 24, 107, 33, $WS_GROUP)
$Button2 = GUICtrlCreateButton($name_excel, 376, 96, 107, 33, $WS_GROUP)
$Button3 = GUICtrlCreateButton($name_powerpnt, 376, 168, 107, 33, $WS_GROUP)
$Button4 = GUICtrlCreateButton($name_outlook, 376, 240, 107, 33, $WS_GROUP)
$Button5 = GUICtrlCreateButton("Einstellungen", 0, 0, 75, 25, $WS_GROUP)
$Pic2 = GUICtrlCreatePic(@ScriptDir & "\Bilder\Excel.bmp", 304, 88, 48, 48, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
$Pic3 = GUICtrlCreatePic(@ScriptDir & "\Bilder\Word.bmp", 304, 16, 48, 48, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
$Pic4 = GUICtrlCreatePic(@ScriptDir & "\Bilder\PowerPoint.bmp", 304, 160, 48, 48, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
$Pic5 = GUICtrlCreatePic(@ScriptDir & "\Bilder\Outlook.bmp", 304, 232, 48, 48, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
$Label1 = GUICtrlCreateLabel("Version 2.2 f2010", 8, 288, 200, 17)
$Pic1 = GUICtrlCreatePic(@ScriptDir & "\Bilder\Logo.bmp", 8, 26, 260, 260, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

;EinstellungsGUI des O S
#Region ### START Koda GUI section ### Form=C:\Users\Johannes Emich\Documents\AutoIt Projekte\Beste Programme\Office Launcher\Heimanwender\Version 2\GUIs Bilder\einstellungen.kxf
$Form2 = GUICreate("Einstellungen", 384, 430, 457, 165)
$Label25 = GUICtrlCreateLabel("Einstellungen", 16, 8, 113, 24)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
$Input21 = GUICtrlCreateInput("Input1", 16, 64, 145, 21)
$Label21 = GUICtrlCreateLabel("Pfad Microsoft Office Word", 16, 40, 132, 17)
$Button21 = GUICtrlCreateButton("...", 168, 64, 33, 25, $WS_GROUP)
$Input22 = GUICtrlCreateInput("", 16, 128, 145, 21)
$Label22 = GUICtrlCreateLabel("Pfad Microsoft Office Excel", 16, 104, 132, 17)
$Button22 = GUICtrlCreateButton("...", 168, 128, 33, 25, $WS_GROUP)
$Label23 = GUICtrlCreateLabel("Pfad Micosoft Office PowerPoint", 16, 168, 157, 17)
$Input23 = GUICtrlCreateInput("", 16, 192, 145, 21)
$Button23 = GUICtrlCreateButton("...", 168, 192, 33, 25, $WS_GROUP)
$Label24 = GUICtrlCreateLabel("Pfad Microsoft Office Outlook", 16, 232, 143, 17)
$Input24 = GUICtrlCreateInput("", 16, 256, 145, 21)
$Button24 = GUICtrlCreateButton("...", 168, 256, 33, 25, $WS_GROUP)
$Checkbox1 = GUICtrlCreateCheckbox("Nach Klick beenden", 16, 304, 121, 17)
$Input35 = GUICtrlCreateInput("", 224, 64, 145, 21)
$Label36 = GUICtrlCreateLabel("Text des Word-Buttons", 224, 40, 113, 17)
$Input36 = GUICtrlCreateInput("", 224, 128, 145, 21)
$Label37 = GUICtrlCreateLabel("Text des Excel-Buttons", 224, 104, 113, 17)
$Input37 = GUICtrlCreateInput("", 224, 192, 145, 21)
$Label38 = GUICtrlCreateLabel("Text des PowerPoint-Buttons", 224, 168, 141, 17)
$Input38 = GUICtrlCreateInput("", 224, 256, 145, 21)
$Label39 = GUICtrlCreateLabel("Text des Outlook-Buttons", 224, 232, 124, 17)
$Button25 = GUICtrlCreateButton("Abbrechen", 16, 344, 75, 25, BitOR($BS_DEFPUSHBUTTON,$WS_GROUP))
$Button26 = GUICtrlCreateButton("Speichern", 112, 344, 75, 25, $WS_GROUP)
$Button27 = GUICtrlCreateButton("BackUp", 280, 312, 91, 25, $WS_GROUP)
$Label210 = GUICtrlCreateLabel("Rechtlicher Hinweis: Die Rechte an den Grafiken hat die Microsoft Corporation. Das OfficeStarter-Logo beinhaltet das Microsoft Office 2010 Logo von Microsoft.", 8, 384, 357, 40)
$Button28 = GUICtrlCreateButton("Update suchen", 280, 344, 91, 25, $WS_GROUP)
#EndRegion ### END Koda GUI section ###
;BackUp GUI
#Region ### START Koda GUI section ### Form=BackUp
$Form3 = GUICreate("BackUp", 290, 239, 227, 158, BitOR($WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS))
$Input41 = GUICtrlCreateInput("", 16, 40, 201, 21)
$Button41 = GUICtrlCreateButton("...", 232, 40, 41, 25, $WS_GROUP)
$Button42 = GUICtrlCreateButton("BackUp", 16, 72, 259, 25, $WS_GROUP)
$Group41 = GUICtrlCreateGroup("BackUp erstellen", 8, 16, 273, 97)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Input42 = GUICtrlCreateInput("", 16, 152, 201, 21)
$Button43 = GUICtrlCreateButton("...", 232, 152, 41, 25, $WS_GROUP)
$Button44 = GUICtrlCreateButton("Wiederherstellen", 16, 184, 259, 25, $WS_GROUP)
$Group42 = GUICtrlCreateGroup("Aus BackUp Wiederherstellen", 8, 128, 273, 97)
GUICtrlCreateGroup("", -99, -99, 1, 1)
#EndRegion ### END Koda GUI section ###

While 1
	;---------------------Lesen der Werte (Pfade)---------------------------------------
	$pfad_word = IniRead(@AppDataDir & "\OfficeStarter\config.cfg", "Pfade", "word", "")
	$pfad_excel = IniRead(@AppDataDir & "\OfficeStarter\config.cfg", "Pfade", "excel", "")
	$pfad_powerpnt = IniRead(@AppDataDir & "\OfficeStarter\config.cfg", "Pfade", "powerpnt", "")
	$pfad_outlook = IniRead(@AppDataDir & "\OfficeStarter\config.cfg", "Pfade", "outlook", "")
	$AfterKlickExit = IniRead(@AppDataDir & "\OfficeStarter\config.cfg", "Check", "KlickExit", "true")
	$name_word = IniRead(@AppDataDir & "\OfficeStarter\config.cfg", "Buttons", "word", "Textdokument")
	$name_excel = IniRead(@AppDataDir & "\OfficeStarter\config.cfg", "Buttons", "excel", "Tabelle")
	$name_powerpnt = IniRead(@AppDataDir & "\OfficeStarter\config.cfg", "Buttons", "powerpnt", "Präsentation")
	$name_outlook = IniRead(@AppDataDir & "\OfficeStarter\config.cfg", "Buttons", "outlook", "E-Mail")
	;-----------------------------------------------------------------------------------
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $Button1
			_Run($pfad_word)
		Case $Button2
			_Run($pfad_excel)
		Case $Button3
			_Run($pfad_powerpnt)
		Case $Button4
			_Run($pfad_outlook)
		Case $Button5
			GUIshow($prog,$Form2,$Form2)
			If $AfterKlickExit = "true" Then
				GUICtrlSetState($Checkbox1, $GUI_CHECKED)
			Else
				GUICtrlSetState($Checkbox1, "")
			EndIf
			GUICtrlSetData($Input21, $pfad_word)
			GUICtrlSetData($Input22, $pfad_excel)
			GUICtrlSetData($Input23, $pfad_powerpnt)
			GUICtrlSetData($Input24, $pfad_outlook)
			GUICtrlSetData($Input35, $name_word)
			GUICtrlSetData($Input36, $name_excel)
			GUICtrlSetData($Input37, $name_powerpnt)
			GUICtrlSetData($Input38, $name_outlook)
			While 1 ;--------------------Anfang EinstellungsGUI-------------------------------------
				$nMsg = GUIGetMsg()
				Switch $nMsg
					Case $GUI_EVENT_CLOSE, $Button25 ;--------------------Schließen und Abbrechen Buttons----------------------------
						GUIhide($Form2,$prog,$Form2)
						ExitLoop
					Case $Button21
						$pfad_word = FileOpenDialog("Word | Öffnen", "C:\", "Programm (*.exe)", 3) ;Auswahl der Word.exe
						GUICtrlSetData($Input21, $pfad_word)
					Case $Button22
						$pfad_excel = FileOpenDialog("Excel | Öffnen", "C:\", "Programm (*.exe)", 3) ;Auswahl der Excel.exe
						GUICtrlSetData($Input22, $pfad_excel)
					Case $Button23
						$pfad_powerpnt = FileOpenDialog("PowerPoint | Öffnen", "C:\", "Programm (*.exe)", 3) ;Auswahl der PowerPnt.exe
						GUICtrlSetData($Input23, $pfad_powerpnt)
					Case $Button24
						$pfad_outlook = FileOpenDialog("Outlook | Öffnen", "C:\", "Programm (*.exe)", 3) ;Auswahl der Outlook.exe
						GUICtrlSetData($Input24, $pfad_outlook)
					Case $Button26 ;----------Speichern Button---------------------------------------------
						If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then										;Checkbox Überprüfung-------
							IniWrite(@AppDataDir & "\OfficeStarter\config.cfg","Check","KlickExit","true")
						Else
							IniWrite(@AppDataDir & "\OfficeStarter\config.cfg","Check","KlickExit","false")
						EndIf
						$text_word = GUICtrlRead($Input35)
						$text_excel = GUICtrlRead($Input36)
						$text_powerpnt = GUICtrlRead($Input37)
						$text_outlook = GUICtrlRead($Input38)
						$2pfad_word = GUICtrlRead($Input21)
						$2pfad_excel = GUICtrlRead($Input22)
						$2pfad_powerpnt = GUICtrlRead($Input23)
						$2pfad_outlook = GUICtrlRead($Input24)
						IniWrite(@AppDataDir & "\OfficeStarter\config.cfg", "Buttons", "word", $text_word)
						IniWrite(@AppDataDir & "\OfficeStarter\config.cfg", "Buttons", "excel", $text_excel)
						IniWrite(@AppDataDir & "\OfficeStarter\config.cfg", "Buttons", "powerpnt", $text_powerpnt)
						IniWrite(@AppDataDir & "\OfficeStarter\config.cfg", "Buttons", "outlook", $text_outlook)
						IniWrite(@AppDataDir & "\OfficeStarter\config.cfg", "Pfade", "word", $2pfad_word) ;---------------------------------------
						IniWrite(@AppDataDir & "\OfficeStarter\config.cfg", "Pfade", "excel", $2pfad_excel) ;Schreiben der Werte
						IniWrite(@AppDataDir & "\OfficeStarter\config.cfg", "Pfade", "powerpnt", $2pfad_powerpnt) ;
						IniWrite(@AppDataDir & "\OfficeStarter\config.cfg", "Pfade", "outlook", $2pfad_outlook) ;---------------------------------------
						GuiCtrlSetData($Button1,$text_word)		;--
						GuiCtrlSetData($Button2,$text_excel)	;--Buttonbeschriftungen ändern
						GuiCtrlSetData($Button3,$text_powerpnt)	;--
						GuiCtrlSetData($Button4,$text_outlook)	;--
						GUIhide($Form2,$prog,$Form2)
						ExitLoop
					Case $Button27
						GUIshow($Form2,$Form3,$Form3)
						GUICtrlSetState($Button42, $GUI_Disable)
						GUICtrlSetState($Button44, $GUI_Disable)
						While 1											;BackUp----------------------------------------------------------------------
							$nMsg = GUIGetMsg()
							Switch $nMsg
								Case $GUI_EVENT_CLOSE
									GUIhide($Form3,$Form2,$Form3)
									ExitLoop
								Case $Button41
									$pfad_backup = FileSelectFolder("Ordner für BackUp wählen","",7)
									GUICtrlSetData($Input41,$pfad_backup)
									GUICtrlSetState($Button42, $GUI_Enable)
								Case $Button42
									$backup = FileRead(@AppDataDir & "\OfficeStarter\config.cfg")
									FileWrite($pfad_backup & "\OfficeStarter_backup_" & _NowDate() &".cfg",$backup)
									If FileExists($pfad_backup & "\OfficeStarter_backup_" & _NowDate() &".cfg") Then
										MsgBox(48,"Erfolgreich","BackUp erfolgreich")
										GUIhide($Form3,$Form2,$Form3)
										ExitLoop
									Else
										MsgBox(48,"Fehler","Fehler beim BackUp")
									EndIf
								Case $Button43
									$pfad_restore = FileOpenDialog("Ordner des BackUps wählen","C:\","Konfigurationsdateien (*.cfg; *.ini)",1)
									GUICtrlSetData($Input42,$pfad_restore)
									GUICtrlSetState($Button44, $GUI_Enable)
								Case $Button44
									$restore = FileRead($pfad_restore)
									FileDelete(@AppDataDir & "\OfficeStarter\config.cfg")
									FileWrite(@AppDataDir & "\OfficeStarter\config.cfg",$restore)
									$answer2 = MsgBox(36,"Fertig","Fertig, der OfficeStarter muss nun neugestartet werden. Beenden?")
									If $answer2 = 6 Then
										Exit
									EndIf
							EndSwitch
						Wend	;Ende BackUp----------------------------------------------------------------
					Case $Button28
						GUICtrlSetData($Button28,"Lädt...")
						Update()
				EndSwitch
			WEnd 	;------------------ENDE EinstellungsGUI--------------------------------------------

	EndSwitch
WEnd

Func _Run($pfad)
	If FileExists($pfad) Then
		If $AfterKlickExit = "true" Then
			Run($pfad)
			Exit
		Else
			Run($pfad)
		EndIf
	Else
		MsgBox(48,"Error","Die gewählte Datei existiert nicht oder der Pfad wurde falsch/nicht angegeben.")
	EndIf
EndFunc

Func GUIhide($Disable,$Enable,$Hide)
	GUISetState(@SW_DISABLE, $Disable)
	GUISetState(@SW_ENABLE, $Enable)
	GUISetState(@SW_HIDE, $Hide)
EndFunc

Func GUIshow($Disable2,$Show2,$Enable2)
	GUISetState(@SW_DISABLE, $Disable2)
	GUISetState(@SW_SHOW, $Show2)
	GUISetState(@SW_ENABLE, $Enable2)
EndFunc

Func Update()
	;------------Code by Jörg Bayer
	Local $hDownload = InetGet("http://joi.cwsurf.de/OS.ver", @AppDataDir & "\OfficeStarter\update.ver", 1, 1)
	Do
		Sleep(250)
	Until InetGetInfo($hDownload, 2)    ; Prüft, ob der Download fertig ist.
	Local $nBytes = InetGetInfo($hDownload, 0)
	InetClose($hDownload)   ; Schleißt das Handle zu den Ressourcen.
	If $nBytes = 0 Then Exit

	$newupdates = FileRead(@AppDataDir & "\OfficeStarter\update.ver")
	$oldupdates = FileRead(@AppDataDir & "\OfficeStarter\version.ver")
	;------------Code by Jörg Bayer Ende
	If $newupdates > $oldupdates Then
		$answer = MsgBox(68,"Update Tool","Eine neue Version des Office Starters (Version " & $newupdates & ") ist vorhanden. Soll diese geladen und installiert werden?")
		If $answer = 6 Then
			GUICtrlSetData($Button28,"Lädt...")
			Local $hDownload = InetGet("http://dl.dropbox.com/u/8045413/UpdateTool.exe",@AppDataDir & "\OfficeStarter\UpdateTool.exe", 1, 1)
			Do
				Sleep(250)
			Until InetGetInfo($hDownload, 2)    ; Prüft, ob der Download fertig ist.
			Local $nBytes = InetGetInfo($hDownload, 0)
			InetClose($hDownload)   ; Schließt das Handle zu den Ressourcen.
			If $nBytes = 0 Then Exit
			Sleep(3000)
			FileDelete(@AppDataDir & "\OfficeStarter\update.ver")
			FileDelete(@AppDataDir & "\OfficeStarter\version.ver")
			FileWrite(@AppDataDir & "\OfficeStarter\version.ver",$newupdates)
			FileSetAttrib(@AppDataDir & "\OfficeStarter\version.ver","+RH")
			Run(@AppDataDir & "\OfficeStarter\UpdateTool.exe")
			Exit
		Else
			FileDelete(@AppDataDir & "\OfficeStarter\update.ver")
			GUICtrlSetData($Button28,"Update suchen")
			Return
		EndIf
	Else
		MsgBox(64,"Update Tool","Ihre Version des OfficeStartes ist die aktuellste.")
		GUICtrlSetData($Button28,"Update suchen")
		FileDelete(@AppDataDir & "\OfficeStarter\update.ver")
	EndIf
EndFunc