OSDN Git Service

・r 1.35 の遅延読み出しの実装で BBSsFindxxxFromxxx が
[gikonavigoeson/gikonavi.git] / BoardGroup.pas
1 unit BoardGroup;
2
3 interface
4
5 uses
6         Windows, SysUtils, Classes, ComCtrls, IniFiles, {HTTPApp,} YofUtils, IdGlobal,
7         ExternalBoardManager, ExternalBoardPlugInMain, StrUtils, DateUtils;
8
9 type
10         //\83\8a\83X\83g\82Ì\95\\8e¦\83A\83C\83e\83\80\91I\91ð
11         TGikoViewType = (gvtAll, gvtLog, gvtNew, gvtUser);
12         //\83\8a\83X\83g\82Ì\8eæ\93¾\8c\8f\90\94
13         //TGikoListCount = (glc50, glc100, glc200, glc500, glc1000, glcAll);
14         //\8f\84\89ñ\94Ô\8d\86
15         //TGikoRoundNo = (grnNone, grn1, grn2, grn3, grn4, grn5, grnOnce);
16         //\83\8a\83X\83g\82Ì\8fã\82°\89º\82°
17         TGikoAgeSage = (gasNone, gasAge, gasSage, gasNew);
18
19 {       TFolder = class
20         private
21                 FItemList: TList;       //\8eq\83A\83C\83e\83\80\83\8a\83X\83g
22                 FLeaf: Boolean;         //\89º\82É\83t\83H\83\8b\83_\82ð\8e\9d\82Â\82±\82Æ\82ª\8fo\97\88\82é\82©
23         public
24                 function Add(Item: TFolder): Integer;
25                 procedure Clear;
26                 procedure Delete(Index: Integer);
27                 procedure Exchange(Index1, Index2: Integer);
28                 procedure Insert(Index: Integer; Item: TFolder);
29                 procedure Move(CurIndex, NewIndex: Integer);
30                 function Remove(Item: TFolder): Integer;
31                 procedure Sort(Compare: TListSortCompare);
32                 property Capacity: Integer read FCapacity write SetCapacity;
33                 property Count: Integer read FCount write SetCount;
34                 property Items[Index: Integer]: TFolder read Get write Put; default;
35
36                 property Leaf: Boolean read FLeaf;
37         end;
38
39         TBBS = class(TFolder)
40         end;
41         TCategory class(TFolder)
42         end;
43         TBoard = class(TFolder)
44         end;
45         TThreadItem = class(TFolder)
46         end;
47 }
48
49 {
50         TBBS = class(TBBS)
51         end;
52         TBoard2ch = class(TBoard)
53         end;
54         TThreadItem2ch = class(TThreadItem)
55         end;
56 }
57
58 //      ITest = interface
59 //      end;
60 //      IBBS = interface
61 //      end;
62 //      ICategory = interface
63 //      end;
64 //      IBoard = interface
65 //      end;
66 //      IThreadItem = interface
67 //      end;
68
69         TCategory = class;
70         TBoard = class;
71         TThreadItem = class;
72
73         // BBS \82Ì\83\8b\81[\83g
74         TBBS = class(TList)
75         private
76                 FTitle: string;
77                 FFilePath : string;                                             // \94Â\83\8a\83X\83g\82Ì\83p\83X
78                 FExpand: Boolean;
79                 FKubetsuChk: Boolean;                                   //\8di\8d\9e\82Ý\8e\9e\91å\95\8e\9a\8f¬\95\8e\9a\8bæ\95Ê
80                 FSelectText: string;                                    //\8di\8d\9e\82Ý\95\8e\9a\97ñ
81                 FShortSelectText: string;
82                 FIsBoardFileRead : Boolean;             // \94Â\83\8a\83X\83g\82Í\93Ç\82Ý\8d\9e\82Ü\82ê\82Ä\82¢\82é\82©\81H
83
84                 function GetCategory(index: integer): TCategory;
85                 procedure SetCategory(index: integer; value: TCategory);
86                 procedure SetSelectText(s: string);
87         public
88                 constructor Create( boardFilePath : string );
89                 destructor Destroy; override;
90
91                 function Add(item: TCategory): integer;
92                 procedure Delete(index: integer);
93                 procedure Clear; override;
94                 function Find(key: string): TCategory;
95                 function FindBBSID(BBSID: string): TBoard;
96                 function FindBoardFromTitle(Title: string): TBoard;
97                 function FindBoardFromURL(inURL: string): TBoard;
98                 function FindThreadFromURL( inURL : string ) : TThreadItem;
99                 function FindThreadItem(BBSID: string; FileName: string): TThreadItem;
100                 function FindCategoryFromTitle( inTitle : string ) : TCategory;
101                 property FilePath : string read FFilePath write FFilePath;
102
103                 property Items[index: integer]: TCategory read GetCategory write SetCategory;
104                 property Title: string read FTitle write FTitle;
105                 property NodeExpand: Boolean read FExpand write FExpand;
106                                                                                  
107                 property KubetsuChk: Boolean read FKubetsuChk write FKubetsuChk;
108                 property SelectText: string read FSelectText write SetSelectText;
109                 property ShortSelectText: string read FShortSelectText write FShortSelectText;
110
111                 property        IsBoardFileRead : Boolean read FIsBoardFileRead write FIsBoardFileRead;
112         end;
113
114         //\83J\83e\83S\83\8a
115         TCategory = class(TList)
116         private
117                 FNo: Integer;
118                 FTitle: string;
119                 FParenTBBS: TBBS;
120                 FExpand: Boolean;
121
122                 function GetBoard(index: integer): TBoard;
123                 procedure SetBoard(index: integer; value: TBoard);
124         public
125                 constructor Create;
126                 destructor Destroy; override;
127
128                 property No: Integer read FNo write FNo;
129                 property Title: string read FTitle write FTitle;
130                 property Items[index: integer]: TBoard read GetBoard write SetBoard;
131                 property ParenTBBS: TBBS read FParenTBBS write FParenTBBS;
132
133                 function Add(item: TBoard): integer;
134                 procedure Delete(index: integer);
135                 procedure Clear; override;
136                 function FindName(key: string): TBoard;
137                 function FindBBSID(BBSID: string): TBoard;
138                 function FindBoardFromTitle(Title: string): TBoard;
139                 function FindBoardFromURL(inURL: string): TBoard;
140                 function FindThreadFromURL( inURL : string ) : TThreadItem;
141                 function IsMidoku: Boolean;
142
143                 property NodeExpand: Boolean read FExpand write FExpand;
144         end;
145
146         //\94Â
147         TBoard = class(TList)
148         private
149                 FContext: DWORD;                                        // \83v\83\89\83O\83C\83\93\82ª\8e©\97R\82É\90Ý\92è\82µ\82Ä\82¢\82¢\92l(\8eå\82É\83C\83\93\83X\83^\83\93\83X\82ª\93ü\82é)
150
151                 FNo: Integer;                                                                   //\94Ô\8d\86
152                 FTitle: string;                                                         //\83{\81[\83h\83^\83C\83g\83\8b
153                 FBBSID: string;                                                         //BBSID
154                 FURL: string;                                                                   //\83{\81[\83hURL
155                 FRound: Boolean;                                                        //\83X\83\8c\83b\83h\88ê\97\97\8f\84\89ñ\97\\96ñ
156                 FRoundName: string;                                             //\8f\84\89ñ\96¼
157                 FRoundDate: TDateTime;                          //\83X\83\8c\83b\83h\88ê\97\97\82ð\8eæ\93¾\82µ\82½\93ú\8e\9e\81i\8f\84\89ñ\93ú\8e\9e\81j
158                 FLastModified: TDateTime;                       //\83X\83\8c\83b\83h\88ê\97\97\82ª\8dX\90V\82³\82ê\82Ä\82¢\82é\93ú\8e\9e\81i\83T\81[\83o\91¤\93ú\8e\9e\81j
159                 FLastGetTime: TDateTime;                        //\83X\83\8c\83b\83h\82Ü\82½\82Í\83X\83\8c\83b\83h\88ê\97\97\82ð\8dÅ\8cã\82É\8dX\90V\82µ\82½\93ú\8e\9e\81i\83T\81[\83o\91¤\93ú\8e\9e\81E\8f\91\82«\8d\9e\82Ý\8e\9e\82É\8eg\97p\82·\82é\81j
160                 FIsThreadDatRead: Boolean;              //\83X\83\8c\83b\83h\83\8a\83X\83g\82Í\93Ç\82Ý\8d\9e\82Ü\82ê\82Ä\82¢\82é\82©\81H
161                 FUnRead: Integer;                                                       //\83X\83\8c\83b\83h\96¢\93Ç\90\94
162                 FParentCategory: TCategory;      //\90e\83J\83e\83S\83\8a
163                 FModified: Boolean;                                             //\8fC\90³\83t\83\89\83O
164                 FBoolData: Boolean;                                             //\82¢\82ë\82ñ\82È\97p\93r\82É\8eg\82¤yo
165                 FSPID: string;                                                          //\8f\91\82«\8d\9e\82Ý\97pSPID
166                 FPON: string;                                                                   //\8f\91\82«\8d\9e\82Ý\97pPON
167                 FKotehanName: string;                                   //\83R\83e\83n\83\93\96¼\91O
168                 FKotehanMail: string;                                   //\83R\83e\83n\83\93\83\81\81[\83\8b
169
170                 FUpdate: Boolean;
171                 FExpand: Boolean;
172
173                 FBoardPlugIn    : TBoardPlugIn; // \82±\82Ì\94Â\82ð\83T\83|\81[\83g\82·\82é\83v\83\89\83O\83C\83\93
174                 FFilePath                       : string;                               // \82±\82Ì\83X\83\8c\88ê\97\97\82ª\95Û\91\82³\82ê\82Ä\82¢\82é\83p\83X
175                 FIsLogFile              : Boolean;                      // \83\8d\83O\91\8dÝ\83t\83\89\83O
176                 FIntData                        : Integer;                      // \8dD\82«\82É\82¢\82\82Á\82Ä\82æ\82µ\81B\82¢\82ë\82ñ\82È\97p\93r\82É\8eg\82¤yo
177                 FListData                       : TList;                                // \8dD\82«\82É\82¢\82\82Á\82Ä\82æ\82µ\81B\82¢\82ë\82ñ\82È\97p\93r\82É\8eg\82¤yo
178
179                 function GetThreadItem(index: integer): TThreadItem;
180                 procedure SetThreadItem(index: integer; value: TThreadItem);
181                 procedure SetRound(b: Boolean);
182                 procedure SetRoundName(s: string);
183                 procedure SetLastModified(d: TDateTime);
184                 procedure SetLastGetTime(d: TDateTime);
185                 procedure SetUnRead(i: Integer);
186                 procedure SetKotehanName(s: string);
187                 procedure SetKotehanMail(s: string);
188                 procedure Init;
189         public
190                 constructor Create( inPlugIn : TBoardPlugIn; inURL : string );
191                 destructor Destroy; override;
192
193                 property Context: DWORD read FContext write FContext;
194
195                 property Items[index: integer]: TThreadItem read GetThreadItem write SetThreadItem;
196                 property No: Integer read FNo write FNo;
197                 property Title: string read FTitle write FTitle;
198                 property BBSID: string read FBBSID write FBBSID;
199                 property URL: string read FURL write FURL;
200                 property Round: Boolean read FRound write SetRound;
201                 property RoundName: string read FRoundName write SetRoundName;
202                 property RoundDate: TDateTime read FRoundDate write FRoundDate;
203                 property LastModified: TDateTime read FLastModified write SetLastModified;
204                 property LastGetTime: TDateTime read FLastGetTime write SetLastGetTime;
205                 property UnRead: Integer read FUnRead write SetUnRead;
206                 property Modified: Boolean read FModified write FModified;
207                 property IsThreadDatRead: Boolean read FIsThreadDatRead write FIsThreadDatRead;
208                 property ParentCategory: TCategory read FParentCategory write FParentCategory;
209
210                 property        BoardPlugIn     : TBoardPlugIn  read FBoardPlugIn;
211                 property        FilePath                : string                                read FFilePath write FFilePath;
212                 property        IsLogFile               : Boolean                               read FIsLogFile write FIsLogFile;
213                 property        IntData                 : Integer                               read FIntData write FIntData;
214                 property        ListData                : TList                                 read FListData write FListData;
215                 function        IsBoardPlugInAvailable : Boolean;
216
217                 function Add(item: TThreadItem): integer;
218                 procedure Insert(Index: Integer; Item: TThreadItem);
219                 procedure Delete(index: integer);
220                 procedure DeleteList(index: integer);
221                 procedure Clear; override;
222                 function Find(ItemFileName: string): TThreadItem;
223                 function FindThreadFromURL( inURL : string ) : TThreadItem;
224                 function GetIndex(ItemFileName: string): Integer;
225                 function GetIndexFromURL(URL: string): Integer;
226                 procedure LoadSettings;
227                 procedure SaveSettings;
228                 function GetReadCgiURL: string;
229                 function GetSubjectFileName: string;
230                 function GetFolderIndexFileName: string;
231                 function GetSendURL: string;
232
233                 function GetNewThreadCount: Integer;
234                 function GetLogThreadCount: Integer;
235                 function GetUserThreadCount: Integer;
236                 function GetNewThread(Index: Integer): TThreadItem;
237                 function GetLogThread(Index: Integer): TThreadItem;
238                 function GetUserThread(Index: Integer): TThreadItem;
239
240                 procedure BeginUpdate;
241                 procedure EndUpdate;
242                 property NodeExpand: Boolean read FExpand write FExpand;
243                 property BoolData: Boolean read FBoolData write FBoolData;
244                 property SPID: string read FSPID write FSPID;
245                 property PON: string read FPON write FPON;
246                 property KotehanName: string read FKotehanName write SetKotehanName;
247                 property KotehanMail: string read FKotehanMail write SetKotehanMail;
248         end;
249
250         //\83X\83\8c
251         TThreadItem = class(TObject)
252         private
253                 FContext: DWORD;                                        // \83v\83\89\83O\83C\83\93\82ª\8e©\97R\82É\90Ý\92è\82µ\82Ä\82¢\82¢\92l(\8eå\82É\83C\83\93\83X\83^\83\93\83X\82ª\93ü\82é)
254
255                 FNo: Integer;                                                   //\94Ô\8d\86
256                 FFileName: string;                              //\83X\83\8c\83b\83h\83t\83@\83C\83\8b\96¼
257                 FTitle: string;                                         //\83X\83\8c\83b\83h\83^\83C\83g\83\8b
258                 FShortTitle: string;                    //\92Z\82¢\83X\83\8c\83b\83h\83^\83C\83g\83\8b\81i\8c\9f\8dõ\97p\81j
259                 FRoundDate: TDateTime;          //\83X\83\8c\83b\83h\82ð\8eæ\93¾\82µ\82½\93ú\8e\9e\81i\8f\84\89ñ\93ú\8e\9e\81j
260                 FLastModified: TDateTime; //\83X\83\8c\83b\83h\82ª\8dX\90V\82³\82ê\82Ä\82¢\82é\93ú\8e\9e\81i\83T\81[\83o\91¤\93ú\8e\9e\81j
261                 FCount: Integer;                                        //\83X\83\8c\83b\83h\83J\83E\83\93\83g\81i\83\8d\81[\83J\83\8b\81j
262                 FAllResCount: Integer;          //\83X\83\8c\83b\83h\83J\83E\83\93\83g\81i\83T\81[\83o\81j
263                 FNewResCount: Integer;          //\83X\83\8c\83b\83h\90V\92\85\90\94
264                 FSize: Integer;                                         //\83X\83\8c\83b\83h\83T\83C\83Y
265                 FRound: Boolean;                                        //\8f\84\89ñ\83t\83\89\83O
266                 FRoundName: string;                             //\8f\84\89ñ\96¼
267                 FIsLogFile: Boolean;                    //\83\8d\83O\91\8dÝ\83t\83\89\83O
268                 FParentBoard: TBoard;                   //\90e\83{\81[\83h
269                 FKokomade: Integer;                             //\83R\83R\82Ü\82Å\93Ç\82ñ\82¾\94Ô\8d\86
270                 FNewReceive: Integer;           //\83R\83R\82©\82ç\90V\8bK\8eó\90M
271                 FNewArrival: Boolean;                   //\90V\92\85
272                 FUnRead: Boolean;                                       //\96¢\93Ç\83t\83\89\83O
273                 FScrollTop: Integer;                    //\83X\83N\83\8d\81[\83\8b\88Ê\92u
274                 FDownloadHost: string;          //\8d¡\82Ì\83z\83X\83g\82Æ\88á\82¤\8fê\8d\87\82Ì\83z\83X\83g
275                 FAgeSage: TGikoAgeSage;         //\83A\83C\83e\83\80\82Ì\8fã\82°\89º\82°
276 //              FSPID: string;                                          //\8f\91\82«\8d\9e\82Ý\97pSPID
277
278                 FUpdate: Boolean;
279                 FExpand: Boolean;
280                 FURL                                    : string;                               // \82±\82Ì\83X\83\8c\82ð\83u\83\89\83E\83U\82Å\95\\8e¦\82·\82é\8dÛ\82Ì URL
281                 FBoardPlugIn    : TBoardPlugIn; // \82±\82Ì\83X\83\8c\82ð\83T\83|\81[\83g\82·\82é\83v\83\89\83O\83C\83\93
282                 FFilePath                       : string;                               // \82±\82Ì\83X\83\8c\82ª\95Û\91\82³\82ê\82Ä\82¢\82é\83p\83X
283                 FSizeByte                       : Integer;                      // CreateHTML2 \82ð\8eÀ\8ds\82µ\82Ä\82¢\82é\8dÅ\92\86\82É\88ê\8e\9e\93I\82É\95Û\91\82³\82ê\82é\92l
284
285                 procedure SetLastModified(d: TDateTime);
286                 procedure SetRound(b: Boolean);
287                 procedure SetRoundName(s: string);
288                 procedure SetKokomade(i: Integer);
289                 procedure SetUnRead(b: Boolean);
290                 procedure SetScrollTop(i: Integer);
291                 procedure Init;
292         function GetCreateDate: TDateTime;
293         public
294                 constructor Create( inPlugIn : TBoardPlugIn; inURL : string );
295                 destructor Destroy; override;
296
297                 function GetDatURL: string;
298                 function GetDatgzURL: string;
299 //              function GetOldDatgzURL: string;
300                 function GetOfflawCgiURL(SessionID: string): string;
301                 function GetSendURL: string;
302                 procedure DeleteLogFile;
303                 function GetThreadFileName: string;
304                 procedure BeginUpdate;
305                 procedure EndUpdate;
306
307                 property Context: DWORD read FContext write FContext;
308
309                 property No: Integer read FNo write FNo;
310                 property FileName: string read FFileName write FFileName;
311                 property Title: string read FTitle write FTitle;
312                 property ShortTitle: string read FShortTitle write FShortTitle;
313                 property RoundDate: TDateTime read FRoundDate write FRoundDate;
314                 property LastModified: TDateTime read FLastModified write SetLastModified;
315                 property Count: Integer read FCount write FCount;
316                 property AllResCount: Integer read FAllResCount write FAllResCount;
317                 property NewResCount: Integer read FNewResCount write FNewResCount;
318                 property Size: Integer read FSize write FSize;
319                 property Round: Boolean read FRound write SetRound;
320                 property RoundName: string read FRoundName write SetRoundName;
321
322                 property IsLogFile: Boolean read FIsLogFile write FIsLogFile;
323                 property ParentBoard: TBoard read FParentBoard write FParentBoard;
324                 property Kokomade: Integer read FKokomade write SetKokomade;
325                 property NewReceive: Integer read FNewReceive write FNewReceive;
326                 property NewArrival: Boolean read FNewArrival write FNewArrival;
327                 property UnRead: Boolean read FUnRead write SetUnRead;
328                 property ScrollTop: Integer read FScrollTop write SetScrollTop;
329                 property Expand: Boolean read FExpand write FExpand;
330                 property DownloadHost: string read FDownloadHost write FDownloadHost;
331                 property AgeSage: TGikoAgeSage read FAgeSage write FAgeSage;
332 //              property SPID: string read FSPID write FSPID;
333         property CreateDate: TDateTime read GetCreateDate;
334                 property        URL                                     : string                                read FURL write FURL;
335                 property        BoardPlugIn     : TBoardPlugIn  read FBoardPlugIn;
336                 property        FilePath                : string                                read FFilePath write FFilePath;
337                 property        SizeByte                : Integer                               read FSizeByte write FSizeByte;
338                 function        IsBoardPlugInAvailable : Boolean;
339         end;
340
341
342
343         //\8c\9f\8dõ\8c\8b\89Ê\83\8a\83X\83g
344 {       TSearchList = class(TList)
345         private
346                 function GetThreadItem(index: integer): TThreadItem;
347                 procedure SetThreadItem(index: integer; value: TThreadItem);
348         public
349                 constructor Create;
350                 destructor Destroy; override;
351
352                 property Items[index: integer]: TThreadItem read GetThreadItem write SetThreadItem;
353
354                 function Add(item: TThreadItem): integer;
355                 procedure Delete(index: integer);
356                 procedure Clear; override;
357         end;}
358
359         function        BBSsFindBoardFromBBSID( inBBSID : string ) : TBoard;
360         function        BBSsFindBoardFromURL( inURL : string ) : TBoard;
361         function        BBSsFindBoardFromTitle( inTitle : string ) : TBoard;
362         function        BBSsFindThreadFromURL( inURL : string ) : TThreadItem;
363     function    ConvertDateTimeString( inDateTimeString : string) : string;
364     
365 var
366         BBSs            : array of TBBS;
367
368 implementation
369
370 uses
371         GikoSystem, RoundData;
372
373 const
374         BBS2CH_NAME:                                     string = '\82Q\82¿\82á\82ñ\82Ë\82é';
375         BBS2CH_LOG_FOLDER:               string = '2ch';
376         EXTERNAL_LOG_FOLDER:            string  = 'exboard';
377
378         FOLDER_INI_FILENAME:     string = 'Folder.ini';
379         FOLDER_INDEX_FILENAME: string   = 'Folder.idx';
380         SUBJECT_FILENAME:                       string  = 'subject.txt';
381         PATH_DELIM:                                             string  = '\';
382         //DEFAULT_LIST_COUNT:           Integer = 100;
383
384 //      COLUMN_CATEGORY:         array[0..0] of string = ('\83J\83e\83S\83\8a\96¼');
385 //      COLUMN_BOARD:                   array[0..3] of string = ('\94Â\96¼', '\8eæ\93¾\90\94', '\8f\84\89ñ\97\\96ñ', '\91O\89ñ\8f\84\89ñ\93ú\8e\9e');
386 //      COLUMN_THREADITEM: array[0..3] of string = ('\83X\83\8c\83b\83h\96¼', '\83J\83E\83\93\83g', '\8f\84\89ñ\97\\96ñ', '\91O\89ñ\8f\84\89ñ\93ú\8e\9e');
387
388 // BBSID \82ð\97p\82¢\82é 2 \82¿\82á\82ñ\82Ë\82é\82Ì\82Ý\92T\82µ\8fo\82µ\82Ü\82·
389 // BBSID \82Ì\8eg\97p\82Í\8bÉ\97Í\94ð\82¯\82Ä\82­\82¾\82³\82¢\81B
390 // \89Â\94\\82È\8fê\8d\87\82Í URL \82ð\8eg\97p\82µ\82Ä\82­\82¾\82³\82¢\81B
391 function        BBSsFindBoardFromBBSID(
392         inBBSID : string
393 ) : TBoard;
394 begin
395
396         Result := BBSs[ 0 ].FindBBSID( inBBSID );
397
398 end;
399
400 function        BBSsFindBoardFromURL(
401         inURL   : string
402 ) : TBoard;
403 var
404         i                       : Integer;
405 begin
406
407         for i := Length( BBSs ) - 1 downto 0 do begin
408                 Result := BBSs[ i ].FindBoardFromURL( inURL );
409                 if Result <> nil then
410                         Exit;
411         end;
412
413         Result := nil;
414
415 end;
416
417 function        BBSsFindBoardFromTitle(
418         inTitle : string
419 ) : TBoard;
420 var
421         i                               : Integer;
422 begin
423
424         for i := Length( BBSs ) - 1 downto 0 do begin
425                 Result := BBSs[ i ].FindBoardFromTitle( inTitle );
426                 if Result <> nil then
427                         Exit;
428         end;
429
430         Result := nil;
431
432 end;
433
434 function        BBSsFindThreadFromURL(
435         inURL                   : string
436 ) : TThreadItem;
437 var
438         board                   : TBoard;
439         boardURL        : string;
440 begin
441
442         boardURL        := GikoSys.GetThreadURL2BoardURL( inURL );
443         board                   := BBSsFindBoardFromURL( boardURL );
444         if board = nil then
445                 Result := nil
446         else
447                 Result := board.FindThreadFromURL( inURL );
448
449 end;
450
451 (*************************************************************************
452  *\8b@\94\\96¼\81FTBBS\83R\83\93\83X\83g\83\89\83N\83^
453  *Public
454  *************************************************************************)
455 constructor TBBS.Create( boardFilePath : string );
456 begin
457         inherited Create;
458         Title := BBS2CH_NAME;
459         FFilePath := boardFilePath;
460 end;
461
462 (*************************************************************************
463  *\8b@\94\\96¼\81FTBBS\83f\83X\83g\83\89\83N\83^
464  *Public
465  *************************************************************************)
466 destructor TBBS.Destroy;
467 begin
468         Clear;
469         inherited;
470 end;
471
472 (*************************************************************************
473  *\8b@\94\\96¼\81F
474  *Public
475  *************************************************************************)
476 function TBBS.GetCategory(index: integer): TCategory;
477 begin
478         Result := TCategory(inherited Items[index]);
479 end;
480
481 procedure TBBS.SetCategory(index: integer; value: TCategory);
482 begin
483         inherited Items[index] := value;
484 end;
485
486 function TBBS.Add(item: TCategory): integer;
487 begin
488         Item.ParenTBBS := self;
489         Result := inherited Add(item);
490 end;
491
492 procedure TBBS.Delete(index: integer);
493 begin
494         if Items[index] <> nil then
495                 TCategory(Items[index]).Free;
496         Items[index] := nil;
497         inherited Delete(index);
498 end;
499
500 procedure TBBS.Clear;
501 var
502         i: integer;
503 begin
504         for i := Count - 1 downto 0 do
505                 Delete(i);
506 end;
507
508 function TBBS.Find(key: string): TCategory;
509 begin
510         Result := nil;
511 end;
512
513 function TBBS.FindBBSID(BBSID: string): TBoard;
514 var
515         i       : Integer;
516 begin
517         if not IsBoardFileRead then
518         GikoSys.ReadBoardFile( Self );
519         for i := Count - 1 downto 0 do begin
520                 Result := Items[ i ].FindBBSID(BBSID);
521                 if Result <> nil then
522                         Exit;
523         end;
524         Result := nil;
525 end;
526
527 //*************************************************************************
528 // \83^\83C\83g\83\8b\82Ì\88ê\92v\82·\82é\94Â\82ð\92T\82·
529 //*************************************************************************)
530 function TBBS.FindBoardFromTitle(Title: string): TBoard;
531 var
532         i: Integer;
533 begin
534         if not IsBoardFileRead then
535         GikoSys.ReadBoardFile( Self );
536         for i := Count - 1 downto 0 do begin
537                 Result := Items[ i ].FindBoardFromTitle(Title);
538                 if Result <> nil then
539                         Exit;
540         end;
541         Result := nil;
542 end;
543
544 //*************************************************************************
545 // URL \82ð\8eó\82¯\95t\82¯\82é\94Â\82ð\92T\82·
546 //*************************************************************************)
547 function TBBS.FindBoardFromURL(inURL: string): TBoard;
548 var
549         i                                       : Integer;
550 begin
551         if not IsBoardFileRead then
552         GikoSys.ReadBoardFile( Self );
553         for i := Count - 1 downto 0 do begin
554                 Result := Items[ i ].FindBoardFromURL( inURL );
555                 if Result <> nil then
556                         Exit;
557         end;
558         Result := nil;
559 end;
560
561 //*************************************************************************
562 // URL \82ð\8eó\82¯\95t\82¯\82é\83X\83\8c\83b\83h\82ð\92T\82·
563 //*************************************************************************)
564 function TBBS.FindThreadFromURL(inURL: string): TThreadItem;
565 var
566         board                   : TBoard;
567         boardURL        : string;
568 begin
569
570         boardURL        := GikoSys.GetThreadURL2BoardURL( inURL );
571         board                   := FindBoardFromURL( boardURL );
572         if board = nil then
573                 Result := nil
574         else
575                 Result := board.FindThreadFromURL( inURL );
576
577 end;
578
579 function TBBS.FindThreadItem(BBSID: string; FileName: string): TThreadItem;
580 var
581         Board: TBoard;
582 begin
583         Result := nil;
584         Board := FindBBSID(BBSID);
585         if Board = nil then
586                 Exit;
587         Result := Board.Find(FileName);
588 end;
589
590 function TBBS.FindCategoryFromTitle( inTitle : string ) : TCategory;
591 var
592         i : Integer;
593 begin
594
595         for i := Count - 1 downto 0 do begin
596                 if AnsiCompareStr(Items[ i ].Title, inTitle) = 0 then begin
597                         Result := Items[ i ];
598                         Exit;
599                 end;
600         end;
601
602         Result := nil;
603
604 end;
605
606 procedure TBBS.SetSelectText(s: string);
607 begin
608         FSelectText := s;
609         ShortSelectText := GikoSys.ZenToHan(s);
610 end;
611
612 {class function TBBS.GetColumnName(Index: Integer): string;
613 begin
614         Result := COLUMN_CATEGORY[Index];
615 end;
616
617 class function TBBS.GetColumnCount: Integer;
618 begin
619         Result := Length(COLUMN_CATEGORY);
620 end;}
621
622 //===================
623 //TCategory
624 //===================
625 constructor TCategory.Create;
626 begin
627         inherited;
628 end;
629
630 destructor TCategory.Destroy;
631 begin
632         Clear;
633         inherited;
634 end;
635
636 function TCategory.GetBoard(index: integer): TBoard;
637 begin
638         Result := TBoard(inherited Items[index]);
639 end;
640
641 procedure TCategory.SetBoard(index: integer; value: TBoard);
642 begin
643         inherited Items[index] := value;
644 end;
645
646 function TCategory.Add(item: TBoard): integer;
647 begin
648         Item.ParentCategory := self;
649         Result := inherited Add(item);
650 end;
651
652 procedure TCategory.Delete(index: integer);
653 begin
654         if Items[index] <> nil then
655                 TBoard(Items[index]).Free;
656         Items[index] := nil;
657         inherited Delete(index);
658 end;
659
660 procedure TCategory.Clear;
661 var
662         i: integer;
663 begin
664         for i := Count - 1 downto 0 do
665                 Delete(i);
666 end;
667
668 function TCategory.FindName(key: string): TBoard;
669 begin
670         Result := nil;
671 end;
672
673 function TCategory.FindBBSID(BBSID: string): TBoard;
674 var
675         i       : integer;
676 begin
677         for i := Count - 1 downto 0 do begin
678                 if AnsiCompareStr(Items[i].FBBSID, BBSID) = 0 then begin
679                         Result := Items[i];
680                         Exit;
681                 end;
682         end;
683         Result := nil;
684 end;
685
686 //*************************************************************************
687 // \83^\83C\83g\83\8b\82Ì\88ê\92v\82·\82é\94Â\82ð\92T\82·
688 //*************************************************************************)
689 function TCategory.FindBoardFromTitle(Title: string): TBoard;
690 var
691         i       : integer;
692 begin
693         for i := Count - 1 downto 0 do begin
694                 if AnsiCompareStr(Items[i].FTitle, Title) = 0 then begin
695                         Result := Items[i];
696                         Exit;
697                 end;
698         end;
699         Result := nil;
700 end;
701
702 //*************************************************************************
703 // URL \82ð\8eó\82¯\95t\82¯\82é\94Â\82ð\92T\82·
704 //*************************************************************************)
705 function TCategory.FindBoardFromURL(inURL: string): TBoard;
706 var
707         i       : Integer;
708 begin
709         for i := Count - 1 downto 0 do begin
710                 if Pos( Items[i].URL, inURL ) = 1 then begin
711                         Result := Items[i];
712                         Exit;
713                 end;
714         end;
715         Result := nil;
716 end;
717
718 //*************************************************************************
719 // URL \82ð\8eó\82¯\95t\82¯\82é\83X\83\8c\83b\83h\82ð\92T\82·
720 //*************************************************************************)
721 function TCategory.FindThreadFromURL(inURL: string): TThreadItem;
722 var
723         board                   : TBoard;
724         boardURL        : string;
725 begin
726
727         boardURL        := GikoSys.GetThreadURL2BoardURL( inURL );
728         board                   := FindBoardFromURL( boardURL );
729         if board = nil then
730                 Result := nil
731         else
732                 Result := board.FindThreadFromURL( inURL );
733
734 end;
735
736 function TCategory.IsMidoku: Boolean;
737 var
738         i: Integer;
739         j: Integer;
740 begin
741         Result := False;
742         for i := 0 to Count - 1 do begin
743                 if Items[i] <> nil then begin
744                         for j := 0 to Items[i].Count - 1 do begin
745                                 if Items[i].Items[j] <> nil then begin
746 //                                      if (Items[i].Items[j].IsLogFile) and (Items[i].Items[j].Count > Items[i].Items[j].Kokomade) then begin
747                                         if (Items[i].Items[j].IsLogFile) and (Items[i].Items[j].UnRead) then begin
748                                                 Result := True;
749                                                 Exit;
750                                         end;
751                                 end;
752                         end;
753                 end;
754         end;
755 end;
756
757 {class function TCategory.GetColumnName(Index: Integer): string;
758 begin
759         Result := COLUMN_BOARD[Index];
760 end;
761
762 class function TCategory.GetColumnCount: Integer;
763 begin
764         Result := Length(COLUMN_BOARD);
765 end;}
766
767 //===================
768 //TBoard
769 //===================
770 procedure TBoard.Init;
771 begin
772         FNo := 0;
773         FTitle := '';
774         FBBSID := '';
775         FURL := '';
776         FRound := False;
777         FRoundDate := ZERO_DATE;
778         FLastModified := ZERO_DATE;
779         FLastGetTime := ZERO_DATE;
780         FIsThreadDatRead := False;
781         FUnRead := 0;
782 //      FListStyle := vsReport;
783 //      FItemNoVisible := True;
784
785         FUpdate := True;
786 end;
787
788 // *************************************************************************
789 // \8aO\95\94\94Â\83v\83\89\83O\83C\83\93\82ð\8ew\92è\82µ\82½\83R\83\93\83X\83g\83\89\83N\83^
790 // *************************************************************************
791 constructor TBoard.Create(
792         inPlugIn        : TBoardPlugIn;
793         inURL                   : string
794 );
795 var
796         protocol, host, path, document, port, bookmark  : string;
797 begin
798
799         inherited Create;
800         Init;
801
802         FBoardPlugIn    := inPlugIn;
803         URL                                             := inURL;
804         BBSID                                   := GikoSys.UrlToID( inURL );
805
806         if inPlugIn = nil then begin
807                 // subject.txt \82Ì\95Û\91\83p\83X\82ð\90Ý\92è
808                 GikoSys.ParseURI( inURL, protocol, host, path, document, port, bookmark );
809                 if GikoSys.Is2chHost( host ) then
810                         FilePath :=
811                                 IncludeTrailingPathDelimiter( GikoSys.Setting.LogFolder ) +
812                                 BBS2CH_LOG_FOLDER + PATH_DELIM + BBSID + PATH_DELIM + SUBJECT_FILENAME
813                 else
814                         FilePath :=
815                                 IncludeTrailingPathDelimiter( GikoSys.Setting.LogFolder ) +
816                                 EXTERNAL_LOG_FOLDER + PATH_DELIM + host + PATH_DELIM + BBSID + PATH_DELIM + SUBJECT_FILENAME
817         end else begin
818                 // \83v\83\89\83O\83C\83\93\82É TBoardItem \82ª\8dì\90¬\82³\82ê\82½\82±\82Æ\82ð\93`\82¦\82é
819                 inPlugIn.CreateBoardItem( DWORD( Self ) );
820         end;
821
822 end;
823
824 // *************************************************************************
825 // \83f\83X\83g\83\89\83N\83^
826 // *************************************************************************
827 destructor TBoard.Destroy;
828 begin
829         if FModified then begin
830                 GikoSys.WriteThreadDat(Self);
831                 SaveSettings;
832         end;
833
834         // \83v\83\89\83O\83C\83\93\82É TBoardItem \82ª\94j\8aü\82³\82ê\82½\82±\82Æ\82ð\93`\82¦\82é
835         if IsBoardPlugInAvailable then
836                 BoardPlugIn.DisposeBoardItem( DWORD( Self ) );
837
838         Clear;
839         inherited;
840 end;
841
842 // *************************************************************************
843 // \8aO\95\94\94Â\83v\83\89\83O\83C\83\93\82ª\8eg\97p\89Â\94\\82©
844 // *************************************************************************
845 function        TBoard.IsBoardPlugInAvailable : Boolean;
846 begin
847
848         repeat
849                 if BoardPlugIn = nil then
850                         Break;
851                         
852                 if not Assigned( Pointer( BoardPlugIn.Module ) ) then
853                         Break;
854
855                 Result := True;
856                 Exit;
857         until True;
858
859         Result := False;
860
861 end;
862
863 function TBoard.GetThreadItem(index: integer): TThreadItem;
864 begin
865         Result := TThreadItem(inherited Items[index]);
866 end;
867
868 procedure TBoard.SetThreadItem(index: integer; value: TThreadItem);
869 begin
870         inherited Items[index] := value;
871 end;
872
873 function TBoard.Add(Item: TThreadItem): Integer;
874 begin
875         Item.ParentBoard := Self;
876         Result := inherited Add(Item);
877 end;
878
879 procedure TBoard.Insert(Index: Integer; Item: TThreadItem);
880 begin
881         Item.ParentBoard := Self;
882         inherited Insert(Index, Item);
883 end;
884
885 //Index\82Å\8ew\92è\82³\82ê\82½\83X\83\8c\83b\83h\83I\83u\83W\83F\83N\83g\82ð\94j\8aü
886 procedure TBoard.Delete(index: Integer);
887 begin
888         if Items[index] <> nil then
889                 TThreadItem(Items[index]).Free;
890         Items[index] := nil;
891         inherited Delete(index);
892 end;
893
894 //Index\82Å\8ew\92è\82³\82ê\82½\83X\83\8c\83b\83h\82ð\83\8a\83X\83g\82©\82ç\8dí\8f\9c\81i\83X\83\8c\83I\83u\83W\83F\83N\83g\82Í\82Ì\82±\82·\81j
895 procedure TBoard.DeleteList(index: integer);
896 begin
897         inherited Delete(index);
898 end;
899
900 procedure TBoard.Clear;
901 var
902         i: integer;
903 begin
904 //      FUnRead := 0;
905         for i := Count - 1 downto 0 do
906                 Delete(i);
907 end;
908
909 function TBoard.Find(ItemFileName: string): TThreadItem;
910 var
911         i: integer;
912 begin
913         Result := nil;
914         for i := 0 to Count - 1 do begin
915                 if AnsiCompareStr(Items[i].FileName, ItemFileName) = 0 then begin
916                         Result := Items[i];
917                         Exit;
918                 end;
919         end;
920 end;
921
922 function TBoard.GetIndex(ItemFileName: string): Integer;
923 var
924         i: integer;
925 begin
926         Result := -1;
927         for i := 0 to Count - 1 do begin
928                 if Items[i].FileName = ItemFileName then begin
929                         Result := i;
930                         Exit;
931                 end;
932         end;
933 end;
934
935 function TBoard.GetIndexFromURL(URL: string): Integer;
936 var
937         i: integer;
938 begin
939         Result := -1;
940         for i := 0 to Count - 1 do begin
941                 if Pos( URL, Items[ i ].URL ) = 1 then begin
942                         Result := i;
943                         Exit;
944                 end;
945         end;
946 end;
947
948 function TBoard.FindThreadFromURL( inURL : string ) : TThreadItem;
949 var
950         i : Integer;
951 begin
952
953         if not IsThreadDatRead then
954                 GikoSys.ReadSubjectFile( Self );
955                 
956         for i := Count - 1 downto 0 do begin
957                 if Pos( inURL, Items[ i ].URL ) = 1 then begin
958                         Result := Items[ i ];
959                         Exit;
960                 end;
961         end;
962         Result := nil;
963
964 end;
965
966 {function TBoard.GetMidokuCount: Integer;
967 var
968         i: integer;
969 begin
970         Result := 0;
971         for i := 0 to Count- 1 do begin
972                 if Items[i] <> nil then begin
973                         if (Items[i].IsLogFile) and (Items[i].Count > Items[i].Kokomade) then
974                                 inc(Result);
975                 end;
976         end;
977 end;
978 }
979
980 procedure TBoard.LoadSettings;
981 var
982         ini: TMemIniFile;
983         FileName: string;
984     tmp: string;
985 begin
986         if Length( FilePath ) > 0 then
987                 FileName := ExtractFilePath( FilePath ) + FOLDER_INI_FILENAME
988         else
989                 FileName := IncludeTrailingPathDelimiter( GikoSys.Setting.LogFolder )
990                                                         + BBS2CH_LOG_FOLDER + BBSID + PATH_DELIM + FOLDER_INI_FILENAME;
991
992         if not FileExists(FileName) then
993                 Exit;
994         ini := TMemIniFile.Create(FileName);
995         try
996 //              Round := ini.ReadBool('Status', 'Round', False);
997                 tmp := ini.ReadString('Status', 'RoundDate', DateTimeToStr(ZERO_DATE));
998         FRoundDate := StrToDateTime(ConvertDateTimeString(tmp));
999         tmp := ini.ReadString('Status', 'LastModified', DateTimeToStr(ZERO_DATE));
1000         FLastModified := StrToDateTime(ConvertDateTimeString(tmp));
1001         tmp := ini.ReadString('Status', 'LastGetTime', DateTimeToStr(ZERO_DATE));
1002         FLastGetTime := StrToDateTime(ConvertDateTimeString(tmp));
1003
1004         {
1005                 try
1006                         FRoundDate := ini.ReadDateTime('Status', 'RoundDate', ZERO_DATE);
1007         except
1008             tmp := ini.ReadString('Status', 'RoundDate', DateTimeToStr(ZERO_DATE));
1009                 FRoundDate := StrToDateTime(ConvertDateTimeString(tmp));
1010         end;
1011         try
1012                 FLastModified := ini.ReadDateTime('Status', 'LastModified', ZERO_DATE);
1013                 except
1014             tmp := ini.ReadString('Status', 'LastModified', DateTimeToStr(ZERO_DATE));
1015                 FLastModified := StrToDateTime(ConvertDateTimeString(tmp));
1016         end;
1017         try
1018                 FLastGetTime := ini.ReadDateTime('Status', 'LastGetTime', ZERO_DATE);
1019         except
1020             tmp := ini.ReadString('Status', 'LastGetTime', DateTimeToStr(ZERO_DATE));
1021                 FLastGetTime := StrToDateTime(ConvertDateTimeString(tmp));
1022         end;
1023         }
1024                 FUnRead := ini.ReadInteger('Status', 'UnRead', 0);
1025                 FSPID := ini.ReadString('Cookie', 'SPID', '');
1026                 FPON := ini.ReadString('Cookie', 'PON', '');
1027                 FKotehanName := ini.ReadString('Kotehan', 'Name', '');
1028                 FKotehanMail := ini.ReadString('Kotehan', 'Mail', '');
1029 //              ListStyle := TViewStyle(Ord(ini.ReadInteger('Status', 'ListStyle', 3)));
1030 //              ItemNoVisible := ini.ReadBool('Status', 'ItemNoVisible', True);
1031 //              ViewType := TGikoViewType(Ord(ini.ReadInteger('Status', 'ViewType', 0)));
1032                 if UnRead < 0 then
1033                         UnRead := 0;
1034         finally
1035                 ini.Free;
1036         end;
1037 end;
1038
1039 procedure TBoard.SaveSettings;
1040 var
1041         ini: TMemIniFile;
1042         FileName: string;
1043 begin
1044         if Length( FilePath ) > 0 then
1045                 FileName := ExtractFilePath( FilePath )
1046         else
1047                 FileName := IncludeTrailingPathDelimiter( GikoSys.Setting.LogFolder )
1048                                                         + BBS2CH_LOG_FOLDER + BBSID + PATH_DELIM;
1049         if not GikoSys.DirectoryExistsEx(FileName) then
1050                 GikoSys.ForceDirectoriesEx(FileName);
1051         FileName := FileName + FOLDER_INI_FILENAME;
1052         ini := TMemIniFile.Create(FileName);
1053         try
1054                 if UnRead < 0 then
1055                         UnRead := 0;
1056 //              ini.WriteBool('Status', 'Round', Round);
1057                 ini.WriteDateTime('Status', 'RoundDate', FRoundDate);
1058                 ini.WriteDateTime('Status', 'LastModified', FLastModified);
1059                 ini.WriteDateTime('Status', 'LastGetTime', FLastGetTime);
1060                 ini.WriteInteger('Status', 'UnRead', FUnRead);
1061                 ini.WriteString('Cookie', 'SPID', FSPID);
1062                 ini.WriteString('Cookie', 'PON', FPON);
1063                 ini.WriteString('Kotehan', 'Name', FKotehanName);
1064                 ini.WriteString('Kotehan', 'Mail', FKotehanMail);
1065 //              ini.WriteInteger('Status', 'ListStyle', Ord(ListStyle));
1066 //              ini.WriteBool('Status', 'ItemNoVisible', ItemNoVisible);
1067 //              ini.WriteInteger('Status', 'ViewType', Ord(ViewType));
1068                 ini.UpdateFile;
1069         finally
1070                 ini.Free;
1071         end;
1072 end;
1073 //\82Æ\82«\82½\82Ü2003 02 08 0:32:13\82±\82ñ\82È\8c`\8e®\82Ì\93ú\95t\82ª\82 \82é\82Ì\82Å\82»\82ê\82ð
1074 //        2003/02/08 0:32:13\82É\95Ï\8a·\82·\82é
1075 function        ConvertDateTimeString( inDateTimeString : string) : string;
1076 var
1077         i : Integer;
1078 begin
1079     if ( AnsiPos('/', inDateTimeString ) = 0 ) and
1080         ( AnsiCompareStr( DateTimeToStr(ZERO_DATE), inDateTimeString) <> 0 ) then begin
1081                 for i := 0 to 1 do begin
1082                 Insert('/',inDateTimeString, AnsiPos(' ', inDateTimeString) + 1 );
1083                 Delete(inDateTimeString, AnsiPos(' ', inDateTimeString), 1);
1084         end;
1085     end;
1086     Result := inDateTimeString;
1087 end;
1088 // \83T\83u\83W\83F\83N\83gURL\8eæ\93¾
1089 function TBoard.GetReadCgiURL: string;
1090 begin
1091         //Result := URL + SUBJECT_FILENAME;
1092         //Result := GikoSys.UrlToServer(URL)
1093         //                              + 'test/read.cgi/' + BBSID + '/?raw=0.0';
1094         Result := URL + SUBJECT_FILENAME;
1095
1096 end;
1097
1098 // \83T\83u\83W\83F\83N\83g\83t\83@\83C\83\8b\96¼\8eæ\93¾\81i\83p\83X\81{\83t\83@\83C\83\8b\96¼\81j
1099 function TBoard.GetSubjectFileName: string;
1100 begin
1101         if Length( FilePath ) > 0 then
1102                 Result := FilePath
1103         else
1104                 Result := IncludeTrailingPathDelimiter( GikoSys.Setting.LogFolder )
1105                                                 + BBS2CH_LOG_FOLDER + BBSID + PATH_DELIM + SUBJECT_FILENAME;
1106 end;
1107
1108 // \83C\83\93\83f\83b\83N\83X\83t\83@\83C\83\8b\96¼(folder.idx)\8eæ\93¾\81i\83p\83X\81{\83t\83@\83C\83\8b\96¼\81j
1109 function TBoard.GetFolderIndexFileName: string;
1110 begin
1111         if Length( FilePath ) > 0 then
1112                 Result := ExtractFilePath( FilePath ) + FOLDER_INDEX_FILENAME
1113         else
1114                 Result := IncludeTrailingPathDelimiter( GikoSys.Setting.LogFolder )
1115                                                 + BBS2CH_LOG_FOLDER + BBSID + PATH_DELIM + FOLDER_INDEX_FILENAME;
1116 end;
1117
1118 // \83X\83\8c\97§\82Ä\91\97\90MURL
1119 function TBoard.GetSendURL: string;
1120 begin
1121         Result := GikoSys.UrlToServer(URL) + 'test/subbbs.cgi';
1122 end;
1123
1124 procedure TBoard.SetRound(b: Boolean);
1125 begin
1126         if b then
1127                 RoundList.Add(Self)
1128         else
1129                 RoundList.Delete(Self);
1130         if FRound = b then Exit;
1131         FRound := b;
1132         if FUpdate then
1133                 FModified := True;
1134 end;
1135
1136 procedure TBoard.SetRoundName(s: string);
1137 begin
1138         if FRoundName = s then Exit;
1139         FRoundName := s;
1140         if FUpdate then
1141                 FModified := True;
1142 end;
1143
1144 procedure TBoard.SetLastModified(d: TDateTime);
1145 begin
1146         if FLastModified = d then Exit;
1147         FLastModified := d;
1148         if FUpdate then
1149                 FModified := True;
1150 end;
1151
1152 procedure TBoard.SetLastGetTime(d: TDateTime);
1153 begin
1154         if FLastGetTime = d then Exit;
1155         FLastGetTime := d;
1156         if FUpdate then
1157                 FModified := True;
1158 end;
1159
1160 procedure TBoard.SetUnRead(i: Integer);
1161 begin
1162         if FUnRead = i then Exit;
1163         if i < 0 then i := 0;
1164         FUnRead := i;
1165         if FUpdate then
1166                 FModified := True;
1167 end;
1168
1169 procedure TBoard.SetKotehanName(s: string);
1170 begin
1171         if FKotehanName = s then Exit;
1172         FKotehanName := s;
1173         if FUpdate then
1174                 FModified := True;
1175 end;
1176
1177 procedure TBoard.SetKotehanMail(s: string);
1178 begin
1179         if FKotehanMail = s then Exit;
1180         FKotehanMail := s;
1181         if FUpdate then
1182                 FModified := True;
1183 end;
1184
1185 function TBoard.GetNewThreadCount: Integer;
1186 var
1187         i: Integer;
1188 begin
1189         Result := 0;
1190         if Length( ParentCategory.ParenTBBS.ShortSelectText ) = 0 then
1191         begin
1192                 for i := 0 to Count - 1 do begin
1193                         if Items[i].NewArrival then
1194                                 inc(Result);
1195                 end;
1196         end else begin
1197                 for i := 0 to Count - 1 do begin
1198                         if Items[i].NewArrival then
1199                         begin
1200                                 if Items[i].ShortTitle = '' then
1201                                         Items[i].ShortTitle := GikoSys.ZenToHan(Items[i].Title);
1202                                 if AnsiPos(ParentCategory.ParenTBBS.ShortSelectText, Items[i].ShortTitle) <> 0 then
1203                                         inc(Result);
1204                         end;
1205                 end;
1206         end;
1207 end;
1208
1209 function TBoard.GetLogThreadCount: Integer;
1210 var
1211         i: Integer;
1212 begin
1213         Result := 0;
1214         if Length( ParentCategory.ParenTBBS.ShortSelectText ) = 0 then
1215         begin
1216                 for i := 0 to Count - 1 do begin
1217                         if Items[i].IsLogFile then
1218                                 inc(Result);
1219                 end;
1220         end else begin
1221                 for i := 0 to Count - 1 do begin
1222                         if Items[i].IsLogFile then
1223                         begin
1224                                 if Items[i].ShortTitle = '' then
1225                                         Items[i].ShortTitle := GikoSys.ZenToHan(Items[i].Title);
1226                                 if AnsiPos(ParentCategory.ParenTBBS.ShortSelectText, Items[i].ShortTitle) <> 0 then
1227                                         inc(Result);
1228                         end;
1229                 end;
1230         end;
1231 end;
1232
1233 function TBoard.GetUserThreadCount: Integer;
1234 var
1235         i: Integer;
1236 begin
1237         Result := 0;
1238         if Length( ParentCategory.ParenTBBS.ShortSelectText ) = 0 then
1239                 Result := Count
1240         else
1241                 for i := 0 to Count - 1 do begin
1242                         if Items[i].ShortTitle = '' then
1243                                 Items[i].ShortTitle := GikoSys.ZenToHan(Items[i].Title);
1244                         if AnsiPos(ParentCategory.ParenTBBS.ShortSelectText, Items[i].ShortTitle) <> 0 then
1245                                 inc(Result);
1246                 end;
1247 end;
1248
1249 function TBoard.GetNewThread(Index: Integer): TThreadItem;
1250 var
1251         i: Integer;
1252         Cnt: Integer;
1253 begin
1254         Result := nil;
1255         Cnt := 0;
1256         if Length( ParentCategory.ParenTBBS.ShortSelectText ) = 0 then
1257         begin
1258                 for i := 0 to Count - 1 do begin
1259                         if Items[i].NewArrival then
1260                                                                         begin
1261                                 if Index = Cnt then begin
1262                                         Result := Items[i];
1263                                         Exit;
1264                                 end;
1265                                 inc(Cnt);
1266                         end;
1267                 end;
1268         end else begin
1269                 for i := 0 to Count - 1 do begin
1270                         if Items[i].NewArrival then
1271                         begin
1272                                 if Items[i].ShortTitle = '' then
1273                                         Items[i].ShortTitle := GikoSys.ZenToHan(Items[i].Title);
1274                                 if AnsiPos(ParentCategory.ParenTBBS.ShortSelectText, Items[i].ShortTitle) <> 0 then begin
1275                                         if Index = Cnt then begin
1276                                                 Result := Items[i];
1277                                                 Exit;
1278                                         end;
1279                                         inc(Cnt);
1280                                 end;
1281                         end;
1282                 end;
1283         end;
1284 end;
1285
1286 function TBoard.GetLogThread(Index: Integer): TThreadItem;
1287 var
1288         i: Integer;
1289         Cnt: Integer;
1290 begin
1291         Cnt := 0;
1292         if Length( ParentCategory.ParenTBBS.ShortSelectText ) = 0 then
1293         begin
1294                 for i := 0 to Count - 1 do begin
1295                         if Items[i].IsLogFile then
1296                                                                         begin
1297                                 if Index = Cnt then begin
1298                                         Result := Items[i];
1299                                         Exit;
1300                                 end;
1301                                 inc(Cnt);
1302                         end;
1303                 end;
1304         end else begin
1305                 for i := 0 to Count - 1 do begin
1306                         if Items[i].IsLogFile then
1307                                 begin
1308                                         if Items[i].ShortTitle = '' then
1309                                                 Items[i].ShortTitle := GikoSys.ZenToHan(Items[i].Title);
1310                                         if AnsiPos(ParentCategory.ParenTBBS.ShortSelectText, Items[i].ShortTitle) <> 0 then begin
1311                                                 if Index = Cnt then begin
1312                                                         Result := Items[i];
1313                                                         Exit;
1314                                         end;
1315                                         inc(Cnt);
1316                                 end;
1317                         end;
1318                 end;
1319         end;
1320         Result := nil;
1321 end;
1322
1323 function TBoard.GetUserThread(Index: Integer): TThreadItem;
1324 var
1325         i: Integer;
1326         Cnt: Integer;
1327 begin
1328         Result := nil;
1329         Cnt := 0;
1330         if Length( ParentCategory.ParenTBBS.ShortSelectText ) = 0 then
1331         begin
1332                 for i := 0 to Count - 1 do begin
1333                         if Index = Cnt then
1334                         begin
1335                                 Result := Items[ i ];
1336                                 Exit;
1337                         end;
1338                         inc( Cnt );
1339                 end;
1340         end else begin
1341                 for i := 0 to Count - 1 do begin
1342                         if Items[i].ShortTitle = '' then
1343                                 Items[i].ShortTitle := GikoSys.ZenToHan(Items[i].Title);
1344                         if AnsiPos(ParentCategory.ParenTBBS.ShortSelectText, Items[i].ShortTitle) <> 0 then begin
1345                                 if Index = Cnt then begin
1346                                         Result := Items[i];
1347                                         Exit;
1348                                 end;
1349                                 inc(Cnt);
1350                         end;
1351                 end;
1352         end;
1353 end;
1354
1355 procedure TBoard.BeginUpdate;
1356 begin
1357         FUpdate := False;
1358 end;
1359
1360 procedure TBoard.EndUpdate;
1361 begin
1362         FUpdate := True;
1363 end;
1364
1365 {class function TBoard.GetColumnName(Index: Integer): string;
1366 begin
1367         Result := COLUMN_THREADITEM[Index];
1368 end;
1369
1370 class function TBoard.GetColumnCount: Integer;
1371 begin
1372         Result := Length(COLUMN_THREADITEM);
1373 end;}
1374
1375 //constructor TThreadItem.Create(AOwner: TComponent);
1376 procedure TThreadItem.Init;
1377 begin
1378         FNo := 0;
1379         FFileName := '';
1380         FTitle := '';
1381         FRoundDate := ZERO_DATE;
1382         FLastModified := ZERO_DATE;
1383         FCount := 0;
1384         FAllResCount := 0;
1385         FNewResCount := 0;
1386         FSize := 0;
1387         FRound := False;
1388         FIsLogFile := False;
1389         FParentBoard := nil;
1390         FKokomade := -1;
1391         FNewReceive := 0;
1392         FNewArrival := False;
1393
1394         FUpdate := True;
1395         FURL := '';
1396         FBoardPlugIn := nil;
1397 end;
1398
1399 // *************************************************************************
1400 // \8aO\95\94\94Â\83v\83\89\83O\83C\83\93\82ð\8ew\92è\82µ\82½\83R\83\93\83X\83g\83\89\83N\83^
1401 // *************************************************************************
1402 constructor TThreadItem.Create(
1403         inPlugIn        : TBoardPlugIn;
1404         inURL                   : string
1405 );
1406 var
1407         foundPos                        : Integer;
1408         protocol, host, path, document, port, bookmark  : string;
1409         BBSID, BBSKey   : string;
1410 const
1411         READ_PATH                                                       = '/test/read.cgi';
1412 begin
1413
1414         inherited Create;
1415         Init;
1416
1417         FBoardPlugIn    := inPlugIn;
1418         URL                                             := inURL;
1419
1420         if inPlugIn = nil then begin
1421                 foundPos := Pos( READ_PATH, inURL );
1422                 if foundPos > 0 then begin
1423                         // dat \82Ì\95Û\91\83p\83X\82ð\90Ý\92è
1424                         GikoSys.ParseURI( inURL, protocol, host, path, document, port, bookmark );
1425                         GikoSys.Parse2chURL( inURL, path, document, BBSID, BBSKey );
1426                         if GikoSys.Is2chHost( host ) then
1427                                 FilePath :=
1428                                         IncludeTrailingPathDelimiter( GikoSys.Setting.LogFolder ) +
1429                                         BBS2CH_LOG_FOLDER + PATH_DELIM + BBSID + PATH_DELIM + BBSKey + '.dat'
1430                         else
1431                                 FilePath :=
1432                                         IncludeTrailingPathDelimiter( GikoSys.Setting.LogFolder ) +
1433                                         EXTERNAL_LOG_FOLDER + PATH_DELIM + host + PATH_DELIM + BBSID + PATH_DELIM + BBSKey + '.dat';
1434                         FileName        := BBSKey + '.dat';
1435                         IsLogFile       := FileExists( FilePath );
1436                         URL                             := GikoSys.Get2chBrowsableThreadURL( inURL );
1437                 end;
1438         end else begin
1439                 // \83v\83\89\83O\83C\83\93\82É TThreadItem \82ª\8dì\90¬\82³\82ê\82½\82±\82Æ\82ð\93`\82¦\82é
1440                 inPlugIn.CreateThreadItem( DWORD( Self ) );
1441         end;
1442
1443 end;
1444
1445 // *************************************************************************
1446 // \83f\83X\83g\83\89\83N\83^
1447 // *************************************************************************
1448 destructor TThreadItem.Destroy;
1449 begin
1450
1451         // \83v\83\89\83O\83C\83\93\82É TThreadItem \82ª\94j\8aü\82³\82ê\82½\82±\82Æ\82ð\93`\82¦\82é
1452         if IsBoardPlugInAvailable then
1453                 FBoardPlugIn.DisposeThreadItem( DWORD( Self ) );
1454
1455         inherited;
1456
1457 end;
1458
1459 // *************************************************************************
1460 // \8aO\95\94\94Â\83v\83\89\83O\83C\83\93\82ª\8eg\97p\89Â\94\\82©
1461 // *************************************************************************
1462 function        TThreadItem.IsBoardPlugInAvailable : Boolean;
1463 begin
1464
1465         repeat
1466                 if BoardPlugIn = nil then
1467                         Break;
1468
1469                 if not Assigned( Pointer( BoardPlugIn.Module ) ) then
1470                         Break;
1471
1472                 Result := True;
1473                 Exit;
1474         until True;
1475
1476         Result := False;
1477
1478 end;
1479
1480 function TThreadItem.GetDatURL: string;
1481 var
1482         Protocol, Host, Path, Document, Port, Bookmark: string;
1483 begin
1484         Result := ParentBoard.URL
1485                                         + 'dat/'
1486                                         + FileName;
1487         if FDownloadHost <> '' then begin
1488                 GikoSys.ParseURI(Result, Protocol, Host, Path, Document, Port, Bookmark);
1489                 Result := Format('%s://%s%s%s', [Protocol,
1490                                                                                                                                                  FDownloadHost,
1491                                                                                                                                                  Path,
1492                                                                                                                                                  Document]);
1493         end;
1494 //      Result := GikoSys.UrlToServer(ParentBoard.URL)
1495 //                                      + 'test/read.cgi/' + ParentBoard.BBSID + '/'
1496 //                                      + ChangeFileExt(FileName, '') + '/?raw='
1497 //                                      + IntToStr(ResNum) + '.' + IntToStr(ResSize);
1498 end;
1499
1500 function TThreadItem.GetDatgzURL: string;
1501         function isOldKako(s: string): Boolean;
1502         begin
1503                 Result := False;
1504                 if AnsiPos('piza.', s) <> 0 then
1505                         Result := True
1506                 else if AnsiPos('www.bbspink.', s) <> 0 then
1507                         Result := True
1508                 else if AnsiPos('tako.', s) <> 0 then
1509                         Result := True;
1510         end;
1511 var
1512         Protocol, Host, Path, Document, Port, Bookmark: string;
1513         DatNo: string;
1514 begin
1515         if FDownloadHost = '' then begin
1516                 DatNo := ChangeFileExt(FileName, '');
1517                 if isOldKako(ParentBoard.URL) then begin
1518                         Result := Format('%s%s/%.3s/%s.dat', [ParentBoard.URL, 'kako', DatNo, DatNo]);
1519                 end else begin
1520                         if Length(DatNo) > 9 then begin
1521                                 //http://xxx.2ch.net/xxx/kako/9999/99999/999999999.dat.gz
1522                                 Result := Format('%s%s/%.4s/%.5s/%s.dat.gz', [ParentBoard.URL, 'kako', DatNo, DatNo, DatNo]);
1523                         end else begin
1524                                 //http://xxx.2ch.net/xxx/kako/999/999999999.dat.gz
1525                                 Result := Format('%s%s/%.3s/%s.dat.gz', [ParentBoard.URL, 'kako', DatNo, DatNo]);
1526                         end;
1527                 end;
1528         end else begin
1529                 Gikosys.ParseURI(Result, Protocol, Host, Path, Document, Port, Bookmark);
1530                 DatNo := ChangeFileExt(Document, '');
1531                 if isOldKako(DownloadHost) then begin
1532                         Result := Format('%s://%s/%s/kako/%.3s/%s.dat', [Protocol, DownloadHost, ParentBoard.FBBSID, DatNo, DatNo]);
1533                 end else begin
1534                         if Length(DatNo) > 9 then begin
1535                                 Result := Format('%s://%s/%s/kako/%.4s/%.5s/%s.dat.gz', [Protocol, DownloadHost, ParentBoard.FBBSID, DatNo, DatNo, DatNo]);
1536                         end else begin
1537                                 Result := Format('%s://%s/%s/kako/%.3s/%s.dat.gz', [Protocol, DownloadHost, ParentBoard.FBBSID, DatNo, DatNo]);
1538                         end;
1539                 end;
1540         end;
1541 end;
1542
1543 {function TThreadItem.GetOldDatgzURL: string;
1544 var
1545         Protocol, Host, Path, Document, Port, Bookmark: string;
1546 begin
1547         Result := Format('%s%s/%.3s/%s.gz', [ParentBoard.URL,
1548                                                                                                                                                          'kako',
1549                                                                                                                                                          FileName,
1550                                                                                                                                                          FileName]);
1551         if FDownloadHost <> '' then begin
1552                 ParseURI(Result, Protocol, Host, Path, Document, Port, Bookmark);
1553                 Result := Format('%s://%s%s%s', [Protocol,
1554                                                                                                                                                  DownloadHost,
1555                                                                                                                                                  Path,
1556                                                                                                                                                  Document]);
1557
1558         end;
1559 end;}
1560
1561 function TThreadItem.GetOfflawCgiURL(SessionID: string): string;
1562 //var
1563 //      Protocol, Host, Path, Document, Port, Bookmark: string;
1564 begin
1565 //      Result := GikoSys.UrlToServer(ParentBoard.URL)
1566 //                                      + 'test/offlaw.cgi/' + ParentBoard.BBSID + '/'
1567 //                                      + ChangeFileExt(FileName, '') + '/?raw=.0&sid=' + HttpEncode(SessionID);
1568         if FDownloadHost = '' then begin
1569                 Result := GikoSys.UrlToServer(ParentBoard.URL)
1570                                                 + 'test/offlaw.cgi/' + ParentBoard.BBSID + '/'
1571                                                 + ChangeFileExt(FileName, '') + '/?raw=.0&sid=' + HttpEncode(SessionID);
1572         end else begin
1573                 //http://news.2ch.net/test/offlaw.cgi/newsplus/1014038577/?raw=.196928&sid=
1574                 //GikoSys.ParseURI(Result, Protocol, Host, Path, Document, Port, Bookmark);
1575                 Result := 'http://' + FDownloadHost
1576                                                 + '/test/offlaw.cgi/' + ParentBoard.BBSID + '/'
1577                                                 + ChangeFileExt(FileName, '') + '/?raw=.0&sid=' + HttpEncode(SessionID);
1578 //              Result := Format('%s://%s%s%s', [Protocol,
1579 //                                                                                                                                               DownloadHost,
1580 //                                                                                                                                               Path,
1581 //                                                                                                                                               Document]);
1582         end;
1583 end;
1584
1585 function TThreadItem.GetSendURL: string;
1586 begin
1587         Result := GikoSys.UrlToServer(ParentBoard.URL)
1588                                         + 'test/bbs.cgi';
1589 end;
1590
1591 procedure TThreadItem.DeleteLogFile;
1592 begin
1593         ParentBoard.BeginUpdate;
1594
1595         DeleteFile(GetThreadFileName);
1596                 if FileExists(ChangeFileExt(GetThreadFileName,'.NG')) = true then
1597                         DeleteFile(ChangeFileExt(GetThreadFileName,'.NG'));
1598         FRoundDate := ZERO_DATE;
1599         FLastModified := ZERO_DATE;
1600         FSize := 0;
1601         FIsLogFile := False;
1602         FKokomade := -1;
1603         FNewReceive := 0;
1604         FNewArrival := False;
1605         FUnRead := False;
1606         FScrollTop := 0;
1607         FRound := False;
1608         FDownloadHost := '';
1609         FAgeSage := gasNone;
1610
1611         FCount := 0;
1612         FNewResCount := 0;
1613         FRoundName := '';
1614
1615         ParentBoard.EndUpdate;
1616         ParentBoard.Modified := True;
1617 end;
1618
1619 function TThreadItem.GetThreadFileName: string;
1620 begin
1621         if Length( FilePath ) > 0 then
1622                 Result := FilePath
1623         else
1624                 Result := IncludeTrailingPathDelimiter( GikoSys.Setting.LogFolder )
1625                                                 + BBS2CH_LOG_FOLDER + ParentBoard.BBSID + PATH_DELIM + FileName;
1626 end;
1627
1628 procedure TThreadItem.SetLastModified(d: TDateTime);
1629 begin
1630         if FLastModified = d then Exit;
1631         FLastModified := d;
1632         if FUpdate and (ParentBoard <> nil) then
1633                 ParentBoard.FModified := True;
1634 end;
1635
1636 {procedure TThreadItem.SetRoundNo(i: Integer);
1637 begin
1638         if FRoundNo = i then Exit;
1639         FRoundNo := i;
1640         if FUpdate and (ParentBoard <> nil) then
1641                 ParentBoard.FModified := True;
1642 end;}
1643
1644 procedure TThreadItem.SetRound(b: Boolean);
1645 begin
1646         if b then
1647                 RoundList.Add(Self)
1648         else
1649                 RoundList.Delete(Self);
1650         if FRound = b then Exit;
1651         FRound := b;
1652         if FUpdate and (ParentBoard <> nil) then
1653                 ParentBoard.FModified := True;
1654 end;
1655
1656 procedure TThreadItem.SetRoundName(s: string);
1657 begin
1658         if FRoundName = s then Exit;
1659         FRoundName := s;
1660         if FUpdate and (ParentBoard <> nil) then
1661                 ParentBoard.FModified := True;
1662 end;
1663
1664 procedure TThreadItem.SetKokomade(i: Integer);
1665 begin
1666         if FKokomade = i then Exit;
1667         FKokomade := i;
1668         if FUpdate and (ParentBoard <> nil) then
1669                 ParentBoard.FModified := True;
1670 end;
1671
1672 procedure TThreadItem.SetUnRead(b: Boolean);
1673 begin
1674         if FUnRead = b then Exit;
1675         FUnRead := b;
1676         if FUpdate and (ParentBoard <> nil) then
1677                 ParentBoard.FModified := True;
1678 end;
1679
1680 procedure TThreadItem.SetScrollTop(i: Integer);
1681 begin
1682         if FScrollTop = i then Exit;
1683         FScrollTop := i;
1684         if FUpdate and (ParentBoard <> nil) then
1685                 ParentBoard.FModified := True;
1686 end;
1687
1688 procedure TThreadItem.BeginUpdate;
1689 begin
1690         FUpdate := False;
1691 end;
1692
1693 procedure TThreadItem.EndUpdate;
1694 begin
1695         FUpdate := True;
1696 end;
1697
1698 {initialization
1699         BBS2ch := TBBS.Create;
1700
1701 finalization
1702         if BBS2ch <> nil then
1703                 BBS2ch.Free;}
1704 function TThreadItem.GetCreateDate: TDateTime;
1705 var
1706         unixtime: Int64;
1707     tmp: string;
1708 begin
1709         // \83t\83@\83C\83\8b\96¼\82©\82ç\83X\83\8c\8dì\90¬\93ú\8e\9e\82ð\8b\81\82ß\82é
1710     try
1711                 // \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
1712         //if IsLogFile then begin
1713             tmp := ChangeFileExt(FFileName, '');
1714             if ( Length(tmp) = 9) and ( tmp[1] = '0' ) then
1715                 Insert('1', tmp, 1);
1716             unixtime := StrToInt64(tmp);
1717                         Result := UnixToDateTime(unixtime) + OffsetFromUTC;
1718         //end else
1719         //      Result := ZERO_DATE;
1720         except
1721                 on E: Exception do
1722                         Result := ZERO_DATE;
1723         end;
1724 end;
1725
1726 end.
1727