mysticbbs/mystic/mutil_msgpurge.pas

122 lines
3.1 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-09-08 01:27:43 -07:00
Unit MUTIL_MsgPurge;
{$I M_OPS.PAS}
Interface
Procedure uPurgeMessageBases;
Implementation
Uses
m_Strings,
2012-09-25 16:20:59 -07:00
m_DateTime,
2012-09-08 01:27:43 -07:00
mUtil_Common,
2012-09-25 16:20:59 -07:00
mUtil_Status,
2013-08-29 03:04:20 -07:00
bbs_Records,
BBS_DataBase,
2012-09-25 16:20:59 -07:00
bbs_MsgBase_ABS,
bbs_MsgBase_JAM,
bbs_MsgBase_Squish;
2012-09-08 01:27:43 -07:00
Procedure uPurgeMessageBases;
2012-09-25 16:20:59 -07:00
Var
PurgeTotal : LongInt = 0;
PurgeBase : LongInt;
BaseFile : File of RecMessageBase;
Base : RecMessageBase;
MsgBase : PMsgBaseABS;
2012-09-08 01:27:43 -07:00
Begin
ProcessName ('Purging Message Bases', True);
ProcessResult (rWORKING, False);
Assign (BaseFile, bbsCfg.DataPath + 'mbases.dat');
2012-09-25 16:20:59 -07:00
{$I-} Reset (BaseFile); {$I+}
If IoResult = 0 Then Begin
While Not Eof(BaseFile) Do Begin
Read (BaseFile, Base);
ProcessStatus (Base.Name, False);
BarOne.Update (FilePos(BaseFile), FileSize(BaseFile));
PurgeBase := 0;
2012-09-26 13:51:07 -07:00
If Not MessageBaseOpen(MsgBase, Base) Then Continue;
2012-09-25 16:20:59 -07:00
If Base.MaxAge > 0 Then Begin
MsgBase^.SeekFirst(1);
While MsgBase^.SeekFound Do Begin
MsgBase^.MsgStartUp;
If MsgBase^.IsDeleted Then Begin
MsgBase^.SeekNext;
Continue;
End;
If DaysAgo(DateStr2Julian(MsgBase^.GetDate), 1) > Base.MaxAge Then Begin
MsgBase^.DeleteMsg;
Inc (PurgeTotal);
Inc (PurgeBase);
End;
MsgBase^.SeekNext;
End;
End;
If Base.MaxMsgs > 0 Then Begin
MsgBase^.SeekFirst(1);
While MsgBase^.SeekFound And (MsgBase^.NumberOfMsgs > Base.MaxMsgs) Do Begin
MsgBase^.MsgStartUp;
If Not MsgBase^.IsDeleted Then Begin
MsgBase^.DeleteMsg;
Inc (PurgeTotal);
Inc (PurgeBase);
End;
MsgBase^.SeekNext;
End;
End;
MsgBase^.CloseMsgBase;
Dispose (MsgBase, Done);
Log (2, '+', ' Purged ' + strI2S(PurgeBase));
End;
Close (BaseFile);
End;
ProcessStatus ('Purged |15' + strI2S(PurgeTotal) + ' |07messages', True);
2012-09-08 01:27:43 -07:00
ProcessResult (rDONE, True);
End;
End.