#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
Global $vText_Server_1 = '10.10.1.10'
Global $vText_Server_2 = '10.10.1.20'
Global $vText_Server_3 = '10.10.1.30'
Global $vText_Server_4 = '10.10.1.40'
Global $vText_Server_5 = '10.10.1.50'
Global $vReplace_1 = '10.10.1.20|10.10.1.30|10.10.1.40|10.10.1.50'
Global $vReplace_2 = '10.10.1.10|10.10.1.30|10.10.1.40|10.10.1.50'
Global $vReplace_3 = '10.10.1.20|10.10.1.10|10.10.1.40|10.10.1.50'
Global $vReplace_4 = '10.10.1.20|10.10.1.30|10.10.1.10|10.10.1.50'
Global $vReplace_5 = '10.10.1.20|10.10.1.30|10.10.1.40|10.10.1.10'
Dim $aCheckBox[3][3] = [[2],['server.txt', '', 'Программу А'],['user.config', '', 'Программу Б']]
$hForm = GUICreate('Server_Change', 180, 267, 300, 165)
$vPageControl1 = GUICtrlCreateTab(0, 8, 180, 259)
$vTabSheet_General = GUICtrlCreateTabItem(' Выбор ')
$vButton_Server_1 = GUICtrlCreateButton('Сервер 1', 8, 42, 75, 25 + $aCheckBox[0][0])
GUICtrlSetFont(-1, 8, 400, 0, 'Arial')
$vButton_Server_2 = GUICtrlCreateButton('Сервер 2', 8, 74, 75, 25 + $aCheckBox[0][0])
GUICtrlSetFont(-1, 8, 400, 0, 'Arial')
$vButton_Server_3 = GUICtrlCreateButton('Сервер 3', 8, 106, 75, 25 + $aCheckBox[0][0])
GUICtrlSetFont(-1, 8, 400, 0, 'Arial')
$vButton_Server_4 = GUICtrlCreateButton('Сервер 4', 8, 138, 75, 25 + $aCheckBox[0][0])
GUICtrlSetFont(-1, 8, 400, 0, 'Arial')
$vButton_Server_5 = GUICtrlCreateButton('Сервер 5', 8, 169, 75, 25 + $aCheckBox[0][0])
GUICtrlSetFont(-1, 8, 400, 0, 'Arial')
$vLabel1 = GUICtrlCreateLabel('10.10.1.10', 96, 49, 61, 18)
GUICtrlSetFont(-1, 8, 400, 0, 'Arial')
$vLabel2 = GUICtrlCreateLabel('10.10.1.20', 96, 81, 55, 18)
GUICtrlSetFont(-1, 8, 400, 0, 'Arial')
$vLabel3 = GUICtrlCreateLabel('10.10.1.30', 96, 113, 73, 18)
GUICtrlSetFont(-1, 8, 400, 0, 'Arial')
$vLabel4 = GUICtrlCreateLabel('10.10.1.40', 96, 145, 79, 18)
GUICtrlSetFont(-1, 8, 400, 0, 'Arial')
$vLabel5 = GUICtrlCreateLabel('10.10.1.50', 96, 177, 73, 18)
GUICtrlSetFont(-1, 8, 400, 0, 'Arial')
For $i = 1 To $aCheckBox[0][0]
$aCheckBox[$i][1] = GUICtrlCreateCheckbox('Выбрать ' & $aCheckBox[$i][2], 20, 205 + ($i - 1) * 30, 140, 20)
Next
$vTabSheet_Option = GUICtrlCreateTabItem(' Инфо ')
$vGroup1 = GUICtrlCreateGroup('', 8, 40, 162, 97)
GUICtrlSetFont(-1, 8, 400, 0, 'Arial')
$vLabel6 = GUICtrlCreateLabel('Локальный Интернет', 16, 56, 144, 18)
$vLabel7 = GUICtrlCreateLabel('10.10.1.10', 16, 72, 61, 18)
$vLabel8 = GUICtrlCreateLabel('10.10.1.20', 16, 88, 55, 18)
$vLabel9 = GUICtrlCreateLabel(' 10.10.1.30', 88, 72, 73, 18)
$vLabel10 = GUICtrlCreateLabel(' 10.10.1.40', 88, 88, 79, 18)
$vLabel11 = GUICtrlCreateLabel(' 10.10.1.50', 88, 104, 73, 18)
GUICtrlCreateGroup('', -99, -99, 1, 1)
$vGroup2 = GUICtrlCreateGroup('', 8, 144, 162, 50)
GUICtrlSetFont(-1, 8, 400, 0, 'Arial')
$vLabel12 = GUICtrlCreateLabel('www.autoit-script.ru', 40, 165, 98, 18)
GUICtrlCreateGroup('', -99, -99, 1, 1)
GUICtrlCreateTabItem('')
ReDim $aCheckBox[3][2]
GUISetState(@SW_SHOW)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $vButton_Server_1
$sFiles = ''
For $i = 1 To $aCheckBox[0][0]
If BitAND(GUICtrlRead($aCheckBox[$i][1]), $GUI_CHECKED) Then
$sFiles &= $aCheckBox[$i][0] & '|'
EndIf
Next
If Not $sFiles Then
MsgBox(0, ' Info', 'Выберите программу', 0, $hForm)
ContinueLoop
EndIf
$sFiles = StringTrimRight($sFiles, 1)
$aSearch = _FileSearch('C:', $sFiles, 1)
If @error Then
MsgBox(16, ' Info', 'Ошибка')
Exit
EndIf
If Not $aSearch[0] Then
MsgBox(0, ' Info', 'Не найдены файлы конфигурации')
Exit
EndIf
For $i = 1 To $aSearch[0]
$vRead = FileRead($aSearch[$i]) ;Считываем
$vOpen = FileOpen($aSearch[$i], 2) ;Открываем
$vReplace = StringRegExpReplace($vRead, $vReplace_1, $vText_Server_1) ;Изменяем
FileWrite($vOpen, $vReplace) ;Переписываем
FileClose($vOpen) ;Закрываем
Next
Sleep (10)
GUICtrlSetStyle($vButton_Server_2, 0, -1)
GUICtrlSetStyle($vButton_Server_3, 0, -1)
GUICtrlSetStyle($vButton_Server_4, 0, -1)
GUICtrlSetStyle($vButton_Server_5, 0, -1)
Sleep (10)
GUICtrlSetBkColor($vButton_Server_1, 0xCCFFCC)
Case $vButton_Server_2
$sFiles = ''
For $i = 1 To $aCheckBox[0][0]
If BitAND(GUICtrlRead($aCheckBox[$i][1]), $GUI_CHECKED) Then
$sFiles &= $aCheckBox[$i][0] & '|'
EndIf
Next
If Not $sFiles Then
MsgBox(0, ' Info', 'Выберите программу', 0, $hForm)
ContinueLoop
EndIf
$sFiles = StringTrimRight($sFiles, 1)
$aSearch = _FileSearch('C:', $sFiles, 1)
If @error Then
MsgBox(16, ' Info', 'Ошибка')
Exit
EndIf
If Not $aSearch[0] Then
MsgBox(0, ' Info', 'Не найдены файлы конфигурации')
Exit
EndIf
For $i = 1 To $aSearch[0]
$vRead = FileRead($aSearch[$i]) ;Считываем
$vOpen = FileOpen($aSearch[$i], 2) ;Открываем
$vReplace = StringRegExpReplace($vRead, $vReplace_2, $vText_Server_2) ;Изменяем
FileWrite($vOpen, $vReplace) ;Переписываем
FileClose($vOpen) ;Закрываем
Next
Sleep (10)
GUICtrlSetStyle($vButton_Server_1, 0, -1)
GUICtrlSetStyle($vButton_Server_3, 0, -1)
GUICtrlSetStyle($vButton_Server_4, 0, -1)
GUICtrlSetStyle($vButton_Server_5, 0, -1)
Sleep (10)
GUICtrlSetBkColor($vButton_Server_2, 0xCCFFCC)
Case $vButton_Server_3
$sFiles = ''
For $i = 1 To $aCheckBox[0][0]
If BitAND(GUICtrlRead($aCheckBox[$i][1]), $GUI_CHECKED) Then
$sFiles &= $aCheckBox[$i][0] & '|'
EndIf
Next
If Not $sFiles Then
MsgBox(0, ' Info', 'Выберите программу', 0, $hForm)
ContinueLoop
EndIf
$sFiles = StringTrimRight($sFiles, 1)
$aSearch = _FileSearch('C:', $sFiles, 1)
If @error Then
MsgBox(16, ' Info', 'Ошибка')
Exit
EndIf
If Not $aSearch[0] Then
MsgBox(0, ' Info', 'Не найдены файлы конфигурации')
Exit
EndIf
For $i = 1 To $aSearch[0]
$vRead = FileRead($aSearch[$i]) ;Считываем
$vOpen = FileOpen($aSearch[$i], 2) ;Открываем
$vReplace = StringRegExpReplace($vRead, $vReplace_3, $vText_Server_3) ;Изменяем
FileWrite($vOpen, $vReplace) ;Переписываем
FileClose($vOpen) ;Закрываем
Next
Sleep (10)
GUICtrlSetStyle($vButton_Server_1, 0, -1)
GUICtrlSetStyle($vButton_Server_2, 0, -1)
GUICtrlSetStyle($vButton_Server_4, 0, -1)
GUICtrlSetStyle($vButton_Server_5, 0, -1)
Sleep (10)
GUICtrlSetBkColor($vButton_Server_3, 0xCCFFCC)
Case $vButton_Server_4
$sFiles = ''
For $i = 1 To $aCheckBox[0][0]
If BitAND(GUICtrlRead($aCheckBox[$i][1]), $GUI_CHECKED) Then
$sFiles &= $aCheckBox[$i][0] & '|'
EndIf
Next
If Not $sFiles Then
MsgBox(0, ' Info', 'Выберите программу', 0, $hForm)
ContinueLoop
EndIf
$sFiles = StringTrimRight($sFiles, 1)
$aSearch = _FileSearch('C:', $sFiles, 1)
If @error Then
MsgBox(16, ' Info', 'Ошибка')
Exit
EndIf
If Not $aSearch[0] Then
MsgBox(0, ' Info', 'Не найдены файлы конфигурации')
Exit
EndIf
For $i = 1 To $aSearch[0]
$vRead = FileRead($aSearch[$i]) ;Считываем
$vOpen = FileOpen($aSearch[$i], 2) ;Открываем
$vReplace = StringRegExpReplace($vRead, $vReplace_4, $vText_Server_4) ;Изменяем
FileWrite($vOpen, $vReplace) ;Переписываем
FileClose($vOpen) ;Закрываем
Next
Sleep (10)
GUICtrlSetStyle($vButton_Server_1, 0, -1)
GUICtrlSetStyle($vButton_Server_2, 0, -1)
GUICtrlSetStyle($vButton_Server_3, 0, -1)
GUICtrlSetStyle($vButton_Server_5, 0, -1)
Sleep (10)
GUICtrlSetBkColor($vButton_Server_4, 0xCCFFCC)
Case $vButton_Server_5
$sFiles = ''
For $i = 1 To $aCheckBox[0][0]
If BitAND(GUICtrlRead($aCheckBox[$i][1]), $GUI_CHECKED) Then
$sFiles &= $aCheckBox[$i][0] & '|'
EndIf
Next
If Not $sFiles Then
MsgBox(0, ' Info', 'Выберите программу', 0, $hForm)
ContinueLoop
EndIf
$sFiles = StringTrimRight($sFiles, 1)
$aSearch = _FileSearch('C:', $sFiles, 1)
If @error Then
MsgBox(16, ' Info', 'Ошибка')
Exit
EndIf
If Not $aSearch[0] Then
MsgBox(0, ' Info', 'Не найдены файлы конфигурации')
Exit
EndIf
For $i = 1 To $aSearch[0]
$vRead = FileRead($aSearch[$i]) ;Считываем
$vOpen = FileOpen($aSearch[$i], 2) ;Открываем
$vReplace = StringRegExpReplace($vRead, $vReplace_5, $vText_Server_5) ;Изменяем
FileWrite($vOpen, $vReplace) ;Переписываем
FileClose($vOpen) ;Закрываем
Next
Sleep (10)
GUICtrlSetStyle($vButton_Server_1, 0, -1)
GUICtrlSetStyle($vButton_Server_2, 0, -1)
GUICtrlSetStyle($vButton_Server_3, 0, -1)
GUICtrlSetStyle($vButton_Server_4, 0, -1)
Sleep (10)
GUICtrlSetBkColor($vButton_Server_5, 0xCCFFCC)
EndSwitch
WEnd
Func _FileSearch($s_Path_Search, $s_File_Mask = '*', $i_Flag = 0, $i_SubDir = 1)
Local $s_Out, $a_Out, $s_Read, $h_Dir, $s_Attrib, $s_Subdir, $s_Parameter, $a_Masks
If StringRight($s_Path_Search, 1) == '\' Then
$s_Path_Search = StringTrimRight($s_Path_Search, 1)
EndIf
$a_Masks = StringSplit($s_File_Mask, '|')
For $i = 1 To $a_Masks[0]
$s_Parameter &= '"' & $s_Path_Search & '\' & $a_Masks[$i] & '";'
Next
$s_Parameter = StringTrimRight($s_Parameter, 1)
If $i_SubDir Then
$s_Subdir = ' /S /B'
Else
$s_Subdir = ' /B'
EndIf
Switch $i_Flag
Case 1
$s_Attrib = ' /A-D'
Case 2
$s_Attrib = ' /AD'
Case Else
$s_Attrib = ' /A'
EndSwitch
$s_Parameter &= $s_Subdir & $s_Attrib
$s_Out = StringToBinary('0' & @CRLF, 2)
$h_Dir = Run(@ComSpec & ' /U /C DIR ' & $s_Parameter, @SystemDir, @SW_HIDE, 6)
If Not $h_Dir Then Return SetError(1)
While 1
$s_Read = StdoutRead($h_Dir, False, True)
If @error Then
ExitLoop
EndIf
If $s_Read Then
$s_Out &= $s_Read
EndIf
Sleep(10)
WEnd
$a_Out = StringRegExp(BinaryToString($s_Out, 2), '[^\r\n]+', 3)
If @error Then Return SetError(1)
$a_Out[0] = UBound($a_Out) - 1
Return $a_Out
EndFunc ;==>_FileSearch