Func _Net_LinkUpdate($p_Show = 0); Show GUI
_PrintDebug('+' & @ScriptLineNumber & ' Calling _Net_LinkUpdate')
Local $Message = IniReadSection($g_TRAIni, 'Nt-LinkUpdate')
Local $Extract, $Fetch, $n, $Entry
If StringInStr($p_Show, 1) Then GUICtrlSetData($g_UI_Interact[6][4], _GetSTR($Message, 'H1')); => help text
$UpdateIni = $g_ProgDir & '\Update\Config\Mod.ini.diff'
$UpdateURL = IniRead($g_MODIni, 'BWS-URLUpdate', 'Down', 'ftp://bwp_update:guest@bwp.bplaced.net/bws_link.7z')
$UpdateArchive = IniRead($g_MODIni, 'BWS-URLUpdate', 'Save', 'bws_link.7z')
; ---------------------------------------------------------------------------------------------
; 1. Step: Get the update-thread and save the file
; ---------------------------------------------------------------------------------------------
If StringInStr($p_Show, 1) Then
Global $g_LogFile = $g_LogDir & '\BiG World Update Debug.txt'
$g_Flags[0] = 1
_Process_Gui_Create(1, 0)
GUICtrlSetData($g_UI_Static[6][1], _GetTR($Message, 'L1')); => watch progress
GUICtrlSetState($g_UI_Button[6][1], $GUI_DISABLE); we don't need input here
GUICtrlSetState($g_UI_Interact[6][5], $GUI_DISABLE)
GUICtrlSetData($g_UI_Static[6][2], _GetTR($Message, 'L2')); => loading data
FileClose(FileOpen($g_LogFile, 2))
EndIf
; ---------------------------------------------------------------------------------------------
; 2. Step: Get the update-file and save the file - if the actual one is too old
; ---------------------------------------------------------------------------------------------
For $p=1 to 3
$Ping = Ping('194.25.0.60', 1000); test if computer is online -- ip is a tcom-dns-server
If $Ping <> 0 Then ExitLoop
Next
If $Ping = 0 Then
If StringInStr($p_Show, 1) Then
GUICtrlSetData($g_UI_Interact[6][1], 100)
_Process_SetScrollLog(_GetTR($Message, 'L9')); => ping failed
GUICtrlSetState($g_UI_Button[0][3], $GUI_ENABLE); Enable the key
_Process_Gui_Delete(6, 6, 5, 5, 1)
ElseIf StringInStr($p_Show, 3) Then
_Misc_MsgGUI(3, _GetTR($g_UI_Message, '0-T1'), StringRegExpReplace(_GetTR($Message, 'L7'), '\A[^\x7c]*\x7c|\x7c.*\z', '')&'|'& _GetTR($g_UI_Message, '9-L1')); => error fetching updates
EndIf
Return; not connected to the net
EndIf
If StringTrimRight(FileGetTime($UpdateIni,1,1), 4) <> @YEAR&@MON&@MDAY&@HOUR Or StringInStr($p_Show, 1) Then; only fetch if forced or file is not modified in current @HOUR
$Fetch = _Net_DownloadFile($UpdateURL, $UpdateArchive, 'BWS-URLUpdate', '', 'BiG World URL-Update', 1)
If $Fetch = 0 And $p_Show = '0' Then; failure: single update
Return; don't halt during download
ElseIf $Fetch = 0 And StringInStr($p_Show, '3') Then; failure: boot update
_Misc_MsgGUI(3, _GetTR($g_UI_Message, '0-T1'), _GetTR($g_UI_Message, '9-L1')); => error fetching updates
Return; not connected to the net
ElseIf $Fetch = 0 And StringInStr($p_Show, '1') Then; failure: manual update
_Process_SetScrollLog(_GetTR($Message, 'L7')); => page could not be loaded
GUICtrlSetState($g_UI_Button[0][3], $GUI_ENABLE); Enable the key
_Process_Gui_Delete(5, 5, 5, 5, 1)
Return
ElseIf $Fetch = 2 and StringInStr($p_Show, '0') Then; exists: boot or single link-update
Return; if file exists, update has been applied
ElseIf $Fetch = 2 and StringInStr($p_Show, '1') Then; exists: manual link-update
_Process_SetScrollLog(_GetTR($Message, 'L8')); => finished
GUICtrlSetState($g_UI_Button[0][3], $GUI_ENABLE); Enable the key
_Process_Gui_Delete(5, 5, 5, 5, 1)
Return; if file exists, update has been applied
ElseIf $Fetch = 1 Then; loaded: all update-types
$UpdateArchive = IniRead($g_MODIni, 'BWS-URLUpdate', 'Save', 'bws_link.7z')
$Extract = _Extract_7z($g_DownDir&'\'&$UpdateArchive, $g_ProgDir & '\Update')
If $Extract = 0 Or Not FileExists($UpdateIni) Or FileGetSize($g_DownDir&'\'&$UpdateArchive) = 32 Then ; extract failed / Ini does not exist / empty place-holder (until the first real update-package is uploaded) was loaded
If StringInStr($p_Show, '1') Then
GUICtrlSetData($g_UI_Interact[6][1], 100)
_Process_SetScrollLog(_GetTR($Message, 'L7')); => page could not be loaded
GUICtrlSetState($g_UI_Button[0][3], $GUI_ENABLE); Enable the key
_Process_Gui_Delete(6, 6, 5, 5, 0)
EndIf
Return
Else
FileSetTime($UpdateIni,@YEAR&@MON&@MDAY&@HOUR&@MIN&@SEC,1); save time so file won't get fetched within current hour
GUICtrlSetData($g_UI_Interact[6][1], 20)
GUICtrlSetData($g_UI_Static[6][2], _GetTR($Message, 'L3')); => prepare
EndIf
EndIf
EndIf
; ---------------------------------------------------------------------------------------------
; 3. Step: Get and write the new entries into the config-files
; ---------------------------------------------------------------------------------------------
If StringInStr($p_Show, '2') Or StringInStr($p_Show, '3') Then
Local $ShownTab[2]=[9,6]
If StringInStr($p_Show, 2) Then
$p_Show = 1
Else
$p_Show = 0
EndIf
If $p_Show Then GUICtrlSetData($g_UI_Interact[6][1], 40)
If $p_Show Then GUICtrlSetData($g_UI_Static[6][2], _GetTR($Message, 'L4')); => process
If $p_Show Then GUICtrlSetState($g_UI_Button[0][3], $GUI_DISABLE); Don't screw things up
If $Extract = 1 Then FileCopy($g_MODIni, $g_MODIni & '-' & @MON & '.' & @MDAY & '-' & @HOUR & '.' & @MIN & '.' & @SEC & '.bak'); create a backup
$SectionNames = IniReadSectionNames($UpdateIni)
For $s = 1 To $g_Setups[0][0]
If _MathCheckDiv($s, 10) = 2 Then GUICtrlSetData($g_UI_Interact[$ShownTab[$p_Show]][1], 40 + ($s * 60 / $g_Setups[0][0]))
$Success = 0
For $n=1 to $SectionNames[0]
If $g_Setups[$s][0] = $SectionNames[$n] Then
$Success = 1
ExitLoop
EndIf
Next
If $Success = 0 Then ContinueLoop; don't update if the chapter is not mentioned
$h = 0; "mod is changed-line" is shown
$NewSection = IniReadSection($UpdateIni, $g_Setups[$s][0]); has to exist we searched for sections from the update-file
$OldSection = IniReadSection($g_MODIni, $g_Setups[$s][0])
If Not IsArray($OldSection) Then; create dummy entry for new additions
Local $OldSection[1][2]
$OldSection[0][0]=0
EndIf
ReDim $OldSection[$NewSection[0][0]+$OldSection[0][0]+1][2]; ReDim seems be faster once & big than small & every time during _IniWrite/Delelte, so use a size big enough.
For $n = 1 to $NewSection[0][0]
$OldValue = _IniRead($OldSection, $NewSection[$n][0], ''); get the old entry
If $NewSection[$n][1] <> $OldValue Then; there is a change
If $h = 0 Then; make a note
$h = 1
If $p_Show Then _Process_SetScrollLog(_GetTR($Message, 'L5') & ' ' & $g_Setups[$s][1] & ':'); => update entry
EndIf
If $NewSection[$n][1] = '' Then; empty key-value => delete key in original file
_IniDelete($OldSection, $NewSection[$n][0])
Else; new or changed value
_IniWrite($OldSection, $NewSection[$n][0], $NewSection[$n][1], 'O')
EndIf
If $p_Show Then _Process_SetScrollLog($NewSection[$n][0] & '=' & $NewSection[$n][1])
EndIf
Next
If $h = 1 Then
ReDim $OldSection[$OldSection[0][0]+1][2]
IniWriteSection($g_MODIni, $g_Setups[$s][0], $OldSection); write changes
If $p_Show Then _Process_SetScrollLog('')
EndIf
Next
$NewSection = IniReadSection($UpdateIni, 'DeletedIniSections'); delete removed section
If Not @error Then
For $n=1 To $NewSection[0][0]
IniDelete($g_MODIni, $NewSection[$n][0])
Next
EndIf
GUICtrlSetData($g_UI_Interact[$ShownTab[$p_Show]][1], 100)
If $p_Show = 0 Then Return
GUICtrlSetData($g_UI_Static[6][2], _GetTR($Message, 'L6')); => reloading to apply changes
_Process_SetScrollLog(_GetTR($Message, 'L6')); => reloading to apply changes
_Tree_GetCurrentSelection(1)
_Misc_ReBuildTreeView()
_Tree_Reload()
_Misc_SetTab(6)
_Process_SetScrollLog(_GetTR($Message, 'L8')); => finished
GUICtrlSetState($g_UI_Button[0][3], $GUI_ENABLE); Enable the key
If StringInStr($p_Show, 1) Then _Process_Gui_Delete(5, 5, 5, 5, 1)
EndIf
EndFunc ;==>_Net_LinkUpdate