From 503d89d9cb7aad0d9fc31ef716ab0546a608dff3 Mon Sep 17 00:00:00 2001 From: naru Date: Wed, 4 Dec 2002 13:26:49 +0000 Subject: [PATCH] SaveToXMLFile --- bottleclient/Logs.pas | 55 ++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/bottleclient/Logs.pas b/bottleclient/Logs.pas index 59968bd..91ac989 100755 --- a/bottleclient/Logs.pas +++ b/bottleclient/Logs.pas @@ -48,6 +48,8 @@ type TBottleLogSortType = (stLogTime, stChannel, stScript, stVote, stAgree); TBottleLogLoadFailureEvent = procedure(Sender: TObject; const Message: String) of object; + EXMLFileOpenException = class(Exception); + TBottleLogList = class(TObjectList) private FOnLoaded: TNotifyEvent; @@ -83,7 +85,8 @@ type 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 @@ -246,8 +249,8 @@ procedure TBottleLogList.HttpSuccess(Sender: TObject); var Stream: TStringStream; StrList: TStringList; begin - Stream := nil; StrList := nil; + Stream := nil; try Stream := TStringStream.Create(FHttpThread.RecvString); StrList := TStringList.Create; @@ -347,6 +350,52 @@ begin 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('—LŒø‚ÈXMLŒ`Ž®‚Å‚Í‚ ‚è‚Ü‚¹‚ñ'); + end; + if DocumentElement = nil then + raise EXMLFileOpenException.Create('—LŒø‚ÈŒ`Ž®‚Å‚Í‚ ‚è‚Ü‚¹‚ñBƒ‹[ƒgƒ^ƒO‚ª‚ ‚è‚Ü‚¹‚ñ'); + if DocumentElement.NodeName <> 'bottlelog' then + raise EXMLFileOpenException.Create('—LŒø‚ÈŒ`Ž®‚Å‚Í‚ ‚è‚Ü‚¹‚ñBbottlelog‚ªŒ©‚‚©‚è‚Ü‚¹‚ñ'); + if DocumentElement.Attributes['version'] <> '1.0' then + raise EXMLFileOpenException.Create('—LŒø‚ÈŒ`Ž®‚Å‚Í‚ ‚è‚Ü‚¹‚ñB‚±‚̃ƒOƒtƒ@ƒCƒ‹‚̃o[ƒWƒ‡ƒ“‚͓ǂݍž‚ß‚Ü‚¹‚ñ'); + 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; @@ -393,7 +442,7 @@ begin end; end; -procedure TBottleLogList.SaveToXmlFile(const FileName: String; +procedure TBottleLogList.SaveToXMLFile(const FileName: String; XMLDocument: TXMLDocument); var i: integer; ANode, BNode: IXMLNode; -- 2.11.0