6 Windows, Messages, SysUtils, Classes,
7 GikoSystem, BoardGroup;
10 TGikoRoundType = (grtBoard, grtItem);
13 TRoundList = class(TObject)
15 FOldFileRead: Boolean;
18 function GetCount(RoundType: TGikoRoundType): Integer;
19 function GetRoundItem(Index: Integer; RoundType: TGikoRoundType): TRoundItem;
20 function ParseRoundBoardLine(Line: string): TRoundItem;
21 function ParseRoundThreadLine(Line: string): TRoundItem;
22 function ParseOldRoundBoardLine(Line: string): TRoundItem;
23 function ParseOldRoundThreadLine(Line: string): TRoundItem;
25 RoundNameList: TStringList;
28 destructor Destroy; override;
29 function Add(Board: TBoard): Integer; overload;
30 function Add(ThreadItem: TThreadItem): Integer; overload;
31 procedure Delete(Board: TBoard); overload;
32 procedure Delete(ThreadItem: TThreadItem); overload;
33 procedure Delete(URL: string; RoundType: TGikoRoundType); overload;
35 function Find(Board: TBoard): Integer; overload;
36 function Find(ThreadItem: TThreadItem): Integer; overload;
37 function Find(URL: string; RoundType: TGikoRoundType): Integer; overload;
38 property Count[RoundType: TGikoRoundType]: Integer read GetCount;
39 property OldFileRead: Boolean read FOldFileRead;
40 property Items[Index: integer; RoundType: TGikoRoundType]: TRoundItem read GetRoundItem;
41 procedure SetRoundName(Board: TBoard; RoundName: string); overload;
42 procedure SetRoundName(ThreadItem: TThreadItem; RoundName: string); overload;
44 procedure LoadRoundBoardFile;
45 procedure LoadRoundThreadFile;
46 procedure SaveRoundFile;
49 TRoundItem = class(TObject)
51 // FBBSType: TGikoBBSType;
53 FRoundType: TGikoRoundType;
59 FBoolData: Boolean; //
\82¢
\82ë
\82¢
\82ë
\8eg
\82¤
\82å
\82£
63 //property BBSType: TGikoBBSType read FBBSType write FBBSType;
64 property RoundName: string read FRoundName write FRoundName;
65 property RoundType: TGikoRoundType read FRoundType write FRoundType;
66 //property Item : TObject read FItem write FItem;
67 property URL : string read FURL write FURL;
68 property BoardTitle: string read FBoardTitle write FBoardTitle;
69 property ThreadTitle: string read FThreadTitle write FThreadTitle;
70 property FileName: string read FFileName write FFileName;
71 property BoolData: Boolean read FBoolData write FBoolData;
75 RoundList: TRoundList;
79 ROUND_BOARD_FILENAME: string = 'RoundBoard.2ch'; //
\82 \82Æ
\82ÅBoardGroup
\82Ö
\88Ú
\93®
80 ROUND_ITEM_FILENAME: string = 'RoundItem.2ch'; //
\93¯
\8fã
81 ROUND_INDEX_VERSION: string = '2.00';
82 ERROR_BOARD_FILENAME: string = 'ErrorBoard.2ch'; //Error
\8ds
\82ð
\95Û
\8aÇ
\82·
\82é
83 ERROR_ITEM_FILENAME: string = 'ErrorItem.2ch'; //Error
\8ds
\82ð
\95Û
\8aÇ
\82·
\82é
84 constructor TRoundItem.Create;
88 constructor TRoundList.Create;
91 FBoardList := TList.Create;
92 FItemList := TList.Create;
93 RoundNameList := TStringList.Create;
94 RoundNameList.Sorted := True;
95 RoundNameList.Duplicates := dupIgnore;
96 FOldFileRead := false;
99 destructor TRoundList.Destroy;
108 function TRoundList.Add(Board: TBoard): Integer;
115 if idx = -1 then begin
116 Item := TRoundItem.Create;
117 // Item.BBSType := gbt2ch; //
\82Æ
\82è
\82 \82¦
\82¸
118 Item.RoundType := grtBoard;
119 // Item.Item := Board;
120 Item.URL := Board.URL;
121 Item.BoardTitle := Board.Title;
122 Item.ThreadTitle := '';
124 Item.RoundName := Board.RoundName;
125 Result := FBoardList.Add(Item);
129 function TRoundList.Add(ThreadItem: TThreadItem): Integer;
135 idx := Find(ThreadItem);
136 if idx = -1 then begin
137 Item := TRoundItem.Create;
138 // Item.BBSType := gbt2ch; //
\82Æ
\82è
\82 \82¦
\82¸
139 Item.RoundType := grtItem;
140 // Item.Item := ThreadItem;
141 Item.URL := Threaditem.URL;
142 Item.BoardTitle := ThreadItem.ParentBoard.Title;
143 Item.ThreadTitle := ThreadItem.Title;
144 Item.FileName := ThreadItem.FileName;
145 Item.RoundName := ThreadItem.RoundName;
146 Result := FItemList.Add(Item);
150 procedure TRoundList.Delete(Board: TBoard);
156 if idx <> -1 then begin
157 TRoundItem(FBoardList[idx]).Free;
158 FBoardList.Delete(idx);
162 procedure TRoundList.Delete(ThreadItem: TThreadItem);
167 idx := Find(ThreadItem);
168 if idx <> -1 then begin
169 TRoundItem(FItemList[idx]).Free;
170 FItemList.Delete(idx);
174 procedure TRoundList.Clear;
178 for i := FBoardList.Count - 1 downto 0 do begin
179 if FBoardList[i] <> nil then
180 TRoundItem(FBoardList[i]).Free;
181 FBoardList.Delete(i);
183 for i := FItemList.Count - 1 downto 0 do begin
184 if FItemList[i] <> nil then
185 TRoundItem(FItemList[i]).Free;
190 function TRoundList.Find(Board: TBoard): Integer;
196 for i := 0 to FBoardList.Count - 1 do begin
197 Item := TRoundItem(FBoardList[i]);
198 if Item.FRoundType <> grtBoard then Continue;
199 if Item.FURL = Board.URL then begin
206 function TRoundList.Find(ThreadItem: TThreadItem): Integer;
212 for i := 0 to FItemList.Count - 1 do begin
213 Item := TRoundItem(FItemList[i]);
214 if Item.FRoundType <> grtItem then Continue;
215 if Item.FURL = ThreadItem.URL then begin
221 function TRoundList.Find(URL: string; RoundType: TGikoRoundType): Integer;
227 if RoundType = grtItem then begin
228 for i := 0 to FItemList.Count - 1 do begin
229 Item := TRoundItem(FItemList[i]);
230 if Item.FRoundType <> RoundType then Continue;
231 if Item.FURL = URL then begin
237 for i := 0 to FBoardList.Count - 1 do begin
238 Item := TRoundItem(FBoardList[i]);
239 if Item.FRoundType <> RoundType then Continue;
240 if Item.FURL = URL then begin
247 procedure TRoundList.Delete(URL: string; RoundType: TGikoRoundType);
252 threadItem: TThreadItem;
254 idx := Find(URL, RoundType);
255 if idx <> -1 then begin
257 if RoundType = grtBoard then begin
258 Item := TRoundItem(FBoardList[idx]);
260 FBoardList.Delete(idx);
261 board := BBSsFindBoardFromURL(URL);
262 if board <> nil then begin
263 board.Round := False;
264 board.RoundName := '';
267 Item := TRoundItem(FItemList[idx]);
269 FItemList.Delete(idx);
271 threadItem := BBSsFindThreadFromURL(URL);
272 if threadItem <> nil then begin
273 threadItem.Round := false;
274 threadItem.RoundName := '';
280 procedure TRoundList.SetRoundName(Board: TBoard; RoundName: string);
286 if idx <> -1 then begin
287 Item := TRoundItem(FBoardList[idx]);
288 Item.RoundName := RoundName;
292 procedure TRoundList.SetRoundName(ThreadItem: TThreadItem; RoundName: string);
297 idx := Find(ThreadItem);
298 if idx <> -1 then begin
299 Item := TRoundItem(FItemList[idx]);
300 Item.RoundName := RoundName;
304 function TRoundList.GetCount(RoundType: TGikoRoundType): Integer;
307 if RoundType = grtBoard then
308 Result := FBoardList.Count
309 else if RoundType = grtItem then
310 Result := FItemList.Count;
313 function TRoundList.GetRoundItem(Index: Integer; RoundType: TGikoRoundType): TRoundItem;
316 if RoundType = grtBoard then begin
317 if (Index >= 0) and (Index < FBoardList.Count) then
318 Result := TRoundItem(FBoardList[Index]);
319 end else if RoundType = grtItem then begin
320 if (Index >= 0) and (Index < FItemList.Count) then
321 Result := TRoundItem(FItemList[Index]);
324 procedure TRoundList.LoadRoundBoardFile;
329 errorSl: TStringList;
330 errorFileName: string;
334 sl := TStringList.Create;
335 errorSl := TStringList.Create;
336 errorSl.Duplicates := dupIgnore;
338 //
\83{
\81[
\83h
\8f\84\89ñ
\83t
\83@
\83C
\83\8b\93Ç
\82Ý
\8d\9e\82Ý
339 FileName := GikoSys.GetConfigDir + ROUND_BOARD_FILENAME;
340 //
\83G
\83\89\81[
\8ds
\95Û
\91¶
\83t
\83@
\83C
\83\8b\93Ç
\82Ý
\8d\9e\82Ý
341 errorFileName := GikoSys.GetConfigDir + ERROR_BOARD_FILENAME;
342 if FileExists(FileName) then begin
343 sl.LoadFromFile(FileName);
344 if FileExists(errorFileName) then begin
346 errorSl.LoadFromFile(errorFileName);
350 //Item := TRoundItem.Create;
352 //
\82P
\8ds
\96Ú
\82Í
\83o
\81[
\83W
\83\87\83\93
353 if sl[0] = ROUND_INDEX_VERSION then begin
354 for i := 1 to sl.Count - 1 do begin
355 Item := ParseRoundBoardLine(sl[i - delCount]);
356 if Item <> nil then begin
357 FBoardList.Add(Item);
358 RoundNameList.Add(Item.RoundName);
360 errorSl.Add( sl[i - delCount] );
361 sl.Delete(i- delCount);
366 if FOldFileRead then begin //
\83M
\83R
\83i
\83r
\96{
\91Ì
\82ª
\83{
\81[
\83h
\83t
\83@
\83C
\83\8b\82ð
\82æ
\82Ý
\82Æ
\82Á
\82½
\8cã
\82¶
\82á
\82È
\82¢
\82Æ
\83N
\83\89\83b
\83V
\83\85\82·
\82é
\82Ì
\82Å
367 for i := 1 to sl.Count - 1 do begin
368 Item := ParseOldRoundBoardLine(sl[i - delCount]);
369 if Item <> nil then begin
370 FBoardList.Add(Item);
371 RoundNameList.Add(Item.RoundName);
373 errorSl.Add( sl[i- delCount] );
374 sl.Delete(i- delCount);
379 FOldFileRead := true;
382 if errorSl.Count > 0 then
383 errorSl.SaveToFile(errorFileName);
389 procedure TRoundList.LoadRoundThreadFile;
395 errorSl: TStringList;
396 errorFileName: string;
399 // boardList : TStringList;
401 // boardList := TStringList.Create;
402 // boardList.Duplicates := dupIgnore;
403 errorSl := TStringList.Create;
404 errorSl.Duplicates := dupIgnore;
405 sl := TStringList.Create;
407 //
\83X
\83\8c\8f\84\89ñ
\83t
\83@
\83C
\83\8b\93Ç
\82Ý
\8d\9e\82Ý
408 FileName := GikoSys.GetConfigDir + ROUND_ITEM_FILENAME;
409 //
\83G
\83\89\81[
\8ds
\95Û
\91¶
\83t
\83@
\83C
\83\8b\93Ç
\82Ý
\8d\9e\82Ý
410 errorFileName := GikoSys.GetConfigDir + ERROR_ITEM_FILENAME;
411 if FileExists(FileName) then begin
412 sl.LoadFromFile(FileName);
413 if FileExists(errorFileName) then begin
415 errorSl.LoadFromFile(errorFileName);
419 //Item := TRoundItem.Create;
421 //
\82P
\8ds
\96Ú
\82Í
\83o
\81[
\83W
\83\87\83\93
422 if sl[0] = ROUND_INDEX_VERSION then begin
423 for i := 1 to sl.Count - 1 do begin
424 Item := ParseRoundThreadLine(sl[i - delCount]);
425 if Item <> nil then begin
427 RoundNameList.Add(Item.RoundName);
429 errorSl.Add(sl[i - delCount]);
430 sl.Delete(i - delCount);
436 for i := 1 to sl.Count - 1 do begin
437 Item := ParseOldRoundThreadLine(sl[i - delCount]);
438 if Item <> nil then begin
440 RoundNameList.Add(Item.RoundName);
442 errorSl.Add(sl[i - delCount]);
443 sl.Delete(i - delCount);
448 // j := boardList.Count - 1;
449 // while j >= 0 do begin
450 // GikoSys.ReadSubjectFile( BBSsFindBoardFromURL( boardList[j] ) );
451 // boardList.Delete(j);
454 if errorSl.Count > 0 then
455 errorSl.SaveToFile(errorFileName);
462 procedure TRoundList.SaveRoundFile;
470 GikoSys.ForceDirectoriesEx(GikoSys.GetConfigDir);
472 sl := TStringList.Create;
474 FileName := GikoSys.GetConfigDir + ROUND_BOARD_FILENAME;
475 sl.Add(ROUND_INDEX_VERSION);
476 for i := 0 to FBoardList.Count - 1 do begin
477 Item := TRoundItem(FBoardList[i]);
479 + Item.BoardTitle + #1
483 sl.SaveToFile(FileName);
485 FileName := GikoSys.GetConfigDir + ROUND_ITEM_FILENAME;
486 sl.Add(ROUND_INDEX_VERSION);
487 for i := 0 to FItemList.Count - 1 do begin
488 Item := TRoundItem(FItemList[i]);
490 + Item.BoardTitle + #1
492 + Item.ThreadTitle + #1
496 sl.SaveToFile(FileName);
501 function TRoundList.ParseRoundBoardLine(Line: string): TRoundItem;
506 Result := TRoundItem.Create;
507 Result.ThreadTitle := '';
508 Result.FileName := '';
509 Result.RoundType := grtBoard;
510 for i := 0 to 2 do begin
511 s := GikoSys.GetTokenIndex(Line, #1, i);
518 1: Result.BoardTitle := s;
519 2: Result.RoundName := s;
528 function TRoundList.ParseRoundThreadLine(Line: string): TRoundItem;
532 // threadItem: TThreadItem;
534 Result := TRoundItem.Create;
535 Result.RoundType := grtItem;
536 for i := 0 to 4 do begin
537 s := GikoSys.GetTokenIndex(Line, #1, i);
543 //threadItem := BBSsFindThreadFromURL( s );
544 //if threadItem <> nil then begin
545 // BoardList.Add( threadItem.ParentBoard.URL );
548 1: Result.BoardTitle := s;
549 2: Result.FileName := s;
550 3: Result.ThreadTitle := s;
551 4: Result.RoundName := s;
560 function TRoundList.ParseOldRoundBoardLine(Line: string): TRoundItem;
566 Result := TRoundItem.Create;
567 Result.ThreadTitle := '';
568 Result.FileName := '';
569 Result.RoundType := grtBoard;
570 for i := 0 to 2 do begin
571 s := GikoSys.GetTokenIndex(Line, #1, i);
576 board := BBSs[ 0 ].FindBBSID( s );
577 if board <> nil then begin
578 Result.URL := board.URL;
580 raise Exception.Create('
\82±
\82Ì
\8f\84\89ñ
\82Í
\93Ç
\82Ý
\8d\9e\82ß
\82È
\82¢
\82æ
\81i
\91½
\95ª
\8aO
\95\94\94Â
\81j');
583 1: Result.FBoardTitle := s;
584 2: Result.RoundName := s;
593 function TRoundList.ParseOldRoundThreadLine(Line: string): TRoundItem;
599 // threadItem: TThreadItem;
602 Result := TRoundItem.Create;
603 Result.RoundType := grtItem;
604 for i := 0 to 4 do begin
605 s := GikoSys.GetTokenIndex(Line, #1, i);
609 1: Result.BoardTitle := s;
612 Result.FileName := s;
613 board := BBSs[ 0 ].FindBBSID(bbsID);
614 if board <> nil then begin
615 buf := Copy(board.GetSendURL,1,LastDelimiter('/', board.GetSendURL)-1);
616 Result.URL := buf + '/read.cgi/'+ board.BBSID+ '/' +ChangeFileExt(s,'') + '/l50';
618 raise Exception.Create('
\82±
\82Ì
\8f\84\89ñ
\82Í
\93Ç
\82Ý
\8d\9e\82ß
\82È
\82¢
\82æ');
621 3: Result.ThreadTitle := s;
622 4: Result.RoundName := s;