#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile_x64=LanguageTransmitter.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseUpx=y
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_Res_Description=Language Transmitter for the LanguageSupport UDF
#AutoIt3Wrapper_Res_Fileversion=18.11.36.92
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#AutoIt3Wrapper_Res_LegalCopyright=mataran
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;~ #AutoIt3Wrapper_Run_Au3Stripper=y
;~ #Au3Stripper_Parameters=/rm /so
;	AU3STRIPPER SEEMS TO SOMEHOW BREAK CONSOLEREAD ???

#cs
	This is the Language Transmitter, which lets you send strings from your Scite-Project directly into a xml file.

	"Installation"
	1. If you do not have done yet, set a User Tools Path for scite (so you do not loose your data upon computer reset):
	- Open SciTEUser.properties
	- set a path for example: user.tools.path=C:\MyTools

	2. To "install" this tool to your scite config add then the following to your au3.properties (Options -> Open au3.properties):
	# 35 mataran's Language Transmitter
	# save.before 1 = save, 2 = do not save
	command.35.$(au3)=$(user.tools.path)\LanguageTransmitter.exe /in "$(FilePath)"
	command.input.35.*=$(CurrentSelection)
	command.subsystem.35.$(au3)=1
	command.name.35.$(au3)=Language Transmitter
	command.shortcut.35.$(au3)=Alt+A
	command.save.before.35.$(au3)=1
	command.replace.selection.35.$(au3)=1
	command.quiet.35.$(au3)=1# 35 mataran's Language Transmitter

	==============================================================================================================================================

	SEE README FOR MORE INFO!

	test string:
	"Hello & you & me I'm a Test!" & @CRLF & @CRLF & "Aren't ya havin' a nice day?" & ' "Test" ' & "my chars' hp: " & $aChar[0] & ' Take this "switch"!' & " And these last vars: "&$var1& @crlf&$var3
#ce

#include <XML.au3>
#include <WinAPIEx.au3>
#include <String.au3>
#include <Array.au3>
Global $iMsg = 0 ; Do not show Info Messages
Global $sPathAu3File = '' ;file path of the .au3 file where the call came from
Global $sPathIni = @ScriptDir & '\LanguageTransmitter.ini'
#Region SetUp
Local $sString = ''
If $CmdLine[0] > 0 Then
	For $i = 1 To $CmdLine[0] ;build cmd-line commands
		If $CmdLine[$i] = '/in' Then $sPathAu3File = $CmdLine[$i + 1]
	Next
	$sString = StringTrimLeft($sString, 1)
Else ;Exit when there are no cmd-line commands
	Exit MsgBox(16, 'Error!', 'Please run via SciTE.')
EndIf
$sString = StringReplace(ConsoleRead(), @CRLF, '')
If $sPathAu3File = '' Then Exit MsgBox(16, 'Error', 'FilePath not set! Make sure SciTE is set up correctly!')
;~ MsgBox(0, 'Console STDIN', '_' & $sString & '_')

Global $sPathLang = IniRead($sPathIni, 'config', 'CustomFilePath', _FileGetCurrentFileDir() & 'strings.xml')
If Not FileExists($sPathIni) Then ; In Case the SettingsFile does not exist create it.
	IniWrite($sPathIni, 'OutFile', 'FileName', 'strings.xml')
	IniWrite($sPathIni, 'Settings', 'InfoMsg', '0')
	IniWrite($sPathIni, 'config', 'CustomFilePath', '')
Else ;If the settings file exists use Settings
	$sPathLang = IniRead($sPathIni, 'config', 'CustomFilePath', _FileGetCurrentFileDir() & 'strings.xml')
	$iMsg = IniRead($sPathIni, 'Settings', 'InfoMsg', '0')
EndIf
If $sPathLang = '' Then $sPathLang = _FileGetCurrentFileDir() & 'strings.xml'
If Not FileExists($sPathLang) Then FileWrite($sPathLang, '')
If @error Or Not FileExists($sPathLang) Then Exit MsgBox(16, 'Language Transmitter Error', 'Could not create file: ' & $sPathLang & @CRLF & @CRLF & 'Check if the folder exists and the correct file path is set in ' & $sPathIni)

#EndRegion SetUp

Main()

Func Main()
	;================================================================================
	;	Start of the Program. If the User selected any text (=value) the program will
	;	evaluate if the selected text is already defined in the file as some value or
	;	unknown. In case it is already defined the matching Key is pasted into SciTE.
	;	However, if the selected Text is not defined, the user will be prompted to
	;	enter a Key for the Text/Value.
	;
	;
	;	In case the user did not select anything, he first will be asked to enter a
	;	new Key (assuming the user is going to add a new String to the file).
	;
	;		If the user enters a Key, he will be asked next to enter a Value for the
	;	Key, after it is ensured that the Key is not defined yet.
	;
	;		 If the user hits cancel, and therefore does not want to add a new string
	;	to the file, he will be asked if he'd like to insert the Init-Script required
	;	into SciTE or to set up a custom xml file path.
	;================================================================================
	Local $sData = FileRead($sPathLang)
	Local $aXML = _xmlNodeCreateArray($sData) ; list all found key-value pairs in an array
	$sData = '' ; "free memory"
	Local $aVarNames[0]
	If $sString <> '' Then ;PROGRAM START -> User selected some text
		If $iMsg <> 0 Then MsgBox(0, 'String', $sString)
		$sString = _checkForVarsInString($sString, $aVarNames) ; checks if the input string contains any variables or macros etc.
		$tmp = _xmlGetEntry($aXML, $sString, 0) ;check if selected Text is already in the file
		If $tmp Then _pasteToScite($sString, $tmp, $aVarNames) ;if Text is already defined... paste the KEY to scite and exit

		;Seems like the Text is not defined yet!
		Local $sKey
		$sKey = AddToLanguageFile($sString, $aXML) ;ask for new Data and add it to File
		_pasteToScite($sString, $sKey, $aVarNames)
	Else ; In case the User did not select any text in SciTE, ask for a new Var+String OR set up the Initialize the LanguageSupport

		$sString = InputBox('LanguageTransmitter', 'Please enter a value (text) for the Key.' & @CRLF & @CRLF & 'On Cancel, you will be asked if you want to create the InitScript for this project.') ;Request a Text (to check first if it exists)
		If $sString = '' Then SetUpLang() ;InputBox is empty! Ask for Initialization...
		$tmp = _xmlGetEntry($aXML, $sString, 0) ;check if set Text is already in the file
		If $tmp Then _pasteToScite($sString, $tmp, $aVarNames) ;if Text is already defined... paste the KEY to scite and exit

		$sKey = InputBox('LanguageTransmitter', 'Please enter a KEY for the value.')
		While (_xmlEntryExists($aXML, $sKey, 0))
			$sString = _xmlGetEntry($aXML, $sKey, 1) ;Check if the Key entered is already defined
			If $sString Then ; aaaaaand it's already defined...
				$iMsgBoxAnswer = MsgBox(36, "LanguageTransmitter", 'The Key "' & $sKey & '" has already the value "' & $sString & '" associated.' & @CRLF & _
						'Do you want to use this Key with its associated string instead of yours? If you do not, you need to define a different Key.')
				Select
					Case $iMsgBoxAnswer = 6 ;Yes, use the existing Key (and its value)
						ConsoleWrite("s('" & _xmlGetEntry($aXML, $sString, 0) & "')") ;paste key to scite
						Exit
					Case $iMsgBoxAnswer = 7 ;No, don't use that Key
						$sKey = InputBox('LanguageTransmitter', 'Please enter an alternative Key.')
						If $sKey = '' Then Exit ;Well, if you don't want to...
				EndSelect
			EndIf
		WEnd

		ConsoleWrite("s('" & $sKey & "')") ;Paste it into SciTE
		AddNewToLanguageFile($sKey, $sString, $aXML) ;add new Data to the file
		Exit
	EndIf
EndFunc   ;==>Main

Func _pasteToScite($sReceived, $sReturn, $aVarNames)
	If Not IsArray($aVarNames) Or UBound($aVarNames) = 0 Then
		If _checkForFormatting($sReceived) Then
			ConsoleWrite("StringFormat(s('" & $sReturn & "'))")
		Else
			ConsoleWrite("s('" & $sReturn & "')") ;paste the associated Key and Exit Program
		EndIf
	Else
		Local $sFormatted = "StringFormat(s('" & $sReturn & "')"
		For $i = 0 To UBound($aVarNames) - 1
			$sFormatted &= ", " & $aVarNames[$i]
		Next
		$sFormatted &= ')'
		ConsoleWrite($sFormatted)
	EndIf
	Exit
EndFunc   ;==>_pasteToScite

Func _checkForFormatting($sString)
	; just some very basic checking, you can still do that on your own
	If StringInStr($sString, '\t') Then Return True
	If StringInStr($sString, '\n') Then Return True
	If StringInStr($sString, '%s') Then Return True
	If StringInStr($sString, '%d') Then Return True
EndFunc   ;==>_checkForFormatting

Func _StringStripTotal($sString)
	$sString = StringReplace($sString, ' ', '')
	$sString = StringReplace($sString, @CRLF, '')
	$sString = StringReplace($sString, @CR, '')
	$sString = StringReplace($sString, @LF, '')
	Return $sString
EndFunc   ;==>_StringStripTotal

Func _prepareString($sString)
	$sString = StringReplace($sString, '</string>', '<./.string>')
	$sString = StringReplace($sString, '">', '".>')
	$sString = StringReplace($sString, '</', '<./')
	$sString = StringReplace($sString, '="', '=."')

	$sString = StringReplace($sString, '"&' & "'", '')
	$sString = StringReplace($sString, '"' & "&'", '')
	$sString = StringReplace($sString, "'&" & '"', '')
	$sString = StringReplace($sString, "'" & '&"', '')
	Return $sString
EndFunc   ;==>_prepareString

; #FUNCTION# ====================================================================================================================
; Name ..........: _checkForVarsInString
; Description ...: checks if there are any AutoIt Variables, Macros etc. in the string
; Syntax ........: _checkForVarsInString($sString, Byref $aVarNames)
; Parameters ....: $sString             - the string/value to be written in the xml file
;                  $aVarNames           - [in/out] 1D-Array containing all found Variables etc.
; Return values .: $sString				- the string but now any variables etc. are replaced with %s (@CRLFs with \r\n) to fit StringFromat style
; Author ........: mataran
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: Test String: "Hello & you & me I'm a Test!" & @CRLF & @CRLF & " Aren't ya havin' a nice day?" & ' "Test" ' & "my chars's stats: " & $aChar[1] & ' Take this "switch"!' & " And back! And these last vars: "&$var1& @crlf&$var3
; ===============================================================================================================================
Func _checkForVarsInString($sString, ByRef $aVarNames)
	$sString = _prepareString($sString)
	$sString = _extractContentString($sString, $aVarNames, '"', '"')
	$sString = _extractContentString($sString, $aVarNames, "'", "'")
	$sString = _extractContentString($sString, $aVarNames, "'", '"')
	$sString = _extractContentString($sString, $aVarNames, '"', "'")
	If (StringLeft(_StringStripTotal($sString), 1) = '"' Or StringLeft(_StringStripTotal($sString), 1) = '"') And StringRight(_StringStripTotal($sString), 1) <> '"' And StringRight(_StringStripTotal($sString), 1) <> "'" Then ; String must have some variable or macro etc. at the end ("string" & $var)
		For $i = StringLen($sString) - 1 To 1 Step -1 ; count backwards to find the last " or ' to then extract any vars etc. that are followed by the string
			If StringMid($sString, $i, 1) = '"' Or StringMid($sString, $i, 1) = "'" Then ExitLoop
		Next
		$tmp = _StringBetween(StringMid($sString, $i), '&', '&')
		If Not @error Then ; we found multiple vars at the end e.g. "string" & $a & $b & $c
			$tmp = _extractTailVarNamesAndModString($sString, $tmp, $aVarNames) ; get all vars except for the very last one ($c in this case)
			$tmp = _StringBetween(StringMid($sString, $i), $tmp & '&', '') ; get last var ($c): from prev-last one until the end of string
			If Not @error Then
				_extractTailVarNamesAndModString($sString, $tmp, $aVarNames)
			Else ; shouldnt happen
				MsgBox(16, 'Error', 'Couldnt find Vars but detects multi tailing... Found: ' & StringMid($sString, $i))
			EndIf
		Else ; did not find multiple vars at the end of the string
			$tmp = _StringBetween(_StringStripTotal(StringMid($sString, $i)), '&', '')
			If Not @error Then
				_extractTailVarNamesAndModString($sString, $tmp, $aVarNames)
			Else ; shouldnt happen
				MsgBox(16, 'Error', 'Couldnt find tailing & -> end... Found: ' & StringMid($sString, $i))
			EndIf
		EndIf
		$sString = StringLeft($sString, $i - 1) & StringRight($sString, StringLen($sString) - $i) ; remove possible tailing "
	EndIf
	If StringLeft($sString, 1) = '"' Or StringLeft($sString, 1) = "'" Then $sString = StringTrimLeft($sString, 1)
	If StringRight($sString, 1) = '"' Or StringRight($sString, 1) = "'" Then $sString = StringTrimRight($sString, 1)
;~ 	MsgBox(0, 'Final String', StringReplace($sString, ' ', ';'))
	Return $sString
EndFunc   ;==>_checkForVarsInString

; #FUNCTION# ====================================================================================================================
; Name ..........: _extractTailVarNamesAndModString
; Description ...: ONLY for string tailing vars/macros: extracts
; Syntax ........: _extractTailVarNamesAndModString(Byref $sString, $aFoundRaw, Byref $aVarNames)
; Parameters ....: $sString             - [in/out] our String we want to patch (again) to fit StringFormat
;                  $aFoundRaw           - array from _StringBetween with the borders of the tailing & -> & or & -> end of string
;                  $aVarNames           - [in/out] our Array of var names
; Return values .: None
; Author ........: mataran
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: "Health: " & $iHP
; ===============================================================================================================================
Func _extractTailVarNamesAndModString(ByRef $sString, $aFoundRaw, ByRef $aVarNames) ; extracts var name and changes the original string to fit stringformat -> this func is only for the string tail vars/macros
	$iLastAND = 0
	For $o = 0 To UBound($aFoundRaw) - 1 ;SAVE FOUND CONTENT
		For $i = StringLen($sString) - 1 To 1 Step -1 ; count backwards to find the last " or ' to then extract any vars etc. that are followed by the string
			If StringMid($sString, $i, 1) = '&' Then $iLastAND = $i
			If StringMid($sString, $i, 1) = '"' Or StringMid($sString, $i, 1) = "'" Then ExitLoop
		Next
		If StringInStr($aFoundRaw[$o], '@CRLF') Or StringInStr($aFoundRaw[$o], '@CR') Or StringInStr($aFoundRaw[$o], '@LF') Then ; since we're gonna use stringformat anyways this is a lot nicer
			$sPlaceHolder = '\r\n' ; set return as placeholder, don't save the now useless CR... macro
		Else
			ReDim $aVarNames[UBound($aVarNames) + 1]
			$aVarNames[UBound($aVarNames) - 1] = $aFoundRaw[$o]
			$sPlaceHolder = '%s' ;for every replaced var or macro set one string placeholder
		EndIf
		; adapt string tail: "xx" & $var -> cut out whitespaces and replace $var
		Local $tmp1 = ''
		If $o = 0 Then
			For $x = $i To StringInStr($sString, "&", 0, 1, $i) - 1
				If StringMid($sString, $x, 1) = ' ' Then $tmp1 &= ' ' ; build string from last " -> &
			Next
		EndIf
		Local $tmp = $tmp1 & '&'
		For $y = $iLastAND To StringInStr($sString, $aFoundRaw[$o], 0, 1, $iLastAND) - 2
			$tmp &= ' ' ; build string from last & -> $var
		Next
		$sString = StringReplace($sString, $tmp & $aFoundRaw[$o], $sPlaceHolder)
	Next
	Return $sPlaceHolder ; return last placeholder to extract the last var afterwards
EndFunc   ;==>_extractTailVarNamesAndModString

; #FUNCTION# ====================================================================================================================
; Name ..........: _extractContentString
; Description ...: Finds and Extracts AutoIt variables, macros, etc. from a string
; Syntax ........: _extractContentString($sString, $aString, Byref $aVarNames, $sDeli1, $sDeli2)
; Parameters ....: $sString             - Our original String
;                  $aVarNames           - [in/out] our Array of var names
;                  $sDeli1              - the start delimeter to split the string
;                  $sDeli2              - the  end  delimeter to split the string
; Return values .: $sString patched to match StringFormat (or unchanged String if nothing found)
; Author ........: mataran
; Modified ......:
; Remarks .......:
; Related .......:
; Link ..........:
; Example .......: No
; ===============================================================================================================================
Func _extractContentString($sString, ByRef $aVarNames, $sDeli1, $sDeli2)
	$aString = _StringBetween($sString, $sDeli1, $sDeli2)
	If @error Then Return $sString
	For $i = 0 To UBound($aString) - 1
		$sPlaceHolder = ''
		If _IsVarGap($aString[$i]) Then
			$tmp = _StringBetween(_StringStripTotal($aString[$i]), '&', '&')
			If Not @error Then
				For $o = 0 To UBound($tmp) - 1 ;SAVE FOUND CONTENT
					If StringInStr($tmp[$o], '@CRLF') Or StringInStr($tmp[$o], '@CR') Or StringInStr($tmp[$o], '@LF') Then ; since we're gonna use stringformat anyways this is a lot nicer
						$sPlaceHolder &= '\r\n' ; set return as placeholder, don't save the now useless CR... macro
					Else
						ReDim $aVarNames[UBound($aVarNames) + 1]
						$aVarNames[UBound($aVarNames) - 1] = $tmp[$o]
						$sPlaceHolder &= '%s' ;for every replaced var or macro set one string placeholder
					EndIf
				Next
				$sString = StringReplace($sString, $sDeli1 & $aString[$i] & $sDeli2, $sPlaceHolder)
				ContinueLoop
			EndIf
			If $sDeli1 <> $sDeli2 And _StringStripTotal($aString[$i]) = '&' Then $sString = StringReplace($sString, $sDeli1 & $aString[$i] & $sDeli2, '') ; removes possible "xxx" & 'yyy' (just switches from " to ' without anything in between
		EndIf
	Next
	Return $sString
EndFunc   ;==>_extractContentString

Func _IsVarGap($sString) ; checks if this is a true gap
	If StringLeft(_StringStripTotal($sString), 1) = '&' And StringRight(_StringStripTotal($sString), 1) = '&' Then
		If StringLeft(_StringStripTotal($sString), 2) <> '&"' And StringRight(_StringStripTotal($sString), 2) <> '"&' Then
			If StringLeft(_StringStripTotal($sString), 2) <> "&'" And StringRight(_StringStripTotal($sString), 2) <> "'&" And StringLen($sString) > 1 Then Return True
		EndIf
	EndIf
	Return False
EndFunc   ;==>_IsVarGap

;===============================================================================
; Function Name:	AddToLanguageFile
; Description:		Adds a String to the xml file and asks for a key
; Parameter(s):		$sString	String (will ask for a key to enter)
;					$aXML		XML Data Array
; Syntax:			AddToLanguageFile($sString, $aXML)
; Author(s):		mataran
; Return Value(s)	matching key to the Value/String & asfd
;===============================================================================
Func AddToLanguageFile($sString, $aXML)
	If Not FileExists($sPathLang) Or (FileRead($sPathLang) = '') Or UBound($aXML) = 0 Or Not IsArray($aXML) Then _XMLCreateFile($sPathLang, 'Resources', False)
	_XMLFileOpen($sPathLang)
	If @error Then Exit MsgBox(16, 'Error!', 'Error opening xml-File: ' & $sPathLang & @CRLF & ' Error: ' & @error)
	If Not _xmlEntryExists($aXML, $sString, 1) Then ;Check that the value/string is NOT already defined
		$sKey = InputBox('LanguageTransmitter', 'Enter the KEY for:' & @CRLF & $sString, StringReplace(StringStripWS($sString, 8), '.', ''))
		If @error Or $sKey = '' Then Exit
		While (_xmlEntryExists($aXML, $sKey, 0))
			$tmp = _xmlGetEntry($aXML, $sKey, 1) ; get the matching value of our key
			If $tmp Then $sKey = InputBox('LanguageTransmitter', 'Key already exists with data: ' & @CRLF & '"' & $tmp & '"' & @CRLF & 'Please choose another Key.')
			If @error Or $sKey = '' Then Exit
		WEnd
		_XMLCreateRootNodeWAttr('string', 'name', $sKey, $sString)
		If @error Then Exit MsgBox(16, 'Error!', 'Error writing xml-File! Error: ' & @error)
		Return $sKey
	Else ;Value/String already exists -> return Key
		Return _xmlGetEntry($aXML, $sString, 0)
	EndIf
	Return -1
EndFunc   ;==>AddToLanguageFile

Func _parseXML($sString)
	$sString = StringReplace($sString, '&amp;', '&')
	$sString = StringReplace($sString, '&lt; ', '<')
	$sString = StringReplace($sString, '&gt;', '>')
	$sString = StringReplace($sString, '&quot;', '"')
	$sString = StringReplace($sString, '&apos;', "'")
	Return $sString
EndFunc   ;==>_parseXML

;===============================================================================
; Function Name:	AddNewToLanguageFile
; Description:		Adds a new Key plus String/text/value to the file
; Parameter(s):		$sKey		Key to use
;					$sString	Value/String of the key
;					$aXML		XML Data Array
; Syntax:			AddNewToLanguageFile($sKey, $sString, $aXML)
; Author(s):		mataran
; Return Value(s)	None
;===============================================================================
Func AddNewToLanguageFile($sKey, $sString, $aXML)
	If (($sKey = '') Or ($sString = '')) Then Exit
	If Not FileExists($sPathLang) Or (FileRead($sPathLang) = '') Then _XMLCreateFile($sPathLang, 'Resources', False)
	_XMLFileOpen($sPathLang)
	If @error Then Exit MsgBox(16, 'Error!', 'Error opening xml-File: ' & $sPathLang & @CRLF & ' Error: ' & @error)
	If UBound($aXML) = 0 Or Not IsArray($aXML) Then ; the File does not exist yet.
		If Not _xmlEntryExists($aXML, $sKey, 0) And Not _xmlEntryExists($aXML, $sString, 1) Then _XMLCreateRootNodeWAttr('string', 'name', $sKey, $sString)
	Else
		_XMLCreateRootNodeWAttr('string', 'name', $sKey, $sString)
	EndIf
EndFunc   ;==>AddNewToLanguageFile

Func _xmlEntryExists($aXML, $sVal, $iEntryType = 0) ; 0 = key, 1 = value
	If $iEntryType > 1 Or $iEntryType < 0 Then Return SetError(-1, 0, False)
	For $i = 0 To UBound($aXML) - 1
		If $sVal = $aXML[$i][$iEntryType] Then Return True
	Next
	Return False
EndFunc   ;==>_xmlEntryExists

Func _xmlGetEntry($aXML, $sVal, $iEntryType = 0) ; 0 = key, 1 = value that I want to get (need: value, have: key -> set iEntryType to 1)
	If $iEntryType > 1 Or $iEntryType < 0 Then Return SetError(-1, 0, False)
	For $i = 0 To UBound($aXML) - 1
		If $sVal = $aXML[$i][Not $iEntryType] Then Return $aXML[$i][$iEntryType]
	Next
	Return SetError(1, 0, '')
EndFunc   ;==>_xmlGetEntry

Func SetUpLang()
	$iMsgBoxAnswer = MsgBox(292, "LanguageTransmitter", "Would you like to set up a language file for this project?" & @CRLF & _
			'On Cancel you will be asked if you would like to set up a fixed file path for the string.xml (useful for projects with code in multiple dirs)')
	Select
		Case $iMsgBoxAnswer = 6 ;Yes
			ConsoleWrite("_LangInit('" & $sPathLang & "')") ;Paste the StandardIni-Script
			Exit
		Case $iMsgBoxAnswer = 7 ;No
			ChangeFilePathForLangFile()
	EndSelect
	Exit
EndFunc   ;==>SetUpLang

Func ChangeFilePathForLangFile()
	$sNewFilePath = FileSaveDialog('Language Transmitter', _FileGetCurrentFileDir() & 'strings.xml', 'XML Files (*.xml)|All (*.*)')
	IniWrite($sPathIni, 'config', 'CustomFilePath', $sNewFilePath)
EndFunc   ;==>ChangeFilePathForLangFile

Func _FileGetCurrentFileDir()
	$sDirPath = ''
	$tmp = StringSplit($sPathAu3File, '\', 2)
	For $i = 0 To UBound($tmp) - 2
		$sDirPath &= $tmp[$i] & '\'
	Next
	Return $sDirPath
EndFunc   ;==>_FileGetCurrentFileDir

;===============================================================================
; Function Name:	_xmlReadString($sData, $sString)
; Description:		reads the String from the XML file
; Parameter(s):		$sData		data read from the xml file
;					$sString	The Key to extract
; Syntax:			_xmlReadString($sData, $sString)
; Author(s):		mataran
; Return Value(s)	Value associated with the key
;===============================================================================
Func _xmlReadString($sData, $sString)
	$aString = _StringBetween($sData, '<string name="' & $sString & '">', '</string>')
	If @error Then
		SetError(1)
		Return '[' & $sString & ']' ; error return
	EndIf
	Return _parseXML($aString[0])
EndFunc   ;==>_xmlReadString

;===============================================================================
; Function Name:	_LangCreateArray($sData)
; Description:		Creates an Array with matching Key-Value pairs of the XML file
; Parameter(s):		$sData		data of fileread from the xml file
; Syntax:			_LangCreateArray($sData)
; Author(s):		mataran
; Return Value(s)	Array with matching Key-Value pairs
;===============================================================================
Func _xmlNodeCreateArray($sData)
	Local $aTmp = _StringBetween($sData, '<string name="', '">')
	If @error Then
		MsgBox(16, 'Error', 'Error: The selected language file seems corrupt!')
		Return SetError(2)
	EndIf
	Local $aNodeArray[UBound($aTmp)][2]
	For $i = 0 To UBound($aTmp) - 1
		$aNodeArray[$i][0] = $aTmp[$i]
		$aNodeArray[$i][1] = _xmlReadString($sData, $aTmp[$i])
		If @error Then SetError(1)
	Next
	Return $aNodeArray
EndFunc   ;==>_xmlNodeCreateArray
