Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GUIConstantsEx.au3>
- #include <GuiTreeView.au3>
- #include <WindowsConstants.au3>
- #include <GuiImageList.au3>
- #Include <File.au3>
- #include <GuiListView.au3>
- #Include <Array.au3> ; тест
- #include <FTPEx.au3>
- Opt("GUIOnEventMode", 1)
- Global $PathCur, $TrWM_NOTIFY=0, $OpenFTPCon, $FileGet
- Global $Address0, $server, $username, $pass
- ; установка входящих параметров
- ; !i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i
- $Gui1 = GUICreate('', 120, 200)
- GUISetOnEvent(-3, "_Exit1")
- Global $inpSet[5]
- GUICtrlCreateLabel('сервер', 10, 13, 300, 17)
- $inpSet[0]=GUICtrlCreateCombo('', 10, 30, 100, 23)
- GUICtrlSetData(-1,'192.168.45.38|192.168.48.36', '192.168.45.38')
- GUICtrlCreateLabel('Пользователь', 10, 63, 300, 17)
- $inpSet[1]=GUICtrlCreateInput('anonymous', 10, 80, 100, 20)
- GUICtrlCreateLabel('Пароль', 10, 113, 300, 17)
- $inpSet[2]=GUICtrlCreateInput('ru@mail.ru', 10, 130, 100, 20)
- GUICtrlCreateButton('OK', 25, 160, 70, 25)
- GUICtrlSetOnEvent(-1, "_OK")
- GUISetState(@SW_SHOW, $Gui1)
- $ex = 0
- While 1
- Sleep(100)
- If $ex = 1 Then
- GUIDelete($Gui1)
- ExitLoop
- EndIf
- WEnd
- Func _OK()
- $Address0 =GUICtrlRead($inpSet[0])
- $server = $Address0
- $username =GUICtrlRead($inpSet[1])
- $pass =GUICtrlRead($inpSet[2])
- $ex =1
- EndFunc
- Func _Exit1()
- Exit
- EndFunc
- ; !i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i!i
- $Gui=GUICreate('Файловый менеджер', 640, 560)
- GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
- $StatusBar = GUICtrlCreateLabel('', 5, 560-18, 640-10, 17)
- $restart = GUICtrlCreateButton("R", 640-20, 2, 18, 20)
- ; GUICtrlSetResizing(-1, 512 + 256 + 32 + 4)
- GUICtrlSetOnEvent(-1, "_restart")
- $TreeView = GUICtrlCreateTreeView(0, 35, 216, 500)
- ; GUICtrlSetResizing(-1, 2 + 4 + 32 + 64)
- $hTreeView = GUICtrlGetHandle($TreeView)
- $hImage = _GUIImageList_Create(16, 16, 5)
- _GUIImageList_AddIcon($hImage, @SystemDir&'\shell32.dll', -4)
- _GUIImageList_AddIcon($hImage, @SystemDir&'\shell32.dll', -5)
- _GUIImageList_AddIcon($hImage, @SystemDir&'\shell32.dll', 0)
- _GUICtrlTreeView_SetNormalImageList($hTreeView, $hImage)
- $E=''
- $i=1
- While 1
- $i+=1
- $sExt = RegEnumKey("HKCR", $i)
- If @error Or StringLeft($sExt, 1)<>'.' then ExitLoop
- $ico1=_FileDefaultIcon($sExt)
- If Not @error Then
- Switch UBound($ico1)
- Case 2
- If StringInStr(';.exe;.scr;.ico;.ani;.cur;', ';'&$sExt&';') Then
- ContinueLoop
- Else
- _GUIImageList_AddIcon($hImage, $ico1[1], 0)
- If @error Then ContinueLoop
- EndIf
- Case 3
- _GUIImageList_AddIcon($hImage, $ico1[1], $ico1[2])
- If @error Then ContinueLoop
- EndSwitch
- $E&='|'&$sExt
- EndIf
- WEnd
- $E=StringTrimLeft($E, 1)
- $aE=StringSplit($E, '|')
- $OpenFTPCon = _FTP_Open('MyFTP_Connect')
- If @error Then
- MsgBox(0, 'Ошибка', 'Ошибка сессии')
- Exit
- EndIf
- $Conn = _FTP_Connect($OpenFTPCon, $server, $username, $pass)
- If @error Then
- MsgBox(0, 'Ошибка', 'Ошибка подключения')
- Exit
- EndIf
- $FolderArr =_FTP_ListToArray($Conn, 1)
- If Not IsArray($FolderArr) Or $FolderArr[0] = 0 Or ($FolderArr[0] = 2 And $FolderArr[1] = "." And $FolderArr[2] = "..") Then
- MsgBox(0, 'Ошибка', 'Отсутствуют каталоги')
- Exit
- EndIf
- For $i = 1 to $FolderArr[0]
- If StringInStr("..", $FolderArr[$i]) Then ContinueLoop
- $hTmp = _GUICtrlTreeView_Add($hTreeView, 0, $FolderArr[$i], 0, 0)
- _FTP_DirSetCurrent($Conn, "/"& $FolderArr[$i] & "/")
- $tmp=_FTP_ListToArray($Conn, 1)
- If Not IsArray($tmp) Or $tmp[0] = 0 Or ($tmp[0] = 2 And $tmp[1] = "." And $tmp[2] = "..") Then ContinueLoop
- For $j = 1 to $tmp[0]
- If StringInStr("..", $tmp[$j]) Then ContinueLoop
- _GUICtrlTreeView_AddChild($hTreeView, $hTmp, $tmp[$j], 0, 0)
- Next
- Next
- $ListView = GUICtrlCreateListView(' ', 220, 35, 420, 500, $LVS_NOCOLUMNHEADER +$LVS_SHOWSELALWAYS, $LVS_OWNERDRAWFIXED)
- GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
- GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_TRACKSELECT, $LVS_EX_TRACKSELECT)
- GUICtrlSetBkColor(-1, 0xf0f0f0) ; 0xE0DFE3
- $hListView = GUICtrlGetHandle($ListView)
- _GUICtrlListView_SetColumnWidth($ListView, 0, 390)
- _GUICtrlListView_SetImageList($hListView, $hImage, 1)
- GUISetState ()
- GUIRegisterMsg(0x004E, 'WM_NOTIFY')
- ; создаём список в ListView корневого каталога
- _GUICtrlListView_BeginUpdate($hListView)
- _GUICtrlListView_DeleteAllItems($hListView)
- For $i = 1 to $FolderArr[0]
- If StringInStr("..", $FolderArr[$i]) Then ContinueLoop
- _GUICtrlListView_AddItem($hListView, $FolderArr[$i], 0)
- Next
- $tmp=_FTP_ListToArray($Conn, 2) ; файлы
- If Not @error And IsArray($tmp) Then
- For $i = 1 to $tmp[0]
- $tmp3=StringRegExpReplace($tmp[$i], '.*(\.\S+)', '\1')
- $ind=_ArraySearch($aE, $tmp3)
- If @error Then $ind=0
- _GUICtrlListView_AddItem($hListView, $tmp[$i], $ind+2)
- Next
- EndIf
- _GUICtrlListView_EndUpdate($hListView)
- While 1
- Sleep(100000)
- WEnd
- Func _Exit()
- $Ftpc = _FTP_Close($OpenFTPCon)
- Exit
- EndFunc
- Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
- Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $tmp, $TrWM_NOTIFY=1
- $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
- $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
- $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
- $iCode = DllStructGetData($tNMHDR, "Code")
- Switch $hWndFrom
- Case $hTreeView
- Switch $iCode
- Case $NM_CLICK
- ; получение хэндла кликнутого пункта и поиск его в массиве
- Local $tMPos = _WinAPI_GetMousePos(True, $hWndFrom), $tHit = _GUICtrlTreeView_HitTestEx($hWndFrom, DllStructGetData($tMPos, 1), DllStructGetData($tMPos, 2))
- Local $hItem = DllStructGetData($tHit, "Item")
- If $hItem <> -1 And $hItem<>0x0 Then
- $tmp=_GetPathItem($hWndFrom, $hItem)
- If $PathCur=$tmp Then
- Return
- Else
- $PathCur=$tmp
- EndIf
- GUICtrlSetData($StatusBar, $PathCur)
- ; GUICtrlSetData($Address, $PathCur)
- _GUICtrlListView_BeginUpdate($hListView)
- _GUICtrlListView_DeleteAllItems($hListView)
- _FTP_DirSetCurrent($Conn, "/"& $PathCur & "/")
- $tmp=_FTP_ListToArray($Conn, 1) ; папки
- If Not @error And IsArray($tmp) Then
- For $i = 1 to $tmp[0]
- If StringInStr("..", $tmp[$i]) Then ContinueLoop
- _GUICtrlListView_AddItem($hListView, $tmp[$i], 0)
- Next
- EndIf
- $tmp=_FTP_ListToArray($Conn, 2) ; файлы
- If Not @error And IsArray($tmp) Then
- For $i = 1 to $tmp[0]
- $tmp3=StringRegExpReplace($tmp[$i], '.*(\.\S+)', '\1')
- $ind=_ArraySearch($aE, $tmp3)
- If @error Then $ind=0
- _GUICtrlListView_AddItem($hListView, $tmp[$i], $ind+2)
- Next
- EndIf
- _GUICtrlListView_EndUpdate($hListView)
- $KolChild=_GUICtrlTreeView_GetChildCount($hWndFrom, $hItem)
- If $KolChild<=0 Then Return
- $h=_GUICtrlTreeView_GetFirstChild($hWndFrom, $hItem)
- $KolH=_GUICtrlTreeView_GetChildCount($hWndFrom, $h)
- If $KolH>0 Then Return
- _CreateItem($hWndFrom, $h, $PathCur)
- For $i = 1 to $KolChild-1
- $h=_GUICtrlTreeView_GetNextChild($hWndFrom, $h)
- $KolH=_GUICtrlTreeView_GetChildCount($hWndFrom, $h)
- If $KolH>0 Then Return
- _CreateItem($hWndFrom, $h, $PathCur)
- Next
- Else
- Return
- EndIf
- Case $NM_RCLICK
- Local $tMPos = _WinAPI_GetMousePos(True, $hWndFrom), $tHit = _GUICtrlTreeView_HitTestEx($hWndFrom, DllStructGetData($tMPos, 1), DllStructGetData($tMPos, 2))
- Local $hItem = DllStructGetData($tHit, "Item")
- If $hItem <> -1 And $hItem<>0x0 Then
- Else
- Return
- EndIf
- EndSwitch
- Case $hListView
- Switch $iCode
- Case $NM_DBLCLK
- $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
- $iItem = DllStructGetData($tInfo, 'Index')
- If $iItem > -1 Then
- $FileGet = $PathCur&'/'&_GUICtrlListView_GetItemText($hListView, $iItem)
- AdlibRegister('_FileGet', 40)
- EndIf
- EndSwitch
- EndSwitch
- $TrWM_NOTIFY=0
- Return $GUI_RUNDEFMSG
- EndFunc
- Func _FileGet()
- AdlibUnRegister('_FileGet')
- $SaveFile = FileSaveDialog('Сохранить как ...', @DesktopDir , 'Все (*.*)', 18, StringRegExpReplace($FileGet, '(^.*)/(.*)$', '\2'), $Gui)
- If @error Then Return
- If _FTP_FileGet($Conn, "/"& $FileGet, $SaveFile) Then
- MsgBox(0, 'Message', 'Готово')
- Else
- MsgBox(0, 'Ошибка', 'Скачивайте файл а не каталог')
- EndIf
- EndFunc
- Func _CreateItem($hWndFrom, $h, $Path)
- Local $text=_GUICtrlTreeView_GetText($hWndFrom, $h)
- _FTP_DirSetCurrent($Conn, "/"& $Path &'/'& $text & "/")
- Local $tmp=_FTP_ListToArray($Conn, 1)
- If @error Or Not IsArray($tmp) Then Return
- For $i = 1 to $tmp[0]
- If $tmp[$i] = "." Or $tmp[$i] = ".." Then ContinueLoop
- _GUICtrlTreeView_AddChild($hTreeView, $h, $tmp[$i], 0, 0)
- Next
- EndFunc
- Func _GetPathItem($hWndFrom, $hItem)
- Local $Path=_GUICtrlTreeView_GetText($hWndFrom, $hItem), $text, $Path
- While 1
- $hItem=_GUICtrlTreeView_GetParentHandle($hWndFrom, $hItem)
- If $hItem = 0 Then ExitLoop
- $text=_GUICtrlTreeView_GetText($hWndFrom, $hItem)
- $Path=$text &'/'& $Path
- WEnd
- Return $Path
- EndFunc
- Func _restart()
- $Ftpc = _FTP_Close($OpenFTPCon)
- Local $sAutoIt_File = @TempDir & "\~Au3_ScriptRestart_TempFile.au3"
- Local $sRunLine, $sScript_Content, $hFile
- $sRunLine = @ScriptFullPath
- If Not @Compiled Then $sRunLine = @AutoItExe & ' /AutoIt3ExecuteScript ""' & $sRunLine & '""'
- If $CmdLine[0] > 0 Then $sRunLine &= ' ' & $CmdLineRaw
- $sScript_Content &= '#NoTrayIcon' & @CRLF & _
- 'While ProcessExists(' & @AutoItPID & ')' & @CRLF & _
- ' Sleep(10)' & @CRLF & _
- 'WEnd' & @CRLF & _
- 'Run("' & $sRunLine & '")' & @CRLF & _
- 'FileDelete(@ScriptFullPath)' & @CRLF
- $hFile = FileOpen($sAutoIt_File, 2)
- FileWrite($hFile, $sScript_Content)
- FileClose($hFile)
- Run(@AutoItExe & ' /AutoIt3ExecuteScript "' & $sAutoIt_File & '"', @ScriptDir, @SW_HIDE)
- Sleep(1000)
- Exit
- EndFunc ;==>_restart
- Func _FileDefaultIcon($sExt)
- If $sExt = '' Or StringInStr($sExt, ':') Then Return SetError(1)
- Local $aCall = DllCall("shlwapi.dll", "int", "AssocQueryStringW", _
- "dword", 0x00000040, _ ;$ASSOCF_VERIFY
- "dword", 15, _ ;$ASSOCSTR_DEFAULTICON
- "wstr", $sExt, _
- "ptr", 0, _
- "wstr", "", _
- "dword*", 65536)
- If @error Then Return SetError(1, 0, "")
- If Not $aCall[0] Then
- $sExt=StringReplace($aCall[5], '"', '')
- $sExt=StringSplit($sExt, ',')
- Opt('ExpandEnvStrings', 1)
- $sExt[1]=$sExt[1]
- Opt('ExpandEnvStrings', 0)
- Return SetError(0, 0, $sExt)
- ElseIf $aCall[0] = 0x80070002 Then
- Return SetError(1, 0, "{unknown}")
- ElseIf $aCall[0] = 0x80004005 Then
- Return SetError(1, 0, "{fail}")
- Else
- Return SetError(2, $aCall[0], "")
- EndIf
- EndFunc ;==>_FileAssociation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement