OSDN Git Service

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