Browse Source

--- Merging r14014 into '.':
U packages/paszlib/src/gzio.pas
--- Merging r14015 into '.':
G packages/paszlib/src/gzio.pas
--- Merging r14016 into '.':
U rtl/inc/strings.pp
--- Merging r14256 into '.':
U packages/paszlib/src/zipper.pp
--- Merging r14501 into '.':
G packages/paszlib/src/zipper.pp

# revisions: 14014,14015,14016,14256,14501
------------------------------------------------------------------------
r14014 | marco | 2009-11-03 10:21:58 +0100 (Tue, 03 Nov 2009) | 2 lines
Changed paths:
M /trunk/packages/paszlib/src/gzio.pas

* fix for windows compilation after last chances (mantis 14980)

------------------------------------------------------------------------
------------------------------------------------------------------------
r14015 | marco | 2009-11-03 12:18:27 +0100 (Tue, 03 Nov 2009) | 1 line
Changed paths:
M /trunk/packages/paszlib/src/gzio.pas

* slight adjustment. Bug #14420 fixed.
------------------------------------------------------------------------
------------------------------------------------------------------------
r14016 | marco | 2009-11-03 13:59:12 +0100 (Tue, 03 Nov 2009) | 2 lines
Changed paths:
M /trunk/rtl/inc/strings.pp

* Minor optimization from mantis 14974

------------------------------------------------------------------------
------------------------------------------------------------------------
r14256 | marco | 2009-11-22 20:48:00 +0100 (Sun, 22 Nov 2009) | 3 lines
Changed paths:
M /trunk/packages/paszlib/src/zipper.pp

* TUnzipper now instrumentable with events to be usable with custom streams
Patch from Andrew, Mantis 15151

------------------------------------------------------------------------
------------------------------------------------------------------------
r14501 | jonas | 2009-12-30 14:19:51 +0100 (Wed, 30 Dec 2009) | 8 lines
Changed paths:
M /trunk/packages/paszlib/src/zipper.pp

* renamed ZStream to zstream in the uses clause so it matches the unit's
file name. Solves the problem that zstream's .o file was not installed
in case of
a) compiling on a case-preserving file systems
b) on an OS that is marked as case-sensitive
c) when using the -Fd command line option (so the directory cache
does not emulate the case-sensitive behaviour)

------------------------------------------------------------------------

git-svn-id: branches/fixes_2_4@14679 -

marco 15 years ago
parent
commit
54f33311bc
3 changed files with 43 additions and 25 deletions
  1. 7 2
      packages/paszlib/src/gzio.pas
  2. 35 22
      packages/paszlib/src/zipper.pp
  3. 1 1
      rtl/inc/strings.pp

+ 7 - 2
packages/paszlib/src/gzio.pas

@@ -225,12 +225,15 @@ begin
     exists:=not (fpstat(path,info)<0);
     exists:=not (fpstat(path,info)<0);
   {$else}
   {$else}
     GetFAttr(s^.gzfile, Attr);
     GetFAttr(s^.gzfile, Attr);
-    exists:=(DosError= 0)
+    exists:=(DosError= 0);
   {$endif}
   {$endif}
   
   
   doseek:=false;
   doseek:=false;
   if ((s^.mode='a') and not exists) or (s^.mode='w') then
   if ((s^.mode='a') and not exists) or (s^.mode='w') then
+    begin
+   
     ReWrite (s^.gzfile,1)  
     ReWrite (s^.gzfile,1)  
+    end
   else
   else
     begin
     begin
       Reset (s^.gzfile,1);  
       Reset (s^.gzfile,1);  
@@ -247,7 +250,9 @@ begin
   // append binary file.
   // append binary file.
   if doseek then
   if doseek then
      seek(s^.gzfile,filesize(s^.gzfile));
      seek(s^.gzfile,filesize(s^.gzfile));
-  s^.mode:='w';   // difference append<->write doesn't matter anymore
+
+  if s^.mode='a' then
+    s^.mode:='w';   // difference append<->write doesn't matter anymore
   if writing then begin { Write a very simple .gz header }
   if writing then begin { Write a very simple .gz header }
 {$IFNDEF NO_DEFLATE}
 {$IFNDEF NO_DEFLATE}
     gzheader [0] := gz_magic [0];
     gzheader [0] := gz_magic [0];

+ 35 - 22
packages/paszlib/src/zipper.pp

@@ -21,7 +21,7 @@ Uses
   {$IFDEF UNIX}
   {$IFDEF UNIX}
    BaseUnix,
    BaseUnix,
   {$ENDIF}
   {$ENDIF}
-   SysUtils,Classes,ZStream;
+   SysUtils,Classes,zstream;
 
 
 
 
 Const
 Const
@@ -362,6 +362,7 @@ Type
   end;
   end;
 
 
   TOnCustomStreamEvent = Procedure(Sender : TObject; var AStream : TStream; AItem : TFullZipFileEntry) of object;
   TOnCustomStreamEvent = Procedure(Sender : TObject; var AStream : TStream; AItem : TFullZipFileEntry) of object;
+  TCustomInputStreamEvent = Procedure(Sender: TObject; var AStream: TStream) of object;
 
 
   { TFullZipFileEntries }
   { TFullZipFileEntries }
 
 
@@ -377,15 +378,17 @@ Type
 
 
   TUnZipper = Class(TObject)
   TUnZipper = Class(TObject)
   Private
   Private
+    FOnCloseInputStream: TCustomInputStreamEvent;
     FOnCreateStream: TOnCustomStreamEvent;
     FOnCreateStream: TOnCustomStreamEvent;
     FOnDoneStream: TOnCustomStreamEvent;
     FOnDoneStream: TOnCustomStreamEvent;
+    FOnOpenInputStream: TCustomInputStreamEvent;
     FUnZipping  : Boolean;
     FUnZipping  : Boolean;
     FBufSize    : LongWord;
     FBufSize    : LongWord;
     FFileName   :  String;         { Name of resulting Zip file                 }
     FFileName   :  String;         { Name of resulting Zip file                 }
     FOutputPath : String;
     FOutputPath : String;
     FEntries    : TFullZipFileEntries;
     FEntries    : TFullZipFileEntries;
     FFiles      : TStrings;
     FFiles      : TStrings;
-    FZipFile     : TFileStream;     { I/O file variables                         }
+    FZipStream  : TStream;     { I/O file variables                         }
     LocalHdr    : Local_File_Header_Type;
     LocalHdr    : Local_File_Header_Type;
     CentralHdr  : Central_File_Header_Type;
     CentralHdr  : Central_File_Header_Type;
     EndHdr      : End_of_Central_Dir_Type;
     EndHdr      : End_of_Central_Dir_Type;
@@ -418,6 +421,8 @@ Type
     Procedure Examine;
     Procedure Examine;
   Public
   Public
     Property BufferSize : LongWord Read FBufSize Write SetBufSize;
     Property BufferSize : LongWord Read FBufSize Write SetBufSize;
+    Property OnOpenInputStream: TCustomInputStreamEvent read FOnOpenInputStream write FOnOpenInputStream;
+    Property OnCloseInputStream: TCustomInputStreamEvent read FOnCloseInputStream write FOnCloseInputStream;
     Property OnCreateStream : TOnCustomStreamEvent Read FOnCreateStream Write FOnCreateStream;
     Property OnCreateStream : TOnCustomStreamEvent Read FOnCreateStream Write FOnCreateStream;
     Property OnDoneStream : TOnCustomStreamEvent Read FOnDoneStream Write FOnDoneStream;
     Property OnDoneStream : TOnCustomStreamEvent Read FOnDoneStream Write FOnDoneStream;
     Property OnPercent : Integer Read FOnPercent Write FOnPercent;
     Property OnPercent : Integer Read FOnPercent Write FOnPercent;
@@ -444,6 +449,7 @@ ResourceString
   SErrMissingArchiveName = 'Missing archive filename in streamed entry %d';
   SErrMissingArchiveName = 'Missing archive filename in streamed entry %d';
   SErrFileDoesNotExist = 'File "%s" does not exist.';
   SErrFileDoesNotExist = 'File "%s" does not exist.';
   SErrNoFileName = 'No archive filename for examine operation.';
   SErrNoFileName = 'No archive filename for examine operation.';
+  SErrNoStream = 'No stream is opened.';
 
 
 { ---------------------------------------------------------------------
 { ---------------------------------------------------------------------
     Auxiliary
     Auxiliary
@@ -1498,7 +1504,10 @@ end;
 Procedure TUnZipper.OpenInput;
 Procedure TUnZipper.OpenInput;
 
 
 Begin
 Begin
-  FZipFile:=TFileStream.Create(FFileName,fmOpenRead);
+  if Assigned(FOnOpenInputStream) then
+    FOnOpenInputStream(Self, FZipStream);
+  if FZipStream = nil then
+    FZipStream:=TFileStream.Create(FFileName,fmOpenRead);
 End;
 End;
 
 
 
 
@@ -1549,7 +1558,9 @@ end;
 Procedure TUnZipper.CloseInput;
 Procedure TUnZipper.CloseInput;
 
 
 Begin
 Begin
-  FreeAndNil(FZipFile);
+  if Assigned(FOnCloseInputStream) then
+    FOnCloseInputStream(Self, FZipStream);
+  FreeAndNil(FZipStream);
 end;
 end;
 
 
 
 
@@ -1558,18 +1569,18 @@ Var
   S : String;
   S : String;
   D : TDateTime;
   D : TDateTime;
 Begin
 Begin
-  FZipFile.Seek(Item.HdrPos,soFromBeginning);
-  FZipFile.ReadBuffer(LocalHdr,SizeOf(LocalHdr));
+  FZipStream.Seek(Item.HdrPos,soFromBeginning);
+  FZipStream.ReadBuffer(LocalHdr,SizeOf(LocalHdr));
 {$IFDEF FPC_BIG_ENDIAN}
 {$IFDEF FPC_BIG_ENDIAN}
   LocalHdr := SwapLFH(LocalHdr);
   LocalHdr := SwapLFH(LocalHdr);
 {$ENDIF}
 {$ENDIF}
   With LocalHdr do
   With LocalHdr do
     begin
     begin
       SetLength(S,Filename_Length);
       SetLength(S,Filename_Length);
-      FZipFile.ReadBuffer(S[1],Filename_Length);
+      FZipStream.ReadBuffer(S[1],Filename_Length);
       //SetLength(E,Extra_Field_Length);
       //SetLength(E,Extra_Field_Length);
-      //FZipFile.ReadBuffer(E[1],Extra_Field_Length);
-      FZipFile.Seek(Extra_Field_Length,soCurrent);
+      //FZipStream.ReadBuffer(E[1],Extra_Field_Length);
+      FZipStream.Seek(Extra_Field_Length,soCurrent);
       Item.ArchiveFileName:=S;
       Item.ArchiveFileName:=S;
       Item.DiskFileName:=S;
       Item.DiskFileName:=S;
       Item.Size:=Uncompressed_Size;
       Item.Size:=Uncompressed_Size;
@@ -1592,36 +1603,36 @@ Var
   D : TDateTime;
   D : TDateTime;
   S : String;
   S : String;
 Begin
 Begin
-  EndHdrPos:=FZipFile.Size-SizeOf(EndHdr);
+  EndHdrPos:=FZipStream.Size-SizeOf(EndHdr);
   if EndHdrPos < 0 then
   if EndHdrPos < 0 then
-    raise EZipError.CreateFmt(SErrCorruptZIP,[FZipFile.FileName]);
-  FZipFile.Seek(EndHdrPos,soFromBeginning);
-  FZipFile.ReadBuffer(EndHdr, SizeOf(EndHdr));
+    raise EZipError.CreateFmt(SErrCorruptZIP,[FileName]);
+  FZipStream.Seek(EndHdrPos,soFromBeginning);
+  FZipStream.ReadBuffer(EndHdr, SizeOf(EndHdr));
 {$IFDEF FPC_BIG_ENDIAN}
 {$IFDEF FPC_BIG_ENDIAN}
   EndHdr := SwapECD(EndHdr);
   EndHdr := SwapECD(EndHdr);
 {$ENDIF}
 {$ENDIF}
   With EndHdr do
   With EndHdr do
     begin
     begin
     if Signature <> END_OF_CENTRAL_DIR_SIGNATURE then
     if Signature <> END_OF_CENTRAL_DIR_SIGNATURE then
-      raise EZipError.CreateFmt(SErrCorruptZIP,[FZipFile.FileName]);
+      raise EZipError.CreateFmt(SErrCorruptZIP,[FileName]);
     CenDirPos:=Start_Disk_Offset;
     CenDirPos:=Start_Disk_Offset;
     end;
     end;
-  FZipFile.Seek(CenDirPos,soFrombeginning);
+  FZipStream.Seek(CenDirPos,soFrombeginning);
   FEntries.Clear;
   FEntries.Clear;
   for i:=0 to EndHdr.Entries_This_Disk-1 do
   for i:=0 to EndHdr.Entries_This_Disk-1 do
     begin
     begin
-    FZipFile.ReadBuffer(CentralHdr, SizeOf(CentralHdr));
+    FZipStream.ReadBuffer(CentralHdr, SizeOf(CentralHdr));
 {$IFDEF FPC_BIG_ENDIAN}
 {$IFDEF FPC_BIG_ENDIAN}
     CentralHdr := SwapCFH(CentralHdr);
     CentralHdr := SwapCFH(CentralHdr);
 {$ENDIF}
 {$ENDIF}
     With CentralHdr do
     With CentralHdr do
       begin
       begin
       if Signature<>CENTRAL_FILE_HEADER_SIGNATURE then
       if Signature<>CENTRAL_FILE_HEADER_SIGNATURE then
-        raise EZipError.CreateFmt(SErrCorruptZIP,[FZipFile.FileName]);
+        raise EZipError.CreateFmt(SErrCorruptZIP,[FileName]);
       NewNode:=FEntries.Add as TFullZipFileEntry;
       NewNode:=FEntries.Add as TFullZipFileEntry;
       NewNode.HdrPos := Local_Header_Offset;
       NewNode.HdrPos := Local_Header_Offset;
       SetLength(S,Filename_Length);
       SetLength(S,Filename_Length);
-      FZipFile.ReadBuffer(S[1],Filename_Length);
+      FZipStream.ReadBuffer(S[1],Filename_Length);
       NewNode.ArchiveFileName:=S;
       NewNode.ArchiveFileName:=S;
       NewNode.Size:=Uncompressed_Size;
       NewNode.Size:=Uncompressed_Size;
       NewNode.FCompressedSize:=Compressed_Size;
       NewNode.FCompressedSize:=Compressed_Size;
@@ -1634,7 +1645,7 @@ Begin
         NewNode.Attributes := External_Attributes;
         NewNode.Attributes := External_Attributes;
       ZipDateTimeToDateTime(Last_Mod_Date,Last_Mod_Time,D);
       ZipDateTimeToDateTime(Last_Mod_Date,Last_Mod_Time,D);
       NewNode.DateTime:=D;
       NewNode.DateTime:=D;
-      FZipFile.Seek(Extra_Field_Length+File_Comment_Length,soCurrent);
+      FZipStream.Seek(Extra_Field_Length+File_Comment_Length,soCurrent);
       end;
       end;
    end;
    end;
 end;
 end;
@@ -1667,14 +1678,14 @@ Var
     begin
     begin
       if (LocalHdr.Compressed_Size<>0) then
       if (LocalHdr.Compressed_Size<>0) then
         begin
         begin
-          Count:=Dest.CopyFrom(FZipFile,LocalHdr.Compressed_Size)
+          Count:=Dest.CopyFrom(FZipStream,LocalHdr.Compressed_Size)
          {$warning TODO: Implement CRC Check}
          {$warning TODO: Implement CRC Check}
         end
         end
       else
       else
         Count:=0;
         Count:=0;
     end
     end
     else
     else
-    With CreateDecompressor(Item, ZMethod, FZipFile, Dest) do
+    With CreateDecompressor(Item, ZMethod, FZipStream, Dest) do
       Try
       Try
         OnProgress:=Self.OnProgress;
         OnProgress:=Self.OnProgress;
         OnPercent:=Self.OnPercent;
         OnPercent:=Self.OnPercent;
@@ -1883,9 +1894,11 @@ end;
 
 
 procedure TUnZipper.Examine;
 procedure TUnZipper.Examine;
 begin
 begin
-  If (FFileName='') then
+  if (FOnOpenInputStream = nil) and (FFileName='') then
     Raise EZipError.Create(SErrNoFileName);
     Raise EZipError.Create(SErrNoFileName);
   OpenInput;
   OpenInput;
+  If (FZipStream=nil) then
+    Raise EZipError.Create(SErrNoStream);
   Try
   Try
     ReadZipDirectory;
     ReadZipDirectory;
   Finally
   Finally

+ 1 - 1
rtl/inc/strings.pp

@@ -160,7 +160,7 @@ implementation
          len:=strlen(p)+1;
          len:=strlen(p)+1;
          getmem(strnew,len);
          getmem(strnew,len);
          if strnew<>nil then
          if strnew<>nil then
-           strmove(strnew,p,len);
+           move(p^,strnew^,len);
       end;
       end;
 
 
     procedure strdispose(p : pchar);
     procedure strdispose(p : pchar);