#include <GuiListView.au3>
#include <GuiButton.au3>
#include <Misc.au3>
Global $hWnd, $hLVCntrl, $hButtOK
Global $sINIFile = @ScriptDir & '\uTFilter.ini'
Global $sTitle = '[CLASS:#32770;REGEXPTITLE:(Добав([А-яЁё]|\h)+?торр?ент)|(Add New Torrent)]'
Global $sLVCntrl = '[CLASS:SysListView32; INSTANCE:1]'
Global $sButtOK = '[CLASS:Button; ID:20]'
Global $Process = 'utorrent.exe'
Global $asINIParam = IniReadSection($sINIFile, 'Filter')
If @error Then Exit MsgBox(16, 'ОШИБКА!', 'Ошибка чтения "uTFilter.ini"!')
If $asINIParam[0][0] < 6 Then Exit MsgBox(16, 'ОШИБКА!', '"uTFilter.ini" имеет НЕ полный набор параметров!')
If $asINIParam[3][0] = 'CBStateSwitch' And $asINIParam[3][1] Then
HotKeySet(_KeyCombination(), '_CBStateSwitch')
$asINIParam[3][0] = True
EndIf
If Not $asINIParam[6][0] = 'FocusWindowID' And Not $asINIParam[6][1] Then $asINIParam[5][0] = ''
While ProcessExists($Process)
$hWnd = WinActivate($sTitle)
If $hWnd Then
$hTimer = TimerInit()
If $asINIParam[4][0] = 'Transparency' And $asINIParam[4][1] Then WinSetTrans($hWnd, '', $asINIParam[4][1])
$hLVCntrl = ControlGetHandle($hWnd, '', $sLVCntrl)
$iCount = ControlListView($hWnd, '', $hLVCntrl, 'GetItemCount') - 1
Dim $aLVItems[$iCount + 1]
_GUICtrlListView_BeginUpdate($hLVCntrl)
If $asINIParam[2][0] = 'CBState' And $asINIParam[2][1] == 0 Then _GUICtrlListView_SetItemChecked($hLVCntrl, -1, False)
For $i = $iCount To 0 Step -1
$sText = ControlListView($hWnd, '', $hLVCntrl, 'GetText', $i, 0)
If StringRegExp($sText, '\.(?i:' & $asINIParam[1][1] & ')$') Then
$aLVItems[$i] = ''
_GUICtrlListView_DeleteItem($hLVCntrl, $i)
Else
$aLVItems[$i] = $sText
EndIf
Next
_GUICtrlListView_SetColumnWidth($hLVCntrl, 0, $LVSCW_AUTOSIZE)
_GUICtrlListView_EndUpdate($hLVCntrl)
$hButtOK = ControlGetHandle($hWnd, '', $sButtOK)
If Not _MyButton() Then ContinueLoop
For $i = 0 To $iCount
If $aLVItems[$i] Then
$iIndex = ControlListView($hWnd, '', $hLVCntrl, 'FindItem', $aLVItems[$i])
If Not _GUICtrlListView_GetItemChecked($hLVCntrl, $iIndex) Then $aLVItems[$i] = ''
EndIf
Next
_GUICtrlListView_BeginUpdate($hLVCntrl)
_GUICtrlListView_DeleteAllItems($hLVCntrl)
For $i = 0 To $iCount
_GUICtrlListView_AddItem($hLVCntrl, $aLVItems[$i])
If $aLVItems[$i] Then _GUICtrlListView_SetItemChecked($hLVCntrl, $i)
Next
ControlFocus($hWnd, '', $hButtOK)
ControlClick($hWnd, '', $hButtOK)
If $asINIParam[5][0] = 'FocusReturn' And $asINIParam[5][1] == 0 Then WinActivate($asINIParam[6][1])
If Not WinWaitClose($hWnd, '', 3) Then WinClose($hWnd)
Else
Sleep(200)
EndIf
WEnd
Func _MyButton()
Local $aiPos, $sControl, $iPosPrevX, $iPosPrevY, $hButton, $aWndList
$aiPos = ControlGetPos($hWnd, '', $hButtOK)
$sControl = ControlGetFocus($hWnd)
If @error Then Return 0
$iPosPrevX = $aiPos[0]
$iPosPrevY = $aiPos[1]
$hButton = _GUICtrlButton_Create($hWnd, 'OK', $aiPos[0], $aiPos[1], $aiPos[2], $aiPos[3])
ControlHide($hWnd, '', $hButtOK)
ControlDisable($hWnd, '', $hButtOK)
ControlFocus($hWnd, '', $sControl)
While Sleep(10)
If Not WinExists($hWnd) Then Return 0
$aWndList = WinList($sTitle)
If $aWndList[0][0] > 1 Then
WinClose($aWndList[1][1])
WinActivate($hWnd)
EndIf
If _GUICtrlButton_GetState($hButton) = 0x0026C Then ExitLoop
If WinActive($hWnd) And _IsPressed('0D') Then ExitLoop
$aiPos = ControlGetPos($hWnd, '', $hButtOK)
If @error Then Return 0
If $iPosPrevX <> $aiPos[0] Or $iPosPrevY <> $aiPos[1] Then ControlMove($hWnd, '', $hButton, $aiPos[0], $aiPos[1])
WEnd
Return ControlEnable($hWnd, '', $hButtOK)
EndFunc ;==>_MyButton
Func _CBStateSwitch()
If WinActive($hWnd) Then
$asINIParam[3][0] = Not $asINIParam[3][0]
_GUICtrlListView_SetItemChecked($hLVCntrl, -1, $asINIParam[3][0])
Else
HotKeySet($asINIParam[3][1])
Send($asINIParam[3][1])
HotKeySet($asINIParam[3][1], '_CBStateSwitch')
EndIf
EndFunc ;==>_CBStateSwitch
Func _KeyCombination()
Local $sOutput
Local $asKeysValue[35][2] = [['}', '{}}'], ['{', '{{}'], ['Alt', '!'], ['Shift', '+'], ['Ctrl', '^'], ['Win|Windows', '#'], ['\!', '{!}'], ['\#', '{#}'], ['\+', '{+}'], _
['\^', '{^}'], ['SPACE|SpaceBar', '{SPACE}'], ['ENTER', '{ENTER}'], ['Backspace', '{BS}'], ['Delete|Del', '{DEL}'], ['UP', '{UP}'], ['DOWN', '{DOWN}'], _
['LEFT', '{LEFT}'], ['RIGHT', '{RIGHT}'], ['HOME', '{HOME}'], ['END', '{END}'], ['ESCAPE|ESC', '{ESC}'], ['INSERT|INS', '{INS}'], ['PageUp|PgUp', '{PGUP}'], _
['PageDown|PgDn', '{PGDN}'], ['F(\d{1,2})', '{F${1}}'], ['TAB', '{TAB}'], ['(Print Screen)|(Prt Scr SysRq)|Prtscr', '{PRINTSCREEN}'], ['LWIN', '{LWIN}'], _
['RWIN', '{RWIN}'], ['NumLock|(Num Lock)|(Num Lk)', '{NUMLOCK}'], ['CapsLock|(Caps Lock)|(Caps Lk)', '{CAPSLOCK}'], _
['ScrollLock|(Scroll Lock)|(Scroll Lk)', '{SCROLLLOCK}'], ['BREAK', '{BREAK}'], ['PAUSE', '{PAUSE}'], ['SLEEP', '{SLEEP}']]
$asKeys = StringSplit($asINIParam[3][1], '+')
$asINIParam[3][1] = ''
For $i = 1 To $asKeys[0]
For $ic = 0 To 34
$sOutput = StringRegExpReplace($asKeys[$i], '(?i)' & $asKeysValue[$ic][0], $asKeysValue[$ic][1])
If @extended Then
$asINIParam[3][1] &= $sOutput
$sOutput = ''
SetExtended(0)
ExitLoop
EndIf
Next
$asINIParam[3][1] &= $sOutput
Next
Return $asINIParam[3][1]
EndFunc ;==>_KeyCombination