Func _FileCompare($sFile1, $sFile2)
Local $sMd5_1 = CheckSumMD5_File_($sFile1)
Local $sMd5_2 = CheckSumMD5_File_($sFile2)
Return ($sMd5_1 = $sMd5_2)
EndFunc
;###################################################################################################
; Описание: вычисляет контрольную сумму файла
;===================================================================================================
; Синтаксис: CheckSumMD5_File_($_sFile)
;===================================================================================================
; Параметры: $_sFile = путь к файлу
;===================================================================================================
; Результат: возвращает контрольную сумму
;===================================================================================================
; Примечание: ?
;###################################################################################################
Func CheckSumMD5_File_($_sFile)
Local $_iError = 1, $_sMD5 = '0x00'
Local $_aFile = DllCall('kernel32.dll', 'hwnd', 'CreateFileW', 'wstr', $_sFile, 'dword', 0x80000000, 'dword', 3, 'ptr', 0, 'dword', 3, 'dword', 0, 'ptr', 0)
If Not @error And ($_aFile[0] <> -1) Then
Local $_aMapping = DllCall('kernel32.dll', 'ptr', 'CreateFileMappingW', 'hwnd', $_aFile[0], 'dword', 0, 'dword', 2, 'dword', 0, 'dword', 0, 'ptr', 0)
If Not @error And $_aMapping[0] Then
Local $_tContext = DllStructCreate('dword i[2];dword buf[4];ubyte in[64];ubyte digest[16]')
Local $_pContext = DllStructGetPtr($_tContext)
DllCall('advapi32.dll', 'none', 'MD5Init', 'ptr', $_pContext)
If Not @error Then
Local $_iBufferSize = 1048576 * 8;8Mb.
Local $_iFileSize = FileGetSize($_sFile)
Local $_iFilePos, $_aMapView
For $_iFilePos = 0 To $_iFileSize Step $_iBufferSize
If ($_iFilePos + $_iBufferSize) > $_iFileSize Then $_iBufferSize = $_iFileSize - $_iFilePos
$_aMapView = DllCall('kernel32.dll', 'ptr', 'MapViewOfFile', 'hwnd', $_aMapping[0], 'dword', 4, 'dword', HiDWord_($_iFilePos), 'dword', LoDWord_($_iFilePos), 'dword', $_iBufferSize)
If Not @error And $_aMapView[0] Then
DllCall('advapi32.dll', 'none', 'MD5Update', 'ptr', $_pContext, 'ptr', $_aMapView[0], 'dword', $_iBufferSize)
$_iError = @error
DllCall('kernel32.dll', 'int', 'UnmapViewOfFile', 'ptr', $_aMapView[0])
If $_iError Then ExitLoop
EndIf
Next
DllCall('advapi32.dll', 'none', 'MD5Final', 'ptr', $_pContext)
If Not @error Then $_sMD5 = '0x'& Hex(DllStructGetData($_tContext, 'digest'))
EndIf
DllCall('kernel32.dll', 'int', 'CloseHandle', 'hwnd', $_aMapping[0])
EndIf
DllCall('kernel32.dll', 'int', 'CloseHandle', 'hwnd', $_aFile[0])
EndIf
Return SetError($_iError, 0, $_sMD5)
EndFunc
Func HiDWord_($_iValue)
Local $_tInt64 = DllStructCreate('int64')
Local $_tQWord = DllStructCreate('dword;dword', DllStructGetPtr($_tInt64))
DllStructSetData($_tInt64, 1, $_iValue)
Return DllStructGetData($_tQWord, 2)
EndFunc
Func LoDWord_($_iValue)
Local $_tInt64 = DllStructCreate('int64')
Local $_tQWord = DllStructCreate('dword;dword', DllStructGetPtr($_tInt64))
DllStructSetData($_tInt64, 1, $_iValue)
Return DllStructGetData($_tQWord, 1)
EndFunc