本帖最后由 maxkingmax 于 2010-10-26 21:01 编辑
做了个自动上传种子到家用BT机的小程序,在WIN XP 下测试正常,但是在Win7 下无法正常工作
具体表现在:
出现上传进度窗口后,停止响应!
不知道是不是 Win7下的 FTPex.au3 兼容性的问题
#include <FTPEx.au3>
#include <file.au3>
#include <Constants.au3>
#include <array.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Dim $Form1,$Progress1 ,$Progress2 ,$Label1 ,$Label2 ,$currentfile,$currentnum,$totalnum
Dim $path = "D:\btpeer"
Dim $address = "myftp.com",$tcpip,$notip
gettcpip() ;测试是否是局域网
func gettcpip()
TraySetToolTip("正在查找服务器位置...")
;~ $a = 0
$ping1 = Ping("192.168.1.111")
$ping2 = Ping("192.168.1.10")
$ping3 = Ping($address)
;~ ConsoleWrite($ping1&" "&$ping2&" "&$ping3)
Select
Case $ping1 = 0 And $ping2 = 0 And $ping3 > 0
TCPStartup()
$tcpip = TCPNameToIP($address)
TCPShutdown()
TraySetToolTip("已经获取到服务器 IP:"&$tcpip)
Case $ping1 > 0 And ($ping2 = 0 Or $ping2 > 0) And ($ping3 > 0 Or $ping3 = 0)
$address = "192.168.1.111"
$tcpip = $address
TraySetToolTip("已经获取到服务器 IP:"&$tcpip)
Case ($ping1 > 0 Or $ping1 = 0) And $ping2 > 0 And ($ping3 > 0 Or $ping3 = 0)
$address = "192.168.1.10"
$tcpip = $address
TraySetToolTip("已经获取到服务器 IP:"&$tcpip)
Case $ping1 = 0 And $ping2 = 0 And $ping3 = 0
$tcpip = ""
;~ If $a = 0 Then
TrayTip("无法获取服务器位置", "可能是服务器未开,或网络连接不正常!", 2)
;~ $a = $a + 1
;~ EndIf
TraySetToolTip("无法获取服务器位置,可能是服务器未开,或网络连接不正常!")
EndSelect
EndFunc ;==>gettcpip
;;程序主体
While 1
If FileExists($path & "\*.torrent") Then
$file = _FileListToArray($path, "*.torrent", 1)
If IsArray($file) Then
$session = _FTP_Open("myftp")
$myftp = _FTP_Connect($session, $tcpip, "anonymous", "")
If @error = -1 Then
If $notip = 1 Then
TrayTip("无法连接", "无法连接到远程 FTP Server,请检查网络连接或联系 FTP Server", 3)
$notip = 0
EndIf
Sleep(3000)
ContinueLoop
EndIf
$notip = 1
gui()
For $i = 1 To $file[0] ;这段循环用于测试种子是否下载完毕,防止上传的种子因为未下载完全就上传,导致BT任务失败!
Do
$size = FileGetSize($path & "\" & $file[$i])
Sleep(500)
$size2 = FileGetSize($path & "\" & $file[$i])
Sleep(500)
$size3 = FileGetSize($path & "\" & $file[$i])
Sleep(500)
If $size3=0 And $size3=$size Then
ExitLoop
EndIf
Until $size2 = $size And $size3 = $size And $size3 = $size2 And $size > 1024 * 5
;~ TrayTip("正在传送" & $filelist[$i], "文件大小: " & Round($size3 / 1024,2) & " KB", 2)
$currentfile=$file[$i]
$currentnum=$i
$totalnum=$file[0]
;~ _FTP_fileput($myftp, $path & "\" & $filelist[$i], $filelist[$i])
_FTP_ProgressUpload($myftp, $path & "\" & $file[$i], $file[$i],'uppress')
;~ TrayTip("进度: " & $i & "/" & $file[0], $file[$i] & "已经传送完毕!", 2)
;~ GUICtrlSetData($Progress2, 100*($i/$file[0]))
;~ _TCP_Client_Send(String($size3))
Sleep(2100)
Next
GUIDelete($form1)
_FTP_Close($session)
;~ For $i = 1 To $file[0]
;~ FileDelete($path & "\" & $file[$i])
;~ Next
EndIf
EndIf
WEnd
Func gui() ;创建上传进度窗口
$Form1 = GUICreate("", 330, 110, @DesktopWidth-330, @DesktopHeight-110-taskbarh(), BitOR($WS_MINIMIZEBOX,$WS_DLGFRAME,$WS_POPUP,$WS_GROUP,$WS_CLIPSIBLINGS), BitOR($WS_EX_TOOLWINDOW,$WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
$Progress1 = GUICtrlCreateProgress(8, 24, 313, 25,$PBS_SMOOTH)
$Progress2 = GUICtrlCreateProgress(8, 74, 313, 25,$PBS_SMOOTH)
$Label1 = GUICtrlCreateLabel("当前文件:", 8, 4, 315, 17)
$Label2 = GUICtrlCreateLabel("总进度:", 8, 56, 311, 17)
GUISetState(@SW_SHOW)
EndFunc
func taskbarh() ;获取任务栏高度
$pos = WinGetPos("[class:Shell_TrayWnd]")
if isarray($pos) Then
return $pos[3]
else
return 0
EndIf
EndFunc
Func uppress($Percentage) ;进度条控制
GUICtrlSetData($Progress1,$Percentage)
GUICtrlSetData($Progress2,1/$totalnum*$Percentage+($currentnum-1)/$totalnum*100)
GUICtrlSetData($Label2,"总进度: "&$currentnum&"/"&$totalnum&' ('&Int(1/$totalnum*$Percentage+($currentnum-1)/$totalnum*100)&'%)')
GUICtrlSetData($Label1,"当前文件: "&StringTrimLeft($currentfile, StringInStr($currentfile, "\", 0, -1))& ' ('&$Percentage&'%)')
Return 1
EndFunc
|