OSDN Git Service

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