#include <file.au3>
Dim $pathObjDictINI = 'objDict_abbrev_calltip.INI'
Dim $newAbbProp = IniReadSection($pathObjDictINI, 'abbrev_properties')
Dim $CallTip = IniReadSection($pathObjDictINI, 'calltips')
Dim $Scite = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\SciTe\"
Dim $pathAbbProp = @HomeDrive & @HomePath & "\abbrev.properties"
Dim $pathKeyAbb = $Scite & "au3.keywords.abbreviations.properties"
Dim $pathUserCallTip = $Scite & '\api\au3.user.calltips.api'
Dim $arAbbProp, $aAbbr[1], $var, $start = False, $count = 1
Dim $lastLine = '#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#-#'

; neue abbrev.properties eintragen
_FileReadToArray($pathAbbProp, $arAbbProp)
For $i = $arAbbProp[0] To 1  Step -1
	If $arAbbProp[$i] = $lastLine Then
		$arAbbProp[$i] = ''
		ExitLoop
	EndIf
Next
ReDim $arAbbProp[UBound($arAbbProp)+13]
For $k = 1 To 12
	$arAbbProp[$i+$k] = $newAbbProp[$k][0] & '=' & $newAbbProp[$k][1]
Next
$arAbbProp[$i+13] = $lastLine
If FileMove($pathAbbProp, $pathAbbProp & @YEAR & @MON & @MDAY & '.BAK', 1) = 0 Then
	MsgBox(0, '', 'Fehler beim Erstellen BAK-Datei: abbrev.properties')
	Exit
EndIf
If _FileWriteFromArray($pathAbbProp, $arAbbProp, 1) = 0 Then
	MsgBox(0, '', 'Fehler beim Schreiben aus Array in Datei: abbrev.properties')
	Exit
EndIf

; abbrev selektieren
For $i = 1 to UBound($arAbbProp) -1
	If StringInStr($arAbbProp[$i], '=') Then
		$var = StringSplit($arAbbProp[$i], '=')
		If $var[1] = 'but' Then $start = True
		If $start Then
			ReDim $aAbbr[UBound($aAbbr)+1]
			$aAbbr[UBound($aAbbr)-1] = $var[1]
		EndIf
	EndIf
Next

; "au3.keywords.abbreviations.properties" neu erstellen
If FileMove($pathKeyAbb, $pathKeyAbb & @YEAR & @MON & @MDAY & '.BAK', 1) = 0 Then
	MsgBox(0, '', 'Fehler beim Erstellen BAK-Datei: au3.keywords.abbrevations.properties')
	Exit
EndIf
Dim $fh = FileOpen($pathKeyAbb, 1), $line = 'au3.keywords.abbrev='
FileWriteLine($fh, @LF & @LF)
For $i = 1 To UBound($aAbbr)-1
	If $count < 15 Then 
		$line &= $aAbbr[$i] & ' '
	Else
		$line &= $aAbbr[$i] & ' \'
		FileWriteLine($fh, $line)
		$line = @TAB & ''
		$count = 0
	EndIf
	$count += 1
	If ($i = UBound($aAbbr)-1) And ($count < 15) Then FileWriteLine($fh, $line)
Next
FileClose($fh)

; user.calltips eintragen
If FileCopy($pathUserCallTip, $pathUserCallTip & @YEAR & @MON & @MDAY & '.BAK', 1) = 0 Then
	MsgBox(0, '', 'Fehler beim Erstellen BAK-Datei: au3.user.calltips.api')
	Exit
EndIf
$fh = FileOpen($pathUserCallTip, 33)
For $i = 1 To UBound($CallTip)-1
	FileWriteLine($fh, $CallTip[$i][1])
Next
FileClose($fh)
MsgBox(0, '', 'Einträge wurden erstellt')