Update FRED.au3

Update FRED.au3

#include-once
#include <Array.au3>
#include <String.au3>

; FRED
; #INDEX# ==========================================================================================================================================================
; Title .........: FRED 1.01
; AutoIt Version : 3.3.10.2
; Language ......: Português Br
; Description ...: codifica: array, Scripting.Dictionary, double, int32, int64, bool, string, Null, Default em uma cadeia de caracteres
; Authors .......: Luismar Chechelaky (Luigi)
; Source.........: https://github.com/chechelaky/AutoIt/blob/master/FRED/FRED.au3
; Version........: 0.0.0.2
; fixeds:
;                  30/06/2014 bug in empty code fixed
; ==================================================================================================================================================================

;~ example_01()
;~ example_02()
;~ example_03()
;~ example_04()
;~ example_05()
;~ example_06()
;~ example_07()

;~ Func example_01()
;~ 	Local $num = 1
;~ 	Local $code = code($num)
;~ 	Local $decode = decode($code)
;~ 	MsgBox(0, 'Example 01', '$num = ' & $num & @LF & '$code = ' & $code & @LF & '$decode = ' & $decode)
;~ EndFunc   ;==>example_01

;~ Func example_02()
;~ 	Local $num = 0
;~ 	Local $code = code($num)
;~ 	Local $decode = decode($code)
;~ 	MsgBox(0, 'Example 02', '$num = ' & $num & @LF & '$code = ' & $code & @LF & '$decode = ' & $decode)
;~ EndFunc   ;==>example_02

;~ Func example_03()
;~ 	Local $num = -1
;~ 	Local $code = code($num)
;~ 	Local $decode = decode($code)
;~ 	MsgBox(0, 'Example 03', '$num = ' & $num & @LF & '$code = ' & $code & @LF & '$decode = ' & $decode)
;~ EndFunc   ;==>example_03

;~ Func example_04()
;~ 	Local $string = 'É um erro ter razão cedo demais.'
;~ 	Local $code = code($string)
;~ 	Local $decode = decode($code)
;~ 	MsgBox(0, 'Example 04', '$num = ' & $string & @LF & '$code = ' & $code & @LF & '$decode = ' & $decode)
;~ EndFunc   ;==>example_04

;~ Func example_05()
;~ 	Local $aTest[2] = ['Violão', 'Argüição']
;~ 	_ArrayDisplay($aTest, 'Ex. 5')
;~ 	Local $code = code($aTest)
;~ 	MsgBox(0, 'Example 05: code array[n]', '$code = ' & $code)
;~ 	Local $decode = decode($code)
;~ 	_ArrayDisplay($decode, 'Ex. 5 decode array')
;~ EndFunc   ;==>example_05

Func example_06()
	Local $aTest1[2] = ['Violão', 'Argüição']
	Local $aTest2[2][2] = [['um', $aTest1],['três', 'quatro']]
	_ArrayDisplay($aTest2, 'Ex. 6')
	Local $code = code($aTest2)
	MsgBox(0, 'Example 06: code array[n][m]', '$code = ' & $code)
	Local $decode = decode($code)
	_ArrayDisplay($decode, 'Ex. 6 decode $aTeste2[n][m]')
	_ArrayDisplay($decode[0][1], 'Ex. 6 decode $aTest1[n]')
EndFunc   ;==>example_06

;~ Func example_07()
;~ 	Local $aTest1[2] = ["Violão", "Argüição"]
;~ 	Local $oo = ObjCreate("Scripting.Dictionary")
;~ 	$oo.Add("key1", "")
;~ 	$oo.Add("key2", "value2")
;~ 	$oo.Add("key3", $aTest1)
;~ 	Local $code = code($oo)
;~ 	MsgBox(0, "Example 07: code obj", "$code = " & $code)
;~ 	Local $decode = decode($code)
;~ 	MsgBox(0, "Example 07: decode", _
;~ 			"key1 = " & $decode.Item("key1") & _
;~ 			"key2 = " & $decode.Item("key2") & _
;~ 			"key3.0 = " & ($decode.Item("key3"))[0] & _
;~ 			"key3.1 = " & ($decode.Item("key3"))[1])
;~ EndFunc   ;==>example_07

Func decode($VAR = '')
	Local $iLenght = __lenght($VAR)
	Local $iSize = StringLeft($VAR, $iLenght)
	Local $sType = StringMid($VAR, $iLenght + 1, 1)
	Switch $sType
		Case 'a'
			Local $aMount[1]
			__mount_array($aMount, $VAR)
			__clean_var($VAR)
			Switch UBound($aMount, 0)
				Case 1
					For $iNext_1 = 0 To UBound($aMount, 1) - 1
						$aMount[$iNext_1] = __mount_next_cell($VAR)
					Next
					Return $aMount
				Case 2
					For $iNext_1 = 0 To UBound($aMount, 1) - 1
						For $iNext_2 = 0 To UBound($aMount, 2) - 1
							$aMount[$iNext_1][$iNext_2] = __mount_next_cell($VAR)
						Next
					Next
					Return $aMount
				Case 3
					For $iNext_1 = 0 To UBound($aMount, 1) - 1
						For $iNext_2 = 0 To UBound($aMount, 2) - 1
							For $iNext_3 = 0 To UBound($aMount, 3) - 1
								$aMount[$iNext_1][$iNext_2][$iNext_3] = __mount_next_cell($VAR)
							Next
						Next
					Next
					Return $aMount
				Case 4
					For $iNext_1 = 0 To UBound($aMount, 1) - 1
						For $iNext_2 = 0 To UBound($aMount, 2) - 1
							For $iNext_3 = 0 To UBound($aMount, 3) - 1
								For $iNext_4 = 0 To UBound($aMount, 4) - 1
									$aMount[$iNext_1][$iNext_2][$iNext_3][$iNext_4] = __mount_next_cell($VAR)
								Next
							Next
						Next
					Next
					Return $aMount
				Case 4
					For $iNext_1 = 0 To UBound($aMount, 1) - 1
						For $iNext_2 = 0 To UBound($aMount, 2) - 1
							For $iNext_3 = 0 To UBound($aMount, 3) - 1
								For $iNext_4 = 0 To UBound($aMount, 4) - 1
									For $iNext_5 = 0 To UBound($aMount, 5) - 1
										$aMount[$iNext_1][$iNext_2][$iNext_3][$iNext_4][$iNext_5] = __mount_next_cell($VAR)
									Next
								Next
							Next
						Next
					Next
					Return $aMount
				Case 5
					For $iNext_1 = 0 To UBound($aMount, 1) - 1
						For $iNext_2 = 0 To UBound($aMount, 2) - 1
							For $iNext_3 = 0 To UBound($aMount, 3) - 1
								For $iNext_4 = 0 To UBound($aMount, 4) - 1
									For $iNext_5 = 0 To UBound($aMount, 5) - 1
										For $iNext_6 = 0 To UBound($aMount, 6) - 1
											$aMount[$iNext_1][$iNext_2][$iNext_3][$iNext_4][$iNext_5][$iNext_6] = __mount_next_cell($VAR)
										Next
									Next
								Next
							Next
						Next
					Next
					Return $aMount
				Case 6
					For $iNext_1 = 0 To UBound($aMount, 1) - 1
						For $iNext_2 = 0 To UBound($aMount, 2) - 1
							For $iNext_3 = 0 To UBound($aMount, 3) - 1
								For $iNext_4 = 0 To UBound($aMount, 4) - 1
									For $iNext_5 = 0 To UBound($aMount, 5) - 1
										For $iNext_6 = 0 To UBound($aMount, 6) - 1
											For $iNext_7 = 0 To UBound($aMount, 7) - 1
												$aMount[$iNext_1][$iNext_2][$iNext_3][$iNext_4][$iNext_5][$iNext_6][$iNext_7] = __mount_next_cell($VAR)
											Next
										Next
									Next
								Next
							Next
						Next
					Next
					Return $aMount
				Case 7
					For $iNext_1 = 0 To UBound($aMount, 1) - 1
						For $iNext_2 = 0 To UBound($aMount, 2) - 1
							For $iNext_3 = 0 To UBound($aMount, 3) - 1
								For $iNext_4 = 0 To UBound($aMount, 4) - 1
									For $iNext_5 = 0 To UBound($aMount, 5) - 1
										For $iNext_6 = 0 To UBound($aMount, 6) - 1
											For $iNext_7 = 0 To UBound($aMount, 7) - 1
												For $iNext_8 = 0 To UBound($aMount, 8) - 1
													$aMount[$iNext_1][$iNext_2][$iNext_3][$iNext_4][$iNext_5][$iNext_6][$iNext_7][$iNext_8] = __mount_next_cell($VAR)
												Next
											Next
										Next
									Next
								Next
							Next
						Next
					Next
					Return $aMount
				Case 8
					For $iNext_1 = 0 To UBound($aMount, 1) - 1
						For $iNext_2 = 0 To UBound($aMount, 2) - 1
							For $iNext_3 = 0 To UBound($aMount, 3) - 1
								For $iNext_4 = 0 To UBound($aMount, 4) - 1
									For $iNext_5 = 0 To UBound($aMount, 5) - 1
										For $iNext_6 = 0 To UBound($aMount, 6) - 1
											For $iNext_7 = 0 To UBound($aMount, 7) - 1
												For $iNext_8 = 0 To UBound($aMount, 8) - 1
													For $iNext_9 = 0 To UBound($aMount, 9) - 1
														$aMount[$iNext_1][$iNext_2][$iNext_3][$iNext_4][$iNext_5][$iNext_6][$iNext_7][$iNext_8][$iNext_9] = __mount_next_cell($VAR)
													Next
												Next
											Next
										Next
									Next
								Next
							Next
						Next
					Next
					Return $aMount
				Case 9
					For $iNext_1 = 0 To UBound($aMount, 1) - 1
						For $iNext_2 = 0 To UBound($aMount, 2) - 1
							For $iNext_3 = 0 To UBound($aMount, 3) - 1
								For $iNext_4 = 0 To UBound($aMount, 4) - 1
									For $iNext_5 = 0 To UBound($aMount, 5) - 1
										For $iNext_6 = 0 To UBound($aMount, 6) - 1
											For $iNext_7 = 0 To UBound($aMount, 7) - 1
												For $iNext_8 = 0 To UBound($aMount, 8) - 1
													For $iNext_9 = 0 To UBound($aMount, 9) - 1
														For $iNext_10 = 0 To UBound($aMount, 10) - 1
															$aMount[$iNext_1][$iNext_2][$iNext_3][$iNext_4][$iNext_5][$iNext_6][$iNext_7][$iNext_8][$iNext_9][$iNext_10] = __mount_next_cell($VAR)
														Next
													Next
												Next
											Next
										Next
									Next
								Next
							Next
						Next
					Next
					Return $aMount
				Case Else
					Return SetError(1, 0, 0)
			EndSwitch
		Case 'o'
			__clean_var($VAR, 1)
			Local $oo = ObjCreate('Scripting.Dictionary')
			While Not $VAR = ''
				Local $key, $value
				$key = __mount_next_cell($VAR)
				$value = __mount_next_cell($VAR)
				$oo.Add($key, $value)
			WEnd
			$VAR = $oo
		Case 'f', 'F'
			If $iSize == 0 Then
				$VAR = 0.0
			Else
				$VAR = StringReplace($VAR, '_', '.')
				$VAR = Number(StringMid($VAR, __lenght($VAR) + 2))
				$VAR *= ($sType == 'F' ? 1 : -1)
			EndIf
		Case 'i', 'I'
			If $iSize == 0 Then
				$VAR = 0
			Else
				$VAR = Number(StringMid($VAR, __lenght($VAR) + 2))
				$VAR *= ($sType == 'I' ? 1 : -1)
			EndIf
		Case 'y', 'Y'
			If $iSize == 0 Then
				$VAR = 0
			Else
				$VAR = Number(StringMid($VAR, __lenght($VAR) + 2))
				$VAR *= ($sType == 'I' ? 1 : -1)
			EndIf
		Case 'b', 'B'
			$VAR = ($sType == 'b' ? False : True)
		Case 'n'
			$VAR = Null
		Case 'd'
			$VAR = Default
		Case 's'
			If $iSize Then
				$VAR = String(__decode(StringMid($VAR, __lenght($VAR) + 2)))
			Else
				$VAR = ''
			EndIf
	EndSwitch
	Return $VAR
EndFunc   ;==>decode

Func code($VAR = '', $mode = 0)
	If Number($mode) == 1 Then
		$VAR = String($VAR)
		If $VAR == '' Then Return SetError(1, 0, 0)
		$VAR = StringRegExpReplace($VAR, '[^A-Za-z0-9\-]', '')
		If StringLen($VAR) == 0 Then Return SetError(1, 0, 0)
	EndIf

	If IsArray($VAR) Then
		Local $aDim[1]
		For $num_0 = 0 To UBound($VAR, 0) - 1
			_ArrayAdd($aDim, UBound($VAR, $num_0 + 1))
		Next
		$aDim = _ArrayToString($aDim, '*', 1)
		Switch UBound($VAR, 0)
			Case 1
				Local $aTemp0[1]
				For $iNext_1 = 0 To UBound($VAR) - 1
					_ArrayAdd($aTemp0, code($VAR[$iNext_1]))
				Next
				Local $string = _ArrayToString($aTemp0, ',', 1)
				Return __return__code_array($aDim, $VAR, $aTemp0)
			Case 2
				Local $aTemp0[1]
				For $iNext_1 = 0 To UBound($VAR, 1) - 1
					Local $aTemp1[1]
					For $iNext_2 = 0 To UBound($VAR, 2) - 1
						_ArrayAdd($aTemp1, code($VAR[$iNext_1][$iNext_2]))
					Next
					_ArrayAdd($aTemp0, '[' & _ArrayToString($aTemp1, ',', 1) & ']')
				Next
				Return __return__code_array($aDim, $VAR, $aTemp0)
			Case 3
				Local $aTemp0[1]
				For $iNext_1 = 0 To UBound($VAR, 1) - 1
					Local $aTemp1[1]
					For $iNext_2 = 0 To UBound($VAR, 2) - 1
						Local $aTemp2[1]
						For $iNext_3 = 0 To UBound($VAR, 3) - 1
							_ArrayAdd($aTemp2, code($VAR[$iNext_1][$iNext_2][$iNext_3]))
						Next
						_ArrayAdd($aTemp1, '[' & _ArrayToString($aTemp2, ',', 1) & ']')
					Next
					_ArrayAdd($aTemp0, '[' & _ArrayToString($aTemp1, ',', 1) & ']')
				Next
				Return __return__code_array($aDim, $VAR, $aTemp0)
			Case 4
				Local $aTemp0[1]
				For $iNext_1 = 0 To UBound($VAR, 1) - 1
					Local $aTemp1[1]
					For $iNext_2 = 0 To UBound($VAR, 2) - 1
						Local $aTemp2[1]
						For $iNext_3 = 0 To UBound($VAR, 3) - 1
							Local $aTemp3[1]
							For $iNext_4 = 0 To UBound($VAR, 4) - 1
								_ArrayAdd($aTemp3, code($VAR[$iNext_1][$iNext_2][$iNext_3][$iNext_4]))
							Next
							_ArrayAdd($aTemp2, '[' & _ArrayToString($aTemp3, ',', 1) & ']')
						Next
						_ArrayAdd($aTemp1, '[' & _ArrayToString($aTemp2, ',', 1) & ']')
					Next
					_ArrayAdd($aTemp0, '[' & _ArrayToString($aTemp1, ',', 1) & ']')
				Next
				Return __return__code_array($aDim, $VAR, $aTemp0)
			Case 5
				Local $aTemp0[1]
				For $iNext_1 = 0 To UBound($VAR, 1) - 1
					Local $aTemp1[1]
					For $iNext_2 = 0 To UBound($VAR, 2) - 1
						Local $aTemp2[1]
						For $iNext_3 = 0 To UBound($VAR, 3) - 1
							Local $aTemp3[1]
							For $iNext_4 = 0 To UBound($VAR, 4) - 1
								Local $aTemp4[1]
								For $iNext_5 = 0 To UBound($VAR, 5) - 1
									_ArrayAdd($aTemp4, code($VAR[$iNext_1][$iNext_2][$iNext_3][$iNext_4][$iNext_5]))
								Next
								_ArrayAdd($aTemp3, '[' & _ArrayToString($aTemp4, ',', 1) & ']')
							Next
							_ArrayAdd($aTemp2, '[' & _ArrayToString($aTemp3, ',', 1) & ']')
						Next
						_ArrayAdd($aTemp1, '[' & _ArrayToString($aTemp2, ',', 1) & ']')
					Next
					_ArrayAdd($aTemp0, '[' & _ArrayToString($aTemp1, ',', 1) & ']')
				Next
				Return __return__code_array($aDim, $VAR, $aTemp0)
			Case 6
				Local $aTemp0[1]
				For $iNext_1 = 0 To UBound($VAR, 1) - 1
					Local $aTemp1[1]
					For $iNext_2 = 0 To UBound($VAR, 2) - 1
						Local $aTemp2[1]
						For $iNext_3 = 0 To UBound($VAR, 3) - 1
							Local $aTemp3[1]
							For $iNext_4 = 0 To UBound($VAR, 4) - 1
								Local $aTemp4[1]
								For $iNext_5 = 0 To UBound($VAR, 5) - 1
									Local $aTemp5[1]
									For $iNext_6 = 0 To UBound($VAR, 6) - 1
										_ArrayAdd($aTemp5, code($VAR[$iNext_1][$iNext_2][$iNext_3][$iNext_4][$iNext_5][$iNext_6]))
									Next
									_ArrayAdd($aTemp4, '[' & _ArrayToString($aTemp5, ',', 1) & ']')
								Next
								_ArrayAdd($aTemp3, '[' & _ArrayToString($aTemp4, ',', 1) & ']')
							Next
							_ArrayAdd($aTemp2, '[' & _ArrayToString($aTemp3, ',', 1) & ']')
						Next
						_ArrayAdd($aTemp1, '[' & _ArrayToString($aTemp2, ',', 1) & ']')
					Next
					_ArrayAdd($aTemp0, '[' & _ArrayToString($aTemp1, ',', 1) & ']')
				Next
				Return __return__code_array($aDim, $VAR, $aTemp0)
			Case 7
				Local $aTemp0[1]
				For $iNext_1 = 0 To UBound($VAR, 1) - 1
					Local $aTemp1[1]
					For $iNext_2 = 0 To UBound($VAR, 2) - 1
						Local $aTemp2[1]
						For $iNext_3 = 0 To UBound($VAR, 3) - 1
							Local $aTemp3[1]
							For $iNext_4 = 0 To UBound($VAR, 4) - 1
								Local $aTemp4[1]
								For $iNext_5 = 0 To UBound($VAR, 5) - 1
									Local $aTemp5[1]
									For $iNext_6 = 0 To UBound($VAR, 6) - 1
										Local $aTemp6[1]
										For $iNext_7 = 0 To UBound($VAR, 7) - 1
											_ArrayAdd($aTemp6, code($VAR[$iNext_1][$iNext_2][$iNext_3][$iNext_4][$iNext_5][$iNext_6][$iNext_7]))
										Next
										_ArrayAdd($aTemp5, '[' & _ArrayToString($aTemp6, ',', 1) & ']')
									Next
									_ArrayAdd($aTemp4, '[' & _ArrayToString($aTemp5, ',', 1) & ']')
								Next
								_ArrayAdd($aTemp3, '[' & _ArrayToString($aTemp4, ',', 1) & ']')
							Next
							_ArrayAdd($aTemp2, '[' & _ArrayToString($aTemp3, ',', 1) & ']')
						Next
						_ArrayAdd($aTemp1, '[' & _ArrayToString($aTemp2, ',', 1) & ']')
					Next
					_ArrayAdd($aTemp0, '[' & _ArrayToString($aTemp1, ',', 1) & ']')
				Next
				Return __return__code_array($aDim, $VAR, $aTemp0)
			Case 8
				Local $aTemp0[1]
				For $iNext_1 = 0 To UBound($VAR, 1) - 1
					Local $aTemp1[1]
					For $iNext_2 = 0 To UBound($VAR, 2) - 1
						Local $aTemp2[1]
						For $iNext_3 = 0 To UBound($VAR, 3) - 1
							Local $aTemp3[1]
							For $iNext_4 = 0 To UBound($VAR, 4) - 1
								Local $aTemp4[1]
								For $iNext_5 = 0 To UBound($VAR, 5) - 1
									Local $aTemp5[1]
									For $iNext_6 = 0 To UBound($VAR, 6) - 1
										Local $aTemp6[1]
										For $iNext_7 = 0 To UBound($VAR, 7) - 1
											Local $aTemp7[1]
											For $iNext_8 = 0 To UBound($VAR, 8) - 1
												_ArrayAdd($aTemp7, code($VAR[$iNext_1][$iNext_2][$iNext_3][$iNext_4][$iNext_5][$iNext_6][$iNext_7][$iNext_8]))
											Next
											_ArrayAdd($aTemp6, '[' & _ArrayToString($aTemp7, ',', 1) & ']')
										Next
										_ArrayAdd($aTemp5, '[' & _ArrayToString($aTemp6, ',', 1) & ']')
									Next
									_ArrayAdd($aTemp4, '[' & _ArrayToString($aTemp5, ',', 1) & ']')
								Next
								_ArrayAdd($aTemp3, '[' & _ArrayToString($aTemp4, ',', 1) & ']')
							Next
							_ArrayAdd($aTemp2, '[' & _ArrayToString($aTemp3, ',', 1) & ']')
						Next
						_ArrayAdd($aTemp1, '[' & _ArrayToString($aTemp2, ',', 1) & ']')
					Next
					_ArrayAdd($aTemp0, '[' & _ArrayToString($aTemp1, ',', 1) & ']')
				Next
				Return __return__code_array($aDim, $VAR, $aTemp0)
			Case 9
				Local $aTemp0[1]
				For $iNext_1 = 0 To UBound($VAR, 1) - 1
					Local $aTemp1[1]
					For $iNext_2 = 0 To UBound($VAR, 2) - 1
						Local $aTemp2[1]
						For $iNext_3 = 0 To UBound($VAR, 3) - 1
							Local $aTemp3[1]
							For $iNext_4 = 0 To UBound($VAR, 4) - 1
								Local $aTemp4[1]
								For $iNext_5 = 0 To UBound($VAR, 5) - 1
									Local $aTemp5[1]
									For $iNext_6 = 0 To UBound($VAR, 6) - 1
										Local $aTemp6[1]
										For $iNext_7 = 0 To UBound($VAR, 7) - 1
											Local $aTemp7[1]
											For $iNext_8 = 0 To UBound($VAR, 8) - 1
												Local $aTemp8[1]
												For $iNext_9 = 0 To UBound($VAR, 9) - 1
													_ArrayAdd($aTemp8, code($VAR[$iNext_1][$iNext_2][$iNext_3][$iNext_4][$iNext_5][$iNext_6][$iNext_7][$iNext_8][$iNext_9]))
												Next
												_ArrayAdd($aTemp7, '[' & _ArrayToString($aTemp8, ',', 1) & ']')
											Next
											_ArrayAdd($aTemp6, '[' & _ArrayToString($aTemp7, ',', 1) & ']')
										Next
										_ArrayAdd($aTemp5, '[' & _ArrayToString($aTemp6, ',', 1) & ']')
									Next
									_ArrayAdd($aTemp4, '[' & _ArrayToString($aTemp5, ',', 1) & ']')
								Next
								_ArrayAdd($aTemp3, '[' & _ArrayToString($aTemp4, ',', 1) & ']')
							Next
							_ArrayAdd($aTemp2, '[' & _ArrayToString($aTemp3, ',', 1) & ']')
						Next
						_ArrayAdd($aTemp1, '[' & _ArrayToString($aTemp2, ',', 1) & ']')
					Next
					_ArrayAdd($aTemp0, '[' & _ArrayToString($aTemp1, ',', 1) & ']')
				Next
				Return __return__code_array($aDim, $VAR, $aTemp0)
			Case 10
				Local $aTemp0[1]
				For $iNext_1 = 0 To UBound($VAR, 1) - 1
					Local $aTemp1[1]
					For $iNext_2 = 0 To UBound($VAR, 2) - 1
						Local $aTemp2[1]
						For $iNext_3 = 0 To UBound($VAR, 3) - 1
							Local $aTemp3[1]
							For $iNext_4 = 0 To UBound($VAR, 4) - 1
								Local $aTemp4[1]
								For $iNext_5 = 0 To UBound($VAR, 5) - 1
									Local $aTemp5[1]
									For $iNext_6 = 0 To UBound($VAR, 6) - 1
										Local $aTemp6[1]
										For $iNext_7 = 0 To UBound($VAR, 7) - 1
											Local $aTemp7[1]
											For $iNext_8 = 0 To UBound($VAR, 8) - 1
												Local $aTemp8[1]
												For $iNext_9 = 0 To UBound($VAR, 9) - 1
													Local $aTemp9[1]
													For $iNext_10 = 0 To UBound($VAR, 10) - 1
														_ArrayAdd($aTemp9, code($VAR[$iNext_1][$iNext_2][$iNext_3][$iNext_4][$iNext_5][$iNext_6][$iNext_7][$iNext_8][$iNext_9][$iNext_10]))
													Next
													_ArrayAdd($aTemp8, '[' & _ArrayToString($aTemp9, ',', 1) & ']')
												Next
												_ArrayAdd($aTemp7, '[' & _ArrayToString($aTemp8, ',', 1) & ']')
											Next
											_ArrayAdd($aTemp6, '[' & _ArrayToString($aTemp7, ',', 1) & ']')
										Next
										_ArrayAdd($aTemp5, '[' & _ArrayToString($aTemp6, ',', 1) & ']')
									Next
									_ArrayAdd($aTemp4, '[' & _ArrayToString($aTemp5, ',', 1) & ']')
								Next
								_ArrayAdd($aTemp3, '[' & _ArrayToString($aTemp4, ',', 1) & ']')
							Next
							_ArrayAdd($aTemp2, '[' & _ArrayToString($aTemp3, ',', 1) & ']')
						Next
						_ArrayAdd($aTemp1, '[' & _ArrayToString($aTemp2, ',', 1) & ']')
					Next
					_ArrayAdd($aTemp0, '[' & _ArrayToString($aTemp1, ',', 1) & ']')
				Next
				Return __return__code_array($aDim, $VAR, $aTemp0)
			Case Else
				Return SetError(1, 0, 0)
		EndSwitch
	Else
		If IsObj($VAR) Then
			Local $aTemp[1]
			Local $oKeys = $VAR.Keys
			If UBound($oKeys) == 0 Then Return SetError(1, 0, 0)
			For $ii = 0 To UBound($oKeys, 1) - 1
				Local $key = code($oKeys[$ii], 1)
				If @error Then Return SetError(1, 0, 0)
				Local $value = $VAR.Item($oKeys[$ii])
				If ($value == '') Or Not $value Then
					$value = '0s'
				Else
					$value = code($value)
				EndIf
				If @error Then Return SetError(1, 0, 0)
				_ArrayAdd($aTemp, $key & ':' & $value)
			Next
			$VAR = 'o{' & _ArrayToString($aTemp, ',', 1) & '}'
			Return StringLen($VAR) & $VAR
		Else
;~ 			ConsoleWrite('code.var[' & $VAR & '] type[' & VarGetType($VAR) & ']' & @LF)
			Local $lenght
			Switch VarGetType($VAR)
				Case 'Bool'
					$VAR = '2|' & ($VAR == True ? '1B' : '1b')
				Case 'Keyword'
					Switch $VAR
						Case Null
							$VAR = '1n'
						Case Default
							$VAR = '1d'
						Case Else
							$VAR = '1k'
					EndSwitch
				Case 'Int32'
					If $VAR == 0 Then
						$VAR = '0i'
					Else
						$lenght = StringLen($VAR)
						If $VAR > 0 Then
							$VAR = $lenght & 'I' & $VAR
						Else
							$VAR = ($lenght - 1) & 'i' & (-1 * $VAR)
						EndIf
					EndIf
					$VAR = StringReplace($VAR, '.', '_')
				Case 'Int64'
					If $VAR == 0 Then
						$VAR = '0y'
					Else
						$lenght = StringLen($VAR)
						If $VAR > 0 Then
							$VAR = $lenght & 'Y' & $VAR
						Else
							$VAR = ($lenght - 1) & 'y' & (-1 * $VAR)
						EndIf
					EndIf
					$VAR = StringReplace($VAR, '.', '_')
				Case 'Double'
					If $VAR == 0 Then
						$VAR = '0f'
					Else
						$lenght = StringLen($VAR)
						If $VAR > 0 Then
							$VAR = $lenght & 'F' & $VAR
						Else
							$VAR = ($lenght - 1) & 'f' & (-1 * $VAR)
						EndIf
					EndIf
					$VAR = StringReplace($VAR, '.', '_')
				Case 'String'
;~ 					ConsoleWrite('String[ ' & $VAR & ' ] IsString[ ' & IsString($VAR) & ' ] IsNull[ ' & ($VAR == '' ? 'Null' : 'NotNull') & ' ]' & @LF)
					If StringLen($VAR) Then
						$VAR = __code($VAR)
						$VAR = StringLen($VAR) & 's' & $VAR
					Else
						$VAR = '0s'
					EndIf
				Case Else
					$VAR = 'eNoType_' & VarGetType($VAR)
					$VAR = StringLen($VAR) & $VAR
			EndSwitch
			Return $VAR
		EndIf
	EndIf
EndFunc   ;==>code

Func __code($VAR)
	; internal function
;~ 	ConsoleWrite('__code( ' & $VAR & ' )' & @LF)
	Local $temp
	$VAR = StringSplit($VAR, '', 2)
	For $ii = 0 To UBound($VAR) - 1
;~ 		ConsoleWrite(AscW($VAR[$ii]) & ' ')
		If StringRegExp($VAR[$ii], '[a-zA-Z0-9_]') Then
			$temp &= $VAR[$ii]
		Else
			$temp &= __code_num($VAR[$ii])
		EndIf
	Next
;~ 	ConsoleWrite(@LF)
	Return $temp
EndFunc   ;==>__code

Func __code_num($VAR)
	; internal function
	; PHP
	If $VAR == '' Then Return SetError(1, 0, 0)
	Local $aPos[4] = ['^', '~', '`', '´']
	Local $pos = 0
	$VAR = Hex(AscW($VAR))
	Do
		$pos += 1
	Until Not (StringMid($VAR, $pos, 1) == 0)
	$VAR = StringTrimLeft($VAR, $pos - 1)
	Return $aPos[StringLen($VAR) - 1] & $VAR
EndFunc   ;==>__code_num

Func __return__code_array($aDim, $VAR, $aTemp0)
	; internal function
	$VAR = 'a' & $aDim & '[' & _ArrayToString($aTemp0, ',', 1) & ']'
	Return StringLen($VAR) & $VAR
EndFunc   ;==>__return__code_array

Func __decode($VAR)
	; internal function
	$VAR = StringSplit($VAR, '', 2)
	Local $arr[4] = ['^', '~', '`', '´']
	Local $return, $ignore, $pos
	For $xx = 0 To UBound($VAR) - 1
		$pos = _ArraySearch($arr, $VAR[$xx])
		If $pos >= 0 Then
			Local $wer = ''
			$ignore = $pos + 1
			For $yy = $xx + 1 To $xx + $pos + 1
				$wer &= $VAR[$yy]
			Next
			$return &= ChrW(Dec($wer))
		Else
			If $ignore Then
				$ignore -= 1
			Else
				$return &= $VAR[$xx]
			EndIf
		EndIf
	Next
	Return $return
EndFunc   ;==>__decode

Func __mount_array(ByRef $aMount, $VAR)
	; internal function
	Local $arr = _StringBetween($VAR, 'a', '[')
	$arr = StringSplit($arr[0], '*', 2)
	Switch UBound($arr)
		Case 1
			ReDim $aMount[$arr[0]]
		Case 2
			ReDim $aMount[$arr[0]][$arr[1]]
		Case 3
			ReDim $aMount[$arr[0]][$arr[1]][$arr[2]]
		Case 4
			ReDim $aMount[$arr[0]][$arr[1]][$arr[2]][$arr[3]]
		Case 5
			ReDim $aMount[$arr[0]][$arr[1]][$arr[2]][$arr[3]][$arr[4]]
		Case 6
			ReDim $aMount[$arr[0]][$arr[1]][$arr[2]][$arr[3]][$arr[4]][$arr[5]]
		Case 7
			ReDim $aMount[$arr[0]][$arr[1]][$arr[2]][$arr[3]][$arr[4]][$arr[5]][$arr[6]]
		Case 8
			ReDim $aMount[$arr[0]][$arr[1]][$arr[2]][$arr[3]][$arr[4]][$arr[5]][$arr[6]][$arr[7]]
		Case 9
			ReDim $aMount[$arr[0]][$arr[1]][$arr[2]][$arr[3]][$arr[4]][$arr[5]][$arr[6]][$arr[7]][$arr[8]]
		Case 10
			ReDim $aMount[$arr[0]][$arr[1]][$arr[2]][$arr[3]][$arr[4]][$arr[5]][$arr[6]][$arr[7]][$arr[8]][$arr[9]]
		Case Else
			Return SetError(1, 0, 0)
	EndSwitch
EndFunc   ;==>__mount_array

Func __clean_var(ByRef $VAR, $type = 0)
	; internal function, VOID
	; PHP
	Local $tag = ($type == 0 ? '[' : '{')
	Local $first = StringInStr($VAR, $tag)
	$VAR = StringTrimRight($VAR, 1)
	$VAR = StringMid($VAR, $first + 1)
EndFunc   ;==>__clean_var

Func __lenght($input)
	; internal function
	; PHP
	Local $iLenght = 0
	While StringRegExp(StringMid($input, $iLenght + 1, 1), '[0-9]')
		$iLenght += 1
	WEnd
	Return $iLenght
EndFunc   ;==>__lenght

Func __mount_next_cell(ByRef $VAR)
	; internal function
	While Not StringRegExp(StringMid($VAR, 1, 1), '[0-9]')
		$VAR = StringTrimLeft($VAR, 1)
	WEnd
	Local $iLenght = __lenght($VAR)
	Local $iSize = StringLeft($VAR, $iLenght)
	Local $sType = StringMid($VAR, $iLenght + 1, 1)
	Local $cell = StringMid($VAR, 1, $iSize + $iLenght + 1)
	$VAR = StringTrimLeft($VAR, StringLen($cell))
	While StringInStr(StringMid($VAR, 1, 1), ',')
		$VAR = StringTrimLeft($VAR, 1)
	WEnd
	Return decode($cell)
EndFunc   ;==>__mount_next_cell

#include-once
#include <Array.au3>
#include <String.au3>

; FRED
; #INDEX# ==========================================================================================================================================================
; Title .........: FRED 1.01
; AutoIt Version : 3.3.10.2
; Language ......: Português Br
; Description ...: codifica: array, Scripting.Dictionary, double, int32, int64, bool, string, Null, Default em uma cadeia de caracteres
; Authors .......: Luismar Chechelaky (Luigi)
; Source.........:
; Version........: 0.0.0.2
; fixeds:
;                  30/06/2014 bug in empty code fixed
; ==================================================================================================================================================================

;~ example_01()
;~ example_02()
;~ example_03()
;~ example_04()
;~ example_05()
;~ example_06()
;~ example_07()

;~ Func example_01()
;~ 	Local $num = 1
;~ 	Local $code = code($num)
;~ 	Local $decode = decode($code)
;~ 	MsgBox(0, 'Example 01', '$num = ' & $num & @LF & '$code = ' & $code & @LF & '$decode = ' & $decode)
;~ EndFunc   ;==>example_01

;~ Func example_02()
;~ 	Local $num = 0
;~ 	Local $code = code($num)
;~ 	Local $decode = decode($code)
;~ 	MsgBox(0, 'Example 02', '$num = ' & $num & @LF & '$code = ' & $code & @LF & '$decode = ' & $decode)
;~ EndFunc   ;==>example_02

;~ Func example_03()
;~ 	Local $num = -1
;~ 	Local $code = code($num)
;~ 	Local $decode = decode($code)
;~ 	MsgBox(0, 'Example 03', '$num = ' & $num & @LF & '$code = ' & $code & @LF & '$decode = ' & $decode)
;~ EndFunc   ;==>example_03

;~ Func example_04()
;~ 	Local $string = 'É um erro ter razão cedo demais.'
;~ 	Local $code = code($string)
;~ 	Local $decode = decode($code)
;~ 	MsgBox(0, 'Example 04', '$num = ' & $string & @LF & '$code = ' & $code & @LF & '$decode = ' & $decode)
;~ EndFunc   ;==>example_04

;~ Func example_05()
;~ 	Local $aTest[2] = ['Violão', 'Argüição']
;~ 	_ArrayDisplay($aTest, 'Ex. 5')
;~ 	Local $code = code($aTest)
;~ 	MsgBox(0, 'Example 05: code array[n]', '$code = ' & $code)
;~ 	Local $decode = decode($code)
;~ 	_ArrayDisplay($decode, 'Ex. 5 decode array')
;~ EndFunc   ;==>example_05

Func example_06()
	Local $aTest1[2] = ['Violão', 'Argüição']
	Local $aTest2[2][2] = [['um', $aTest1],['três', 'quatro']]
	_ArrayDisplay($aTest2, 'Ex. 6')
	Local $code = code($aTest2)
	MsgBox(0, 'Example 06: code array[n][m]', '$code = ' & $code)
	Local $decode = decode($code)
	_ArrayDisplay($decode, 'Ex. 6 decode $aTeste2[n][m]')
	_ArrayDisplay($decode[0][1], 'Ex. 6 decode $aTest1[n]')
EndFunc   ;==>example_06

;~ Func example_07()
;~ 	Local $aTest1[2] = ["Violão", "Argüição"]
;~ 	Local $oo = ObjCreate("Scripting.Dictionary")
;~ 	$oo.Add("key1", "")
;~ 	$oo.Add("key2", "value2")
;~ 	$oo.Add("key3", $aTest1)
;~ 	Local $code = code($oo)
;~ 	MsgBox(0, "Example 07: code obj", "$code = " & $code)
;~ 	Local $decode = decode($code)
;~ 	MsgBox(0, "Example 07: decode", _
;~ 			"key1 = " & $decode.Item("key1") & _
;~ 			"key2 = " & $decode.Item("key2") & _
;~ 			"key3.0 = " & ($decode.Item("key3"))[0] & _
;~ 			"key3.1 = " & ($decode.Item("key3"))[1])
;~ EndFunc   ;==>example_07

Func decode($VAR = '')
	Local $iLenght = __lenght($VAR)
	Local $iSize = StringLeft($VAR, $iLenght)
	Local $sType = StringMid($VAR, $iLenght + 1, 1)
	Switch $sType
		Case 'a'
			Local $aMount[1]
			__mount_array($aMount, $VAR)
			__clean_var($VAR)
			Switch UBound($aMount, 0)
				Case 1
					For $iNext_1 = 0 To UBound($aMount, 1) - 1
						$aMount[$iNext_1] = __mount_next_cell($VAR)
					Next
					Return $aMount
				Case 2
					For $iNext_1 = 0 To UBound($aMount, 1) - 1
						For $iNext_2 = 0 To UBound($aMount, 2) - 1
							$aMount[$iNext_1][$iNext_2] = __mount_next_cell($VAR)
						Next
					Next
					Return $aMount
				Case 3
					For $iNext_1 = 0 To UBound($aMount, 1) - 1
						For $iNext_2 = 0 To UBound($aMount, 2) - 1
							For $iNext_3 = 0 To UBound($aMount, 3) - 1
								$aMount[$iNext_1][$iNext_2][$iNext_3] = __mount_next_cell($VAR)
							Next
						Next
					Next
					Return $aMount
				Case 4
					For $iNext_1 = 0 To UBound($aMount, 1) - 1
						For $iNext_2 = 0 To UBound($aMount, 2) - 1
							For $iNext_3 = 0 To UBound($aMount, 3) - 1
								For $iNext_4 = 0 To UBound($aMount, 4) - 1
									$aMount[$iNext_1][$iNext_2][$iNext_3][$iNext_4] = __mount_next_cell($VAR)
								Next
							Next
						Next
					Next
					Return $aMount
				Case 4
					For $iNext_1 = 0 To UBound($aMount, 1) - 1
						For $iNext_2 = 0 To UBound($aMount, 2) - 1
							For $iNext_3 = 0 To UBound($aMount, 3) - 1
								For $iNext_4 = 0 To UBound($aMount, 4) - 1
									For $iNext_5 = 0 To UBound($aMount, 5) - 1
										$aMount[$iNext_1][$iNext_2][$iNext_3][$iNext_4][$iNext_5] = __mount_next_cell($VAR)
									Next
								Next
							Next
						Next
					Next
					Return $aMount
				Case 5
					For $iNext_1 = 0 To UBound($aMount, 1) - 1
						For $iNext_2 = 0 To UBound($aMount, 2) - 1
							For $iNext_3 = 0 To UBound($aMount, 3) - 1
								For $iNext_4 = 0 To UBound($aMount, 4) - 1
									For $iNext_5 = 0 To UBound($aMount, 5) - 1
										For $iNext_6 = 0 To UBound($aMount, 6) - 1
											$aMount[$iNext_1][$iNext_2][$iNext_3][$iNext_4][$iNext_5][$iNext_6] = __mount_next_cell($VAR)
										Next
									Next
								Next
							Next
						Next
					Next
					Return $aMount
				Case 6
					For $iNext_1 = 0 To UBound($aMount, 1) - 1
						For $iNext_2 = 0 To UBound($aMount, 2) - 1
							For $iNext_3 = 0 To UBound($aMount, 3) - 1
								For $iNext_4 = 0 To UBound($aMount, 4) - 1
									For $iNext_5 = 0 To UBound($aMount, 5) - 1
										For $iNext_6 = 0 To UBound($aMount, 6) - 1
											For $iNext_7 = 0 To UBound($aMount, 7) - 1
												$aMount[$iNext_1][$iNext_2][$iNext_3][$iNext_4][$iNext_5][$iNext_6][$iNext_7] = __mount_next_cell($VAR)
											Next
										Next
									Next
								Next
							Next
						Next
					Next
					Return $aMount
				Case 7
					For $iNext_1 = 0 To UBound($aMount, 1) - 1
						For $iNext_2 = 0 To UBound($aMount, 2) - 1
							For $iNext_3 = 0 To UBound($aMount, 3) - 1
								For $iNext_4 = 0 To UBound($aMount, 4) - 1
									For $iNext_5 = 0 To UBound($aMount, 5) - 1
										For $iNext_6 = 0 To UBound($aMount, 6) - 1
											For $iNext_7 = 0 To UBound($aMount, 7) - 1
												For $iNext_8 = 0 To UBound($aMount, 8) - 1
													$aMount[$iNext_1][$iNext_2][$iNext_3][$iNext_4][$iNext_5][$iNext_6][$iNext_7][$iNext_8] = __mount_next_cell($VAR)
												Next
											Next
										Next
									Next
								Next
							Next
						Next
					Next
					Return $aMount
				Case 8
					For $iNext_1 = 0 To UBound($aMount, 1) - 1
						For $iNext_2 = 0 To UBound($aMount, 2) - 1
							For $iNext_3 = 0 To UBound($aMount, 3) - 1
								For $iNext_4 = 0 To UBound($aMount, 4) - 1
									For $iNext_5 = 0 To UBound($aMount, 5) - 1
										For $iNext_6 = 0 To UBound($aMount, 6) - 1
											For $iNext_7 = 0 To UBound($aMount, 7) - 1
												For $iNext_8 = 0 To UBound($aMount, 8) - 1
													For $iNext_9 = 0 To UBound($aMount, 9) - 1
														$aMount[$iNext_1][$iNext_2][$iNext_3][$iNext_4][$iNext_5][$iNext_6][$iNext_7][$iNext_8][$iNext_9] = __mount_next_cell($VAR)
													Next
												Next
											Next
										Next
									Next
								Next
							Next
						Next
					Next
					Return $aMount
				Case 9
					For $iNext_1 = 0 To UBound($aMount, 1) - 1
						For $iNext_2 = 0 To UBound($aMount, 2) - 1
							For $iNext_3 = 0 To UBound($aMount, 3) - 1
								For $iNext_4 = 0 To UBound($aMount, 4) - 1
									For $iNext_5 = 0 To UBound($aMount, 5) - 1
										For $iNext_6 = 0 To UBound($aMount, 6) - 1
											For $iNext_7 = 0 To UBound($aMount, 7) - 1
												For $iNext_8 = 0 To UBound($aMount, 8) - 1
													For $iNext_9 = 0 To UBound($aMount, 9) - 1
														For $iNext_10 = 0 To UBound($aMount, 10) - 1
															$aMount[$iNext_1][$iNext_2][$iNext_3][$iNext_4][$iNext_5][$iNext_6][$iNext_7][$iNext_8][$iNext_9][$iNext_10] = __mount_next_cell($VAR)
														Next
													Next
												Next
											Next
										Next
									Next
								Next
							Next
						Next
					Next
					Return $aMount
				Case Else
					Return SetError(1, 0, 0)
			EndSwitch
		Case 'o'
			__clean_var($VAR, 1)
			Local $oo = ObjCreate('Scripting.Dictionary')
			While Not $VAR = ''
				Local $key, $value
				$key = __mount_next_cell($VAR)
				$value = __mount_next_cell($VAR)
				$oo.Add($key, $value)
			WEnd
			$VAR = $oo
		Case 'f', 'F'
			If $iSize == 0 Then
				$VAR = 0.0
			Else
				$VAR = StringReplace($VAR, '_', '.')
				$VAR = Number(StringMid($VAR, __lenght($VAR) + 2))
				$VAR *= ($sType == 'F' ? 1 : -1)
			EndIf
		Case 'i', 'I'
			If $iSize == 0 Then
				$VAR = 0
			Else
				$VAR = Number(StringMid($VAR, __lenght($VAR) + 2))
				$VAR *= ($sType == 'I' ? 1 : -1)
			EndIf
		Case 'y', 'Y'
			If $iSize == 0 Then
				$VAR = 0
			Else
				$VAR = Number(StringMid($VAR, __lenght($VAR) + 2))
				$VAR *= ($sType == 'I' ? 1 : -1)
			EndIf
		Case 'b', 'B'
			$VAR = ($sType == 'b' ? False : True)
		Case 'n'
			$VAR = Null
		Case 'd'
			$VAR = Default
		Case 's'
			If $iSize Then
				$VAR = String(__decode(StringMid($VAR, __lenght($VAR) + 2)))
			Else
				$VAR = ''
			EndIf
	EndSwitch
	Return $VAR
EndFunc   ;==>decode

Func code($VAR = '', $mode = 0)
	If Number($mode) == 1 Then
		$VAR = String($VAR)
		If $VAR == '' Then Return SetError(1, 0, 0)
		$VAR = StringRegExpReplace($VAR, '[^A-Za-z0-9\-]', '')
		If StringLen($VAR) == 0 Then Return SetError(1, 0, 0)
	EndIf

	If IsArray($VAR) Then
		Local $aDim[1]
		For $num_0 = 0 To UBound($VAR, 0) - 1
			_ArrayAdd($aDim, UBound($VAR, $num_0 + 1))
		Next
		$aDim = _ArrayToString($aDim, '*', 1)
		Switch UBound($VAR, 0)
			Case 1
				Local $aTemp0[1]
				For $iNext_1 = 0 To UBound($VAR) - 1
					_ArrayAdd($aTemp0, code($VAR[$iNext_1]))
				Next
				Local $string = _ArrayToString($aTemp0, ',', 1)
				Return __return__code_array($aDim, $VAR, $aTemp0)
			Case 2
				Local $aTemp0[1]
				For $iNext_1 = 0 To UBound($VAR, 1) - 1
					Local $aTemp1[1]
					For $iNext_2 = 0 To UBound($VAR, 2) - 1
						_ArrayAdd($aTemp1, code($VAR[$iNext_1][$iNext_2]))
					Next
					_ArrayAdd($aTemp0, '[' & _ArrayToString($aTemp1, ',', 1) & ']')
				Next
				Return __return__code_array($aDim, $VAR, $aTemp0)
			Case 3
				Local $aTemp0[1]
				For $iNext_1 = 0 To UBound($VAR, 1) - 1
					Local $aTemp1[1]
					For $iNext_2 = 0 To UBound($VAR, 2) - 1
						Local $aTemp2[1]
						For $iNext_3 = 0 To UBound($VAR, 3) - 1
							_ArrayAdd($aTemp2, code($VAR[$iNext_1][$iNext_2][$iNext_3]))
						Next
						_ArrayAdd($aTemp1, '[' & _ArrayToString($aTemp2, ',', 1) & ']')
					Next
					_ArrayAdd($aTemp0, '[' & _ArrayToString($aTemp1, ',', 1) & ']')
				Next
				Return __return__code_array($aDim, $VAR, $aTemp0)
			Case 4
				Local $aTemp0[1]
				For $iNext_1 = 0 To UBound($VAR, 1) - 1
					Local $aTemp1[1]
					For $iNext_2 = 0 To UBound($VAR, 2) - 1
						Local $aTemp2[1]
						For $iNext_3 = 0 To UBound($VAR, 3) - 1
							Local $aTemp3[1]
							For $iNext_4 = 0 To UBound($VAR, 4) - 1
								_ArrayAdd($aTemp3, code($VAR[$iNext_1][$iNext_2][$iNext_3][$iNext_4]))
							Next
							_ArrayAdd($aTemp2, '[' & _ArrayToString($aTemp3, ',', 1) & ']')
						Next
						_ArrayAdd($aTemp1, '[' & _ArrayToString($aTemp2, ',', 1) & ']')
					Next
					_ArrayAdd($aTemp0, '[' & _ArrayToString($aTemp1, ',', 1) & ']')
				Next
				Return __return__code_array($aDim, $VAR, $aTemp0)
			Case 5
				Local $aTemp0[1]
				For $iNext_1 = 0 To UBound($VAR, 1) - 1
					Local $aTemp1[1]
					For $iNext_2 = 0 To UBound($VAR, 2) - 1
						Local $aTemp2[1]
						For $iNext_3 = 0 To UBound($VAR, 3) - 1
							Local $aTemp3[1]
							For $iNext_4 = 0 To UBound($VAR, 4) - 1
								Local $aTemp4[1]
								For $iNext_5 = 0 To UBound($VAR, 5) - 1
									_ArrayAdd($aTemp4, code($VAR[$iNext_1][$iNext_2][$iNext_3][$iNext_4][$iNext_5]))
								Next
								_ArrayAdd($aTemp3, '[' & _ArrayToString($aTemp4, ',', 1) & ']')
							Next
							_ArrayAdd($aTemp2, '[' & _ArrayToString($aTemp3, ',', 1) & ']')
						Next
						_ArrayAdd($aTemp1, '[' & _ArrayToString($aTemp2, ',', 1) & ']')
					Next
					_ArrayAdd($aTemp0, '[' & _ArrayToString($aTemp1, ',', 1) & ']')
				Next
				Return __return__code_array($aDim, $VAR, $aTemp0)
			Case 6
				Local $aTemp0[1]
				For $iNext_1 = 0 To UBound($VAR, 1) - 1
					Local $aTemp1[1]
					For $iNext_2 = 0 To UBound($VAR, 2) - 1
						Local $aTemp2[1]
						For $iNext_3 = 0 To UBound($VAR, 3) - 1
							Local $aTemp3[1]
							For $iNext_4 = 0 To UBound($VAR, 4) - 1
								Local $aTemp4[1]
								For $iNext_5 = 0 To UBound($VAR, 5) - 1
									Local $aTemp5[1]
									For $iNext_6 = 0 To UBound($VAR, 6) - 1
										_ArrayAdd($aTemp5, code($VAR[$iNext_1][$iNext_2][$iNext_3][$iNext_4][$iNext_5][$iNext_6]))
									Next
									_ArrayAdd($aTemp4, '[' & _ArrayToString($aTemp5, ',', 1) & ']')
								Next
								_ArrayAdd($aTemp3, '[' & _ArrayToString($aTemp4, ',', 1) & ']')
							Next
							_ArrayAdd($aTemp2, '[' & _ArrayToString($aTemp3, ',', 1) & ']')
						Next
						_ArrayAdd($aTemp1, '[' & _ArrayToString($aTemp2, ',', 1) & ']')
					Next
					_ArrayAdd($aTemp0, '[' & _ArrayToString($aTemp1, ',', 1) & ']')
				Next
				Return __return__code_array($aDim, $VAR, $aTemp0)
			Case 7
				Local $aTemp0[1]
				For $iNext_1 = 0 To UBound($VAR, 1) - 1
					Local $aTemp1[1]
					For $iNext_2 = 0 To UBound($VAR, 2) - 1
						Local $aTemp2[1]
						For $iNext_3 = 0 To UBound($VAR, 3) - 1
							Local $aTemp3[1]
							For $iNext_4 = 0 To UBound($VAR, 4) - 1
								Local $aTemp4[1]
								For $iNext_5 = 0 To UBound($VAR, 5) - 1
									Local $aTemp5[1]
									For $iNext_6 = 0 To UBound($VAR, 6) - 1
										Local $aTemp6[1]
										For $iNext_7 = 0 To UBound($VAR, 7) - 1
											_ArrayAdd($aTemp6, code($VAR[$iNext_1][$iNext_2][$iNext_3][$iNext_4][$iNext_5][$iNext_6][$iNext_7]))
										Next
										_ArrayAdd($aTemp5, '[' & _ArrayToString($aTemp6, ',', 1) & ']')
									Next
									_ArrayAdd($aTemp4, '[' & _ArrayToString($aTemp5, ',', 1) & ']')
								Next
								_ArrayAdd($aTemp3, '[' & _ArrayToString($aTemp4, ',', 1) & ']')
							Next
							_ArrayAdd($aTemp2, '[' & _ArrayToString($aTemp3, ',', 1) & ']')
						Next
						_ArrayAdd($aTemp1, '[' & _ArrayToString($aTemp2, ',', 1) & ']')
					Next
					_ArrayAdd($aTemp0, '[' & _ArrayToString($aTemp1, ',', 1) & ']')
				Next
				Return __return__code_array($aDim, $VAR, $aTemp0)
			Case 8
				Local $aTemp0[1]
				For $iNext_1 = 0 To UBound($VAR, 1) - 1
					Local $aTemp1[1]
					For $iNext_2 = 0 To UBound($VAR, 2) - 1
						Local $aTemp2[1]
						For $iNext_3 = 0 To UBound($VAR, 3) - 1
							Local $aTemp3[1]
							For $iNext_4 = 0 To UBound($VAR, 4) - 1
								Local $aTemp4[1]
								For $iNext_5 = 0 To UBound($VAR, 5) - 1
									Local $aTemp5[1]
									For $iNext_6 = 0 To UBound($VAR, 6) - 1
										Local $aTemp6[1]
										For $iNext_7 = 0 To UBound($VAR, 7) - 1
											Local $aTemp7[1]
											For $iNext_8 = 0 To UBound($VAR, 8) - 1
												_ArrayAdd($aTemp7, code($VAR[$iNext_1][$iNext_2][$iNext_3][$iNext_4][$iNext_5][$iNext_6][$iNext_7][$iNext_8]))
											Next
											_ArrayAdd($aTemp6, '[' & _ArrayToString($aTemp7, ',', 1) & ']')
										Next
										_ArrayAdd($aTemp5, '[' & _ArrayToString($aTemp6, ',', 1) & ']')
									Next
									_ArrayAdd($aTemp4, '[' & _ArrayToString($aTemp5, ',', 1) & ']')
								Next
								_ArrayAdd($aTemp3, '[' & _ArrayToString($aTemp4, ',', 1) & ']')
							Next
							_ArrayAdd($aTemp2, '[' & _ArrayToString($aTemp3, ',', 1) & ']')
						Next
						_ArrayAdd($aTemp1, '[' & _ArrayToString($aTemp2, ',', 1) & ']')
					Next
					_ArrayAdd($aTemp0, '[' & _ArrayToString($aTemp1, ',', 1) & ']')
				Next
				Return __return__code_array($aDim, $VAR, $aTemp0)
			Case 9
				Local $aTemp0[1]
				For $iNext_1 = 0 To UBound($VAR, 1) - 1
					Local $aTemp1[1]
					For $iNext_2 = 0 To UBound($VAR, 2) - 1
						Local $aTemp2[1]
						For $iNext_3 = 0 To UBound($VAR, 3) - 1
							Local $aTemp3[1]
							For $iNext_4 = 0 To UBound($VAR, 4) - 1
								Local $aTemp4[1]
								For $iNext_5 = 0 To UBound($VAR, 5) - 1
									Local $aTemp5[1]
									For $iNext_6 = 0 To UBound($VAR, 6) - 1
										Local $aTemp6[1]
										For $iNext_7 = 0 To UBound($VAR, 7) - 1
											Local $aTemp7[1]
											For $iNext_8 = 0 To UBound($VAR, 8) - 1
												Local $aTemp8[1]
												For $iNext_9 = 0 To UBound($VAR, 9) - 1
													_ArrayAdd($aTemp8, code($VAR[$iNext_1][$iNext_2][$iNext_3][$iNext_4][$iNext_5][$iNext_6][$iNext_7][$iNext_8][$iNext_9]))
												Next
												_ArrayAdd($aTemp7, '[' & _ArrayToString($aTemp8, ',', 1) & ']')
											Next
											_ArrayAdd($aTemp6, '[' & _ArrayToString($aTemp7, ',', 1) & ']')
										Next
										_ArrayAdd($aTemp5, '[' & _ArrayToString($aTemp6, ',', 1) & ']')
									Next
									_ArrayAdd($aTemp4, '[' & _ArrayToString($aTemp5, ',', 1) & ']')
								Next
								_ArrayAdd($aTemp3, '[' & _ArrayToString($aTemp4, ',', 1) & ']')
							Next
							_ArrayAdd($aTemp2, '[' & _ArrayToString($aTemp3, ',', 1) & ']')
						Next
						_ArrayAdd($aTemp1, '[' & _ArrayToString($aTemp2, ',', 1) & ']')
					Next
					_ArrayAdd($aTemp0, '[' & _ArrayToString($aTemp1, ',', 1) & ']')
				Next
				Return __return__code_array($aDim, $VAR, $aTemp0)
			Case 10
				Local $aTemp0[1]
				For $iNext_1 = 0 To UBound($VAR, 1) - 1
					Local $aTemp1[1]
					For $iNext_2 = 0 To UBound($VAR, 2) - 1
						Local $aTemp2[1]
						For $iNext_3 = 0 To UBound($VAR, 3) - 1
							Local $aTemp3[1]
							For $iNext_4 = 0 To UBound($VAR, 4) - 1
								Local $aTemp4[1]
								For $iNext_5 = 0 To UBound($VAR, 5) - 1
									Local $aTemp5[1]
									For $iNext_6 = 0 To UBound($VAR, 6) - 1
										Local $aTemp6[1]
										For $iNext_7 = 0 To UBound($VAR, 7) - 1
											Local $aTemp7[1]
											For $iNext_8 = 0 To UBound($VAR, 8) - 1
												Local $aTemp8[1]
												For $iNext_9 = 0 To UBound($VAR, 9) - 1
													Local $aTemp9[1]
													For $iNext_10 = 0 To UBound($VAR, 10) - 1
														_ArrayAdd($aTemp9, code($VAR[$iNext_1][$iNext_2][$iNext_3][$iNext_4][$iNext_5][$iNext_6][$iNext_7][$iNext_8][$iNext_9][$iNext_10]))
													Next
													_ArrayAdd($aTemp8, '[' & _ArrayToString($aTemp9, ',', 1) & ']')
												Next
												_ArrayAdd($aTemp7, '[' & _ArrayToString($aTemp8, ',', 1) & ']')
											Next
											_ArrayAdd($aTemp6, '[' & _ArrayToString($aTemp7, ',', 1) & ']')
										Next
										_ArrayAdd($aTemp5, '[' & _ArrayToString($aTemp6, ',', 1) & ']')
									Next
									_ArrayAdd($aTemp4, '[' & _ArrayToString($aTemp5, ',', 1) & ']')
								Next
								_ArrayAdd($aTemp3, '[' & _ArrayToString($aTemp4, ',', 1) & ']')
							Next
							_ArrayAdd($aTemp2, '[' & _ArrayToString($aTemp3, ',', 1) & ']')
						Next
						_ArrayAdd($aTemp1, '[' & _ArrayToString($aTemp2, ',', 1) & ']')
					Next
					_ArrayAdd($aTemp0, '[' & _ArrayToString($aTemp1, ',', 1) & ']')
				Next
				Return __return__code_array($aDim, $VAR, $aTemp0)
			Case Else
				Return SetError(1, 0, 0)
		EndSwitch
	Else
		If IsObj($VAR) Then
			Local $aTemp[1]
			Local $oKeys = $VAR.Keys
			If UBound($oKeys) == 0 Then Return SetError(1, 0, 0)
			For $ii = 0 To UBound($oKeys, 1) - 1
				Local $key = code($oKeys[$ii], 1)
				If @error Then Return SetError(1, 0, 0)
				Local $value = $VAR.Item($oKeys[$ii])
				If ($value == '') Or Not $value Then
					$value = '0s'
				Else
					$value = code($value)
				EndIf
				If @error Then Return SetError(1, 0, 0)
				_ArrayAdd($aTemp, $key & ':' & $value)
			Next
			$VAR = 'o{' & _ArrayToString($aTemp, ',', 1) & '}'
			Return StringLen($VAR) & $VAR
		Else
;~ 			ConsoleWrite('code.var[' & $VAR & '] type[' & VarGetType($VAR) & ']' & @LF)
			Local $lenght
			Switch VarGetType($VAR)
				Case 'Bool'
					$VAR = '2|' & ($VAR == True ? '1B' : '1b')
				Case 'Keyword'
					Switch $VAR
						Case Null
							$VAR = '1n'
						Case Default
							$VAR = '1d'
						Case Else
							$VAR = '1k'
					EndSwitch
				Case 'Int32'
					If $VAR == 0 Then
						$VAR = '0i'
					Else
						$lenght = StringLen($VAR)
						If $VAR > 0 Then
							$VAR = $lenght & 'I' & $VAR
						Else
							$VAR = ($lenght - 1) & 'i' & (-1 * $VAR)
						EndIf
					EndIf
					$VAR = StringReplace($VAR, '.', '_')
				Case 'Int64'
					If $VAR == 0 Then
						$VAR = '0y'
					Else
						$lenght = StringLen($VAR)
						If $VAR > 0 Then
							$VAR = $lenght & 'Y' & $VAR
						Else
							$VAR = ($lenght - 1) & 'y' & (-1 * $VAR)
						EndIf
					EndIf
					$VAR = StringReplace($VAR, '.', '_')
				Case 'Double'
					If $VAR == 0 Then
						$VAR = '0f'
					Else
						$lenght = StringLen($VAR)
						If $VAR > 0 Then
							$VAR = $lenght & 'F' & $VAR
						Else
							$VAR = ($lenght - 1) & 'f' & (-1 * $VAR)
						EndIf
					EndIf
					$VAR = StringReplace($VAR, '.', '_')
				Case 'String'
;~ 					ConsoleWrite('String[ ' & $VAR & ' ] IsString[ ' & IsString($VAR) & ' ] IsNull[ ' & ($VAR == '' ? 'Null' : 'NotNull') & ' ]' & @LF)
					If StringLen($VAR) Then
						$VAR = __code($VAR)
						$VAR = StringLen($VAR) & 's' & $VAR
					Else
						$VAR = '0s'
					EndIf
				Case Else
					$VAR = 'eNoType_' & VarGetType($VAR)
					$VAR = StringLen($VAR) & $VAR
			EndSwitch
			Return $VAR
		EndIf
	EndIf
EndFunc   ;==>code

Func __code($VAR)
	; internal function
;~ 	ConsoleWrite('__code( ' & $VAR & ' )' & @LF)
	Local $temp
	$VAR = StringSplit($VAR, '', 2)
	For $ii = 0 To UBound($VAR) - 1
;~ 		ConsoleWrite(AscW($VAR[$ii]) & ' ')
		If StringRegExp($VAR[$ii], '[a-zA-Z0-9_]') Then
			$temp &= $VAR[$ii]
		Else
			$temp &= __code_num($VAR[$ii])
		EndIf
	Next
;~ 	ConsoleWrite(@LF)
	Return $temp
EndFunc   ;==>__code

Func __code_num($VAR)
	; internal function
	; PHP
	If $VAR == '' Then Return SetError(1, 0, 0)
	Local $aPos[4] = ['^', '~', '`', '´']
	Local $pos = 0
	$VAR = Hex(AscW($VAR))
	Do
		$pos += 1
	Until Not (StringMid($VAR, $pos, 1) == 0)
	$VAR = StringTrimLeft($VAR, $pos - 1)
	Return $aPos[StringLen($VAR) - 1] & $VAR
EndFunc   ;==>__code_num

Func __return__code_array($aDim, $VAR, $aTemp0)
	; internal function
	$VAR = 'a' & $aDim & '[' & _ArrayToString($aTemp0, ',', 1) & ']'
	Return StringLen($VAR) & $VAR
EndFunc   ;==>__return__code_array

Func __decode($VAR)
	; internal function
	$VAR = StringSplit($VAR, '', 2)
	Local $arr[4] = ['^', '~', '`', '´']
	Local $return, $ignore, $pos
	For $xx = 0 To UBound($VAR) - 1
		$pos = _ArraySearch($arr, $VAR[$xx])
		If $pos >= 0 Then
			Local $wer = ''
			$ignore = $pos + 1
			For $yy = $xx + 1 To $xx + $pos + 1
				$wer &= $VAR[$yy]
			Next
			$return &= ChrW(Dec($wer))
		Else
			If $ignore Then
				$ignore -= 1
			Else
				$return &= $VAR[$xx]
			EndIf
		EndIf
	Next
	Return $return
EndFunc   ;==>__decode

Func __mount_array(ByRef $aMount, $VAR)
	; internal function
	Local $arr = _StringBetween($VAR, 'a', '[')
	$arr = StringSplit($arr[0], '*', 2)
	Switch UBound($arr)
		Case 1
			ReDim $aMount[$arr[0]]
		Case 2
			ReDim $aMount[$arr[0]][$arr[1]]
		Case 3
			ReDim $aMount[$arr[0]][$arr[1]][$arr[2]]
		Case 4
			ReDim $aMount[$arr[0]][$arr[1]][$arr[2]][$arr[3]]
		Case 5
			ReDim $aMount[$arr[0]][$arr[1]][$arr[2]][$arr[3]][$arr[4]]
		Case 6
			ReDim $aMount[$arr[0]][$arr[1]][$arr[2]][$arr[3]][$arr[4]][$arr[5]]
		Case 7
			ReDim $aMount[$arr[0]][$arr[1]][$arr[2]][$arr[3]][$arr[4]][$arr[5]][$arr[6]]
		Case 8
			ReDim $aMount[$arr[0]][$arr[1]][$arr[2]][$arr[3]][$arr[4]][$arr[5]][$arr[6]][$arr[7]]
		Case 9
			ReDim $aMount[$arr[0]][$arr[1]][$arr[2]][$arr[3]][$arr[4]][$arr[5]][$arr[6]][$arr[7]][$arr[8]]
		Case 10
			ReDim $aMount[$arr[0]][$arr[1]][$arr[2]][$arr[3]][$arr[4]][$arr[5]][$arr[6]][$arr[7]][$arr[8]][$arr[9]]
		Case Else
			Return SetError(1, 0, 0)
	EndSwitch
EndFunc   ;==>__mount_array

Func __clean_var(ByRef $VAR, $type = 0)
	; internal function, VOID
	; PHP
	Local $tag = ($type == 0 ? '[' : '{')
	Local $first = StringInStr($VAR, $tag)
	$VAR = StringTrimRight($VAR, 1)
	$VAR = StringMid($VAR, $first + 1)
EndFunc   ;==>__clean_var

Func __lenght($input)
	; internal function
	; PHP
	Local $iLenght = 0
	While StringRegExp(StringMid($input, $iLenght + 1, 1), '[0-9]')
		$iLenght += 1
	WEnd
	Return $iLenght
EndFunc   ;==>__lenght

Func __mount_next_cell(ByRef $VAR)
	; internal function
	While Not StringRegExp(StringMid($VAR, 1, 1), '[0-9]')
		$VAR = StringTrimLeft($VAR, 1)
	WEnd
	Local $iLenght = __lenght($VAR)
	Local $iSize = StringLeft($VAR, $iLenght)
	Local $sType = StringMid($VAR, $iLenght + 1, 1)
	Local $cell = StringMid($VAR, 1, $iSize + $iLenght + 1)
	$VAR = StringTrimLeft($VAR, StringLen($cell))
	While StringInStr(StringMid($VAR, 1, 1), ',')
		$VAR = StringTrimLeft($VAR, 1)
	WEnd
	Return decode($cell)
EndFunc   ;==>__mount_next_cell


Updated deployment test script

Updated deployment test script

; ****** REMEMBER TO SWITCH OFF UAC ON TARGET MACHINE!!! *********
;
; This script will install, run and uninstall SasView
; given location of the installer. The exit code of the script
; points at failure location:
;
; 0 - OK
; 1 - Download failure
; 2 - Installer failure
; 3 - Problems running SasView (simple fitting)
; 4 - Uninstaller failure

#include <Constants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <InetConstants.au3>
#include <WinAPIFiles.au3>

; Custom error handler
;Global $oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

; Modifiable globals
if $CmdLine[0] == 0 Then
   ; Expected command line with the build number as argument
   Exit (-1)
EndIf

Local $lBuildNumber = $CmdLine[1]
;Global $fInstallerLocation = "C:\util\setupSasView.exe" ; debug and testing location
Global $fInstallerLocation = @TempDir & "\setupSasView.exe"
Global $fRemoteInstallerLocation = "https://jenkins.esss.dk/sasview/job/SasView_Win7_Test/" & $lBuildNumber & "/artifact/sasview/dist/setupSasView.exe"
Global $fUninstallerLocation = "C:\Program Files (x86)\SasView\unins000.exe"
Global $lTimeout = 10          ; 10 sec timeout for waiting on windows
Global $lInstallTimeout = 120  ; 2 min timeout for the installation process

; General globals
Global $installerPID = 0

;; MAIN SCRIPT
Download()
Install()
RunSasView()
Uninstall()

Exit(0)

;==============================================================
Func Download()
   ; Download the file in the background with the selected option of 'force a reload from the remote site.'
   ConsoleWrite("Downloading...." & @CRLF)
   Local $iFailFlag = 1
   Local $hDownload = InetGet($fRemoteInstallerLocation, $fInstallerLocation, $INET_FORCERELOAD)

    ; Close the handle returned by InetGet.
    InetClose($hDownload)
	Assert($hDownload, $iFailFlag)
	ConsoleWrite("Installer downloaded successfully to " & $fInstallerLocation & @CRLF)

EndFunc

Func Install()
   ;;;;; APPLICATION INSTALLED ;;;;;;;
   Local $sSetupWindow = "Setup - SasView"
   Local $iFailFlag = 2
   ; Run setup
   if FileExists($fInstallerLocation) Then
	  $installerPID = Run($fInstallerLocation)
	  Assert($installerPID, $iFailFlag)
	  Sleep(1000)
   Else
	  ;$Error = ObjEvent(AutoIt.Error, "Setup file does not exist","123")
	  Exit($iFailFlag)
   EndIf

   ; License click through
   WinActivate($sSetupWindow) ; <-- REQUIRED when connecting from another host
   Local $test = WinWaitActive($sSetupWindow, "License Agreement", $lTimeout)
   ;ConsoleWrite("license agreement: " & $test)
   Assert($test, $iFailFlag)
   sleep(1000)

   Send("{TAB}{up}{ENTER}")

   ; Location
   Sleep(1000)
   $test = WinWaitActive($sSetupWindow, "Select Destination Location", $lTimeout)
   Assert($test, $iFailFlag)
   Send("{ENTER}")

   ; Icons, Startup entry
   Sleep(1000)
   $test = WinWaitActive($sSetupWindow, "Select Additional Tasks", $lTimeout)
   Assert($test, $iFailFlag)
   Send("{ENTER}")

   ; Ready to install...
   Sleep(1000)
   $test = WinWaitActive($sSetupWindow, "Ready to Install", $lTimeout)
   Assert($test, $iFailFlag)
   Send("{ENTER}")

   ; Final OK on running
   Sleep(5000)
   $test = WinWaitActive($sSetupWindow, "Completing the SasView Setup Wizard", $lInstallTimeout)
   Assert($test, $iFailFlag)
   Send("{ENTER}")
   ;ConsoleWrite("Installed" & @CRLF)

EndFunc

Func RunSasView()
   ;;;;; APPLICATION STARTED ;;;;;;;
   ; Start app - DEBUG ONLY
   ;;Run("C:\Program Files (x86)\SasView\SasView.exe")
   Local $iFailFlag = 2
   ; Wait for the window
   Sleep(1000)
   Local $hWnd = WinWaitActive("SasView  - Fitting -", "", $lTimeout)
   Assert($hWnd, $iFailFlag)

   ;;;;; Load a File
   ; Open File Load dialog
   Send("!{f}{ENTER}")
   WinWaitActive("Choose a file", "", $lTimeout)
   Assert($hWnd, $iFailFlag)
   Sleep(200)

   ; Focus is in file chooser - enter filename
   Send("C:\Program Files (x86)\SasView\test\1d_data\cyl_400_20.txt")
   Sleep(1000)
   Send("{ENTER}")

   ;; Send file to fitting
   ControlClick($hWnd, "Send To", 231)

   ;; Choose a model
   ControlCommand($hWnd, "", "ComboBox3", "SetCurrentSelection", 1)

   ;; Calculate the model
   ControlClick($hWnd, "Compute", 211)

   ;; Close SasView
   WinClose($hWnd)

   Local $hEnd = WinWaitActive("Confirm Exit", "", $lTimeout)
   Assert($hEnd, $iFailFlag)
   ControlClick($hEnd, "", "[CLASS:Button; INSTANCE:1]")

   Local $sv_closed = WinWaitClose($hWnd, "", $lTimeout)
   Assert($sv_closed, $iFailFlag)

EndFunc

Func Uninstall()
;;;;; UNINSTALL ;;;;;;;
   Local $iFailFlag = 3
   $installerPID = Run($fUninstallerLocation)
   Assert($installerPID, $iFailFlag)

   Local $sSetupWindow = "SasView Uninstall"

   Local $test = WinWaitActive($sSetupWindow, "", $lTimeout)
   Assert($test, $iFailFlag)
   Send("{TAB}{ENTER}")

   WinActivate("SasView Uninstal")
   $test = WinWaitActive($sSetupWindow, "SasView was successfully removed", $lTimeout)
   Assert($test, $iFailFlag)
   Send("{ENTER}")

EndFunc

;;; HELPER FUNCTIONS ;;;;
Func Assert($test, $lExitValue)
   ;;; Asserts $test to be non-zero and exit with code $lExitValue ;;;
   if $test == 0 Then
	  ProcessClose($installerPID)
	  Exit($lExitValue)
   EndIf
EndFunc

; ****** REMEMBER TO SWITCH OFF UAC ON TARGET MACHINE!!! *********
;
; This script will install, run and uninstall SasView
; given location of the installer. The exit code of the script
; points at failure location:
;
; 0 - OK
; 1 - Installer failure
; 2 - Problems running SasView (simple fitting)
; 3 - Uninstaller failure

#include <Constants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIFiles.au3>

; Custom error handler
;Global $oMyError = ObjEvent("AutoIt.Error","MyErrFunc")

; Modifiable globals
Global $fInstallerLocation = "C:\util\setupSasView.exe"
Global $lTimeout = 10          ; 10 sec timeout for waiting on windows
Global $lInstallTimeout = 120  ; 2 min timeout for the installation process

; General globals
Global $installerPID = 0

;; MAIN SCRIPT
Install()
RunSasView()
Uninstall()
Exit(0)

;==============================================================
Func Install()
   ;;;;; APPLICATION INSTALLED ;;;;;;;
   Local $sSetupWindow = "Setup - SasView"

   ; Run setup
   if FileExists($fInstallerLocation) Then
	  $installerPID = Run($fInstallerLocation)
	  Assert($installerPID, 1)
	  Sleep(1000)
   Else
	  ;$Error = ObjEvent(AutoIt.Error, "Setup file does not exist","123")
	  Exit(1)
   EndIf

   ; License click through
   Local $test = WinWaitActive($sSetupWindow, "License Agreement", $lTimeout)
   ;ConsoleWrite("license agreement: " & $test)
   Assert($test, 1)
   sleep(1000)

   Send("{TAB}{up}{ENTER}")

   ; Location
   Sleep(1000)
   $test = WinWaitActive($sSetupWindow, "Select Destination Location", $lTimeout)
   Assert($test, 1)
   Send("{ENTER}")

   ; Icons, Startup entry
   Sleep(1000)
   $test = WinWaitActive($sSetupWindow, "Select Additional Tasks", $lTimeout)
   Assert($test, 1)
   Send("{ENTER}")

   ; Ready to install...
   Sleep(1000)
   $test = WinWaitActive($sSetupWindow, "Ready to Install", $lTimeout)
   Assert($test, 1)
   Send("{ENTER}")

   ; Final OK on running
   Sleep(5000)
   $test = WinWaitActive($sSetupWindow, "Completing the SasView Setup Wizard", $lInstallTimeout)
   Assert($test, 1)
   Send("{ENTER}")
   ;ConsoleWrite("Installed" & @CRLF)

EndFunc

Func RunSasView()
   ;;;;; APPLICATION STARTED ;;;;;;;
   ; Start app - DEBUG ONLY
   ;;Run("C:\Program Files (x86)\SasView\SasView.exe")

   ; Wait for the window
   Sleep(1000)
   Local $hWnd = WinWaitActive("SasView  - Fitting -", "", $lTimeout)
   Assert($hWnd, 2)

   ;;;;; Load a File
   ; Open File Load dialog
   Send("!{f}{ENTER}")
   WinWaitActive("Choose a file", "", $lTimeout)
   Assert($hWnd, 2)
   Sleep(200)

   ; Focus is in file chooser - enter filename
   Send("C:\Program Files (x86)\SasView\test\1d_data\cyl_400_20.txt")
   Sleep(1000)
   Send("{ENTER}")

   ;; Send file to fitting
   ControlClick($hWnd, "Send To", 231)

   ;; Choose a model
   ControlCommand($hWnd, "", "ComboBox3", "SetCurrentSelection", 1)

   ;; Calculate the model
   ControlClick($hWnd, "Compute", 211)

   ;; Close SasView
   WinClose($hWnd)

   Local $hEnd = WinWaitActive("Confirm Exit", "", $lTimeout)
   Assert($hEnd, 2)
   ControlClick($hEnd, "", "[CLASS:Button; INSTANCE:1]")

   Local $sv_closed = WinWaitClose($hWnd, "", $lTimeout)
   Assert($sv_closed, 2)

EndFunc

Func Uninstall()
;;;;; UNINSTALL ;;;;;;;
   $installerPID = Run("C:\Program Files (x86)\SasView\unins000.exe")

   Local $sSetupWindow = "SasView Uninstall"

   Local $test = WinWaitActive($sSetupWindow, "", $lTimeout)
   Assert($test, 3)
   Send("{TAB}{ENTER}")

   WinActivate("SasView Uninstal")
   $test = WinWaitActive($sSetupWindow, "SasView was successfully removed", $lTimeout)
   Assert($test, 3)
   Send("{ENTER}")

EndFunc

;;; HELPER FUNCTIONS ;;;;
Func Assert($test, $lExitValue)
   ;;; Asserts $test to be non-zero and exit with code $lExitValue ;;;
   if $test == 0 Then
	  ProcessClose($installerPID)
	  Exit($lExitValue)
   EndIf
EndFunc


Path on include?

Path on include?

#Region includes
#include-once
#include <array.au3>
#include <date.au3>
#include <File.au3>
#include <AutoitObject/AutoitObject.au3>
#include <micro.test.au3>
#include <micro.test.suite.au3>
#EndRegion includes

_AutoItObject_Startup(True)

#Region includes
#include-once
#include <array.au3>
#include <date.au3>
#include <File.au3>
#include <AutoitObject.au3>
#include <micro.test.au3>
#include <micro.test.suite.au3>
#EndRegion includes

_AutoItObject_Startup(True)


- Add test 1 for Workbase

- Add test 1 for Workbase

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include "lib/autoit/appmonitor.au3"

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

Local $hMainGUI = GUICreate("Crypt Tool", 300, 150)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEButton")
GUICtrlCreateLabel("Input pharse to be encrypted", 0, 0)
Local $iEncryptButton = GUICtrlCreateButton("Encrypt", 120, 120, 60)
GUICtrlSetOnEvent($iEncryptButton, "EncryptButton")
Local $g_idInputEdit = GUICtrlCreateEdit("", 0, 20, 300, 20, $ES_WANTRETURN)
Local $g_idOutputEdit = GUICtrlCreateEdit("", 0, 45, 300, 70, $ES_READONLY)

GUISetState(@SW_SHOW, $hMainGUI)

While 1
    Sleep(100) ; Sleep to reduce CPU usage
WEnd

Func EncryptButton()
    Local $sRead = GUICtrlRead($g_idInputEdit)
    If $sRead <> "" Then
        Local $sHexEncrypted = AppmonitorEncrypt($sRead)
        GUICtrlSetData($g_idOutputEdit, $sHexEncrypted)
    EndIf
EndFunc   ;==>OKButton

Func CLOSEButton()
    Exit
EndFunc   ;==>CLOSEButton

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include "testsuites/autoit_include/appmonitor.au3"

Opt("GUIOnEventMode", 1) ; Change to OnEvent mode

Local $hMainGUI = GUICreate("Crypt Tool", 300, 150)
GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEButton")
GUICtrlCreateLabel("Input pharse to be encrypted", 0, 0)
Local $iEncryptButton = GUICtrlCreateButton("Encrypt", 120, 120, 60)
GUICtrlSetOnEvent($iEncryptButton, "EncryptButton")
Local $g_idInputEdit = GUICtrlCreateEdit("", 0, 20, 300, 20, $ES_WANTRETURN)
Local $g_idOutputEdit = GUICtrlCreateEdit("", 0, 45, 300, 70, $ES_READONLY)

GUISetState(@SW_SHOW, $hMainGUI)

While 1
    Sleep(100) ; Sleep to reduce CPU usage
WEnd

Func EncryptButton()
    Local $sRead = GUICtrlRead($g_idInputEdit)
    If $sRead <> "" Then
        Local $sHexEncrypted = AppmonitorEncrypt($sRead)
        GUICtrlSetData($g_idOutputEdit, $sHexEncrypted)
    EndIf
EndFunc   ;==>OKButton

Func CLOSEButton()
    Exit
EndFunc   ;==>CLOSEButton


15 backspaces -> 30

15 backspaces -> 30

in some situations 15 weren't enough apparently. 30 should be way more than enough.

#include <Array.au3>
#include <SQLite.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <AutoItConstants.au3>
#include <FontConstants.au3>
#include <MsgBoxConstants.au3>
#include <GuiListBox.au3>
#include <File.au3>
#include <String.au3>

HotKeySet("{PGUP}","WriteTransferMoney");
HotKeySet("{PGDN}","ParseBankLogs");

Func Paste()
   Sleep(2*1000);
   Send(ClipGet());
EndFunc
Func init()
   _SQLite_Startup() ; Load the DLL
   If @error Then Exit MsgBox($MB_SYSTEMMODAL, "SQLite Error", "error loading SQLite3.dll ! you can download it from https://www.sqlite.org/download.html , look for ""Precompiled Binaries for Windows"", should be named something like sqlite-dll-win32-x86-3220000.zip");
;why this isn't the default beats me...
   AutoItSetOption("MouseClickDelay",0);
   AutoItSetOption("MouseClickDownDelay",0);
   AutoItSetOption("MouseClickDragDelay",0);
   AutoItSetOption("SendKeyDelay",1);
   AutoItSetOption("SendKeyDownDelay",1);
   AutoItSetOption("WinWaitDelay",0);
   AutoItSetOption("MustDeclareVars",1);
   Global $playerDB=selectPlayer();
   Global $db=_SQLite_Open ( $playerDB,$SQLITE_OPEN_READWRITE, $SQLITE_ENCODING_UTF8 );
   If @error Then Exit MsgBox($MB_SYSTEMMODAL, "SQLite Error", "error loading " & $playerDB & " ! (_SQLite_Open failed, and i'm too lazy to add proper error description code atm)");
EndFunc
Func selectPlayer()
Local $FileList=_FileListToArray(@AppDataDir & "\Onlink\users\","*.db");
Local $GUI = GUICreate("Select agent", 300, 300) ;create gui
Local $ListBox = _GUICtrlListBox_Create($GUI, "", 0, 0,300,300) ;create listbox
For $i = 1 To $FileList[0]
    ;MsgBox(0, $i, $FileList[$i])
    _GUICtrlListBox_AddString($ListBox, StringReplace($FileList[$i],".db","",-1) )
Next

GUISetState() ;show the gui
WinSetOnTop($GUI,"",$WINDOWS_ONTOP);
Local $selected=-1
Do
   Sleep(100);
   $selected=_GUICtrlListBox_GetCurSel ( $ListBox );
Until $selected <> -1;
Local $ret=@AppDataDir & "\Onlink\users\" & _GUICtrlListBox_GetText($ListBox,$selected) & ".db";
ConsoleWriteError($ret);
GUIDelete() ; if autoit expect me to clean up all inner gui controls myself, and this technically leaks memory, here is a list of all the f*ks i give:
Return $ret;
EndFunc

Func SplashMessage($title,$message, $timeoutMS=500)
   Return 0;not working with onlink, onlink overrides WinSetOnTop, apparently...
	  Local $size=50+(StringLen($message)*15);
	  Local $hwnd=SplashTextOn($title, $message, $size, $size, -1, -1, $DLG_TEXTLEFT, "", 24)
	  WinSetOnTop($hwnd,"",$WINDOWS_ONTOP);
	  Sleep($timeoutMS);
	  SplashOff()
   EndFunc

Func e_SQLite_GetTable2d ( $hDB, $sSQL, ByRef $aResult, ByRef $iRows, ByRef $iColumns, $iCharSize = -1, $bSwichDimensions = False )
   if( _SQLite_GetTable2d ( $hDB, $sSQL,$aResult, $iRows,$iColumns, $iCharSize, $bSwichDimensions ) <> $SQLITE_OK) Then
	  Exit MsgBox(0,"SQL error","error executing: " & $sSql );
   EndIf

EndFunc

Func WriteTransferMoney()
   Local $aResult, $iRows, $iColumns;
   local $connectedIp;
   Send("{tab}" & _StringRepeat("{BACKSPACE}",30) & "waiting for db flush, hold on...");
   Do
	  sleep(100);
	  e_SQLite_GetTable2d($db, 'SELECT remotehost FROM player LIMIT 1', $aResult, $iRows, $iColumns) ;
	  $connectedIp=$aResult[1][0];
	  ; get player's account for current bank:
      e_SQLite_GetTable2d($db, 'SELECT SUBSTR(content,LENGTH((SELECT remotehost FROM player LIMIT 1))+2) FROM accounts WHERE content LIKE (SELECT remotehost FROM player LIMIT 1) || '' %'' AND suP_ref LIKE ''%(player)'' LIMIT 1',$aResult, $iRows, $iColumns) ;
	  ;_ArrayDisplay($aResult, "Results from the query");
	  ;ConsoleWrite(UBound($aResult) & @CRLF);
   Until (UBound($aResult) == 2) ; waiting for the game to flush db after entering transfer money screen.. sometimes it takes a few seconds.
   ;_ArrayDisplay($aResult, "Results from the query")
   ;_ArrayDisplay($aResult, "Results from the query");
   local $playerAccountNumber=$aResult[1][0];
   ;ConsoleWrite($playerAccount  & @CRLF );
   e_SQLite_GetTable2d($db, 'SELECT bankaccount.balance FROM bankaccount WHERE bankaccount.accountnumber=(SELECT remote.security_name FROM remote)',$aResult, $iRows, $iColumns) ;
   ;_ArrayDisplay($aResult, "Results from the query");
   Local $connectedAccountBalance=$aResult[1][0];
   e_SQLite_GetTable2d($db, 'SELECT remote.security_name FROM remote WHERE id=1',$aResult, $iRows, $iColumns) ;
   Local $connectedAccountNumber=$aResult[1][0];
   Send(_StringRepeat("{BACKSPACE}",33) & $connectedAccountNumber &  "{tab}" & $connectedIp & "{tab}" & $playerAccountNumber & "{tab}" & $connectedAccountBalance);
; get current connected bank account number: SELECT remote.security_name WHERE id=1

; get balance of current connected bank account: SELECT bankaccount.balance FROM bankaccount WHERE bankaccount.accountnumber=(SELECT remote.security_name FROM remote)

EndFunc
Func ParseBankLogs()
   Local $aResult, $iRows, $iColumns;
   local $connectedIp;
   ;Send("{tab}" & _StringRepeat("{BACKSPACE}",15) & "waiting for db flush, hold on...");
   Do
	  sleep(100);
	  e_SQLite_GetTable2d($db, 'SELECT remotehost FROM player LIMIT 1', $aResult, $iRows, $iColumns) ;
	  $connectedIp=$aResult[1][0];
	  ; get player's account for current bank:
      e_SQLite_GetTable2d($db, 'SELECT SUBSTR(content,LENGTH((SELECT remotehost FROM player LIMIT 1))+2) FROM accounts WHERE content LIKE (SELECT remotehost FROM player LIMIT 1) || '' %'' AND suP_ref LIKE ''%(player)'' LIMIT 1',$aResult, $iRows, $iColumns) ;
	  ;_ArrayDisplay($aResult, "Results from the query");
	  ;ConsoleWrite(UBound($aResult) & @CRLF);
   Until (UBound($aResult) == 2) ; waiting for the game to flush db after entering transfer money screen.. sometimes it takes a few seconds.
   ; current connected account number: SELECT remote.security_name FROM remote WHERE id=1
   ; logbank: SELECT logbank FROM bankaccount WHERE accountnumber = (SELECT remote.security_name FROM remote WHERE id=1)
   ; logs: SELECT data1,data2,data3,date,fromip,fromname FROM accesslog WHERE sup_ref = ((SELECT logbank FROM bankaccount WHERE accountnumber = (SELECT remote.security_name FROM remote WHERE id=1)) || ''(logbank)'')
   e_SQLite_GetTable2d($db,'SELECT data1 FROM accesslog WHERE sup_ref = ((SELECT logbank FROM bankaccount WHERE accountnumber = (SELECT remote.security_name FROM remote WHERE id=1)) || ''(logbank)'')',$aResult, $iRows, $iColumns);
   ;_ArrayDisplay($aResult, "Results from the query");
   Local $cur, $curL, $matchIp, $matchAccount, $sql, $aResult2,$iRows2,$iColumns2;
   For $i = 1 To $iRows Step 1
	  $curL=$aResult[$i][0];
	  ;ConsoleWrite($cur & @CRLF);
	  $cur=StringRegExp($curL,"^(\d+\.\d+\.\d+\.\d+)\ (\d+)$",$STR_REGEXPARRAYMATCH);
	  if @error Then ContinueLoop
	  $matchIp=$cur[0];
	  $matchAccount=$cur[1];
	  ;ConsoleWrite($matchIp & " - " & $matchAccount & @CRLF);
	  e_SQLite_GetTable2d($db,'SELECT * FROM accesscodes WHERE key = ' & _SQLite_Escape($curL) & ' AND sup_ref = ''1(player)''',$aResult2, $iRows2, $iColumns2);
	  ;_ArrayDisplay($aResult2, "Results from the query");
	  ConsoleWrite($iRows2);

	  if($iRows2 > 0) Then ContinueLoop
	  $sql='INSERT INTO accesscodes (content,key,sup_ref) VALUES(''?'', ' & _SQLite_Escape($curL) & ', ''1(player)'');';
	  if(_SQLite_Exec($db,$sql) <> $SQLITE_OK) Then
		 ; sigh...
		Exit MsgBox(0,"error","SQLite error executing " & $sql);
	  EndIf
   Next
   Beep();
EndFunc

init();
While 1
   Sleep(100);
WEnd

#include <Array.au3>
#include <SQLite.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <AutoItConstants.au3>
#include <FontConstants.au3>
#include <MsgBoxConstants.au3>
#include <GuiListBox.au3>
#include <File.au3>
#include <String.au3>

HotKeySet("{PGUP}","WriteTransferMoney");
HotKeySet("{PGDN}","ParseBankLogs");

Func Paste()
   Sleep(2*1000);
   Send(ClipGet());
EndFunc
Func init()
   _SQLite_Startup() ; Load the DLL
   If @error Then Exit MsgBox($MB_SYSTEMMODAL, "SQLite Error", "error loading SQLite3.dll ! you can download it from https://www.sqlite.org/download.html , look for ""Precompiled Binaries for Windows"", should be named something like sqlite-dll-win32-x86-3220000.zip");
;why this isn't the default beats me...
   AutoItSetOption("MouseClickDelay",0);
   AutoItSetOption("MouseClickDownDelay",0);
   AutoItSetOption("MouseClickDragDelay",0);
   AutoItSetOption("SendKeyDelay",1);
   AutoItSetOption("SendKeyDownDelay",1);
   AutoItSetOption("WinWaitDelay",0);
   AutoItSetOption("MustDeclareVars",1);
   Global $playerDB=selectPlayer();
   Global $db=_SQLite_Open ( $playerDB,$SQLITE_OPEN_READWRITE, $SQLITE_ENCODING_UTF8 );
   If @error Then Exit MsgBox($MB_SYSTEMMODAL, "SQLite Error", "error loading " & $playerDB & " ! (_SQLite_Open failed, and i'm too lazy to add proper error description code atm)");
EndFunc
Func selectPlayer()
Local $FileList=_FileListToArray(@AppDataDir & "\Onlink\users\","*.db");
Local $GUI = GUICreate("Select agent", 300, 300) ;create gui
Local $ListBox = _GUICtrlListBox_Create($GUI, "", 0, 0,300,300) ;create listbox
For $i = 1 To $FileList[0]
    ;MsgBox(0, $i, $FileList[$i])
    _GUICtrlListBox_AddString($ListBox, StringReplace($FileList[$i],".db","",-1) )
Next

GUISetState() ;show the gui
WinSetOnTop($GUI,"",$WINDOWS_ONTOP);
Local $selected=-1
Do
   Sleep(100);
   $selected=_GUICtrlListBox_GetCurSel ( $ListBox );
Until $selected <> -1;
Local $ret=@AppDataDir & "\Onlink\users\" & _GUICtrlListBox_GetText($ListBox,$selected) & ".db";
ConsoleWriteError($ret);
GUIDelete() ; if autoit expect me to clean up all inner gui controls myself, and this technically leaks memory, here is a list of all the f*ks i give:
Return $ret;
EndFunc

Func SplashMessage($title,$message, $timeoutMS=500)
   Return 0;not working with onlink, onlink overrides WinSetOnTop, apparently...
	  Local $size=50+(StringLen($message)*15);
	  Local $hwnd=SplashTextOn($title, $message, $size, $size, -1, -1, $DLG_TEXTLEFT, "", 24)
	  WinSetOnTop($hwnd,"",$WINDOWS_ONTOP);
	  Sleep($timeoutMS);
	  SplashOff()
   EndFunc

Func e_SQLite_GetTable2d ( $hDB, $sSQL, ByRef $aResult, ByRef $iRows, ByRef $iColumns, $iCharSize = -1, $bSwichDimensions = False )
   if( _SQLite_GetTable2d ( $hDB, $sSQL,$aResult, $iRows,$iColumns, $iCharSize, $bSwichDimensions ) <> $SQLITE_OK) Then
	  Exit MsgBox(0,"SQL error","error executing: " & $sSql );
   EndIf

EndFunc

Func WriteTransferMoney()
   Local $aResult, $iRows, $iColumns;
   local $connectedIp;
   Send("{tab}" & _StringRepeat("{BACKSPACE}",15) & "waiting for db flush, hold on...");
   Do
	  sleep(100);
	  e_SQLite_GetTable2d($db, 'SELECT remotehost FROM player LIMIT 1', $aResult, $iRows, $iColumns) ;
	  $connectedIp=$aResult[1][0];
	  ; get player's account for current bank:
      e_SQLite_GetTable2d($db, 'SELECT SUBSTR(content,LENGTH((SELECT remotehost FROM player LIMIT 1))+2) FROM accounts WHERE content LIKE (SELECT remotehost FROM player LIMIT 1) || '' %'' AND suP_ref LIKE ''%(player)'' LIMIT 1',$aResult, $iRows, $iColumns) ;
	  ;_ArrayDisplay($aResult, "Results from the query");
	  ;ConsoleWrite(UBound($aResult) & @CRLF);
   Until (UBound($aResult) == 2) ; waiting for the game to flush db after entering transfer money screen.. sometimes it takes a few seconds.
   ;_ArrayDisplay($aResult, "Results from the query")
   ;_ArrayDisplay($aResult, "Results from the query");
   local $playerAccountNumber=$aResult[1][0];
   ;ConsoleWrite($playerAccount  & @CRLF );
   e_SQLite_GetTable2d($db, 'SELECT bankaccount.balance FROM bankaccount WHERE bankaccount.accountnumber=(SELECT remote.security_name FROM remote)',$aResult, $iRows, $iColumns) ;
   ;_ArrayDisplay($aResult, "Results from the query");
   Local $connectedAccountBalance=$aResult[1][0];
   e_SQLite_GetTable2d($db, 'SELECT remote.security_name FROM remote WHERE id=1',$aResult, $iRows, $iColumns) ;
   Local $connectedAccountNumber=$aResult[1][0];
   Send(_StringRepeat("{BACKSPACE}",33) & $connectedAccountNumber &  "{tab}" & $connectedIp & "{tab}" & $playerAccountNumber & "{tab}" & $connectedAccountBalance);
; get current connected bank account number: SELECT remote.security_name WHERE id=1

; get balance of current connected bank account: SELECT bankaccount.balance FROM bankaccount WHERE bankaccount.accountnumber=(SELECT remote.security_name FROM remote)

EndFunc
Func ParseBankLogs()
   Local $aResult, $iRows, $iColumns;
   local $connectedIp;
   ;Send("{tab}" & _StringRepeat("{BACKSPACE}",15) & "waiting for db flush, hold on...");
   Do
	  sleep(100);
	  e_SQLite_GetTable2d($db, 'SELECT remotehost FROM player LIMIT 1', $aResult, $iRows, $iColumns) ;
	  $connectedIp=$aResult[1][0];
	  ; get player's account for current bank:
      e_SQLite_GetTable2d($db, 'SELECT SUBSTR(content,LENGTH((SELECT remotehost FROM player LIMIT 1))+2) FROM accounts WHERE content LIKE (SELECT remotehost FROM player LIMIT 1) || '' %'' AND suP_ref LIKE ''%(player)'' LIMIT 1',$aResult, $iRows, $iColumns) ;
	  ;_ArrayDisplay($aResult, "Results from the query");
	  ;ConsoleWrite(UBound($aResult) & @CRLF);
   Until (UBound($aResult) == 2) ; waiting for the game to flush db after entering transfer money screen.. sometimes it takes a few seconds.
   ; current connected account number: SELECT remote.security_name FROM remote WHERE id=1
   ; logbank: SELECT logbank FROM bankaccount WHERE accountnumber = (SELECT remote.security_name FROM remote WHERE id=1)
   ; logs: SELECT data1,data2,data3,date,fromip,fromname FROM accesslog WHERE sup_ref = ((SELECT logbank FROM bankaccount WHERE accountnumber = (SELECT remote.security_name FROM remote WHERE id=1)) || ''(logbank)'')
   e_SQLite_GetTable2d($db,'SELECT data1 FROM accesslog WHERE sup_ref = ((SELECT logbank FROM bankaccount WHERE accountnumber = (SELECT remote.security_name FROM remote WHERE id=1)) || ''(logbank)'')',$aResult, $iRows, $iColumns);
   ;_ArrayDisplay($aResult, "Results from the query");
   Local $cur, $curL, $matchIp, $matchAccount, $sql, $aResult2,$iRows2,$iColumns2;
   For $i = 1 To $iRows Step 1
	  $curL=$aResult[$i][0];
	  ;ConsoleWrite($cur & @CRLF);
	  $cur=StringRegExp($curL,"^(\d+\.\d+\.\d+\.\d+)\ (\d+)$",$STR_REGEXPARRAYMATCH);
	  if @error Then ContinueLoop
	  $matchIp=$cur[0];
	  $matchAccount=$cur[1];
	  ;ConsoleWrite($matchIp & " - " & $matchAccount & @CRLF);
	  e_SQLite_GetTable2d($db,'SELECT * FROM accesscodes WHERE key = ' & _SQLite_Escape($curL) & ' AND sup_ref = ''1(player)''',$aResult2, $iRows2, $iColumns2);
	  ;_ArrayDisplay($aResult2, "Results from the query");
	  ConsoleWrite($iRows2);

	  if($iRows2 > 0) Then ContinueLoop
	  $sql='INSERT INTO accesscodes (content,key,sup_ref) VALUES(''?'', ' & _SQLite_Escape($curL) & ', ''1(player)'');';
	  if(_SQLite_Exec($db,$sql) <> $SQLITE_OK) Then
		 ; sigh...
		Exit MsgBox(0,"error","SQLite error executing " & $sql);
	  EndIf
   Next
   Beep();
EndFunc

init();
While 1
   Sleep(100);
WEnd


Fixed one-click login, fixes atomizer/muledump#68

The local flash store for your .sol is stored within a different directory,
matching the new domain.
(realmofthemadgod.com -> realmofthemadgodhrd.appspot.com)

#include <String.au3>
#include <File.au3>
#include <Array.au3>

Global $string, $password, $email, $data, $path, $search, $file, $root
$root = "HKEY_CLASSES_ROOT\muledump"

Func _write()
	RegWrite($root,"","REG_SZ","URL: muledump Protocol")
	RegWrite($root,"URL Protocol","REG_SZ","")
	RegWrite($root & "\shell")
	RegWrite($root & "\shell\open")
	RegWrite($root & "\shell\open\command","","REG_SZ", @AutoItExe & ' "' & @ScriptFullPath & '" %1')
	If RegRead("HKEY_CLASSES_ROOT\muledump","") Then
		MsgBox(64,"mulelogin","muledump: URL handler installed")
	Else
		MsgBox(16,"mulelogin","Unable to write to registry" & @CRLF & "Try again with admin rights")
	EndIf
	Exit
EndFunc

Func _install()
	Local $k
	$k = RegEnumKey($root, 1)
	If @error == 2 Then
		MsgBox(16,"mulelogin","Unable to open the registry" & @CRLF & "Try again with admin rights")
		Exit
	EndIf
	If @error == 1 Then _write()
	$k = MsgBox(6 + 32, 'mulelogin', _
		'URL handler is already installed. Uninstall?' & @CRLF & @CRLF & _
		'"Cancel" to do nothing' & @CRLF & _
		'"Try Again" to reinstall' & @CRLF & _
		'"Continue" to uninstall')
	If $k == 10 Then _write()
	If $k == 11 Then
		RegDelete($root)
		if @error <> 0 Then
			MsgBox(16,"mulelogin","Unable to delete the key" & @CRLF & "Try again with admin rights")
		Else
			MsgBox(64,"mulelogin","muledump: URL handler uninstalled")
		EndIf
	EndIf
	Exit
EndFunc

Func _length($string)
	Local $binlength, $declength, $array, $result
	$declength = StringLen($string)/2
    While $declength > 0
        $binlength &= Mod($declength,2)
        $declength = Floor($declength/2)
    WEnd
	$binlength = StringReverse($binlength)
	if @error <> 0 Then
		$binlength = _StringReverse($binlength)
	EndIf
	$binlength = $binlength & "1"
	$array = StringSplit($binlength,"")
	For $i = 1 To $array[0]
        $array[0] -= 1
        If $array[$i] = "1" Then $result += 2 ^ ($array[0])
	Next
	Return Hex(Int($result),2)
EndFunc

Func _build()
	;header
	$string  = "0x 00 BF" 						;Magic Number		 2 bytes
	$string &= "?? ?? ?? ??"					;Size				 4 bytes
	$string &= "54 43 53 4F 00 04 00 00 00 00"	;Marker				10 bytes
	$string &= "00 05"							;Name Size			 2 bytes
	$string &= "52 6F 74 4D 47"					;"RotMG"			 5 bytes
	$string &= "00 00 00"						;Padding			 3 bytes
	$string &= "03"								;AMF Version		 1 byte

	;data
	$string &= "11"								;Length				 1 byte
	$string &= "50 61 73 73 77 6F 72 64"		;"Password"			 8 bytes
	$string &= "06"								;Type (string) 		 1 byte
	$string &= _length($password)				;Length				 1 byte
	$string &= $password						;Actual Password	 ? bytes
	$string &= "00"								;AMF Padding		 1 byte

	$string &= "09"								;Length				 1 byte
	$string &= "47 55 49 44"					;"GUID"				 4 bytes
	$string &= "06"								;Type (string)		 1 byte
	$string &= _length($email)					;Length				 1 byte
	$string &=  $email							;Email				 ? bytes
	$string &= "00"								;AMF Padding		 1 byte

	$string = StringReplace($string," ","")
	$string = StringRegExpReplace($string,"\?{8}",Hex(Int(StringLen(StringMid($string,15))/2)))
EndFunc

If $CmdLine[0] = 0 Then _install()

$data = StringReplace($CmdLine[1],"muledump:","")
$data = StringSplit($data,"-")
$email = $data[1]
$password = $data[2]

_build()

$path = @AppDataDir & "\Macromedia\Flash Player\#SharedObjects\"
$search = FileFindFirstFile($path & "*")
$path &= FileFindNextFile($search) & "\realmofthemadgodhrd.appspot.com\RotMG.sol"
FileClose($search)
$file = FileOpen($path,18)
FileWrite($file,$string)
FileClose($file)

ShellExecute("http://www.realmofthemadgod.com/")
; replace the line above if you're using a projector
; for example, with totalcmd + swfview
;ShellExecute('C:\Program Files\Total Commander\Totalcmd.exe', '/S=L:Pswfview e:\temp\rotmg\loader.swf')
; or to open the latest swf with the default Adobe Flash Projector
;ShellExecute('C:\flashplayer_16_sa.exe', 'https://realmofthemadgodhrd.appspot.com/AssembleeGameClient'&BinaryToString(InetRead("http://www.realmofthemadgod.com/version.txt"))&'.swf')

#include <String.au3>
#include <File.au3>
#include <Array.au3>

Global $string, $password, $email, $data, $path, $search, $file, $root
$root = "HKEY_CLASSES_ROOT\muledump"

Func _write()
	RegWrite($root,"","REG_SZ","URL: muledump Protocol")
	RegWrite($root,"URL Protocol","REG_SZ","")
	RegWrite($root & "\shell")
	RegWrite($root & "\shell\open")
	RegWrite($root & "\shell\open\command","","REG_SZ", @AutoItExe & ' "' & @ScriptFullPath & '" %1')
	If RegRead("HKEY_CLASSES_ROOT\muledump","") Then
		MsgBox(64,"mulelogin","muledump: URL handler installed")
	Else
		MsgBox(16,"mulelogin","Unable to write to registry" & @CRLF & "Try again with admin rights")
	EndIf
	Exit
EndFunc

Func _install()
	Local $k
	$k = RegEnumKey($root, 1)
	If @error == 2 Then
		MsgBox(16,"mulelogin","Unable to open the registry" & @CRLF & "Try again with admin rights")
		Exit
	EndIf
	If @error == 1 Then _write()
	$k = MsgBox(6 + 32, 'mulelogin', _
		'URL handler is already installed. Uninstall?' & @CRLF & @CRLF & _
		'"Cancel" to do nothing' & @CRLF & _
		'"Try Again" to reinstall' & @CRLF & _
		'"Continue" to uninstall')
	If $k == 10 Then _write()
	If $k == 11 Then
		RegDelete($root)
		if @error <> 0 Then
			MsgBox(16,"mulelogin","Unable to delete the key" & @CRLF & "Try again with admin rights")
		Else
			MsgBox(64,"mulelogin","muledump: URL handler uninstalled")
		EndIf
	EndIf
	Exit
EndFunc

Func _length($string)
	Local $binlength, $declength, $array, $result
	$declength = StringLen($string)/2
    While $declength > 0
        $binlength &= Mod($declength,2)
        $declength = Floor($declength/2)
    WEnd
	$binlength = StringReverse($binlength)
	if @error <> 0 Then
		$binlength = _StringReverse($binlength)
	EndIf
	$binlength = $binlength & "1"
	$array = StringSplit($binlength,"")
	For $i = 1 To $array[0]
        $array[0] -= 1
        If $array[$i] = "1" Then $result += 2 ^ ($array[0])
	Next
	Return Hex(Int($result),2)
EndFunc

Func _build()
	;header
	$string  = "0x 00 BF" 						;Magic Number		 2 bytes
	$string &= "?? ?? ?? ??"					;Size				 4 bytes
	$string &= "54 43 53 4F 00 04 00 00 00 00"	;Marker				10 bytes
	$string &= "00 05"							;Name Size			 2 bytes
	$string &= "52 6F 74 4D 47"					;"RotMG"			 5 bytes
	$string &= "00 00 00"						;Padding			 3 bytes
	$string &= "03"								;AMF Version		 1 byte

	;data
	$string &= "11"								;Length				 1 byte
	$string &= "50 61 73 73 77 6F 72 64"		;"Password"			 8 bytes
	$string &= "06"								;Type (string) 		 1 byte
	$string &= _length($password)				;Length				 1 byte
	$string &= $password						;Actual Password	 ? bytes
	$string &= "00"								;AMF Padding		 1 byte

	$string &= "09"								;Length				 1 byte
	$string &= "47 55 49 44"					;"GUID"				 4 bytes
	$string &= "06"								;Type (string)		 1 byte
	$string &= _length($email)					;Length				 1 byte
	$string &=  $email							;Email				 ? bytes
	$string &= "00"								;AMF Padding		 1 byte

	$string = StringReplace($string," ","")
	$string = StringRegExpReplace($string,"\?{8}",Hex(Int(StringLen(StringMid($string,15))/2)))
EndFunc

If $CmdLine[0] = 0 Then _install()

$data = StringReplace($CmdLine[1],"muledump:","")
$data = StringSplit($data,"-")
$email = $data[1]
$password = $data[2]

_build()

$path = @AppDataDir & "\Macromedia\Flash Player\#SharedObjects\"
$search = FileFindFirstFile($path & "*")
$path &= FileFindNextFile($search) & "\www.realmofthemadgod.com\RotMG.sol"
FileClose($search)
$file = FileOpen($path,18)
FileWrite($file,$string)
FileClose($file)

ShellExecute("http://www.realmofthemadgod.com/")
; replace the line above if you're using a projector
; for example, with totalcmd + swfview
;ShellExecute('C:\Program Files\Total Commander\Totalcmd.exe', '/S=L:Pswfview e:\temp\rotmg\loader.swf')


udf cleanup

udf cleanup

#include-once
#include <..\bin\variables.au3>
#include <FileIncludes.au3>
#region Secrets
	#include <..\secret\dbEncriptionPass.secret>
#endregion
#region UDF
	#include <Array.au3>
	#include <File.au3>
   #include <Constants.au3>
   #include <Date.au3>
;~ 	#include <IE.au3>
#endregion UDF
#region internal UDF
	#include <../udf/WinHttpConstants.au3>
	#include <../udf/WinHttp.au3>
	#include <../udf/WinHttp1.au3>
	#include <..\udf\CleanString.au3>
	#include <..\udf\_epoch.au3>
	#include <..\udf\OO_JSON.au3>
	#include <..\udf\_PrintFromArray.au3>
	#include <..\udf\Telegram UDF.au3>
#endregion internal UDF
#region BIN
	#include <..\SQLite\SQLite.au3>
	#include <SQLite.dll.au3>
	#include <..\SQLite\SQLite_Functions.au3>
	#include <..\control\AI.au3>
	#include <..\control\functions.au3>

#endregion

#include-once
#include <..\bin\variables.au3>
#include <FileIncludes.au3>
#region Secrets
	#include <..\secret\dbEncriptionPass.secret>
#endregion
#region UDF
	#include <Array.au3>
	#include <File.au3>
   #include <Constants.au3>
   #include <Date.au3>
	#include <IE.au3>
#endregion UDF
#region internal UDF
	#include <../udf/WinHttpConstants.au3>
	#include <../udf/WinHttp.au3>
	#include <../udf/WinHttp1.au3>
	#include <..\udf\CleanString.au3>
	#include <..\udf\_epoch.au3>
	#include <..\udf\OO_JSON.au3>
	#include <..\udf\_PrintFromArray.au3>
	#include <..\udf\Telegram UDF.au3>
#endregion internal UDF
#region BIN
	#include <..\SQLite\SQLite.au3>
	#include <SQLite.dll.au3>
	#include <..\SQLite\SQLite_Functions.au3>
	#include <..\control\AI.au3>
	#include <..\control\functions.au3>

#endregion


Update Sample.au3

Update Sample.au3


"Unbenannt - Editor" wird automatisch benutzt, wenn es das einzige Notepad-Fenster ist

#include <MsgBoxConstants.au3>
#include <Date.au3>
#include <WinAPI.au3>

; Konstanten
Const $editorPath = "%SystemRoot%\system32\NOTEPAD.EXE"
Const $targetWindowClass = "[CLASS:Notepad]"

; von Funktionen als Seiteneffekt nderbare Werte
$userRequestedNewEditor = False

Func OpenNewEditor()
    $userRequestedNewEditor = True
    Run(_WinAPI_ExpandEnvironmentStrings($editorPath))
    Sleep(2000)
EndFunc

Func GetWindowList()
    Return WinList($targetWindowClass)
EndFunc

; hole oder ffne Notepad Fenster
Do
    $windowList = GetWindowList()
	If $windowlist[0][0] = 0 Then
        $hNotepad = 0
        $msgBoxResult = MsgBox(BitOR($MB_CANCELTRYCONTINUE, $MB_ICONERROR), _
		    "WatchClipBoard - Error", "No editor window found!" & @CRLF & @CRLF & _
			"  CANCEL" & Chr(9) & Chr(9) & "exit" & @CRLF & _
			"  RETRY" & Chr(9) & Chr(9) & "try again" & @CRLF & _
			"  CONTINUE" & Chr(9) & "open a new text editor window")
		Switch $msgBoxResult
          Case 11   ; Weiter
			OpenNewEditor()
			ContinueCase
		  Case 10   ; Wiederholen
		  Case Else ; Abbrechen/Dialog-Schlieen (2) etc.
            Exit 1
        EndSwitch
	Else
        If $windowlist[0][0] = 1 And ($userRequestedNewEditor Or $windowList[1][0] = "Unbenannt - Editor") Then
            $j = 1
        Else
            $allWindowTitles = ""
		    For $i = 1 To $windowlist[0][0]
		        $allWindowTitles = $allWindowTitles & $i & "  " & $windowList[$i][0] & @CRLF
		    Next
		    $inputBoxResult = InputBox("WatchClipBoard - Choice required", "These editor windows have been found:" & _
			    @CRLF & @CRLF & $allWindowTitles & @CRLF & @CRLF & "Enter the number of the editor to use," & @CRLF & _
			    "or 0 for a new editor", "0", "", -1, 250)
            If @error Then
                Exit 1
            EndIf
            $j = 1 * $inputBoxResult
        EndIf
		If $j = 0 Then
		    OpenNewEditor()
			Do
			  Sleep(300)
			  $newWindowList = GetWindowList()
			  $theNewWindowHandle = 0
			  ; alle neuen Window-Handles prfen, ob ein bisher unbekanntes dabei ist
			  For $k = 1 To $newWindowlist[0][0]
				 $knownWindow = False
				 For $i = 1 To $windowlist[0][0]
					If $windowList[$i][1] = $newWindowList[$k][1] Then
					   $knownWindow = True
					   ExitLoop
					EndIf
				 Next
				 If Not $knownWindow Then
					$theNewWindowHandle = $newWindowList[$k][1]
					ExitLoop
				 EndIf
			  Next
			Until $theNewWindowHandle <> 0
        	$hNotepad = $theNewWindowHandle
		 Else
			; prfen, ob der eingegebene Index valide ist
			If $j < 0 Or $j > $windowList[0][0] Then
			   $hNotepad = 0
			Else
			   $hNotepad = $windowList[$j][1]
			EndIf
	    EndIf
    EndIf
Until $hNotepad <> 0

; Hauptschleife
$lastClipContents = ClipGet()
While True
    $clipContents = ClipGet()
    If Not @error And $clipContents <> $lastClipContents Then
        $hCurrentWin = WinGetHandle("")
        If WinActivate($hNotepad) = 0 Then
            MsgBox($MB_ICONERROR, "WatchClipBoard - Error", "Editor window no more available!" & @CRLF & "Please restart.")
            Exit 1
        EndIf
        Sleep(300)
		If Not StringRegExp($clipContents, "^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d") Then
            Send(StringReplace(_Date_Time_SystemTimeToDateTimeStr(_Date_Time_GetLocalTime(), 1), "/", "-") & " -")
			If Not StringRegExp($clipContents, "^\s") Then
                Send(" ")
			EndIf
		EndIf
        Send("^v")
		If StringRight($clipContents, 2) <> @CRLF Then
            Send("{ENTER}")
	    EndIf
        Sleep(300)
        WinActivate($hCurrentWin)
        $lastClipContents = $clipContents
    EndIf
    Sleep(300)
WEnd

#include <MsgBoxConstants.au3>
#include <Date.au3>
#include <WinAPI.au3>

; Konstanten
Const $editorPath = "%SystemRoot%\system32\NOTEPAD.EXE"
Const $targetWindowClass = "[CLASS:Notepad]"

Func OpenNewEditor()
   Run(_WinAPI_ExpandEnvironmentStrings($editorPath))
   Sleep(2000)
EndFunc

Func GetWindowList()
   Return WinList($targetWindowClass)
EndFunc

; hole oder ffne Notepad Fenster
Do
    $windowList = GetWindowList()
	If $windowlist[0][0] = 0 Then
        $hNotepad = 0
        $msgBoxResult = MsgBox(BitOR($MB_CANCELTRYCONTINUE, $MB_ICONERROR), _
		    "WatchClipBoard - Error", "Editor not found for window class: '" & $targetWindowClass & "'" & @CRLF & _
			"(Press 'Continue' to open a new text editor window)")
		Switch $msgBoxResult
        Case 11   ; Weiter
			OpenNewEditor()
			ContinueCase
		Case 10   ; Wiederholen
		Case Else ; Abbrechen/Dialog-Schlieen (2) etc.
            Exit 1
        EndSwitch
	Else
		$allWindowTitles = ""
		For $i = 1 To $windowlist[0][0]
		   $allWindowTitles = $allWindowTitles & $i & "  " & $windowList[$i][0] & @CRLF
		Next
		$j = 1 * InputBox("WatchClipBoard - Choice required", "These editor windows have been found:" & _
			@CRLF & @CRLF & $allWindowTitles & @CRLF & @CRLF & "Enter the number of the editor to use," & @CRLF & _
			"or 0 for a new editor", "0", "", -1, 250)
		If $j = 0 Then
		    OpenNewEditor()
			Do
			  Sleep(300)
			  $newWindowList = GetWindowList()
			  $theNewWindowHandle = 0
			  ; alle neuen Window-Handles prfen, ob ein bisher unbekanntes dabei ist
			  For $k = 1 To $newWindowlist[0][0]
				 $knownWindow = False
				 For $i = 1 To $windowlist[0][0]
					If $windowList[$i][1] = $newWindowList[$k][1] Then
					   $knownWindow = True
					   ExitLoop
					EndIf
				 Next
				 If Not $knownWindow Then
					$theNewWindowHandle = $newWindowList[$k][1]
					ExitLoop
				 EndIf
			  Next
			Until $theNewWindowHandle <> 0
        	$hNotepad = $theNewWindowHandle
		 Else
			; prfen, ob der eingegebene Index valide ist
			If $j < 0 Or $j > $windowList[0][0] Then
			   $hNotepad = 0
			Else
			   $hNotepad = $windowList[$j][1]
			EndIf
	    EndIf
    EndIf
Until $hNotepad <> 0

; Hauptschleife
$lastClipContents = ClipGet()
While True
    $clipContents = ClipGet()
    If Not @error And $clipContents <> $lastClipContents Then
        $hCurrentWin = WinGetHandle("")
        WinActivate($hNotepad)
        Sleep(300)
		If Not StringRegExp($clipContents, "^\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d") Then
            Send(StringReplace(_Date_Time_SystemTimeToDateTimeStr(_Date_Time_GetLocalTime(), 1), "/", "-") & " -")
			If Not StringRegExp($clipContents, "^\s") Then
                Send(" ")
			EndIf
		EndIf
        Send("^v")
		If StringRight($clipContents, 2) <> @CRLF Then
            Send("{ENTER}")
	    EndIf
        Sleep(300)
        WinActivate($hCurrentWin)
        $lastClipContents = $clipContents
    EndIf
    Sleep(300)
WEnd