找回密码
 加入
搜索
查看: 5889|回复: 5

[效率算法] 此程序不完美,出错!请高手指正,谢谢!

[复制链接]
发表于 2014-11-10 09:35:23 | 显示全部楼层 |阅读模式
问题有两个:
1、多文件 CRC32 检测的值有点文件的值对,但有点文件的值不对!
2、遇到大文件时还会出错!
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>

Local $Content = ""
Local $sDir = FileSelectFolder("请选择一个文件夹.", "")
GUICreate($sDir,640,520,100,200,-1,$WS_EX_ACCEPTFILES)
$listview = GUICtrlCreateListView("名称|大小|CRC32",0,0,640,480)
$Button_1 = GUICtrlCreateButton("分析一个新的文件夹",10,490)
$Button_2 = GUICtrlCreateButton("内容保存为文本文件",210,490)
$Button_3 = GUICtrlCreateButton("退出",410,490)
GUICtrlSetState(-1, $GUI_DROPACCEPTED)
GUISetState()
$hListview = ControlGetHandle($sDir,"",$listview)
_GUICtrlListView_SetColumnWidth($hListview,0,480)
_GUICtrlListView_SetColumnWidth($hListview,1,79)

FindAllFile($sDir)

While 1
        $msg = GUIGetMsg()
        Select
                Case $msg = $GUI_EVENT_CLOSE
                        ExitLoop
                Case $msg = $Button_1
                        Local $sDir = FileSelectFolder("请选择一个文件夹.", "")
                        FindAllFile($sDir)
                Case $msg = $Button_2
                        $File_1 = @ScriptDir & "" & @HOUR & @MIN & @SEC & ".txt"
                        FileOpen($File_1,10)
                        FileWrite($File_1,$Content)
                        FileClose($File_1)
                        MsgBox(0,"保存文件",$File_1 & " 保存完成!",3)
                Case $msg = $Button_3
                        ExitLoop
        EndSelect
WEnd

Func FindAllFile($sDir)
        Local $hSearch = FileFindFirstFile($sDir & "\*.*")
    If $hSearch = -1 Then Return
    While 1
        Local $sFile = FileFindNextFile($hSearch)
        If @error Then ExitLoop
        If @extended Then 
            FindAllFile($sDir & "" & $sFile)
            ContinueLoop
        EndIf
                $BufferSize = 0x20000
                Global $sCRC32 = 0
                For $i = 1 To Ceiling(FileGetSize($sDir & "" & $sFile)/$BufferSize)
                        $sCRC32 = _CRC32(FileRead(FileOpen($sDir & "" & $sFile,16),$BufferSize),BitNot($sCRC32))
                Next
                $Content &= Hex($sCRC32,8) & @TAB & SF(FileGetSize($sDir & "" & $sFile)) & @TAB & $sDir & "" & $sFile & @CRLF
                GUICtrlCreateListViewItem($sDir & "" & $sFile & "|" & SF(FileGetSize($sDir & "" & $sFile)) & "|" & Hex($sCRC32,8), $listview)
    WEnd
    FileClose($hSearch)
EndFunc

Func _CRC32($Data, $CRC32 = -1)
        Local $Opcode = '0xC800040053BA2083B8EDB9000100008D41FF516A0859D1E8730231D0E2F85989848DFCFBFFFFE2E78B5D088B4D0C8B451085DB7416E3148A1330C20FB6D2C1E80833849500FCFFFF43E2ECF7D05BC9C21000'
        Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]")
        DllStructSetData($CodeBuffer, 1, $Opcode)
        Local $Input = DllStructCreate("byte[" & BinaryLen($Data) & "]")
        DllStructSetData($Input, 1, $Data)
        Local $Ret = DllCall("user32.dll", "uint", "CallWindowProc", "ptr", DllStructGetPtr($CodeBuffer), _
                                                                                                        "ptr", DllStructGetPtr($Input), _
                                                                                                        "int", BinaryLen($Data), _
                                                                                                        "uint", $CRC32, _
                                                                                                        "int", 0)
        $Input = 0
        $CodeBuffer = 0
        Return $Ret[0]
EndFunc

Func SF($Size)
        Switch StringLen($Size)
                Case 4 To 6
                        $Size = StringLeft($Size,StringLen($Size)-3) & "," & StringRight($Size,3)
                Case 7 To 9
                        $Size = StringLeft($Size,StringLen($Size)-6) & "," & StringMid($Size,StringLen($Size)-5,3) & "," & StringRight($Size,3)
                Case 10 To 12
                        $Size = StringLeft($Size,StringLen($Size)-9) & "," & StringMid($Size,StringLen($Size)-5,3) & "," & StringMid($Size,StringLen($Size)-2,3) & "," & StringRight($Size,3)
        EndSwitch
        Return StringFormat("%11s\n",$Size)
EndFunc

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2014-11-14 21:41:08 | 显示全部楼层
_CRC32(FileRead(FileOpen($sDir & "\" & $sFile, 16), $BufferSize), BitNOT($sCRC32))

必死无疑
 楼主| 发表于 2014-11-19 07:45:57 | 显示全部楼层
回复 2# Qokelate


    CRC32 的例子就是这样的,我原版借用。请问详情,为何必死?
 楼主| 发表于 2014-11-30 11:17:29 | 显示全部楼层
请版主帮忙看看,谢谢!
 楼主| 发表于 2014-11-30 11:19:00 | 显示全部楼层
附:CRC32.au3
Func _CRC32($Data, $CRC32 = -1)
        Local $Opcode = '0xC800040053BA2083B8EDB9000100008D41FF516A0859D1E8730231D0E2F85989848DFCFBFFFFE2E78B5D088B4D0C8B451085DB7416E3148A1330C20FB6D2C1E80833849500FCFFFF43E2ECF7D05BC9C21000'

        Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]")
        DllStructSetData($CodeBuffer, 1, $Opcode)

        Local $Input = DllStructCreate("byte[" & BinaryLen($Data) & "]")
        DllStructSetData($Input, 1, $Data)

        Local $Ret = DllCall("user32.dll", "uint", "CallWindowProc", "ptr", DllStructGetPtr($CodeBuffer), _
                                                                                                        "ptr", DllStructGetPtr($Input), _
                                                                                                        "int", BinaryLen($Data), _
                                                                                                        "uint", $CRC32, _
                                                                                                        "int", 0)

        $Input = 0
        $CodeBuffer = 0

        Return $Ret[0]
EndFunc
 楼主| 发表于 2014-11-30 11:20:01 | 显示全部楼层
附:CRC32FileTest.au3
Global $BufferSize = 0x20000
Global $Filename = FileOpenDialog("Open file", "", "Any file (*.*)")
If $Filename = "" Then Exit

Global $Timer = TimerInit()
;Global $FileHandle = FileOpen($Filename, 16)
Global $CRC32 = 0

For $i = 1 To Ceiling(FileGetSize($Filename) / $BufferSize)
        $CRC32 = _CRC32(FileRead(FileOpen($Filename, 16), $BufferSize), BitNot($CRC32))
Next

MsgBox (0, "Result", Hex($CRC32, 8) & " in " & Round(TimerDiff($Timer)) & " ms")

Func _CRC32($Data, $CRC32 = -1)
        Local $Opcode = '0xC800040053BA2083B8EDB9000100008D41FF516A0859D1E8730231D0E2F85989848DFCFBFFFFE2E78B5D088B4D0C8B451085DB7416E3148A1330C20FB6D2C1E80833849500FCFFFF43E2ECF7D05BC9C21000'
        Local $CodeBuffer = DllStructCreate("byte[" & BinaryLen($Opcode) & "]")
        DllStructSetData($CodeBuffer, 1, $Opcode)
        Local $Input = DllStructCreate("byte[" & BinaryLen($Data) & "]")
        DllStructSetData($Input, 1, $Data)
        Local $Ret = DllCall("user32.dll", "uint", "CallWindowProc", "ptr", DllStructGetPtr($CodeBuffer), _
                                                                                                        "ptr", DllStructGetPtr($Input), _
                                                                                                        "int", BinaryLen($Data), _
                                                                                                        "uint", $CRC32, _
                                                                                                        "int", 0)
        $Input = 0
        $CodeBuffer = 0
        Return $Ret[0]
EndFunc
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-6 03:10 , Processed in 0.080722 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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