Permalink
Browse files

^ GpDelphiUnits rev. 55

  • Loading branch information...
mremec
mremec committed May 2, 2013
1 parent 6c1a8b5 commit bba27f3129561cf0d2c09b730535b05cc3da7d1b
Showing with 3,599 additions and 502 deletions.
  1. +78 −7 GpStreamWrapper.pas
  2. +222 −27 GpTextStream.pas
  3. +3,037 −336 extras/DSiWin32.pas
  4. +44 −14 extras/GpSecurity.pas
  5. +49 −31 extras/GpSharedMemory.pas
  6. +169 −87 extras/GpSync.pas
View
@@ -3,16 +3,18 @@
(*:Some useful stream wrappers.
@author Primoz Gabrijelcic
@desc <pre>
(c) 2006 Primoz Gabrijelcic
(c) 2012 Primoz Gabrijelcic
Free for personal and commercial use. No rights reserved.
Author : Primoz Gabrijelcic
Creation date : 2001-07-17
Last modification: 2006-09-21
Version : 1.04
Last modification: 2012-04-24
Version : 1.05
</pre>
*)(*
History:
1.05: 2012-04-24
- Added overload for 64-bit Seek.
1.04: 2006-09-21
- TGpStreamWindow class moved to the GpStreams unit.
1.03: 2006-08-31
@@ -48,6 +50,11 @@ TGpStreamWrapper = class(TStream)
swSeekOffset : longint;
swStoredPosition: longint;
swStream : TStream;
{$IFDEF D6Plus}
private
swDelayedSeek64 : boolean;
swSeekOrigin : TSeekOrigin;
{$ENDIF D6Plus}
protected
function GetPosition: {$IFDEF D6PLUS}int64;{$ELSE}longint;{$ENDIF D6PLUS} virtual;
function GetSize: {$IFDEF D6PLUS}int64; override;{$ELSE}longint; virtual;{$ENDIF D6PLUS}
@@ -61,7 +68,9 @@ TGpStreamWrapper = class(TStream)
constructor Create(wrappedStream: TStream);
procedure DelayedSeek; virtual;
function Seek(offset: integer; mode: word): longint; {$IFDEF D6PLUS}overload;{$ENDIF D6PLUS} override;
{:Wrapped (underlying) stream.}
{$IFDEF D6Plus}
function Seek(const offset: int64; origin: TSeekOrigin): int64; overload; override;
{$ENDIF D6Plus} {:Wrapped (underlying) stream.}
property WrappedStream: TStream read swStream;
end; { TGpStreamWrapper }
@@ -80,9 +89,17 @@ constructor TGpStreamWrapper.Create(wrappedStream: TStream);
}
procedure TGpStreamWrapper.DelayedSeek;
begin
{$IFDEF D6Plus}
if swDelayedSeek64 then begin
if (swSeekOffset <> 0) or (swSeekOrigin <> soCurrent) then
WrappedSeek(swSeekOffset, swSeekOrigin);
swDelayedSeek64 := false;
end
else
{$ENDIF D6Plus}
if swDelayedSeek then begin
if (swSeekOffset <> 0) or (swSeekMode <> soFromCurrent) then
WrappedSeek(swSeekOffset,swSeekMode);
WrappedSeek(swSeekOffset, swSeekMode);
swDelayedSeek := false;
end;
end; { TGpStreamWrapper.DelayedSeek }
@@ -161,6 +178,60 @@ function TGpStreamWrapper.Seek(offset: longint; mode: word): longint;
end;
end; { TGpStreamWrapper.Seek }
{:Repositions stream pointer. Actually only stores this information for later
use (when stream pointer position is really used).
@param offset Offset from start, current position, or end of stream (as set
by the 'mode' parameter) in bytes.
@param mode Specifies starting point for offset calculation
(soFromBeginning, soFromCurrent, soFromEnd).
@returns New position of stream pointer.
}
function TGpStreamWrapper.Seek(const offset: int64; origin: TSeekOrigin): int64;
begin
// TStream is using following code to get Size of the stream:
// Pos := Seek(0, soFromCurrent);
// Result := Seek(0, soFromEnd);
// Seek(Pos, soFromBeginning);
// This code tries to hack around this stupid behaviour.
if not swDelayedSeek64 then begin
if (origin = soCurrent) and (offset = 0) then begin
// possible GetSize call
swDelayedSeek64 := true;
swSeekOffset := offset;
swSeekOrigin := origin;
swStoredPosition := GetPosition;
Result := swStoredPosition;
end
else // not a GetSize call, forward it
Result := WrappedSeek(offset, origin);
end
else begin
if origin = soCurrent then
// not a GetSize call; saved Seek can only be (0, fromCurrent) - it is not
// necessary to call DelayedSeek
Result := WrappedSeek(offset, origin)
else if origin = soEnd then begin
if swSeekOrigin = soCurrent then begin
// possible GetSize call
swSeekOffset := offset;
swSeekOrigin := origin;
Result := GetSize;
end
else // not a GetSize call
Result := WrappedSeek(offset, origin);
end
else {if mode = soBeginning} begin
if (swSeekOrigin = soEnd) and (swStoredPosition = offset) then begin
// definitely GetSize call
swDelayedSeek64 := false;
Result := swStoredPosition;
end
else // not a GetSize call
Result := WrappedSeek(offset, origin);
end;
end;
end; { TGpStreamWrapper.Seek }
{:Sets the position in the wrapping (virtual) stream. Trivial implementation
from this class sets position of the wrapped (underlying) stream.
If descendant overrides this method, it must never call TGpStreamWrapper.Seek
@@ -192,11 +263,11 @@ function TGpStreamWrapper.WrappedSeek(offset: integer;
Result := WrappedStream.Seek(offset, mode);
end; { TGpStreamWrapper.WrappedSeek }
{$IFDEF D6PLUS}
{$IFDEF D6Plus}
function TGpStreamWrapper.WrappedSeek(offset: int64; origin: TSeekOrigin): int64;
begin
Result := WrappedStream.Seek(offset, origin);
end;
{$ENDIF D6PLUS}
{$ENDIF D6Plus}
end.
Oops, something went wrong.

0 comments on commit bba27f3

Please sign in to comment.