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;
48 procedure URLReplace(oldURLs: TStringList; newURLs :TStringList);
51 TRoundItem = class(TObject)
53 // FBBSType: TGikoBBSType;
55 FRoundType: TGikoRoundType;
61 FBoolData: Boolean; //
\82¢
\82ë
\82¢
\82ë
\8eg
\82¤
\82å
\82£
65 //property BBSType: TGikoBBSType read FBBSType write FBBSType;
66 property RoundName: string read FRoundName write FRoundName;
67 property RoundType: TGikoRoundType read FRoundType write FRoundType;
68 //property Item : TObject read FItem write FItem;
69 property URL : string read FURL write FURL;
70 property BoardTitle: string read FBoardTitle write FBoardTitle;
71 property ThreadTitle: string read FThreadTitle write FThreadTitle;
72 property FileName: string read FFileName write FFileName;
73 property BoolData: Boolean read FBoolData write FBoolData;
77 RoundList: TRoundList;
81 ROUND_BOARD_FILENAME: string = 'RoundBoard.2ch'; //
\82 \82Æ
\82ÅBoardGroup
\82Ö
\88Ú
\93®
82 ROUND_ITEM_FILENAME: string = 'RoundItem.2ch'; //
\93¯
\8fã
83 ROUND_INDEX_VERSION: string = '2.00';
84 ERROR_BOARD_FILENAME: string = 'ErrorBoard.2ch'; //Error
\8ds
\82ð
\95Û
\8aÇ
\82·
\82é
85 ERROR_ITEM_FILENAME: string = 'ErrorItem.2ch'; //Error
\8ds
\82ð
\95Û
\8aÇ
\82·
\82é
86 constructor TRoundItem.Create;
90 constructor TRoundList.Create;
93 FBoardList := TList.Create;
94 FItemList := TList.Create;
95 RoundNameList := TStringList.Create;
96 RoundNameList.Sorted := True;
97 RoundNameList.Duplicates := dupIgnore;
98 FOldFileRead := false;
101 destructor TRoundList.Destroy;
110 function TRoundList.Add(Board: TBoard): Integer;
117 if idx = -1 then begin
118 Item := TRoundItem.Create;
119 // Item.BBSType := gbt2ch; //
\82Æ
\82è
\82 \82¦
\82¸
120 Item.RoundType := grtBoard;
121 // Item.Item := Board;
122 Item.URL := Board.URL;
123 Item.BoardTitle := Board.Title;
124 Item.ThreadTitle := '';
126 Item.RoundName := Board.RoundName;
127 Result := FBoardList.Add(Item);
131 function TRoundList.Add(ThreadItem: TThreadItem): Integer;
137 idx := Find(ThreadItem);
138 if idx = -1 then begin
139 Item := TRoundItem.Create;
140 // Item.BBSType := gbt2ch; //
\82Æ
\82è
\82 \82¦
\82¸
141 Item.RoundType := grtItem;
142 // Item.Item := ThreadItem;
143 Item.URL := Threaditem.URL;
144 Item.BoardTitle := ThreadItem.ParentBoard.Title;
145 Item.ThreadTitle := ThreadItem.Title;
146 Item.FileName := ThreadItem.FileName;
147 Item.RoundName := ThreadItem.RoundName;
148 Result := FItemList.Add(Item);
152 procedure TRoundList.Delete(Board: TBoard);
158 if idx <> -1 then begin
159 TRoundItem(FBoardList[idx]).Free;
160 FBoardList.Delete(idx);
164 procedure TRoundList.Delete(ThreadItem: TThreadItem);
169 idx := Find(ThreadItem);
170 if idx <> -1 then begin
171 TRoundItem(FItemList[idx]).Free;
172 FItemList.Delete(idx);
176 procedure TRoundList.Clear;
180 for i := FBoardList.Count - 1 downto 0 do begin
181 if FBoardList[i] <> nil then
182 TRoundItem(FBoardList[i]).Free;
183 FBoardList.Delete(i);
185 FBoardList.Capacity := FBoardList.Count;
186 for i := FItemList.Count - 1 downto 0 do begin
187 if FItemList[i] <> nil then
188 TRoundItem(FItemList[i]).Free;
191 FItemList.Capacity := FItemList.Count;
194 function TRoundList.Find(Board: TBoard): Integer;
200 for i := 0 to FBoardList.Count - 1 do begin
201 Item := TRoundItem(FBoardList[i]);
202 if Item.FRoundType <> grtBoard then Continue;
203 if Item.FURL = Board.URL then begin
210 function TRoundList.Find(ThreadItem: TThreadItem): Integer;
216 for i := 0 to FItemList.Count - 1 do begin
217 Item := TRoundItem(FItemList[i]);
218 if Item.FRoundType <> grtItem then Continue;
219 if Item.FURL = ThreadItem.URL then begin
225 function TRoundList.Find(URL: string; RoundType: TGikoRoundType): Integer;
231 if RoundType = grtItem then begin
232 for i := 0 to FItemList.Count - 1 do begin
233 Item := TRoundItem(FItemList[i]);
234 if Item.FRoundType <> RoundType then Continue;
235 if Item.FURL = URL then begin
241 for i := 0 to FBoardList.Count - 1 do begin
242 Item := TRoundItem(FBoardList[i]);
243 if Item.FRoundType <> RoundType then Continue;
244 if Item.FURL = URL then begin
251 procedure TRoundList.Delete(URL: string; RoundType: TGikoRoundType);
256 threadItem: TThreadItem;
258 idx := Find(URL, RoundType);
259 if idx <> -1 then begin
261 if RoundType = grtBoard then begin
262 Item := TRoundItem(FBoardList[idx]);
264 FBoardList.Delete(idx);
265 board := BBSsFindBoardFromURL(URL);
266 if board <> nil then begin
267 board.Round := False;
268 board.RoundName := '';
271 Item := TRoundItem(FItemList[idx]);
273 FItemList.Delete(idx);
275 threadItem := BBSsFindThreadFromURL(URL);
276 if threadItem <> nil then begin
277 threadItem.Round := false;
278 threadItem.RoundName := '';
284 procedure TRoundList.SetRoundName(Board: TBoard; RoundName: string);
290 if idx <> -1 then begin
291 Item := TRoundItem(FBoardList[idx]);
292 Item.RoundName := RoundName;
296 procedure TRoundList.SetRoundName(ThreadItem: TThreadItem; RoundName: string);
301 idx := Find(ThreadItem);
302 if idx <> -1 then begin
303 Item := TRoundItem(FItemList[idx]);
304 Item.RoundName := RoundName;
308 function TRoundList.GetCount(RoundType: TGikoRoundType): Integer;
311 if RoundType = grtBoard then
312 Result := FBoardList.Count
313 else if RoundType = grtItem then
314 Result := FItemList.Count;
317 function TRoundList.GetRoundItem(Index: Integer; RoundType: TGikoRoundType): TRoundItem;
320 if RoundType = grtBoard then begin
321 if (Index >= 0) and (Index < FBoardList.Count) then
322 Result := TRoundItem(FBoardList[Index]);
323 end else if RoundType = grtItem then begin
324 if (Index >= 0) and (Index < FItemList.Count) then
325 Result := TRoundItem(FItemList[Index]);
328 procedure TRoundList.LoadRoundBoardFile;
333 errorSl: TStringList;
334 errorFileName: string;
338 sl := TStringList.Create;
339 errorSl := TStringList.Create;
340 errorSl.Duplicates := dupIgnore;
342 //
\83{
\81[
\83h
\8f\84\89ñ
\83t
\83@
\83C
\83\8b\93Ç
\82Ý
\8d\9e\82Ý
343 FileName := GikoSys.GetConfigDir + ROUND_BOARD_FILENAME;
344 //
\83G
\83\89\81[
\8ds
\95Û
\91¶
\83t
\83@
\83C
\83\8b\93Ç
\82Ý
\8d\9e\82Ý
345 errorFileName := GikoSys.GetConfigDir + ERROR_BOARD_FILENAME;
346 if FileExists(FileName) then begin
347 sl.LoadFromFile(FileName);
348 if FileExists(errorFileName) then begin
350 errorSl.LoadFromFile(errorFileName);
354 //Item := TRoundItem.Create;
356 //
\82P
\8ds
\96Ú
\82Í
\83o
\81[
\83W
\83\87\83\93
357 if sl[0] = ROUND_INDEX_VERSION then begin
358 for i := 1 to sl.Count - 1 do begin
359 Item := ParseRoundBoardLine(sl[i - delCount]);
360 if Item <> nil then begin
361 FBoardList.Add(Item);
362 RoundNameList.Add(Item.RoundName);
364 errorSl.Add( sl[i - delCount] );
365 sl.Delete(i- delCount);
370 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Å
371 for i := 1 to sl.Count - 1 do begin
372 Item := ParseOldRoundBoardLine(sl[i - delCount]);
373 if Item <> nil then begin
374 FBoardList.Add(Item);
375 RoundNameList.Add(Item.RoundName);
377 errorSl.Add( sl[i- delCount] );
378 sl.Delete(i- delCount);
383 FOldFileRead := true;
386 if errorSl.Count > 0 then
387 errorSl.SaveToFile(errorFileName);
393 procedure TRoundList.LoadRoundThreadFile;
399 errorSl: TStringList;
400 errorFileName: string;
403 // boardList : TStringList;
405 // boardList := TStringList.Create;
406 // boardList.Duplicates := dupIgnore;
407 errorSl := TStringList.Create;
408 errorSl.Duplicates := dupIgnore;
409 sl := TStringList.Create;
411 //
\83X
\83\8c\8f\84\89ñ
\83t
\83@
\83C
\83\8b\93Ç
\82Ý
\8d\9e\82Ý
412 FileName := GikoSys.GetConfigDir + ROUND_ITEM_FILENAME;
413 //
\83G
\83\89\81[
\8ds
\95Û
\91¶
\83t
\83@
\83C
\83\8b\93Ç
\82Ý
\8d\9e\82Ý
414 errorFileName := GikoSys.GetConfigDir + ERROR_ITEM_FILENAME;
415 if FileExists(FileName) then begin
416 sl.LoadFromFile(FileName);
417 if FileExists(errorFileName) then begin
419 errorSl.LoadFromFile(errorFileName);
423 //Item := TRoundItem.Create;
425 //
\82P
\8ds
\96Ú
\82Í
\83o
\81[
\83W
\83\87\83\93
426 if sl[0] = ROUND_INDEX_VERSION then begin
427 for i := 1 to sl.Count - 1 do begin
428 Item := ParseRoundThreadLine(sl[i - delCount]);
429 if Item <> nil then begin
431 RoundNameList.Add(Item.RoundName);
433 errorSl.Add(sl[i - delCount]);
434 sl.Delete(i - delCount);
440 for i := 1 to sl.Count - 1 do begin
441 Item := ParseOldRoundThreadLine(sl[i - delCount]);
442 if Item <> nil then begin
444 RoundNameList.Add(Item.RoundName);
446 errorSl.Add(sl[i - delCount]);
447 sl.Delete(i - delCount);
452 // j := boardList.Count - 1;
453 // while j >= 0 do begin
454 // GikoSys.ReadSubjectFile( BBSsFindBoardFromURL( boardList[j] ) );
455 // boardList.Delete(j);
458 if errorSl.Count > 0 then
459 errorSl.SaveToFile(errorFileName);
467 procedure TRoundList.SaveRoundFile;
475 GikoSys.ForceDirectoriesEx(GikoSys.GetConfigDir);
477 sl := TStringList.Create;
479 FileName := GikoSys.GetConfigDir + ROUND_BOARD_FILENAME;
480 sl.Add(ROUND_INDEX_VERSION);
481 for i := 0 to FBoardList.Count - 1 do begin
482 Item := TRoundItem(FBoardList[i]);
484 + Item.BoardTitle + #1
488 sl.SaveToFile(FileName);
490 FileName := GikoSys.GetConfigDir + ROUND_ITEM_FILENAME;
491 sl.Add(ROUND_INDEX_VERSION);
492 for i := 0 to FItemList.Count - 1 do begin
493 Item := TRoundItem(FItemList[i]);
495 + Item.BoardTitle + #1
497 + Item.ThreadTitle + #1
501 sl.SaveToFile(FileName);
506 function TRoundList.ParseRoundBoardLine(Line: string): TRoundItem;
511 Result := TRoundItem.Create;
512 Result.ThreadTitle := '';
513 Result.FileName := '';
514 Result.RoundType := grtBoard;
515 for i := 0 to 2 do begin
516 s := GikoSys.GetTokenIndex(Line, #1, i);
523 1: Result.BoardTitle := s;
524 2: Result.RoundName := s;
533 function TRoundList.ParseRoundThreadLine(Line: string): TRoundItem;
537 // threadItem: TThreadItem;
539 Result := TRoundItem.Create;
540 Result.RoundType := grtItem;
541 for i := 0 to 4 do begin
542 s := GikoSys.GetTokenIndex(Line, #1, i);
548 //threadItem := BBSsFindThreadFromURL( s );
549 //if threadItem <> nil then begin
550 // BoardList.Add( threadItem.ParentBoard.URL );
553 1: Result.BoardTitle := s;
554 2: Result.FileName := s;
555 3: Result.ThreadTitle := s;
556 4: Result.RoundName := s;
565 function TRoundList.ParseOldRoundBoardLine(Line: string): TRoundItem;
571 Result := TRoundItem.Create;
572 Result.ThreadTitle := '';
573 Result.FileName := '';
574 Result.RoundType := grtBoard;
575 for i := 0 to 2 do begin
576 s := GikoSys.GetTokenIndex(Line, #1, i);
581 board := BBSs[ 0 ].FindBBSID( s );
582 if board <> nil then begin
583 Result.URL := board.URL;
585 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');
588 1: Result.FBoardTitle := s;
589 2: Result.RoundName := s;
598 function TRoundList.ParseOldRoundThreadLine(Line: string): TRoundItem;
604 // threadItem: TThreadItem;
607 Result := TRoundItem.Create;
608 Result.RoundType := grtItem;
609 for i := 0 to 4 do begin
610 s := GikoSys.GetTokenIndex(Line, #1, i);
614 1: Result.BoardTitle := s;
617 Result.FileName := s;
618 board := BBSs[ 0 ].FindBBSID(bbsID);
619 if board <> nil then begin
620 buf := Copy(board.GetSendURL,1,LastDelimiter('/', board.GetSendURL)-1);
621 Result.URL := buf + '/read.cgi/'+ board.BBSID+ '/' +ChangeFileExt(s,'') + '/l50';
623 raise Exception.Create('
\82±
\82Ì
\8f\84\89ñ
\82Í
\93Ç
\82Ý
\8d\9e\82ß
\82È
\82¢
\82æ');
626 3: Result.ThreadTitle := s;
627 4: Result.RoundName := s;
635 procedure TRoundList.URLReplace(oldURLs: TStringList; newURLs :TStringList);
642 oldBoardName: string;
644 newBoardName: string;
646 if oldURLs.Count <> newURLs.Count then
648 //
\82±
\82±
\82©
\82ç
\81ABoard
\82ÌURL
\82Ì
\95Ï
\8dX
649 for j :=0 to oldURLs.Count - 1 do begin
650 for i :=0 to FBoardList.Count - 1 do begin
651 if TRoundItem(FBoardList[i]).FURL = oldURLs[j] then
652 TRoundItem(FBoardList[i]).FURL := newURLs[j];
655 //
\82±
\82±
\82Ü
\82Å
\81ABoard
\82ÌURL
\82Ì
\95Ï
\8dX
657 //
\82±
\82±
\82©
\82ç
\81AThread
\82ÌURL
\82Ì
\95Ï
\8dX
658 //
\96Ê
\93|
\82¾
\82¯
\82Çthread
\82Í
\82»
\82ê
\82¼
\82êURL
\82ð
\83`
\83\83\83b
\83N
\82µ
\82È
\82ª
\82ç
\82â
\82Á
\82Ä
\82©
\82È
\82«
\82á
\82¢
\82¯
\82È
\82¢
\81B
659 for i := 0 to oldURLs.Count - 1 do begin
660 tmpURL := Copy(oldURLs[i], 1, Length(oldURLs[i]) -1);
661 oldHost := Copy(tmpURL, 1, LastDelimiter('/', tmpURL) );
662 oldBoardName := Copy(tmpURL, LastDelimiter('/', tmpURL), Length(tmpURL) ) + '/';
663 tmpURL := Copy(newURLs[i], 1, Length(newURLs[i]) -1);
664 newHost := Copy(tmpURL, 1, LastDelimiter('/', tmpURL) );
665 newBoardName := Copy(tmpURL, LastDelimiter('/', tmpURL), Length(tmpURL) ) + '/';
667 for j := 0 to FItemList.Count - 1 do begin
668 tempString := TRoundItem(FItemList[j]).FURL;
669 if ( AnsiPos(oldBoardName, tempString) <> 0 ) and ( AnsiPos(oldHost, tempString ) <> 0 ) then begin
670 tempString := StringReplace(tempString, oldHost, newHost,[]);
671 TRoundItem(FItemList[j]).FURL := tempString;
675 //
\82±
\82±
\82Ü
\82Å
\81AThread
\82ÌURL
\82Ì
\95Ï
\8dX