[Setup]
AppName=test
AppVerName=test
DefaultDirName={tmp}
CreateAppDir=no
Uninstallable=no
CreateUninstallRegKey=no
[Languages]
Name: ru; MessagesFile: compiler:Languages\russian.isl
[Code]
#define A = (Defined UNICODE) ? "W" : "A"
const
GENERIC_READ = $80000000;
FILE_SHARE_READ = $0001;
OPEN_EXISTING = $0003;
PAGE_READONLY = $0002;
FILE_MAP_READ = $0004;
INVALID_HANDLE_VALUE = (-1);
HEAP_ZERO_MEMORY = $0008;
FILE_FLAG_SEQUENTIAL_SCAN = $08000000;
function CreateFile(lpFileName: string; dwDesiredAccess, dwShareMode: DWORD; lpSecurityAttributes: Longint; dwCreationDisposition, dwFlagsAndAttributes: DWORD; hTemplateFile: THandle): THandle; external 'CreateFile{#A}@kernel32.dll stdcall';
function CloseHandle(hObject: THandle): BOOL; external 'CloseHandle@kernel32.dll stdcall';
function RtlComputeCrc32(dwInitial: DWORD; const pData: Longint; iLen: Integer): DWORD; 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 GetCRC32OfFile(const FileName: string): DWORD;
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
Result := RtlComputeCrc32(Result, lpBuffer, dwRead);
finally
if hHeap <> 0 then
HeapFree(hHeap, 0, lpBuffer);
CloseHandle(hFile);
end;
end;
///////////////////////////
procedure InitializeWizard;
var
szFileName: string;
dwCRC32: DWORD;
begin
szFileName := ExpandConstant('{sys}\calc.exe');
dwCRC32 := GetCRC32OfFile(szFileName);
MsgBox(Format('File: %s'#13'CRC32: %x', [szFileName, dwCRC32]), mbInformation, MB_OK);
end;