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