|
@@ -45,6 +45,7 @@ Type
|
|
FOwnsStreams: Boolean;
|
|
FOwnsStreams: Boolean;
|
|
function GetStream(aIndex : Integer): TStream;
|
|
function GetStream(aIndex : Integer): TStream;
|
|
function GetStreamCount: Integer;
|
|
function GetStreamCount: Integer;
|
|
|
|
+ function IsValidStreamIndex(aIndex: Integer): Boolean;
|
|
Protected
|
|
Protected
|
|
Function CurrentStream : TStream;
|
|
Function CurrentStream : TStream;
|
|
Function StreamSize : Int64;
|
|
Function StreamSize : Int64;
|
|
@@ -74,16 +75,22 @@ begin
|
|
Result:=Length(FStreams);
|
|
Result:=Length(FStreams);
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+function TChainedStream.IsValidStreamIndex(aIndex : Integer) : Boolean;
|
|
|
|
+
|
|
|
|
+begin
|
|
|
|
+ Result:=(aIndex>=0) and (aIndex<Length(FStreams));
|
|
|
|
+end;
|
|
|
|
+
|
|
function TChainedStream.GetStream(aIndex : Integer): TStream;
|
|
function TChainedStream.GetStream(aIndex : Integer): TStream;
|
|
begin
|
|
begin
|
|
- if (aIndex<0) or (aIndex>=Length(FStreams)) then
|
|
|
|
|
|
+ if not IsValidStreamIndex(aIndex) then
|
|
Raise EListError.CreateFmt(SListIndexError,[aIndex]);
|
|
Raise EListError.CreateFmt(SListIndexError,[aIndex]);
|
|
Result:=FStreams[aIndex].Stream;
|
|
Result:=FStreams[aIndex].Stream;
|
|
end;
|
|
end;
|
|
|
|
|
|
function TChainedStream.CurrentStream: TStream;
|
|
function TChainedStream.CurrentStream: TStream;
|
|
begin
|
|
begin
|
|
- if FCurrentStreamIdx<Length(FStreams) then
|
|
|
|
|
|
+ if IsValidStreamIndex(FCurrentStreamIdx) then
|
|
Result:=FStreams[FCurrentStreamIdx].Stream
|
|
Result:=FStreams[FCurrentStreamIdx].Stream
|
|
else
|
|
else
|
|
Result:=Nil;
|
|
Result:=Nil;
|
|
@@ -91,7 +98,7 @@ end;
|
|
|
|
|
|
function TChainedStream.StreamSize: Int64;
|
|
function TChainedStream.StreamSize: Int64;
|
|
begin
|
|
begin
|
|
- if FCurrentStreamIdx<Length(FStreams) then
|
|
|
|
|
|
+ if IsValidStreamIndex(FCurrentStreamIdx) then
|
|
begin
|
|
begin
|
|
if FStreams[FCurrentStreamIdx].Size=-1 then
|
|
if FStreams[FCurrentStreamIdx].Size=-1 then
|
|
FStreams[FCurrentStreamIdx].Size:=FStreams[FCurrentStreamIdx].Stream.Size;
|
|
FStreams[FCurrentStreamIdx].Size:=FStreams[FCurrentStreamIdx].Stream.Size;
|
|
@@ -104,13 +111,13 @@ end;
|
|
function TChainedStream.NextStream: Boolean;
|
|
function TChainedStream.NextStream: Boolean;
|
|
begin
|
|
begin
|
|
Inc(FCurrentStreamIdx);
|
|
Inc(FCurrentStreamIdx);
|
|
- Result:=FCurrentStreamIdx<Length(FStreams);
|
|
|
|
|
|
+ Result:=IsValidStreamIndex(FCurrentStreamIdx);
|
|
end;
|
|
end;
|
|
|
|
|
|
function TChainedStream.PrevStream: Boolean;
|
|
function TChainedStream.PrevStream: Boolean;
|
|
begin
|
|
begin
|
|
Dec(FCurrentStreamIdx);
|
|
Dec(FCurrentStreamIdx);
|
|
- Result:=FCurrentStreamIdx>=0;
|
|
|
|
|
|
+ Result:=IsValidStreamIndex(FCurrentStreamIdx);
|
|
end;
|
|
end;
|
|
|
|
|
|
function TChainedStream.GetTotalSize: Int64;
|
|
function TChainedStream.GetTotalSize: Int64;
|
|
@@ -228,19 +235,25 @@ Var
|
|
|
|
|
|
Procedure MoveForward(aStartPos : Int64; aOrigin : TSeekOrigin);
|
|
Procedure MoveForward(aStartPos : Int64; aOrigin : TSeekOrigin);
|
|
|
|
|
|
|
|
+ var
|
|
|
|
+ aSize : Int64;
|
|
|
|
+
|
|
begin
|
|
begin
|
|
- while (aOff>StreamSize-aStartPos) do
|
|
|
|
|
|
+ aSize:=StreamSize;
|
|
|
|
+ while (aOff>aSize-aStartPos) do
|
|
begin
|
|
begin
|
|
- Dec(aOff,StreamSize-aStartPos);
|
|
|
|
- Inc(FPosition,StreamSize-aStartPos);
|
|
|
|
|
|
+ Dec(aOff,aSize-aStartPos);
|
|
|
|
+ Inc(FPosition,aSize-aStartPos);
|
|
if not NextStream then
|
|
if not NextStream then
|
|
Break;
|
|
Break;
|
|
aStartPos:=0;
|
|
aStartPos:=0;
|
|
|
|
+ aSize:=StreamSize;
|
|
end;
|
|
end;
|
|
if CurrentStream=Nil then
|
|
if CurrentStream=Nil then
|
|
FCurrentStreamIdx:=Length(FStreams)-1;
|
|
FCurrentStreamIdx:=Length(FStreams)-1;
|
|
- if aOff>StreamSize then
|
|
|
|
- aOff:=StreamSize;
|
|
|
|
|
|
+ aSize:=StreamSize;
|
|
|
|
+ if aOff>aSize then
|
|
|
|
+ aOff:=aSize;
|
|
inc(FPosition,aOff);
|
|
inc(FPosition,aOff);
|
|
Result:=FPosition;
|
|
Result:=FPosition;
|
|
CurrentStream.Seek(aOff,aOrigin);
|
|
CurrentStream.Seek(aOff,aOrigin);
|