TBottleLogSortType = (stLogTime, stChannel, stScript, stVote, stAgree);
TBottleLogLoadFailureEvent = procedure(Sender: TObject; const Message: String) of object;
+ EXMLFileOpenException = class(Exception);
+
TBottleLogList = class(TObjectList)
private
FOnLoaded: TNotifyEvent;
procedure SaveToText(const FileName: String);
procedure SaveToSstpLog(const FileName: String;
const WithChannel: boolean = false);
- procedure SaveToXmlFile(const FileName: String; XmlDocument: TXmlDocument);
+ procedure SaveToXMLFile(const FileName: String; XMLDocument: TXMLDocument);
+ procedure LoadFromXMLFile(const FileName: String; XMLDocument: TXMLDocument);
end;
var
var Stream: TStringStream;
StrList: TStringList;
begin
- Stream := nil;
StrList := nil;
+ Stream := nil;
try
Stream := TStringStream.Create(FHttpThread.RecvString);
StrList := TStringList.Create;
FHttpThread.Resume;
end;
+procedure TBottleLogList.LoadFromXMLFile(const FileName: String;
+ XMLDocument: TXMLDocument);
+var i: integer;
+ Time: TDateTime;
+ ANode: IXMLNode;
+ Item: TLogItem;
+begin
+ Self.Clear;
+ XMLDocument.XML.LoadFromFile(FileName);
+ with XMLDocument do begin
+ try
+ Active := true;
+ except
+ raise EXMLFileOpenException.Create('\97L\8cø\82ÈXML\8c`\8e®\82Å\82Í\82 \82è\82Ü\82¹\82ñ');
+ end;
+ if DocumentElement = nil then
+ raise EXMLFileOpenException.Create('\97L\8cø\82È\8c`\8e®\82Å\82Í\82 \82è\82Ü\82¹\82ñ\81B\83\8b\81[\83g\83^\83O\82ª\82 \82è\82Ü\82¹\82ñ');
+ if DocumentElement.NodeName <> 'bottlelog' then
+ raise EXMLFileOpenException.Create('\97L\8cø\82È\8c`\8e®\82Å\82Í\82 \82è\82Ü\82¹\82ñ\81Bbottlelog\82ª\8c©\82Â\82©\82è\82Ü\82¹\82ñ');
+ if DocumentElement.Attributes['version'] <> '1.0' then
+ raise EXMLFileOpenException.Create('\97L\8cø\82È\8c`\8e®\82Å\82Í\82 \82è\82Ü\82¹\82ñ\81B\82±\82Ì\83\8d\83O\83t\83@\83C\83\8b\82Ì\83o\81[\83W\83\87\83\93\82Í\93Ç\82Ý\8d\9e\82ß\82Ü\82¹\82ñ');
+ for i := 0 to DocumentElement.ChildNodes.Count-1 do begin
+ ANode := DocumentElement.ChildNodes[i];
+ Item := nil;
+ try
+ if TryStrToDateTime(ANode.ChildValues['date'], Time) then begin
+ Item := TLogItem.Create(
+ ltBottle,
+ ANode.Attributes['mid'],
+ ANode.ChildNodes['channel'].Text,
+ ANode.ChildNodes['script'].Text,
+ ANode.ChildNodes['ghost'].Text,
+ Time,
+ );
+ Item.Votes := StrToIntDef(ANode.ChildNodes['votes'].Text, 0);
+ Item.Agrees := StrToIntDef(ANode.ChildNodes['agrees'].Text, 0);
+ Item.State := lsOpened;
+ Self.Add(Item);
+ end;
+ except
+ Item.Free;
+ end;
+ end;
+ end;
+end;
+
procedure TBottleLogList.SaveToSstpLog(const FileName: String;
const WithChannel: boolean = false);
var i: integer;
end;
end;
-procedure TBottleLogList.SaveToXmlFile(const FileName: String;
+procedure TBottleLogList.SaveToXMLFile(const FileName: String;
XMLDocument: TXMLDocument);
var i: integer;
ANode, BNode: IXMLNode;