6 Contnrs, Controls, Classes, SysUtils, Dialogs, Forms, HttpThread, BottleDef,
7 DateUtils, SsParser, XDOM_2_3_J3, Graphics, SppList;
11 TLogType = (ltBottle, ltSystemLog);
12 TLogState = (lsUnopened, lsPlaying, lsOpened);
14 THasURL = (huUndefined, huYes, huNo);
16 TLogItem = class(TPersistent)
28 procedure SetChannel(const Value: String);
29 procedure SetLogType(const Value: TLogType);
30 procedure SetMID(const Value: String);
31 procedure SetScript(const Value: String);
32 procedure SetLogTime(const Value: TDateTime);
33 procedure SetGhost(const Value: String);
34 procedure SetVotes(const Value: Integer);
35 procedure SetAgreements(const Value: Integer);
36 procedure SetState(const Value: TLogState);
37 procedure SetHasURL(const Value: THasURL);
39 constructor Create(LogType: TLogType; const MID, Channel, Script,
40 Ghost: String; LogTime: TDateTime); overload;
41 constructor Create(Source: TLogItem); overload;
42 property LogType: TLogType read FLogType write SetLogType;
43 property MID: String read FMID write SetMID;
44 property Channel: String read FChannel write SetChannel;
45 property LogTime: TDateTime read FLogTime write SetLogTime;
46 property Script: String read FScript write SetScript;
47 property Ghost: String read FGhost write SetGhost;
48 property Votes: Integer read FVotes write SetVotes;
49 property Agrees: Integer read FAgreements write SetAgreements;
50 property State: TLogState read FState write SetState;
51 property HasURL: THasURL read FHasURL write SetHasURL;
52 procedure Assign(Source: TPersistent); override;
55 TBottleLogSortType = (stLogTime, stChannel, stGhost, stScript, stVote, stAgree);
56 TBottleLogLoadFailureEvent = procedure(Sender: TObject; const Message: String) of object;
57 TBottleLogHTMLOutputWork = procedure(Sender: TObject; const Count: integer;
58 var Canceled: boolean) of object;
60 EXMLFileOpenException = class(Exception);
62 TBottleLogDownLoadCondition = packed record
72 TLogXMLThread = class(TThread)
76 FOnLoadFailure: TBottleLogLoadFailureEvent;
77 FOnLoaded: TNotifyEvent;
78 FLoadFailureMessage: String;
79 procedure SetOnLoaded(const Value: TNotifyEvent);
80 procedure SetOnLoadFailure(const Value: TBottleLogLoadFailureEvent);
82 procedure Execute; override;
84 procedure DoLoadFailure;
86 property OnLoaded: TNotifyEvent read FOnLoaded write SetOnLoaded;
87 property OnLoadFailure: TBottleLogLoadFailureEvent
88 read FOnLoadFailure write SetOnLoadFailure;
89 property List: TObjectList read FList;
90 constructor Create(FileName: String);
91 destructor Destroy; override;
94 THTMLOutputUseColor = (ucUse, ucNoUse);
95 THTMLOutputImageType = (itNone, itBMP, itPNG, itJPG);
96 THTMLOutputRange = (orAll, orUpward, orSelected);
98 THTMLOutputOptions = record
100 UseColor: THTMLOutputUseColor;
101 ImageType: THTMLOutputImageType;
104 TBottleLogList = class(TObjectList)
106 FOnLoaded: TNotifyEvent;
107 FHttpThread: THTTPDownloadThread;
108 FXMLThread: TLogXMLThread;
111 FOnLoadFailure: TBottleLogLoadFailureEvent;
112 FOldSortColumn: TBottleLogSortType; //
\83\8d\83O
\91\8b
113 FOldSortDesc: boolean; //
\83\8d\83O
\91\8b
114 FSelectedIndex: integer;
115 FOnLoadWork: TNotifyEvent; //
\83\8d\83O
\91\8b
116 FImagePath: String; // HTML
\8fo
\97Í
\8e\9e\82ÌIMG
\83^
\83O
\82Ì
\83p
\83X(
\91\8a\91Î
\82Ü
\82½
\82Í
\90â
\91Î
\83p
\83X)
117 FImageFiles: TStringList;
118 FOnHTMLOutputWork: TBottleLogHTMLOutputWork; //
\8fd
\95¡
\89æ
\91\9c\8fo
\97Í
\82µ
\82È
\82¢
\82½
\82ß
\82Ì
\83`
\83F
\83b
\83J
120 function GetBottles(Index: integer): TLogItem;
121 procedure SetOnLoaded(const Value: TNotifyEvent);
122 procedure HttpSuccess(Sender: TObject);
123 procedure HttpFailure(Sender: TObject);
124 procedure HttpWork(Sender: TObject; LoadBytes: integer);
125 procedure XMLLoaded(Sener: TObject);
126 procedure XMLLoadFailure(Sender: TObject; const Message: String);
127 procedure SetTitle(const Value: String);
128 procedure SetOnLoadFailure(const Value: TBottleLogLoadFailureEvent);
129 procedure SetSelectedIndex(const Value: integer);
130 procedure SetOnLoadWork(const Value: TNotifyEvent);
131 procedure DoLoadFailure(const ErrorMessage: String);
132 function ColorToHex(const Col: TColor): String;
133 procedure PrintHTMLBottle(Strs: TStringList; Bottle: TLogItem;
134 SsParser: TSsParser; const Options: THTMLOutputOptions);
135 function PrintSurfaceImage(Strs: TStringList; const Ghost: String; ID: integer;
136 const Options: THTMLOutputOptions): boolean;
137 procedure SetOnHTMLOutputWork(const Value: TBottleLogHTMLOutputWork);
139 constructor Create(const Title: String);
140 destructor Destroy; override;
141 procedure SortBottles(LogSortType: TBottleLogSortType);
142 function Bottle(MID: String): TLogItem;
143 property Bottles[Index: integer]: TLogItem read GetBottles;
144 procedure LoadFromWeb(const Cond: TBottleLogDownloadCondition);
145 property Title: String read FTitle write SetTitle;
146 procedure LoadFromStream(Stream: TStream);
147 property OnLoaded: TNotifyEvent read FOnLoaded write SetOnLoaded;
148 property OnLoadWork: TNotifyEvent read FOnLoadWork write SetOnLoadWork;
149 property OnLoadFailure: TBottleLogLoadFailureEvent read FOnLoadFailure write SetOnLoadFailure;
150 property SelectedIndex: integer read FSelectedIndex write SetSelectedIndex;
151 procedure AddScriptLog(const Script, Channel, MID, Ghost: String);
152 procedure AddSystemLog(const MessageString: String);
153 procedure SaveToText(const FileName: String);
154 procedure SaveToSstpLog(const FileName: String;
155 const WithChannel: boolean = false);
156 procedure SaveToXMLFile(const FileName: String);
157 procedure LoadFromXMLFile(const FileName: String);
158 procedure SaveToHTML(const FileName: String;
159 const Options: THTMLOutputOptions; SsParser: TSsParser);
160 procedure ExtractUniqueChannels(Target: TStrings);
161 procedure ExtractUniqueGhosts(Target: TStrings);
162 property OnHTMLOutputWork: TBottleLogHTMLOutputWork read FOnHTMLOutputWork write SetOnHTMLOutputWork;
166 ASortType: TBottleLogSortType; //LogCompare
\8aÖ
\90\94\82©
\82ç
\8c©
\82¦
\82é
\82æ
\82¤
\82É
\88ê
\8e\9e\91Þ
\94ð
\97p
169 function LogCompare(Item1, Item2: Pointer): integer;
172 ////////////////////////////////////////////////////////////////////////////////
177 function LogCompare(Item1, Item2: Pointer): Integer;
179 Log1, Log2: TLogItem;
181 Log1 := TLogItem(Item1);
182 Log2 := TLogItem(Item2);
186 Result := AnsiCompareStr(Log2.MID, Log1.MID);
189 Result := AnsiCompareStr(Log1.Channel, Log2.Channel);
192 Result := AnsiCompareStr(Log1.Ghost, Log2.Ghost);
195 Result := AnsiCompareStr(Log1.Script, Log2.Script);
198 Result := Log2.Votes - Log1.Votes;
201 Result := Log2.Agrees - Log1.Agrees;
204 if ASortDesc then Result := -Result; //
\8f¸
\8f\87
209 constructor TLogItem.Create(LogType: TLogType; const MID, Channel, Script,
210 Ghost: String; LogTime: TDateTime);
212 Self.LogType := LogType;
214 Self.Script := Script;
215 Self.Channel := Channel;
217 Self.LogTime := LogTime;
218 Self.State := lsUnopened;
221 procedure TLogItem.SetChannel(const Value: String);
226 procedure TLogItem.SetLogType(const Value: TLogType);
231 procedure TLogItem.SetMID(const Value: String);
236 procedure TLogItem.SetScript(const Value: String);
241 procedure TLogItem.SetLogTime(const Value: TDateTime);
246 procedure TLogItem.SetAgreements(const Value: Integer);
248 FAgreements := Value;
251 procedure TLogItem.SetVotes(const Value: Integer);
256 procedure TLogItem.SetGhost(const Value: String);
262 procedure TLogItem.SetState(const Value: TLogState);
267 procedure TLogItem.Assign(Source: TPersistent);
270 if not (Source is TLogItem) then
273 Src := Source as TLogItem;
274 self.FScript := Src.FScript;
275 self.FChannel := Src.FChannel;
276 self.FMID := Src.FMID;
277 self.FLogTime := Src.FLogTime;
278 self.FLogType := Src.FLogType;
279 self.FGhost := Src.FGhost;
280 self.FVotes := Src.FVotes;
281 self.FAgreements := Src.FAgreements;
282 self.FState := Src.FState;
283 self.FHasURL := Src.FHasURL;
287 constructor TLogItem.Create(Source: TLogItem);
292 procedure TLogItem.SetHasURL(const Value: THasURL);
299 procedure TBottleLogList.AddScriptLog(const Script, Channel, MID,
301 var LogItem: TLogItem;
303 LogItem := TLogItem.Create(ltBottle, MID, Channel, Script, Ghost, Now());
312 procedure TBottleLogList.AddSystemLog(const MessageString: String);
313 var LogItem: TLogItem;
315 LogItem := TLogItem.Create(ltSystemLog, '', '', MessageString, '', Now());
324 function TBottleLogList.Bottle(MID: String): TLogItem;
328 for i := 0 to Count-1 do
329 if (Items[i] as TLogItem).MID = MID then begin
330 Result := Items[i] as TLogItem;
335 function TBottleLogList.ColorToHex(const Col: TColor): String;
340 RGB := ColorToRGB(Col);
342 G := (RGB and $FF00) shr 8;
343 B := (RGB and $FF0000) shr 16;
344 RGB := (R shl 16) or (G shl 8) or B;
345 Result := '#' + IntToHex(RGB, 6);
348 constructor TBottleLogList.Create(const Title: String);
353 FSelectedIndex := -1; //
\91I
\91ð
\82³
\82ê
\82Ä
\82¢
\82È
\82¢
356 destructor TBottleLogList.Destroy;
359 // FHttpThread
\82Í
\8e©
\95ª
\82ðFree
\82·
\82é
\81u
\91O
\81v
\82ÉSynchronize
\82Å
\8eQ
\8fÆ
\82ª
\8dí
\8f\9c\82³
\82ê
\82é
\82Ì
\82Å
\81A
360 // FHttpThread <> nil
\82È
\82ç
\8eÀ
\91Ì
\82ª
\91¶
\8dÝ
\82·
\82é
\82±
\82Æ
\82Í
\8am
\8eÀ
\82Å
\82 \82é
\81B
361 if FHttpThread <> nil then begin
362 FHttpThread.OnSuccess := nil;
363 FHttpThread.OnConnectionFailed := nil;
367 procedure TBottleLogList.DoLoadFailure(const ErrorMessage: String);
370 self.AddSystemLog(ErrorMessage);
371 if Assigned(FOnLoadFailure) then FOnLoadFailure(self, ErrorMessage);
374 procedure TBottleLogList.ExtractUniqueChannels(Target: TStrings);
377 //
\82±
\82Ì
\83\8d\83O
\92\86\82Ì
\83`
\83\83\83\93\83l
\83\8b\82ð
\8eæ
\82è
\8fo
\82·
378 // TStrings
\82Ì
\8eÀ
\91\95\82ÍTHashedStringList
\90\84\8f§
379 for i := 0 to Count-1 do begin
380 if Length(Bottles[i].Channel) > 0 then begin
381 if Target.IndexOf(Bottles[i].Channel) < 0 then begin
382 Target.Add(Bottles[i].Channel);
388 procedure TBottleLogList.ExtractUniqueGhosts(Target: TStrings);
391 //
\82±
\82Ì
\83\8d\83O
\92\86\82Ì
\83S
\81[
\83X
\83g
\82ð
\8eæ
\82è
\8fo
\82·
392 // TStrings
\82Ì
\8eÀ
\91\95\82ÍTHashedStringList
\90\84\8f§
393 for i := 0 to Count-1 do begin
394 if Length(Bottles[i].Ghost) > 0 then begin
395 if Target.IndexOf(Bottles[i].Ghost) < 0 then begin
396 Target.Add(Bottles[i].Ghost);
402 function TBottleLogList.GetBottles(Index: integer): TLogItem;
404 Result := Items[Index] as TLogItem;
407 procedure TBottleLogList.HttpFailure(Sender: TObject);
409 if Assigned(FOnLoadFailure) then
410 DoLoadFailure('
\83T
\81[
\83o
\82Ì
\90Ú
\91±
\82É
\8e¸
\94s
\82µ
\82Ü
\82µ
\82½');
413 procedure TBottleLogList.HttpSuccess(Sender: TObject);
414 var Stream: TStringStream;
415 StrList: TStringList;
417 Stream := TStringStream.Create(FHttpThread.RecvString);
419 StrList := TStringList.Create;
421 StrList.Text := Stream.DataString;
422 if StrList[0] <> 'Result: OK' then begin
423 if Assigned(FOnLoadFailure) then
424 DoLoadFailure('
\83T
\81[
\83o
\82ª
\83G
\83\89\81[
\82ð
\95Ô
\82µ
\82Ü
\82µ
\82½'#13#10 + Stream.DataString);
426 while StrList.Count > 0 do
427 if StrList[0] <> '' then StrList.Delete(0) else Break; //
\83w
\83b
\83_
\81[
\82ð
\8dí
\8f\9c\82·
\82é
428 if StrList.Count > 0 then StrList.Delete(0); //
\83w
\83b
\83_
\81[
\8cã
\82Ì
\8bó
\8ds
\8dí
\8f\9c
429 Stream.Seek(0, soFromBeginning);
430 Stream.Size := Length(StrList.Text);
431 Stream.WriteString(StrList.Text);
432 Stream.Seek(0, soFromBeginning);
433 LoadFromStream(Stream);
440 // nil
\82Å
\82È
\82¢
\8fê
\8d\87\82É
\82Í
\8eÀ
\91Ì
\82ª
\91¶
\8dÝ
\82·
\82é
\82±
\82Æ
\82ð
\8am
\8eÀ
\82É
\82·
\82é
441 //
\82½
\82¾
\82µ nil
\82¾
\82©
\82ç
\82Æ
\82¢
\82Á
\82Ä
\8eÀ
\91Ì
\82ª
\91¶
\8dÝ
\82µ
\82È
\82¢
\82Æ
\82Í
\8cÀ
\82ç
\82È
\82¢(FreeOnTerminate
\82Ì
\82½
\82ß)
446 procedure TBottleLogList.HttpWork(Sender: TObject; LoadBytes: integer);
449 AddSystemLog(Format('
\83_
\83E
\83\93\83\8d\81[
\83h
\92\86\82Å
\82· - %4d KB', [LoadBytes div 1024]));
450 FLoadBytes := LoadBytes;
451 if Assigned(FOnLoadWork) then FOnLoadWork(self);
454 procedure TBottleLogList.LoadFromStream(Stream: TStream);
456 SourceStream: TStringStream;
459 function S2D (const S: String): TDateTime;
461 Result := EncodeDateTime(
462 StrToInt(Copy(S, 1, 4)), StrToInt(Copy(S, 5, 2)), StrToInt(Copy(S, 7, 2)),
463 StrToInt(Copy(S, 9, 2)), StrToInt(Copy(S, 11, 2)), StrToInt(Copy(S, 13, 2)), 0);
470 SourceStream := TStringStream.Create('');
471 SourceStream.Seek(0, soFromBeginning);
472 SourceStream.CopyFrom(Stream, Stream.Size);
473 Source := TStringList.Create;
474 Source.Text := SourceStream.DataString;
476 if Source.Count = 0 then begin
477 DoLoadFailure('
\8ew
\92è
\8fð
\8c\8f\82Ì
\83\8d\83O
\82Í
\91¶
\8dÝ
\82µ
\82Ü
\82¹
\82ñ');
480 if Source[0] <> 'OK' then begin
483 while (i + 7) < Source.Count do begin
484 LogItem := TLogItem.Create(ltBottle, Source[i+1], Source[i+2],
485 Source[i+7], Source[i+3], S2D(Source[i]));
486 LogItem.Votes := StrToInt(Source[i+5]);
487 LogItem.Agrees := StrToInt(Source[i+6]);
488 LogItem.State := lsOpened;
497 On EConvertError do begin
498 DoLoadFailure('
\83T
\81[
\83o
\89\9e\93\9a\82Ì
\8c`
\8e®
\82ª
\95s
\90³
\82Å
\82·');
502 FOldSortColumn := stLogTime;
503 FOldSortDesc := false;
504 if Assigned(FOnLoaded) then FOnLoaded(Self);
507 procedure TBottleLogList.LoadFromWeb(const Cond: TBottleLogDownloadCondition);
511 AddSystemLog('
\83_
\83E
\83\93\83\8d\81[
\83h
\92\86\82Å
\82· -
\83T
\81[
\83o
\82©
\82ç
\89\9e\93\9a\91Ò
\82¿');
513 if Cond.IsRange then begin
514 Param := Format('year_lo=%d&month_lo=%d&day_lo=%d&year_hi=%d&month_hi=%d&day_hi=%d&',
515 [YearOf(DateLo), MonthOf(DateLo), DayOf(DateLo),
516 YearOf(DateHi), MonthOf(DateHi), DayOf(DateHi)]);
518 Param := Format('recent=%d&', [RecentCount]);
520 Param := Param + Format('minvote=%d&minagree=%d&channel=%s&sort=timedesc&delimiter=%%0D%%0A',
521 [MinVote, MinAgree, ParamsEncode(Channel)]);
523 FHttpThread := THTTPDownloadThread.Create(Pref.BottleServer, Pref.CgiFetchLog, Param);
524 if Pref.UseHttpProxy then begin
525 FHttpThread.ProxyServer := Pref.ProxyAddress;
526 FHttpThread.ProxyPort := Pref.ProxyPort;
528 FHttpThread.FreeOnTerminate := true;
529 FHttpThread.OnSuccess := HttpSuccess;
530 FHttpThread.OnConnectionFailed := HttpFailure;
531 FHttpThread.OnHttpWork := HttpWork;
537 procedure TBottleLogList.LoadFromXMLFile(const FileName: String);
540 AddSystemLog('
\83\8d\81[
\83h
\92\86...');
541 FXMLThread := TLogXMLThread.Create(FileName);
542 FXMLThread.FreeOnTerminate := true; //
\8f\9f\8eè
\82É
\8fÁ
\82¦
\82Ä
\82à
\82ç
\82¤
545 OnLoaded := XMLLoaded;
546 OnLoadFailure := XMLLoadFailure;
551 procedure TBottleLogList.PrintHTMLBottle(Strs: TStringList;
552 Bottle: TLogItem; SsParser: TSsParser; const Options: THTMLOutputOptions);
555 InScope1, InSync: boolean;
557 sur0, sur1, sur: integer;
563 if InSync then Cl := 'synchronized'
564 else if InScope1 then Cl := 'scope1'
566 if Options.ImageType = itNone then
570 Add(' <tr class="' + Cl + '">');
571 Add(' <td class="talk">' + XMLEntity(Talk) + '</td>');
578 Add(' <tr class="' + Cl + '">');
579 Add(' <td class="surface">');
582 PrintSurfaceImage(Strs, Bottle.Ghost, Sur0, Options);
583 PrintSurfaceImage(Strs, Bottle.Ghost, Sur1, Options);
584 end else if InScope1 then
586 PrintSurfaceImage(Strs, Bottle.Ghost, Sur1, Options);
589 PrintSurfaceImage(Strs, Bottle.Ghost, Sur0, Options);
592 Add(' <td class="talk">' + Talk + '</td>');
597 end; // of sub-procedure TalkEnd
599 SsParser.EscapeInvalidMeta := false;
600 SsParser.LeaveEscape := false;
601 SsParser.InputString := Bottle.Script;
606 for i := 0 to SsParser.Count-1 do
607 case SsParser.MarkUpType[i] of
609 Talk := Talk + XMLEntity(SsParser.Str[i]);
612 Tag := SsParser.Str[i];
615 if InScope1 and not InSync then
618 end else if (Tag = '\u') then
620 if not InScope1 and not InSync then
623 end else if Tag = '\_s' then
626 InSync := not InSync;
627 end else if SsParser.Match(Tag, '\s%d') = 3 then
630 sur := Ord(Tag[3]) - Ord('0');
635 end else if InScope1 then
639 end else if (SsParser.Match(Tag, '\s[%D]') > 0) or (Tag = '\s[-1]') then
642 sur := StrToInt(SsParser.GetParam(Tag, 1));
647 end else if InScope1 then
651 end else if SsParser.Match(Tag, '\n') >= 2 then
654 Talk := Talk + '<br>';
655 end else if Tag = '\c' then
664 function TBottleLogList.PrintSurfaceImage(Strs: TStringList; const Ghost: String;
665 ID: integer; const Options: THTMLOutputOptions): boolean;
668 Path, Ext, Name: String;
671 if (ID < 0) or (Ghost = '') then
674 Name := Format('%s,%d.%s', [SafeFileName(Ghost), ID, Ext]);
675 if FImageFiles.IndexOf(Name) >= 0 then
677 Strs.Add(Format(' <img src="%s\%s" alt="%s,%d">',
678 [FImagePath, XMLEntity(Name), XMLEntity(Ghost), ID]));
682 Bmp := TBitmap.Create;
684 if Spps.TryGetImage(Ghost, ID, Bmp) then
686 Path := Options.ImageDir + PathDelim + Name;
687 Bmp.SaveToFile(Path);
688 Strs.Add(Format(' <img src="%s\%s" alt="%s,%d">',
689 [FImagePath, XMLEntity(Name), XMLEntity(Ghost), ID]));
691 FImageFiles.Add(Name); //
\8e\9f\89ñ
\82©
\82ç
\8cÄ
\82Ñ
\8fo
\82³
\82È
\82
\82Ä
\82¢
\82¢
\82æ
\82¤
\82É
\82·
\82é
693 Strs.Add(Format(' [%d]', [ID]));
700 procedure TBottleLogList.SaveToHTML(const FileName: String;
701 const Options: THTMLOutputOptions; SsParser: TSsParser);
705 ChannelAndGhost: String;
708 if ExtractFilePath(FileName) = ExtractFilePath(Options.ImageDir) then
709 FImagePath := ExtractFileName(Options.ImageDir)
711 FImagePath := Options.ImageDir;
713 Screen.Cursor := crHourGlass;
714 FImageFiles := TStringList.Create;
716 Strs := TStringList.Create;
720 Add('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">');
722 Add('<style type="text/css"><!--');
723 Add('table.bottle td{font-family: monospace}');
724 if Options.UseColor = ucUse then
726 Add(Format('p.bottleattr {color: %s}', [ColorToHex(Pref.TalkColorH)]));
727 Add(Format('body {background-color: %s}', [ColorToHex(Pref.BgColor)]));
728 Add(Format('table.bottle tr.scope0 td.talk{color: %s}', [ColorToHex(Pref.TalkColorH)]));
729 Add(Format('table.bottle tr.scope1 td.talk{color: %s}', [ColorToHex(Pref.TalkColorU)]));
730 Add(Format('table.bottle tr.synchronized td.talk{color: %s}', [ColorToHex(Pref.TalkColorS)]));
731 Add('table.bottle td.surface {text-align: center}');
734 for i := 0 to Self.Count-1 do
736 if Assigned(FOnHTMLOutputWork) then
739 FOnHTMLOutputWork(Self, i, Cancel);
743 if Bottles[i].Ghost <> '' then
744 ChannelAndGhost := XMLEntity(Bottles[i].Channel) + '/' + XMLEntity(Bottles[i].Ghost)
746 ChannelAndGhost := XMLEntity(Bottles[i].Channel);
747 Add(Format('<p class="bottleattr">%s %s
\93\8a\95[%d
\93¯
\88Ó%d</p>', [
748 FormatDateTime('yyyy/mm/dd hh:nn:ss', Bottles[i].LogTime),
753 Add('<table class="bottle">');
754 PrintHTMLBottle(Strs, Bottles[i], SsParser, Options);
759 SaveToFile(FileName);
766 Screen.Cursor := crArrow;
770 procedure TBottleLogList.SaveToSstpLog(const FileName: String;
771 const WithChannel: boolean = false);
777 DayStr: array[1..7] of String = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
781 Str := TStringList.Create;
782 for i := 0 to Self.Count - 1 do begin
783 Item := Self.Items[i] as TLogItem;
784 if Item.LogType = ltBottle then begin
785 Date := FormatDateTime('yyyy/mm/dd hh:nn:ss ', Item.LogTime);
786 Date := Date + '(' + DayStr[DayOfWeek(Item.LogTime)] + ')';
788 Date := Date + ',' + Item.Channel +',SEND,' + Item.Script
790 Date := Date + ',0.0.0.0,SEND,' + Item.Script;
794 Str.SaveToFile(FileName);
800 procedure TBottleLogList.SaveToText(const FileName: String);
806 Str := TStringList.Create;
807 for i := 0 to Self.Count - 1 do
808 if (Self.Items[i] as TLogItem).LogType = ltBottle then
809 Str.Add((Self.Items[i] as TLogItem).Script);
810 Str.SaveToFile(FileName);
816 procedure TBottleLogList.SaveToXMLFile(const FileName: String);
818 MessageNode, Child: TdomElement;
821 Parser: TXmlToDomParser;
822 Impl: TDomImplementation;
825 Impl := TDomImplementation.create(nil);
827 Parser := TXmlToDomParser.create(nil);
828 Parser.DOMImpl := Impl;
831 DOM := Parser.fileToDom(ExtractFilePath(Application.ExeName)+'xbtl.dat');
832 //
\82±
\82ê
\82Í
\96¾
\8e¦
\93I
\82ÉFree
\82µ
\82È
\82
\82Ä
\82æ
\82¢
835 documentElement.setAttribute('saved',
836 FormatDateTime('yy/mm/dd hh:nn:ss', Now));
837 documentElement.setAttribute('generator', VersionString);
838 documentElement.setAttribute('version', '1.0');
839 for i := 0 to Self.Count-1 do begin
840 Item := Self.GetBottles(i);
841 MessageNode := createElement('message');
842 MessageNode.setAttribute('mid', Item.MID);
843 documentElement.appendChild(MessageNode);
846 Child := createElement('date');
847 Child.appendChild(createTextNode(FormatDateTime('yy/mm/dd hh:nn:ss', Item.LogTime)));
848 MessageNode.appendChild(Child);
849 //
\83`
\83\83\83\93\83l
\83\8b
850 Child := createElement('channel');
851 Child.appendChild(createTextNode(Item.Channel));
852 MessageNode.appendChild(Child);
853 //
\83X
\83N
\83\8a\83v
\83g
854 Child := createElement('script');
855 Child.appendChild(createTextNode(Item.Script));
856 MessageNode.appendChild(Child);
858 Child := createElement('votes');
859 Child.appendChild(createTextNode(IntToStr(Item.Votes)));
860 MessageNode.appendChild(Child);
862 Child := createElement('agrees');
863 Child.appendChild(createTextNode(IntToStr(Item.Agrees)));
864 MessageNode.appendChild(Child);
866 Child := createElement('ghost');
867 Child.appendChild(createTextNode(Item.Ghost));
868 MessageNode.appendChild(Child);
872 FS := TFileStream.Create(FileName, fmCreate or fmShareExclusive);
874 DOM.writeCodeAsShiftJIS(FS);
879 ShowMessage('xbtl.dat
\82ð
\8dÄ
\83C
\83\93\83X
\83g
\81[
\83\8b\82µ
\82Ä
\82
\82¾
\82³
\82¢
\81B');
882 Parser.DOMImpl.freeDocument(DOM);
890 procedure TBottleLogList.SetOnHTMLOutputWork(
891 const Value: TBottleLogHTMLOutputWork);
893 FOnHTMLOutputWork := Value;
896 procedure TBottleLogList.SetOnLoaded(const Value: TNotifyEvent);
901 procedure TBottleLogList.SetOnLoadFailure(
902 const Value: TBottleLogLoadFailureEvent);
904 FOnLoadFailure := Value;
907 procedure TBottleLogList.SetOnLoadWork(const Value: TNotifyEvent);
909 FOnLoadWork := Value;
912 procedure TBottleLogList.SetSelectedIndex(const Value: integer);
914 FSelectedIndex := Value;
917 procedure TBottleLogList.SetTitle(const Value: String);
922 procedure TBottleLogList.SortBottles(LogSortType: TBottleLogSortType);
924 if FOldSortColumn = LogSortType then
925 ASortDesc := not FOldSortDesc
929 ASortType := LogSortType;
930 Self.Sort(LogCompare);
931 FOldSortColumn := ASortType;
932 FOldSortDesc := ASortDesc;
935 procedure TBottleLogList.XMLLoaded(Sener: TObject);
937 Self.Assign(FXMLThread.List);
938 if Assigned(FOnLoaded) then FOnLoaded(Self);
942 procedure TBottleLogList.XMLLoadFailure(Sender: TObject;
943 const Message: String);
945 if Assigned(FOnLoadFailure) then
946 DoLoadFailure(Message);
951 constructor TLogXMLThread.Create(FileName: String);
953 inherited Create(true);
954 FList := TObjectList.Create(false); // OwnsObject = false (!!)
955 FFileName := FileName;
958 destructor TLogXMLThread.Destroy;
964 procedure TLogXMLThread.DoLoaded;
966 if Assigned(FOnLoaded) then
970 procedure TLogXMLThread.DoLoadFailure;
972 if Assigned(FOnLoadFailure) then
973 FOnLoadFailure(self, FLoadFailureMessage);
976 procedure TLogXMLThread.Execute;
977 var i, j, votes, agrees: integer;
979 ANode, Child: TdomElement;
982 Parser: TXmlToDomParser;
983 Impl: TDomImplementation;
984 Str, mid, channel, script, ghost: String;
987 Impl := TDomImplementation.create(nil);
989 Parser := TXmlToDomParser.create(nil);
990 Parser.DOMImpl := Impl;
993 DOM := Parser.fileToDom(FFileName); //
\82±
\82ê
\82Í
\96¾
\8e¦
\93I
\82ÉFree
\82µ
\82È
\82
\82Ä
\82æ
\82¢
995 if not DOM.validate(nil, erReplace) then
996 raise EXMLFileOpenException.Create('
\97L
\8cø
\82È
\83{
\83g
\83\8b\83\8d\83O
\8c`
\8e®
\82Å
\82Í
\82 \82è
\82Ü
\82¹
\82ñ
\81B');
999 if DocumentElement = nil then
1001 FLoadFailureMessage := '
\97L
\8cø
\82È
\8c`
\8e®
\82Å
\82Í
\82 \82è
\82Ü
\82¹
\82ñ
\81B' +
1002 '
\83\8b\81[
\83g
\83^
\83O
\82ª
\82 \82è
\82Ü
\82¹
\82ñ';
1003 Synchronize(DoLoadFailure);
1006 if DocumentElement.nodeName <> 'bottlelog' then
1008 FLoadFailureMessage := '
\97L
\8cø
\82È
\8c`
\8e®
\82Å
\82Í
\82 \82è
\82Ü
\82¹
\82ñ
\81B' +
1009 'bottlelog
\82ª
\8c©
\82Â
\82©
\82è
\82Ü
\82¹
\82ñ';
1010 Synchronize(DoLoadFailure);
1013 Str := DocumentElement.getAttribute('version');
1014 if Str <> '1.0' then
1016 FLoadFailureMessage := Format('
\97L
\8cø
\82È
\8c`
\8e®
\82Å
\82Í
\82 \82è
\82Ü
\82¹
\82ñ
\81B' +
1017 '
\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]);
1018 Synchronize(DoLoadFailure);
1021 for i := 0 to DocumentElement.childNodes.length-1 do
1023 if documentElement.childNodes.item(i).nodeType <> ntElement_Node then
1025 ANode := documentElement.childNodes.item(i) as TdomElement;
1026 if ANode.nodeName <> 'message' then
1028 mid := ANode.getAttribute('mid');
1035 for j := 0 to ANode.childNodes.length-1 do
1037 if ANode.childNodes.item(j).nodeType <> ntElement_Node then
1039 Child := ANode.childNodes.item(j) as TdomElement;
1040 if Child.nodeName = 'channel' then
1041 channel := Trim(Child.textContent)
1042 else if Child.nodeName = 'script' then
1043 script := Trim(Child.textContent)
1044 else if Child.nodeName = 'ghost' then
1045 ghost := Trim(Child.textContent)
1046 else if Child.nodeName = 'votes' then
1047 votes := StrToIntDef(Child.textContent, 0)
1048 else if Child.nodeName = 'agrees' then
1049 agrees := StrToIntDef(Child.textContent, 0)
1050 else if Child.nodeName = 'date' then
1051 TryStrToDateTime(Trim(Child.textContent), Time);
1053 Item := TLogItem.Create(ltBottle, mid, channel, script, ghost, time);
1054 Item.Votes := votes;
1055 Item.Agrees := agrees;
1056 Item.State := lsOpened;
1063 Synchronize(DoLoaded);
1066 on E: EParserException do
1068 FLoadFailureMessage := 'XML
\89ð
\90Í
\83G
\83\89\81[
\81B' + E.Message;
1069 Synchronize(DoLoadFailure);
1074 FLoadFailureMessage := 'XML
\83I
\81[
\83v
\83\93\8e\9e\82É
\83G
\83\89\81[
\82ª
\94
\90¶
\82µ
\82Ü
\82µ
\82½
\81B' +
1076 Synchronize(DoLoadFailure);
1081 Parser.DOMImpl.freeDocument(DOM);
1089 procedure TLogXMLThread.SetOnLoaded(const Value: TNotifyEvent);
1094 procedure TLogXMLThread.SetOnLoadFailure(const Value: TBottleLogLoadFailureEvent);
1096 FOnLoadFailure := Value;