找回密码
 加入
搜索
查看: 4211|回复: 9

[网络通信] [已解决]Inetget下载文件假死情况

  [复制链接]
发表于 2010-7-7 13:46:37 | 显示全部楼层 |阅读模式
本帖最后由 Evol 于 2010-7-7 16:45 编辑

;代码如下
;$remoteAdr定义了远程文件地址
;$LocalAdr定义了本地保存的地址
;$FileName定义了下载的文件名
;$DFsize定义了获得下载文件的大小
;$ErrD定义了函数返回值,0为下载成功,1为下载失败
Func DLFile($remoteAdr="",$LocalAdr="",$FileName="",$DFSize=0) ;0成功,1失败
        $Open_Update_File=InetGet($remoteAdr, $LocalAdr,1,1)
        $ErrD=0
        Do
                If InetGetInfo($Open_Update_File, 4)<>0 Then
                        $ErrD=1
                        ExitLoop
                EndIf
                ToolTip("正在下载更新列表:" & inetGetInfo($Open_Update_File, 0) & "/" & $DFSize,0,0,$FileName,1,1)
        Until InetGetInfo($Open_Update_File, 2)
        InetClose($Open_Update_File)
        Return $ErrD
EndFunc

问题:用TOOLTIP来显示下载进度,但实际运行中发现,inetGetInfo($Open_Update_File, 0)即已下载大小并非立即变动的,有时几乎不动,就开始下载下一个文件,请问如何解决这个问题呢!?
发表于 2010-7-7 14:10:17 | 显示全部楼层
在循环中加入 Sleep(1) 试试
 楼主| 发表于 2010-7-7 14:14:32 | 显示全部楼层
不成啊。。。试过了。毫无改变。
发表于 2010-7-7 14:26:47 | 显示全部楼层
你测试的下载文件地址是?
发表于 2010-7-7 14:44:25 | 显示全部楼层
;;;;;;;;;;;;;;;检测文件大小呢?

$s = "http://dl_dir.qq.com/qqfile/qq/QQ2010/QQ2010.exe"
$a = InetGetSize($s)
InetGet($s, "QQ2010.exe",0,1)

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)

$Form1 = GUICreate("下载文件", 534, 258, -1, -1)
$Progress1 = GUICtrlCreateProgress(56, 56, 425, 25)
$Label1 = GUICtrlCreateLabel("来自:" & StringLeft($s,StringInStr($s, "/", 0, 3)-1), 56, 32, 300, 17)
$Label2 = GUICtrlCreateLabel("估计剩余时间:", 88, 96, 200, 17)
$Label3 = GUICtrlCreateLabel("下载到:QQ2010.exe", 88, 120, 200, 17)
$Label4 = GUICtrlCreateLabel("传输速度:", 88, 144, 200, 17)

$Button1 = GUICtrlCreateButton("打开文件", 72, 200, 113, 33)
$Button2 = GUICtrlCreateButton("打开文件夹", 220, 200, 113, 33)
$Button3 = GUICtrlCreateButton("取消", 365, 199, 113, 33)
GUICtrlSetOnEvent($Button3, "quit")
GUISetOnEvent($GUI_EVENT_CLOSE, "quit")


GUISetState(@SW_SHOW)
$d = 0
While 1
$b = FileGetSize("QQ2010.exe")
$c = $b / $a
$c = $c * 100
GUICtrlSetData($Progress1,$c)
$c = StringLeft($c, 2)
if StringLeft($c, 1) = 0 then $c = "0"
$c = StringReplace($c, ".", "")
WinSetTitle($Form1, "", "下载文件" & $c & "%")
$d = $b - $d
if $d <> 0 then
if $d > 1024 then
$d = $d / 1024 & "KB"
else
$d = $d & "Byte"
endif
ControlSetText($Form1, "", $Label4, "传输速度:" & $d)
endif
$d = FileGetSize("QQ2010.exe")
sleep(500)
WEnd

Func quit()
exit
EndFunc
 楼主| 发表于 2010-7-7 14:44:38 | 显示全部楼层
嗯,我刚刚测试了下,如果下载较大的文件,即下载时间较长时,它又会显示。好难搞啊。。。
下载地址如下:www.gsjczx.com/evol/pla/pla.exe
发表于 2010-7-7 14:58:24 | 显示全部楼层
回复 6# Evol


    我这测试完全正常哦
 楼主| 发表于 2010-7-7 15:00:39 | 显示全部楼层
回复  Evol


    我这测试完全正常哦
afan 发表于 2010-7-7 14:58



  嗯,估计是我这系统和网络的问题吧。我个人感觉写的代码也没多大问题。谢谢!
 楼主| 发表于 2010-7-7 15:03:53 | 显示全部楼层
;;;;;;;;;;;;;;;检测文件大小呢?

$s = "http://dl_dir.qq.com/qqfile/qq/QQ2010/QQ2010.exe"
$a = Inet ...
xsjtxy 发表于 2010-7-7 14:44

谢谢~我不用界面显示,还是谢了!我想知道Opt("GUIOnEventMode", 1)这句话,是说让窗体同时响应其他事件。面向过程的编程时,有没有相同功能的语句呢?
发表于 2010-7-7 15:04:18 | 显示全部楼层
回复 8# Evol


    嗯,只是记得加入sleep,不然下载期间cpu占用会居高不下~
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-2 20:15 , Processed in 0.074181 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表