OSDN Git Service

スキンを使わなくても、レスアンカーをクリックするとそのレスに飛ぶようにした。
[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         MojuUtils, ExternalBoardManager, ExternalBoardPlugInMain;
18
19 type
20         //BBS\83^\83C\83v
21         TGikoBBSType = (gbt2ch);
22         //\83\8d\83O\83^\83C\83v
23         TGikoLogType = (glt2chNew, glt2chOld);
24         //\83\81\83b\83Z\81[\83W\83A\83C\83R\83\93
25         TGikoMessageIcon = (gmiOK, gmiSAD, gmiNG, gmiWhat, gmiNone);
26         //URL\83I\81[\83v\83\93\83u\83\89\83E\83U\83^\83C\83v
27         TGikoBrowserType = (gbtIE, gbtUserApp, gbtAuto);
28
29
30         TStrTokSeparator = set of Char;
31         TStrTokRec = record
32                 Str: string;
33                 Pos: Integer;
34         end;
35
36         //\83C\83\93\83f\83b\83N\83X\83t\83@\83C\83\8b\83\8c\83R\81[\83h
37         TIndexRec = record
38                 FNo: Integer;
39                 FFileName: string;
40                 FTitle: string;
41                 FCount: Integer;
42                 FSize: Integer;
43 //              FRoundNo: Integer;
44                 FRoundDate: TDateTime;
45                 FLastModified: TDateTime;
46                 FKokomade: Integer;
47                 FNewReceive: Integer;
48                 FMishiyou: Boolean;     //\96¢\8eg\97p
49                 FUnRead: Boolean;
50                 FScrollTop: Integer;
51                 //Index Ver 1.01
52                 FAllResCount: Integer;
53                 FNewResCount: Integer;
54                 FAgeSage: TGikoAgeSage;
55         end;
56
57         //\83T\83u\83W\83F\83N\83g\83\8c\83R\81[\83h
58         TSubjectRec = record
59                 FFileName: string;
60                 FTitle: string;
61                 FCount: Integer;
62         end;
63
64         //\83\8c\83X\83\8c\83R\81[\83h
65         TResRec = record
66                 FTitle: string;
67                 FMailTo: string;
68                 FName: string;
69                 FDateTime: string;
70                 FBody: string;
71                 FType: TGikoLogType;
72         end;
73
74         //URLPath\83\8c\83R\81[\83h
75         TPathRec = record
76                 FBBS: string;                           //BBSID
77                 FKey: string;                           //ThreadID
78                 FSt: Int64;                             //\8aJ\8en\83\8c\83X\94Ô
79                 FTo: Int64;                             //\8fI\97¹\83\8c\83X\94Ô
80                 FFirst: Boolean;                //>>1\82Ì\95\\8e¦
81                 FStBegin: Boolean;      //1\81`\95\\8e¦
82                 FToEnd: Boolean;                //\81`\8dÅ\8cã\82Ü\82Å\95\\8e¦
83                 FDone: Boolean;                 //\90¬\8c÷
84         end;
85
86         TGikoSys = class(TObject)
87         private
88                 { Private \90é\8c¾ }
89                 FSetting: TSetting;
90                 FDolib: TDolib;
91                 FAWKStr: TAWKStr;
92                 FOnlyAHundredRes : Boolean;
93
94 //              FExitWrite: TStringList;
95 //              function StrToFloatDef(s: string; Default: Double): Double;
96         public
97                 { Public \90é\8c¾ }
98                 FAbon : TAbon;
99                 FSelectResFilter : TAbon;
100                 constructor Create;
101
102                 destructor Destroy; override;
103                 property OnlyAHundredRes : Boolean read FOnlyAHundredRes write FOnlyAHundredRes;
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 GetUserAgent: string;
129                                 function GetSambaFileName : 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; var List: TStringList; SubDir: Boolean; IsPathAdd: Boolean); overload;
136                 procedure GetFileList(Path: string; Mask: string; var List: TStringList; IsPathAdd: Boolean); overload;//\83T\83u\83t\83H\83\8b\83_\82Í\8c\9f\8dõ\82µ\82È\82¢
137                 procedure GetDirectoryList(Path: string; Mask: string; List: TStringList; SubDir: Boolean);
138
139                 procedure CreateHTML2(doc: Variant; ThreadItem: TThreadItem; var sTitle: string);
140                 function AddAnchorTag(s: string): string;
141
142                 function DivideSubject(Line: string): TSubjectRec;
143                 function DivideStrLine(Line: string): TResRec;
144
145                 property Setting: TSetting read FSetting write FSetting;
146                 property Dolib: TDolib read FDolib write FDolib;
147
148                 function UrlToID(url: string): string;
149                 function UrlToServer(url: string): string;
150
151                 function StrTokFirst(const s:string; const sep:TStrTokSeparator; var Rec:TStrTokRec):string;
152                 function StrTokNext(const sep:TStrTokSeparator; var Rec:TStrTokRec): string;
153
154                 function GetFileSize(FileName : string) : longint;
155                 function GetFileLineCount(FileName : string): longint;
156                 function Get2chDate(aDate: TDateTime): string;
157                 function IntToDateTime(val: Int64): TDateTime;
158                 function DateTimeToInt(ADate: TDateTime): Int64;
159
160                 function ReadThreadFile(FileName: string; Line: Integer): string;
161
162                 procedure MenuFont(Font: TFont);
163
164                 function RemoveToken(var s:string; const delimiter:string):string;
165                 function GetTokenIndex(s: string; delimiter: string; index: Integer): string;
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; overload;
170         function ConvRes(const Body, Bbs, Key,  ParamBBS, ParamKey, ParamStart, ParamTo, ParamNoFirst, ParamTrue, FullURL : string): string; overload;
171
172                 function BoolToInt(b: Boolean): Integer;
173                 function IntToBool(i: Integer): Boolean;
174                 function GzipDecompress(ResStream: TStream; ContentEncoding: string): string;
175                 procedure LoadKeySetting(ActionList: TActionList);
176                 procedure SaveKeySetting(ActionList: TActionList);
177                 procedure LoadEditorKeySetting(ActionList: TActionList);
178                 procedure SaveEditorKeySetting(ActionList: TActionList);
179
180                 procedure CreateProcess(const AppPath: string; const Param: string);
181                 procedure OpenBrowser(URL: string; BrowserType: TGikoBrowserType);
182                 function HTMLDecode(const AStr: String): String;
183                 function GetHRefText(s: string): string;
184                 function Is2chHost(Host: string): Boolean;
185                 function Parse2chURL(const url: string; const path: string; const document: string; var BBSID: string; var BBSKey: string): Boolean;
186                 function Parse2chURL2(URL: string): TPathRec;
187                 procedure ParseURI(var URL, Protocol, Host, Path, Document, Port, Bookmark: string);
188                 function GetVersionBuild: Integer;
189                 function        GetBrowsableThreadURL( inURL : string ) : string;
190                 function        GetThreadURL2BoardURL( inURL : string ) : string;
191                 function        Get2chThreadURL2BoardURL( inURL : string ) : string;
192                 function        Get2chBrowsableThreadURL( inURL : string ) : string;
193                 function        Get2chBoard2ThreadURL( inBoard : TBoard; inKey : string ) : string;
194                 procedure ListBoardFile;
195                 procedure ReadBoardFile( bbs : TBBS );
196
197                 function        GetUnknownCategory : TCategory;
198                 function        GetUnknownBoard( inPlugIn : TBoardPlugIn; inURL : string ) : TBoard;
199
200         procedure GetPopupResNumber(URL : string; var stRes, endRes : Int64);
201
202                 // \83X\83L\83\93\82ð\93Ç\82Ý\8d\9e\82Ý\81A\92l\82ð\92u\8a·\82·\82é
203                 function LoadFromSkin( fileName: string; ThreadItem: TThreadItem; SizeByte: Integer ): string;
204         // \83\8c\83X\82Ì\92l\82ð\92u\8a·\82·\82é
205                 function SkinedRes( skin: string; Res: TResRec; No: string ): string;
206
207         //Samba24\82Ì\83t\83@\83C\83\8b\82ª\91\8dÝ\82·\82é\82©\81B\91\8dÝ\82µ\82È\82¢\8fê\8d\87\81Adefault\83t\83@\83C\83\8b\82ðrename\82·\82é
208         procedure SambaFileExists();
209         end;
210
211 var
212         GikoSys: TGikoSys;
213 const
214         //LENGTH_RESTITLE                       = 40;
215         ZERO_DATE: Integer      = 25569;
216         BETA_VERSION_NAME_E = 'beta';
217         BETA_VERSION_NAME_J = 'ÊÞÀ';
218         BETA_VERSION                            = 48;
219         BETA_VERSION_BUILD      = '';                           //debug\94Å\82È\82Ç
220         APP_NAME                                                = 'gikoNavi';
221
222 implementation
223
224 uses
225         Giko, RoundData;
226
227 const
228         FOLDER_INDEX_VERSION                                    = '1.01';
229         USER_AGENT                                                                              = 'Monazilla';
230         DEFAULT_NGWORD_FILE_NAME : String = 'NGword.txt';
231         NGWORDs_DIR_NAME : String               = 'NGwords';
232
233         READ_PATH: string =                     '/test/read.cgi/';
234         OLD_READ_PATH: string =         '/test/read.cgi?';
235         KAKO_PATH: string =                     '/kako/';
236
237 (*************************************************************************
238  *GikoSys\83R\83\93\83X\83g\83\89\83N\83^
239  *************************************************************************)
240 constructor TGikoSys.Create;
241 begin
242         FSetting := TSetting.Create;
243         FDolib := TDolib.Create;
244         FAWKStr := TAWKStr.Create(nil);
245         if DirectoryExists(GetConfigDir) = false then begin
246                 CreateDir(GetConfigDir);
247         end;
248         FAbon := TAbon.Create;
249         FAbon.Setroot(GetConfigDir+NGWORDs_DIR_NAME);
250         FAbon.GoHome;
251         FAbon.ReturnNGwordLineNum := FSetting.ShowNGLinesNum;
252         FAbon.SetNGResAnchor := FSetting.AddResAnchor;
253     FAbon.DeleteSyria := FSetting.DeleteSyria;
254         FAbon.Deleterlo := FSetting.AbonDeleterlo;
255         FAbon.Replaceul := FSetting.AbonReplaceul;
256         FAbon.AbonPopupRes := FSetting.PopUpAbon;
257
258         FSelectResFilter := TAbon.Create;
259         // \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
260         FSelectResFilter.AbonString := '';
261         //
262         OnlyAHundredRes := FSetting.OnlyAHundredRes;
263 end;
264
265 (*************************************************************************
266  *GikoSys\83f\83X\83g\83\89\83N\83^
267  *************************************************************************)
268 destructor TGikoSys.Destroy;
269 var
270         i: Integer;
271         FileList: TStringList;
272 begin
273         //\83X\83\8c\83b\83h\83f\81[\83^\83t\83@\83C\83\8b\82ð\8dX\90V
274 //      FlashExitWrite;
275
276 //      FExitWrite.Free;
277         FAWKStr.Free;
278         FSetting.Free;
279         FDolib.Free;
280         FAbon.Free;
281         FSelectResFilter.Free;
282         //\83e\83\93\83|\83\89\83\8aHTML\82ð\8dí\8f\9c
283         FileList := TStringList.Create;
284         try
285                 GetFileList(GetTempFolder, '*.html', FileList, False, True);
286                 for i := 0 to FileList.Count - 1 do begin
287                         DeleteFile(FileList[i]);
288                 end;
289         finally
290                 FileList.Free;
291         end;
292         inherited;
293 end;
294
295 (*************************************************************************
296  *\95\8e\9a\97ñ\90\94\8e\9a\83`\83F\83b\83N
297  *************************************************************************)
298 {$HINTS OFF}
299 function TGikoSys.IsNumeric(s: string): boolean;
300 var
301         e: integer;
302         v: integer;
303 begin
304         Val(s, v, e);
305         Result := e = 0;
306 end;
307 {$HINTS ON}
308
309 (*************************************************************************
310  *\95\8e\9a\97ñ\95\82\93®\8f¬\90\94\93_\90\94\8e\9a\83`\83F\83b\83N
311  *************************************************************************)
312 function TGikoSys.IsFloat(s: string): boolean;
313 var
314         v: Extended;
315 begin
316         Result := TextToFloat(PChar(s), v, fvExtended);
317 end;
318
319 (*************************************************************************
320  *\83{\81[\83h\83t\83@\83C\83\8b\96¼\8eæ\93¾\81i\83p\83X\81{\83t\83@\83C\83\8b\96¼\81j
321  *************************************************************************)
322 function TGikoSys.GetBoardFileName: string;
323 begin
324         Result := Setting.GetBoardFileName;
325 end;
326
327 (*************************************************************************
328  *\83{\81[\83h\83t\83@\83C\83\8b\96¼\8eæ\93¾\81i\83p\83X\81{\83t\83@\83C\83\8b\96¼\81j
329  *************************************************************************)
330 function TGikoSys.GetCustomBoardFileName: string;
331 begin
332         Result := Setting.GetCustomBoardFileName;
333 end;
334
335 (*************************************************************************
336  *\83e\83\93\83|\83\89\83\8a\83t\83H\83\8b\83_\81[\96¼\8eæ\93¾
337  *************************************************************************)
338 function TGikoSys.GetHtmlTempFileName: string;
339 begin
340         Result := Setting.GetHtmlTempFileName;
341 end;
342
343
344 (*************************************************************************
345  *\8eÀ\8ds\83t\83@\83C\83\8b\83t\83H\83\8b\83_\8eæ\93¾
346  *************************************************************************)
347 function TGikoSys.GetAppDir: string;
348 begin
349         Result := Setting.GetAppDir;
350 end;
351
352 (*************************************************************************
353  *TempHtml\83t\83@\83C\83\8b\96¼\8eæ\93¾\81i\83p\83X\81{\83t\83@\83C\83\8b\96¼\81j
354  *************************************************************************)
355 function TGikoSys.GetTempFolder: string;
356 begin
357         Result := Setting.GetTempFolder;
358 end;
359
360 (*************************************************************************
361  *sent.ini\83t\83@\83C\83\8b\96¼\8eæ\93¾\81i\83p\83X\81{\83t\83@\83C\83\8b\96¼\81j
362  *************************************************************************)
363 function TGikoSys.GetSentFileName: string;
364 begin
365         Result := Setting.GetSentFileName;
366 end;
367
368 (*************************************************************************
369  *outbox.ini\83t\83@\83C\83\8b\96¼\8eæ\93¾\81i\83p\83X\81{\83t\83@\83C\83\8b\96¼\81j
370  *************************************************************************)
371 function TGikoSys.GetOutBoxFileName: string;
372 begin
373         Result := Setting.GetOutBoxFileName;
374 end;
375
376 (*************************************************************************
377  *Config\83t\83H\83\8b\83_\8eæ\93¾
378  *************************************************************************)
379 function TGikoSys.GetConfigDir: string;
380 begin
381         Result := Setting.GetConfigDir;
382 end;
383
384 function TGikoSys.GetStyleSheetDir: string;
385 begin
386         Result := Setting.GetStyleSheetDir;
387 end;
388
389 function TGikoSys.GetSkinDir: string;
390 begin
391         Result := Setting.GetSkinDir;
392 end;
393
394 function TGikoSys.GetSkinHeaderFileName: string;
395 begin
396         Result := Setting.GetSkinHeaderFileName;
397 end;
398
399 function TGikoSys.GetSkinFooterFileName: string;
400 begin
401         Result := Setting.GetSkinFooterFileName;
402 end;
403
404 function TGikoSys.GetSkinNewResFileName: string;
405 begin
406         Result := Setting.GetSkinNewResFileName;
407 end;
408
409 function TGikoSys.GetSkinResFileName: string;
410 begin
411         Result := Setting.GetSkinResFileName;
412 end;
413
414 function TGikoSys.GetSkinBookmarkFileName: string;
415 begin
416         Result := Setting.GetSkinBookmarkFileName;
417 end;
418
419 function TGikoSys.GetSkinNewmarkFileName: string;
420 begin
421         Result := Setting.GetSkinNewmarkFileName;
422 end;
423
424 // UserAgent\8eæ\93¾
425 function TGikoSys.GetUserAgent: string;
426 begin
427         if Dolib.Connected then begin
428                 Result := Format('%s %s/%s%d%s', [
429                                                                 Dolib.UserAgent,
430                                                                 APP_NAME,
431                                                                 //MAJOR_VERSION,
432                                                                 //MINOR_VERSION,
433                                                                 BETA_VERSION_NAME_E,
434                                                                 BETA_VERSION,
435                                                                 BETA_VERSION_BUILD]);
436         end else begin
437                 Result := Format('%s/%s %s/%s%d%s', [
438                                                                 USER_AGENT,
439                                                                 Dolib.Version,
440                                                                 APP_NAME,
441                                                                 //MAJOR_VERSION,
442                                                                 //MINOR_VERSION,
443                                                                 BETA_VERSION_NAME_E,
444                                                                 BETA_VERSION,
445                                                                 BETA_VERSION_BUILD]);
446         end;
447 end;
448
449 (*************************************************************************
450  *\82Q\82¿\82á\82ñ\82Ë\82é\95û\8e®\8e\9e\8d\8f\8eæ\93¾
451  *************************************************************************)
452 function TGikoSys.Get2chDate(aDate: TDateTime): string;
453 var
454         d1: TDateTime;
455         d2: TDateTime;
456 begin
457         d1 := EncodeDate(1970, 1, 1);
458         d2 := aDate - EncodeTime(9, 0, 0, 0);
459         //Result := FloatToStr(Trunc((d2 - d1) * 24 * 60 * 60));
460         Result := FloatToStr(Trunc((d2 - d1) * 86400));
461 end;
462
463
464 function TGikoSys.IntToDateTime(val: Int64): TDateTime;
465 var
466         d1: tdatetime;
467         d2: tdatetime;
468 begin
469         d1 := EncodeDate(1970, 1, 1);
470         d2 := val / 86400.0;//(val * 1000) / (24 * 60 * 60 * 1000);
471         Result := d1 + d2;
472 end;
473
474 function TGikoSys.DateTimeToInt(ADate: TDateTime): Int64;
475 var
476         d: TDateTime;
477         c: Currency;
478 begin
479         d := EncodeDate(1970, 1, 1);
480         c := (ADate - d) * 86400; //(ADate - d) * 24 * 60 * 60;
481         Result := Trunc(c);
482 end;
483
484
485 (*************************************************************************
486  *Subject\83t\83@\83C\83\8bRead
487  *************************************************************************)
488 procedure TGikoSys.ReadSubjectFile(Board: TBoard);
489 var
490         ThreadItem: TThreadItem;
491         FileName: string;
492         FileList: TStringList;
493         TmpFileList: TStringList;
494         Index: Integer;
495         sl: TStringList;
496         i: Integer;
497         Rec: TIndexRec;
498         UnRead: Integer;
499         ini: TMemIniFile;
500         ResRec: TResRec;
501         RoundItem: TRoundItem;
502         idx: Integer;
503         usePlugIn : Boolean;
504         tmpStr: string;
505 begin
506         if Board.IsThreadDatRead then
507                 Exit;
508         Board.Clear;
509         UnRead := 0;
510
511         usePlugIn := Board.IsBoardPlugInAvailable;
512
513         FileName := Board.GetFolderIndexFileName;
514
515         FileList := TStringList.Create;
516         FileList.Sorted := True;
517         TmpFileList := TStringList.Create;
518         TmpFileList.Sorted := True;
519
520         //IsLogFile\97pDAT\83t\83@\83C\83\8b\83\8a\83X\83g
521         GetFileList(ExtractFileDir(Board.GetFolderIndexFileName), '*.dat', FileList, False);
522         //\91O\89ñ\88Ù\8fí\8fI\97¹\8e\9e\97pTmp\83t\83@\83C\83\8b\83\8a\83X\83g
523         GetFileList(ExtractFileDir(Board.GetFolderIndexFileName), '*.tmp', TmpFileList, False);
524
525         // \8fd\95¡\82ð\96h\82®
526         Board.BeginUpdate;
527         Board.Sorted := True;
528
529         sl := TStringList.Create;
530         try
531                 if FileExists(FileName) then begin
532                         sl.LoadFromFile(FileName);
533
534                         //\82Q\8ds\96Ú\82©\82ç\81i\82P\8ds\96Ú\82Í\83o\81[\83W\83\87\83\93\81j
535                         for i := sl.Count - 1 downto 1 do begin
536                                 Rec := ParseIndexLine(sl[i]);
537                                 if usePlugIn then
538                                         ThreadItem := TThreadItem.Create(
539                                                         Board.BoardPlugIn,
540                                                         Board.BoardPlugIn.FileName2ThreadURL( DWORD( Board ), Rec.FFileName ) )
541                                 else
542                                         ThreadItem := TThreadItem.Create(
543                                                 nil,
544                                                 Get2chBoard2ThreadURL( Board, ChangeFileExt( Rec.FFileName, '' ) ) );
545
546                                 if FileList.Count <> 0 then
547                                         if FileList.Find( ThreadItem.FileName, Index ) then
548                                                 FileList.Delete( Index );
549
550                                 ThreadItem.BeginUpdate;
551                                 ThreadItem.No := Rec.FNo;
552                                 ThreadItem.FileName := Rec.FFileName;
553                                 ThreadItem.Title := Rec.FTitle;
554                                 ThreadItem.Count := Rec.FCount;
555                                 ThreadItem.Size := Rec.FSize;
556 //                      ThreadItem.RoundNo := Rec.FRoundNo;
557                                 ThreadItem.RoundDate := Rec.FRoundDate;
558                                 ThreadItem.LastModified := Rec.FLastModified;
559                                 ThreadItem.Kokomade := Rec.FKokomade;
560                                 ThreadItem.NewReceive := Rec.FNewReceive;
561 //                      ThreadItem.Round := Rec.FRound;
562                                 ThreadItem.UnRead := Rec.FUnRead;
563                                 ThreadItem.ScrollTop := Rec.FScrollTop;
564                                 ThreadItem.AllResCount := Rec.FAllResCount;
565                                 ThreadItem.NewResCount := Rec.FNewResCount;
566                                 ThreadItem.AgeSage := Rec.FAgeSage;
567                                 ThreadItem.ParentBoard := Board;
568
569                                 //\8f\84\89ñ\83\8a\83X\83g\82É\91\8dÝ\82µ\82½\82ç\8f\84\89ñ\83t\83\89\83O\83Z\83b\83g
570                                 if ThreadItem.IsLogFile then begin
571                                         idx := RoundList.Find(ThreadItem);
572                                         if idx <> -1 then begin
573                                                 RoundItem := RoundList.Items[idx, grtItem];
574                                                 ThreadItem.RoundName := RoundItem.RoundName;
575                                                 ThreadItem.Round := True;
576                                         end;
577                                 end;
578
579                                 //\91O\89ñ\88Ù\8fí\8fI\97¹\8e\9e\83`\83F\83b\83N
580                                 if TmpFileList.Count <> 0 then begin
581                                         if TmpFileList.Find(ChangeFileExt(ThreadItem.FileName, '.tmp'), Index) then begin
582                                                 ini := TMemIniFile.Create(ExtractFilePath(Board.GetFolderIndexFileName) + TmpFileList[Index]);
583                                                 try
584                                                         tmpStr := ini.ReadString('Setting', 'RoundDate', DateTimeToStr(ZERO_DATE));
585                                                         ThreadItem.RoundDate := ConvertDateTimeString(tmpStr);
586
587                                                         tmpStr := ini.ReadString('Setting', 'LastModified', DateTimeToStr(ZERO_DATE));
588                                                         ThreadItem.LastModified := ConvertDateTimeString(tmpStr);
589
590                                                         ThreadItem.Size := ini.ReadInteger('Setting', 'Size', 0);
591                                                         if(ThreadItem.Size = 0) and (FileExists(ThreadItem.GetThreadFileName)) then begin
592                                                                 try
593                                                                         ThreadItem.Size := GetFileSize(ThreadItem.GetThreadFileName) - ThreadItem.Count;
594                                                                 except
595                                                                 end;
596                                                         end;
597                                                         ThreadItem.Count := ini.ReadInteger('Setting', 'Count', 0);
598                                                         ThreadItem.NewReceive := ini.ReadInteger('Setting', 'NewReceive', 0);
599                                                         ThreadItem.Round := ini.ReadBool('Setting', 'Round', False);
600                                                         ThreadItem.UnRead := False;//ini.ReadBool('Setting', 'UnRead', False);
601                                                         ThreadItem.ScrollTop := ini.ReadInteger('Setting', 'ScrollTop', 0);
602                                                         ThreadItem.AllResCount := ini.ReadInteger('Setting', 'AllResCount', ThreadItem.Count);
603                                                         ThreadItem.NewResCount := ini.ReadInteger('Setting', 'NewResCount', 0);
604                                                         ThreadItem.AgeSage := TGikoAgeSage(ini.ReadInteger('Setting', 'AgeSage', Ord(gasNone)));
605                                                 finally
606                                                         ini.Free;
607                                                 end;
608                                                 DeleteFile(ExtractFilePath(Board.GetFolderIndexFileName) + TmpFileList[Index]);
609                                                 TmpFileList.Delete(Index);
610                                         end;
611                                 end;
612
613                                 ThreadItem.EndUpdate;
614                                 Board.Add(ThreadItem);
615
616                                 if (ThreadItem.IsLogFile) and (ThreadItem.UnRead) then
617                                         Inc(UnRead);
618                         end;
619                 end;
620
621                 if UnRead <> Board.UnRead then
622                         Board.UnRead := UnRead;
623
624                 //\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
625                 for i := 0 to FileList.Count - 1 do begin
626                         FileName := ExtractFileDir(Board.GetFolderIndexFileName) + '\' + FileList[i];
627
628                         //ResRec := DivideStrLine(ReadThreadFile(FileName, 1));
629                         if usePlugIn then begin
630                                 ThreadItem := TThreadItem.Create(
631                                         Board.BoardPlugIn,
632                                         Board.BoardPlugIn.FileName2ThreadURL( DWORD( Board ), FileList[i] ) );
633                                 ResRec := DivideStrLine(Board.BoardPlugIn.GetDat( DWORD( ThreadItem ), 1 ));
634                         end else begin
635                                 ThreadItem := TThreadItem.Create(
636                                         nil, Get2chBoard2ThreadURL( Board, ChangeFileExt( FileList[i], '' ) ) );
637                                 ResRec := DivideStrLine(ReadThreadFile(FileName, 1));
638                         end;
639
640                         ThreadItem.BeginUpdate;
641                         ThreadItem.FilePath := FileName;
642                         ThreadItem.No := Board.Count + 1;
643                         ThreadItem.FileName := FileList[i];
644                         ThreadItem.Title := ResRec.FTitle;
645                         ThreadItem.Count := GetFileLineCount(FileName);
646                         ThreadItem.AllResCount := ThreadItem.Count;
647                         ThreadItem.NewResCount := ThreadItem.Count;
648                         ThreadItem.Size := GetFileSize(FileName) - ThreadItem.Count;//1byte\82¸\82ê\82é\82Æ\82«\82ª\82 \82é\82¯\82Ç\82»\82ê\82Í\82 \82«\82ç\82ß\82é
649                         ThreadItem.RoundDate := ZERO_DATE;
650                         ThreadItem.LastModified := ZERO_DATE;
651                         ThreadItem.Kokomade := -1;
652                         ThreadItem.NewReceive := ThreadItem.Count;
653                         ThreadItem.ParentBoard := Board;
654                         ThreadItem.IsLogFile := True;
655                         ThreadItem.Round := False;
656                         ThreadItem.UnRead := False;
657                         ThreadItem.ScrollTop := 0;
658                         ThreadItem.AgeSage := gasNone;
659                         ThreadItem.EndUpdate;
660                         Board.Add(ThreadItem);
661                 end;
662                 Board.EndUpdate;
663         finally
664                 sl.Free;
665                 FileList.Free;
666                 TmpFileList.Free;
667                 Board.Sorted := False;
668         end;
669         Board.IsThreadDatRead := True;
670 end;
671
672 (*************************************************************************
673  *\83X\83\8c\83b\83h\83C\83\93\83f\83b\83N\83X\83t\83@\83C\83\8b(Folder.idx)\8dì\90¬
674  *************************************************************************)
675 procedure TGikoSys.CreateThreadDat(Board: TBoard);
676 var
677         i: integer;
678         s: string;
679         SubjectList: TStringList;
680         sl: TStringList;
681         Rec: TSubjectRec;
682         FileName: string;
683         cnt: Integer;
684 begin
685         if not FileExists(Board.GetSubjectFileName) then Exit;
686         FileName := Board.GetFolderIndexFileName;
687
688         SubjectList := TStringList.Create;
689         try
690                 SubjectList.LoadFromFile(Board.GetSubjectFileName);
691                 sl := TStringList.Create;
692                 try
693                         cnt := 1;
694                         sl.Add(FOLDER_INDEX_VERSION);
695                         for i := 0 to SubjectList.Count - 1 do begin
696                                 Rec := DivideSubject(SubjectList[i]);
697
698                                 if (Trim(Rec.FFileName) = '') or (Trim(Rec.FTitle) = '') then
699                                         Continue;
700
701                                 s := Format('%x', [cnt]) + #1                                   //\94Ô\8d\86
702                                          + Rec.FFileName + #1                                                           //\83t\83@\83C\83\8b\96¼
703                                          + Rec.FTitle + #1                                                                      //\83^\83C\83g\83\8b
704                                          + Format('%x', [Rec.FCount]) + #1      //\83J\83E\83\93\83g
705                                          + Format('%x', [0]) + #1                                               //size
706                                          + Format('%x', [0]) + #1                                               //RoundDate
707                                          + Format('%x', [0]) + #1                                               //LastModified
708                                          + Format('%x', [0]) + #1                                               //Kokomade
709                                          + Format('%x', [0]) + #1                                               //NewReceive
710                                          + '0' + #1                                                                                             //\96¢\8eg\97p
711                                          + Format('%x', [0]) + #1                                               //UnRead
712                                          + Format('%x', [0]) + #1                                               //ScrollTop
713                                          + Format('%x', [Rec.FCount]) + #1      //AllResCount
714                                          + Format('%x', [0]) + #1                                               //NewResCount
715                                          + Format('%x', [0]);                                                           //AgeSage
716
717                                 sl.Add(s);
718                                 inc(cnt);
719                         end;
720                         sl.SaveToFile(FileName);
721                 finally
722                         sl.Free;
723                 end;
724         finally
725                 SubjectList.Free;
726         end;
727 end;
728
729 (*************************************************************************
730  *\83X\83\8c\83b\83h\83C\83\93\83f\83b\83N\83X(Thread.dat)\8f\91\82«\8d\9e\82Ý
731  *Public
732  *************************************************************************)
733 procedure TGikoSys.WriteThreadDat(Board: TBoard);
734 //const
735 //      Values: array[Boolean] of string = ('0', '1');
736 var
737         i: integer;
738         baseup: Integer;
739         FileName: string;
740         sl: TStringList;
741         s: string;
742         TmpFileList: TStringList;
743         TmpThreadItem: TThreadItem;
744 begin
745         if not Board.IsThreadDatRead then
746                 Exit;
747         FileName := Board.GetFolderIndexFileName;
748         ForceDirectoriesEx( ExtractFilePath( FileName ) );
749
750         sl := TStringList.Create;
751         TmpFileList := TStringList.Create;
752         TmpFileList.Sorted := true;
753         try
754                 GetFileList(ExtractFileDir(Board.GetFolderIndexFileName), '*.tmp', TmpFileList, false);
755                 sl.BeginUpdate;
756                 sl.Add(FOLDER_INDEX_VERSION);
757                 for i := 0 to Board.Count - 1 do begin
758                         Board.Items[i].No := i + 1;
759                         s := Format('%x', [Board.Items[i].No]) + #1
760                                  + Board.Items[i].FileName + #1
761                                  + Board.Items[i].Title + #1
762                                  + Format('%x', [Board.Items[i].Count]) + #1
763                                  + Format('%x', [Board.Items[i].Size]) + #1
764                                  + Format('%x', [DateTimeToInt(Board.Items[i].RoundDate)]) + #1
765                                  + Format('%x', [DateTimeToInt(Board.Items[i].LastModified)]) + #1
766                                  + Format('%x', [Board.Items[i].Kokomade]) + #1
767                                  + Format('%x', [Board.Items[i].NewReceive]) + #1
768                                  + '0' + #1     //\96¢\8eg\97p
769                                  + Format('%x', [BoolToInt(Board.Items[i].UnRead)]) + #1
770                                  + Format('%x', [Board.Items[i].ScrollTop]) + #1
771                                  + Format('%x', [Board.Items[i].AllResCount]) + #1
772                                  + Format('%x', [Board.Items[i].NewResCount]) + #1
773                                  + Format('%x', [Ord(Board.Items[i].AgeSage)]);
774
775                         sl.Add(s);
776                 end;
777                 sl.EndUpdate;
778                 sl.SaveToFile(FileName);
779
780                 for i := 0 to TmpFileList.Count - 1 do begin
781                         DeleteFile(ExtractFilePath(Board.GetFolderIndexFileName) + TmpFileList[i]);
782                 end;
783
784         finally
785                 TmpFileList.Free;
786                 sl.Free;
787         end;
788 end;
789
790 function TGikoSys.ParseIndexLine(Line: string): TIndexRec;
791 begin
792         Result.FNo := StrToIntDef('$' + RemoveToken(Line, #1), 0);
793         Result.FFileName := RemoveToken(Line, #1);
794         Result.FTitle := RemoveToken(Line, #1);
795         Result.FCount := StrToIntDef('$' + RemoveToken(Line, #1), 0);
796         Result.FSize := StrToIntDef('$' + RemoveToken(Line, #1), 0);
797         Result.FRoundDate := IntToDateTime(StrToIntDef('$' + RemoveToken(Line, #1), ZERO_DATE));
798         Result.FLastModified := IntToDateTime(StrToIntDef('$' + RemoveToken(Line, #1), ZERO_DATE));
799         Result.FKokomade := StrToIntDef('$' + RemoveToken(Line, #1), -1);
800         Result.FNewReceive := StrToIntDef('$' + RemoveToken(Line, #1), 0);
801         RemoveToken(Line, #1);//9: ;    //\96¢\8eg\97p
802         Result.FUnRead := IntToBool(StrToIntDef('$' + RemoveToken(Line, #1), 0));
803         Result.FScrollTop := StrToIntDef('$' + RemoveToken(Line, #1), 0);
804         Result.FAllResCount := StrToIntDef('$' + RemoveToken(Line, #1), 0);
805         Result.FNewResCount := StrToIntDef('$' + RemoveToken(Line, #1), 0);
806         Result.FAgeSage := TGikoAgeSage(StrToIntDef('$' + RemoveToken(Line, #1), 0));
807
808 end;
809
810 //\8ew\92è\83t\83H\83\8b\83_\93à\82Ì\8ew\92è\83t\83@\83C\83\8b\88ê\97\97\82ð\8eæ\93¾\82·\82é
811 // ListFiles('c:\', '*.txt', list, True);
812 procedure TGikoSys.GetFileList(Path: string; Mask: string; var List: TStringList; SubDir: Boolean; IsPathAdd: Boolean);
813 var
814         rc: Integer;
815         SearchRec : TSearchRec;
816         s: string;
817         maskExt: string;
818 begin
819         maskExt := Copy(Mask, 1, Length(Mask) - 1);
820
821         Path := IncludeTrailingPathDelimiter(Path);
822         rc := FindFirst(Path + '*.*', faAnyfile, SearchRec);
823         try
824                 while rc = 0 do begin
825                         if (SearchRec.Name <> '..') and (SearchRec.Name <> '.') then begin
826                                 s := Path + SearchRec.Name;
827                                 //if (SearchRec.Attr and faDirectory > 0) then
828                                 //      s := IncludeTrailingPathDelimiter(s)
829
830                                 if (SearchRec.Attr and faDirectory = 0) and (MatchesMask(s, Mask)) then
831                                                 if IsPathAdd then
832                                                         List.Add(s)
833                                                 else
834                                                         List.Add(SearchRec.Name);
835                                 if SubDir and (SearchRec.Attr and faDirectory > 0) then
836                                         GetFileList(s, Mask, List, True, IsPathAdd);
837                         end;
838                         rc := FindNext(SearchRec);
839                 end;
840         finally
841                 SysUtils.FindClose(SearchRec);
842         end;
843         List.Sort;
844 end;
845 //\8ew\92è\83t\83H\83\8b\83_\93à\82Ì\8ew\92è\83t\83@\83C\83\8b\88ê\97\97\82ð\8eæ\93¾\82·\82é
846 //\83T\83u\83t\83H\83\8b\83_\82Í\8c\9f\8dõ\82µ\82È\82¢
847 // ListFiles('c:\', '*.txt', list, True);
848 procedure TGikoSys.GetFileList(Path: string; Mask: string; var List: TStringList; IsPathAdd: Boolean);
849 var
850         rc: Integer;
851         SearchRec : TSearchRec;
852         s: string;
853 begin
854         Path := IncludeTrailingPathDelimiter(Path);
855         rc := FindFirst(Path + Mask, faAnyfile, SearchRec);
856         try
857                 while rc = 0 do begin
858                         if (SearchRec.Name <> '..') and (SearchRec.Name <> '.') then begin
859                                 s := Path + SearchRec.Name;
860
861                                 if (SearchRec.Attr and faDirectory = 0) then
862                                                 if IsPathAdd then
863                                                         List.Add(s)
864                                                 else
865                                                         List.Add(SearchRec.Name);
866                         end;
867                         rc := FindNext(SearchRec);
868                 end;
869         finally
870                 SysUtils.FindClose(SearchRec);
871         end;
872         List.Sort;
873 end;
874 //\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é
875 procedure TGikoSys.GetDirectoryList(Path: string; Mask: string; List: TStringList; SubDir: Boolean);
876 var
877         rc: Integer;
878         SearchRec : TSearchRec;
879         s: string;
880 begin
881         Path := IncludeTrailingPathDelimiter(Path);
882         rc := FindFirst(Path + '*.*', faDirectory, SearchRec);
883         try
884                 while rc = 0 do begin
885                         if (SearchRec.Name <> '..') and (SearchRec.Name <> '.') then begin
886                                 s := Path + SearchRec.Name;
887                                 //if (SearchRec.Attr and faDirectory > 0) then
888                                 //      s := IncludeTrailingPathDelimiter(s)
889
890                                 if (SearchRec.Attr and faDirectory > 0) and (MatchesMask(s, Mask)) then
891                                         List.Add( IncludeTrailingPathDelimiter( s ) );
892                                 if SubDir and (SearchRec.Attr and faDirectory > 0) then
893                                         GetDirectoryList(s, Mask, List, True);
894                         end;
895                         rc := FindNext(SearchRec);
896                 end;
897         finally
898                 SysUtils.FindClose(SearchRec);
899         end;
900 end;
901
902 // \83X\83L\83\93\82ð\93Ç\82Ý\8d\9e\82Ý\81A\92l\82ð\92u\8a·\82·\82é
903 function TGikoSys.LoadFromSkin(
904         fileName: string;
905         ThreadItem: TThreadItem;
906         SizeByte: Integer
907 ): string;
908 var
909         Skin: TStringList;
910 begin
911
912         Skin := TStringList.Create;
913         try
914                 if FileExists( fileName ) then begin
915                         Skin.LoadFromFile( fileName );
916
917                         // \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
918                         try
919                                 if ThreadItem.ParentBoard <> nil then
920                                         if ThreadItem.ParentBoard.ParentCategory <> nil then
921                                                 CustomStringReplace( Skin, '<BBSNAME/>', ThreadItem.ParentBoard.ParentCategory.ParenTBBS.Title);
922                                         CustomStringReplace( Skin, '<THREADURL/>', ThreadItem.URL);
923                         except end;
924                         CustomStringReplace( Skin, '<BOARDNAME/>', ThreadItem.ParentBoard.Title);
925                         CustomStringReplace( Skin, '<BOARDURL/>', ThreadItem.ParentBoard.URL);
926                         CustomStringReplace( Skin, '<THREADNAME/>', ThreadItem.Title);
927                         CustomStringReplace( Skin, '<SKINPATH/>', Setting.CSSFileName);
928                         CustomStringReplace( Skin, '<GETRESCOUNT/>', IntToStr( ThreadItem.Count - ThreadItem.NewResCount ));
929                                                 CustomStringReplace( Skin, '<NEWRESCOUNT/>', IntToStr( ThreadItem.NewResCount ));
930                                                 CustomStringReplace( Skin, '<ALLRESCOUNT/>', IntToStr( ThreadItem.Count ));
931
932                         CustomStringReplace( Skin, '<NEWDATE/>',FormatDateTime('yyyy/mm/dd(ddd) hh:mm', ThreadItem.RoundDate));
933                                                 CustomStringReplace( Skin, '<SIZEKB/>', IntToStr( Floor( SizeByte / 1024 ) ));
934                                                 CustomStringReplace( Skin, '<SIZE/>', IntToStr( SizeByte ));
935
936                         //----- \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µ
937                         // \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
938                         try
939                                 if ThreadItem.ParentBoard <> nil then
940                                         if ThreadItem.ParentBoard.ParentCategory <> nil then
941                                                 CustomStringReplace( Skin, '&BBSNAME', ThreadItem.ParentBoard.ParentCategory.ParenTBBS.Title);
942                                         CustomStringReplace( Skin, '&THREADURL', ThreadItem.URL);
943                         except end;
944                         CustomStringReplace( Skin, '&BOARDNAME', ThreadItem.ParentBoard.Title);
945                         CustomStringReplace( Skin, '&BOARDURL', ThreadItem.ParentBoard.URL);
946                         CustomStringReplace( Skin, '&THREADNAME', ThreadItem.Title);
947                         CustomStringReplace( Skin, '&SKINPATH', Setting.CSSFileName);
948                         CustomStringReplace( Skin, '&GETRESCOUNT', IntToStr( ThreadItem.NewReceive - 1 ));
949                         CustomStringReplace( Skin, '&NEWRESCOUNT', IntToStr( ThreadItem.NewResCount ));
950                         CustomStringReplace( Skin, '&ALLRESCOUNT', IntToStr( ThreadItem.AllResCount ));
951
952                         CustomStringReplace( Skin, '&NEWDATE', FormatDateTime('yyyy/mm/dd(ddd) hh:mm', ThreadItem.RoundDate));
953                         CustomStringReplace( Skin, '&SIZEKB', IntToStr( Floor( SizeByte / 1024 ) ));
954                         CustomStringReplace( Skin, '&SIZE', IntToStr( SizeByte ));
955                         //----- \82±\82±\82Ü\82Å
956                 end;
957                 Result := Skin.Text;
958         finally
959                 Skin.Free;
960         end;
961 end;
962
963 // \83\8c\83X\82Ì\92l\82ð\92u\8a·\82·\82é
964 function TGikoSys.SkinedRes(
965         skin: string;
966         Res: TResRec;
967         No: string
968 ): string;
969 begin
970
971         try
972                 Skin := CustomStringReplace( Skin, '<NUMBER/>',
973                         '<a href="menu:' + No + '" name="' + No + '">' + No + '</a>');
974                 Skin := CustomStringReplace( Skin, '<PLAINNUMBER/>', No);
975                 Skin := CustomStringReplace( Skin, '<NAME/>', '<b>' + Res.FName + '</b>');
976                 Skin := CustomStringReplace( Skin, '<MAILNAME/>',
977                         '<a href="mailto:' + Res.FMailTo + '"><b>' + Res.FName + '</b></a>');
978                 Skin := CustomStringReplace( Skin, '<MAIL/>', Res.FMailTo);
979                 Skin := CustomStringReplace( Skin, '<DATE/>', Res.FDateTime);
980                 Skin := CustomStringReplace( Skin, '<MESSAGE/>', Res.FBody);
981
982                 //----- \82©\82¿\82ã\81`\82µ\82á\8cÝ\8a·\97p\81B\83R\83\81\83\93\83g\83A\83E\83g\82µ\82Ä\82à\82æ\82µ
983                 Skin := CustomStringReplace( Skin, '&NUMBER',
984                         '<a href="menu:' + No + '" name="' + No + '">' + No + '</a>');
985                 Skin := CustomStringReplace( Skin, '&PLAINNUMBER', No);
986                 Skin := CustomStringReplace( Skin, '&NAME', '<b>' + Res.FName + '</b>');
987                 Skin := CustomStringReplace( Skin, '&MAILNAME',
988                         '<a href="mailto:' + Res.FMailTo + '"><b>' + Res.FName + '</b></a>');
989                 Skin := CustomStringReplace( Skin, '&MAIL', Res.FMailTo);
990                 Skin := CustomStringReplace( Skin, '&DATE', Res.FDateTime);
991                 Skin := CustomStringReplace( Skin, '&MESSAGE', Res.FBody);
992                 //----- \82±\82±\82Ü\82Å
993
994                 Result := Skin;
995         finally
996         end;
997
998 end;
999
1000 procedure TGikoSys.CreateHTML2(doc: Variant; ThreadItem: TThreadItem; var sTitle: string);
1001 var
1002         i: integer;
1003         No: string;
1004         //bufList : TStringList;
1005         ReadList: TStringList;
1006         SaveList: TStringList;
1007         CSSFileName: string;
1008         BBSID: string;
1009         FileName: string;
1010         NewReceiveNo: Integer;
1011         Res: TResRec;
1012         boardPlugIn : TBoardPlugIn;
1013
1014         UserOptionalStyle: string;
1015         SkinHeader: string;
1016         SkinNewRes: string;
1017         SkinRes: string;
1018
1019         function LoadSkin( fileName: string ): string;
1020         begin
1021                 Result := LoadFromSkin( fileName, ThreadItem, ThreadItem.Size );
1022         end;
1023         function ReplaceRes( skin: string ): string;
1024         begin
1025                 Result := SkinedRes( skin, Res, No );
1026         end;
1027 begin
1028         if ThreadItem <> nil then begin
1029                 if ThreadItem.IsBoardPlugInAvailable then begin
1030                         //===== \83v\83\89\83O\83C\83\93\82É\82æ\82é\95\\8e¦
1031                         boardPlugIn             := ThreadItem.BoardPlugIn;
1032                         NewReceiveNo    := ThreadItem.NewReceive;
1033                         // \83t\83H\83\93\83g\82â\83T\83C\83Y\82Ì\90Ý\92è
1034                         if Length( GikoSys.Setting.BrowserFontName ) > 0 then
1035                                 UserOptionalStyle := UserOptionalStyle +
1036                                                                 'font-family:"' + GikoSys.Setting.BrowserFontName + '";';
1037                         if GikoSys.Setting.BrowserFontSize <> 0 then
1038                                 UserOptionalStyle := UserOptionalStyle +
1039                                                                 'font-size:' + IntToStr( GikoSys.Setting.BrowserFontSize ) + 'pt;';
1040                         if GikoSys.Setting.BrowserFontColor <> -1 then
1041                                 UserOptionalStyle := UserOptionalStyle +
1042                                                                 'color:#' + IntToHex( GikoSys.Setting.BrowserFontColor, 6 ) + ';';
1043                         if GikoSys.Setting.BrowserBackColor <> -1 then
1044                                 UserOptionalStyle := UserOptionalStyle +
1045                                                                 'background-color:#' + IntToHex( GikoSys.Setting.BrowserBackColor, 6 ) + ';';
1046                         case GikoSys.Setting.BrowserFontBold of
1047                                 -1: UserOptionalStyle := UserOptionalStyle + 'font-weight:normal;';
1048                                 1: UserOptionalStyle := UserOptionalStyle + 'font-weight:bold;';
1049                         end;
1050                         case GikoSys.Setting.BrowserFontItalic of
1051                                 -1: UserOptionalStyle := UserOptionalStyle + 'font-style:normal;';
1052                                 1: UserOptionalStyle := UserOptionalStyle + 'font-style:italic;';
1053                         end;
1054
1055                         SaveList := TStringList.Create;
1056                         try
1057                                 doc.open;
1058                                 // \95\8e\9a\83R\81[\83h\82Í\83v\83\89\83O\83C\83\93\82É\94C\82¹\82é
1059                                 // doc.charset := 'Shift_JIS';
1060
1061                                 // \83w\83b\83_
1062                                 SaveList.Add( boardPlugIn.GetHeader( DWORD( threadItem ),
1063                                         '<style type="text/css">body {' + UserOptionalStyle + '}</style>' ) );
1064
1065                                 for i := 0 to threadItem.Count - 1 do begin
1066                                         if (OnlyAHundredRes = true) and ( i <> 0 ) and ( (threadItem.Count-i) > 101 ) then begin
1067                                                 Continue;
1068                                         end;
1069
1070                                         // \90V\92\85\83}\81[\83N
1071                                         if (NewReceiveNo = (i + 1)) or ((NewReceiveNo = 0) and (i = 0)) then begin
1072                                                 try
1073                                                         if GikoSys.Setting.UseSkin then begin
1074                                                                 if FileExists( GetSkinNewmarkFileName ) then
1075                                                                         SaveList.Add( LoadSkin( GetSkinNewmarkFileName ) )
1076                                                                 else
1077                                                                         SaveList.Add( '<a name="new"></a>' );
1078                                                         end else if GikoSys.Setting.UseCSS then begin
1079                                                                 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>');
1080                                                         end else begin
1081                                                                 SaveList.Add('</dl>');
1082                                                                 SaveList.Add('<a name="new"></a>');
1083                                                                 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>');
1084                                                                 SaveList.Add('<dl>');
1085                                                         end;
1086                                                 except
1087                                                         SaveList.Add( '<a name="new"></a>' );
1088                                                 end;
1089                                         end;
1090
1091                                         // \83\8c\83X
1092                                         SaveList.Add( boardPlugIn.GetRes( DWORD( threadItem ), i + 1 ) );
1093
1094                                         if ThreadItem.Kokomade = (i + 1) then begin
1095                                                 // \82±\82±\82Ü\82Å\93Ç\82ñ\82¾
1096                                                 try
1097                                                         if GikoSys.Setting.UseSkin then begin
1098                                                                 if FileExists( GetSkinBookmarkFileName ) then
1099                                                                         SaveList.Add( LoadSkin( GetSkinBookmarkFileName ) )
1100                                                                 else
1101                                                                         SaveList.Add( '<a name="koko"></a>' );
1102                                                         end else if GikoSys.Setting.UseCSS then begin
1103                                                                 SaveList.Add('<a name="koko"></a><div class="koko">\83R\83R\82Ü\82Å\93Ç\82ñ\82¾</div>');
1104                                                         end else begin
1105                                                                 SaveList.Add('</dl>');
1106                                                                 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>');
1107                                                                 SaveList.Add('<dl>');
1108                                                         end;
1109                                                 except
1110                                                         SaveList.Add( '<a name="koko"></a>' );
1111                                                 end;
1112                                         end;
1113
1114                                         doc.Write(SaveList.Text);
1115                                         SaveList.Clear;
1116                                 end;
1117
1118
1119                                 // \83X\83L\83\93(\83t\83b\83^)
1120                                 SaveList.Add( boardPlugIn.GetFooter( DWORD( threadItem ), '<a name="bottom"></a>' ) );
1121
1122                                 doc.Write(SaveList.Text);
1123                         finally
1124                                 SaveList.Free;
1125                                 doc.Close;
1126                         end;
1127
1128                         Exit;
1129                 end;
1130         end;
1131         ShortDayNames[1] := '\93ú';               ShortDayNames[2] := '\8c\8e';
1132         ShortDayNames[3] := '\89Î';               ShortDayNames[4] := '\90\85';
1133         ShortDayNames[5] := '\96Ø';               ShortDayNames[6] := '\8bà';
1134         ShortDayNames[7] := '\93y';
1135         BBSID := ThreadItem.ParentBoard.BBSID;
1136         NewReceiveNo := ThreadItem.NewReceive;
1137         ReadList := TStringList.Create;
1138         try
1139                 if ThreadItem.IsLogFile then begin
1140                         FileName := ThreadItem.GetThreadFileName;
1141                         ReadList.LoadFromFile(FileName);
1142                         FAbon.IndividualAbon(ReadList, ChangeFileExt(FileName,'.NG'));
1143                         FAbon.Execute(ReadList);                //       \82 \82Ú\81`\82ñ\82µ\82Ä
1144                         FSelectResFilter.ExecuteEx(ReadList); //\83\8c\83X\82Ì\83t\83B\83\8b\83^\83\8a\83\93\83O\82ð\82·\82é
1145                         Res := DivideStrLine(ReadList[0]);
1146                         Res.FTitle := CustomStringReplace(Res.FTitle, '\81\97\81M', ',');
1147                         sTitle := Res.FTitle;
1148                 end else begin
1149                         sTitle := CustomStringReplace(ThreadItem.Title, '\81\97\81M', ',');
1150                 end;
1151                 SaveList := TStringList.Create;
1152                 try
1153                         doc.open;
1154                         doc.charset := 'Shift_JIS';
1155
1156                         // \83t\83H\83\93\83g\82â\83T\83C\83Y\82Ì\90Ý\92è
1157                         if Length( GikoSys.Setting.BrowserFontName ) > 0 then
1158                                 UserOptionalStyle := UserOptionalStyle +
1159                                                                 'font-family:"' + GikoSys.Setting.BrowserFontName + '";';
1160                         if GikoSys.Setting.BrowserFontSize <> 0 then
1161                                 UserOptionalStyle := UserOptionalStyle +
1162                                                                 'font-size:' + IntToStr( GikoSys.Setting.BrowserFontSize ) + 'pt;';
1163                         if GikoSys.Setting.BrowserFontColor <> -1 then
1164                                 UserOptionalStyle := UserOptionalStyle +
1165                                                                 'color:#' + IntToHex( GikoSys.Setting.BrowserFontColor, 6 ) + ';';
1166                         if GikoSys.Setting.BrowserBackColor <> -1 then
1167                                 UserOptionalStyle := UserOptionalStyle +
1168                                                                 'background-color:#' + IntToHex( GikoSys.Setting.BrowserBackColor, 6 ) + ';';
1169                         case GikoSys.Setting.BrowserFontBold of
1170                                 -1: UserOptionalStyle := UserOptionalStyle + 'font-weight:normal;';
1171                                 1: UserOptionalStyle := UserOptionalStyle + 'font-weight:bold;';
1172                         end;
1173                         case GikoSys.Setting.BrowserFontItalic of
1174                                 -1: UserOptionalStyle := UserOptionalStyle + 'font-style:normal;';
1175                                 1: UserOptionalStyle := UserOptionalStyle + 'font-style:italic;';
1176                         end;
1177
1178                         CSSFileName := GetStyleSheetDir + Setting.CSSFileName;
1179                         if GikoSys.Setting.UseSkin then begin
1180                                 // \83X\83L\83\93\8eg\97p
1181                                 // \83X\83L\83\93\82Ì\90Ý\92è
1182                                 try
1183                                         SkinHeader := LoadSkin( GetSkinHeaderFileName );
1184                                         if Length( UserOptionalStyle ) > 0 then
1185                                                 SkinHeader := CustomStringReplace( SkinHeader, '</head>',
1186                                                         '<style type="text/css">body {' + UserOptionalStyle + '}</style></head>');
1187                                         SaveList.Add( SkinHeader );
1188                                 except
1189                                 end;
1190                                 try
1191                                         SkinNewRes := LoadSkin( GetSkinNewResFileName );
1192                                 except
1193                                                                 end;
1194                                 try
1195                                         SkinRes := LoadSkin( GetSkinResFileName );
1196                                 except
1197                                 end;
1198
1199                                 SaveList.Add('<a name="top"></a>');
1200
1201                                 for i := 0 to ReadList.Count - 1 do begin
1202                                         if (OnlyAHundredRes = true) and ( i <> 0 ) and ( (ReadList.Count-i) > 101 ) then begin
1203                                                 Continue;
1204                                         end;
1205                                         // \90V\92\85\83}\81[\83N
1206                                         if (NewReceiveNo = i + 1) or ((NewReceiveNo = 0) and (i = 0)) then begin
1207                                                 try
1208                                                         if FileExists( GetSkinNewmarkFileName ) then
1209                                                                 SaveList.Add( LoadSkin( GetSkinNewmarkFileName ) )
1210                                                         else
1211                                                                 SaveList.Add( '<a name="new"></a>' );
1212                                                 except
1213                                                         SaveList.Add( '<a name="new"></a>' );
1214                                                 end;
1215                                         end;
1216                                         if (Trim(ReadList[i]) <> '') then begin
1217                                                 No := IntToStr(i + 1);
1218
1219                                                 Res := DivideStrLine(ReadList[i]);
1220                                                 if Res.FType = glt2chOld then begin
1221                                                         Res.FMailTo := CustomStringReplace(Res.FMailTo, '\81\97\81M', ',');
1222                                                         Res.FName := CustomStringReplace(Res.FName, '\81\97\81M', ',');
1223                                                         Res.FBody := CustomStringReplace(Res.FBody, '\81\97\81M', ',');
1224                                                 end;
1225
1226                                                 Res.FBody := AddAnchorTag(Res.FBody);
1227                                                 Res.FBody := ConvRes(Res.FBody, ThreadItem.ParentBoard.BBSID, ChangeFileExt(ThreadItem.FileName, ''), 'bbs', 'key', 'st', 'to', 'nofirst', 'true');
1228
1229                                                 try
1230                                                         if NewReceiveNo <= (i + 1) then
1231                                                                 // \90V\92\85\83\8c\83X
1232                                                                 SaveList.Add( ReplaceRes( SkinNewRes ) )
1233                                                         else
1234                                                                 // \92Ê\8fí\82Ì\83\8c\83X
1235                                                                 SaveList.Add( ReplaceRes( SkinRes ) );
1236                                                 except
1237                                                 end;
1238                                         end;
1239
1240                                         if ThreadItem.Kokomade = (i + 1) then begin
1241                                                 // \82±\82±\82Ü\82Å\93Ç\82ñ\82¾
1242                                                 try
1243                                                         if FileExists( GetSkinBookmarkFileName ) then
1244                                                                 SaveList.Add( LoadSkin( GetSkinBookmarkFileName ) )
1245                                                         else
1246                                                                 SaveList.Add( '<a name="koko"></a>' );
1247                                                 except
1248                                                         SaveList.Add( '<a name="koko"></a>' );
1249                                                 end;
1250                                         end;
1251                                         doc.Write(SaveList.Text);
1252                                         SaveList.Clear;
1253                                 end;
1254                                 SaveList.Add('<a name="bottom"></a>');
1255                                 // \83X\83L\83\93(\83t\83b\83^)
1256                                 try
1257                                         SaveList.Add( LoadSkin( GetSkinFooterFileName ) );
1258                                 except
1259                                 end;
1260                                 doc.Write(SaveList.Text);
1261
1262                         end else if GikoSys.Setting.UseCSS and FileExists(CSSFileName) then begin
1263                                 //CSS\8eg\97p
1264                                 //CSSFileName := GetAppDir + CSS_FILE_NAME;
1265 //                              SaveList.Add('<html lang="ja"><head>');
1266                                 SaveList.Add('<html><head>');
1267                                 SaveList.Add('<meta http-equiv="Content-type" content="text/html; charset=Shift_JIS">');
1268                                 SaveList.Add('<title>' + sTitle + '</title>');
1269                                 SaveList.Add('<link rel="stylesheet" href="'+CSSFileName+'" type="text/css">');
1270                                 if Length( UserOptionalStyle ) > 0 then
1271                                         SaveList.Add('<style type="text/css">body {' + UserOptionalStyle + '}</style>');
1272                                 SaveList.Add('</head>');
1273                                 SaveList.Add('<body>');
1274                                 SaveList.Add('<a name="top"></a>');
1275                                 SaveList.Add('<div class="title">' + sTitle + '</div>');
1276                                 doc.Write(SaveList.Text);
1277                                 SaveList.Clear;
1278                                 //Application.ProcessMessages;
1279                                 for i := 0 to ReadList.Count - 1 do begin
1280                                         if (OnlyAHundredRes = true) and ( i <> 0 ) and ( (ReadList.Count-i) > 101 ) then begin
1281                                                 Continue;
1282                                         end;
1283                     if (NewReceiveNo = (i + 1)) or ((NewReceiveNo = 0) and (i = 0)) then begin
1284                                                 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>');
1285                                         end;
1286                                         if (Trim(ReadList[i]) <> '') then begin
1287                                                 No := IntToStr(i + 1);
1288                                                 Res := DivideStrLine(ReadList[i]);
1289                                                 Res.FBody := AddAnchorTag(Res.FBody);
1290                                                 Res.FBody := ConvRes(Res.FBody, ThreadItem.ParentBoard.BBSID, ChangeFileExt(ThreadItem.FileName, ''), 'bbs', 'key', 'st', 'to', 'nofirst', 'true');
1291                                                 if Res.FMailTo = '' then
1292                                                         SaveList.Add('<a name="' + No + '"></a>'
1293                                                                                         + '<div class="header"><span class="no"><a href="menu:' + No + '">' + No + '</a></span> '
1294                                                                                         + '<span class="name_label">\96¼\91O\81F</span> '
1295                                                                                         + '<span class="name"><b>' + Res.FName + '</b></span> '
1296                                                                                         + '<span class="date_label">\93\8a\8de\93ú\81F</span> '
1297                                                                                         + '<span class="date">' + Res.FDateTime+ '</span></div>'
1298                                                                                                                                                                                 + '<div class="mes">' + Res.FBody + ' </div>')
1299                                                 else if GikoSys.Setting.ShowMail then
1300                                                         SaveList.Add('<a name="' + No + '"></a>'
1301                                                                                         + '<div class="header"><span class="no"><a href="menu:' + No + '">' + No + '</a></span>'
1302                                                                                                                                                                                 + '<span class="name_label"> \96¼\91O\81F </span>'
1303                                                                                         + '<a class="name_mail" href="mailto:' + Res.FMailTo + '">'
1304                                                                                         + '<b>' + Res.FName + '</b></a><span class="mail"> [' + Res.FMailTo + ']</span>'
1305                                                                                         + '<span class="date_label"> \93\8a\8de\93ú\81F</span>'
1306                                                                                         + '<span class="date"> ' + Res.FDateTime+ '</span></div>'
1307                                                                                         + '<div class="mes">' + Res.FBody + ' </div>')
1308                                                 else
1309                                                         SaveList.Add('<a name="' + No + '"></a>'
1310                                                                                         + '<div class="header"><span class="no"><a href="menu:' + No + '">' + No + '</a></span>'
1311                                                                                         + '<span class="name_label"> \96¼\91O\81F </span>'
1312                                                                                         + '<a class="name_mail" href="mailto:' + Res.FMailTo + '">'
1313                                                                                         + '<b>' + Res.FName + '</b></a>'
1314                                                                                         + '<span class="date_label"> \93\8a\8de\93ú\81F</span>'
1315                                                                                         + '<span class="date"> ' + Res.FDateTime+ '</span></div>'
1316                                                                                                                                                                                 + '<div class="mes">' + Res.FBody + ' </div>');
1317                                         end;
1318                                         if ThreadItem.Kokomade = (i + 1) then begin
1319                                                 SaveList.Add('<a name="koko"></a><div class="koko">\83R\83R\82Ü\82Å\93Ç\82ñ\82¾</div>');
1320                                         end;
1321
1322                                         doc.Write(SaveList.Text);
1323                                         SaveList.Clear;
1324                                 end;
1325                                 SaveList.Add('<a name="bottom"></a>');
1326                                 SaveList.Add('</body></html>');
1327                                 SaveList.Add('<a name="last"></a>');
1328                                 SaveList.Add('</body></html>');
1329
1330                                 doc.Write(SaveList.Text);
1331                         end else begin
1332                                 //CSS\94ñ\8eg\97p
1333 //                              SaveList.Add('<html lang="ja"><head>');
1334                                 SaveList.Add('<html><head>');
1335                                 SaveList.Add('<meta http-equiv="Content-type" content="text/html; charset=Shift_JIS">');
1336                                 SaveList.Add('<title>' + sTitle + '</title></head>');
1337                                 SaveList.Add('<body TEXT="#000000" BGCOLOR="#EFEFEF" link="#0000FF" alink="#FF0000" vlink="#660099">');
1338                                 SaveList.Add('<a name="top"></a>');
1339                                 SaveList.Add('<font size=+1 color="#FF0000">' + sTitle + '</font>');
1340                                 SaveList.Add('<dl>');
1341                                 doc.Write(SaveList.Text);
1342                                 SaveList.Clear;
1343                                 //Application.ProcessMessages;
1344                                 for i := 0 to ReadList.Count - 1 do begin
1345                                         if (OnlyAHundredRes = true) and ( i <> 0 ) and ( (ReadList.Count-i) > 101 ) then begin
1346                                                 Continue;
1347                                         end;
1348                     if (NewReceiveNo = (i + 1)) or ((NewReceiveNo = 0) and (i = 0)) then begin
1349                                                 SaveList.Add('</dl>');
1350                                                 SaveList.Add('<a name="new"></a>');
1351                                                 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>');
1352                                                 SaveList.Add('<dl>');
1353                                         end;
1354                                         if (Trim(ReadList[i]) <> '') then begin
1355                                                 No := IntToStr(i + 1);
1356                                                 Res := DivideStrLine(ReadList[i]);
1357                                                 if Res.FType = glt2chOld then begin
1358                                                         Res.FMailTo := CustomStringReplace(Res.FMailTo, '\81\97\81M', ',');
1359                                                         Res.FName := CustomStringReplace(Res.FName, '\81\97\81M', ',');
1360                                                         Res.FBody := CustomStringReplace(Res.FBody, '\81\97\81M', ',');
1361                                                 end;
1362                                                 Res.FBody := AddAnchorTag(Res.FBody);
1363                                                 Res.FBody := ConvRes(Res.FBody, ThreadItem.ParentBoard.BBSID, ChangeFileExt(ThreadItem.FileName, ''), 'bbs', 'key', 'st', 'to', 'nofirst', 'true');
1364                                                 if Res.FMailTo = '' then
1365                                                         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>')
1366                                                 else if GikoSys.Setting.ShowMail then
1367                                                         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>')
1368                                                 else
1369                                                         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>');
1370                                         end;
1371                                         if ThreadItem.Kokomade = (i + 1) then begin
1372                                                 SaveList.Add('</dl>');
1373                                                 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>');
1374                                                 SaveList.Add('<dl>');
1375                                         end;
1376                                         doc.Write(SaveList.Text);
1377                                         SaveList.Clear;
1378                                 end;
1379                                 SaveList.Add('</dl>');
1380                                 SaveList.Add('<a name="bottom"></a>');
1381                                 SaveList.Add('</body></html>');
1382                                 doc.Write(SaveList.Text);
1383                         end;
1384                 finally
1385                         SaveList.Free;
1386                         doc.Close;
1387                 end;
1388         finally
1389                 ReadList.Free;
1390         end;
1391 end;
1392 (*************************************************************************
1393  *http://\82Ì\95\8e\9a\97ñ\82ðanchor\83^\83O\95t\82«\82É\82·\82é\81B
1394  *************************************************************************)
1395 function TGikoSys.AddAnchorTag(s: string): string;
1396 const
1397         URL_CHAR: string = '0123456789'
1398                                                                          + 'abcdefghijklmnopqrstuvwxyz'
1399                                                                          + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
1400                                                                          + '#$%&()*+,-./:;=?@[]^_`{|}~!''\';
1401         ANCHOR_REF      = 'href=';
1402         RES_REF                 = '&gt;&gt;';
1403 var
1404         wkIdx: array[0..9] of Integer;
1405         url: string;
1406         href: string;
1407         i, b: Integer;
1408         idx: Integer;
1409         anchorLen : Integer;
1410 begin
1411         Result := '';
1412         // + 3 \82Í 'href="' ('"'\82Â\82«)\82È\82Ç\82Ì\83o\83\8a\83G\81[\83V\83\87\83\93\82É\97]\97T\82ð\8e\9d\82½\82¹\82é\82½\82ß
1413         anchorLen := Length( ANCHOR_REF ) + 3;
1414
1415         while True do begin
1416                 wkIdx[0] := AnsiPos('http://', s);
1417                 wkIdx[1] := AnsiPos('ttp://', s);
1418                 wkIdx[2] := AnsiPos('tp://', s);
1419                 wkIdx[3] := AnsiPos('ms-help://', s);
1420                 wkIdx[4] := AnsiPos('p://', s);
1421                 wkIdx[5] := AnsiPos('https://', s);
1422                 wkIdx[6] := AnsiPos('www.', s);
1423                 wkIdx[7] := AnsiPos('ftp://', s);
1424                 wkIdx[8] := AnsiPos('news://', s);
1425                 wkIdx[9] := AnsiPos('rtsp://', s);
1426
1427                 idx := MaxInt;
1428                 for i := 0 to 9 do
1429                         if wkIdx[i] <> 0 then idx := Min(wkIdx[i], idx);
1430
1431                 if idx = MaxInt then begin
1432                         //\83\8a\83\93\83N\82ª\96³\82¢\82æ\81B
1433                         Result := Result + s;
1434                         Break;
1435                 end;
1436
1437                 if (idx > 1) and
1438                         (Pos( ANCHOR_REF, Copy(s, idx - anchorLen, anchorLen ) ) > 0) then begin
1439                         //\8aù\82É\83\8a\83\93\83N\83^\83O\82ª\82Â\82¢\82Ä\82¢\82é\82Á\82Û\82¢\82Æ\82«\82Í\83\80\83V
1440                         href := Copy( s, idx, Length( s ) );
1441                         Result := Result + Copy( s, 1, idx + Pos( '</a>', href ) + Length( '</a>' ) - 2 );
1442                         s := href;
1443                         s := Copy( s, Pos( '</a>', s ) + Length( '</a>' ), Length( s ) );
1444
1445                         Continue;
1446                 end;
1447
1448                 Result := Result + Copy(s, 0, idx - 1);
1449
1450                 s := Copy(s, idx, length(s));
1451
1452                 b := Length( s ) + 1;
1453                 for i := 1 to b do begin
1454                         if i = b then
1455         idx := 0
1456       else
1457                                 idx := AnsiPos(s[i], URL_CHAR);
1458                         if idx = 0 then begin
1459                                 //URL\82\82á\82È\82¢\95\8e\9a\94­\8c©\81I\82Æ\82©\81A\95\8e\9a\82ª\82È\82­\82È\82Á\82½\81B
1460                                 url := Copy(s, 0, i - 1);
1461
1462                                 if AnsiPos('ttp://', url) = 1 then
1463                                         href := 'h' + url
1464                                 else if AnsiPos('tp://', url) = 1 then
1465                                         href := 'ht' + url
1466                                 else if AnsiPos('p://', url) = 1 then
1467                                         href := 'htt' + url
1468                                 else if AnsiPos('www.', url) = 1 then
1469                                         href := 'http://' + url
1470                                 else
1471                                         href := url;
1472                                 Result := Result + '<a href="' + href + '" target="_blank">' + url + '</a>';
1473                                 s := Copy(s, i, MaxInt);
1474                                 Break;
1475                         end;
1476                 end;
1477         end;
1478 end;
1479
1480 (*************************************************************************
1481  *\83T\83u\83W\83F\83N\83g\88ê\8ds\82ð\95ª\8a\84
1482  *************************************************************************)
1483 function TGikoSys.DivideSubject(Line: string): TSubjectRec;
1484 var
1485         i: integer;
1486         ws: WideString;
1487         Delim: string;
1488         LeftK: string;
1489         RightK: string;
1490 begin
1491         Result.FCount := 0;
1492
1493         if AnsiPos('<>', Line) = 0 then
1494                 Delim := ','
1495         else
1496                 Delim := '<>';
1497         Result.FFileName := RemoveToken(Line, Delim);
1498         Result.FTitle := RemoveToken(Line, Delim);
1499
1500         ws := Trim(Result.FTitle);
1501
1502         if Copy(ws, Length(ws), 1) = ')' then begin
1503                 LeftK := '(';
1504                 RightK := ')';
1505         end else if Copy(ws, Length(ws), 1) = '\81j' then begin
1506                 LeftK := '\81i';
1507                 RightK := '\81j';
1508         end else if Copy(ws, Length(ws), 1) = '<' then begin
1509                 LeftK := '<';
1510                 RightK := '>';
1511         end;
1512
1513         for i := Length(ws) - 1 downto 1 do begin
1514                 if ws[i] = LeftK then begin
1515                         ws := Copy(ws, i + 1, Length(ws) - i - 1);
1516                         if IsNumeric(ws) then
1517                                 Result.FCount := StrToInt(ws);
1518                         Result.FTitle := Trim(CustomStringReplace(Result.FTitle, LeftK + ws + RightK, ''));
1519                         break;
1520                 end;
1521         end;
1522 end;
1523
1524 (*************************************************************************
1525  * dat\83t\83@\83C\83\8b\82Ì\88ê\83\89\83C\83\93\82ð\95ª\89ð
1526  *************************************************************************)
1527 function TGikoSys.DivideStrLine(Line: string): TResRec;
1528 var
1529         Delim: string;
1530                 bufbody : String;
1531 begin
1532         if AnsiPos('<>', Line) = 0 then begin
1533                 Delim := ',';
1534                 Result.FType := glt2chOld;
1535         end else begin
1536                 Delim := '<>';
1537                 Result.FType := glt2chNew;
1538         end;
1539         Result.FName := Trim(RemoveToken(Line, Delim));
1540         Result.FMailTo := Trim(RemoveToken(Line, Delim));
1541         Result.FDateTime := Trim(RemoveToken(Line, Delim));
1542         bufBody := Trim(RemoveToken(Line, Delim));
1543
1544         if bufbody = '' then begin
1545                 Insert('&nbsp;',bufbody, 1);
1546         end;
1547         Result.FBody := bufBody;
1548         Result.FTitle := Trim(RemoveToken(Line, Delim));
1549
1550 end;
1551
1552 (*************************************************************************
1553  * URL\82©\82çBBSID\82ð\8eæ\93¾
1554  *************************************************************************)
1555 function TGikoSys.UrlToID(url: string): string;
1556 var
1557         i: integer;
1558 begin
1559         Result := '';
1560         url := Trim(url);
1561
1562         if url = '' then Exit;
1563
1564         url := Copy(url, 0, Length(url) - 1);
1565         for i := Length(url) downto 0 do begin
1566                 if url[i] = '/' then begin
1567                         Result := Copy(url, i + 1, Length(url));
1568                         Break;
1569                 end;
1570         end;
1571 end;
1572
1573 (*************************************************************************
1574  *URL\82©\82çBBSID\88È\8aO\82Ì\95\94\95ª(http://teri.2ch.net/)\82ð\8eæ\93¾
1575  *************************************************************************)
1576 function TGikoSys.UrlToServer(url: string): string;
1577 var
1578         i: integer;
1579         wsURL: WideString;
1580 begin
1581         Result := '';
1582         wsURL := url;
1583         wsURL := Trim(wsURL);
1584
1585         if wsURL = '' then exit;
1586
1587         if Copy(wsURL, Length(wsURL), 1) = '/' then
1588                 wsURL := Copy(wsURL, 0, Length(wsURL) - 1);
1589
1590         for i := Length(wsURL) downto 0 do begin
1591                 if wsURL[i] = '/' then begin
1592                         Result := Copy(wsURL, 0, i);
1593                         break;
1594                 end;
1595         end;
1596 end;
1597
1598 (*************************************************************************
1599  *\83f\83B\83\8c\83N\83g\83\8a\82ª\91\8dÝ\82·\82é\82©\83`\83F\83b\83N
1600  *************************************************************************)
1601 function TGikoSys.DirectoryExistsEx(const Name: string): Boolean;
1602 var
1603         Code: Integer;
1604 begin
1605         Code := GetFileAttributes(PChar(Name));
1606         Result := (Code <> -1) and (FILE_ATTRIBUTE_DIRECTORY and Code <> 0);
1607 end;
1608
1609 (*************************************************************************
1610  *\83f\83B\83\8c\83N\83g\83\8a\8dì\90¬\81i\95¡\90\94\8aK\91w\91Î\89\9e\81j
1611  *************************************************************************)
1612 function TGikoSys.ForceDirectoriesEx(Dir: string): Boolean;
1613 begin
1614         Result := True;
1615         if Length(Dir) = 0 then
1616                 raise Exception.Create('\83t\83H\83\8b\83_\82ª\8dì\90¬\8fo\97\88\82Ü\82¹\82ñ');
1617         Dir := ExcludeTrailingPathDelimiter(Dir);
1618         if (Length(Dir) < 3) or DirectoryExistsEx(Dir)
1619                 or (ExtractFilePath(Dir) = Dir) then Exit; // avoid 'xyz:\' problem.
1620         Result := ForceDirectoriesEx(ExtractFilePath(Dir)) and CreateDir(Dir);
1621 end;
1622
1623 (*************************************************************************
1624  *\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
1625  *FDelphi\82©\82ç\82Ì\83p\83N\83\8a
1626  *************************************************************************)
1627 function TGikoSys.StrTokFirst(const s:string; const sep: TStrTokSeparator; var Rec: TStrTokRec): string;
1628 begin
1629         Rec.Str := s;
1630         Rec.Pos := 1;
1631         Result := StrTokNext(sep, Rec);
1632 end;
1633
1634 (*************************************************************************
1635  *\95\8e\9a\97ñ\82©\82ç\83g\81[\83N\83\93\82Ì\90Ø\82è\8fo\82µ
1636  *FDelphi\82©\82ç\82Ì\83p\83N\83\8a
1637  *************************************************************************)
1638 function TGikoSys.StrTokNext(const sep: TStrTokSeparator; var Rec: TStrTokRec): string;
1639 var
1640         Len, I: Integer;
1641 begin
1642         with Rec do     begin
1643                 Len := Length(Str);
1644                 Result := '';
1645                 if Len >= Pos then begin
1646                         while (Pos <= Len) and (Str[Pos] in sep) do begin
1647                          Inc(Pos);
1648                         end;
1649                         I := Pos;
1650                         while (Pos<= Len) and not (Str[Pos] in sep) do begin
1651                                 if IsDBCSLeadByte(Byte(Str[Pos])) then begin
1652                                         Inc(Pos);
1653                                 end;
1654                                 Inc(Pos);
1655                         end;
1656                         Result := Copy(Str, I, Pos - I);
1657                         while (Pos <= Len) and (Str[Pos] in sep) do begin// \82±\82ê\82Í\82¨\8dD\82Ý
1658                                 Inc(Pos);
1659                         end;
1660                 end;
1661         end;
1662 end;
1663
1664 (*************************************************************************
1665  *\83t\83@\83C\83\8b\83T\83C\83Y\8eæ\93¾
1666  *************************************************************************)
1667 function TGikoSys.GetFileSize(FileName : string): longint;
1668 var
1669         F : File;
1670 begin
1671         try
1672                 if not FileExists(FileName) then begin
1673                         Result := 0;
1674                         Exit;
1675                 end;
1676                 Assign(F, FileName);
1677                 Reset(F, 1);
1678                 Result := FileSize(F);
1679                 CloseFile(F);
1680         except
1681                 Result := 0;
1682         end;
1683 end;
1684
1685 (*************************************************************************
1686  *\83t\83@\83C\83\8b\8ds\90\94\8eæ\93¾
1687  *************************************************************************)
1688 function TGikoSys.GetFileLineCount(FileName : string): longint;
1689 var
1690         sl: TStringList;
1691 begin
1692         sl := TStringList.Create;
1693         try
1694                 try
1695                         sl.LoadFromFile(FileName);
1696                         Result := sl.Count;
1697                 except
1698                         Result := 0;
1699                 end;
1700         finally
1701                 sl.Free;
1702         end;
1703
1704 end;
1705
1706 (*************************************************************************
1707  *\83X\83\8c\83b\83h\83t\83@\83C\83\8b\82©\82ç\8ew\92è\8ds\82ð\8eæ\93¾
1708  *************************************************************************)
1709 function TGikoSys.ReadThreadFile(FileName: string; Line: Integer): string;
1710 var
1711         fileTmp : TStringList;
1712 begin
1713         Result := '';
1714         if FileExists(FileName) then begin
1715                 fileTmp := TStringList.Create;
1716                 try
1717                         try
1718                                 fileTmp.LoadFromFile( FileName );
1719                                 if ( Line       >= 1 ) and ( Line       < fileTmp.Count + 1 ) then begin
1720                                         Result := fileTmp.Strings[ Line-1 ];
1721                                 end;
1722                         except
1723                                 //on EFOpenError do Result := '';
1724                         end;
1725                 finally
1726                         fileTmp.Free;
1727                 end;
1728         end;
1729 end;
1730
1731 (*************************************************************************
1732  *\83V\83X\83e\83\80\83\81\83j\83\85\81[\83t\83H\83\93\83g\82Ì\91®\90«\82ð\8eæ\93¾
1733  *************************************************************************)
1734 procedure TGikoSys.MenuFont(Font: TFont);
1735 var
1736         lf: LOGFONT;
1737         nm: NONCLIENTMETRICS;
1738 begin
1739         nm.cbSize := sizeof(NONCLIENTMETRICS);
1740
1741         SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, @nm, 0);
1742         lf := nm.lfMenuFont;
1743
1744         Font.Name := lf.lfFaceName;
1745         Font.Height := lf.lfHeight;
1746         Font.Style := [];
1747         if lf.lfWeight >= 700 then
1748                 Font.Style := Font.Style + [fsBold];
1749         if lf.lfItalic = 1 then
1750                 Font.Style := Font.Style + [fsItalic];
1751 end;
1752
1753 (*************************************************************************
1754  *
1755  *\82Ç\82±\82©\82Ì\83T\83C\83g\82©\82ç\82Ì\83p\83N\83\8a
1756  *************************************************************************)
1757 function TGikoSys.RemoveToken(var s: string;const delimiter: string): string;
1758 var
1759         p: Integer;
1760 begin
1761         p := AnsiPos(delimiter, s);
1762         if p = 0 then
1763                 Result := s
1764         else
1765                 Result := Copy(s, 1, p - 1);
1766         s := Copy(s, Length(Result) + Length(delimiter) + 1, Length(s));
1767 end;
1768
1769 (*************************************************************************
1770  *
1771  *\82Ç\82±\82©\82Ì\83T\83C\83g\82©\82ç\82Ì\83p\83N\83\8a
1772  *************************************************************************)
1773 function TGikoSys.GetTokenIndex(s: string; delimiter: string; index: Integer): string;
1774 var
1775         i: Integer;
1776 begin
1777         Result := '';
1778         for i := 0 to index do
1779                 Result := RemoveToken(s, delimiter);
1780 end;
1781
1782 (*************************************************************************
1783  *
1784  *************************************************************************)
1785 function TGikoSys.DeleteLink(const s: string): string;
1786 var
1787         s1: string;
1788         s2: string;
1789         idx: Integer;
1790         i: Integer;
1791 begin
1792         i := 0;
1793         Result := '';
1794         while True do begin
1795                 s1 := GetTokenIndex(s, '<a href="', i);
1796                 s2 := GetTokenIndex(s, '<a href="', i + 1);
1797
1798                 idx := Pos('">', s1);
1799                 if idx <> 0 then
1800                         Delete(s1, 1, idx + 1);
1801                 idx := Pos('">', s2);
1802                 if idx <> 0 then
1803                         Delete(s2, 1, idx + 1);
1804
1805                 Result := Result + s1 + s2;
1806
1807                 if s2 = '' then
1808                         Break;
1809
1810                 inc(i, 2);
1811         end;
1812 end;
1813
1814 //\83C\83\93\83f\83b\83N\83X\96¢\8dX\90V\83o\83b\83t\83@\82ð\83t\83\89\83b\83V\83\85\81I
1815 {procedure TGikoSys.FlashExitWrite;
1816 var
1817         i: Integer;
1818 begin
1819         //\83X\83\8c\83b\83h\83f\81[\83^\83t\83@\83C\83\8b\82ð\8dX\90V
1820         for i := 0 to FExitWrite.Count - 1 do
1821                 WriteThreadDat(FExitWrite[i]);
1822         FExitWrite.Clear;
1823 end;}
1824
1825 (*************************************************************************
1826  *\83X\83\8c\96¼\82È\82Ç\82ð\92Z\82¢\96¼\91O\82É\95Ï\8a·\82·\82é
1827  *from HotZonu
1828  *************************************************************************)
1829 function TGikoSys.GetShortName(const LongName: string; ALength: integer): string;
1830 const
1831         ERASECHAR : array [1..39] of string =
1832                 ('\81\99','\81\9a','\81¡','\81 ','\81\9f','\81\9e','\81Q','\81\94','\81£','\81¥',
1833                  '\81¢','\81¤','\81\9c','\81\9b','\81\9d','\81y','\81z','\81ô','\81s','\81t',
1834                  '\81g','\81h','\81k','\81l','\81e','\81f','\81\83','\81\84','\81á','\81â',
1835                  '\81o','\81p','\81q','\81r','\81w','\81x','\81¬','\81c', '\81@');
1836 var
1837         Chr : array [0..255]    of      char;
1838         S : string;
1839         i : integer;
1840 begin
1841         s := Trim(LongName);
1842         if (Length(s) <= ALength) then begin
1843                 Result := s;
1844         end else begin
1845                 S := s;
1846                 for i := Low(ERASECHAR) to      High(ERASECHAR) do      begin
1847                         S := CustomStringReplace(S, ERASECHAR[i], '');
1848                 end;
1849                 if (Length(S) <= ALength) then begin
1850                         Result := S;
1851                 end else begin
1852                         Windows.LCMapString(
1853                                         GetUserDefaultLCID(),
1854                                         LCMAP_HALFWIDTH,
1855                                         PChar(S),
1856                                         Length(S) + 1,
1857                                         chr,
1858                                         Sizeof(chr)
1859                                         );
1860                         S := Chr;
1861                         S := Copy(S,1,ALength);
1862                         while true do begin
1863                                 if (ByteType(S, Length(S)) = mbLeadByte ) then begin
1864                                         S := Copy(S, 1, Length(S) - 1);
1865                                 end else begin
1866                                         Break;
1867                                 end;
1868                         end;
1869                         Result := S;
1870                 end;
1871         end;
1872 end;
1873
1874 (*************************************************************************
1875  *
1876  * from HotZonu
1877  *************************************************************************)
1878 function TGikoSys.ConvRes(const Body, Bbs, Key,
1879         ParamBBS, ParamKey, ParamStart, ParamTo, ParamNoFirst, ParamTrue : string): string;
1880 type
1881         PIndex = ^TIndex;
1882         TIndex = record
1883                 FIndexFrom      : integer;
1884                 FIndexTo                : integer;
1885                 FNo                              : string;
1886         end;
1887 const
1888         GT      = '&gt;';
1889         SN      = '0123456789-';
1890         ZN      = '\82O\82P\82Q\82R\82S\82T\82U\82V\82W\82X\81|';
1891 var
1892         i : integer;
1893         s,r : string;
1894         b : TMbcsByteType;
1895         sw: boolean;
1896         sp: integer;
1897         No: string;
1898         sx: string;
1899         List: TList;
1900         oc      : string;
1901         st, et: string;
1902         chk : boolean;
1903         al : boolean;
1904         procedure Add(IndexFrom, IndexTo: integer; const No: string);
1905         var
1906                 FIndex : PIndex;
1907         begin
1908                 New(FIndex);
1909                 FIndex.FIndexFrom       := IndexFrom;
1910                 FIndex.FIndexTo         := IndexTo;
1911                 FIndex.FNo                               := No;
1912                 List.Add(FIndex);
1913         end;
1914         function ChooseString(const Text, Separator: string; Index: integer): string;
1915         var
1916                 S : string;
1917                 i, p : integer;
1918         begin
1919                 S :=    Text;
1920                 for i :=        0 to    Index - 1 do    begin
1921                         if      (AnsiPos(Separator, S) = 0) then        S :=    ''
1922                         else    S :=    Copy(S, AnsiPos(Separator, S) + Length(Separator), Length(S));
1923                 end;
1924                 p :=    AnsiPos(Separator, S);
1925                 if      (p > 0) then    Result  :=      Copy(S, 1, p - 1) else Result :=        S;
1926         end;
1927 begin
1928         { v1.0 b2 - 03 }
1929         s        :=     Body;
1930         r        :=     Body;
1931         i        :=     1;
1932         sw      :=      False;
1933         No      :=      '';
1934         List:=  TList.Create;
1935         oc      :=      '';
1936         sp      :=      0;
1937         chk :=  False;
1938         al      :=      False;
1939         while true      do      begin
1940                 b :=    ByteType(s, i);
1941                 case    b of
1942                         mbSingleByte    : begin
1943                                 if      (not sw) and (Copy(s,i,8) = GT + GT) then       begin
1944                                         if      (AnsiPos('<A HREF', AnsiUpperCase(oc)) = 0) then        begin
1945                                                 sw      :=      True;
1946                                                 sp      :=      i;
1947                                                 i :=    i + 7;
1948                                                 oc:='';
1949                                                 chk :=  True;
1950                                         end;
1951                                 end else
1952                                 if      (not sw) and (Copy(s,i,8) = GT + GT) then       begin
1953                                         if      (AnsiPos('<A HREF', AnsiUpperCase(oc)) = 1) then        begin
1954                                                 i :=    i + 7;
1955                                                 oc:='';
1956                                                 chk :=  True;
1957                                         end;
1958                                 end else
1959                                 if      (not sw) and (Copy(s,i,4) = GT) then    begin
1960                                         if      (AnsiPos('<A HREF', AnsiUpperCase(oc)) = 0) then        begin
1961                                                 sw      :=      True;
1962                                                 sp      :=      i;
1963                                                 i :=    i + 3;
1964                                                 oc:='';
1965                                                 chk :=  True;
1966                                         end;
1967                                 end else
1968                                 if      ((not sw) and (Copy(s,i,1) = ',')) or
1969                                                 ((not sw) and (Copy(s,i,1) = '=')) then begin
1970                                         if      ((not Chk) and (AnsiLowerCase(oc) = '</a>')) or
1971                                                         ((Chk) and      (oc = '')) or
1972                                                         ((not Chk) and (al)) then
1973                                         begin
1974                                                 sw      :=      True;
1975                                                 sp      :=      i;
1976                                                 //i :=  i + 1;
1977                                                 oc:='';
1978                                         end;
1979                                 end else
1980                                 if      (sw) then begin
1981                                         sx      :=      Copy(s,i,1);
1982                                         if      (AnsiPos(sx, SN) > 0)   then    begin
1983                                                 No      :=      No      + sx;
1984                                         end else begin
1985                                                 if      (No <> '') and (No <> '-')       then   begin
1986                                                         Add(sp, i, No);
1987                                                         al := True;
1988                                                 end;
1989                                                 sw      :=      False;
1990                                                 //
1991                                                 i := i - 1;
1992                                                 //
1993                                                 No      := '';
1994                                                 oc:='';
1995                                                 //chk :=        False;
1996                                         end;
1997                                 end else begin
1998                                         if      Copy(s,i,1) = '<' then  oc      :=      '';
1999                                         oc      :=      oc + Copy(s,i,1);
2000                                         chk :=  False;
2001                                         al      :=      False;
2002                                 end;
2003                         end;
2004                         mbLeadByte      : begin
2005                                 if      (not sw) and (Copy(s,i,4) = '\81\84\81\84') then        begin
2006                                         sw      :=      True;
2007                                         sp      :=      i;
2008                                         i :=    i + 3;
2009                                         chk :=  True;
2010                                 end else
2011                                 if      (not sw) and (Copy(s,i,2) = '\81\84') then  begin
2012                                         sw      :=      True;
2013                                         sp      :=      i;
2014                                         i :=    i + 1;
2015                                         chk :=  True;
2016                                 end else
2017                                 if      (sw) then begin
2018                                         sx      :=      Copy(s,i,2);
2019                                         if      (AnsiPos(sx, ZN) > 0)   then    begin
2020                                                 No      :=      No      + ZenToHan(sx);
2021                                         end else begin
2022                                                 if      (No <> '') and (No <> '-')      and (No <> '\81|') then   begin
2023                                                         Add(sp, i, No);
2024                                                 end;
2025                                                 sw      :=      False;
2026                                                 i := i - 1;
2027                                                 No      :=      '';
2028                                         end;
2029                                 end else begin
2030                                         oc      :=      '';
2031                                         chk :=  False;
2032                                 end;
2033                                 al      :=      False;
2034                         end;
2035                 end;
2036                 inc(i);
2037                 if      (i > Length(Body))      then    begin
2038                         if      (sw)    then    begin
2039                                 if      (No <> '')      then    Add(sp, i, No);
2040                         end;
2041                         Break;
2042                 end;
2043         end;
2044         for i :=        List.Count - 1  downto  0 do    begin
2045                 if      (AnsiPos('-', PIndex(List[i]).FNo) > 0) then    begin
2046                         st      :=      ChooseString(PIndex(List[i]).FNo, '-', 0);
2047                         et      :=      ChooseString(PIndex(List[i]).FNo, '-', 1);
2048                 end else begin
2049                         st      :=      PIndex(List[i]).FNo;
2050                         et      :=      PIndex(List[i]).FNo;
2051                 end;
2052                 r :=    Copy(r,0, PIndex(List[i]).FIndexFrom - 1) +
2053                                         Format('<a href="../test/read.cgi?%s=%s&%s=%s&%s=%s&%s=%s&%s=%s" target="_blank">',
2054                                                                 [ParamBBS, Bbs, ParamKey, Key, ParamStart, st, ParamTo, et, ParamNoFirst, ParamTrue]) +
2055                                         Copy(r,PIndex(List[i]).FIndexFrom, PIndex(List[i]).FIndexTo - PIndex(List[i]).FIndexFrom) + '</A>' +
2056                                         Copy(r,PIndex(List[i]).FIndexTo,Length(r));
2057                 Dispose(PIndex(List[i]));
2058         end;
2059         List.Free;
2060         Result  :=      r;
2061 end;
2062
2063 function TGikoSys.ConvRes(
2064         const Body, Bbs, Key, ParamBBS, ParamKey,
2065     ParamStart, ParamTo, ParamNoFirst,
2066     ParamTrue, FullURL : string
2067 ): string;
2068 type
2069         PIndex = ^TIndex;
2070         TIndex = record
2071                 FIndexFrom      : integer;
2072                 FIndexTo                : integer;
2073                 FNo                              : string;
2074         end;
2075 const
2076         GT      = '&gt;';
2077         SN      = '0123456789-';
2078         ZN      = '\82O\82P\82Q\82R\82S\82T\82U\82V\82W\82X\81|';
2079 var
2080         i : integer;
2081         s,r : string;
2082         b : TMbcsByteType;
2083         sw: boolean;
2084         sp: integer;
2085         No: string;
2086         sx: string;
2087         List: TList;
2088         oc      : string;
2089         st, et: string;
2090         chk : boolean;
2091         al : boolean;
2092         procedure Add(IndexFrom, IndexTo: integer; const No: string);
2093         var
2094                 FIndex : PIndex;
2095         begin
2096                 New(FIndex);
2097                 FIndex.FIndexFrom       := IndexFrom;
2098                 FIndex.FIndexTo         := IndexTo;
2099                 FIndex.FNo                               := No;
2100                 List.Add(FIndex);
2101         end;
2102         function ChooseString(const Text, Separator: string; Index: integer): string;
2103         var
2104                 S : string;
2105                 i, p : integer;
2106         begin
2107                 S :=    Text;
2108                 for i :=        0 to    Index - 1 do    begin
2109                         if      (AnsiPos(Separator, S) = 0) then        S :=    ''
2110                         else    S :=    Copy(S, AnsiPos(Separator, S) + Length(Separator), Length(S));
2111                 end;
2112                 p :=    AnsiPos(Separator, S);
2113                 if      (p > 0) then    Result  :=      Copy(S, 1, p - 1) else Result :=        S;
2114         end;
2115 begin
2116         { v1.0 b2 - 03 }
2117         s        :=     Body;
2118         r        :=     Body;
2119         i        :=     1;
2120         sw      :=      False;
2121         No      :=      '';
2122         List:=  TList.Create;
2123         oc      :=      '';
2124         sp      :=      0;
2125         chk :=  False;
2126         al      :=      False;
2127         while true      do      begin
2128                 b :=    ByteType(s, i);
2129                 case    b of
2130                         mbSingleByte    : begin
2131                                 if      (not sw) and (Copy(s,i,8) = GT + GT) then       begin
2132                                         if      (AnsiPos('<A HREF', AnsiUpperCase(oc)) = 0) then        begin
2133                                                 sw      :=      True;
2134                                                 sp      :=      i;
2135                                                 i :=    i + 7;
2136                                                 oc:='';
2137                                                 chk :=  True;
2138                                         end;
2139                                 end else
2140                                 if      (not sw) and (Copy(s,i,8) = GT + GT) then       begin
2141                                         if      (AnsiPos('<A HREF', AnsiUpperCase(oc)) = 1) then        begin
2142                                                 i :=    i + 7;
2143                                                 oc:='';
2144                                                 chk :=  True;
2145                                         end;
2146                                 end else
2147                                 if      (not sw) and (Copy(s,i,4) = GT) then    begin
2148                                         if      (AnsiPos('<A HREF', AnsiUpperCase(oc)) = 0) then        begin
2149                                                 sw      :=      True;
2150                                                 sp      :=      i;
2151                                                 i :=    i + 3;
2152                                                 oc:='';
2153                                                 chk :=  True;
2154                                         end;
2155                                 end else
2156                                 if      ((not sw) and (Copy(s,i,1) = ',')) or
2157                                                 ((not sw) and (Copy(s,i,1) = '=')) then begin
2158                                         if      ((not Chk) and (AnsiLowerCase(oc) = '</a>')) or
2159                                                         ((Chk) and      (oc = '')) or
2160                                                         ((not Chk) and (al)) then
2161                                         begin
2162                                                 sw      :=      True;
2163                                                 sp      :=      i;
2164                                                 //i :=  i + 1;
2165                                                 oc:='';
2166                                         end;
2167                                 end else
2168                                 if      (sw) then begin
2169                                         sx      :=      Copy(s,i,1);
2170                                         if      (AnsiPos(sx, SN) > 0)   then    begin
2171                                                 No      :=      No      + sx;
2172                                         end else begin
2173                                                 if      (No <> '') and (No <> '-')       then   begin
2174                                                         Add(sp, i, No);
2175                                                         al := True;
2176                                                 end;
2177                                                 sw      :=      False;
2178                                                 //
2179                                                 i := i - 1;
2180                                                 //
2181                                                 No      := '';
2182                                                 oc:='';
2183                                                 //chk :=        False;
2184                                         end;
2185                                 end else begin
2186                                         if      Copy(s,i,1) = '<' then  oc      :=      '';
2187                                         oc      :=      oc + Copy(s,i,1);
2188                                         chk :=  False;
2189                                         al      :=      False;
2190                                 end;
2191                         end;
2192                         mbLeadByte      : begin
2193                                 if      (not sw) and (Copy(s,i,4) = '\81\84\81\84') then        begin
2194                                         sw      :=      True;
2195                                         sp      :=      i;
2196                                         i :=    i + 3;
2197                                         chk :=  True;
2198                                 end else
2199                                 if      (not sw) and (Copy(s,i,2) = '\81\84') then  begin
2200                                         sw      :=      True;
2201                                         sp      :=      i;
2202                                         i :=    i + 1;
2203                                         chk :=  True;
2204                                 end else
2205                                 if      (sw) then begin
2206                                         sx      :=      Copy(s,i,2);
2207                                         if      (AnsiPos(sx, ZN) > 0)   then    begin
2208                                                 No      :=      No      + ZenToHan(sx);
2209                                         end else begin
2210                                                 if      (No <> '') and (No <> '-')      and (No <> '\81|') then   begin
2211                                                         Add(sp, i, No);
2212                                                 end;
2213                                                 sw      :=      False;
2214                                                 i := i - 1;
2215                                                 No      :=      '';
2216                                         end;
2217                                 end else begin
2218                                         oc      :=      '';
2219                                         chk :=  False;
2220                                 end;
2221                                 al      :=      False;
2222                         end;
2223                 end;
2224                 inc(i);
2225                 if      (i > Length(Body))      then    begin
2226                         if      (sw)    then    begin
2227                                 if      (No <> '')      then    Add(sp, i, No);
2228                         end;
2229                         Break;
2230                 end;
2231         end;
2232         for i :=        List.Count - 1  downto  0 do    begin
2233         //plName := Copy(PluginName, LastDelimiter('\',PluginName) + 1, Length(PluginName) - LastDelimiter('/',PluginName) -1 );
2234                 if      (AnsiPos('-', PIndex(List[i]).FNo) > 0) then    begin
2235                         st      :=      ChooseString(PIndex(List[i]).FNo, '-', 0);
2236                         et      :=      ChooseString(PIndex(List[i]).FNo, '-', 1);
2237                 end else begin
2238                         st      :=      PIndex(List[i]).FNo;
2239                         et      :=      PIndex(List[i]).FNo;
2240                 end;
2241                 r :=    Copy(r,0, PIndex(List[i]).FIndexFrom - 1) +
2242                                         Format('<a href="%s&%s=%s&%s=%s&%s=%s" target="_blank">',
2243                                                                 [FullURL, ParamStart, st, ParamTo, et, ParamNoFirst, ParamTrue]) +
2244                                         Copy(r,PIndex(List[i]).FIndexFrom, PIndex(List[i]).FIndexTo - PIndex(List[i]).FIndexFrom) + '</A>' +
2245                                         Copy(r,PIndex(List[i]).FIndexTo,Length(r));
2246                 Dispose(PIndex(List[i]));
2247         end;
2248         List.Free;
2249         Result  :=      r;
2250 end;
2251
2252
2253 function TGikoSys.BoolToInt(b: Boolean): Integer;
2254 begin
2255         Result := IfThen(b, 1, 0);
2256 end;
2257
2258 function TGikoSys.IntToBool(i: Integer): Boolean;
2259 begin
2260         Result := i = 1;
2261 end;
2262
2263 //gzip\82Å\88³\8fk\82³\82ê\82½\82Ì\82ð\96ß\82·
2264 function TGikoSys.GzipDecompress(ResStream: TStream; ContentEncoding: string): string;
2265 const
2266         BUF_SIZE = 4096;
2267 var
2268         GZipStream: TGzipDecompressStream;
2269         TextStream: TStringStream;
2270         buf: array[0..BUF_SIZE - 1] of Byte;
2271         cnt: Integer;
2272         s: string;
2273         i: Integer;
2274 begin
2275         Result := '';
2276         TextStream := TStringStream.Create('');
2277         try
2278 //\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¢)
2279 //              if LowerCase(Trim(ContentEncoding)) = 'gzip' then begin
2280                 if AnsiPos('gzip', LowerCase(Trim(ContentEncoding))) > 0 then begin
2281                         ResStream.Position := 0;
2282                         GZipStream := TGzipDecompressStream.Create(TextStream);
2283                         try
2284                                 repeat
2285                                         FillChar(buf, BUF_SIZE, 0);
2286                                         cnt := ResStream.Read(buf, BUF_SIZE);
2287                                         if cnt > 0 then
2288                                                 GZipStream.Write(buf, BUF_SIZE);
2289                                 until cnt = 0;
2290                         finally
2291                                 GZipStream.Free;
2292                         end;
2293                 end else begin
2294                         ResStream.Position := 0;
2295                         repeat
2296                                 FillChar(buf, BUF_SIZE, 0);
2297                                 cnt := ResStream.Read(buf, BUF_SIZE);
2298                                 if cnt > 0 then
2299                                         TextStream.Write(buf, BUF_SIZE);
2300                         until cnt = 0;
2301                 end;
2302
2303                 //NULL\95\8e\9a\82ð"*"\82É\82·\82é
2304                 s := TextStream.DataString;
2305                 i := Length(s);
2306                 while (i > 0) and (s[i] = #0) do
2307                         Dec(i);
2308                 s := Copy(s, 1, i);
2309
2310                 i := Pos(#0, s);
2311                 while i <> 0 do begin
2312                         s[i] := '*';
2313                         i := Pos(#0, s);
2314                 end;
2315                 Result := s;
2316         finally
2317                 TextStream.Free;
2318         end;
2319 end;
2320
2321 procedure TGikoSys.LoadKeySetting(ActionList: TActionList);
2322 const
2323         STD_SEC = 'KeySetting';
2324 var
2325         i: Integer;
2326         ini: TMemIniFile;
2327         ActionName: string;
2328         ActionKey: Integer;
2329         SecList: TStringList;
2330         Component: TComponent;
2331 begin
2332         if not FileExists(GetConfigDir + KEY_SETTING_FILE_NAME) then
2333                 Exit;
2334         SecList := TStringList.Create;
2335         ini := TMemIniFile.Create(GetConfigDir + KEY_SETTING_FILE_NAME);
2336         try
2337                 ini.ReadSection(STD_SEC, SecList);
2338                 for i := 0 to SecList.Count - 1 do begin
2339                         ActionName := SecList[i];
2340                         ActionKey := ini.ReadInteger(STD_SEC, ActionName, -1);
2341                         if ActionKey <> -1 then begin
2342                                 Component := ActionList.Owner.FindComponent(ActionName);
2343                                 if TObject(Component) is TAction then begin
2344                                         TAction(Component).ShortCut := ActionKey;
2345                                 end;
2346                         end;
2347                 end;
2348         finally
2349                 ini.Free;
2350                 SecList.Free;
2351         end;
2352 end;
2353
2354 procedure TGikoSys.SaveKeySetting(ActionList: TActionList);
2355 const
2356         STD_SEC = 'KeySetting';
2357 var
2358         i: Integer;
2359         ini: TMemIniFile;
2360 begin
2361         ini := TMemIniFile.Create(GetConfigDir + KEY_SETTING_FILE_NAME);
2362         try
2363                 for i := 0 to ActionList.ActionCount - 1 do begin
2364                         if ActionList.Actions[i].Tag = -1 then
2365                                 Continue;
2366                         ini.WriteInteger(STD_SEC, ActionList.Actions[i].Name, TAction(ActionList.Actions[i]).ShortCut);
2367                 end;
2368                 ini.UpdateFile;
2369         finally
2370                 ini.Free;
2371         end;
2372 end;
2373
2374 procedure TGikoSys.LoadEditorKeySetting(ActionList: TActionList);
2375 const
2376         STD_SEC = 'KeySetting';
2377 var
2378         i: Integer;
2379         ini: TMemIniFile;
2380         ActionName: string;
2381         ActionKey: Integer;
2382         SecList: TStringList;
2383         Component: TComponent;
2384 begin
2385         if not FileExists(GetConfigDir + EKEY_SETTING_FILE_NAME) then
2386                 Exit;
2387         SecList := TStringList.Create;
2388         ini := TMemIniFile.Create(GetConfigDir + EKEY_SETTING_FILE_NAME);
2389         try
2390                 ini.ReadSection(STD_SEC, SecList);
2391                 for i := 0 to SecList.Count - 1 do begin
2392                         ActionName := SecList[i];
2393                         ActionKey := ini.ReadInteger(STD_SEC, ActionName, -1);
2394                         if ActionKey <> -1 then begin
2395                                 Component := ActionList.Owner.FindComponent(ActionName);
2396                                 if TObject(Component) is TAction then begin
2397                                         TAction(Component).ShortCut := ActionKey;
2398                                 end;
2399                         end;
2400                 end;
2401         finally
2402                 ini.Free;
2403                 SecList.Free;
2404         end;
2405 end;
2406
2407 procedure TGikoSys.SaveEditorKeySetting(ActionList: TActionList);
2408 const
2409         STD_SEC = 'KeySetting';
2410 var
2411         i: Integer;
2412         ini: TMemIniFile;
2413 begin
2414         ini := TMemIniFile.Create(GetConfigDir + EKEY_SETTING_FILE_NAME);
2415         try
2416                 for i := 0 to ActionList.ActionCount - 1 do begin
2417                         if ActionList.Actions[i].Tag = -1 then
2418                                 Continue;
2419                         ini.WriteInteger(STD_SEC, ActionList.Actions[i].Name, TAction(ActionList.Actions[i]).ShortCut);
2420                 end;
2421                 ini.UpdateFile;
2422         finally
2423                 ini.Free;
2424         end;
2425 end;
2426
2427 //
2428 procedure TGikoSys.CreateProcess(const AppPath: string; const Param: string);
2429 var
2430         PI: TProcessInformation;
2431         SI: TStartupInfo;
2432         Path: string;
2433 begin
2434         Path := '"' + AppPath + '"';
2435         if Param <> '' then
2436                 Path := Path + ' ' + Param;
2437
2438         SI.Cb := SizeOf(Si);
2439         SI.lpReserved   := nil;
2440         SI.lpDesktop     := nil;
2441         SI.lpTitle               := nil;
2442         SI.dwFlags               := 0;
2443         SI.cbReserved2 := 0;
2444         SI.lpReserved2 := nil;
2445         SI.dwysize               := 0;
2446         Windows.CreateProcess(nil,
2447                                                                 PChar(Path),
2448                                                                 nil,
2449                                                                 nil,
2450                                                                 False,
2451                                                                 0,
2452                                                                 nil,
2453                                                                 nil,
2454                                                                 SI,
2455                                                                 PI);
2456 end;
2457
2458 procedure TGikoSys.OpenBrowser(URL: string; BrowserType: TGikoBrowserType);
2459 begin
2460         case BrowserType of
2461                 gbtIE:
2462                         HlinkNavigateString(nil, PWideChar(WideString(URL)));
2463                 gbtUserApp, gbtAuto:
2464                         if (Setting.URLApp) and (FileExists(Setting.URLAppFile)) then
2465                                 GikoSys.CreateProcess(Setting.URLAppFile, URL)
2466                         else
2467                                 HlinkNavigateString(nil, PWideChar(WideString(URL)));
2468         end;
2469 end;
2470
2471 function TGikoSys.HTMLDecode(const AStr: String): String;
2472 var
2473         Sp, Rp, Cp, Tp: PChar;
2474         S: String;
2475         I, Code: Integer;
2476         Num: Boolean;
2477 begin
2478         SetLength(Result, Length(AStr));
2479         Sp := PChar(AStr);
2480         Rp := PChar(Result);
2481         //Cp := Sp;
2482         try
2483                 while Sp^ <> #0 do begin
2484                         case Sp^ of
2485                                 '&': begin
2486                                                          //Cp := Sp;
2487                                                          Inc(Sp);
2488                                                          case Sp^ of
2489                                                                  'a': if AnsiStrPos(Sp, 'amp;') = Sp then
2490                                                                                         begin
2491                                                                                                 Inc(Sp, 3);
2492                                                                                                 Rp^ := '&';
2493                                                                                         end;
2494                                                                  'l',
2495                                                                  'g': if (AnsiStrPos(Sp, 'lt;') = Sp) or (AnsiStrPos(Sp, 'gt;') = Sp) then
2496                                                                                         begin
2497                                                                                                 Cp := Sp;
2498                                                                                                 Inc(Sp, 2);
2499                                                                                                 while (Sp^ <> ';') and (Sp^ <> #0) do
2500                                                                                                         Inc(Sp);
2501                                                                                                 if Cp^ = 'l' then
2502                                                                                                         Rp^ := '<'
2503                                                                                                 else
2504                                                                                                         Rp^ := '>';
2505                                                                                         end;
2506                                                                  'q': if AnsiStrPos(Sp, 'quot;') = Sp then
2507                                                                                         begin
2508                                                                                                 Inc(Sp,4);
2509                                                                                                 Rp^ := '"';
2510                                                                                         end;
2511                                                                  '#': begin
2512                                                                                                 Tp := Sp;
2513                                                                                                 Inc(Tp);
2514                                                                                                 Num := IsNumeric(Copy(Tp, 1, 1));
2515                                                                                                 while (Sp^ <> ';') and (Sp^ <> #0) do begin
2516                                                                                                         if (Num) and (not IsNumeric(Copy(Sp, 1, 1))) then
2517                                                                                                                 Break;
2518                                                                                                         Inc(Sp);
2519                                                                                                 end;
2520                                                                                                 SetString(S, Tp, Sp - Tp);
2521                                                                                                 Val(S, I, Code);
2522                                                                                                 Rp^ := Chr((I));
2523                                                                                         end;
2524                                                          //      else
2525                                                                          //raise EConvertError.CreateFmt(sInvalidHTMLEncodedChar,
2526                                                                                  //[Cp^ + Sp^, Cp - PChar(AStr)])
2527                                                          end;
2528                                          end
2529                         else
2530                                 Rp^ := Sp^;
2531                         end;
2532                         Inc(Rp);
2533                         Inc(Sp);
2534                 end;
2535         except
2536 //              on E:EConvertError do
2537 //                      raise EConvertError.CreateFmt(sInvalidHTMLEncodedChar,
2538 //                              [Cp^ + Sp^, Cp - PChar(AStr)])
2539         end;
2540         SetLength(Result, Rp - PChar(Result));
2541 end;
2542
2543 function TGikoSys.GetHRefText(s: string): string;
2544 var
2545         Index: Integer;
2546         Index2: Integer;
2547 begin
2548         Result := '';
2549         s := Trim(s);
2550         if s = '' then
2551                 Exit;
2552
2553         Index := AnsiPos('href', LowerCase(s));
2554         if Index = 0 then
2555                 Exit;
2556         s := Trim(Copy(s, Index + 4, Length(s)));
2557         s := Trim(Copy(s, 2, Length(s)));
2558
2559         //\8en\82ß\82Ì\95\8e\9a\82ª'"'\82È\82ç\8eæ\82è\8f\9c\82­
2560         //if Copy(s, 1, 1) = '"' then begin
2561     if s[1]  = '"' then begin
2562                 s := Trim(Copy(s, 2, Length(s)));
2563         end;
2564
2565         Index := AnsiPos('"', s);
2566         if Index <> 0 then begin
2567                 //'"'\82Ü\82ÅURL\82Æ\82·\82é
2568                 s := Copy(s, 1, Index - 1);
2569         end else begin
2570                 //'"'\82ª\96³\82¯\82ê\82Î\83X\83y\81[\83X\82©">"\82Ì\91\81\82¢\95û\82Ü\82Å\82ðURL\82Æ\82·\82é
2571                 Index := AnsiPos(' ', s);
2572                 Index2 := AnsiPos('>', s);
2573                 if Index = 0 then
2574                         Index := Index2;
2575                 if Index > Index2 then
2576                         Index := Index2;
2577                 if Index <> 0 then
2578                         s := Copy(s, 1, Index - 1)
2579                 else
2580                         //\82±\82ê\88È\8fã\82à\82¤\92m\82ç\82ñ\82Ê
2581                         ;
2582         end;
2583         Result := Trim(s);
2584 end;
2585
2586 //\83z\83X\83g\96¼\82ª\82Q\82\83\82\88\82©\82Ç\82¤\82©\83`\83F\83b\83N\82·\82é
2587 function TGikoSys.Is2chHost(Host: string): Boolean;
2588 const
2589         HOST_NAME: array[0..1] of string = ('2ch.net', 'bbspink.com');
2590 var
2591         i: Integer;
2592 //      Len: Integer;
2593 begin
2594         Result := False;
2595         if RightStr( Host, 1 ) = '/' then
2596                 Host := Copy( Host, 1, Length( Host ) - 1 );
2597         OutputDebugString(pchar(HOST_NAME[0]));
2598         for i := 0 to Length(HOST_NAME) - 1 do begin
2599 //              Len := Length(HOST_NAME[i]);
2600                 if AnsiPos(HOST_NAME[i], Host) = (Length(Host) - Length(HOST_NAME[i]) + 1) then begin
2601                         Result := True;
2602                         Exit;
2603                 end;
2604         end;
2605 end;
2606
2607 function TGikoSys.Parse2chURL(const url: string; const path: string; const document: string; var BBSID: string; var BBSKey: string): Boolean;
2608 var
2609         Index: Integer;
2610         s: string;
2611         SList: TStringList;
2612 begin
2613         BBSID := '';
2614         BBSKey := '';
2615         Result := False;
2616
2617         Index := AnsiPos(READ_PATH, path);
2618         if Index <> 0 then begin
2619                 s := Copy(path, Length(READ_PATH) + 1, Length(path));
2620                 BBSID := GetTokenIndex(s, '/', 0);
2621                 BBSKey := GetTokenIndex(s, '/', 1);
2622                 if BBSKey = '' then
2623                         BBSKey := Document;
2624                 Result := (BBSID <> '') or (BBSKey <> '');
2625                 Exit;
2626         end;
2627         Index := AnsiPos(KAKO_PATH, path);
2628         if Index <> 0 then begin
2629                 s := Copy(path, 2, Length(path));
2630                 BBSID := GetTokenIndex(s, '/', 0);
2631                 if (BBSID = 'log') and (GetTokenIndex(s, '/', 2) = 'kako') then
2632                         BBSID := GetTokenIndex(s, '/', 1);
2633                 BBSKey := ChangeFileExt(Document, '');
2634                 Result := (BBSID <> '') or (BBSKey <> '');
2635                 Exit;
2636         end;
2637         Index := AnsiPos('read.cgi?', URL);
2638         if Index <> 0 then begin
2639                 SList := TStringList.Create;
2640                 try
2641                         try
2642 //                              s := HTMLDecode(Document);
2643                                 ExtractHTTPFields(['?', '&'], [], PChar(URL), SList, False);
2644                                 BBSID := SList.Values['bbs'];
2645                                 BBSKey := SList.Values['key'];
2646                                 Result := (BBSID <> '') or (BBSKey <> '');
2647                                 Exit;
2648                         except
2649                                 Exit;
2650                         end;
2651                 finally
2652                         SList.Free;
2653                 end;
2654         end;
2655 end;
2656 procedure TGikoSys.GetPopupResNumber(URL : string; var stRes, endRes : Int64);
2657 var
2658     buf : String;
2659     convBuf : String;
2660     ps : Int64;
2661     pch : PChar;
2662 begin
2663         URL := Trim(LowerCase(URL));
2664     if (AnsiPos('&st=', URL ) <> 0) and ( AnsiPos( '&to=',URL) <> 0 ) then begin
2665         try
2666             stRes := StrToInt64( Copy( URL, AnsiPos('&st=', URL ) + 4, AnsiPos( '&to=',URL) - AnsiPos('&st=', URL ) - 4 ) );
2667             if AnsiPos( '&nofirst=',URL) <> 0 then begin
2668                 buf := Copy( URL, AnsiPos('&to=', URL ) + 4, AnsiPos( '&nofirst=',URL) - AnsiPos('&to=', URL ) - 4);
2669             end else begin
2670                 buf := Copy( URL, AnsiPos('&to=', URL ) + 4, Length( URL ) - AnsiPos('&to=', URL ) - 4 + 1 );
2671                 ps := 0;
2672                 pch := PChar(buf);
2673                 while  ( ps < Length(buf) )and ( pch[ps] >= '0' ) and ( pch[ps] <= '9' ) do Inc(ps);
2674                 buf := Copy( buf, 1, ps );
2675             end;
2676             try
2677                 if buf <> '' then
2678                     endRes := StrToInt64(buf);
2679             except
2680                 endRes := 0;
2681             end;
2682         except
2683             stRes := 0;
2684         end;
2685         GikoSys.GetBrowsableThreadURL( URL );
2686     end else if( AnsiPos('&res=', URL ) <> 0 ) then begin
2687         endRes := 0;
2688         buf := Copy( URL, AnsiPos('&res=', URL ) + 5, Length( URL ) - AnsiPos('&res=', URL ) - 5 + 1 );
2689         ps := 0;
2690         pch := PChar(buf);
2691         while  ( ps < Length(buf) )and ( pch[ps] >= '0' ) and ( pch[ps] <= '9' ) do Inc(ps);
2692         buf := Copy( buf, 1, ps );
2693         try
2694             if buf <> '' then
2695                 stRes := StrToInt(buf)
2696             else begin
2697                 stRes := 0;
2698             end;
2699         except
2700             stRes := 0;
2701         end;
2702     end else if (AnsiPos('&start=', URL ) <> 0) and ( AnsiPos( '&end=',URL) <> 0 ) then begin
2703         try
2704             stRes := StrToInt64( Copy( URL, AnsiPos('&start=', URL ) + 7, AnsiPos( '&end=',URL) - AnsiPos('&start=', URL ) - 7 ) );
2705             if AnsiPos( '&nofirst=',URL) <> 0 then begin
2706                 buf := Copy( URL, AnsiPos('&end=', URL ) + 5, AnsiPos( '&nofirst=',URL) - AnsiPos('&end=', URL ) - 5);
2707             end else begin
2708                 buf := Copy( URL, AnsiPos('&end=', URL ) + 5, Length( URL ) - AnsiPos('&to=', URL ) - 5 + 1 );
2709                 ps := 0;
2710                 pch := PChar(buf);
2711                 while  ( ps < Length(buf) )and ( pch[ps] >= '0' ) and ( pch[ps] <= '9' ) do Inc(ps);
2712                 buf := Copy( buf, 1, ps );
2713             end;
2714             try
2715                 if buf <> '' then
2716                     endRes := StrToInt64(buf);
2717             except
2718                 endRes := 0;
2719             end;
2720         except
2721             stRes := 0;
2722         end;
2723     end else if ( AnsiPos('.html',URL) <> Length(URL) -4 ) and ( AnsiPos('.htm',URL) <> Length(URL) -3 ) then begin
2724         buf := Copy(URL, LastDelimiter('/',URL)+1,Length(URL)-LastDelimiter('/',URL)+1);
2725         if  Length(buf) > 0 then begin
2726             ps := 0;
2727             pch := PChar(buf);
2728             while  ( ps < Length(buf) )and ( pch[ps] >= '0' ) and ( pch[ps] <= '9' ) do Inc(ps);
2729             try
2730                 convBuf := Copy( buf, 1, ps );
2731                 if convBuf <> '' then begin
2732                     stRes := StrToInt64(convBuf);
2733                     Delete(buf,1,ps+1);
2734                     ps := 0;
2735                     pch := PChar(buf);
2736                     while  ( ps < Length(buf) )and ( pch[ps] >= '0' ) and ( pch[ps] <= '9' ) do Inc(ps);
2737                     try
2738                         convBuf := Copy( buf, 1, ps );
2739                         if convBuf <> '' then
2740                             endRes := StrToInt64(convBuf)
2741                         else
2742                             endRes := 0;
2743                     except
2744                         endRes := 0;
2745                     end;
2746                 end else begin
2747                     stRes := 0;
2748                 end;
2749
2750             except
2751                 stRes := 0;
2752                 endRes := 0;
2753             end;
2754
2755         end;
2756     end else begin
2757             //stRes := 0;
2758         //endRes := 0;
2759     end;
2760 end;
2761
2762 function TGikoSys.Parse2chURL2(URL: string): TPathRec;
2763 var
2764         i: Integer;
2765         s: string;
2766 //    buf : String;
2767 //    convBuf : String;
2768         wk: string;
2769         wkMin: Integer;
2770         wkMax: Integer;
2771         wkInt: Integer;
2772         RStart: Integer;
2773         RLength: Integer;
2774 //    ps : Integer;
2775 //    pch : PChar;
2776         SList: TStringList;
2777 begin
2778         URL := Trim(LowerCase(URL));
2779         Result.FBBS := '';
2780         Result.FKey := '';
2781         Result.FSt := 0;
2782         Result.FTo := 0;
2783         Result.FFirst := False;
2784         Result.FStBegin := False;
2785         Result.FToEnd := False;
2786         Result.FDone := False;
2787
2788         wkMin := 0;
2789         wkMax := 1;
2790     if URL[length(URL)] = '\' then
2791         URL := URL + 'n';
2792         FAWKStr.RegExp := 'http://.+\.(2ch\.net|bbspink\.com)/';
2793         if FAWKStr.Match(FAWKStr.ProcessEscSeq(URL), RStart, RLength) <> 0 then begin
2794                 s := Copy(URL, RStart + RLength - 1, Length(URL));
2795
2796         //\95W\8f\80\8f\91\8e®
2797         //\8dÅ\8cã\82Íl50, 10, 10-20, 10n, 10-20n, -10, 10-, 10n- \82È\82Ç
2798         //http://xxx.2ch.net/test/read.cgi/bbsid/1000000000/
2799         FAWKStr.RegExp := '/test/read.cgi/.+/[0-9]+/.*';
2800         if FAWKStr.Match(FAWKStr.ProcessEscSeq(s), RStart, RLength) > 0 then begin
2801             s := Copy(s, 15, Length(s));
2802
2803             SList := TStringList.Create;
2804             try
2805                 SList.Clear;
2806                 FAWKStr.RegExp := '/';
2807                 if FAWKStr.Split(FAWKStr.ProcessEscSeq(s), SList) >= 2 then begin
2808                     Result.FBBS := SList[1];
2809                     Result.FKey := SList[2];
2810                     if SList.Count >= 3 then
2811                         s := SList[3]
2812                     else
2813                         s := '';
2814                 end else
2815                     Exit;
2816
2817                 SList.Clear;
2818                 FAWKStr.LineSeparator := mcls_CRLF;
2819                 FAWKStr.RegExp := '-';
2820                 if FAWKStr.Split(FAWKStr.ProcessEscSeq(s), SList) = 0 then begin
2821                     Result.FFirst := True;
2822                 end else begin
2823                     FAWKStr.RegExp := 'l[0-9]+';
2824                     if FAWKStr.Match(FAWKStr.ProcessEscSeq(s), RStart, RLength) > 0 then begin
2825                         Result.FFirst := True;
2826                     end else begin
2827                         for i := 0 to SList.Count - 1 do begin
2828                             if Trim(SList[i]) = '' then begin
2829                                 if i = 0 then
2830                                     Result.FStBegin := True;
2831                                 if i = (SList.Count - 1) then
2832                                     Result.FToEnd := True;
2833                             end else if IsNumeric(SList[i]) then begin
2834                                 wkInt := StrToInt(SList[i]);
2835                                 wkMax := Max(wkMax, wkInt);
2836                                 if wkMin = 0 then
2837                                     wkMin := wkInt
2838                                 else
2839                                     wkMin := Min(wkMin, wkInt);
2840                             end else if Trim(SList[i]) = 'n' then begin
2841                                 Result.FFirst := True;
2842                             end else begin
2843                                 FAWKStr.RegExp := '^n[0-9]+$|^[0-9]+n$';
2844                                 if FAWKStr.Match(FAWKStr.ProcessEscSeq(SList[i]), RStart, RLength) > 0 then begin
2845                                     if Copy(SList[i], 1, 1) = 'n' then
2846                                         wkInt := StrToInt(Copy(SList[i], 2, Length(SList[i])))
2847                                     else
2848                                         wkInt := StrToInt(Copy(SList[i], 1, Length(SList[i]) - 1));
2849                                     Result.FFirst := True;
2850                                     wkMax := Max(wkMax, wkInt);
2851                                     if wkMin = 1 then
2852                                         wkMin := wkInt
2853                                     else
2854                                         wkMin := Min(wkMin, wkInt);
2855                                 end;
2856                             end;
2857                         end;
2858                         if Result.FStBegin and (not Result.FToEnd) then
2859                             Result.FSt := wkMin
2860                         else if (not Result.FStBegin) and Result.FToEnd then
2861                             Result.FTo := wkMax
2862                         else if (not Result.FStBegin) and (not Result.FToEnd) then begin
2863                             Result.FSt := wkMin;
2864                             Result.FTo := wkMax;
2865                         end;
2866                         //Result.FSt := wkMin;
2867                         //Result.FTo := wkMax;
2868                     end;
2869                 end;
2870             finally
2871                 SList.Free;
2872             end;
2873             Result.FDone := True;
2874             Exit;
2875         end;
2876
2877         //\90Vkako\8f\91\8e®
2878         //http://server.2ch.net/ITA_NAME/kako/1000/10000/1000000000.html
2879         FAWKStr.RegExp := '/.+/kako/[0-9]+/[0-9]+/[0-9]+\.html';
2880         if FAWKStr.Match(FAWKStr.ProcessEscSeq(s), RStart, RLength) > 0 then begin
2881             SList := TStringList.Create;
2882             try
2883                 SList.Clear;
2884                 FAWKStr.RegExp := '/';
2885                 if FAWKStr.Split(FAWKStr.ProcessEscSeq(s), SList) >= 6 then begin
2886                     Result.FBBS := SList[1];
2887                     Result.FKey := ChangeFileExt(SList[5], '');
2888                     Result.FFirst := True;
2889                 end else
2890                     Exit;
2891             finally
2892                 SList.Free;
2893             end;
2894             Result.FDone := True;
2895             Exit;
2896         end;
2897
2898         //\8b\8ckako\8f\91\8e®
2899         //http://server.2ch.net/ITA_NAME/kako/999/999999999.html
2900         FAWKStr.RegExp := '/.+/kako/[0-9]+/[0-9]+\.html';
2901         if FAWKStr.Match(FAWKStr.ProcessEscSeq(s), RStart, RLength) > 0 then begin
2902             SList := TStringList.Create;
2903             try
2904                 SList.Clear;
2905                 FAWKStr.RegExp := '/';
2906                 if FAWKStr.Split(FAWKStr.ProcessEscSeq(s), SList) >= 5 then begin
2907                     Result.FBBS := SList[1];
2908                     Result.FKey := ChangeFileExt(SList[4], '');
2909                     Result.FFirst := True;
2910                 end else
2911                     Exit;
2912             finally
2913                 SList.Free;
2914             end;
2915             Result.FDone := True;
2916             Exit;
2917         end;
2918
2919         //log\8by\82Ñlog2\8f\91\8e®
2920         //http://server.2ch.net/log/ITA_NAME/kako/999/999999999.html
2921         //http://server.2ch.net/log2/ITA_NAME/kako/999/999999999.html
2922         FAWKStr.RegExp := '/log2?/.+/kako/[0-9]+/[0-9]+\.html';
2923         if FAWKStr.Match(FAWKStr.ProcessEscSeq(s), RStart, RLength) > 0 then begin
2924             SList := TStringList.Create;
2925             try
2926                 SList.Clear;
2927                 FAWKStr.RegExp := '/';
2928                 if FAWKStr.Split(FAWKStr.ProcessEscSeq(s), SList) >= 6 then begin
2929                     Result.FBBS := SList[2];
2930                     Result.FKey := ChangeFileExt(SList[5], '');
2931                     Result.FFirst := True;
2932                 end else
2933                     Exit;
2934             finally
2935                 SList.Free;
2936             end;
2937             Result.FDone := True;
2938             Exit;
2939         end;
2940
2941
2942         //\8b\8cURL\8f\91\8e®
2943         //http://server.2ch.net/test/read.cgi?bbs=ITA_NAME&key=1000000000&st=1&to=5&nofirst=true
2944         FAWKStr.RegExp := '/test/read\.cgi\?';
2945         if FAWKStr.Match(FAWKStr.ProcessEscSeq(s), RStart, RLength) > 0 then begin
2946             s := Copy(s, 16, Length(s));
2947             SList := TStringList.Create;
2948             try
2949                 SList.Clear;
2950                 FAWKStr.RegExp := '&';
2951                 if FAWKStr.Split(FAWKStr.ProcessEscSeq(s), SList) >= 2 then begin
2952                     Result.FFirst := True;
2953                     for i := 0 to SList.Count - 1 do begin
2954                         if Pos('bbs=', SList[i]) = 1 then begin
2955                             Result.FBBS := Copy(SList[i], 5, Length(SList[i]));
2956                         end else if Pos('key=', SList[i]) = 1 then begin
2957                             Result.FKey := Copy(SList[i], 5, Length(SList[i]));
2958                         end else if Pos('st=', SList[i]) = 1 then begin
2959                             wk := Copy(SList[i], 4, Length(SList[i]));
2960                             if IsNumeric(wk) then
2961                                 Result.FSt := StrToInt(wk)
2962                             else if wk = '' then
2963                                 Result.FStBegin := True;
2964                         end else if Pos('to=', SList[i]) = 1 then begin
2965                             wk := Copy(SList[i], 4, Length(SList[i]));
2966                             if IsNumeric(wk) then
2967                                 Result.FTo := StrToInt(wk)
2968                             else if wk = '' then
2969                                 Result.FToEnd := True;
2970                         end else if Pos('nofirst=', SList[i]) = 1 then begin
2971                             Result.FFirst := False;
2972                         end;
2973                     end;
2974                 end else
2975                     Exit;
2976             finally
2977                 SList.Free;
2978             end;
2979
2980             if (Result.FBBS <> '') and (Result.FKey <> '') then begin
2981                 Result.FDone := True;
2982             end;
2983             Exit;
2984         end;
2985     end;
2986 end;
2987
2988 procedure TGikoSys.ParseURI(var URL, Protocol, Host, Path, Document, Port, Bookmark: string);
2989 var
2990         URI: TIdURI;
2991 begin
2992         Protocol := '';
2993         Host := '';
2994         Path := '';
2995         Document := '';
2996         Port := '';
2997         Bookmark := '';
2998         URI := TIdURI.Create(URL);
2999         try
3000                 Protocol := URI.Protocol;
3001                 Host := URI.Host;
3002                 Path := URI.Path;
3003                 Document := URI.Document;
3004                 Port := URI.Port;
3005                 Bookmark := URI.Bookmark;
3006         finally
3007                 URI.Free;
3008         end;
3009 end;
3010
3011 function TGikoSys.GetVersionBuild: Integer;
3012 var
3013         FixedFileInfo: PVSFixedFileInfo;
3014         VersionHandle, VersionSize: DWORD;
3015         pVersionInfo: Pointer;
3016         ItemLen : UInt;
3017         AppFile: string;
3018 begin
3019         Result := 0;
3020         AppFile := Application.ExeName;
3021         VersionSize := GetFileVersionInfoSize(pChar(AppFile), VersionHandle);
3022         if VersionSize = 0 then
3023                 Exit;
3024         GetMem(pVersionInfo, VersionSize);
3025         try
3026                 if GetFileVersionInfo(PChar(AppFile),VersionHandle,VersionSize, pVersionInfo) then
3027                         if VerQueryValue(pVersionInfo, '\', Pointer(FixedFileInfo), ItemLen) then
3028                                 Result := LOWORD(FixedFileInfo^.dwFileVersionLS);
3029         finally
3030                 FreeMem(pVersionInfo, VersionSize);
3031         end;
3032 end;
3033
3034 function        TGikoSys.GetBrowsableThreadURL(
3035         inURL : string
3036 ) : string;
3037 var
3038         threadItem      : TThreadItem;
3039         boardPlugIn     : TBoardPlugIn;
3040         i                                               : Integer;
3041 begin
3042
3043         //===== \83v\83\89\83O\83C\83\93
3044         try
3045                 for i := Length( BoardPlugIns ) - 1 downto 0 do begin
3046                         if Assigned( Pointer( BoardPlugIns[ i ].Module ) ) then begin
3047                                 if BoardPlugIns[ i ].AcceptURL( inURL ) = atThread then begin
3048                                         boardPlugIn := BoardPlugIns[ i ];
3049                                         threadItem      := TThreadItem.Create( boardPlugIn, inURL );
3050                                         Result                  := threadItem.URL;
3051                                         threadItem.Free;
3052
3053                                         Break;
3054                                 end;
3055                         end;
3056                 end;
3057         except
3058                 // exception \82ª\94­\90\82µ\82½\8fê\8d\87\82Í\93à\95\94\8f\88\97\9d\82É\94C\82¹\82½\82¢\82Ì\82Å\82±\82±\82Å\82Í\89½\82à\82µ\82È\82¢
3059         end;
3060
3061         if Length( Result ) = 0 then
3062                 Result := GikoSys.Get2chBrowsableThreadURL( inURL );
3063
3064 end;
3065
3066 function        TGikoSys.GetThreadURL2BoardURL(
3067         inURL : string
3068 ) : string;
3069 var
3070         threadItem      : TThreadItem;
3071         boardPlugIn     : TBoardPlugIn;
3072         i                                               : Integer;
3073 begin
3074
3075         //===== \83v\83\89\83O\83C\83\93
3076         try
3077                 for i := Length( BoardPlugIns ) - 1 downto 0 do begin
3078                         if Assigned( Pointer( BoardPlugIns[ i ].Module ) ) then begin
3079                                 if BoardPlugIns[ i ].AcceptURL( inURL ) = atThread then begin
3080                                         boardPlugIn := BoardPlugIns[ i ];
3081                                         threadItem      := TThreadItem.Create( boardPlugIn, inURL );
3082                                         Result                  := BoardPlugIns[ i ].GetBoardURL( Longword( threadItem ) );
3083                                         threadItem.Free;
3084
3085                                         Break;
3086                                 end;
3087                         end;
3088                 end;
3089         except
3090                 // exception \82ª\94­\90\82µ\82½\8fê\8d\87\82Í\93à\95\94\8f\88\97\9d\82É\94C\82¹\82½\82¢\82Ì\82Å\82±\82±\82Å\82Í\89½\82à\82µ\82È\82¢
3091         end;
3092
3093         if Length( Result ) = 0 then
3094                 Result := GikoSys.Get2chThreadURL2BoardURL( inURL );
3095
3096 end;
3097
3098 function        TGikoSys.Get2chThreadURL2BoardURL(
3099         inURL : string
3100 ) : string;
3101 var
3102         Protocol, Host, Path, Document, Port, Bookmark : string;
3103         BBSID, BBSKey : string;
3104         foundPos                        : Integer;
3105 begin
3106
3107         ParseURI( inURL, Protocol, Host, Path, Document, Port, Bookmark );
3108         Parse2chURL( inURL, Path, Document, BBSID, BBSKey );
3109
3110         foundPos := Pos( '/test/read.cgi', inURL );
3111         if foundPos > 0 then
3112                 Result := Copy( inURL, 1, foundPos ) + BBSID + '/'
3113         else
3114                 Result := Protocol + '://' + Host + '/' + BBSID + '/';
3115
3116 end;
3117
3118 function        TGikoSys.Get2chBrowsableThreadURL(
3119         inURL                   : string
3120 ) : string;
3121 var
3122         Protocol, Host, Path, Document, Port, Bookmark : string;
3123         BBSID, BBSKey : string;
3124         foundPos        : Integer;
3125 begin
3126
3127 //      if Pos( KAKO_PATH, inURL ) > 0 then begin
3128 //              Result := inURL;
3129 //      end else begin
3130                 ParseURI( inURL, Protocol, Host, Path, Document, Port, Bookmark );
3131                 Parse2chURL( inURL, Path, Document, BBSID, BBSKey );
3132                 foundPos := Pos( '/test/read.cgi', inURL ) - 1;
3133
3134                 if Is2chHost( Host ) then begin
3135                         Result := Protocol + '://' + Host +
3136                                 READ_PATH + BBSID + '/' + BBSKey + '/l50';
3137                 end else begin
3138                         if foundPos > 0 then
3139                                 Result := Copy( inURL, 1, foundPos ) +
3140                                         OLD_READ_PATH + 'bbs=' + BBSID + '&key=' + BBSKey + '&ls=50'
3141                         else
3142                                 Result := Protocol + '://' + Host +
3143                                         OLD_READ_PATH + 'bbs=' + BBSID + '&key=' + BBSKey + '&ls=50';
3144                 end;
3145 //      end;
3146
3147 end;
3148
3149 function        TGikoSys.Get2chBoard2ThreadURL(
3150         inBoard : TBoard;
3151         inKey           : string
3152 ) : string;
3153 var
3154         server  : string;
3155 begin
3156
3157         server := UrlToServer( inBoard.URL );
3158         if Is2chHost( server ) then
3159                 Result := server + 'test/read.cgi/' + inBoard.BBSID + '/' + inKey + '/l50'
3160         else
3161                 Result := server + 'test/read.cgi?bbs=' + inBoard.BBSID + '&key=' + inKey + '&ls=50';
3162
3163 end;
3164
3165 (*************************************************************************
3166  *\8b@\94\\96¼\81@\81@\81F\83{\81[\83h\83t\83@\83C\83\8b\97ñ\8b\93
3167  *\89Â\8e\8b\81@\81@\81@\81FPublic
3168  *************************************************************************)
3169 procedure TGikoSys.ListBoardFile;
3170 var
3171         boardFileList   : TStringList;
3172         i, l                                    : Integer;
3173 begin
3174
3175   // BBS \82Ì\8aJ\95ú
3176   try
3177     for i := 0 to Length( BBSs ) - 1 do
3178       BBSs[ i ].Free;
3179   except
3180   end;
3181   SetLength( BBSs, 0 );
3182
3183   l := 0;
3184   // \94Â\83\8a\83X\83g\82Ì\97ñ\8b\93
3185   if FileExists( GikoSys.GetBoardFileName ) then begin
3186     SetLength( BBSs, l + 1 );
3187     BBSs[ l ]                           := TBBS.Create( GikoSys.GetBoardFileName );
3188     BBSs[ l ].Title     := '\82Q\82¿\82á\82ñ\82Ë\82é';
3189                 Inc( l );
3190   end;
3191
3192   if FileExists( GikoSys.GetCustomBoardFileName ) then begin
3193     SetLength( BBSs, l + 1 );
3194     BBSs[ l ]                           := TBBS.Create( GikoSys.GetCustomBoardFileName );
3195     BBSs[ l ].Title     := '\82»\82Ì\91¼';
3196                 Inc( l );
3197   end;
3198
3199   // Board \83t\83H\83\8b\83_
3200   if DirectoryExists( GikoSys.Setting.GetBoardDir ) then begin
3201     BoardFileList := TStringList.Create;
3202     try
3203           GikoSys.GetFileList( GikoSys.Setting.GetBoardDir, '*', BoardFileList, True, True );
3204                         SetLength( BBSs, l + BoardFileList.Count );
3205       for i := BoardFileList.Count - 1 downto 0 do begin
3206         BBSs[ l ]                               := TBBS.Create( BoardFileList[ i ] );
3207         BBSs[ l ].Title := ChangeFileExt( ExtractFileName( BoardFileList[ i ] ), '' );
3208
3209         Inc( l );
3210       end;
3211     finally
3212       BoardFileList.Free;
3213     end;
3214   end;
3215
3216 end;
3217
3218 (*************************************************************************
3219  *\8b@\94\\96¼\81@\81@\81F\83{\81[\83h\83t\83@\83C\83\8b\93Ç\82Ý\8d\9e\82Ý
3220  *\89Â\8e\8b\81@\81@\81@\81FPublic
3221  *************************************************************************)
3222 procedure TGikoSys.ReadBoardFile( bbs : TBBS );
3223 var
3224         idx                                             : Integer;
3225         ini                                             : TMemIniFile;
3226
3227         boardFile                       : TStringList;
3228         CategoryList    : TStringList;
3229         BoardList                       : TStringList;
3230         Category                        : TCategory;
3231         Board                                   : TBoard;
3232         inistr                          : string;
3233         RoundItem                       : TRoundItem;
3234
3235         i, iBound                       : Integer;
3236         j, jBound                       : Integer;
3237         k, kBound                       : Integer;
3238 begin
3239
3240   if not FileExists( bbs.FilePath ) then
3241     Exit;
3242
3243         bbs.Clear;
3244   ini := TMemIniFile.Create('');
3245   boardFile := TStringList.Create;
3246   try
3247     boardFile.LoadFromFile( bbs.FilePath );
3248
3249     ini.SetStrings( boardFile );
3250     CategoryList        := TStringList.Create;
3251     BoardList                   := TStringList.Create;
3252     try
3253       ini.ReadSections( CategoryList );
3254
3255       iBound := CategoryList.Count - 1;
3256       for i := 0 to iBound do begin
3257         ini.ReadSection( CategoryList[i], BoardList );
3258         Category                                := TCategory.Create;
3259         Category.No                     := i + 1;
3260         Category.Title  := CategoryList[i];
3261
3262         jBound := BoardList.Count - 1;
3263         for j := 0 to jBound do begin
3264           Board := nil;
3265           inistr := ini.ReadString(CategoryList[i], BoardList[j], '');
3266
3267           //===== \83v\83\89\83O\83C\83\93
3268           try
3269             kBound := Length( BoardPlugIns ) - 1;
3270             for k := 0 to kBound do begin
3271               if Assigned( Pointer( BoardPlugIns[ k ].Module ) ) then begin
3272                 if BoardPlugIns[ k ].AcceptURL( inistr ) = atBoard then begin
3273                   Board := TBoard.Create( BoardPlugIns[ k ], inistr );
3274
3275                   Break;
3276                 end;
3277               end;
3278             end;
3279           except
3280             // exception \82ª\94­\90\82µ\82½\8fê\8d\87\82Í\93à\95\94\8f\88\97\9d\82É\94C\82¹\82½\82¢\82Ì\82Å\82±\82±\82Å\82Í\89½\82à\82µ\82È\82¢
3281           end;
3282
3283           if Board = nil then
3284             Board := TBoard.Create( nil, inistr );
3285           Board.BeginUpdate;
3286           Board.No := j + 1;
3287           Board.Title := BoardList[j];
3288           Board.RoundDate := ZERO_DATE;
3289
3290           idx := RoundList.Find(Board);
3291           if idx <> -1 then begin
3292             RoundItem                           := RoundList.Items[idx, grtBoard];
3293             Board.Round                 := True;
3294             Board.RoundName     := RoundItem.RoundName;
3295           end;
3296
3297           Category.Add(Board);
3298           Board.LoadSettings;
3299           Board.EndUpdate;
3300         end;
3301
3302         bbs.Add( Category );
3303       end;
3304                         bbs.IsBoardFileRead := True;
3305     finally
3306       BoardList.Free;
3307       CategoryList.Free;
3308     end;
3309   finally
3310     boardFile.Free;
3311     ini.Free;
3312   end;
3313
3314 end;
3315
3316 function        TGikoSys.GetUnknownCategory : TCategory;
3317 const
3318         UNKNOWN_CATEGORY = '(\96¼\8fÌ\95s\96¾)';
3319 begin
3320
3321         if Length( BBSs ) < 2 then begin
3322                 Result := nil;
3323                 Exit;
3324         end;
3325
3326         Result := BBSs[ 1 ].FindCategoryFromTitle( UNKNOWN_CATEGORY );
3327         if Result = nil then begin
3328                 Result                          := TCategory.Create;
3329                 Result.Title    := UNKNOWN_CATEGORY;
3330                 BBSs[ 1 ].Add( Result );
3331         end;
3332
3333 end;
3334
3335 function        TGikoSys.GetUnknownBoard( inPlugIn : TBoardPlugIn; inURL : string ) : TBoard;
3336 var
3337         category : TCategory;
3338 const
3339         UNKNOWN_BOARD = '(\96¼\8fÌ\95s\96¾)';
3340 begin
3341
3342         category := GetUnknownCategory;
3343         if category = nil then begin
3344                 Result := nil;
3345         end else begin
3346                 Result := category.FindBoardFromTitle( UNKNOWN_BOARD );
3347                 if Result = nil then begin
3348                         Result                          := TBoard.Create( inPlugIn, inURL );
3349                         Result.Title    := UNKNOWN_BOARD;
3350                         category.Add( Result );
3351                 end;
3352         end;
3353
3354 end;
3355 function TGikoSys.GetSambaFileName : string;
3356 begin
3357         Result := Setting.GetSambaFileName;
3358 end;
3359 procedure TGikoSys.SambaFileExists();
3360 var
3361         sambaTmp: string;
3362     sambaStrList: TStringList;
3363 begin
3364     if not FileExists(GikoSys.GetSambaFileName) then begin
3365         sambaTmp := ChangeFileExt(GikoSys.GetSambaFileName, '.default');
3366         sambaStrList := TStringList.Create;
3367         try
3368             if FileExists(sambaTmp) then begin
3369                         sambaStrList.LoadFromFile(sambaTmp);
3370                 sambaStrList.SaveToFile(GikoSys.GetSambaFileName);
3371             end;
3372         finally
3373                 sambaStrList.Free;
3374         end;
3375     end;
3376 end;
3377
3378 initialization
3379         GikoSys := TGikoSys.Create;
3380
3381 finalization
3382         if GikoSys <> nil then begin
3383                 GikoSys.Free;
3384                 GikoSys := nil;
3385         end;
3386 end.