我是采用文件大小对比来确定是否有更新的.代码如下;======================开始 "更新" 函数======================
Func SELFUPDATE()
$BD = "D:\PROGRAM FILES\TEST\YMTOOL.EXE"
$TEMP = "D:\PROGRAM FILES\TEST\YMTOOL.TMP"
$FWQ = "HTTP://L4EVER.CN/API/UPDATE/YMTOOL.EXE"
$NAME = "XXXXXXXXX"
TrayTip("<" & $NAME & ">", "请稍等,正在检查更新...", 2, 1)
$DOWNLOAD = $FWQ
$SIZE = InetGetSize($FWQ)
If @error Then
TrayTip("<" & $NAME & ">", "与更新服务器连接错误!检查更新失败!", 3, 3)
Else
If FileGetSize($BD) <> InetGetSize($FWQ) Then
MsgBox(64, "提示", "<" & $NAME & ">有更新" & @CRLF & "开始自动更新!", 10)
DirCreate("D:\PROGRAM FILES\YMNETWORK\TEMP\") ;创建本地文件夹,以便保存下载的文件
InetGet($DOWNLOAD, $TEMP, 1, 1)
While @InetGetActive
$SIZE = InetGetSize($DOWNLOAD)
$PER = @InetGetBytesRead / $SIZE * 100
$RES = StringLeft($PER, 4) ;计算百分值
$DOWNED = @InetGetBytesRead / 1024 / 1024
$DOWNRES = StringLeft($DOWNED, 3)
$DOWNNEED = $SIZE / 1024 / 1024
$DOWNALL = StringLeft($DOWNNEED, 3)
ToolTip("总大小/已下载:" & $DOWNALL & "MB/" & $DOWNRES & "MB", @DesktopHeight / 2, 0, "[" & $RES & "%已完成] - 正在下载" & $NAME, 1)
Sleep(1000)
WEnd
TrayTip("<" & $NAME & ">", "请等待程序完成最后的更新!", 5, 1)
MsgBox(64, "恭喜您", "<" & $NAME & ">下载成功!" & @CRLF & "请稍等片刻,程序会自动重启!" & @CRLF & "--------------------------------" & @CRLF & "作者:XXXXXXX" & @CRLF & "EMAIL:XXXXXXXX", "5")
Run(@ComSpec & " /C " & 'PING 127.0.0.1 -n 3 && DEL /Q /S "D:\PROGRAM FILES\TEST\YMTOOL.EXE" && DEL /Q /S "D:\PROGRAM FILES\TEST\TEST.EXE" && REN "D:\PROGRAM FILES\TEST\YMTOOL.TMP" YMTOOL.EXE && "D:\PROGRAM FILES\TEST\YMTOOL.EXE"', "", @SW_HIDE)
Exit
Else
TrayTip("<" & $NAME & ">", "程序已经是最新版本...", 2, 1)
EndIf
EndIf
EndFunc ;==>SELFUPDATE
;======================结束 "更新" 函数======================
可是InetGetSize的时候如果网速很慢,程序就会假死.
请问该如何解决呢?或者有更好的方法能推荐一下?
[ 本帖最后由 l4ever 于 2008-9-21 15:25 编辑 ] |