OSDN Git Service

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