mysticbbs/mdl/m_protocol_queue.pas

171 lines
3.8 KiB
ObjectPascal
Raw Normal View History

// ====================================================================
// Mystic BBS Software Copyright 1997-2013 By James Coyle
// ====================================================================
//
// This file is part of Mystic BBS.
//
// Mystic BBS 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.
//
// Mystic BBS 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 Mystic BBS. If not, see <http://www.gnu.org/licenses/>.
//
// ====================================================================
2012-08-08 10:52:56 -07:00
Unit m_Protocol_Queue;
{$I M_OPS.PAS}
Interface
Const
QueueMaxSize = 100;
QueueMaxPathSize = 120;
QueueMaxNameSize = 120;
QueuePending = 0;
QueueSuccess = 1;
QueueFailed = 2;
QueueInTransit = 3;
QueueSkipped = 4;
QueueNoFile = 5;
Type
TProtocolQueuePTR = ^TProtocolQueueRec;
TProtocolQueueRec = Record
FilePath : String[QueueMaxPathSize];
FileName : String[QueueMaxNameSize];
2013-04-06 20:58:33 -07:00
FileNew : String[QueueMaxNameSize];
2013-09-23 17:37:27 -07:00
Extra : String[QueueMaxPathSize];
2012-08-08 10:52:56 -07:00
FileSize : Int64;
Status : Byte;
End;
TProtocolQueue = Class
2013-03-24 02:45:47 -07:00
QFSize : Cardinal;
QSize : Word;
QPos : Word;
QData : Array[1..QueueMaxSize] of TProtocolQueuePTR;
2012-08-08 10:52:56 -07:00
Constructor Create;
Destructor Destroy; Override;
2013-05-26 17:52:36 -07:00
Function Add (CheckValid: Boolean; fPath, fName, fNew: String) : Boolean;
2012-08-08 10:52:56 -07:00
Procedure Delete (Idx: Word);
Procedure Clear;
Function Next : Boolean;
End;
Implementation
Constructor TProtocolQueue.Create;
Begin
Inherited Create;
2013-03-24 02:45:47 -07:00
QFSize := 0;
QSize := 0;
QPos := 0;
2012-08-08 10:52:56 -07:00
End;
Destructor TProtocolQueue.Destroy;
Begin
Clear;
End;
2013-05-26 17:52:36 -07:00
Function TProtocolQueue.Add (CheckValid: Boolean; fPath, fName, fNew: String) : Boolean;
2012-08-08 10:52:56 -07:00
Var
F : File;
Begin
2013-03-24 02:45:47 -07:00
Result := False;
2012-08-08 10:52:56 -07:00
If (QSize = QueueMaxSize) Then Exit;
Inc (QSize);
New (QData[QSize]);
QData[QSize]^.FilePath := fPath;
QData[QSize]^.FileName := fName;
2013-04-06 20:58:33 -07:00
QData[QSize]^.FileNew := fNew;
2012-08-08 10:52:56 -07:00
QData[Qsize]^.FileSize := 0;
2013-04-06 20:58:33 -07:00
If fNew = '' Then
QData[QSize]^.FileNew := fName;
2012-08-08 10:52:56 -07:00
Assign (F, fPath + fName);
{$I-} Reset(F, 1); {$I+}
2012-08-11 09:50:14 -07:00
2012-08-08 10:52:56 -07:00
If IoResult = 0 Then Begin
QData[QSize]^.FileSize := FileSize(F);
QData[QSize]^.Status := QueuePending;
2013-03-24 02:45:47 -07:00
Inc (QFSize, QData[QSize]^.FileSize);
2012-08-08 10:52:56 -07:00
Close(F);
2013-05-26 17:52:36 -07:00
End Else
If CheckValid Then Begin
2013-03-24 02:45:47 -07:00
Dispose (QData[QSize]);
Dec (QSize);
Exit;
2013-05-26 17:52:36 -07:00
End Else
QData[QSize]^.Status := QueueNoFile;
2013-03-24 02:45:47 -07:00
Result := True;
2012-08-08 10:52:56 -07:00
End;
Procedure TProtocolQueue.Delete (Idx: Word);
Var
Count : Word;
Begin
If QData[Idx] <> NIL Then Begin
2013-03-24 02:45:47 -07:00
Dec (QFSize, QData[QSize]^.FileSize);
2012-08-08 10:52:56 -07:00
Dispose (QData[Idx]);
For Count := Idx To QueueMaxSize - 1 Do
QData[Count] := QData[Count + 1];
Dec (QSize);
If QPos >= Idx Then Dec(QPos);
End;
End;
Function TProtocolQueue.Next : Boolean;
Begin
Next := False;
If QPos < QSize Then
Repeat
Inc (QPos);
If QData[QPos]^.Status <> QueueNoFile Then Begin
Next := True;
Break;
End;
Until (QPos = QSize);
End;
Procedure TProtocolQueue.Clear;
Var
Count : Word;
Begin
For Count := 1 to QSize Do Begin
Dispose (QData[Count]);
QData[Count] := NIL;
End;
2013-03-24 02:45:47 -07:00
QFSize := 0;
QSize := 0;
QPos := 0;
2012-08-08 10:52:56 -07:00
End;
End.