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 FBoardList.Capacity := FBoardList.Count;
184 for i := FItemList.Count - 1 downto 0 do begin
185 if FItemList[i] <> nil then
186 TRoundItem(FItemList[i]).Free;
189 FItemList.Capacity := FItemList.Count;
192 function TRoundList.Find(Board: TBoard): Integer;
198 for i := 0 to FBoardList.Count - 1 do begin
199 Item := TRoundItem(FBoardList[i]);
200 if Item.FRoundType <> grtBoard then Continue;
201 if Item.FURL = Board.URL then begin
208 function TRoundList.Find(ThreadItem: TThreadItem): Integer;
214 for i := 0 to FItemList.Count - 1 do begin
215 Item := TRoundItem(FItemList[i]);
216 if Item.FRoundType <> grtItem then Continue;
217 if Item.FURL = ThreadItem.URL then begin
223 function TRoundList.Find(URL: string; RoundType: TGikoRoundType): Integer;
229 if RoundType = grtItem then begin
230 for i := 0 to FItemList.Count - 1 do begin
231 Item := TRoundItem(FItemList[i]);
232 if Item.FRoundType <> RoundType then Continue;
233 if Item.FURL = URL then begin
239 for i := 0 to FBoardList.Count - 1 do begin
240 Item := TRoundItem(FBoardList[i]);
241 if Item.FRoundType <> RoundType then Continue;
242 if Item.FURL = URL then begin
249 procedure TRoundList.Delete(URL: string; RoundType: TGikoRoundType);
254 threadItem: TThreadItem;
256 idx := Find(URL, RoundType);
257 if idx <> -1 then begin
259 if RoundType = grtBoard then begin
260 Item := TRoundItem(FBoardList[idx]);
262 FBoardList.Delete(idx);
263 board := BBSsFindBoardFromURL(URL);
264 if board <> nil then begin
265 board.Round := False;
266 board.RoundName := '';
269 Item := TRoundItem(FItemList[idx]);
271 FItemList.Delete(idx);
273 threadItem := BBSsFindThreadFromURL(URL);
274 if threadItem <> nil then begin
275 threadItem.Round := false;
276 threadItem.RoundName := '';
282 procedure TRoundList.SetRoundName(Board: TBoard; RoundName: string);
288 if idx <> -1 then begin
289 Item := TRoundItem(FBoardList[idx]);
290 Item.RoundName := RoundName;
294 procedure TRoundList.SetRoundName(ThreadItem: TThreadItem; RoundName: string);
299 idx := Find(ThreadItem);
300 if idx <> -1 then begin
301 Item := TRoundItem(FItemList[idx]);
302 Item.RoundName := RoundName;
306 function TRoundList.GetCount(RoundType: TGikoRoundType): Integer;
309 if RoundType = grtBoard then
310 Result := FBoardList.Count
311 else if RoundType = grtItem then
312 Result := FItemList.Count;
315 function TRoundList.GetRoundItem(Index: Integer; RoundType: TGikoRoundType): TRoundItem;
318 if RoundType = grtBoard then begin
319 if (Index >= 0) and (Index < FBoardList.Count) then
320 Result := TRoundItem(FBoardList[Index]);
321 end else if RoundType = grtItem then begin
322 if (Index >= 0) and (Index < FItemList.Count) then
323 Result := TRoundItem(FItemList[Index]);
326 procedure TRoundList.LoadRoundBoardFile;
331 errorSl: TStringList;
332 errorFileName: string;
336 sl := TStringList.Create;
337 errorSl := TStringList.Create;
338 errorSl.Duplicates := dupIgnore;
340 //
\83{
\81[
\83h
\8f\84\89ñ
\83t
\83@
\83C
\83\8b\93Ç
\82Ý
\8d\9e\82Ý
341 FileName := GikoSys.GetConfigDir + ROUND_BOARD_FILENAME;
342 //
\83G
\83\89\81[
\8ds
\95Û
\91¶
\83t
\83@
\83C
\83\8b\93Ç
\82Ý
\8d\9e\82Ý
343 errorFileName := GikoSys.GetConfigDir + ERROR_BOARD_FILENAME;
344 if FileExists(FileName) then begin
345 sl.LoadFromFile(FileName);
346 if FileExists(errorFileName) then begin
348 errorSl.LoadFromFile(errorFileName);
352 //Item := TRoundItem.Create;
354 //
\82P
\8ds
\96Ú
\82Í
\83o
\81[
\83W
\83\87\83\93
355 if sl[0] = ROUND_INDEX_VERSION then begin
356 for i := 1 to sl.Count - 1 do begin
357 Item := ParseRoundBoardLine(sl[i - delCount]);
358 if Item <> nil then begin
359 FBoardList.Add(Item);
360 RoundNameList.Add(Item.RoundName);
362 errorSl.Add( sl[i - delCount] );
363 sl.Delete(i- delCount);
368 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Å
369 for i := 1 to sl.Count - 1 do begin
370 Item := ParseOldRoundBoardLine(sl[i - delCount]);
371 if Item <> nil then begin
372 FBoardList.Add(Item);
373 RoundNameList.Add(Item.RoundName);
375 errorSl.Add( sl[i- delCount] );
376 sl.Delete(i- delCount);
381 FOldFileRead := true;
384 if errorSl.Count > 0 then
385 errorSl.SaveToFile(errorFileName);
391 procedure TRoundList.LoadRoundThreadFile;
397 errorSl: TStringList;
398 errorFileName: string;
401 // boardList : TStringList;
403 // boardList := TStringList.Create;
404 // boardList.Duplicates := dupIgnore;
405 errorSl := TStringList.Create;
406 errorSl.Duplicates := dupIgnore;
407 sl := TStringList.Create;
409 //
\83X
\83\8c\8f\84\89ñ
\83t
\83@
\83C
\83\8b\93Ç
\82Ý
\8d\9e\82Ý
410 FileName := GikoSys.GetConfigDir + ROUND_ITEM_FILENAME;
411 //
\83G
\83\89\81[
\8ds
\95Û
\91¶
\83t
\83@
\83C
\83\8b\93Ç
\82Ý
\8d\9e\82Ý
412 errorFileName := GikoSys.GetConfigDir + ERROR_ITEM_FILENAME;
413 if FileExists(FileName) then begin
414 sl.LoadFromFile(FileName);
415 if FileExists(errorFileName) then begin
417 errorSl.LoadFromFile(errorFileName);
421 //Item := TRoundItem.Create;
423 //
\82P
\8ds
\96Ú
\82Í
\83o
\81[
\83W
\83\87\83\93
424 if sl[0] = ROUND_INDEX_VERSION then begin
425 for i := 1 to sl.Count - 1 do begin
426 Item := ParseRoundThreadLine(sl[i - delCount]);
427 if Item <> nil then begin
429 RoundNameList.Add(Item.RoundName);
431 errorSl.Add(sl[i - delCount]);
432 sl.Delete(i - delCount);
438 for i := 1 to sl.Count - 1 do begin
439 Item := ParseOldRoundThreadLine(sl[i - delCount]);
440 if Item <> nil then begin
442 RoundNameList.Add(Item.RoundName);
444 errorSl.Add(sl[i - delCount]);
445 sl.Delete(i - delCount);
450 // j := boardList.Count - 1;
451 // while j >= 0 do begin
452 // GikoSys.ReadSubjectFile( BBSsFindBoardFromURL( boardList[j] ) );
453 // boardList.Delete(j);
456 if errorSl.Count > 0 then
457 errorSl.SaveToFile(errorFileName);
465 procedure TRoundList.SaveRoundFile;
473 GikoSys.ForceDirectoriesEx(GikoSys.GetConfigDir);
475 sl := TStringList.Create;
477 FileName := GikoSys.GetConfigDir + ROUND_BOARD_FILENAME;
478 sl.Add(ROUND_INDEX_VERSION);
479 for i := 0 to FBoardList.Count - 1 do begin
480 Item := TRoundItem(FBoardList[i]);
482 + Item.BoardTitle + #1
486 sl.SaveToFile(FileName);
488 FileName := GikoSys.GetConfigDir + ROUND_ITEM_FILENAME;
489 sl.Add(ROUND_INDEX_VERSION);
490 for i := 0 to FItemList.Count - 1 do begin
491 Item := TRoundItem(FItemList[i]);
493 + Item.BoardTitle + #1
495 + Item.ThreadTitle + #1
499 sl.SaveToFile(FileName);
504 function TRoundList.ParseRoundBoardLine(Line: string): TRoundItem;
509 Result := TRoundItem.Create;
510 Result.ThreadTitle := '';
511 Result.FileName := '';
512 Result.RoundType := grtBoard;
513 for i := 0 to 2 do begin
514 s := GikoSys.GetTokenIndex(Line, #1, i);
521 1: Result.BoardTitle := s;
522 2: Result.RoundName := s;
531 function TRoundList.ParseRoundThreadLine(Line: string): TRoundItem;
535 // threadItem: TThreadItem;
537 Result := TRoundItem.Create;
538 Result.RoundType := grtItem;
539 for i := 0 to 4 do begin
540 s := GikoSys.GetTokenIndex(Line, #1, i);
546 //threadItem := BBSsFindThreadFromURL( s );
547 //if threadItem <> nil then begin
548 // BoardList.Add( threadItem.ParentBoard.URL );
551 1: Result.BoardTitle := s;
552 2: Result.FileName := s;
553 3: Result.ThreadTitle := s;
554 4: Result.RoundName := s;
563 function TRoundList.ParseOldRoundBoardLine(Line: string): TRoundItem;
569 Result := TRoundItem.Create;
570 Result.ThreadTitle := '';
571 Result.FileName := '';
572 Result.RoundType := grtBoard;
573 for i := 0 to 2 do begin
574 s := GikoSys.GetTokenIndex(Line, #1, i);
579 board := BBSs[ 0 ].FindBBSID( s );
580 if board <> nil then begin
581 Result.URL := board.URL;
583 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');
586 1: Result.FBoardTitle := s;
587 2: Result.RoundName := s;
596 function TRoundList.ParseOldRoundThreadLine(Line: string): TRoundItem;
602 // threadItem: TThreadItem;
605 Result := TRoundItem.Create;
606 Result.RoundType := grtItem;
607 for i := 0 to 4 do begin
608 s := GikoSys.GetTokenIndex(Line, #1, i);
612 1: Result.BoardTitle := s;
615 Result.FileName := s;
616 board := BBSs[ 0 ].FindBBSID(bbsID);
617 if board <> nil then begin
618 buf := Copy(board.GetSendURL,1,LastDelimiter('/', board.GetSendURL)-1);
619 Result.URL := buf + '/read.cgi/'+ board.BBSID+ '/' +ChangeFileExt(s,'') + '/l50';
621 raise Exception.Create('
\82±
\82Ì
\8f\84\89ñ
\82Í
\93Ç
\82Ý
\8d\9e\82ß
\82È
\82¢
\82æ');
624 3: Result.ThreadTitle := s;
625 4: Result.RoundName := s;