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
380 if Target.IndexOf(Bottles[i].Channel) < 0 then
381 Target.Add(Bottles[i].Channel);
384 procedure TBottleLogList.ExtractUniqueGhosts(Target: TStrings);
387 //
\82±
\82Ì
\83\8d\83O
\92\86\82Ì
\83S
\81[
\83X
\83g
\82ð
\8eæ
\82è
\8fo
\82·
388 // TStrings
\82Ì
\8eÀ
\91\95\82ÍTHashedStringList
\90\84\8f§
389 for i := 0 to Count-1 do
390 if Target.IndexOf(Bottles[i].Ghost) < 0 then
391 Target.Add(Bottles[i].Ghost);
394 function TBottleLogList.GetBottles(Index: integer): TLogItem;
396 Result := Items[Index] as TLogItem;
399 procedure TBottleLogList.HttpFailure(Sender: TObject);
401 if Assigned(FOnLoadFailure) then
402 DoLoadFailure('
\83T
\81[
\83o
\82Ì
\90Ú
\91±
\82É
\8e¸
\94s
\82µ
\82Ü
\82µ
\82½');
405 procedure TBottleLogList.HttpSuccess(Sender: TObject);
406 var Stream: TStringStream;
407 StrList: TStringList;
409 Stream := TStringStream.Create(FHttpThread.RecvString);
411 StrList := TStringList.Create;
413 StrList.Text := Stream.DataString;
414 if StrList[0] <> 'Result: OK' then begin
415 if Assigned(FOnLoadFailure) then
416 DoLoadFailure('
\83T
\81[
\83o
\82ª
\83G
\83\89\81[
\82ð
\95Ô
\82µ
\82Ü
\82µ
\82½'#13#10 + Stream.DataString);
418 while StrList.Count > 0 do
419 if StrList[0] <> '' then StrList.Delete(0) else Break; //
\83w
\83b
\83_
\81[
\82ð
\8dí
\8f\9c\82·
\82é
420 if StrList.Count > 0 then StrList.Delete(0); //
\83w
\83b
\83_
\81[
\8cã
\82Ì
\8bó
\8ds
\8dí
\8f\9c
421 Stream.Seek(0, soFromBeginning);
422 Stream.Size := Length(StrList.Text);
423 Stream.WriteString(StrList.Text);
424 Stream.Seek(0, soFromBeginning);
425 LoadFromStream(Stream);
432 // nil
\82Å
\82È
\82¢
\8fê
\8d\87\82É
\82Í
\8eÀ
\91Ì
\82ª
\91¶
\8dÝ
\82·
\82é
\82±
\82Æ
\82ð
\8am
\8eÀ
\82É
\82·
\82é
433 //
\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ß)
438 procedure TBottleLogList.HttpWork(Sender: TObject; LoadBytes: integer);
441 AddSystemLog(Format('
\83_
\83E
\83\93\83\8d\81[
\83h
\92\86\82Å
\82· - %4d KB', [LoadBytes div 1024]));
442 FLoadBytes := LoadBytes;
443 if Assigned(FOnLoadWork) then FOnLoadWork(self);
446 procedure TBottleLogList.LoadFromStream(Stream: TStream);
448 SourceStream: TStringStream;
451 function S2D (const S: String): TDateTime;
453 Result := EncodeDateTime(
454 StrToInt(Copy(S, 1, 4)), StrToInt(Copy(S, 5, 2)), StrToInt(Copy(S, 7, 2)),
455 StrToInt(Copy(S, 9, 2)), StrToInt(Copy(S, 11, 2)), StrToInt(Copy(S, 13, 2)), 0);
462 SourceStream := TStringStream.Create('');
463 SourceStream.Seek(0, soFromBeginning);
464 SourceStream.CopyFrom(Stream, Stream.Size);
465 Source := TStringList.Create;
466 Source.Text := SourceStream.DataString;
468 if Source.Count = 0 then begin
469 DoLoadFailure('
\8ew
\92è
\8fð
\8c\8f\82Ì
\83\8d\83O
\82Í
\91¶
\8dÝ
\82µ
\82Ü
\82¹
\82ñ');
472 if Source[0] <> 'OK' then begin
475 while (i + 7) < Source.Count do begin
476 LogItem := TLogItem.Create(ltBottle, Source[i+1], Source[i+2],
477 Source[i+7], Source[i+3], S2D(Source[i]));
478 LogItem.Votes := StrToInt(Source[i+5]);
479 LogItem.Agrees := StrToInt(Source[i+6]);
480 LogItem.State := lsOpened;
489 On EConvertError do begin
490 DoLoadFailure('
\83T
\81[
\83o
\89\9e\93\9a\82Ì
\8c`
\8e®
\82ª
\95s
\90³
\82Å
\82·');
494 FOldSortColumn := stLogTime;
495 FOldSortDesc := false;
496 if Assigned(FOnLoaded) then FOnLoaded(Self);
499 procedure TBottleLogList.LoadFromWeb(const Cond: TBottleLogDownloadCondition);
503 AddSystemLog('
\83_
\83E
\83\93\83\8d\81[
\83h
\92\86\82Å
\82· -
\83T
\81[
\83o
\82©
\82ç
\89\9e\93\9a\91Ò
\82¿');
505 if Cond.IsRange then begin
506 Param := Format('year_lo=%d&month_lo=%d&day_lo=%d&year_hi=%d&month_hi=%d&day_hi=%d&',
507 [YearOf(DateLo), MonthOf(DateLo), DayOf(DateLo),
508 YearOf(DateHi), MonthOf(DateHi), DayOf(DateHi)]);
510 Param := Format('recent=%d&', [RecentCount]);
512 Param := Param + Format('minvote=%d&minagree=%d&channel=%s&sort=timedesc&delimiter=%%0D%%0A',
513 [MinVote, MinAgree, ParamsEncode(Channel)]);
515 FHttpThread := THTTPDownloadThread.Create(Pref.BottleServer, Pref.CgiFetchLog, Param);
516 if Pref.UseHttpProxy then begin
517 FHttpThread.ProxyServer := Pref.ProxyAddress;
518 FHttpThread.ProxyPort := Pref.ProxyPort;
520 FHttpThread.FreeOnTerminate := true;
521 FHttpThread.OnSuccess := HttpSuccess;
522 FHttpThread.OnConnectionFailed := HttpFailure;
523 FHttpThread.OnHttpWork := HttpWork;
529 procedure TBottleLogList.LoadFromXMLFile(const FileName: String);
532 AddSystemLog('
\83\8d\81[
\83h
\92\86...');
533 FXMLThread := TLogXMLThread.Create(FileName);
534 FXMLThread.FreeOnTerminate := true; //
\8f\9f\8eè
\82É
\8fÁ
\82¦
\82Ä
\82à
\82ç
\82¤
537 OnLoaded := XMLLoaded;
538 OnLoadFailure := XMLLoadFailure;
543 procedure TBottleLogList.PrintHTMLBottle(Strs: TStringList;
544 Bottle: TLogItem; SsParser: TSsParser; const Options: THTMLOutputOptions);
547 InScope1, InSync: boolean;
549 sur0, sur1, sur: integer;
555 if InSync then Cl := 'synchronized'
556 else if InScope1 then Cl := 'scope1'
558 if Options.ImageType = itNone then
562 Add(' <tr class="' + Cl + '">');
563 Add(' <td class="talk">' + XMLEntity(Talk) + '</td>');
570 Add(' <tr class="' + Cl + '">');
571 Add(' <td class="surface">');
574 PrintSurfaceImage(Strs, Bottle.Ghost, Sur0, Options);
575 PrintSurfaceImage(Strs, Bottle.Ghost, Sur1, Options);
576 end else if InScope1 then
578 PrintSurfaceImage(Strs, Bottle.Ghost, Sur1, Options);
581 PrintSurfaceImage(Strs, Bottle.Ghost, Sur0, Options);
584 Add(' <td class="talk">' + Talk + '</td>');
589 end; // of sub-procedure TalkEnd
591 SsParser.EscapeInvalidMeta := false;
592 SsParser.LeaveEscape := false;
593 SsParser.InputString := Bottle.Script;
598 for i := 0 to SsParser.Count-1 do
599 case SsParser.MarkUpType[i] of
601 Talk := Talk + XMLEntity(SsParser.Str[i]);
604 Tag := SsParser.Str[i];
607 if InScope1 and not InSync then
610 end else if (Tag = '\u') then
612 if not InScope1 and not InSync then
615 end else if Tag = '\_s' then
618 InSync := not InSync;
619 end else if SsParser.Match(Tag, '\s%d') = 3 then
622 sur := Ord(Tag[3]) - Ord('0');
627 end else if InScope1 then
631 end else if (SsParser.Match(Tag, '\s[%D]') > 0) or (Tag = '\s[-1]') then
634 sur := StrToInt(SsParser.GetParam(Tag, 1));
639 end else if InScope1 then
643 end else if SsParser.Match(Tag, '\n') >= 2 then
646 Talk := Talk + '<br>';
647 end else if Tag = '\c' then
656 function TBottleLogList.PrintSurfaceImage(Strs: TStringList; const Ghost: String;
657 ID: integer; const Options: THTMLOutputOptions): boolean;
660 Path, Ext, Name: String;
663 if (ID < 0) or (Ghost = '') then
666 Name := Format('%s,%d.%s', [SafeFileName(Ghost), ID, Ext]);
667 if FImageFiles.IndexOf(Name) >= 0 then
669 Strs.Add(Format(' <img src="%s\%s" alt="%s,%d">',
670 [FImagePath, XMLEntity(Name), XMLEntity(Ghost), ID]));
674 Bmp := TBitmap.Create;
676 if Spps.TryGetImage(Ghost, ID, Bmp) then
678 Path := Options.ImageDir + PathDelim + Name;
679 Bmp.SaveToFile(Path);
680 Strs.Add(Format(' <img src="%s\%s" alt="%s,%d">',
681 [FImagePath, XMLEntity(Name), XMLEntity(Ghost), ID]));
683 FImageFiles.Add(Name); //
\8e\9f\89ñ
\82©
\82ç
\8cÄ
\82Ñ
\8fo
\82³
\82È
\82
\82Ä
\82¢
\82¢
\82æ
\82¤
\82É
\82·
\82é
685 Strs.Add(Format(' [%d]', [ID]));
692 procedure TBottleLogList.SaveToHTML(const FileName: String;
693 const Options: THTMLOutputOptions; SsParser: TSsParser);
697 ChannelAndGhost: String;
700 if ExtractFilePath(FileName) = ExtractFilePath(Options.ImageDir) then
701 FImagePath := ExtractFileName(Options.ImageDir)
703 FImagePath := Options.ImageDir;
705 Screen.Cursor := crHourGlass;
706 FImageFiles := TStringList.Create;
708 Strs := TStringList.Create;
712 Add('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">');
714 Add('<style type="text/css"><!--');
715 Add('table.bottle td{font-family: monospace}');
716 if Options.UseColor = ucUse then
718 Add(Format('p.bottleattr {color: %s}', [ColorToHex(Pref.TalkColorH)]));
719 Add(Format('body {background-color: %s}', [ColorToHex(Pref.BgColor)]));
720 Add(Format('table.bottle tr.scope0 td.talk{color: %s}', [ColorToHex(Pref.TalkColorH)]));
721 Add(Format('table.bottle tr.scope1 td.talk{color: %s}', [ColorToHex(Pref.TalkColorU)]));
722 Add(Format('table.bottle tr.synchronized td.talk{color: %s}', [ColorToHex(Pref.TalkColorS)]));
723 Add('table.bottle td.surface {text-align: center}');
726 for i := 0 to Self.Count-1 do
728 if Assigned(FOnHTMLOutputWork) then
731 FOnHTMLOutputWork(Self, i, Cancel);
735 if Bottles[i].Ghost <> '' then
736 ChannelAndGhost := XMLEntity(Bottles[i].Channel) + '/' + XMLEntity(Bottles[i].Ghost)
738 ChannelAndGhost := XMLEntity(Bottles[i].Channel);
739 Add(Format('<p class="bottleattr">%s %s
\93\8a\95[%d
\93¯
\88Ó%d</p>', [
740 FormatDateTime('yyyy/mm/dd hh:nn:ss', Bottles[i].LogTime),
745 Add('<table class="bottle">');
746 PrintHTMLBottle(Strs, Bottles[i], SsParser, Options);
751 SaveToFile(FileName);
758 Screen.Cursor := crArrow;
762 procedure TBottleLogList.SaveToSstpLog(const FileName: String;
763 const WithChannel: boolean = false);
769 DayStr: array[1..7] of String = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
773 Str := TStringList.Create;
774 for i := 0 to Self.Count - 1 do begin
775 Item := Self.Items[i] as TLogItem;
776 if Item.LogType = ltBottle then begin
777 Date := FormatDateTime('yyyy/mm/dd hh:nn:ss ', Item.LogTime);
778 Date := Date + '(' + DayStr[DayOfWeek(Item.LogTime)] + ')';
780 Date := Date + ',' + Item.Channel +',SEND,' + Item.Script
782 Date := Date + ',0.0.0.0,SEND,' + Item.Script;
786 Str.SaveToFile(FileName);
792 procedure TBottleLogList.SaveToText(const FileName: String);
798 Str := TStringList.Create;
799 for i := 0 to Self.Count - 1 do
800 if (Self.Items[i] as TLogItem).LogType = ltBottle then
801 Str.Add((Self.Items[i] as TLogItem).Script);
802 Str.SaveToFile(FileName);
808 procedure TBottleLogList.SaveToXMLFile(const FileName: String);
810 MessageNode, Child: TdomElement;
813 Parser: TXmlToDomParser;
814 Impl: TDomImplementation;
817 Impl := TDomImplementation.create(nil);
819 Parser := TXmlToDomParser.create(nil);
820 Parser.DOMImpl := Impl;
823 DOM := Parser.fileToDom(ExtractFilePath(Application.ExeName)+'xbtl.dat');
824 //
\82±
\82ê
\82Í
\96¾
\8e¦
\93I
\82ÉFree
\82µ
\82È
\82
\82Ä
\82æ
\82¢
827 documentElement.setAttribute('saved',
828 FormatDateTime('yy/mm/dd hh:nn:ss', Now));
829 documentElement.setAttribute('generator', VersionString);
830 documentElement.setAttribute('version', '1.0');
831 for i := 0 to Self.Count-1 do begin
832 Item := Self.GetBottles(i);
833 MessageNode := createElement('message');
834 MessageNode.setAttribute('mid', Item.MID);
835 documentElement.appendChild(MessageNode);
838 Child := createElement('date');
839 Child.appendChild(createTextNode(FormatDateTime('yy/mm/dd hh:nn:ss', Item.LogTime)));
840 MessageNode.appendChild(Child);
841 //
\83`
\83\83\83\93\83l
\83\8b
842 Child := createElement('channel');
843 Child.appendChild(createTextNode(Item.Channel));
844 MessageNode.appendChild(Child);
845 //
\83X
\83N
\83\8a\83v
\83g
846 Child := createElement('script');
847 Child.appendChild(createTextNode(Item.Script));
848 MessageNode.appendChild(Child);
850 Child := createElement('votes');
851 Child.appendChild(createTextNode(IntToStr(Item.Votes)));
852 MessageNode.appendChild(Child);
854 Child := createElement('agrees');
855 Child.appendChild(createTextNode(IntToStr(Item.Agrees)));
856 MessageNode.appendChild(Child);
858 Child := createElement('ghost');
859 Child.appendChild(createTextNode(Item.Ghost));
860 MessageNode.appendChild(Child);
864 FS := TFileStream.Create(FileName, fmCreate or fmShareExclusive);
866 DOM.writeCodeAsShiftJIS(FS);
871 ShowMessage('xbtl.dat
\82ð
\8dÄ
\83C
\83\93\83X
\83g
\81[
\83\8b\82µ
\82Ä
\82
\82¾
\82³
\82¢
\81B');
874 Parser.DOMImpl.freeDocument(DOM);
882 procedure TBottleLogList.SetOnHTMLOutputWork(
883 const Value: TBottleLogHTMLOutputWork);
885 FOnHTMLOutputWork := Value;
888 procedure TBottleLogList.SetOnLoaded(const Value: TNotifyEvent);
893 procedure TBottleLogList.SetOnLoadFailure(
894 const Value: TBottleLogLoadFailureEvent);
896 FOnLoadFailure := Value;
899 procedure TBottleLogList.SetOnLoadWork(const Value: TNotifyEvent);
901 FOnLoadWork := Value;
904 procedure TBottleLogList.SetSelectedIndex(const Value: integer);
906 FSelectedIndex := Value;
909 procedure TBottleLogList.SetTitle(const Value: String);
914 procedure TBottleLogList.SortBottles(LogSortType: TBottleLogSortType);
916 if FOldSortColumn = LogSortType then
917 ASortDesc := not FOldSortDesc
921 ASortType := LogSortType;
922 Self.Sort(LogCompare);
923 FOldSortColumn := ASortType;
924 FOldSortDesc := ASortDesc;
927 procedure TBottleLogList.XMLLoaded(Sener: TObject);
929 Self.Assign(FXMLThread.List);
930 if Assigned(FOnLoaded) then FOnLoaded(Self);
934 procedure TBottleLogList.XMLLoadFailure(Sender: TObject;
935 const Message: String);
937 if Assigned(FOnLoadFailure) then
938 DoLoadFailure(Message);
943 constructor TLogXMLThread.Create(FileName: String);
945 inherited Create(true);
946 FList := TObjectList.Create(false); // OwnsObject = false (!!)
947 FFileName := FileName;
950 destructor TLogXMLThread.Destroy;
956 procedure TLogXMLThread.DoLoaded;
958 if Assigned(FOnLoaded) then
962 procedure TLogXMLThread.DoLoadFailure;
964 if Assigned(FOnLoadFailure) then
965 FOnLoadFailure(self, FLoadFailureMessage);
968 procedure TLogXMLThread.Execute;
969 var i, j, votes, agrees: integer;
971 ANode, Child: TdomElement;
974 Parser: TXmlToDomParser;
975 Impl: TDomImplementation;
976 Str, mid, channel, script, ghost: String;
979 Impl := TDomImplementation.create(nil);
981 Parser := TXmlToDomParser.create(nil);
982 Parser.DOMImpl := Impl;
985 DOM := Parser.fileToDom(FFileName); //
\82±
\82ê
\82Í
\96¾
\8e¦
\93I
\82ÉFree
\82µ
\82È
\82
\82Ä
\82æ
\82¢
987 if not DOM.validate(nil, erReplace) then
988 raise EXMLFileOpenException.Create('
\97L
\8cø
\82È
\83{
\83g
\83\8b\83\8d\83O
\8c`
\8e®
\82Å
\82Í
\82 \82è
\82Ü
\82¹
\82ñ
\81B');
991 if DocumentElement = nil then
993 FLoadFailureMessage := '
\97L
\8cø
\82È
\8c`
\8e®
\82Å
\82Í
\82 \82è
\82Ü
\82¹
\82ñ
\81B' +
994 '
\83\8b\81[
\83g
\83^
\83O
\82ª
\82 \82è
\82Ü
\82¹
\82ñ';
995 Synchronize(DoLoadFailure);
998 if DocumentElement.nodeName <> 'bottlelog' then
1000 FLoadFailureMessage := '
\97L
\8cø
\82È
\8c`
\8e®
\82Å
\82Í
\82 \82è
\82Ü
\82¹
\82ñ
\81B' +
1001 'bottlelog
\82ª
\8c©
\82Â
\82©
\82è
\82Ü
\82¹
\82ñ';
1002 Synchronize(DoLoadFailure);
1005 Str := DocumentElement.getAttribute('version');
1006 if Str <> '1.0' then
1008 FLoadFailureMessage := Format('
\97L
\8cø
\82È
\8c`
\8e®
\82Å
\82Í
\82 \82è
\82Ü
\82¹
\82ñ
\81B' +
1009 '
\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]);
1010 Synchronize(DoLoadFailure);
1013 for i := 0 to DocumentElement.childNodes.length-1 do
1015 if documentElement.childNodes.item(i).nodeType <> ntElement_Node then
1017 ANode := documentElement.childNodes.item(i) as TdomElement;
1018 if ANode.nodeName <> 'message' then
1020 mid := ANode.getAttribute('mid');
1027 for j := 0 to ANode.childNodes.length-1 do
1029 if ANode.childNodes.item(j).nodeType <> ntElement_Node then
1031 Child := ANode.childNodes.item(j) as TdomElement;
1032 if Child.nodeName = 'channel' then
1033 channel := Trim(Child.textContent)
1034 else if Child.nodeName = 'script' then
1035 script := Trim(Child.textContent)
1036 else if Child.nodeName = 'ghost' then
1037 ghost := Trim(Child.textContent)
1038 else if Child.nodeName = 'votes' then
1039 votes := StrToIntDef(Child.textContent, 0)
1040 else if Child.nodeName = 'agrees' then
1041 agrees := StrToIntDef(Child.textContent, 0)
1042 else if Child.nodeName = 'date' then
1043 TryStrToDateTime(Trim(Child.textContent), Time);
1045 Item := TLogItem.Create(ltBottle, mid, channel, script, ghost, time);
1046 Item.Votes := votes;
1047 Item.Agrees := agrees;
1048 Item.State := lsOpened;
1055 Synchronize(DoLoaded);
1058 on E: EParserException do
1060 FLoadFailureMessage := 'XML
\89ð
\90Í
\83G
\83\89\81[
\81B' + E.Message;
1061 Synchronize(DoLoadFailure);
1066 FLoadFailureMessage := 'XML
\83I
\81[
\83v
\83\93\8e\9e\82É
\83G
\83\89\81[
\82ª
\94
\90¶
\82µ
\82Ü
\82µ
\82½
\81B' +
1068 Synchronize(DoLoadFailure);
1073 Parser.DOMImpl.freeDocument(DOM);
1081 procedure TLogXMLThread.SetOnLoaded(const Value: TNotifyEvent);
1086 procedure TLogXMLThread.SetOnLoadFailure(const Value: TBottleLogLoadFailureEvent);
1088 FOnLoadFailure := Value;