Ich habe folgende Komprimierungsroutine:
Delphi-Quellcode:
procedure TSave.CompressFiles(Files: TStrings; const Filename: string);
var
infile, outfile: TFileStream;
tmpFile: TStreamProgressAdapter;
compr : TCompressionStream;
i, l : Integer;
s : string;
begin
if Files.Count > 0 then
begin
outfile := TFileStream.Create(Filename, fmCreate);
try
{ the number of files }
l := Files.Count;
outfile.Write(l, SizeOf(l));
for i := 0 to Files.Count - 1 do
begin
//FPercentDone := (i * 100) div Files.Count;
infile := TStreamProgressAdapter.Create(TFileStream.Create(Files[i], fmOpenRead));
try
infile.OnProgress := SetProgress;
Synchronize(DoProgress);
{ the original filename }
s := ExtractFilename(Files[i]);
l := Length(s);
outfile.Write(l, SizeOf(l));
outfile.Write(s[1], l);
{ the original filesize }
l := infile.Size;
outfile.Write(l, SizeOf(l));
{ compress and store the file temporary}
tmpFile := TFileStream.Create('tmp', fmCreate);
compr := TCompressionStream.Create(clMax, tmpfile);
try
compr.CopyFrom(infile, l);
finally
compr.Free;
tmpFile.Free;
end;
{ append the compressed file to the destination file }
tmpFile := TFileStream.Create('tmp', fmOpenRead);
try
outfile.CopyFrom(tmpFile, 0);
finally
tmpFile.Free;
end;
finally
infile.Free;
end;
end;
finally
outfile.Free;
end;
DeleteFile('tmp');
end;
end;
TStereamProgressAdapter ist eine Stream-Klasse die ein OnProgress Ereignis implementiert (Klasse im Anhang). Ein Beispiel, wie man sie anwendet:
Delphi-Quellcode:
procedure TForm1.Button1Click(Sender: TObject);
var
SrcFile: TStreamProgressAdapter;
DestFile: TFileStream;
Filename: string;
begin
if OpenDialog1.Execute then
begin
Filename := OpenDialog1.FileName;
SrcFile := TStreamProgressAdapter.Create(TFileStream.Create(FileName,
fmOpenRead or fmShareDenyNone));
try
SrcFile.OnProgress := Progress;
DestFile := TFileStream.Create(Filename + '.copy', fmCreate);
try
DestFile.CopyFrom(SrcFile, SrcFile.Size);
finally
DestFile.Free;
end;
finally
SrcFile.Free;
end;
end;
end;
Jetzt hab eich aber ja nicht nur eine Quelldatei, sondern viele. Wie kann man es erreichen, dass man trotzdem den Fortschritt angezeigt bekommt?