With reference to this thread..
http://www.nabble.com/FPC-Zip-library-td15145102.html
and the resulting bug entry..
http://bugs.freepascal.org/view.php?id=10787
I had a similar requirement, so I went and had a crack at patching zipper.pas.
It does precisely what _I_ want it to do, but it's not the cleanest of hacks and I wonder if there
is a better way to do it?
I post it here for comment anyway.
In short rather than call ZipFiles(), I now call ZipSomeFiles(). I can then replace the path each
file will appear to have inside the zip file with SetFilePath() prior to calling ZipAllFiles() to
create the zipfile.
I was thinking perhaps it might be better to attach an ansistring to each stringlist.object entry
with a new path prior to calling ZipFiles() instead, but I thought I'd solicit comment first.
Regards,
Brad
--
Dolphins are so intelligent that within a few weeks they can
train Americans to stand at the edge of the pool and throw them
fish.
--- /tracks/devel/fpc/fpc-src/packages/paszlib/src/zipper.pp 2007-12-02 02:38:01.000000000 +0400
+++ zipper.pas 2008-09-28 11:13:29.000000000 +0400
@@ -121,6 +121,7 @@
TZipItem = Class(TObject)
Path : String;
+ ArchivePath : String;
Name : String;
Size : LongInt;
DateTime : TDateTime;
@@ -295,7 +296,9 @@
Public
Constructor Create;
Destructor Destroy;override;
+ Procedure SetFilePath(Entry, NewPath : String);
Procedure ZipAllFiles; virtual;
+ Procedure ZipSomeFiles(AFileName : String; FileList : TStrings);
Procedure ZipFiles(AFileName : String; FileList : TStrings);
Procedure Clear;
Public
@@ -903,6 +906,24 @@
TZipper
---------------------------------------------------------------------}
+Procedure TZipper.SetFilePath(Entry, NewPath : String);
+Var
+ I : LongInt;
+ Found : Boolean;
+Begin
+ I := 0;
+ Found := False;
+ While (I < FFiles.Count) and Not Found do
+ begin
+ If Entry = FFiles[I] then
+ begin
+ TZipItem(FFiles.Objects[I]).ArchivePath := NewPath;
+ Found := True;
+ end
+ else
+ inc(I);
+ end;
+End;
Procedure TZipper.GetFileInfo;
@@ -919,6 +940,7 @@
try
NewNode:=TZipItem.Create;
NewNode.Path := ExtractFilePath(FFiles[i]);
+ NewNode.ArchivePath := NewNode.Path;
NewNode.Name := Info.Name;
NewNode.Size := Info.Size;
NewNode.DateTime:=FileDateToDateTime(Info.Time);
@@ -984,7 +1006,7 @@
var
ZFileName : ShortString;
Begin
- ZFileName:=Item.Path+Item.Name;
+ ZFileName:=Item.ArchivePath+Item.Name;
With LocalHdr do
begin
FileName_Length := Length(ZFileName);
@@ -1125,7 +1147,6 @@
exit;
FZipping:=True;
Try
- GetFileInfo;
OpenOutput;
Try
filecnt:=0;
@@ -1148,7 +1169,6 @@
end;
end;
-
Procedure TZipper.SetBufSize(Value : LongWord);
begin
@@ -1171,9 +1191,18 @@
begin
FFiles.Assign(FileList);
FFileName:=AFileName;
+ GetFileInfo;
ZipAllFiles;
end;
+Procedure TZipper.ZipSomeFiles(AFileName : String; FileList : TStrings);
+
+begin
+ FFiles.Assign(FileList);
+ FFileName:=AFileName;
+ GetFileInfo;
+end;
+
Procedure TZipper.DoEndOfFile;
Var
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-pascal