OSDN Git Service

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