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);
   {$else}
     GetFAttr(s^.gzfile, Attr);
-    exists:=(DosError= 0)
+    exists:=(DosError= 0);
   {$endif}
   
   doseek:=false;
   if ((s^.mode='a') and not exists) or (s^.mode='w') then
+    begin
+   
     ReWrite (s^.gzfile,1)  
+    end
   else
     begin
       Reset (s^.gzfile,1);  
@@ -247,7 +250,9 @@ begin
   // append binary file.
   if doseek then
      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 }
 {$IFNDEF NO_DEFLATE}
     gzheader [0] := gz_magic [0];

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

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

+ 1 - 1
rtl/inc/strings.pp

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