uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, ToolWin, StdCtrls, ExtCtrls, SsParser, BottleDef, Menus,
- Clipbrd, Logs, ShellAPI, Commctrl, DirectSstp, Contnrs, xmldom, XMLIntf,
- XMLDoc, StrUtils, msxmldom;
+ Clipbrd, Logs, ShellAPI, Commctrl, DirectSstp, Contnrs, StrUtils;
type
TSaveLogType = (stLog, stLogWithChannels, stText, stXML);
PopupMenuTab: TPopupMenu;
mnCloseTab: TMenuItem;
tbtnFindBottle: TToolButton;
- XMLDocument: TXMLDocument;
tbtnOpenLog: TToolButton;
OpenDialog: TOpenDialog;
tbtnInsertCue: TToolButton;
//
FDragTabIndex: integer; //\83^\83u\83h\83\89\83b\83O\83h\83\8d\83b\83v\8aÖ\98A
FDragTabDest: integer; //\83h\83\8d\83b\83v\82·\82é\88Ê\92u(\82·\82®\89E\82É\82\82é\83^\83u\82Ì\83C\83\93\83f\83b\83N\83X)
+ //
procedure UpdateScript(const Script: String);
procedure UpdateScriptConversationColor(const Script: String);
procedure UpdateScriptScript(const Script: String);
SaveDialog.DefaultExt := 'xml';
SaveDialog.FilterIndex := 3;
if SaveDialog.Execute then
- SelectedBottleLog.SaveToXmlFile(SaveDialog.FileName, XMLDocument);
+ SelectedBottleLog.SaveToXmlFile(SaveDialog.FileName);
end;
procedure TfrmLog.lvwLogData(Sender: TObject; Item: TListItem);
for i := 0 to OpenDialog.Files.Count-1 do begin
BottleLog := TBottleLogList.Create(ExtractFileName(OpenDialog.Files[i]));
try
- BottleLog.LoadFromXMLFile(OpenDialog.Files[i], XMLDocument);
+ BottleLog.LoadFromXMLFile(OpenDialog.Files[i]);
except
on E: EXMLFileOpenException do begin
Beep;
uses
Contnrs, Classes, SysUtils, Dialogs, Forms, HttpThread, BottleDef,
- DateUtils, IdURI, xmldom, XMLIntf,
- msxmldom, XMLDoc;
+ DateUtils, IdURI, XDOM_2_3_J3;
type
procedure SaveToText(const FileName: String);
procedure SaveToSstpLog(const FileName: String;
const WithChannel: boolean = false);
- procedure SaveToXMLFile(const FileName: String; XMLDocument: TXMLDocument);
- procedure LoadFromXMLFile(const FileName: String; XMLDocument: TXMLDocument);
+ procedure SaveToXMLFile(const FileName: String);
+ procedure LoadFromXMLFile(const FileName: String);
end;
var
FHttpThread.Resume;
end;
-procedure TBottleLogList.LoadFromXMLFile(const FileName: String;
- XMLDocument: TXMLDocument);
-var i: integer;
+procedure TBottleLogList.LoadFromXMLFile(const FileName: String);
+var i, j, votes, agrees: integer;
Time: TDateTime;
- ANode: IXMLNode;
+ ANode, Child: TdomElement;
Item: TLogItem;
+ DOM: TdomDocument;
+ Parser: TXmlToDomParser;
+ Impl: TDomImplementation;
+ Str, mid, channel, script, ghost: String;
begin
Self.Clear;
- XMLDocument.XML.LoadFromFile(FileName);
- with XMLDocument do begin
+ Impl := TDomImplementation.create(nil);
+ try
+ Parser := TXmlToDomParser.create(nil);
+ Parser.DOMImpl := Impl;
try
- Active := true;
- except
- on E: Exception do
- raise EXMLFileOpenException.Create('\97L\8cø\82ÈXML\8c`\8e®\82Å\82Í\82 \82è\82Ü\82¹\82ñ\81B'#13#10 + E.Message);
- 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);
+ DOM := Parser.fileToDom(FileName);
+ if not DOM.validate(nil, erReplace) then
+ raise EXMLFileOpenException.Create('\97L\8cø\82È\83{\83g\83\8b\83\8d\83O\8c`\8e®\82Å\82Í\82 \82è\82Ü\82¹\82ñ\81B');
+ with DOM do
+ begin
+ 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ñ');
+ Str := DocumentElement.getAttribute('version');
+ if Str <> '1.0' then
+ raise EXMLFileOpenException.CreateFmt('\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(%s)\82Í\93Ç\82Ý\8d\9e\82ß\82Ü\82¹\82ñ', [Str]);
+
+ for i := 0 to DocumentElement.childNodes.length-1 do
+ begin
+ if documentElement.childNodes.item(i).nodeType <> ntElement_Node then
+ Continue;
+ ANode := documentElement.childNodes.item(i) as TdomElement;
+ if ANode.nodeName <> 'message' then
+ Continue;
+ mid := ANode.getAttribute('mid');
+ channel := '';
+ script := '';
+ ghost := '';
+ votes := 0;
+ agrees := 0;
+ Time := Now;
+ for j := 0 to ANode.childNodes.length-1 do
+ begin
+ if ANode.childNodes.item(j).nodeType <> ntElement_Node then
+ Continue;
+ Child := ANode.childNodes.item(j) as TdomElement;
+ if Child.nodeName = 'channel' then
+ channel := Child.textContent
+ else if Child.nodeName = 'script' then
+ script := Child.textContent
+ else if Child.nodeName = 'ghost' then
+ ghost := Child.textContent
+ else if Child.nodeName = 'votes' then
+ votes := StrToIntDef(Child.textContent, 0)
+ else if Child.nodeName = 'agrees' then
+ agrees := StrToIntDef(Child.textContent, 0)
+ else if Child.nodeName = 'date' then
+ TryStrToDateTime(Child.textContent, Time);
+ end;
+ Item := TLogItem.Create(ltBottle, mid, channel, script, ghost, time);
+ Item.Votes := votes;
+ Item.Agrees := agrees;
+ Item.State := lsOpened;
+ try
+ Self.Add(Item);
+ except
+ Item.Free;
+ end;
+ end;
end;
except
- Item.Free;
+ on E: EParserException do
+ raise EXMLFileOpenException.Create('XML\89ð\90Í\83G\83\89\81[' + E.Message);
end;
+ finally
+ Parser.DOMImpl.freeDocument(DOM);
+ Parser.Free;
end;
+ finally
+ Impl.Free;
end;
end;
end;
end;
-procedure TBottleLogList.SaveToXMLFile(const FileName: String;
- XMLDocument: TXMLDocument);
+procedure TBottleLogList.SaveToXMLFile(const FileName: String);
var i: integer;
- ANode, BNode: IXMLNode;
+ MessageNode, Child: TdomElement;
Item: TLogItem;
+ DOM: TdomDocument;
+ Parser: TXmlToDomParser;
+ Impl: TDomImplementation;
+ FS: TFileStream;
begin
- with XMLDocument do begin
+ Impl := TDomImplementation.create(nil);
+ try
+ Parser := TXmlToDomParser.create(nil);
+ Parser.DOMImpl := Impl;
+ try
+ try
+ DOM := Parser.fileToDom(ExtractFilePath(Application.ExeName)+'xbtl.dat');
+ with DOM do
+ begin
+ documentElement.setAttribute('saved',
+ FormatDateTime('yy/mm/dd hh:nn:ss', Now));
+ documentElement.setAttribute('generator', VersionString);
+ documentElement.setAttribute('version', '1.0');
+ for i := 0 to Self.Count-1 do begin
+ Item := Self.GetBottles(i);
+ MessageNode := TdomElement.create(DOM, 'message');
+ MessageNode.setAttribute('mid', Item.MID);
+ documentElement.appendChild(MessageNode);
+
+ // \93ú\95t
+ Child := createElement('date');
+ Child.appendChild(createTextNode(FormatDateTime('yy/mm/dd hh:nn:ss', Item.LogTime)));
+ MessageNode.appendChild(Child);
+ // \83`\83\83\83\93\83l\83\8b
+ Child := createElement('channel');
+ Child.appendChild(createTextNode(Item.Channel));
+ MessageNode.appendChild(Child);
+ // \83X\83N\83\8a\83v\83g
+ Child := createElement('script');
+ Child.appendChild(createTextNode(Item.Script));
+ MessageNode.appendChild(Child);
+ // \93\8a\95[
+ Child := createElement('votes');
+ Child.appendChild(createTextNode(IntToStr(Item.Votes)));
+ MessageNode.appendChild(Child);
+ // \93¯\88Ó
+ Child := createElement('agrees');
+ Child.appendChild(createTextNode(IntToStr(Item.Agrees)));
+ MessageNode.appendChild(Child);
+ // \83S\81[\83X\83g
+ Child := createElement('ghost');
+ Child.appendChild(createTextNode(Item.Ghost));
+ MessageNode.appendChild(Child);
+
+ end;
+ end;
+ FS := TFileStream.Create(FileName, fmCreate or fmShareExclusive);
+ try
+ DOM.writeCodeAsShiftJIS(FS);
+ finally
+ FS.Free;
+ end;
+ except
+ ShowMessage('xbtl.dat\82ð\8dÄ\83C\83\93\83X\83g\81[\83\8b\82µ\82Ä\82\82¾\82³\82¢\81B');
+ end;
+ finally
+ Parser.DOMImpl.freeDocument(DOM);
+ Parser.Free;
+ end;
+ finally
+ Impl.Free;
+ end;
+
+
+
+ {with XMLDocument do begin
try
XML.LoadFromFile(ExtractFilePath(Application.ExeName)+'xbtl.dat');
Active := true;
BNode.Text := Item.Ghost;
end;
end;
- XMLDocument.XML.SaveToFile(FileName);
+ XMLDocument.XML.SaveToFile(FileName);}
end;
procedure TBottleLogList.SetOnLoaded(const Value: TNotifyEvent);