Новый участник
Сообщения: 28
Благодарности: 9
|
Профиль
|
Отправить PM
| Цитировать
Цитата ErikPshat:
А вот API CRC32: 00:00:015 - как так возможно?
А Fast CRC-32C: 00:00:000 »
|
сказывается 3 день Пасхи  не назначил отдельную переменную для имени файла, и s потом вместо файла указывало на посчитанную ранее md5 сумму.
Скрытый текст
Код: 
#define CP = (Defined UNICODE) ? "unicode" : "ansi"
#define AW = (Defined UNICODE) ? "W" : "A"
[Setup]
AppName=test
AppVerName=test
DefaultDirName={tmp}
CreateAppDir=no
Uninstallable=no
CreateUninstallRegKey=no
[Files]
Source: crc32c_{#CP}.dll; Flags: dontcopy;
[.Code]
type
TMyMsg = record hWnd: HWND; msg, wParam: Word; lParam: LongWord; Time: TFileTime; pt: TPoint; end;
function GetCRC32COfFile(FilePath: String): Cardinal;
external 'GetCRC32COfFile@files:crc32c_{#CP}.dll stdcall';
function GetTickCount: Dword;
external 'GetTickCount@kernel32.dll stdcall';
function RtlComputeCrc32(dwInitial: Cardinal; const pData: Longint; iLen: Integer): Cardinal;
external 'RtlComputeCrc32@ntdll.dll stdcall';
function ReadFile(hFile: THandle; lpBuffer: Longint; nNumberOfBytesToRead: DWORD; var lpNumberOfBytesRead: DWORD; lpOverlapped: Longint): BOOL;
external 'ReadFile@kernel32.dll stdcall';
function GetProcessHeap: THandle;
external 'GetProcessHeap@kernel32.dll stdcall';
function HeapAlloc(hHeap: THandle; dwFlags, dwBytes: DWORD): Longint;
external 'HeapAlloc@kernel32.dll stdcall';
function HeapSize(hHeap: THandle; dwFlags: DWORD; lpMem: Longint): DWORD;
external 'HeapSize@kernel32.dll stdcall';
function HeapFree(hHeap: THandle; dwFlags: DWORD; lpMem: Longint): BOOL;
external 'HeapFree@kernel32.dll stdcall';
function PeekMessage(var lpMsg: TMyMsg; hWnd: HWND; wMsgFilterMin, wMsgFilterMax, wRemoveMsg: UINT): BOOL;
external 'PeekMessage{#AW}@user32.dll stdcall';
function TranslateMessage(const lpMsg: TMyMsg): BOOL;
external 'TranslateMessage@user32.dll stdcall';
function DispatchMessage(const lpMsg: TMyMsg): Longint;
external 'DispatchMessage{#AW}@user32.dll stdcall';
function CreateFile(lpFileName: String; dwDesiredAccess: DWORD; dwShareMode: DWORD; lpSecurityAttributes: DWORD; dwCreationDisposition: DWORD; dwFlagsAndAttributes: DWORD; hTemplateFile: THandle): THandle;
external 'CreateFile{#AW}@kernel32.dll stdcall';
function CloseHandle(hObject: THandle): BOOL;
external 'CloseHandle@kernel32.dll stdcall';
const
PAGE_READONLY = $0002;
FILE_MAP_READ = $0004;
HEAP_ZERO_MEMORY = $0008;
FILE_FLAG_SEQUENTIAL_SCAN = $08000000;
GENERIC_READ = $80000000;
GENERIC_WRITE = $40000000;
GENERIC_EXECUTE = $20000000;
GENERIC_ALL = $10000000;
FILE_SHARE_READ = 1;
FILE_SHARE_WRITE = 2;
FILE_SHARE_DELETE = 4;
CREATE_NEW = 1;
CREATE_ALWAYS = 2;
OPEN_EXISTING = 3;
OPEN_ALWAYS = 4;
TRUNCATE_EXISTING = 5;
INVALID_HANDLE_VALUE = (-1);
procedure AppProcessMessage;
var
Msg: TMyMsg;
begin
while PeekMessage(Msg, 0, 0, 0, 1) do
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end;
function GetCRC32OfFile(FileName: string): Cardinal;
var
hFile, hHeap: THandle;
lpBuffer: Longint;
dwBufferSize, dwRead: DWORD;
begin
Result := 0;
hFile := CreateFile(FileName, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL or FILE_FLAG_SEQUENTIAL_SCAN, 0);
if hFile = INVALID_HANDLE_VALUE then Exit;
try
hHeap := GetProcessHeap;
if hHeap = 0 then Exit;
lpBuffer := HeapAlloc(hHeap, HEAP_ZERO_MEMORY, 32*1024);
if lpBuffer = 0 then Exit;
dwBufferSize := HeapSize(hHeap, 0, lpBuffer);
if dwBufferSize = 0 then Exit;
while ReadFile(hFile, lpBuffer, dwBufferSize, dwRead, 0) and BOOL(dwRead > 0) do
begin
AppProcessMessage;
Result := RtlComputeCrc32(Result, lpBuffer, dwRead);
end;
finally
if hHeap <> 0 then
HeapFree(hHeap, 0, lpBuffer);
CloseHandle(hFile);
end;
end;
function FormatTime(time: int64): string;
var
Ms : int64;
H, M, S : Integer;
begin
Ms := time;
H := Ms div (60 * 60 * 1000);
Ms := Ms mod (60 * 60 * 1000);
M := Ms div (60 * 1000);
Ms := Ms mod (60 * 1000);
S := Ms div 1000;
Ms := Ms mod 1000;
Result := Format('%.2dh:%.2dm:%.2ds:%.3dms',[H,M,S,Ms]);
end;
///////////////////////////
procedure InitializeWizard;
var
s,fs: string;
c: cardinal;
Elapsed,Start,Stop:int64;
begin
fs:='C:\44.txt';
if FileExists (fs) then
begin
Elapsed := 0;
Start:=GetTickCount;
s:=GetMD5OfFile(fs);
Stop:=GetTickCount;
Elapsed:=Stop-Start;
MsgBox(s+' Inno MD5 Time: '+FormatTime(Elapsed), mbInformation, MB_OK);
/////////////
Elapsed := 0;
Start:=GetTickCount;
c:=GetCRC32OfFile(fs);
Stop:=GetTickCount;
Elapsed:=Stop-Start;
MsgBox(Format('%.8x',[c])+' Api CRC32 Time: '+FormatTime(Elapsed), mbInformation, MB_OK);
/////////////
Elapsed := 0;
Start:=GetTickCount;
c:=GetCRC32COfFile(fs);
Stop:=GetTickCount;
Elapsed:=Stop-Start;
MsgBox(Format('%.8x',[c])+' Fast CRC-32C Time: '+FormatTime(Elapsed), mbInformation, MB_OK);
end;
end;
ErikPshat,
http://qaru.site/questions/332124/crc32-vs-crc32c
|