OSDN Git Service

cee8bbdcad8ffe8ea6a3707d2919a23e9d67455d
[gikonavigoeson/gikonavi.git] / GikoSystem.pas
1 unit GikoSystem;
2
3 interface
4
5 uses
6         Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
7         ComCtrls, IniFiles, ShellAPI, ActnList, Math,
8 {$IF Defined(DELPRO) }
9         SHDocVw,
10         MSHTML,
11 {$ELSE}
12         SHDocVw_TLB,
13         MSHTML_TLB,
14 {$IFEND}
15         {HttpApp,} YofUtils, URLMon, IdGlobal, IdURI, {Masks,}
16         Setting, BoardGroup, gzip, Dolib, bmRegExp, AbonUnit;
17
18 type
19         //BBS\83^\83C\83v
20         TGikoBBSType = (gbt2ch);
21         //\83\8d\83O\83^\83C\83v
22         TGikoLogType = (glt2chNew, glt2chOld);
23         //\83\81\83b\83Z\81[\83W\83A\83C\83R\83\93
24         TGikoMessageIcon = (gmiOK, gmiSAD, gmiNG, gmiWhat, gmiNone);
25         //URL\83I\81[\83v\83\93\83u\83\89\83E\83U\83^\83C\83v
26         TGikoBrowserType = (gbtIE, gbtUserApp, gbtAuto);
27
28
29         TStrTokSeparator = set of Char;
30         TStrTokRec = record
31                 Str: string;
32                 Pos: Integer;
33         end;
34
35         //\83C\83\93\83f\83b\83N\83X\83t\83@\83C\83\8b\83\8c\83R\81[\83h
36         TIndexRec = record
37                 FNo: Integer;
38                 FFileName: string;
39                 FTitle: string;
40                 FCount: Integer;
41                 FSize: Integer;
42 //              FRoundNo: Integer;
43                 FRoundDate: TDateTime;
44                 FLastModified: TDateTime;
45                 FKokomade: Integer;
46                 FNewReceive: Integer;
47                 FMishiyou: Boolean;     //\96¢\8eg\97p
48                 FUnRead: Boolean;
49                 FScrollTop: Integer;
50                 //Index Ver 1.01
51                 FAllResCount: Integer;
52                 FNewResCount: Integer;
53                 FAgeSage: TGikoAgeSage;
54         end;
55
56         //\83T\83u\83W\83F\83N\83g\83\8c\83R\81[\83h
57         TSubjectRec = record
58                 FFileName: string;
59                 FTitle: string;
60                 FCount: Integer;
61         end;
62
63         //\83\8c\83X\83\8c\83R\81[\83h
64         TResRec = record
65                 FTitle: string;
66                 FMailTo: string;
67                 FName: string;
68                 FDateTime: string;
69                 FBody: string;
70                 FType: TGikoLogType;
71         end;
72
73         //URLPath\83\8c\83R\81[\83h
74         TPathRec = record
75                 FBBS: string;                           //BBSID
76                 FKey: string;                           //ThreadID
77                 FSt: Integer;                           //\8aJ\8en\83\8c\83X\94Ô
78                 FTo: Integer;                           //\8fI\97¹\83\8c\83X\94Ô
79                 FFirst: Boolean;                //>>1\82Ì\95\\8e¦
80                 FStBegin: Boolean;      //1\81`\95\\8e¦
81                 FToEnd: Boolean;                //\81`\8dÅ\8cã\82Ü\82Å\95\\8e¦
82                 FDone: Boolean;                 //\90¬\8c÷
83         end;
84
85         TGikoSys = class(TObject)
86         private
87                 { Private \90é\8c¾ }
88                 FSetting: TSetting;
89                 FDolib: TDolib;
90                 FAWKStr: TAWKStr;
91                                 FOnlyAHundredRes : Boolean;
92 //              FExitWrite: TStringList;
93 //              function StrToFloatDef(s: string; Default: Double): Double;
94
95         public
96                 { Public \90é\8c¾ }
97                 FAbon : TAbon;
98                 FSelectResFilter : TAbon;
99                 constructor Create;
100
101                 destructor Destroy; override;
102                 property OnlyAHundredRes : Boolean read FOnlyAHundredRes write FOnlyAHundredRes;
103
104 //              function MsgBox(Msg: string; Title: string; Flags: Longint): integer; overload;
105 //              function MsgBox(Handle: THandle; Msg: string; Title: string; Flags: Longint): integer; overload;
106                 function IsNumeric(s: string): boolean;
107                 function IsFloat(s: string): boolean;
108                 function DirectoryExistsEx(const Name: string): Boolean;
109                 function ForceDirectoriesEx(Dir: string): Boolean;
110 //              function GetVersion: string;
111
112                 function GetBoardFileName: string;
113                 function GetCustomBoardFileName: string;
114                 function GetHtmlTempFileName: string;
115                 function GetAppDir: string;
116                 function GetTempFolder: string;
117                 function GetSentFileName: string;
118                 function GetConfigDir: string;
119                 function GetSkinDir: string;
120                 function GetSkinHeaderFileName: string;
121                 function GetSkinFooterFileName: string;
122                 function GetSkinResFileName: string;
123                 function GetSkinNewResFileName: string;
124                 function GetSkinBookmarkFileName: string;
125                 function GetSkinNewmarkFileName: string;
126                 function GetStyleSheetDir: string;
127                 function GetOutBoxFileName: string;
128                 function GetURL(BBSID: string; FileName: string): string;
129                 function GetUserAgent: string;
130
131                 procedure ReadSubjectFile(Board: TBoard);
132                 procedure CreateThreadDat(Board: TBoard);
133                 procedure WriteThreadDat(Board: TBoard);
134                 function ParseIndexLine(Line: string): TIndexRec;
135                 procedure GetFileList(Path: string; Mask: string; List: TStringList; SubDir: Boolean; IsPathAdd: Boolean);
136                 procedure GetDirectoryList(Path: string; Mask: string; List: TStringList; SubDir: Boolean);
137
138                 procedure CreateHTML2(doc: Variant; ThreadItem: TThreadItem; var sTitle: string);
139                 function AddAnchorTag(s: string): string;
140
141                 function DivideSubject(Line: string): TSubjectRec;
142                 function DivideStrLine(Line: string): TResRec;
143
144                 property Setting: TSetting read FSetting write FSetting;
145                 property Dolib: TDolib read FDolib write FDolib;
146
147                 function UrlToID(url: string): string;
148                 function UrlToServer(url: string): string;
149
150                 function StrTokFirst(const s:string; const sep:TStrTokSeparator; var Rec:TStrTokRec):string;
151                 function StrTokNext(const sep:TStrTokSeparator; var Rec:TStrTokRec): string;
152
153                 function GetFileSize(FileName : string) : longint;
154                 function GetFileLineCount(FileName : string): longint;
155                 function Get2chDate(aDate: TDateTime): string;
156                 function IntToDateTime(val: Int64): TDateTime;
157                 function DateTimeToInt(ADate: TDateTime): Integer;
158
159                 function ReadThreadFile(FileName: string; Line: Integer): string;
160
161                 procedure MenuFont(Font: TFont);
162
163                 function RemoveToken(var s:string;delimiter:string):string;
164                 function GetTokenIndex(s: string; delimiter: string; index: Integer): string;
165
166                 function DeleteLink(const s: string): string;
167
168                 function GetShortName(const LongName: string; ALength: integer): string;
169                 function ConvRes(const Body, Bbs, Key,  ParamBBS, ParamKey, ParamStart, ParamTo, ParamNoFirst, ParamTrue : string): string;
170
171                 function ZenToHan(const s: string): string;
172                 function VaguePos(const Substr, S: string): Integer;
173                 function BoolToInt(b: Boolean): Integer;
174                 function IntToBool(i: Integer): Boolean;
175                 function GzipDecompress(ResStream: TStream; ContentEncoding: string): string;
176                 procedure LoadKeySetting(ActionList: TActionList);
177                 procedure SaveKeySetting(ActionList: TActionList);
178                 procedure CreateProcess(const AppPath: string; const Param: string);
179                 procedure OpenBrowser(URL: string; BrowserType: TGikoBrowserType);
180                 function HTMLDecode(const AStr: String): String;
181                 function GetHRefText(s: string): string;
182                 function Is2chHost(Host: string): Boolean;
183                 function Parse2chURL(const url: string; const path: string; const document: string; var BBSID: string; var BBSKey: string): Boolean;
184                 function Parse2chURL2(URL: string): TPathRec;
185                 procedure ParseURI(var URL, Protocol, Host, Path, Document, Port, Bookmark: string);
186                 function GetVersionBuild: Integer;
187
188                                 // \83X\83L\83\93\82ð\93Ç\82Ý\8d\9e\82Ý\81A\92l\82ð\92u\8a·\82·\82é
189                 function LoadFromSkin( fileName: string; ThreadItem: TThreadItem; SizeByte: Integer ): string;
190                         // \83\8c\83X\82Ì\92l\82ð\92u\8a·\82·\82é
191                 function SkinedRes( skin: string; Res: TResRec; No: string ): string;
192
193         end;
194
195 var
196         GikoSys: TGikoSys;
197 const
198         LENGTH_RESTITLE                 = 40;
199         ZERO_DATE: Integer      = 25569;
200         BETA_VERSION_NAME_E = 'beta';
201         BETA_VERSION_NAME_J = 'ÊÞÀ';
202         BETA_VERSION                            = 43;
203         BETA_VERSION_BUILD      = '';                           //debug\94Å\82È\82Ç
204         APP_NAME                                                = 'gikoNavi';
205
206 implementation
207
208 uses
209         Giko, RoundData, ExternalBoardManager;
210
211 const
212         FOLDER_INDEX_VERSION                                    = '1.01';
213         USER_AGENT                                                                              = 'Monazilla';
214         DEFAULT_NGWORD_FILE_NAME : String = 'NGword.txt';
215         NGWORDs_DIR_NAME : String               = 'NGwords';
216
217 (*************************************************************************
218  *GikoSys\83R\83\93\83X\83g\83\89\83N\83^
219  *************************************************************************)
220 constructor TGikoSys.Create;
221 begin
222         FSetting := TSetting.Create;
223         FDolib := TDolib.Create;
224         FAWKStr := TAWKStr.Create(nil);
225         if DirectoryExists(GetConfigDir) = false then begin
226                 CreateDir(GetConfigDir);
227         end;
228         FAbon := TAbon.Create;
229         FAbon.Setroot(GetConfigDir+NGWORDs_DIR_NAME);
230         FAbon.GoHome;
231         FAbon.ReturnNGwordLineNum := FSetting.ShowNGLinesNum;
232         FAbon.SetNGResAnchor := FSetting.AddResAnchor;
233         FAbon.Deleterlo := FSetting.AbonDeleterlo;
234         FAbon.Replaceul := FSetting.AbonReplaceul;
235         FAbon.AbonPopupRes := FSetting.PopUpAbon;
236
237         FSelectResFilter := TAbon.Create;
238         // \8di\82è\8d\9e\82Þ\82Æ\82«\82Í\8bÉ\97Í\88ê\97\97\82ª\8c©\82ç\82ê\82é\82Ù\82¤\82ª\82¢\82¢\82Ì\82Å\91¼\82Í\8a®\91S\82É\8dí\8f\9c
239         FSelectResFilter.AbonString := '';
240         //
241         OnlyAHundredRes := FSetting.OnlyAHundredRes;
242 end;
243
244 (*************************************************************************
245  *GikoSys\83f\83X\83g\83\89\83N\83^
246  *************************************************************************)
247 destructor TGikoSys.Destroy;
248 var
249         i: Integer;
250         FileList: TStringList;
251 begin
252         //\83X\83\8c\83b\83h\83f\81[\83^\83t\83@\83C\83\8b\82ð\8dX\90V
253 //      FlashExitWrite;
254
255 //      FExitWrite.Free;
256         FAWKStr.Free;
257         FSetting.Free;
258         FDolib.Free;
259
260         //\83e\83\93\83|\83\89\83\8aHTML\82ð\8dí\8f\9c
261         FileList := TStringList.Create;
262         try
263                 GetFileList(GetTempFolder, '*.html', FileList, False, True);
264                 for i := 0 to FileList.Count - 1 do begin
265                         DeleteFile(FileList[i]);
266                 end;
267         finally
268                 FileList.Free;
269         end;
270         inherited;
271 end;
272
273 (*************************************************************************
274  *\95\8e\9a\97ñ\90\94\8e\9a\83`\83F\83b\83N
275  *************************************************************************)
276 {$HINTS OFF}
277 function TGikoSys.IsNumeric(s: string): boolean;
278 var
279         e: integer;
280         v: integer;
281 begin
282         Val(s, v, e);
283         Result := e = 0;
284 end;
285 {$HINTS ON}
286
287 (*************************************************************************
288  *\95\8e\9a\97ñ\95\82\93®\8f¬\90\94\93_\90\94\8e\9a\83`\83F\83b\83N
289  *************************************************************************)
290 function TGikoSys.IsFloat(s: string): boolean;
291 var
292         v: Extended;
293 begin
294         Result := TextToFloat(PChar(s), v, fvExtended);
295 end;
296
297 (*************************************************************************
298  *\83{\81[\83h\83t\83@\83C\83\8b\96¼\8eæ\93¾\81i\83p\83X\81{\83t\83@\83C\83\8b\96¼\81j
299  *************************************************************************)
300 function TGikoSys.GetBoardFileName: string;
301 begin
302         Result := Setting.GetBoardFileName;
303 end;
304
305 (*************************************************************************
306  *\83{\81[\83h\83t\83@\83C\83\8b\96¼\8eæ\93¾\81i\83p\83X\81{\83t\83@\83C\83\8b\96¼\81j
307  *************************************************************************)
308 function TGikoSys.GetCustomBoardFileName: string;
309 begin
310         Result := Setting.GetCustomBoardFileName;
311 end;
312
313 (*************************************************************************
314  *\83e\83\93\83|\83\89\83\8a\83t\83H\83\8b\83_\81[\96¼\8eæ\93¾
315  *************************************************************************)
316 function TGikoSys.GetHtmlTempFileName: string;
317 begin
318         Result := Setting.GetHtmlTempFileName;
319 end;
320
321
322 (*************************************************************************
323  *\8eÀ\8ds\83t\83@\83C\83\8b\83t\83H\83\8b\83_\8eæ\93¾
324  *************************************************************************)
325 function TGikoSys.GetAppDir: string;
326 begin
327         Result := Setting.GetAppDir;
328 end;
329
330 (*************************************************************************
331  *TempHtml\83t\83@\83C\83\8b\96¼\8eæ\93¾\81i\83p\83X\81{\83t\83@\83C\83\8b\96¼\81j
332  *************************************************************************)
333 function TGikoSys.GetTempFolder: string;
334 begin
335         Result := Setting.GetTempFolder;
336 end;
337
338 (*************************************************************************
339  *sent.ini\83t\83@\83C\83\8b\96¼\8eæ\93¾\81i\83p\83X\81{\83t\83@\83C\83\8b\96¼\81j
340  *************************************************************************)
341 function TGikoSys.GetSentFileName: string;
342 begin
343         Result := Setting.GetSentFileName;
344 end;
345
346 (*************************************************************************
347  *outbox.ini\83t\83@\83C\83\8b\96¼\8eæ\93¾\81i\83p\83X\81{\83t\83@\83C\83\8b\96¼\81j
348  *************************************************************************)
349 function TGikoSys.GetOutBoxFileName: string;
350 begin
351         Result := Setting.GetOutBoxFileName;
352 end;
353
354 (*************************************************************************
355  *Config\83t\83H\83\8b\83_\8eæ\93¾
356  *************************************************************************)
357 function TGikoSys.GetConfigDir: string;
358 begin
359         Result := Setting.GetConfigDir;
360 end;
361
362 function TGikoSys.GetStyleSheetDir: string;
363 begin
364         Result := Setting.GetStyleSheetDir;
365 end;
366
367 function TGikoSys.GetSkinDir: string;
368 begin
369         Result := Setting.GetSkinDir;
370 end;
371
372 function TGikoSys.GetSkinHeaderFileName: string;
373 begin
374         Result := Setting.GetSkinHeaderFileName;
375 end;
376
377 function TGikoSys.GetSkinFooterFileName: string;
378 begin
379         Result := Setting.GetSkinFooterFileName;
380 end;
381
382 function TGikoSys.GetSkinNewResFileName: string;
383 begin
384         Result := Setting.GetSkinNewResFileName;
385 end;
386
387 function TGikoSys.GetSkinResFileName: string;
388 begin
389         Result := Setting.GetSkinResFileName;
390 end;
391
392 function TGikoSys.GetSkinBookmarkFileName: string;
393 begin
394         Result := Setting.GetSkinBookmarkFileName;
395 end;
396
397 function TGikoSys.GetSkinNewmarkFileName: string;
398 begin
399         Result := Setting.GetSkinNewmarkFileName;
400 end;
401
402 (*************************************************************************
403  *URL\82ð\8dì\90¬(\83R\83s\83y\97p)
404  *************************************************************************)
405 function TGikoSys.GetURL(BBSID: string; FileName: string): string;
406 var
407         Board: TBoard;
408 begin
409         Board := BoardGroup.BBS2ch.GetBoardFromBBSID(BBSID);
410         Result := UrlToServer(Board.URL) + 'test/read.cgi/' + UrlToID(Board.URL) + '/' + ChangeFileExt(FileName, '') + '/l50';
411         //http://teri.2ch.net/test/read.cgi?bbs=accuse&key=974619522&ls=50
412         //http://pc.2ch.net/test/read.cgi/tech/1003664165/l50
413 end;
414
415 // UserAgent\8eæ\93¾
416 function TGikoSys.GetUserAgent: string;
417 begin
418         if Dolib.Connected then begin
419                 Result := Format('%s %s/%s%d%s', [
420                                                                 Dolib.UserAgent,
421                                                                 APP_NAME,
422                                                                 //MAJOR_VERSION,
423                                                                 //MINOR_VERSION,
424                                                                 BETA_VERSION_NAME_E,
425                                                                 BETA_VERSION,
426                                                                 BETA_VERSION_BUILD]);
427         end else begin
428                 Result := Format('%s/%s %s/%s%d%s', [
429                                                                 USER_AGENT,
430                                                                 Dolib.Version,
431                                                                 APP_NAME,
432                                                                 //MAJOR_VERSION,
433                                                                 //MINOR_VERSION,
434                                                                 BETA_VERSION_NAME_E,
435                                                                 BETA_VERSION,
436                                                                 BETA_VERSION_BUILD]);
437         end;
438 end;
439
440 (*************************************************************************
441  *\82Q\82¿\82á\82ñ\82Ë\82é\95û\8e®\8e\9e\8d\8f\8eæ\93¾
442  *************************************************************************)
443 function TGikoSys.Get2chDate(aDate: TDateTime): string;
444 var
445         d1: TDateTime;
446         d2: TDateTime;
447 begin
448         d1 := EncodeDate(1970, 1, 1);
449         d2 := aDate - EncodeTime(9, 0, 0, 0);
450         Result := FloatToStr(Trunc((d2 - d1) * 24 * 60 * 60));
451 end;
452
453
454 function TGikoSys.IntToDateTime(val: Int64): TDateTime;
455 var
456         d1: tdatetime;
457         d2: tdatetime;
458 begin
459         d1 := EncodeDate(1970, 1, 1);
460         d2 := (val * 1000) / (24 * 60 * 60 * 1000);
461         Result := d1 + d2;
462 end;
463
464 function TGikoSys.DateTimeToInt(ADate: TDateTime): Integer;
465 var
466         d: TDateTime;
467         c: Currency;
468 begin
469         d := EncodeDate(1970, 1, 1);
470         c := (ADate - d) * 24 * 60 * 60;
471         Result := Trunc(c);
472 end;
473
474
475 (*************************************************************************
476  *Subject\83t\83@\83C\83\8bRead
477  *************************************************************************)
478 procedure TGikoSys.ReadSubjectFile(Board: TBoard);
479 var
480         ThreadItem: TThreadItem;
481         FileName: string;
482         FileList: TStringList;
483         TmpFileList: TStringList;
484 //      SrchRec: TSearchRec;
485 //      R: integer;
486         Index: Integer;
487         sl: TStringList;
488         i: Integer;
489         Rec: TIndexRec;
490         UnRead: Integer;
491 //      TmpUpdate: Boolean;
492         ini: TMemIniFile;
493         ResRec: TResRec;
494         RoundItem: TRoundItem;
495         idx: Integer;
496 begin
497         Board.Clear;
498         UnRead := 0;
499 //      TmpUpdate := False;
500
501         FileName := Board.GetFolderIndexFileName;
502         if not FileExists(FileName) then CreateThreadDat(Board);
503 //      if not FileExists(FileName) then Exit;
504
505         //IsLogFile\97pDAT\83t\83@\83C\83\8b\83\8a\83X\83g
506         FileList := TStringList.Create;
507         FileList.Sorted := True;
508         GetFileList(ExtractFileDir(Board.GetFolderIndexFileName), '*.dat', FileList, False, False);
509
510         //\91O\89ñ\88Ù\8fí\8fI\97¹\8e\9e\97pTmp\83t\83@\83C\83\8b\83\8a\83X\83g
511         TmpFileList := TStringList.Create;
512         TmpFileList.Sorted := True;
513         GetFileList(ExtractFileDir(Board.GetFolderIndexFileName), '*.tmp', TmpFileList, False, False);
514
515 {       R := FindFirst(ExtractFileDir(Board.GetFolderIndexFileName) + '\*.dat', 0, SrchRec);
516         while R = 0 do begin
517                 FileList.Add(SrchRec.Name);
518                 R := FindNext(SrchRec);
519         end;
520         FindClose(SrchRec);}
521
522         sl := TStringList.Create;
523         try
524                 if FileExists(FileName) then
525                         sl.LoadFromFile(FileName);
526
527                 //\82Q\8ds\96Ú\82©\82ç\81i\82P\8ds\96Ú\82Í\83o\81[\83W\83\87\83\93\81j
528                 for i := 1 to sl.Count - 1 do begin
529                         Rec := ParseIndexLine(sl[i]);
530
531                         ThreadItem := TThreadItem.Create;
532                         ThreadItem.BeginUpdate;
533                         ThreadItem.No := Rec.FNo;
534                         ThreadItem.FileName := Rec.FFileName;
535                         ThreadItem.Title := Rec.FTitle;
536                         ThreadItem.Count := Rec.FCount;
537                         ThreadItem.Size := Rec.FSize;
538 //                      ThreadItem.RoundNo := Rec.FRoundNo;
539                         ThreadItem.RoundDate := Rec.FRoundDate;
540                         ThreadItem.LastModified := Rec.FLastModified;
541                         ThreadItem.Kokomade := Rec.FKokomade;
542                         ThreadItem.NewReceive := Rec.FNewReceive;
543 //                      ThreadItem.Round := Rec.FRound;
544                         ThreadItem.UnRead := Rec.FUnRead;
545                         ThreadItem.ScrollTop := Rec.FScrollTop;
546                         ThreadItem.AllResCount := Rec.FAllResCount;
547                         ThreadItem.NewResCount := Rec.FNewResCount;
548                         ThreadItem.AgeSage := Rec.FAgeSage;
549                         ThreadItem.ParentBoard := Board;
550
551                         //IsLogFile\83`\83F\83b\83N
552                         ThreadItem.IsLogFile := False;
553                         if FileList.Count <> 0 then begin
554                                 if FileList.Find(ThreadItem.FileName, Index) then begin
555                                         ThreadItem.IsLogFile := True;
556                                         FileList.Delete(Index);
557                                 end;
558                         end;
559
560                         //\8f\84\89ñ\83\8a\83X\83g\82É\91\8dÝ\82µ\82½\82ç\8f\84\89ñ\83t\83\89\83O\83Z\83b\83g
561                         if ThreadItem.IsLogFile then begin
562                                 idx := RoundList.Find(ThreadItem);
563                                 if idx <> -1 then begin
564                                         RoundItem := RoundList.Items[idx, grtItem];
565                                         ThreadItem.RoundName := RoundItem.RoundName;
566                                         ThreadItem.Round := True;
567                                 end;
568                         end;
569
570                         //\91O\89ñ\88Ù\8fí\8fI\97¹\8e\9e\83`\83F\83b\83N
571                         if TmpFileList.Count <> 0 then begin
572                                 if TmpFileList.Find(ChangeFileExt(ThreadItem.FileName, '.tmp'), Index) then begin
573                                         ini := TMemIniFile.Create(ChangeFileExt(ThreadItem.GetThreadFileName, '.tmp'));
574                                         try
575                                                 ThreadItem.RoundDate := ini.ReadDateTime('Setting', 'RoundDate', ZERO_DATE);
576                                                 ThreadItem.LastModified := ini.ReadDateTime('Setting', 'LastModified', ZERO_DATE);
577                                                 ThreadItem.Size := ini.ReadInteger('Setting', 'Size', 0);
578                                                 ThreadItem.Count := ini.ReadInteger('Setting', 'Count', 0);
579                                                 ThreadItem.NewReceive := ini.ReadInteger('Setting', 'NewReceive', 0);
580                                                 ThreadItem.Round := ini.ReadBool('Setting', 'Round', False);
581                                                 ThreadItem.UnRead := False;//ini.ReadBool('Setting', 'UnRead', False);
582                                                 ThreadItem.ScrollTop := ini.ReadInteger('Setting', 'ScrollTop', 0);
583                                                 ThreadItem.AllResCount := ini.ReadInteger('Setting', 'AllResCount', 0);
584                                                 ThreadItem.NewResCount := ini.ReadInteger('Setting', 'NewResCount', 0);
585                                                 ThreadItem.AgeSage := TGikoAgeSage(ini.ReadInteger('Setting', 'AgeSage', Ord(gasNone)));
586                                         finally
587                                                 ini.Free;
588                                         end;
589                                         TmpFileList.Delete(Index);
590                                 end;
591                         end;
592
593                         ThreadItem.EndUpdate;
594                         Board.Add(ThreadItem);
595
596 //                      if (ThreadItem.IsLogFile) and (ThreadItem.Count > ThreadItem.Kokomade) then
597                         if (ThreadItem.IsLogFile) and (ThreadItem.UnRead) then
598                                 Inc(UnRead);
599                 end;
600                 if UnRead <> Board.UnRead then
601                         Board.UnRead := UnRead;
602
603                 //\83C\83\93\83f\83b\83N\83X\82É\96³\82©\82Á\82½\83\8d\83O\82ð\92Ç\89Á\81i\95\85\82ê\83C\83\93\83f\83b\83N\83X\91Î\89\9e\81j
604                 for i := 0 to FileList.Count - 1 do begin
605                         FileName := ExtractFileDir(Board.GetFolderIndexFileName) + '\' + FileList[i];
606
607                         ResRec := DivideStrLine(ReadThreadFile(FileName, 1));
608                         ThreadItem := TThreadItem.Create;
609                         ThreadItem.No := Board.Count + 1;
610                         ThreadItem.FileName := FileList[i];
611                         ThreadItem.Title := ResRec.FTitle;
612                         ThreadItem.Count := GetFileLineCount(FileName);
613                         ThreadItem.AllResCount := ThreadItem.Count;
614                         ThreadItem.NewResCount := 0;
615                         ThreadItem.Size := 0;
616                         ThreadItem.RoundDate := ZERO_DATE;
617                         ThreadItem.LastModified := ZERO_DATE;
618                         ThreadItem.Kokomade := -1;
619                         ThreadItem.NewReceive := 0;
620                         ThreadItem.ParentBoard := Board;
621                         ThreadItem.IsLogFile := True;
622                         ThreadItem.Round := False;
623                         ThreadItem.UnRead := False;
624                         ThreadItem.ScrollTop := 0;
625                         ThreadItem.AgeSage := gasNone;
626                         Board.Add(ThreadItem);
627                 end;
628         finally
629                 sl.Free;
630         end;
631         FileList.Free;
632         TmpFileList.Free;
633         Board.IsThreadDatRead := True;
634 end;
635
636 (*************************************************************************
637  *\83X\83\8c\83b\83h\83C\83\93\83f\83b\83N\83X\83t\83@\83C\83\8b(Folder.idx)\8dì\90¬
638  *************************************************************************)
639 procedure TGikoSys.CreateThreadDat(Board: TBoard);
640 var
641         i: integer;
642         s: string;
643         SubjectList: TStringList;
644         sl: TStringList;
645         Rec: TSubjectRec;
646         FileName: string;
647         cnt: Integer;
648 begin
649         if not FileExists(Board.GetSubjectFileName) then Exit;
650         FileName := Board.GetFolderIndexFileName;
651
652         SubjectList := TStringList.Create;
653         try
654                 SubjectList.LoadFromFile(Board.GetSubjectFileName);
655                 sl := TStringList.Create;
656                 try
657                         cnt := 1;
658                         sl.Add(FOLDER_INDEX_VERSION);
659                         for i := 0 to SubjectList.Count - 1 do begin
660                                 Rec := DivideSubject(SubjectList[i]);
661
662                                 if (Trim(Rec.FFileName) = '') or (Trim(Rec.FTitle) = '') then
663                                         Continue;
664
665                                 s := Format('%x', [cnt]) + #1                                   //\94Ô\8d\86
666                                          + Rec.FFileName + #1                                                           //\83t\83@\83C\83\8b\96¼
667                                          + Rec.FTitle + #1                                                                      //\83^\83C\83g\83\8b
668                                          + Format('%x', [Rec.FCount]) + #1      //\83J\83E\83\93\83g
669                                          + Format('%x', [0]) + #1                                               //size
670                                          + Format('%x', [0]) + #1                                               //RoundDate
671                                          + Format('%x', [0]) + #1                                               //LastModified
672                                          + Format('%x', [0]) + #1                                               //Kokomade
673                                          + Format('%x', [0]) + #1                                               //NewReceive
674                                          + '0' + #1                                                                                             //\96¢\8eg\97p
675                                          + Format('%x', [0]) + #1                                               //UnRead
676                                          + Format('%x', [0]) + #1                                               //ScrollTop
677                                          + Format('%x', [Rec.FCount]) + #1      //AllResCount
678                                          + Format('%x', [0]) + #1                                               //NewResCount
679                                          + Format('%x', [0]);                                                           //AgeSage
680
681                                 sl.Add(s);
682                                 inc(cnt);
683                         end;
684                         sl.SaveToFile(FileName);
685                 finally
686                         sl.Free;
687                 end;
688         finally
689                 SubjectList.Free;
690         end;
691 end;
692
693 (*************************************************************************
694  *\83X\83\8c\83b\83h\83C\83\93\83f\83b\83N\83X(Thread.dat)\8f\91\82«\8d\9e\82Ý
695  *Public
696  *************************************************************************)
697 procedure TGikoSys.WriteThreadDat(Board: TBoard);
698 //const
699 //      Values: array[Boolean] of string = ('0', '1');
700 var
701         i: integer;
702         FileName: string;
703         sl: TStringList;
704         s: string;
705         FileList: TStringList;
706 begin
707         if not Board.IsThreadDatRead then
708                 Exit;
709         FileName := Board.GetFolderIndexFileName;
710         ForceDirectoriesEx(Board.ParentCategory.ParentBBS2ch.GetLogFolder + Board.BBSID);
711
712         sl := TStringList.Create;
713         try
714                 sl.Add(FOLDER_INDEX_VERSION);
715                 for i := 0 to Board.Count - 1 do begin
716                         if Board.Items[i].No = 0 then
717                                 Board.Items[i].No := i + 1;
718
719                         s := Format('%x', [Board.Items[i].No]) + #1
720                                  + Board.Items[i].FileName + #1
721                                  + Board.Items[i].Title + #1
722                                  + Format('%x', [Board.Items[i].Count]) + #1
723                                  + Format('%x', [Board.Items[i].Size]) + #1
724                                  + Format('%x', [DateTimeToInt(Board.Items[i].RoundDate)]) + #1
725                                  + Format('%x', [DateTimeToInt(Board.Items[i].LastModified)]) + #1
726                                  + Format('%x', [Board.Items[i].Kokomade]) + #1
727                                  + Format('%x', [Board.Items[i].NewReceive]) + #1
728                                  + '0' + #1     //\96¢\8eg\97p
729                                  + Format('%x', [BoolToInt(Board.Items[i].UnRead)]) + #1
730                                  + Format('%x', [Board.Items[i].ScrollTop]) + #1
731                                  + Format('%x', [Board.Items[i].AllResCount]) + #1
732                                  + Format('%x', [Board.Items[i].NewResCount]) + #1
733                                  + Format('%x', [Ord(Board.Items[i].AgeSage)]);
734
735                         sl.Add(s);
736                 end;
737
738                 sl.SaveToFile(FileName);
739
740                 FileList := TStringList.Create;
741                 try
742                         GetFileList(ExtractFileDir(Board.GetFolderIndexFileName), '*.tmp', FileList, False, True);
743                         for i := 0 to FileList.Count - 1 do begin
744                                 DeleteFile(FileList[i]);
745                         end;
746                 finally
747                         FileList.Free;
748                 end;
749         finally
750                 sl.Free;
751         end;
752 end;
753
754 function TGikoSys.ParseIndexLine(Line: string): TIndexRec;
755 var
756         s: string;
757         i: Integer;
758 begin
759         for i := 0 to 14 do begin
760                 s := GetTokenIndex(Line, #1, i);
761                 case i of
762                         0: Result.FNo := StrToIntDef('$' + s, 0);
763                         1: Result.FFileName := s;
764                         2: Result.FTitle := s;
765                         3: Result.FCount := StrToIntDef('$' + s, 0);
766                         4: Result.FSize := StrToIntDef('$' + s, 0);
767                         5: Result.FRoundDate := IntToDateTime(StrToIntDef('$' + s, ZERO_DATE));
768                         6: Result.FLastModified := IntToDateTime(StrToIntDef('$' + s, ZERO_DATE));
769                         7: Result.FKokomade := StrToIntDef('$' + s, -1);
770                         8: Result.FNewReceive := StrToIntDef('$' + s, 0);
771                         9: ;    //\96¢\8eg\97p
772                         10: Result.FUnRead := IntToBool(StrToIntDef('$' + s, 0));
773                         11: Result.FScrollTop := StrToIntDef('$' + s, 0);
774                         12: Result.FAllResCount := StrToIntDef('$' + s, 0);
775                         13: Result.FNewResCount := StrToIntDef('$' + s, 0);
776                         14: Result.FAgeSage := TGikoAgeSage(StrToIntDef('$' + s, 0));
777                 end;
778         end;
779 end;
780
781 //\8ew\92è\83t\83H\83\8b\83_\93à\82Ì\8ew\92è\83t\83@\83C\83\8b\88ê\97\97\82ð\8eæ\93¾\82·\82é
782 // ListFiles('c:\', '*.txt', list, True);
783 procedure TGikoSys.GetFileList(Path: string; Mask: string; List: TStringList; SubDir: Boolean; IsPathAdd: Boolean);
784 var
785         rc: Integer;
786         SearchRec : TSearchRec;
787         s: string;
788 begin
789         Path := IncludeTrailingPathDelimiter(Path);
790         rc := FindFirst(Path + '*.*', faAnyfile, SearchRec);
791         try
792                 while rc = 0 do begin
793                         if (SearchRec.Name <> '..') and (SearchRec.Name <> '.') then begin
794                                 s := Path + SearchRec.Name;
795                                 //if (SearchRec.Attr and faDirectory > 0) then
796                                 //      s := IncludeTrailingPathDelimiter(s)
797
798                                 if (SearchRec.Attr and faDirectory = 0) and (MatchesMask(s, Mask)) then
799                                         if IsPathAdd then
800                                                 List.Add(s)
801                                         else
802                                                 List.Add(SearchRec.Name);
803                                 if SubDir and (SearchRec.Attr and faDirectory > 0) then
804                                         GetFileList(s, Mask, List, True, IsPathAdd);
805                         end;
806                         rc := FindNext(SearchRec);
807                 end;
808         finally
809                 SysUtils.FindClose(SearchRec);
810         end;
811 end;
812
813 //\8ew\92è\83t\83H\83\8b\83_\93à\82Ì\83f\83B\83\8c\83N\83g\83\8a\88ê\97\97\82ð\8eæ\93¾\82·\82é
814 procedure TGikoSys.GetDirectoryList(Path: string; Mask: string; List: TStringList; SubDir: Boolean);
815 var
816         rc: Integer;
817         SearchRec : TSearchRec;
818         s: string;
819 begin
820         Path := IncludeTrailingPathDelimiter(Path);
821         rc := FindFirst(Path + '*.*', faDirectory, SearchRec);
822         try
823                 while rc = 0 do begin
824                         if (SearchRec.Name <> '..') and (SearchRec.Name <> '.') then begin
825                                 s := Path + SearchRec.Name;
826                                 //if (SearchRec.Attr and faDirectory > 0) then
827                                 //      s := IncludeTrailingPathDelimiter(s)
828
829                                 if (SearchRec.Attr and faDirectory > 0) and (MatchesMask(s, Mask)) then
830                                         List.Add( IncludeTrailingPathDelimiter( s ) );
831                                 if SubDir and (SearchRec.Attr and faDirectory > 0) then
832                                         GetDirectoryList(s, Mask, List, True);
833                         end;
834                         rc := FindNext(SearchRec);
835                 end;
836         finally
837                 SysUtils.FindClose(SearchRec);
838         end;
839 end;
840
841 // \83X\83L\83\93\82ð\93Ç\82Ý\8d\9e\82Ý\81A\92l\82ð\92u\8a·\82·\82é
842 function TGikoSys.LoadFromSkin(
843         fileName: string;
844         ThreadItem: TThreadItem;
845         SizeByte: Integer
846 ): string;
847 var
848         Skin: TStringList;
849 begin
850
851         Skin := TStringList.Create;
852         try
853                 if FileExists( fileName ) then begin
854                         Skin.LoadFromFile( fileName );
855
856                         // \82â\82è\82©\82½\82ª\8bê\82µ\82¢\82¯\82Ç\81A\83I\83v\83V\83\87\83\93\83_\83C\83A\83\8d\83O\82Ì\83v\83\8c\83r\83\85\81[\97p try
857                         try
858         if ThreadItem.ParentBoard <> nil then
859                                         if ThreadItem.ParentBoard.ParentCategory <> nil then
860                                                 Skin.Text := StringReplace( Skin.Text, '<BBSNAME/>', ThreadItem.ParentBoard.ParentCategory.ParentBBS2ch.Title, [rfReplaceAll] );
861                                 Skin.Text := StringReplace( Skin.Text, '<THREADURL/>', ThreadItem.URL, [rfReplaceAll] );
862                         except end;
863                         Skin.Text := StringReplace( Skin.Text, '<BOARDNAME/>', ThreadItem.ParentBoard.Title, [rfReplaceAll] );
864                         Skin.Text := StringReplace( Skin.Text, '<BOARDURL/>', ThreadItem.ParentBoard.URL, [rfReplaceAll] );
865                         Skin.Text := StringReplace( Skin.Text, '<THREADNAME/>', ThreadItem.Title, [rfReplaceAll] );
866                         Skin.Text := StringReplace( Skin.Text, '<SKINPATH/>', Setting.CSSFileName, [rfReplaceAll] );
867                         Skin.Text := StringReplace( Skin.Text, '<GETRESCOUNT/>', IntToStr( ThreadItem.NewReceive - 1 ), [rfReplaceAll] );
868                         Skin.Text := StringReplace( Skin.Text, '<NEWRESCOUNT/>', IntToStr( ThreadItem.NewResCount ), [rfReplaceAll] );
869                         Skin.Text := StringReplace( Skin.Text, '<ALLRESCOUNT/>', IntToStr( ThreadItem.AllResCount ), [rfReplaceAll] );
870
871                         Skin.Text := StringReplace( Skin.Text, '<NEWDATE/>',
872                         FormatDateTime('yyyy/mm/dd(ddd) hh:mm', ThreadItem.RoundDate), [rfReplaceAll] );
873                         Skin.Text := StringReplace( Skin.Text, '<SIZEKB/>', IntToStr( Floor( SizeByte / 1024 ) ), [rfReplaceAll] );
874                         Skin.Text := StringReplace( Skin.Text, '<SIZE/>', IntToStr( SizeByte ), [rfReplaceAll] );
875
876                         //----- \82Æ\82è\82 \82¦\82¸\82©\82¿\82ã\81`\82µ\82á\8cÝ\8a·\97p\81B\83R\83\81\83\93\83g\83A\83E\83g\82µ\82Ä\82à\82æ\82µ
877                         // \82â\82è\82©\82½\82ª\8bê\82µ\82¢\82¯\82Ç\81A\83I\83v\83V\83\87\83\93\83_\83C\83A\83\8d\83O\82Ì\83v\83\8c\83r\83\85\81[\97p try
878                         try
879         if ThreadItem.ParentBoard <> nil then
880                                         if ThreadItem.ParentBoard.ParentCategory <> nil then
881                                                 Skin.Text := StringReplace( Skin.Text, '&BBSNAME', ThreadItem.ParentBoard.ParentCategory.ParentBBS2ch.Title, [rfReplaceAll] );
882                                 Skin.Text := StringReplace( Skin.Text, '&THREADURL', ThreadItem.URL, [rfReplaceAll] );
883                         except end;
884                         Skin.Text := StringReplace( Skin.Text, '&BOARDNAME', ThreadItem.ParentBoard.Title, [rfReplaceAll] );
885                         Skin.Text := StringReplace( Skin.Text, '&BOARDURL', ThreadItem.ParentBoard.URL, [rfReplaceAll] );
886                         Skin.Text := StringReplace( Skin.Text, '&THREADNAME', ThreadItem.Title, [rfReplaceAll] );
887                         Skin.Text := StringReplace( Skin.Text, '&SKINPATH', Setting.CSSFileName, [rfReplaceAll] );
888                         Skin.Text := StringReplace( Skin.Text, '&GETRESCOUNT', IntToStr( ThreadItem.NewReceive - 1 ), [rfReplaceAll] );
889                         Skin.Text := StringReplace( Skin.Text, '&NEWRESCOUNT', IntToStr( ThreadItem.NewResCount ), [rfReplaceAll] );
890                         Skin.Text := StringReplace( Skin.Text, '&ALLRESCOUNT', IntToStr( ThreadItem.AllResCount ), [rfReplaceAll] );
891
892                         Skin.Text := StringReplace( Skin.Text, '&NEWDATE',
893                                         FormatDateTime('yyyy/mm/dd(ddd) hh:mm', ThreadItem.RoundDate), [rfReplaceAll] );
894                         Skin.Text := StringReplace( Skin.Text, '&SIZEKB', IntToStr( Floor( SizeByte / 1024 ) ), [rfReplaceAll] );
895                         Skin.Text := StringReplace( Skin.Text, '&SIZE', IntToStr( SizeByte ), [rfReplaceAll] );
896                         //----- \82±\82±\82Ü\82Å
897                 end;
898                 Result := Skin.Text;
899         finally
900                 Skin.Free;
901         end;
902 end;
903
904 // \83\8c\83X\82Ì\92l\82ð\92u\8a·\82·\82é
905 function TGikoSys.SkinedRes(
906         skin: string;
907         Res: TResRec;
908         No: string
909 ): string;
910 begin
911
912         try
913                 Skin := StringReplace( Skin, '<NUMBER/>',
914                         '<a href="menu:' + No + '" name="' + No + '">' + No + '</a>', [rfReplaceAll] );
915                 Skin := StringReplace( Skin, '<PLAINNUMBER/>', No, [rfReplaceAll] );
916                 Skin := StringReplace( Skin, '<NAME/>', '<b>' + Res.FName + '</b>', [rfReplaceAll] );
917                 Skin := StringReplace( Skin, '<MAILNAME/>',
918                         '<a href="mailo:' + Res.FMailTo + '"><b>' + Res.FName + '</b></a>', [rfReplaceAll] );
919                 Skin := StringReplace( Skin, '<MAIL/>', Res.FMailTo, [rfReplaceAll] );
920                 Skin := StringReplace( Skin, '<DATE/>', Res.FDateTime, [rfReplaceAll] );
921                 Skin := StringReplace( Skin, '<MESSAGE/>', Res.FBody, [rfReplaceAll] );
922
923                 //----- \82©\82¿\82ã\81`\82µ\82á\8cÝ\8a·\97p\81B\83R\83\81\83\93\83g\83A\83E\83g\82µ\82Ä\82à\82æ\82µ
924                 Skin := StringReplace( Skin, '&NUMBER',
925                         '<a href="menu:' + No + '" name="' + No + '">' + No + '</a>', [rfReplaceAll] );
926                 Skin := StringReplace( Skin, '&PLAINNUMBER', No, [rfReplaceAll] );
927                 Skin := StringReplace( Skin, '&NAME', '<b>' + Res.FName + '</b>', [rfReplaceAll] );
928                 Skin := StringReplace( Skin, '&MAILNAME',
929                         '<a href="mailo:' + Res.FMailTo + '"><b>' + Res.FName + '</b></a>', [rfReplaceAll] );
930                 Skin := StringReplace( Skin, '&MAIL', Res.FMailTo, [rfReplaceAll] );
931                 Skin := StringReplace( Skin, '&DATE', Res.FDateTime, [rfReplaceAll] );
932                 Skin := StringReplace( Skin, '&MESSAGE', Res.FBody, [rfReplaceAll] );
933                 //----- \82±\82±\82Ü\82Å
934
935                 Result := Skin;
936         finally
937         end;
938
939 end;
940
941 procedure TGikoSys.CreateHTML2(doc: Variant; ThreadItem: TThreadItem; var sTitle: string);
942 var
943         i: integer;
944         No: string;
945         //bufList : TStringList;
946         ReadList: TStringList;
947         SaveList: TStringList;
948         CSSFileName: string;
949         BBSID: string;
950         FileName: string;
951         NewReceiveNo: Integer;
952         Res: TResRec;
953         boardPlugIn : TBoardPlugIn;
954
955         UserOptionalStyle: string;
956         SkinHeader: string;
957         SkinNewRes: string;
958         SkinRes: string;
959         SizeByte: Integer;
960
961         function LoadSkin( fileName: string ): string;
962         begin
963                 Result := LoadFromSkin( fileName, ThreadItem, SizeByte );
964         end;
965         function ReplaceRes( skin: string ): string;
966         begin
967                 Result := SkinedRes( skin, Res, No );
968         end;
969 begin
970         if ThreadItem <> nil then
971                 boardPlugIn := ThreadItem.BoardPlugIn
972         else
973                 boardPlugIn := nil;
974         if boardPlugIn <> nil then begin
975                 //===== \83v\83\89\83O\83C\83\93\82É\82æ\82é\95\\8e¦
976                 if Assigned( Pointer( boardPlugIn.Module ) ) then begin
977                         NewReceiveNo := ThreadItem.NewReceive;
978
979                         // \83t\83H\83\93\83g\82â\83T\83C\83Y\82Ì\90Ý\92è
980                         if Length( GikoSys.Setting.BrowserFontName ) > 0 then
981                                 UserOptionalStyle := UserOptionalStyle +
982                                                                 'font-family:"' + GikoSys.Setting.BrowserFontName + '";';
983                         if GikoSys.Setting.BrowserFontSize <> 0 then
984                                 UserOptionalStyle := UserOptionalStyle +
985                                                                 'font-size:' + IntToStr( GikoSys.Setting.BrowserFontSize ) + 'pt;';
986                         if GikoSys.Setting.BrowserFontColor <> -1 then
987                                 UserOptionalStyle := UserOptionalStyle +
988                                                                 'color:#' + IntToHex( GikoSys.Setting.BrowserFontColor, 6 ) + ';';
989                         if GikoSys.Setting.BrowserBackColor <> -1 then
990                                 UserOptionalStyle := UserOptionalStyle +
991                                                                 'background-color:#' + IntToHex( GikoSys.Setting.BrowserBackColor, 6 ) + ';';
992                         case GikoSys.Setting.BrowserFontBold of
993                                 -1: UserOptionalStyle := UserOptionalStyle + 'font-weight:normal;';
994                                 1: UserOptionalStyle := UserOptionalStyle + 'font-weight:bold;';
995                         end;
996                         case GikoSys.Setting.BrowserFontItalic of
997                                 -1: UserOptionalStyle := UserOptionalStyle + 'font-style:normal;';
998                                 1: UserOptionalStyle := UserOptionalStyle + 'font-style:italic;';
999                         end;
1000
1001                         SaveList := TStringList.Create;
1002                         try
1003                                 doc.open;
1004                                 // \95\8e\9a\83R\81[\83h\82Í\83v\83\89\83O\83C\83\93\82É\94C\82¹\82é
1005                                 // doc.charset := 'Shift_JIS';
1006                                 threadItem.SizeByte := 0;
1007
1008                                 // \83w\83b\83_
1009                                 SaveList.Add( boardPlugIn.GetHeader( DWORD( threadItem ),
1010                                         '<style type="text/css">body {' + UserOptionalStyle + '}</style>' ) );
1011                                 SaveList.Add('<a name="top"></a>');
1012
1013                                 for i := 0 to threadItem.AllResCount - 1 do begin
1014                                         if (OnlyAHundredRes = true) and ( i <> 0 ) and ( (threadItem.AllResCount-i) > 101 ) then begin
1015                                                 Continue;
1016                                         end;
1017
1018                                         // \90V\92\85\83}\81[\83N
1019                                         if (NewReceiveNo = (i + 1)) or ((NewReceiveNo = 0) and (i = 0)) then begin
1020                                                 try
1021                                                         SaveList.Add( LoadSkin( GetSkinNewmarkFileName ) );
1022                                                 except
1023                                                         SaveList.Add( '<a name="new"></a>' );
1024                                                 end;
1025                                         end;
1026
1027                                         // \83\8c\83X
1028                                         SaveList.Add( boardPlugIn.GetRes( DWORD( threadItem ), i + 1 ) );
1029
1030                                         if ThreadItem.Kokomade = (i + 1) then begin
1031                                                 // \82±\82±\82Ü\82Å\93Ç\82ñ\82¾
1032                                                 try
1033                                                         SaveList.Add( LoadSkin( GetSkinBookmarkFileName ) );
1034                                                 except
1035                                                         SaveList.Add( '<a name="koko"></a>' );
1036                                                 end;
1037                                         end;
1038
1039                                         threadItem.SizeByte := SizeByte + Length( SaveList.Text );
1040                                         doc.Write(SaveList.Text);
1041                                         SaveList.Clear;
1042                                 end;
1043
1044                                 SaveList.Add('<a name="bottom"></a>');
1045                                 threadItem.SizeByte := SizeByte + Length( SaveList.Text );
1046
1047                                 // \83X\83L\83\93(\83t\83b\83^)
1048                                 SaveList.Add( boardPlugIn.GetFooter( DWORD( threadItem ), '' ) );
1049
1050                                 doc.Write(SaveList.Text);
1051                         finally
1052                                 SaveList.Free;
1053                                 doc.Close;
1054                         end;
1055
1056                         Exit;
1057                 end;
1058         end;
1059         ShortDayNames[1] := '\93ú';               ShortDayNames[2] := '\8c\8e';
1060         ShortDayNames[3] := '\89Î';               ShortDayNames[4] := '\90\85';
1061         ShortDayNames[5] := '\96Ø';               ShortDayNames[6] := '\8bà';
1062         ShortDayNames[7] := '\93y';
1063         SizeByte := 0;
1064         BBSID := ThreadItem.ParentBoard.BBSID;
1065         NewReceiveNo := ThreadItem.NewReceive;
1066         ReadList := TStringList.Create;
1067         try
1068                 if ThreadItem.IsLogFile then begin
1069                         FileName := ThreadItem.GetThreadFileName;
1070                         ReadList.LoadFromFile(FileName);
1071                         FAbon.IndividualAbon(ReadList, ChangeFileExt(FileName,'.NG'));
1072                         FAbon.Execute(ReadList);                //       \82 \82Ú\81`\82ñ\82µ\82Ä
1073                         FSelectResFilter.Execute(ReadList); //\83\8c\83X\82Ì\83t\83B\83\8b\83^\83\8a\83\93\83O\82ð\82·\82é
1074                         Res := DivideStrLine(ReadList[0]);
1075                         Res.FTitle := StringReplace(Res.FTitle, '\81\97\81M', ',', [rfReplaceAll]);
1076                         sTitle := Res.FTitle;
1077                 end else begin
1078                         sTitle := StringReplace(ThreadItem.Title, '\81\97\81M', ',', [rfReplaceAll]);
1079                 end;
1080                 SaveList := TStringList.Create;
1081                 try
1082                         doc.open;
1083                         doc.charset := 'Shift_JIS';
1084
1085                         // \83t\83H\83\93\83g\82â\83T\83C\83Y\82Ì\90Ý\92è
1086                         if Length( GikoSys.Setting.BrowserFontName ) > 0 then
1087                                 UserOptionalStyle := UserOptionalStyle +
1088                                                                 'font-family:"' + GikoSys.Setting.BrowserFontName + '";';
1089                         if GikoSys.Setting.BrowserFontSize <> 0 then
1090                                 UserOptionalStyle := UserOptionalStyle +
1091                                                                 'font-size:' + IntToStr( GikoSys.Setting.BrowserFontSize ) + 'pt;';
1092                         if GikoSys.Setting.BrowserFontColor <> -1 then
1093                                 UserOptionalStyle := UserOptionalStyle +
1094                                                                 'color:#' + IntToHex( GikoSys.Setting.BrowserFontColor, 6 ) + ';';
1095                         if GikoSys.Setting.BrowserBackColor <> -1 then
1096                                 UserOptionalStyle := UserOptionalStyle +
1097                                                                 'background-color:#' + IntToHex( GikoSys.Setting.BrowserBackColor, 6 ) + ';';
1098                         case GikoSys.Setting.BrowserFontBold of
1099                                 -1: UserOptionalStyle := UserOptionalStyle + 'font-weight:normal;';
1100                                 1: UserOptionalStyle := UserOptionalStyle + 'font-weight:bold;';
1101                         end;
1102                         case GikoSys.Setting.BrowserFontItalic of
1103                                 -1: UserOptionalStyle := UserOptionalStyle + 'font-style:normal;';
1104                                 1: UserOptionalStyle := UserOptionalStyle + 'font-style:italic;';
1105                         end;
1106
1107                         CSSFileName := GetStyleSheetDir + Setting.CSSFileName;
1108                         if GikoSys.Setting.UseSkin then begin
1109                                 // \83X\83L\83\93\8eg\97p
1110                                 // \83X\83L\83\93\82Ì\90Ý\92è
1111                                 try
1112                                         SkinHeader := LoadSkin( GetSkinHeaderFileName );
1113                                         if Length( UserOptionalStyle ) > 0 then
1114                                                 SkinHeader := StringReplace( SkinHeader, '</head>',
1115                                                         '<style type="text/css">body {' + UserOptionalStyle + '}</style></head>', [rfReplaceAll] );
1116                                         SaveList.Add( SkinHeader );
1117                                 except
1118                                 end;
1119                                 try
1120                                         SkinNewRes := LoadSkin( GetSkinNewResFileName );
1121                                 except
1122                                                                 end;
1123                                 try
1124                                         SkinRes := LoadSkin( GetSkinResFileName );
1125                                 except
1126                                 end;
1127
1128                                 SaveList.Add('<a name="top"></a>');
1129
1130                                 for i := 0 to ReadList.Count - 1 do begin
1131                                         if (OnlyAHundredRes = true) and ( i <> 0 ) and ( (ReadList.Count-i) > 101 ) then begin
1132                                                 Continue;
1133                                         end;
1134                                         if (Trim(ReadList[i]) <> '') then begin
1135                                                 No := IntToStr(i + 1);
1136
1137                                                 Res := DivideStrLine(ReadList[i]);
1138                                                 Res.FBody := ConvRes(Res.FBody, ThreadItem.ParentBoard.BBSID, ChangeFileExt(ThreadItem.FileName, ''), 'bbs', 'key', 'st', 'to', 'nofirst', 'true');
1139
1140                                                 if Res.FType = glt2chOld then begin
1141                                                         Res.FMailTo := StringReplace(Res.FMailTo, '\81\97\81M', ',', [rfReplaceAll]);
1142                                                         Res.FName := StringReplace(Res.FName, '\81\97\81M', ',', [rfReplaceAll]);
1143                                                         Res.FBody := StringReplace(Res.FBody, '\81\97\81M', ',', [rfReplaceAll]);
1144                                                 end;
1145
1146                                                 Res.FBody := AddAnchorTag(Res.FBody);
1147                                                 if Res.FName = '' then
1148                                                         Res.FName := '&nbsp;';
1149
1150                                                 // \90V\92\85\83}\81[\83N
1151                                                 if (NewReceiveNo = (i + 1)) or ((NewReceiveNo = 0) and (i = 0)) then begin
1152                                                         try
1153                                                                 SaveList.Add( LoadSkin( GetSkinNewmarkFileName ) );
1154                                                         except
1155                                                                 SaveList.Add( '<a name="new"></a>' );
1156                                                         end;
1157                                                 end;
1158                                                 try
1159                                                         if NewReceiveNo <= (i + 1) then
1160                                                                 // \90V\92\85\83\8c\83X
1161                                                                 SaveList.Add( ReplaceRes( SkinNewRes ) )
1162                                                         else
1163                                                                 // \92Ê\8fí\82Ì\83\8c\83X
1164                                                                 SaveList.Add( ReplaceRes( SkinRes ) );
1165                                                 except
1166                                                 end;
1167                                                 if ThreadItem.Kokomade = (i + 1) then begin
1168                                                         // \82±\82±\82Ü\82Å\93Ç\82ñ\82¾
1169                                                         try
1170                                                                 SaveList.Add( LoadSkin( GetSkinBookmarkFileName ) );
1171                                                         except
1172                                                                 SaveList.Add( '<a name="koko"></a>' );
1173                                                         end;
1174                                                 end;
1175                                         end;
1176                                         SizeByte := SizeByte + Length( SaveList.Text );
1177                                         doc.Write(SaveList.Text);
1178                                         SaveList.Clear;
1179                                 end;
1180                                 SaveList.Add('<a name="bottom"></a>');
1181                                 SizeByte := SizeByte + Length( SaveList.Text );
1182                                 // \83X\83L\83\93(\83t\83b\83^)
1183                                 try
1184                                         SaveList.Add( LoadSkin( GetSkinFooterFileName ) );
1185                                 except
1186                                 end;
1187                                 doc.Write(SaveList.Text);
1188
1189                         end else if GikoSys.Setting.UseCSS and FileExists(CSSFileName) then begin
1190                                 //CSS\8eg\97p
1191                                 //CSSFileName := GetAppDir + CSS_FILE_NAME;
1192 //                              SaveList.Add('<html lang="ja"><head>');
1193                                 SaveList.Add('<html><head>');
1194                                 SaveList.Add('<meta http-equiv="Content-type" content="text/html; charset=Shift_JIS">');
1195                                 SaveList.Add('<title>' + sTitle + '</title>');
1196                                 SaveList.Add('<link rel="stylesheet" href="'+CSSFileName+'" type="text/css">');
1197                                 if Length( UserOptionalStyle ) > 0 then
1198                                         SaveList.Add('<style type="text/css">body {' + UserOptionalStyle + '}</style>');
1199                                 SaveList.Add('</head>');
1200                                 SaveList.Add('<body>');
1201                                 SaveList.Add('<a name="top"></a>');
1202                                 SaveList.Add('<div class="title">' + sTitle + '</div>');
1203                                 doc.Write(SaveList.Text);
1204                                 SaveList.Clear;
1205                                 //Application.ProcessMessages;
1206                                 for i := 0 to ReadList.Count - 1 do begin
1207                                         if (OnlyAHundredRes = true) and ( i <> 0 ) and ( (ReadList.Count-i) > 101 ) then begin
1208                                                 Continue;
1209                                         end;
1210                                         if (Trim(ReadList[i]) <> '') then begin
1211                                                 No := IntToStr(i + 1);
1212                                                 if (NewReceiveNo = (i + 1)) or ((NewReceiveNo = 0) and (i = 0)) then begin
1213                                                         SaveList.Add('<a name="new"></a><div class="new">\90V\92\85\83\8c\83X <span class="newdate">' + FormatDateTime('yyyy/mm/dd(ddd) hh:mm', ThreadItem.RoundDate) + '</span></div>');
1214                                                 end;
1215                                                 Res := DivideStrLine(ReadList[i]);
1216                                                 Res.FBody := ConvRes(Res.FBody, ThreadItem.ParentBoard.BBSID, ChangeFileExt(ThreadItem.FileName, ''), 'bbs', 'key', 'st', 'to', 'nofirst', 'true');
1217                                                 Res.FBody := AddAnchorTag(Res.FBody);
1218                                                 if Res.FName = '' then
1219                                                         Res.FName := '&nbsp;';
1220                                                 if Res.FMailTo = '' then
1221                                                         SaveList.Add('<a name="' + No + '"></a>'
1222                                                                                         + '<div class="header"><span class="no"><a href="menu:' + No + '">' + No + '</a></span> '
1223                                                                                         + '<span class="name_label">\96¼\91O\81F</span> '
1224                                                                                         + '<span class="name"><b>' + Res.FName + '</b></span> '
1225                                                                                         + '<span class="date_label">\93\8a\8de\93ú\81F</span> '
1226                                                                                         + '<span class="date">' + Res.FDateTime+ '</span></div>'
1227                                                                                                                                                                                 + '<div class="mes">' + Res.FBody + ' </div>')
1228                                                 else if GikoSys.Setting.ShowMail then
1229                                                         SaveList.Add('<a name="' + No + '"></a>'
1230                                                                                         + '<div class="header"><span class="no"><a href="menu:' + No + '">' + No + '</a></span>'
1231                                                                                                                                                                                 + '<span class="name_label"> \96¼\91O\81F </span>'
1232                                                                                         + '<a class="name_mail" href="mailto:' + Res.FMailTo + '">'
1233                                                                                         + '<b>' + Res.FName + '</b></a><span class="mail"> [' + Res.FMailTo + ']</span>'
1234                                                                                         + '<span class="date_label"> \93\8a\8de\93ú\81F</span>'
1235                                                                                         + '<span class="date"> ' + Res.FDateTime+ '</span></div>'
1236                                                                                         + '<div class="mes">' + Res.FBody + ' </div>')
1237                                                 else
1238                                                         SaveList.Add('<a name="' + No + '"></a>'
1239                                                                                         + '<div class="header"><span class="no"><a href="menu:' + No + '">' + No + '</a></span>'
1240                                                                                         + '<span class="name_label"> \96¼\91O\81F </span>'
1241                                                                                         + '<a class="name_mail" href="mailto:' + Res.FMailTo + '">'
1242                                                                                         + '<b>' + Res.FName + '</b></a>'
1243                                                                                         + '<span class="date_label"> \93\8a\8de\93ú\81F</span>'
1244                                                                                         + '<span class="date"> ' + Res.FDateTime+ '</span></div>'
1245                                                                                                                                                                                 + '<div class="mes">' + Res.FBody + ' </div>');
1246                                                 if ThreadItem.Kokomade = (i + 1) then begin
1247                                                         SaveList.Add('<a name="koko"></a><div class="koko">\83R\83R\82Ü\82Å\93Ç\82ñ\82¾</div>');
1248                                                 end;
1249                                         end;
1250
1251                                         doc.Write(SaveList.Text);
1252                                         SaveList.Clear;
1253                                 end;
1254                                 //FOnlyAHundredRes
1255                                 SaveList.Add('<a name="bottom"></a>');
1256                                 SaveList.Add('</body></html>');
1257                                 SaveList.Add('<a name="last"></a>');
1258                                 SaveList.Add('</body></html>');
1259
1260                                 doc.Write(SaveList.Text);
1261                         end else begin
1262                                 //CSS\94ñ\8eg\97p
1263 //                              SaveList.Add('<html lang="ja"><head>');
1264                                 SaveList.Add('<html><head>');
1265                                 SaveList.Add('<meta http-equiv="Content-type" content="text/html; charset=Shift_JIS">');
1266                                 SaveList.Add('<title>' + sTitle + '</title></head>');
1267                                 SaveList.Add('<body TEXT="#000000" BGCOLOR="#EFEFEF" link="#0000FF" alink="#FF0000" vlink="#660099">');
1268                                 SaveList.Add('<a name="top"></a>');
1269                                 SaveList.Add('<font size=+1 color="#FF0000">' + sTitle + '</font>');
1270                                 SaveList.Add('<dl>');
1271                                 doc.Write(SaveList.Text);
1272                                 SaveList.Clear;
1273                                 //Application.ProcessMessages;
1274                                 for i := 0 to ReadList.Count - 1 do begin
1275                                         if (OnlyAHundredRes = true) and ( i <> 0 ) and ( (ReadList.Count-i) > 101 ) then begin
1276                                                 Continue;
1277                                         end;
1278                                         if (Trim(ReadList[i]) <> '') then begin
1279                                                 No := IntToStr(i + 1);
1280
1281                                                 if (NewReceiveNo = (i + 1)) or ((NewReceiveNo = 0) and (i = 0)) then begin
1282                                                         SaveList.Add('</dl>');
1283                                                                                                                 SaveList.Add('<a name="new"></a>');
1284                                                                                                                 SaveList.Add('<table width="100%" bgcolor="#3333CC" cellpadding="0" cellspacing="1"><tr><td align="center" bgcolor="#6666FF" valign="middle"><font size="-1" color="#ffffff"><b>\90V\92\85\83\8c\83X ' + FormatDateTime('yyyy/mm/dd(ddd) hh:mm', ThreadItem.RoundDate) + '</b></font></td></tr></table>');
1285                                                                                                                 SaveList.Add('<dl>');
1286                                                 end;
1287                                                 Res := DivideStrLine(ReadList[i]);
1288                                                 Res.FBody := ConvRes(Res.FBody, ThreadItem.ParentBoard.BBSID, ChangeFileExt(ThreadItem.FileName, ''), 'bbs', 'key', 'st', 'to', 'nofirst', 'true');
1289                                                 if Res.FType = glt2chOld then begin
1290                                                         Res.FMailTo := StringReplace(Res.FMailTo, '\81\97\81M', ',', [rfReplaceAll]);
1291                                                         Res.FName := StringReplace(Res.FName, '\81\97\81M', ',', [rfReplaceAll]);
1292                                                         Res.FBody := StringReplace(Res.FBody, '\81\97\81M', ',', [rfReplaceAll]);
1293                                                 end;
1294                                                 Res.FBody := AddAnchorTag(Res.FBody);
1295                                                 if Res.FMailTo = '' then
1296                                                         SaveList.Add('<a name="' + No + '"></a><dt><a href="menu:' + No + '">' + No + '</a> \96¼\91O\81F<font color="forestgreen"><b> ' + Res.FName + ' </b></font> \93\8a\8de\93ú\81F ' + Res.FDateTime+ '<br><dd>' + Res.Fbody + ' <br><br><br>')
1297                                                 else if GikoSys.Setting.ShowMail then
1298                                                         SaveList.Add('<a name="' + No + '"></a><dt><a href="menu:' + No + '">' + No + '</a> \96¼\91O\81F<a href="mailto:' + Res.FMailTo + '"><b> ' + Res.FName + ' </B></a> [' + Res.FMailTo + '] \93\8a\8de\93ú\81F ' + Res.FDateTime+ '<br><dd>' + Res.Fbody + ' <br><br><br>')
1299                                                 else
1300                                                         SaveList.Add('<a name="' + No + '"></a><dt><a href="menu:' + No + '">' + No + '</a> \96¼\91O\81F<a href="mailto:' + Res.FMailTo + '"><b> ' + Res.FName + ' </B></a> \93\8a\8de\93ú\81F ' + Res.FDateTime+ '<br><dd>' + Res.Fbody + ' <br><br><br>');
1301                                                 if ThreadItem.Kokomade = (i + 1) then begin
1302                                                         SaveList.Add('</dl>');
1303                                                         SaveList.Add('<a name="koko"></a><table width="100%" bgcolor="#55AA55" cellpadding="0" cellspacing="1"><tr><td align="center" bgcolor="#77CC77" valign="middle"><font size="-1" color="#ffffff"><b>\83R\83R\82Ü\82Å\93Ç\82ñ\82¾</b></font></td></tr></table>');
1304                                                         SaveList.Add('<dl>');
1305                                                 end;
1306                                         end;
1307                                         //if SaveList.Count > 50 then begin
1308                                                 doc.Write(SaveList.Text);
1309                                                 SaveList.Clear;
1310                                                 //Application.ProcessMessages;
1311                                         //end;
1312                                 end;
1313                                 SaveList.Add('</dl>');
1314                                 SaveList.Add('<a name="bottom"></a>');
1315                                 SaveList.Add('</body></html>');
1316                                 doc.Write(SaveList.Text);
1317                         end;
1318                 finally
1319                         SaveList.Free;
1320                         doc.Close;
1321                 end;
1322         finally
1323                 ReadList.Free;
1324         end;
1325 end;
1326 (*************************************************************************
1327  *http://\82Ì\95\8e\9a\97ñ\82ðanchor\83^\83O\95t\82«\82É\82·\82é\81B
1328  *************************************************************************)
1329 function TGikoSys.AddAnchorTag(s: string): string;
1330 const
1331         URL_CHAR: string = '0123456789'
1332                                                                          + 'abcdefghijklmnopqrstuvwxyz'
1333                                                                          + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
1334                                                                          + '#$%&()*+,-./:;=?@[]^_`{|}~!''\';
1335 var
1336         wkIdx: array[0..9] of Integer;
1337         url: string;
1338         href: string;
1339         i: Integer;
1340         idx: Integer;
1341 begin
1342         Result := '';
1343
1344         while True do begin
1345                 wkIdx[0] := AnsiPos('http://', s);
1346                 wkIdx[1] := AnsiPos('ttp://', s);
1347                 wkIdx[2] := AnsiPos('tp://', s);
1348                 wkIdx[3] := AnsiPos('ms-help://', s);
1349                 wkIdx[4] := AnsiPos('p://', s);
1350                 wkIdx[5] := AnsiPos('https://', s);
1351                 wkIdx[6] := AnsiPos('www.', s);
1352                 wkIdx[7] := AnsiPos('ftp://', s);
1353                 wkIdx[8] := AnsiPos('news://', s);
1354                 wkIdx[9] := AnsiPos('rtsp://', s);
1355
1356                 idx := MaxInt;
1357                 for i := 0 to 8 do
1358                         if wkIdx[i] <> 0 then idx := Min(wkIdx[i], idx);
1359
1360                 if idx = MaxInt then begin
1361                         //\83\8a\83\93\83N\82ª\96³\82¢\82æ\81B
1362                         Result := Result + s;
1363                         Break;
1364                 end;
1365
1366                 if (idx > 1) and (Copy(s, idx - 1, 1) = '"') then begin
1367                         //\8aù\82É\83\8a\83\93\83N\83^\83O\82ª\82Â\82¢\82Ä\82¢\82é\82Á\82Û\82¢\82Æ\82«\82Í\83\80\83V
1368                         Result := Result + Copy(s, 0, idx + Length('http://') - 1);
1369                         s := Copy(s, idx + Length('http://'), length(s));
1370                         Continue;
1371                 end;
1372
1373                 Result := Result + Copy(s, 0, idx - 1);
1374
1375                 s := Copy(s, idx, length(s));
1376
1377                 for i := 0 to Length(s) do begin
1378                         idx := AnsiPos(s[i + 1], URL_CHAR);
1379                         if (idx = 0) or (i = (Length(s))) then begin
1380                                 //URL\82\82á\82È\82¢\95\8e\9a\94­\8c©\81I\82Æ\82©\81A\95\8e\9a\82ª\82È\82­\82È\82Á\82½\81B
1381                                 url := Copy(s, 0, i);
1382
1383                                 if AnsiPos('ttp://', url) = 1 then
1384                                         href := 'h' + url
1385                                 else if AnsiPos('tp://', url) = 1 then
1386                                         href := 'ht' + url
1387                                 else if AnsiPos('p://', url) = 1 then
1388                                         href := 'htt' + url
1389                                 else if AnsiPos('www.', url) = 1 then
1390                                         href := 'http://' + url
1391                                 else
1392                                         href := url;
1393                                 Result := Result + '<a href="' + href + '" target="_blank">' + url + '</a>';
1394                                 s := Copy(s, i + 1, Length(s));
1395                                 Break;
1396                         end;
1397                 end;
1398         end;
1399 end;
1400
1401 (*************************************************************************
1402  *\83T\83u\83W\83F\83N\83g\88ê\8ds\82ð\95ª\8a\84
1403  *************************************************************************)
1404 function TGikoSys.DivideSubject(Line: string): TSubjectRec;
1405 var
1406         i: integer;
1407         ws: WideString;
1408         Delim: string;
1409         LeftK: string;
1410         RightK: string;
1411 begin
1412         Result.FCount := 0;
1413
1414         if Pos('<>', Line) = 0 then
1415                 Delim := ','
1416         else
1417                 Delim := '<>';
1418
1419         Result.FFileName := GetTokenIndex(Line, Delim, 0);
1420         Result.FTitle := GetTokenIndex(Line, Delim, 1);
1421
1422         ws := Trim(Result.FTitle);
1423
1424         if Copy(ws, Length(ws), 1) = ')' then begin
1425                 LeftK := '(';
1426                 RightK := ')';
1427         end else if Copy(ws, Length(ws), 1) = '\81j' then begin
1428                 LeftK := '\81i';
1429                 RightK := '\81j';
1430         end else if Copy(ws, Length(ws), 1) = '<' then begin
1431                 LeftK := '<';
1432                 RightK := '>';
1433         end;
1434
1435         for i := Length(ws) - 1 downto 1 do begin
1436                 if ws[i] = LeftK then begin
1437                         ws := Copy(ws, i + 1, Length(ws) - i - 1);
1438                         if IsNumeric(ws) then
1439                                 Result.FCount := StrToInt(ws);
1440                         Result.FTitle := Trim(StringReplace(Result.FTitle, LeftK + ws + RightK, '', [rfReplaceAll]));
1441                         break;
1442                 end;
1443         end;
1444 end;
1445
1446 (*************************************************************************
1447  * dat\83t\83@\83C\83\8b\82Ì\88ê\83\89\83C\83\93\82ð\95ª\89ð
1448  *************************************************************************)
1449 function TGikoSys.DivideStrLine(Line: string): TResRec;
1450 var
1451         Delim: string;
1452                 bufbody : String;
1453 begin
1454         if Pos('<>', Line) = 0 then begin
1455                 Delim := ',';
1456                 Result.FType := glt2chOld;
1457         end else begin
1458                 Delim := '<>';
1459                 Result.FType := glt2chNew;
1460         end;
1461         Result.FName := Trim(GetTokenIndex(Line, Delim, 0));
1462         Result.FMailTo := Trim(GetTokenIndex(Line, Delim, 1));
1463         Result.FDateTime := Trim(GetTokenIndex(Line, Delim, 2));
1464         bufBody := Trim(GetTokenIndex(Line, Delim, 3));
1465         if bufbody = '' then begin
1466                 Insert('&nbsp;',bufbody, 1);
1467         end;
1468         Result.FBody := bufBody;
1469         Result.FTitle := Trim(GetTokenIndex(Line, Delim, 4));
1470
1471 end;
1472
1473 (*************************************************************************
1474  * URL\82©\82çBBSID\82ð\8eæ\93¾
1475  *************************************************************************)
1476 function TGikoSys.UrlToID(url: string): string;
1477 var
1478         i: integer;
1479 begin
1480         Result := '';
1481         url := Trim(url);
1482
1483         if url = '' then Exit;
1484
1485         url := Copy(url, 0, Length(url) - 1);
1486         for i := Length(url) downto 0 do begin
1487                 if url[i] = '/' then begin
1488                         Result := Copy(url, i + 1, Length(url));
1489                         Break;
1490                 end;
1491         end;
1492 end;
1493
1494 (*************************************************************************
1495  *URL\82©\82çBBSID\88È\8aO\82Ì\95\94\95ª(http://teri.2ch.net/)\82ð\8eæ\93¾
1496  *************************************************************************)
1497 function TGikoSys.UrlToServer(url: string): string;
1498 var
1499         i: integer;
1500         wsURL: WideString;
1501 begin
1502         Result := '';
1503         wsURL := url;
1504         wsURL := Trim(wsURL);
1505
1506         if wsURL = '' then exit;
1507
1508         if Copy(wsURL, Length(wsURL), 1) = '/' then
1509                 wsURL := Copy(wsURL, 0, Length(wsURL) - 1);
1510
1511         for i := Length(wsURL) downto 0 do begin
1512                 if wsURL[i] = '/' then begin
1513                         Result := Copy(wsURL, 0, i);
1514                         break;
1515                 end;
1516         end;
1517 end;
1518
1519 (*************************************************************************
1520  *\83f\83B\83\8c\83N\83g\83\8a\82ª\91\8dÝ\82·\82é\82©\83`\83F\83b\83N
1521  *************************************************************************)
1522 function TGikoSys.DirectoryExistsEx(const Name: string): Boolean;
1523 var
1524         Code: Integer;
1525 begin
1526         Code := GetFileAttributes(PChar(Name));
1527         Result := (Code <> -1) and (FILE_ATTRIBUTE_DIRECTORY and Code <> 0);
1528 end;
1529
1530 (*************************************************************************
1531  *\83f\83B\83\8c\83N\83g\83\8a\8dì\90¬\81i\95¡\90\94\8aK\91w\91Î\89\9e\81j
1532  *************************************************************************)
1533 function TGikoSys.ForceDirectoriesEx(Dir: string): Boolean;
1534 begin
1535         Result := True;
1536         if Length(Dir) = 0 then
1537                 raise Exception.Create('\83t\83H\83\8b\83_\82ª\8dì\90¬\8fo\97\88\82Ü\82¹\82ñ');
1538         Dir := ExcludeTrailingPathDelimiter(Dir);
1539         if (Length(Dir) < 3) or DirectoryExistsEx(Dir)
1540                 or (ExtractFilePath(Dir) = Dir) then Exit; // avoid 'xyz:\' problem.
1541         Result := ForceDirectoriesEx(ExtractFilePath(Dir)) and CreateDir(Dir);
1542 end;
1543
1544 (*************************************************************************
1545  *\95\8e\9a\97ñ\82©\82ç\83g\81[\83N\83\93\82Ì\90Ø\82è\8fo\82µ\81i\8f\89\8aú\8f\88\97\9d\81j
1546  *FDelphi\82©\82ç\82Ì\83p\83N\83\8a
1547  *************************************************************************)
1548 function TGikoSys.StrTokFirst(const s:string; const sep: TStrTokSeparator; var Rec: TStrTokRec): string;
1549 begin
1550         Rec.Str := s;
1551         Rec.Pos := 1;
1552         Result := StrTokNext(sep, Rec);
1553 end;
1554
1555 (*************************************************************************
1556  *\95\8e\9a\97ñ\82©\82ç\83g\81[\83N\83\93\82Ì\90Ø\82è\8fo\82µ
1557  *FDelphi\82©\82ç\82Ì\83p\83N\83\8a
1558  *************************************************************************)
1559 function TGikoSys.StrTokNext(const sep: TStrTokSeparator; var Rec: TStrTokRec): string;
1560 var
1561         Len, I: Integer;
1562 begin
1563         with Rec do     begin
1564                 Len := Length(Str);
1565                 Result := '';
1566                 if Len >= Pos then begin
1567                         while (Pos <= Len) and (Str[Pos] in sep) do begin
1568                          Inc(Pos);
1569                         end;
1570                         I := Pos;
1571                         while (Pos<= Len) and not (Str[Pos] in sep) do begin
1572                                 if IsDBCSLeadByte(Byte(Str[Pos])) then begin
1573                                         Inc(Pos);
1574                                 end;
1575                                 Inc(Pos);
1576                         end;
1577                         Result := Copy(Str, I, Pos - I);
1578                         while (Pos <= Len) and (Str[Pos] in sep) do begin// \82±\82ê\82Í\82¨\8dD\82Ý
1579                                 Inc(Pos);
1580                         end;
1581                 end;
1582         end;
1583 end;
1584
1585 (*************************************************************************
1586  *\83t\83@\83C\83\8b\83T\83C\83Y\8eæ\93¾
1587  *************************************************************************)
1588 function TGikoSys.GetFileSize(FileName : string): longint;
1589 var
1590         F : File;
1591 begin
1592         try
1593                 if not FileExists(FileName) then begin
1594                         Result := 0;
1595                         Exit;
1596                 end;
1597                 Assign(F, FileName);
1598                 Reset(F, 1);
1599                 Result := FileSize(F);
1600                 CloseFile(F);
1601         except
1602                 Result := 0;
1603         end;
1604 end;
1605
1606 (*************************************************************************
1607  *\83t\83@\83C\83\8b\8ds\90\94\8eæ\93¾
1608  *************************************************************************)
1609 function TGikoSys.GetFileLineCount(FileName : string): longint;
1610 var
1611         sl: TStringList;
1612 begin
1613         sl := TStringList.Create;
1614         try
1615                 try
1616                         sl.LoadFromFile(FileName);
1617                         Result := sl.Count;
1618                 except
1619                         Result := 0;
1620                 end;
1621         finally
1622                 sl.Free;
1623         end;
1624
1625 end;
1626
1627 (*************************************************************************
1628  *\83X\83\8c\83b\83h\83t\83@\83C\83\8b\82©\82ç\8ew\92è\8ds\82ð\8eæ\93¾
1629  *************************************************************************)
1630 function TGikoSys.ReadThreadFile(FileName: string; Line: Integer): string;
1631 const
1632         BUFFER_SIZE = 1024;
1633 var
1634         f: TextFile;
1635         s: string;
1636         num: Integer;
1637         ArrBuff: array [1..BUFFER_SIZE] of Char;
1638 begin
1639         Result := '';
1640         if FileExists(FileName) then begin
1641                 AssignFile(f, FileName);
1642                 System.SetTextBuf(f, ArrBuff);
1643                 try
1644                         Reset(f);
1645                         num := 1;
1646                         while not Eof(f) do begin
1647                                 Readln(f, s);
1648                                 if Line = num then begin
1649                                         Result := s;
1650 //                                      CloseFile(f);
1651                                         Break;
1652                                 end;
1653                                 inc(num);
1654                         end;
1655                 finally
1656                         CloseFile(f);
1657                 end;
1658         end;
1659 end;
1660
1661 (*************************************************************************
1662  *\83V\83X\83e\83\80\83\81\83j\83\85\81[\83t\83H\83\93\83g\82Ì\91®\90«\82ð\8eæ\93¾
1663  *************************************************************************)
1664 procedure TGikoSys.MenuFont(Font: TFont);
1665 var
1666         lf: LOGFONT;
1667         nm: NONCLIENTMETRICS;
1668 begin
1669         nm.cbSize := sizeof(NONCLIENTMETRICS);
1670
1671         SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, @nm, 0);
1672         lf := nm.lfMenuFont;
1673
1674         Font.Name := lf.lfFaceName;
1675         Font.Height := lf.lfHeight;
1676         Font.Style := [];
1677         if lf.lfWeight >= 700 then
1678                 Font.Style := Font.Style + [fsBold];
1679         if lf.lfItalic = 1 then
1680                 Font.Style := Font.Style + [fsItalic];
1681 end;
1682
1683 (*************************************************************************
1684  *
1685  *\82Ç\82±\82©\82Ì\83T\83C\83g\82©\82ç\82Ì\83p\83N\83\8a
1686  *************************************************************************)
1687 function TGikoSys.RemoveToken(var s: string; delimiter: string): string;
1688 var
1689         p: Integer;
1690 begin
1691         p := AnsiPos(delimiter, s);
1692         if p = 0 then
1693                 Result := s
1694         else
1695                 Result := Copy(s, 1, p - 1);
1696         s := Copy(s, Length(Result) + Length(delimiter) + 1, Length(s));
1697 end;
1698
1699 (*************************************************************************
1700  *
1701  *\82Ç\82±\82©\82Ì\83T\83C\83g\82©\82ç\82Ì\83p\83N\83\8a
1702  *************************************************************************)
1703 function TGikoSys.GetTokenIndex(s: string; delimiter: string; index: Integer): string;
1704 var
1705         i: Integer;
1706 begin
1707         Result := '';
1708         for i := 0 to index do
1709                 Result := RemoveToken(s, delimiter);
1710 end;
1711
1712 (*************************************************************************
1713  *
1714  *************************************************************************)
1715 function TGikoSys.DeleteLink(const s: string): string;
1716 var
1717         s1: string;
1718         s2: string;
1719         idx: Integer;
1720         i: Integer;
1721 begin
1722         i := 0;
1723         Result := '';
1724         while True do begin
1725                 s1 := GetTokenIndex(s, '<a href="', i);
1726                 s2 := GetTokenIndex(s, '<a href="', i + 1);
1727
1728                 idx := Pos('">', s1);
1729                 if idx <> 0 then
1730                         Delete(s1, 1, idx + 1);
1731                 idx := Pos('">', s2);
1732                 if idx <> 0 then
1733                         Delete(s2, 1, idx + 1);
1734
1735                 Result := Result + s1 + s2;
1736
1737                 if s2 = '' then
1738                         Break;
1739
1740                 inc(i, 2);
1741         end;
1742 end;
1743
1744 //\83C\83\93\83f\83b\83N\83X\96¢\8dX\90V\83o\83b\83t\83@\82ð\83t\83\89\83b\83V\83\85\81I
1745 {procedure TGikoSys.FlashExitWrite;
1746 var
1747         i: Integer;
1748 begin
1749         //\83X\83\8c\83b\83h\83f\81[\83^\83t\83@\83C\83\8b\82ð\8dX\90V
1750         for i := 0 to FExitWrite.Count - 1 do
1751                 WriteThreadDat(FExitWrite[i]);
1752         FExitWrite.Clear;
1753 end;}
1754
1755 (*************************************************************************
1756  *\83X\83\8c\96¼\82È\82Ç\82ð\92Z\82¢\96¼\91O\82É\95Ï\8a·\82·\82é
1757  *from HotZonu
1758  *************************************************************************)
1759 function TGikoSys.GetShortName(const LongName: string; ALength: integer): string;
1760 const
1761         ERASECHAR : array [1..39] of string =
1762                 ('\81\99','\81\9a','\81¡','\81 ','\81\9f','\81\9e','\81Q','\81\94','\81£','\81¥',
1763                  '\81¢','\81¤','\81\9c','\81\9b','\81\9d','\81y','\81z','\81ô','\81s','\81t',
1764                  '\81g','\81h','\81k','\81l','\81e','\81f','\81\83','\81\84','\81á','\81â',
1765                  '\81o','\81p','\81q','\81r','\81w','\81x','\81¬','\81c', '\81@');
1766 var
1767         Chr : array [0..255]    of      char;
1768         S : string;
1769         i : integer;
1770 begin
1771         s := Trim(LongName);
1772         if (Length(s) <= ALength) then begin
1773                 Result := s;
1774         end else begin
1775                 S := s;
1776                 for i := Low(ERASECHAR) to      High(ERASECHAR) do      begin
1777                         S := StringReplace(S, ERASECHAR[i], '', [rfReplaceAll]);
1778                 end;
1779                 if (Length(S) <= ALength) then begin
1780                         Result := S;
1781                 end else begin
1782                         Windows.LCMapString(
1783                                         GetUserDefaultLCID(),
1784                                         LCMAP_HALFWIDTH,
1785                                         PChar(S),
1786                                         Length(S) + 1,
1787                                         chr,
1788                                         Sizeof(chr)
1789                                         );
1790                         S := Chr;
1791                         S := Copy(S,1,ALength);
1792                         while true do begin
1793                                 if (ByteType(S, Length(S)) = mbLeadByte ) then begin
1794                                         S := Copy(S, 1, Length(S) - 1);
1795                                 end else begin
1796                                         Break;
1797                                 end;
1798                         end;
1799                         Result := S;
1800                 end;
1801         end;
1802 end;
1803
1804 (*************************************************************************
1805  *
1806  * from HotZonu
1807  *************************************************************************)
1808 function TGikoSys.ConvRes(const Body, Bbs, Key,
1809         ParamBBS, ParamKey, ParamStart, ParamTo, ParamNoFirst, ParamTrue : string): string;
1810 type
1811         PIndex = ^TIndex;
1812         TIndex = record
1813                 FIndexFrom      : integer;
1814                 FIndexTo                : integer;
1815                 FNo                              : string;
1816         end;
1817 const
1818         GT      = '&gt;';
1819         SN      = '0123456789-';
1820         ZN      = '\82O\82P\82Q\82R\82S\82T\82U\82V\82W\82X\81|';
1821 var
1822         i : integer;
1823         s,r : string;
1824         b : TMbcsByteType;
1825         sw: boolean;
1826         sp: integer;
1827         No: string;
1828         sx: string;
1829         List: TList;
1830         oc      : string;
1831         st, et: string;
1832         chk : boolean;
1833         al : boolean;
1834         procedure Add(IndexFrom, IndexTo: integer; const No: string);
1835         var
1836                 FIndex : PIndex;
1837         begin
1838                 New(FIndex);
1839                 FIndex.FIndexFrom       := IndexFrom;
1840                 FIndex.FIndexTo         := IndexTo;
1841                 FIndex.FNo                               := No;
1842                 List.Add(FIndex);
1843         end;
1844         function ChooseString(const Text, Separator: string; Index: integer): string;
1845         var
1846                 S : string;
1847                 i, p : integer;
1848         begin
1849                 S :=    Text;
1850                 for i :=        0 to    Index - 1 do    begin
1851                         if      (AnsiPos(Separator, S) = 0) then        S :=    ''
1852                         else    S :=    Copy(S, AnsiPos(Separator, S) + Length(Separator), Length(S));
1853                 end;
1854                 p :=    AnsiPos(Separator, S);
1855                 if      (p > 0) then    Result  :=      Copy(S, 1, p - 1) else Result :=        S;
1856         end;
1857 begin
1858         { v1.0 b2 - 03 }
1859         s        :=     Body;
1860         r        :=     Body;
1861         i        :=     1;
1862         sw      :=      False;
1863         No      :=      '';
1864         List:=  TList.Create;
1865         oc      :=      '';
1866         sp      :=      0;
1867         chk :=  False;
1868         al      :=      False;
1869         while true      do      begin
1870                 b :=    ByteType(s, i);
1871                 case    b of
1872                         mbSingleByte    : begin
1873                                 if      (not sw) and (Copy(s,i,8) = GT + GT) then       begin
1874                                         if      (AnsiPos('<A HREF', AnsiUpperCase(oc)) = 0) then        begin
1875                                                 sw      :=      True;
1876                                                 sp      :=      i;
1877                                                 i :=    i + 7;
1878                                                 oc:='';
1879                                                 chk :=  True;
1880                                         end;
1881                                 end else
1882                                 if      (not sw) and (Copy(s,i,8) = GT + GT) then       begin
1883                                         if      (AnsiPos('<A HREF', AnsiUpperCase(oc)) = 1) then        begin
1884                                                 i :=    i + 7;
1885                                                 oc:='';
1886                                                 chk :=  True;
1887                                         end;
1888                                 end else
1889                                 if      (not sw) and (Copy(s,i,4) = GT) then    begin
1890                                         if      (AnsiPos('<A HREF', AnsiUpperCase(oc)) = 0) then        begin
1891                                                 sw      :=      True;
1892                                                 sp      :=      i;
1893                                                 i :=    i + 3;
1894                                                 oc:='';
1895                                                 chk :=  True;
1896                                         end;
1897                                 end else
1898                                 if      ((not sw) and (Copy(s,i,1) = ',')) or
1899                                                 ((not sw) and (Copy(s,i,1) = '=')) then begin
1900                                         if      ((not Chk) and (AnsiLowerCase(oc) = '</a>')) or
1901                                                         ((Chk) and      (oc = '')) or
1902                                                         ((not Chk) and (al)) then
1903                                         begin
1904                                                 sw      :=      True;
1905                                                 sp      :=      i;
1906                                                 //i :=  i + 1;
1907                                                 oc:='';
1908                                         end;
1909                                 end else
1910                                 if      (sw) then begin
1911                                         sx      :=      Copy(s,i,1);
1912                                         if      (AnsiPos(sx, SN) > 0)   then    begin
1913                                                 No      :=      No      + sx;
1914                                         end else begin
1915                                                 if      (No <> '') and (No <> '-')       then   begin
1916                                                         Add(sp, i, No);
1917                                                         al := True;
1918                                                 end;
1919                                                 sw      :=      False;
1920                                                 //
1921                                                 i := i - 1;
1922                                                 //
1923                                                 No      := '';
1924                                                 oc:='';
1925                                                 //chk :=        False;
1926                                         end;
1927                                 end else begin
1928                                         if      Copy(s,i,1) = '<' then  oc      :=      '';
1929                                         oc      :=      oc + Copy(s,i,1);
1930                                         chk :=  False;
1931                                         al      :=      False;
1932                                 end;
1933                         end;
1934                         mbLeadByte      : begin
1935                                 if      (not sw) and (Copy(s,i,4) = '\81\84\81\84') then        begin
1936                                         sw      :=      True;
1937                                         sp      :=      i;
1938                                         i :=    i + 3;
1939                                         chk :=  True;
1940                                 end else
1941                                 if      (not sw) and (Copy(s,i,2) = '\81\84') then  begin
1942                                         sw      :=      True;
1943                                         sp      :=      i;
1944                                         i :=    i + 1;
1945                                         chk :=  True;
1946                                 end else
1947                                 if      (sw) then begin
1948                                         sx      :=      Copy(s,i,2);
1949                                         if      (AnsiPos(sx, ZN) > 0)   then    begin
1950                                                 No      :=      No      + ZenToHan(sx);
1951                                         end else begin
1952                                                 if      (No <> '') and (No <> '-')      and (No <> '\81|') then   begin
1953                                                         Add(sp, i, No);
1954                                                 end;
1955                                                 sw      :=      False;
1956                                                 i := i - 1;
1957                                                 No      :=      '';
1958                                         end;
1959                                 end else begin
1960                                         oc      :=      '';
1961                                         chk :=  False;
1962                                 end;
1963                                 al      :=      False;
1964                         end;
1965                 end;
1966                 inc(i);
1967                 if      (i > Length(Body))      then    begin
1968                         if      (sw)    then    begin
1969                                 if      (No <> '')      then    Add(sp, i, No);
1970                         end;
1971                         Break;
1972                 end;
1973         end;
1974         for i :=        List.Count - 1  downto  0 do    begin
1975                 if      (AnsiPos('-', PIndex(List[i]).FNo) > 0) then    begin
1976                         st      :=      ChooseString(PIndex(List[i]).FNo, '-', 0);
1977                         et      :=      ChooseString(PIndex(List[i]).FNo, '-', 1);
1978                 end else begin
1979                         st      :=      PIndex(List[i]).FNo;
1980                         et      :=      PIndex(List[i]).FNo;
1981                 end;
1982                 r :=    Copy(r,0, PIndex(List[i]).FIndexFrom - 1) +
1983                                         Format('<a href="../test/read.cgi?%s=%s&%s=%s&%s=%s&%s=%s&%s=%s" target="_blank">',
1984                                                                 [ParamBBS, Bbs, ParamKey, Key, ParamStart, st, ParamTo, et, ParamNoFirst, ParamTrue]) +
1985                                         Copy(r,PIndex(List[i]).FIndexFrom, PIndex(List[i]).FIndexTo - PIndex(List[i]).FIndexFrom) + '</A>' +
1986                                         Copy(r,PIndex(List[i]).FIndexTo,Length(r));
1987                 Dispose(PIndex(List[i]));
1988         end;
1989         List.Free;
1990         Result  :=      r;
1991 end;
1992
1993 (*************************************************************************
1994  * \91S\8ap\81¨\94¼\8ap
1995  * from HotZonu
1996  *************************************************************************)
1997 function TGikoSys.ZenToHan(const s: string): string;
1998 var
1999         Chr: array [0..255] of char;
2000 begin
2001         Windows.LCMapString(
2002                  GetUserDefaultLCID(),
2003 //               LCMAP_HALFWIDTH,
2004                  LCMAP_HALFWIDTH or LCMAP_KATAKANA or LCMAP_LOWERCASE,
2005                  PChar(s),
2006                  Length(s) + 1,
2007                  chr,
2008                  Sizeof(chr)
2009                  );
2010         Result := Chr;
2011 end;
2012
2013 (*************************************************************************
2014  * \91S\8ap\94¼\8ap\82Ð\82ç\82ª\82È\82©\82½\82©\82È\82ð\8bæ\95Ê\82µ\82È\82¢\90¦\82¢Pos
2015  *************************************************************************)
2016 function TGikoSys.VaguePos(const Substr, S: string): Integer;
2017 begin
2018         Result := Pos(ZenToHan(Substr), ZenToHan(S));
2019 end;
2020
2021 function TGikoSys.BoolToInt(b: Boolean): Integer;
2022 begin
2023         Result := IfThen(b, 1, 0);
2024 end;
2025
2026 function TGikoSys.IntToBool(i: Integer): Boolean;
2027 begin
2028         Result := i = 1;
2029 end;
2030
2031 //gzip\82Å\88³\8fk\82³\82ê\82½\82Ì\82ð\96ß\82·
2032 function TGikoSys.GzipDecompress(ResStream: TStream; ContentEncoding: string): string;
2033 const
2034         BUF_SIZE = 4096;
2035 var
2036         GZipStream: TGzipDecompressStream;
2037         TextStream: TStringStream;
2038         buf: array[0..BUF_SIZE - 1] of Byte;
2039         cnt: Integer;
2040         s: string;
2041         i: Integer;
2042 begin
2043         Result := '';
2044         TextStream := TStringStream.Create('');
2045         try
2046 //\83m\81[\83g\83\93\83E\83\93\83`\83E\83B\83\8b\83X2003\91Î\8dô(x-gzip\82Æ\82©\82É\82È\82é\82Ý\82½\82¢)
2047 //              if LowerCase(Trim(ContentEncoding)) = 'gzip' then begin
2048                 if AnsiPos('gzip', LowerCase(Trim(ContentEncoding))) > 0 then begin
2049                         ResStream.Position := 0;
2050                         GZipStream := TGzipDecompressStream.Create(TextStream);
2051                         try
2052                                 repeat
2053                                         FillChar(buf, BUF_SIZE, 0);
2054                                         cnt := ResStream.Read(buf, BUF_SIZE);
2055                                         if cnt > 0 then
2056                                                 GZipStream.Write(buf, BUF_SIZE);
2057                                 until cnt = 0;
2058                         finally
2059                                 GZipStream.Free;
2060                         end;
2061                 end else begin
2062                         ResStream.Position := 0;
2063                         repeat
2064                                 FillChar(buf, BUF_SIZE, 0);
2065                                 cnt := ResStream.Read(buf, BUF_SIZE);
2066                                 if cnt > 0 then
2067                                         TextStream.Write(buf, BUF_SIZE);
2068                         until cnt = 0;
2069                 end;
2070
2071                 //NULL\95\8e\9a\82ð"*"\82É\82·\82é
2072                 s := TextStream.DataString;
2073                 i := Length(s);
2074                 while (i > 0) and (s[i] = #0) do
2075                         Dec(i);
2076                 s := Copy(s, 1, i);
2077
2078                 i := Pos(#0, s);
2079                 while i <> 0 do begin
2080                         s[i] := '*';
2081                         i := Pos(#0, s);
2082                 end;
2083                 Result := s;
2084         finally
2085                 TextStream.Free;
2086         end;
2087 end;
2088
2089 procedure TGikoSys.LoadKeySetting(ActionList: TActionList);
2090 const
2091         STD_SEC = 'KeySetting';
2092 var
2093         i: Integer;
2094         ini: TMemIniFile;
2095         ActionName: string;
2096         ActionKey: Integer;
2097         SecList: TStringList;
2098         Component: TComponent;
2099 begin
2100         if not FileExists(GetConfigDir + KEY_SETTING_FILE_NAME) then
2101                 Exit;
2102         SecList := TStringList.Create;
2103         ini := TMemIniFile.Create(GetConfigDir + KEY_SETTING_FILE_NAME);
2104         try
2105                 ini.ReadSection(STD_SEC, SecList);
2106                 for i := 0 to SecList.Count - 1 do begin
2107                         ActionName := SecList[i];
2108                         ActionKey := ini.ReadInteger(STD_SEC, ActionName, -1);
2109                         if ActionKey <> -1 then begin
2110                                 Component := ActionList.Owner.FindComponent(ActionName);
2111                                 if TObject(Component) is TAction then begin
2112                                         TAction(Component).ShortCut := ActionKey;
2113                                 end;
2114                         end;
2115                 end;
2116         finally
2117                 ini.Free;
2118                 SecList.Free;
2119         end;
2120 end;
2121
2122 procedure TGikoSys.SaveKeySetting(ActionList: TActionList);
2123 const
2124         STD_SEC = 'KeySetting';
2125 var
2126         i: Integer;
2127         ini: TMemIniFile;
2128 begin
2129         ini := TMemIniFile.Create(GetConfigDir + KEY_SETTING_FILE_NAME);
2130         try
2131                 for i := 0 to ActionList.ActionCount - 1 do begin
2132                         if ActionList.Actions[i].Tag = -1 then
2133                                 Continue;
2134                         ini.WriteInteger(STD_SEC, ActionList.Actions[i].Name, TAction(ActionList.Actions[i]).ShortCut);
2135                 end;
2136                 ini.UpdateFile;
2137         finally
2138                 ini.Free;
2139         end;
2140 end;
2141
2142 //
2143 procedure TGikoSys.CreateProcess(const AppPath: string; const Param: string);
2144 var
2145         PI: TProcessInformation;
2146         SI: TStartupInfo;
2147         Path: string;
2148 begin
2149         Path := '"' + AppPath + '"';
2150         if Param <> '' then
2151                 Path := Path + ' ' + Param;
2152
2153         SI.Cb := SizeOf(Si);
2154         SI.lpReserved   := nil;
2155         SI.lpDesktop     := nil;
2156         SI.lpTitle               := nil;
2157         SI.dwFlags               := 0;
2158         SI.cbReserved2 := 0;
2159         SI.lpReserved2 := nil;
2160         SI.dwysize               := 0;
2161         Windows.CreateProcess(nil,
2162                                                                 PChar(Path),
2163                                                                 nil,
2164                                                                 nil,
2165                                                                 False,
2166                                                                 0,
2167                                                                 nil,
2168                                                                 nil,
2169                                                                 SI,
2170                                                                 PI);
2171 end;
2172
2173 procedure TGikoSys.OpenBrowser(URL: string; BrowserType: TGikoBrowserType);
2174 begin
2175         case BrowserType of
2176                 gbtIE:
2177                         HlinkNavigateString(nil, PWideChar(WideString(URL)));
2178                 gbtUserApp, gbtAuto:
2179                         if (Setting.URLApp) and (FileExists(Setting.URLAppFile)) then
2180                                 GikoSys.CreateProcess(Setting.URLAppFile, URL)
2181                         else
2182                                 HlinkNavigateString(nil, PWideChar(WideString(URL)));
2183         end;
2184 end;
2185
2186 function TGikoSys.HTMLDecode(const AStr: String): String;
2187 var
2188         Sp, Rp, Cp, Tp: PChar;
2189         S: String;
2190         I, Code: Integer;
2191         Num: Boolean;
2192 begin
2193         SetLength(Result, Length(AStr));
2194         Sp := PChar(AStr);
2195         Rp := PChar(Result);
2196         //Cp := Sp;
2197         try
2198                 while Sp^ <> #0 do begin
2199                         case Sp^ of
2200                                 '&': begin
2201                                                          //Cp := Sp;
2202                                                          Inc(Sp);
2203                                                          case Sp^ of
2204                                                                  'a': if AnsiStrPos(Sp, 'amp;') = Sp then
2205                                                                                         begin
2206                                                                                                 Inc(Sp, 3);
2207                                                                                                 Rp^ := '&';
2208                                                                                         end;
2209                                                                  'l',
2210                                                                  'g': if (AnsiStrPos(Sp, 'lt;') = Sp) or (AnsiStrPos(Sp, 'gt;') = Sp) then
2211                                                                                         begin
2212                                                                                                 Cp := Sp;
2213                                                                                                 Inc(Sp, 2);
2214                                                                                                 while (Sp^ <> ';') and (Sp^ <> #0) do
2215                                                                                                         Inc(Sp);
2216                                                                                                 if Cp^ = 'l' then
2217                                                                                                         Rp^ := '<'
2218                                                                                                 else
2219                                                                                                         Rp^ := '>';
2220                                                                                         end;
2221                                                                  'q': if AnsiStrPos(Sp, 'quot;') = Sp then
2222                                                                                         begin
2223                                                                                                 Inc(Sp,4);
2224                                                                                                 Rp^ := '"';
2225                                                                                         end;
2226                                                                  '#': begin
2227                                                                                                 Tp := Sp;
2228                                                                                                 Inc(Tp);
2229                                                                                                 Num := IsNumeric(Copy(Tp, 1, 1));
2230                                                                                                 while (Sp^ <> ';') and (Sp^ <> #0) do begin
2231                                                                                                         if (Num) and (not IsNumeric(Copy(Sp, 1, 1))) then
2232                                                                                                                 Break;
2233                                                                                                         Inc(Sp);
2234                                                                                                 end;
2235                                                                                                 SetString(S, Tp, Sp - Tp);
2236                                                                                                 Val(S, I, Code);
2237                                                                                                 Rp^ := Chr((I));
2238                                                                                         end;
2239                                                          //      else
2240                                                                          //raise EConvertError.CreateFmt(sInvalidHTMLEncodedChar,
2241                                                                                  //[Cp^ + Sp^, Cp - PChar(AStr)])
2242                                                          end;
2243                                          end
2244                         else
2245                                 Rp^ := Sp^;
2246                         end;
2247                         Inc(Rp);
2248                         Inc(Sp);
2249                 end;
2250         except
2251 //              on E:EConvertError do
2252 //                      raise EConvertError.CreateFmt(sInvalidHTMLEncodedChar,
2253 //                              [Cp^ + Sp^, Cp - PChar(AStr)])
2254         end;
2255         SetLength(Result, Rp - PChar(Result));
2256 end;
2257
2258 function TGikoSys.GetHRefText(s: string): string;
2259 var
2260         Index: Integer;
2261         Index2: Integer;
2262 begin
2263         Result := '';
2264         s := Trim(s);
2265         if s = '' then
2266                 Exit;
2267
2268         Index := AnsiPos('href', LowerCase(s));
2269         if Index = 0 then
2270                 Exit;
2271         s := Trim(Copy(s, Index + 4, Length(s)));
2272         s := Trim(Copy(s, 2, Length(s)));
2273
2274         //\8en\82ß\82Ì\95\8e\9a\82ª'"'\82È\82ç\8eæ\82è\8f\9c\82­
2275         if Copy(s, 1, 1) = '"' then begin
2276                 s := Trim(Copy(s, 2, Length(s)));
2277         end;
2278
2279         Index := AnsiPos('"', s);
2280         if Index <> 0 then begin
2281                 //'"'\82Ü\82ÅURL\82Æ\82·\82é
2282                 s := Copy(s, 1, Index - 1);
2283         end else begin
2284                 //'"'\82ª\96³\82¯\82ê\82Î\83X\83y\81[\83X\82©">"\82Ì\91\81\82¢\95û\82Ü\82Å\82ðURL\82Æ\82·\82é
2285                 Index := AnsiPos(' ', s);
2286                 Index2 := AnsiPos('>', s);
2287                 if Index = 0 then
2288                         Index := Index2;
2289                 if Index > Index2 then
2290                         Index := Index2;
2291                 if Index <> 0 then
2292                         s := Copy(s, 1, Index - 1)
2293                 else
2294                         //\82±\82ê\88È\8fã\82à\82¤\92m\82ç\82ñ\82Ê
2295                         ;
2296         end;
2297         Result := Trim(s);
2298 end;
2299
2300 //\83z\83X\83g\96¼\82ª\82Q\82\83\82\88\82©\82Ç\82¤\82©\83`\83F\83b\83N\82·\82é
2301 function TGikoSys.Is2chHost(Host: string): Boolean;
2302 const
2303         HOST_NAME: array[0..1] of string = ('2ch.net', 'bbspink.com');
2304 var
2305         i: Integer;
2306 //      Len: Integer;
2307 begin
2308         Result := False;
2309         OutputDebugString(pchar(HOST_NAME[0]));
2310         for i := 0 to Length(HOST_NAME) - 1 do begin
2311 //              Len := Length(HOST_NAME[i]);
2312                 if AnsiPos(HOST_NAME[i], Host) = (Length(Host) - Length(HOST_NAME[i]) + 1) then begin
2313                         Result := True;
2314                         Exit;
2315                 end;
2316         end;
2317 end;
2318
2319 function TGikoSys.Parse2chURL(const url: string; const path: string; const document: string; var BBSID: string; var BBSKey: string): Boolean;
2320 const
2321         READ_PATH: string =                     '/test/read.cgi/';
2322         OLD_READ_PATH: string =         '/test/read.cgi?';
2323         KAKO_PATH: string =                     '/kako/';
2324 var
2325         Index: Integer;
2326         s: string;
2327         SList: TStringList;
2328 begin
2329         BBSID := '';
2330         BBSKey := '';
2331         Result := False;
2332
2333         Index := AnsiPos(READ_PATH, path);
2334         if Index <> 0 then begin
2335                 s := Copy(path, Length(READ_PATH) + 1, Length(path));
2336                 BBSID := GetTokenIndex(s, '/', 0);
2337                 BBSKey := GetTokenIndex(s, '/', 1);
2338                 if BBSKey = '' then
2339                         BBSKey := Document;
2340                 Result := (BBSID <> '') or (BBSKey <> '');
2341                 Exit;
2342         end;
2343         Index := AnsiPos(KAKO_PATH, path);
2344         if Index <> 0 then begin
2345                 s := Copy(path, 2, Length(path));
2346                 BBSID := GetTokenIndex(s, '/', 0);
2347                 if (BBSID = 'log') and (GetTokenIndex(s, '/', 2) = 'kako') then
2348                         BBSID := GetTokenIndex(s, '/', 1);
2349                 BBSKey := ChangeFileExt(Document, '');
2350                 Result := (BBSID <> '') or (BBSKey <> '');
2351                 Exit;
2352         end;
2353         Index := AnsiPos('read.cgi?', URL);
2354         if Index <> 0 then begin
2355                 SList := TStringList.Create;
2356                 try
2357                         try
2358 //                              s := HTMLDecode(Document);
2359                                 ExtractHTTPFields(['?', '&'], [], PChar(URL), SList, False);
2360                                 BBSID := SList.Values['bbs'];
2361                                 BBSKey := SList.Values['key'];
2362                                 Result := (BBSID <> '') or (BBSKey <> '');
2363                                 Exit;
2364                         except
2365                                 Exit;
2366                         end;
2367                 finally
2368                         SList.Free;
2369                 end;
2370         end;
2371 end;
2372
2373 function TGikoSys.Parse2chURL2(URL: string): TPathRec;
2374 var
2375         i: Integer;
2376         s: string;
2377         wk: string;
2378         wkMin: Integer;
2379         wkMax: Integer;
2380         wkInt: Integer;
2381         RStart: Integer;
2382         RLength: Integer;
2383         SList: TStringList;
2384 begin
2385         URL := Trim(LowerCase(URL));
2386         Result.FBBS := '';
2387         Result.FKey := '';
2388         Result.FSt := 0;
2389         Result.FTo := 0;
2390         Result.FFirst := False;
2391         Result.FStBegin := False;
2392         Result.FToEnd := False;
2393         Result.FDone := False;
2394
2395         wkMin := 0;
2396         wkMax := 1;
2397
2398         FAWKStr.RegExp := 'http://.+\.(2ch\.net|bbspink\.com)/';
2399         if FAWKStr.Match(FAWKStr.ProcessEscSeq(URL), RStart, RLength) = 0 then
2400                 Exit;
2401         s := Copy(URL, RStart + RLength - 1, Length(URL));
2402
2403         //\95W\8f\80\8f\91\8e®
2404         //\8dÅ\8cã\82Íl50, 10, 10-20, 10n, 10-20n, -10, 10-, 10n- \82È\82Ç
2405         //http://xxx.2ch.net/test/read.cgi/bbsid/1000000000/
2406         FAWKStr.RegExp := '/test/read.cgi/.+/[0-9]+/.*';
2407         if FAWKStr.Match(FAWKStr.ProcessEscSeq(s), RStart, RLength) > 0 then begin
2408                 s := Copy(s, 15, Length(s));
2409
2410                 SList := TStringList.Create;
2411                 try
2412                         SList.Clear;
2413                         FAWKStr.RegExp := '/';
2414                         if FAWKStr.Split(FAWKStr.ProcessEscSeq(s), SList) >= 2 then begin
2415                                 Result.FBBS := SList[1];
2416                                 Result.FKey := SList[2];
2417                                 if SList.Count >= 3 then
2418                                         s := SList[3]
2419                                 else
2420                                         s := '';
2421                         end else
2422                                 Exit;
2423
2424                         SList.Clear;
2425                         FAWKStr.LineSeparator := mcls_CRLF;
2426                         FAWKStr.RegExp := '-';
2427                         if FAWKStr.Split(FAWKStr.ProcessEscSeq(s), SList) = 0 then begin
2428                                 Result.FFirst := True;
2429                         end else begin
2430                                 FAWKStr.RegExp := 'l[0-9]+';
2431                                 if FAWKStr.Match(FAWKStr.ProcessEscSeq(s), RStart, RLength) > 0 then begin
2432                                         Result.FFirst := True;
2433                                 end else begin
2434                                         for i := 0 to SList.Count - 1 do begin
2435                                                 if Trim(SList[i]) = '' then begin
2436                                                         if i = 0 then
2437                                                                 Result.FStBegin := True;
2438                                                         if i = (SList.Count - 1) then
2439                                                                 Result.FToEnd := True;
2440                                                 end else if IsNumeric(SList[i]) then begin
2441                                                         wkInt := StrToInt(SList[i]);
2442                                                         wkMax := Max(wkMax, wkInt);
2443                                                         if wkMin = 0 then
2444                                                                 wkMin := wkInt
2445                                                         else
2446                                                                 wkMin := Min(wkMin, wkInt);
2447                                                 end else if Trim(SList[i]) = 'n' then begin
2448                                                         Result.FFirst := True;
2449                                                 end else begin
2450                                                         FAWKStr.RegExp := '^n[0-9]+$|^[0-9]+n$';
2451                                                         if FAWKStr.Match(FAWKStr.ProcessEscSeq(SList[i]), RStart, RLength) > 0 then begin
2452                                                                 if Copy(SList[i], 1, 1) = 'n' then
2453                                                                         wkInt := StrToInt(Copy(SList[i], 2, Length(SList[i])))
2454                                                                 else
2455                                                                         wkInt := StrToInt(Copy(SList[i], 1, Length(SList[i]) - 1));
2456                                                                 Result.FFirst := True;
2457                                                                 wkMax := Max(wkMax, wkInt);
2458                                                                 if wkMin = 1 then
2459                                                                         wkMin := wkInt
2460                                                                 else
2461                                                                         wkMin := Min(wkMin, wkInt);
2462                                                         end;
2463                                                 end;
2464                                         end;
2465                                         if Result.FStBegin and (not Result.FToEnd) then
2466                                                 Result.FSt := wkMin
2467                                         else if (not Result.FStBegin) and Result.FToEnd then
2468                                                 Result.FTo := wkMax
2469                                         else if (not Result.FStBegin) and (not Result.FToEnd) then begin
2470                                                 Result.FSt := wkMin;
2471                                                 Result.FTo := wkMax;
2472                                         end;
2473                                         //Result.FSt := wkMin;
2474                                         //Result.FTo := wkMax;
2475                                 end;
2476                         end;
2477                 finally
2478                         SList.Free;
2479                 end;
2480                 Result.FDone := True;
2481                 Exit;
2482         end;
2483
2484         //\90Vkako\8f\91\8e®
2485         //http://server.2ch.net/ITA_NAME/kako/1000/10000/1000000000.html
2486         FAWKStr.RegExp := '/.+/kako/[0-9]+/[0-9]+/[0-9]+\.html';
2487         if FAWKStr.Match(FAWKStr.ProcessEscSeq(s), RStart, RLength) > 0 then begin
2488                 SList := TStringList.Create;
2489                 try
2490                         SList.Clear;
2491                         FAWKStr.RegExp := '/';
2492                         if FAWKStr.Split(FAWKStr.ProcessEscSeq(s), SList) >= 6 then begin
2493                                 Result.FBBS := SList[1];
2494                                 Result.FKey := ChangeFileExt(SList[5], '');
2495                                 Result.FFirst := True;
2496                         end else
2497                                 Exit;
2498                 finally
2499                         SList.Free;
2500                 end;
2501                 Result.FDone := True;
2502                 Exit;
2503         end;
2504
2505         //\8b\8ckako\8f\91\8e®
2506         //http://server.2ch.net/ITA_NAME/kako/999/999999999.html
2507         FAWKStr.RegExp := '/.+/kako/[0-9]+/[0-9]+\.html';
2508         if FAWKStr.Match(FAWKStr.ProcessEscSeq(s), RStart, RLength) > 0 then begin
2509                 SList := TStringList.Create;
2510                 try
2511                         SList.Clear;
2512                         FAWKStr.RegExp := '/';
2513                         if FAWKStr.Split(FAWKStr.ProcessEscSeq(s), SList) >= 5 then begin
2514                                 Result.FBBS := SList[1];
2515                                 Result.FKey := ChangeFileExt(SList[4], '');
2516                                 Result.FFirst := True;
2517                         end else
2518                                 Exit;
2519                 finally
2520                         SList.Free;
2521                 end;
2522                 Result.FDone := True;
2523                 Exit;
2524         end;
2525
2526         //log\8by\82Ñlog2\8f\91\8e®
2527         //http://server.2ch.net/log/ITA_NAME/kako/999/999999999.html
2528         //http://server.2ch.net/log2/ITA_NAME/kako/999/999999999.html
2529         FAWKStr.RegExp := '/log2?/.+/kako/[0-9]+/[0-9]+\.html';
2530         if FAWKStr.Match(FAWKStr.ProcessEscSeq(s), RStart, RLength) > 0 then begin
2531                 SList := TStringList.Create;
2532                 try
2533                         SList.Clear;
2534                         FAWKStr.RegExp := '/';
2535                         if FAWKStr.Split(FAWKStr.ProcessEscSeq(s), SList) >= 6 then begin
2536                                 Result.FBBS := SList[2];
2537                                 Result.FKey := ChangeFileExt(SList[5], '');
2538                                 Result.FFirst := True;
2539                         end else
2540                                 Exit;
2541                 finally
2542                         SList.Free;
2543                 end;
2544                 Result.FDone := True;
2545                 Exit;
2546         end;
2547
2548
2549         //\8b\8cURL\8f\91\8e®
2550         //http://server.2ch.net/test/read.cgi?bbs=ITA_NAME&key=1000000000&st=1&to=5&nofirst=true
2551         FAWKStr.RegExp := '/test/read\.cgi\?';
2552         if FAWKStr.Match(FAWKStr.ProcessEscSeq(s), RStart, RLength) > 0 then begin
2553                 s := Copy(s, 16, Length(s));
2554                 SList := TStringList.Create;
2555                 try
2556                         SList.Clear;
2557                         FAWKStr.RegExp := '&';
2558                         if FAWKStr.Split(FAWKStr.ProcessEscSeq(s), SList) >= 2 then begin
2559                                 Result.FFirst := True;
2560                                 for i := 0 to SList.Count - 1 do begin
2561                                         if Pos('bbs=', SList[i]) = 1 then begin
2562                                                 Result.FBBS := Copy(SList[i], 5, Length(SList[i]));
2563                                         end else if Pos('key=', SList[i]) = 1 then begin
2564                                                 Result.FKey := Copy(SList[i], 5, Length(SList[i]));
2565                                         end else if Pos('st=', SList[i]) = 1 then begin
2566                                                 wk := Copy(SList[i], 4, Length(SList[i]));
2567                                                 if IsNumeric(wk) then
2568                                                         Result.FSt := StrToInt(wk)
2569                                                 else if wk = '' then
2570                                                         Result.FStBegin := True;
2571                                         end else if Pos('to=', SList[i]) = 1 then begin
2572                                                 wk := Copy(SList[i], 4, Length(SList[i]));
2573                                                 if IsNumeric(wk) then
2574                                                         Result.FTo := StrToInt(wk)
2575                                                 else if wk = '' then
2576                                                         Result.FToEnd := True;
2577                                         end else if Pos('nofirst=', SList[i]) = 1 then begin
2578                                                 Result.FFirst := False;
2579                                         end;
2580                                 end;
2581                         end else
2582                                 Exit;
2583                 finally
2584                         SList.Free;
2585                 end;
2586
2587                 if (Result.FBBS <> '') and (Result.FKey <> '') then begin
2588                         Result.FDone := True;
2589                 end;
2590                 Exit;
2591         end;
2592 end;
2593
2594 procedure TGikoSys.ParseURI(var URL, Protocol, Host, Path, Document, Port, Bookmark: string);
2595 var
2596         URI: TIdURI;
2597 begin
2598         Protocol := '';
2599         Host := '';
2600         Path := '';
2601         Document := '';
2602         Port := '';
2603         Bookmark := '';
2604         URI := TIdURI.Create(URL);
2605         try
2606                 Protocol := URI.Protocol;
2607                 Host := URI.Host;
2608                 Path := URI.Path;
2609                 Document := URI.Document;
2610                 Port := URI.Port;
2611                 Bookmark := URI.Bookmark;
2612         finally
2613                 URI.Free;
2614         end;
2615 end;
2616
2617 function TGikoSys.GetVersionBuild: Integer;
2618 var
2619         FixedFileInfo: PVSFixedFileInfo;
2620         VersionHandle, VersionSize: DWORD;
2621         pVersionInfo: Pointer;
2622         ItemLen : UInt;
2623         AppFile: string;
2624 begin
2625         Result := 0;
2626         AppFile := Application.ExeName;
2627         VersionSize := GetFileVersionInfoSize(pChar(AppFile), VersionHandle);
2628         if VersionSize = 0 then
2629                 Exit;
2630         GetMem(pVersionInfo, VersionSize);
2631         try
2632                 if GetFileVersionInfo(PChar(AppFile),VersionHandle,VersionSize, pVersionInfo) then
2633                         if VerQueryValue(pVersionInfo, '\', Pointer(FixedFileInfo), ItemLen) then
2634                                 Result := LOWORD(FixedFileInfo^.dwFileVersionLS);
2635         finally
2636                 FreeMem(pVersionInfo, VersionSize);
2637         end;
2638 end;
2639
2640 initialization
2641         GikoSys := TGikoSys.Create;
2642
2643 finalization
2644         if GikoSys <> nil then begin
2645                 GikoSys.Free;
2646                 GikoSys := nil;
2647         end;
2648 end.