#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