請選擇 進入手機版 | 繼續訪問電腦版

微剋多資訊

 找回密碼
 註冊

Sign in with google

Google帳號登入

搜索

該用戶從未簽到

升級   0%

發表於 2013-3-2 18:11 | 顯示全部樓層 |閱讀模式
本帖最後由 rictirse 於 2014-12-24 08:26 編輯

基於上一版大家給的建議,這邊噹噹稍作修改
可以比對MD5,新版本辨識更加準確
順便撰寫了一個檔案產生器,方便大量傳檔

下載器內部的子控數量會隨著檔案數量而變化
如果你檔案在aspx內只有一筆那在更新器也只會看到一筆資料
防止錯誤下載

這邊有使用教學影片歡迎跟噹噹來來研究



自動更新辨識器
  1. #include <IE.au3>
  2. #include <Array.au3>
  3. #include <GUIConstantsEx.au3>

  4. Dim $DirPath = @ScriptDir&"Download"

  5. $oIE = _IECreate( "http://myweb.hinet.net/home19/leojackey/Update.aspx", 1, 0, 1)
  6. $sText = _IEBodyReadText($oIE)
  7. _IEQuit ($oIE)

  8. $Line = StringSplit ( $sText, @LF, 2)
  9. Global $Array[UBound($Line)][3]
  10. Global $Local_MD5[UBound($Line)]
  11. Global $Download[UBound($Line)]

  12. For $i = 0 To (UBound($Line)-1)
  13.   $Split = StringSplit ( $Line[$i], @TAB, 2)
  14.   $Array[$i][0] = $Split[0]
  15.   $Array[$i][1] = $Split[1]
  16.   $Array[$i][2] = $Split[2]
  17. Next

  18. GUICreate ( "Auto Update", 710, 40+($i*40))

  19. GUICtrlCreateLabel ( "更新進度", 10, 13)

  20. $Progres = GUICtrlCreateProgress ( 70, 10, 628, 20)

  21. For $i = 0 To (UBound($Line)-1)
  22.   GUICtrlCreateLabel ( "軟體名稱:"&$Array[$i][1], 10, 37+($i*40), 290, 40)
  23.     GUICtrlSetFont( -1, 18, 800)

  24.   GUICtrlCreateLabel ( "Server MD5:"&$Array[$i][2], 310, 40+($i*40), 300)

  25.   $Local_MD5[$i] = GUICtrlCreateLabel ( "Local MD5:"&$Array[$i][2], 310, 55+($i*40), 300)

  26.   $Download[$i] = GUICtrlCreateButton ( "下載", 650, 42+($i*40), 50, 25)
  27.     GUICtrlSetState  ( -1, $GUI_DISABLE)
  28. Next

  29. _CheckMD5()

  30. GUISetState()

  31. While True
  32.   $msg = GUIGetMsg()
  33.   For $i = 0 To (UBound($Line)-1)
  34.     If $msg = $Download[$i] Then
  35.       _Download ( $Array[$i][0], $DirPath&""&$Array[$i][1])
  36.       GUICtrlSetState  ( $Download[$i], $GUI_DISABLE)
  37.     EndIf
  38.   Next

  39.   If $msg = $GUI_EVENT_CLOSE Then Exit
  40. WEnd

  41. Func _Download ( $FilePath_Server, $FilePath_Local)
  42.   $TotalSize = InetGetSize ($FilePath_Server) ;; 取得總容量
  43.   $hDownload = InetGet ($FilePath_Server, $FilePath_Local, 1, 1) ;;開始下載

  44.   Do
  45.     Sleep (50)
  46.     $NowDownload = InetGetInfo($hDownload, 0)

  47.     $per = Int ($NowDownload/$TotalSize*100) ;;計算百分比
  48.     $res = Int (StringLeft ( $per, 3)) ;;百分值
  49.     GUICtrlSetData ($progres , $res) ;;下載進度

  50.     TrayTip ( "正在下載更新中", "已下載 " & Int ($NowDownload/1024)&" kB", 1) ;;監視已下載大小


  51.   Until InetGetInfo ( $hDownload, 2)

  52.   GuiCtrlSetData ( $progres , 0)

  53.   If $TotalSize = FileGetSize ($FilePath_Local) Then
  54. ;~     MsgBox ( 0, "更新完成", "檔案大小:" &Int ($TotalSize/1024)&" kB"&@CRLF&"已下載大小:" & Int ($NowDownload/1024)&" kB")
  55.     Run($FilePath_Local) ;;執行程序
  56.   Else
  57.     MsgBox ( 16, "錯誤", "更新失敗。")
  58.   EndIf

  59. EndFunc

  60. Func _CheckMD5()
  61.   Local $MD5

  62.   For $i = 0 To (UBound($Line)-1)
  63.     If FileExists ($DirPath&""&$Array[$i][1]) Then
  64.       $MD5 = _MD5($DirPath&""&$Array[$i][1])
  65.       GUICtrlSetData ( $Local_MD5[$i], "Local MD5:"&$MD5)
  66.       If $MD5 = $Array[$i][2] Then GUICtrlSetState  ( $Download[$i], $GUI_DISABLE)
  67.     Else
  68.       GUICtrlSetData ( $Local_MD5[$i], "Local MD5:未發現")
  69.         GUICtrlSetState  ( $Download[$i], $GUI_ENABLE)
  70.     EndIf
  71.   Next
  72. EndFunc

  73. Func _MD5($sFile)
  74.   Local Const $CALG_MD2 = 0x8001
  75.   Local Const $CALG_MD4 = 0x8002
  76.   Local Const $CALG_MD5 = 0x8003
  77.   Local Const $CALG_SHA1 = 0x8004

  78.   $hFile = FileOpen ($sFile, 16)
  79.   $bData = FileRead ($hFile)
  80.   $iLength = BinaryLen ($bData)
  81.   FileClose($hFile)


  82.   $tBuffer = DllStructCreate("byte[" & $iLength & "]")
  83.   $pBuffer = DllStructGetPtr($tBuffer)
  84.   DllStructSetData($tBuffer, 1, $bData)

  85.   $iResult = DllCall ("Crypt32.dll", "int", "CryptHashCertificate", "hWnd", 0, "dword", $CALG_MD5, "dword", 0, "ptr", $pBuffer, "dword", $iLength, "ptr", 0, "dword*", 0)
  86.   $tResult = DllStructCreate ("byte[" & $iResult[7] & "]")
  87.   $pResult = DllStructGetPtr ($tResult)
  88.   $iResult = DllCall ("Crypt32.dll", "int", "CryptHashCertificate", "hWnd", 0, "dword", $CALG_MD5, "dword", 0, "ptr", $pBuffer, "dword", $iLength, "ptr", $pResult, "dword*", $iResult[7])
  89.   If $iResult[0] <> 0 Then Return StringTrimLeft (DllStructGetData ($tResult, 1), 2)

  90.   $tBuffer = 0
  91.   $tResult = 0
  92. EndFunc
複製代碼
aspx 產生器
  1. #include <IE.au3>
  2. #include <Array.au3>
  3. #include <GUIConstantsEx.au3>

  4. Dim $DirPath = @ScriptDir&"Download"

  5. $oIE = _IECreate( "http://myweb.hinet.net/home19/leojackey/Update.aspx", 1, 0, 1)
  6. $sText = _IEBodyReadText($oIE)
  7. _IEQuit ($oIE)

  8. $Line = StringSplit ( $sText, @LF, 2)
  9. Global $Array[UBound($Line)][3]
  10. Global $Local_MD5[UBound($Line)]
  11. Global $Download[UBound($Line)]

  12. For $i = 0 To (UBound($Line)-1)

  13.   $Split = StringSplit ( $Line[$i], @TAB, 2)
  14.   $Array[$i][0] = $Split[0]
  15.   $Array[$i][1] = $Split[1]
  16.   $Array[$i][2] = $Split[2]
  17. Next

  18. GUICreate ( "Auto Update", 710, 40+($i*40))

  19. GUICtrlCreateLabel ( "更新進度", 10, 13)

  20. $Progres = GUICtrlCreateProgress ( 70, 10, 628, 20)

  21. For $i = 0 To (UBound($Line)-1)
  22.   GUICtrlCreateLabel ( "軟體名稱:"&$Array[$i][1], 10, 37+($i*40), 290, 40)
  23.     GUICtrlSetFont( -1, 18, 800)

  24.   GUICtrlCreateLabel ( "Server MD5:"&$Array[$i][2], 310, 40+($i*40), 300)

  25.   $Local_MD5[$i] = GUICtrlCreateLabel ( "Local MD5:"&$Array[$i][2], 310, 55+($i*40), 300)

  26.   $Download[$i] = GUICtrlCreateButton ( "下載", 650, 42+($i*40), 50, 25)
  27.     GUICtrlSetState  ( -1, $GUI_DISABLE)
  28. Next

  29. _CheckMD5()

  30. GUISetState()

  31. While True
  32.   $msg = GUIGetMsg()
  33.   For $i = 0 To (UBound($Line)-1)
  34.     If $msg = $Download[$i] Then
  35.       _Download ( $Array[$i][0], $DirPath&""&$Array[$i][1])
  36.       GUICtrlSetState  ( $Download[$i], $GUI_DISABLE)
  37.     EndIf
  38.   Next

  39.   If $msg = $GUI_EVENT_CLOSE Then Exit
  40. WEnd

  41. Func _Download ( $FilePath_Server, $FilePath_Local)
  42.   $TotalSize = InetGetSize ($FilePath_Server) ;; 取得總容量
  43.   $hDownload = InetGet ($FilePath_Server, $FilePath_Local, 1, 1) ;;開始下載

  44.   Do

  45.     Sleep (50)
  46.     $NowDownload = InetGetInfo($hDownload, 0)

  47.     $per = Int ($NowDownload/$TotalSize*100) ;;計算百分比
  48.     $res = Int (StringLeft ( $per, 3)) ;;百分值
  49.     GUICtrlSetData ($progres , $res) ;;下載進度

  50.     TrayTip ( "正在下載更新中", "已下載 " & Int ($NowDownload/1024)&" kB", 1) ;;監視已下載大小

  51.   Until InetGetInfo ( $hDownload, 2)

  52.   GuiCtrlSetData ( $progres , 0)

  53.   If $TotalSize = FileGetSize ($FilePath_Local) Then
  54. ;~     MsgBox ( 0, "更新完成", "檔案大小:" &Int ($TotalSize/1024)&" kB"&@CRLF&"已下載大小:" & Int ($NowDownload/1024)&" kB")
  55.     Run($FilePath_Local) ;;執行程序
  56.   Else
  57.     MsgBox ( 16, "錯誤", "更新失敗。")
  58.   EndIf

  59. EndFunc

  60. Func _CheckMD5()
  61.   Local $MD5

  62.   For $i = 0 To (UBound($Line)-1)
  63.     If FileExists ($DirPath&""&$Array[$i][1]) Then
  64.       $MD5 = _MD5($DirPath&""&$Array[$i][1])
  65.       GUICtrlSetData ( $Local_MD5[$i], "Local MD5:"&$MD5)
  66.       If $MD5 = $Array[$i][2] Then GUICtrlSetState  ( $Download[$i], $GUI_DISABLE)
  67.     Else
  68.       GUICtrlSetData ( $Local_MD5[$i], "Local MD5:未發現")
  69.         GUICtrlSetState  ( $Download[$i], $GUI_ENABLE)
  70.     EndIf
  71.   Next
  72. EndFunc

  73. Func _MD5($sFile)
  74.   Local Const $CALG_MD2 = 0x8001
  75.   Local Const $CALG_MD4 = 0x8002
  76.   Local Const $CALG_MD5 = 0x8003
  77.   Local Const $CALG_SHA1 = 0x8004

  78.   $hFile = FileOpen ($sFile, 16)
  79.   $bData = FileRead ($hFile)
  80.   $iLength = BinaryLen ($bData)
  81.   FileClose($hFile)

  82.   $tBuffer = DllStructCreate("byte[" & $iLength & "]")
  83.   $pBuffer = DllStructGetPtr($tBuffer)
  84.   DllStructSetData($tBuffer, 1, $bData)

  85.   $iResult = DllCall ("Crypt32.dll", "int", "CryptHashCertificate", "hWnd", 0, "dword", $CALG_MD5, "dword", 0, "ptr", $pBuffer, "dword", $iLength, "ptr", 0, "dword*", 0)
  86.   $tResult = DllStructCreate ("byte[" & $iResult[7] & "]")
  87.   $pResult = DllStructGetPtr ($tResult)
  88.   $iResult = DllCall ("Crypt32.dll", "int", "CryptHashCertificate", "hWnd", 0, "dword", $CALG_MD5, "dword", 0, "ptr", $pBuffer, "dword", $iLength, "ptr", $pResult, "dword*", $iResult[7])
  89.   If $iResult[0] <> 0 Then Return StringTrimLeft (DllStructGetData ($tResult, 1), 2)

  90.   $tBuffer = 0
  91.   $tResult = 0
  92. EndFunc
複製代碼
樓主熱門主題

該用戶從未簽到

升級   0%

 樓主| 發表於 2013-3-2 20:12 | 顯示全部樓層
ShekBoy 發表於 2013-3-2 18:21
請問大大你的鼠標手勢是什麼軟件

StrokeIt

本帖子中包含更多資源

您需要 登入 才可以下載或查看,沒有帳號?註冊

x

使用道具

您需要登入後才可以回帖 登入 | 註冊

本版積分規則

小黑屋|Archiver|微剋多資訊(MicroDuo)

GMT+8, 2024-3-29 03:29

Discuz! X

© 2009-2023 Microduo

快速回覆 返回頂部 返回列表