X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fshared%2Fxstreams.pas;h=81a104cc9e33be77409318c25766fcdc5b0382b3;hb=b744498c3f6d4d30731c74ba376e15e71de9b610;hp=e7e70e70ef79769651fb825edf1243e1f243ef3d;hpb=b8fa6d703be4f383a2be1f3ed093a597c2ad6829;p=d2df-sdl.git diff --git a/src/shared/xstreams.pas b/src/shared/xstreams.pas index e7e70e7..81a104c 100644 --- a/src/shared/xstreams.pas +++ b/src/shared/xstreams.pas @@ -1,6 +1,21 @@ +(* Copyright (C) DooM 2D:Forever Developers + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + *) // special stream classes -{$MODE DELPHI} -{$R+} +{$INCLUDE a_modes.inc} +{.$R+} unit xstreams; interface @@ -301,9 +316,10 @@ begin fSize := aSize; GetMem(fBuffer, ZBufSize); fSkipHeader := aSkipHeader; + fSrcStPos := fSrcSt.position; + FillChar(fZlibSt, sizeof(fZlibSt), 0); if fSkipHeader then err := inflateInit2(fZlibSt, -MAX_WBITS) else err := inflateInit(fZlibSt); if err <> Z_OK then raise XStreamError.Create(zerror(err)); - fSrcStPos := fSrcSt.position; end; @@ -322,6 +338,7 @@ var sz: LongInt; begin result := 0; + if (fSize >= 0) and (fPos >= fSize) then exit; if count > 0 then begin fZlibSt.next_out := @buffer; @@ -360,7 +377,7 @@ begin //writeln(' reading ', rd, ' bytes...'); rr := readBuf(buf, rd); //writeln(' got ', rr, ' bytes; fPos=', fPos, '; fSkipToPos=', fSkipToPos); - if rd <> rr then raise XStreamError.Create('seek error'); + if rr <= 0 then raise XStreamError.Create('seek error'); end; //writeln(' pos: fPos=', fPos, '; fSkipToPos=', fSkipToPos); fSkipToPos := -1; @@ -380,12 +397,12 @@ begin while true do begin rd := readBuf(buf, 4096); - if rd <> 4096 then break; + if rd = 0 then break; end; fSize := fPos; //writeln(' unzstream size is ', fSize); finally - fSkipToPos := opos; + if fSkipToPos < 0 then fSkipToPos := opos; end; end; @@ -408,9 +425,11 @@ procedure TUnZStream.reset (); var err: Integer; begin + //writeln('doing RESET'); fSrcSt.position := fSrcStPos; fPos := 0; inflateEnd(fZlibSt); + FillChar(fZlibSt, sizeof(fZlibSt), 0); if fSkipHeader then err := inflateInit2(fZlibSt, -MAX_WBITS) else err := inflateInit(fZlibSt); if err <> Z_OK then raise XStreamError.Create(zerror(err)); end;