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 for i := 0 to FItemList.Count - 1 do begin
228 Item := TRoundItem(FItemList[i]);
229 if Item.FRoundType <> RoundType then Continue;
230 if Item.FURL = URL then begin
236 procedure TRoundList.Delete(URL: string; RoundType: TGikoRoundType);
241 threadItem: TThreadItem;
243 idx := Find(URL, RoundType);
244 if idx <> -1 then begin
245 Item := TRoundItem(FItemList[idx]);
247 FItemList.Delete(idx);
248 if RoundType = grtBoard then begin
249 board := BBSsFindBoardFromURL(URL);
250 board.Round := False;
251 board.RoundName := '';
253 threadItem := BBSsFindThreadFromURL(URL);
254 threadItem.Round := false;
255 threadItem.RoundName := '';
260 procedure TRoundList.SetRoundName(Board: TBoard; RoundName: string);
266 if idx <> -1 then begin
267 Item := TRoundItem(FBoardList[idx]);
268 Item.RoundName := RoundName;
272 procedure TRoundList.SetRoundName(ThreadItem: TThreadItem; RoundName: string);
277 idx := Find(ThreadItem);
278 if idx <> -1 then begin
279 Item := TRoundItem(FItemList[idx]);
280 Item.RoundName := RoundName;
284 function TRoundList.GetCount(RoundType: TGikoRoundType): Integer;
287 if RoundType = grtBoard then
288 Result := FBoardList.Count
289 else if RoundType = grtItem then
290 Result := FItemList.Count;
293 function TRoundList.GetRoundItem(Index: Integer; RoundType: TGikoRoundType): TRoundItem;
296 if RoundType = grtBoard then begin
297 if (Index >= 0) and (Index < FBoardList.Count) then
298 Result := TRoundItem(FBoardList[Index]);
299 end else if RoundType = grtItem then begin
300 if (Index >= 0) and (Index < FItemList.Count) then
301 Result := TRoundItem(FItemList[Index]);
304 procedure TRoundList.LoadRoundBoardFile;
309 errorSl: TStringList;
310 errorFileName: string;
313 sl := TStringList.Create;
314 errorSl := TStringList.Create;
315 errorSl.Duplicates := dupIgnore;
317 //
\83{
\81[
\83h
\8f\84\89ñ
\83t
\83@
\83C
\83\8b\93Ç
\82Ý
\8d\9e\82Ý
318 FileName := GikoSys.GetConfigDir + ROUND_BOARD_FILENAME;
319 //
\83G
\83\89\81[
\8ds
\95Û
\91¶
\83t
\83@
\83C
\83\8b\93Ç
\82Ý
\8d\9e\82Ý
320 errorFileName := GikoSys.GetConfigDir + ERROR_BOARD_FILENAME;
321 if FileExists(FileName) then begin
322 sl.LoadFromFile(FileName);
323 if FileExists(errorFileName) then begin
325 errorSl.LoadFromFile(errorFileName);
329 //Item := TRoundItem.Create;
330 //
\82P
\8ds
\96Ú
\82Í
\83o
\81[
\83W
\83\87\83\93
331 if sl[0] = ROUND_INDEX_VERSION then begin
332 for i := sl.Count - 1 downto 1 do begin
333 Item := ParseRoundBoardLine(sl[i]);
334 if Item <> nil then begin
335 FBoardList.Add(Item);
336 RoundNameList.Add(Item.RoundName);
338 errorSl.Add( sl[i] );
343 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Å
344 for i := sl.Count - 1 downto 1 do begin
345 Item := ParseOldRoundBoardLine(sl[i]);
346 if Item <> nil then begin
347 FBoardList.Add(Item);
348 RoundNameList.Add(Item.RoundName);
350 errorSl.Add( sl[i] );
355 FOldFileRead := true;
358 if errorSl.Count > 0 then
359 errorSl.SaveToFile(errorFileName);
365 procedure TRoundList.LoadRoundThreadFile;
371 errorSl: TStringList;
372 errorFileName: string;
374 // boardList : TStringList;
376 // boardList := TStringList.Create;
377 // boardList.Duplicates := dupIgnore;
378 errorSl := TStringList.Create;
379 errorSl.Duplicates := dupIgnore;
380 sl := TStringList.Create;
382 //
\83X
\83\8c\8f\84\89ñ
\83t
\83@
\83C
\83\8b\93Ç
\82Ý
\8d\9e\82Ý
383 FileName := GikoSys.GetConfigDir + ROUND_ITEM_FILENAME;
384 //
\83G
\83\89\81[
\8ds
\95Û
\91¶
\83t
\83@
\83C
\83\8b\93Ç
\82Ý
\8d\9e\82Ý
385 errorFileName := GikoSys.GetConfigDir + ERROR_ITEM_FILENAME;
386 if FileExists(FileName) then begin
387 sl.LoadFromFile(FileName);
388 if FileExists(errorFileName) then begin
390 errorSl.LoadFromFile(errorFileName);
394 //Item := TRoundItem.Create;
395 //
\82P
\8ds
\96Ú
\82Í
\83o
\81[
\83W
\83\87\83\93
396 if sl[0] = ROUND_INDEX_VERSION then begin
397 for i := sl.Count - 1 downto 1 do begin
398 Item := ParseRoundThreadLine(sl[i]);
399 if Item <> nil then begin
401 RoundNameList.Add(Item.RoundName);
409 for i := sl.Count - 1 downto 1 do begin
410 Item := ParseOldRoundThreadLine(sl[i]);
411 if Item <> nil then begin
413 RoundNameList.Add(Item.RoundName);
420 // j := boardList.Count - 1;
421 // while j >= 0 do begin
422 // GikoSys.ReadSubjectFile( BBSsFindBoardFromURL( boardList[j] ) );
423 // boardList.Delete(j);
426 if errorSl.Count > 0 then
427 errorSl.SaveToFile(errorFileName);
434 procedure TRoundList.SaveRoundFile;
442 GikoSys.ForceDirectoriesEx(GikoSys.GetConfigDir);
444 sl := TStringList.Create;
446 FileName := GikoSys.GetConfigDir + ROUND_BOARD_FILENAME;
447 sl.Add(ROUND_INDEX_VERSION);
448 for i := FBoardList.Count - 1 downto 0 do begin
449 Item := TRoundItem(FBoardList[i]);
451 + Item.BoardTitle + #1
455 sl.SaveToFile(FileName);
457 FileName := GikoSys.GetConfigDir + ROUND_ITEM_FILENAME;
458 sl.Add(ROUND_INDEX_VERSION);
459 for i := FItemList.Count - 1 downto 0 do begin
460 Item := TRoundItem(FItemList[i]);
462 + Item.BoardTitle + #1
464 + Item.ThreadTitle + #1
468 sl.SaveToFile(FileName);
473 function TRoundList.ParseRoundBoardLine(Line: string): TRoundItem;
478 Result := TRoundItem.Create;
479 Result.ThreadTitle := '';
480 Result.FileName := '';
481 Result.RoundType := grtBoard;
482 for i := 0 to 2 do begin
483 s := GikoSys.GetTokenIndex(Line, #1, i);
490 1: Result.BoardTitle := s;
491 2: Result.RoundName := s;
500 function TRoundList.ParseRoundThreadLine(Line: string): TRoundItem;
504 // threadItem: TThreadItem;
506 Result := TRoundItem.Create;
507 Result.RoundType := grtItem;
508 for i := 0 to 4 do begin
509 s := GikoSys.GetTokenIndex(Line, #1, i);
515 //threadItem := BBSsFindThreadFromURL( s );
516 //if threadItem <> nil then begin
517 // BoardList.Add( threadItem.ParentBoard.URL );
520 1: Result.BoardTitle := s;
521 2: Result.FileName := s;
522 3: Result.ThreadTitle := s;
523 4: Result.RoundName := s;
532 function TRoundList.ParseOldRoundBoardLine(Line: string): TRoundItem;
538 Result := TRoundItem.Create;
539 Result.ThreadTitle := '';
540 Result.FileName := '';
541 Result.RoundType := grtBoard;
542 for i := 0 to 2 do begin
543 s := GikoSys.GetTokenIndex(Line, #1, i);
548 board := BBSs[ 0 ].FindBBSID( s );
549 if board <> nil then begin
550 Result.URL := board.URL;
552 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');
555 1: Result.FBoardTitle := s;
556 2: Result.RoundName := s;
565 function TRoundList.ParseOldRoundThreadLine(Line: string): TRoundItem;
571 // threadItem: TThreadItem;
574 Result := TRoundItem.Create;
575 Result.RoundType := grtItem;
576 for i := 0 to 4 do begin
577 s := GikoSys.GetTokenIndex(Line, #1, i);
581 1: Result.BoardTitle := s;
584 Result.FileName := s;
585 board := BBSs[ 0 ].FindBBSID(bbsID);
586 if board <> nil then begin
587 buf := Copy(board.GetSendURL,1,LastDelimiter('/', board.GetSendURL)-1);
588 Result.URL := buf + '/read.cgi/'+ board.BBSID+ '/' +ChangeFileExt(s,'') + '/l50';
590 raise Exception.Create('
\82±
\82Ì
\8f\84\89ñ
\82Í
\93Ç
\82Ý
\8d\9e\82ß
\82È
\82¢
\82æ');
593 3: Result.ThreadTitle := s;
594 4: Result.RoundName := s;