var
src, dst: Integer;
buf: Pointer;
n, bytes, bytestocopy: Integer;
lastpart:
array [0..4]
of Integer;
begin
if Tag = 0
then
begin
Tag := 1;
cancel := False;
Button1.Enabled := False; Button2.Enabled := False; Button4.Enabled := False;
Button3.Caption := '
&Abbrechen';
src := INVALID_HANDLE_VALUE;
dst := INVALID_HANDLE_VALUE;
try
GetMem(buf, 1
shl 20);
// 1 Megabyte
src := CreateFile(PChar(Edit1.Text), GENERIC_READ, FILE_SHARE_READ,
nil, OPEN_EXISTING, 0, 0);
if (src = INVALID_HANDLE_VALUE)
then
raise EInOutError.Create('
Datei nicht gefunden');
dst := CreateFile(PChar(Edit2.Text), GENERIC_WRITE, FILE_SHARE_READ,
nil, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
if (dst = INVALID_HANDLE_VALUE)
then
raise EInOutError.Create('
Fehler beim Erzeugen der Datei');
bytestocopy := SetFilePointer(src, 0,
nil, FILE_END);
SetFilePointer(src, -sizeof(lastpart),
nil, FILE_END);
if (
not ReadFile(src, lastpart, sizeof(lastpart), n,
nil))
then
raise EInOutError.Create('
Datei zu kurz');
if (((lastpart[0] = $21444E45)
and
(lastpart[2] = $3552454E))
or
((lastpart[1] = $21444E45)
and
(lastpart[3] = $4F52454E)))
then
begin
bytestocopy := lastpart[4];
asm
mov eax, bytestocopy
xchg ah, al
rol eax, 16
xchg ah, al
mov bytestocopy, eax
end;
end;
Dec(bytestocopy, 512*600);
// fehler1 if (SetFilePointer(src, 512*600, nil, FILE_BEGIN) = -1) then
raise EInOutError.Create('
Datei zu kurz');
while (bytestocopy > 0)
do
begin
bytes := bytestocopy;
if (bytes > 1
shl 20)
then
bytes := 1
shl 20;
//fehler2 if (not ReadFile(src, buf^, bytes, n, nil)) then
raise EInOutError.Create('
Fehler beim Lesen');
if n = 0
then
break;
Dec(bytestocopy, n);
if cancel
then
break;
//fehler3 if (not WriteFile(dst, buf^, n, n, nil)) then
raise EInOutError.Create('
Fehler beim Schreiben');
Label1.Caption := Format('
%d Bytes kopiert', [SetFilePointer(src, 0,
nil, FILE_CURRENT)]);
Label1.Update;
Application.ProcessMessages;
end;
Label1.Caption := '
fertig.';
except
on e: EInOutError
do
Label1.Caption := '
Fehler: ' + e.
Message;
end;
CloseHandle(src);
CloseHandle(dst);
Button3.Caption := '
&Konvertieren';
Button1.Enabled := True; Button2.Enabled := True; Button4.Enabled := True;
Tag := 0;
end
else
cancel := True;