Buffer class changes/bugfix for log roller and fido export

This commit is contained in:
g00r00 2013-10-01 21:24:44 -04:00
parent 024c502d9f
commit afa47cad86
1 changed files with 24 additions and 3 deletions

View File

@ -63,6 +63,7 @@ Type
TFileBufferOpenType = ( TFileBufferOpenType = (
fmOpen, fmOpen,
fmOpenCreate, fmOpenCreate,
fmOpenAppend,
fmCreate fmCreate
); );
@ -93,7 +94,7 @@ Type
Procedure ReadBlock (Var Buf; Size: LongInt); Overload; Procedure ReadBlock (Var Buf; Size: LongInt); Overload;
Procedure ReadRecord (Var Buf); Procedure ReadRecord (Var Buf);
Procedure SeekRecord (RP: LongInt); Procedure SeekRecord (RP: LongInt);
Procedure SeekRaw ( FP : LongInt); Procedure SeekRaw (FP: LongInt);
Procedure WriteBlock (Var Buf; Size: LongInt); Procedure WriteBlock (Var Buf; Size: LongInt);
Procedure WriteRecord (Var Buf); Procedure WriteRecord (Var Buf);
@ -596,7 +597,8 @@ Begin
Case OpenType of Case OpenType of
fmOpen : If Not ioReset (InFile, 1, OpenMode) Then Exit; fmOpen : If Not ioReset (InFile, 1, OpenMode) Then Exit;
fmOpenCreate : If Not ioReset (InFile, 1, OpenMode) Then fmOpenCreate,
fmOpenAppend : If Not ioReset (InFile, 1, OpenMode) Then
If Not FileExist(FN) Then Begin If Not FileExist(FN) Then Begin
If Not ioReWrite (InFile, 1, OpenMode) Then Exit; If Not ioReWrite (InFile, 1, OpenMode) Then Exit;
End Else End Else
@ -604,6 +606,9 @@ Begin
fmCreate : If Not ioReWrite (InFile, 1, OpenMode) Then Exit; fmCreate : If Not ioReWrite (InFile, 1, OpenMode) Then Exit;
End; End;
If OpenType = fmOpenAppend Then
ioSeek (InFile, System.FileSize(InFile));
GetMem (Buffer, BufSize); GetMem (Buffer, BufSize);
FillBuffer; FillBuffer;
@ -706,14 +711,28 @@ Begin
Offset := BufSize - BufPos; Offset := BufSize - BufPos;
If Offset > 0 Then If Offset > 0 Then
Move(Buf, Buffer^[BufPos], Offset); Move (Buf, Buffer^[BufPos], Offset);
BufRead := BufSize;
FlushBuffer; FlushBuffer;
// -----
Move (TFileBufferRec(Buf)[Offset], Buffer^[0], Size - Offset);
BufStart := System.FilePos(InFile);
BufEnd := BufStart + Size - Offset;
BufPos := Size - Offset;
BufEOF := System.EOF(InFile);
BufRead := BufPos;
(* the above replaces the 3 lines below... but is it reliable?
FillBuffer; FillBuffer;
Move (TFileBufferRec(Buf)[Offset], Buffer^[BufPos], Size - Offset); Move (TFileBufferRec(Buf)[Offset], Buffer^[BufPos], Size - Offset);
BufPos := BufPos + Size - Offset; BufPos := BufPos + Size - Offset;
*)
End Else Begin End Else Begin
Move (Buf, Buffer^[BufPos], Size); Move (Buf, Buffer^[BufPos], Size);
Inc (BufPos, Size); Inc (BufPos, Size);
@ -778,12 +797,14 @@ End;
Function TFileBuffer.FileSizeRaw : LongInt; Function TFileBuffer.FileSizeRaw : LongInt;
Begin Begin
If BufDirty Then FlushBuffer; If BufDirty Then FlushBuffer;
Result := System.FileSize(InFile); Result := System.FileSize(InFile);
End; End;
Function TFileBuffer.FileSizeRecord : LongInt; Function TFileBuffer.FileSizeRecord : LongInt;
Begin Begin
If BufDirty Then FlushBuffer; If BufDirty Then FlushBuffer;
Result := System.FileSize(InFile) DIV RecSize; Result := System.FileSize(InFile) DIV RecSize;
End; End;