(Gast)
n/a Beiträge
|
Re: FileClose und CloseFile schliesst Datei nicht?
28. Jul 2005, 19:30
In diesem Fall allerdings nicht:
Delphi-Quellcode:
////////////////////////////////////////////////////////////////////////////////
// MD5: Erstellt aus einer Datei eine Checksumme
////////////////////////////////////////////////////////////////////////////////
function TMD5Form.FileScan(const FileName: String): String;
const MAX_Buffer = 2048;
var AFile: TFileStream;
var i, ActSize, FSize, BufferSize, Blocks, Last: Integer;
var Buffer: Array[1..MAX_Buffer] of Byte; // Datenpuffer
var Context: MD5Context;
var Dig: MD5Digest;
var f, c: Extended;
begin
c := 0;
ActSize := 0;
if FileExists(FileName) then
begin
AFile := TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone);
try
// Datei konnte geöffnet werden
MD5Init(Context);
FSize := AFile.Size; // Dateigröße in Byte
if FSize <> 0 then
begin
Panel.Visible := True;
OKBtn.Enabled := False;
UserEdit.Enabled := False;
Blocks := FSize div MAX_Buffer; // Anzahl max. Blöcke
Last := FSize mod MAX_Buffer; // Größe des Rest-Puffer
if Last <> 0 then
inc(Blocks); // sofern, unser Restpuffer ungleich 0 Byte groß ist, wird unsere Blockvariable um 1 erhöht
f := 100 / Blocks;
for i := 0 to Blocks -1 do // Blöcke einlesen
begin
if CancelProcess then
Break;
AFile.Position := ActSize; // Start-Position in Byte (wird von Block zu Block angepasst)
inc(ActSize, MAX_Buffer);
if ActSize <= FSize then
BufferSize := MAX_Buffer else
BufferSize := Last;
c := c + f;
ProgressBar.Position := Round(c);
Application.ProcessMessages;
AFile.ReadBuffer(Buffer[1], BufferSize);
MD5Update(Context, @Buffer, BufferSize);
end;
end;
if CancelProcess then
Result := '' else
begin
MD5Final(Context, Dig);
Result := MD5Print(Dig);
end;
finally
AFile.Free;
Panel.Visible := False;
OKBtn.Enabled := True;
UserEdit.Enabled := True;
end;
end;
end;
|
|
Zitat
|