OSDN Git Service

巡回予約名の上書き時に反映されない不具合の修正
[gikonavigoeson/gikonavi.git] / RoundData.pas
1 unit RoundData;
2
3 interface
4
5 uses
6         Windows, Messages, SysUtils, Classes,
7         GikoSystem, BoardGroup;
8
9 type
10         TGikoRoundType = (grtBoard, grtItem);
11         TRoundItem = class;
12
13         TRoundList = class(TObject)
14         private
15         FOldFileRead: Boolean;
16                 FBoardList: TList;
17                 FItemList: TList;
18                 function GetCount(RoundType: TGikoRoundType): Integer;
19                 function GetRoundItem(Index: Integer; RoundType: TGikoRoundType): TRoundItem;
20                 function ParseRoundBoardLine(Line: string):             Boolean;
21                 function ParseRoundThreadLine(Line: string):    Boolean;
22                 function ParseOldRoundBoardLine(Line: string):  Boolean;
23                 function ParseOldRoundThreadLine(Line: string): Boolean;
24         public
25                 RoundNameList: TStringList;
26
27                 constructor Create;
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;
34                 procedure Clear;
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;
43
44                 procedure LoadRoundBoardFile;
45         procedure LoadRoundThreadFile;
46                 procedure SaveRoundFile;
47
48         procedure URLReplace(oldURLs: TStringList; newURLs :TStringList);
49         end;
50
51         TRoundItem = class(TObject)
52         private
53                 FItem           : TObject;
54                 FRoundName: string;
55                 FRoundType: TGikoRoundType;
56                 FTmpURL : string;
57                 FBoolData: Boolean;             //\82¢\82ë\82¢\82ë\8eg\82¤\82å\82£
58                 function GetBoardTitle : string;
59                 function GetThreadTitle : string;
60                 function GetURL : string;
61                 function GetFileName : string;
62         //! \8f\84\89ñ\96¼\8eæ\93¾
63         function GetRoundName : string;
64         public
65                 constructor Create;
66                 property Item : TObject read FItem;
67                 property RoundName: string read GetRoundName;
68                 property RoundType: TGikoRoundType read FRoundType write FRoundType;
69                 property URL : string read GetURL;
70                 property TmpURL : string read FTmpURL write FTmpURL;
71                 property BoardTitle: string read GetBoardTitle;
72                 property ThreadTitle: string read GetThreadTitle;
73                 property FileName: string read GEtFileName;
74                 property BoolData: Boolean read FBoolData write FBoolData;
75         end;
76
77 var
78         RoundList: TRoundList;
79
80 implementation
81 const
82         ROUND_BOARD_FILENAME: string = 'RoundBoard.2ch';        //\82 \82Æ\82ÅBoardGroup\82Ö\88Ú\93®
83         ROUND_ITEM_FILENAME: string  = 'RoundItem.2ch';         //\93¯\8fã
84         ROUND_INDEX_VERSION: string = '2.00';
85     ERROR_BOARD_FILENAME: string = 'ErrorBoard.2ch'; //Error\8ds\82ð\95Û\8aÇ\82·\82é
86     ERROR_ITEM_FILENAME: string = 'ErrorItem.2ch'; //Error\8ds\82ð\95Û\8aÇ\82·\82é
87 constructor TRoundItem.Create;
88 begin
89         inherited Create;
90 end;
91 function TRoundItem.GetBoardTitle : string;
92 begin
93         Result := '';
94         if( Self.FItem <> nil) then begin
95                 if( Self.FItem is TBoard) then begin
96                         Result := TBoard(Self.FItem).Title;
97                 end else if( Self.FItem is TThreadItem) then begin
98                         Result := TThreadItem(Self.FItem).ParentBoard.Title;
99                 end;
100         end;
101 end;
102 function TRoundItem.GetThreadTitle : string;
103 begin
104         Result := '';
105         if( Self.FItem <> nil) then begin
106                 if( Self.FItem is TThreadItem) then begin
107                         Result := TThreadItem(Self.FItem).Title;
108                 end;
109         end;
110 end;
111 function TRoundItem.GetURL      : string;
112 begin
113         Result := '';
114         if( Self.FItem <> nil) then begin
115                 if( Self.FItem is TBoard) then begin
116                         Result := TBoard(Self.FItem).URL;
117                 end else if( Self.FItem is TThreadItem) then begin
118                         Result := TThreadItem(Self.FItem).URL;
119                 end;
120         end;
121 end;
122 function TRoundItem.GetFileName : string;
123 begin
124         Result := '';
125         if( Self.FItem <> nil) then begin
126                 if( Self.FItem is TThreadItem) then begin
127                         Result := TThreadItem(Self.FItem).FileName;
128                 end;
129         end;
130 end;
131 //! \8f\84\89ñ\96¼\8eæ\93¾
132 function TRoundItem.GetRoundName : string;
133 begin
134         Result := '';
135         if( Self.FItem <> nil) then begin
136                 if( Self.FItem is TBoard) then begin
137                         Result := TBoard(Self.FItem).RoundName;
138                 end else if( Self.FItem is TThreadItem) then begin
139                         Result := TThreadItem(Self.FItem).RoundName;
140                 end;
141         end;
142 end;
143
144 constructor TRoundList.Create;
145 begin
146         inherited;
147         FBoardList := TList.Create;
148         FItemList := TList.Create;
149         RoundNameList := TStringList.Create;
150         RoundNameList.Sorted := True;
151         RoundNameList.Duplicates := dupIgnore;
152     FOldFileRead := false;
153 end;
154
155 destructor TRoundList.Destroy;
156 begin
157         RoundNameList.Free;
158         Clear;
159         FBoardList.Free;
160         FItemList.Free;
161         //inherited;
162 end;
163
164 function TRoundList.Add(Board: TBoard): Integer;
165 var
166         idx: Integer;
167         Item: TRoundItem;
168 begin
169     Result := -1;
170         idx := Find(Board);
171         //RoundNameList.Add(Board.RoundName);
172         if idx = -1 then begin
173                 Item := TRoundItem.Create;
174                 Item.FItem := Board;
175 //              Item.BBSType := gbt2ch; //\82Æ\82è\82 \82¦\82¸
176                 Item.RoundType := grtBoard;
177 //      Item.Item := Board;
178                 //Item.URL := Board.URL;
179                 //Item.BoardTitle := Board.Title;
180                 //Item.ThreadTitle := '';
181                 //Item.FileName := '';
182                 //Item.RoundName := Board.RoundName;
183                 Result := FBoardList.Add(Item);
184         end;
185 end;
186
187 function TRoundList.Add(ThreadItem: TThreadItem): Integer;
188 var
189         idx: Integer;
190         Item: TRoundItem;
191 begin
192     Result := -1;
193         idx := Find(ThreadItem);
194         //RoundNameList.Add(ThreadItem.RoundName);
195         if idx = -1 then begin
196                 Item := TRoundItem.Create;
197                 Item.FItem := ThreadItem;
198 //              Item.BBSType := gbt2ch; //\82Æ\82è\82 \82¦\82¸
199                 Item.RoundType := grtItem;
200 //              Item.Item := ThreadItem;
201                 //Item.URL := Threaditem.URL;
202                 //Item.BoardTitle := ThreadItem.ParentBoard.Title;
203                 //Item.ThreadTitle := ThreadItem.Title;
204                 //Item.FileName := ThreadItem.FileName;
205                 //Item.RoundName := ThreadItem.RoundName;
206                 Result := FItemList.Add(Item);
207         end;
208 end;
209
210 procedure TRoundList.Delete(Board: TBoard);
211 var
212         idx: Integer;
213 //      Item: TRoundItem;
214 begin
215         idx := Find(Board);
216         if idx <> -1 then begin
217                 TBoard(TRoundItem(FBoardList[idx]).FItem).RoundName := '';
218                 TRoundItem(FBoardList[idx]).Free;
219                 FBoardList.Delete(idx);
220         end;
221 end;
222
223 procedure TRoundList.Delete(ThreadItem: TThreadItem);
224 var
225         idx: Integer;
226 //      Item: TRoundItem;
227 begin
228         idx := Find(ThreadItem);
229         if idx <> -1 then begin
230         TThreadItem(TRoundItem(FItemList[idx]).FItem).RoundName := '';
231                 TRoundItem(FItemList[idx]).Free;
232                 FItemList.Delete(idx);
233         end;
234 end;
235
236 procedure TRoundList.Clear;
237 var
238         i: Integer;
239 begin
240         for i := FBoardList.Count - 1 downto 0 do begin
241         if FBoardList[i] <> nil then
242                         TRoundItem(FBoardList[i]).Free;
243                 FBoardList.Delete(i);
244         end;
245     FBoardList.Capacity := FBoardList.Count;
246         for i := FItemList.Count - 1 downto 0 do begin
247         if FItemList[i] <> nil then
248                         TRoundItem(FItemList[i]).Free;
249                 FItemList.Delete(i);
250         end;
251     FItemList.Capacity := FItemList.Count;
252 end;
253
254 function TRoundList.Find(Board: TBoard): Integer;
255 var
256         i: Integer;
257         Item: TRoundItem;
258 begin
259         Result := -1;
260         for i := 0 to FBoardList.Count - 1 do begin
261                 Item := TRoundItem(FBoardList[i]);
262                 if Item.FRoundType <> grtBoard then Continue;
263                 if Item.FItem = Board then begin
264                         Result := i;
265                         Exit;
266                 end;
267         end;
268 end;
269
270 function TRoundList.Find(ThreadItem: TThreadItem): Integer;
271 var
272         i: Integer;
273         Item: TRoundItem;
274 begin
275         Result := -1;
276         for i := 0 to FItemList.Count - 1 do begin
277                 Item := TRoundItem(FItemList[i]);
278                 if Item.FRoundType <> grtItem then Continue;
279                 if Item.FItem = ThreadItem then begin
280                         Result := i;
281                         Exit;
282                 end;
283         end;
284 end;
285 function TRoundList.Find(URL: string; RoundType: TGikoRoundType): Integer;
286 var
287         i: Integer;
288         Item: TRoundItem;
289 begin
290         Result := -1;
291     if RoundType = grtItem then begin
292                 for i := 0 to FItemList.Count - 1 do begin
293                         Item := TRoundItem(FItemList[i]);
294                         if Item.FRoundType <> RoundType then Continue;
295                         if Item.URL = URL then begin
296                                 Result := i;
297                                 Exit;
298                         end;
299                 end;
300         end else begin
301                 for i := 0 to FBoardList.Count - 1 do begin
302                         Item := TRoundItem(FBoardList[i]);
303                         if Item.FRoundType <> RoundType then Continue;
304                         if Item.URL = URL then begin
305                                 Result := i;
306                                 Exit;
307                         end;
308                 end;
309     end;
310 end;
311 procedure TRoundList.Delete(URL: string; RoundType: TGikoRoundType);
312 var
313         idx: Integer;
314         Item: TRoundItem;
315     board: TBoard;
316     threadItem: TThreadItem;
317 begin
318         idx := Find(URL, RoundType);
319         if idx <> -1 then begin
320
321         if RoundType = grtBoard then begin
322                         Item := TRoundItem(FBoardList[idx]);
323                         board := TBoard(Item);
324                         Item.Free;
325                         FBoardList.Delete(idx);
326                         //board := BBSsFindBoardFromURL(URL);
327                         if board <> nil then begin
328                                 board.Round := False;
329                                 board.RoundName := '';
330                         end;
331                 end else begin
332                         Item := TRoundItem(FItemList[idx]);
333                         threadItem := TThreadItem(Item.FItem);
334                         Item.Free;
335                         FItemList.Delete(idx);
336
337                         //threadItem := BBSsFindThreadFromURL(URL);
338             if threadItem <> nil then begin
339                     threadItem.Round := false;
340                 threadItem.RoundName := '';
341             end;
342         end;
343         end;
344 end;
345 {
346 procedure TRoundList.SetRoundName(Board: TBoard; RoundName: string);
347 var
348         idx: Integer;
349         Item: TRoundItem;
350 begin
351         idx := Find(Board);
352         if idx <> -1 then begin
353                 Item := TRoundItem(FBoardList[idx]);
354                 Item.RoundName := RoundName;
355         end;
356 end;
357 }
358 {
359 procedure TRoundList.SetRoundName(ThreadItem: TThreadItem; RoundName: string);
360 var
361         idx: Integer;
362         Item: TRoundItem;
363 begin
364         idx := Find(ThreadItem);
365         if idx <> -1 then begin
366                 Item := TRoundItem(FItemList[idx]);
367                 Item.RoundName := RoundName;
368         end;
369 end;
370 }
371 function TRoundList.GetCount(RoundType: TGikoRoundType): Integer;
372 begin
373         Result := 0;
374         if RoundType = grtBoard then
375                 Result := FBoardList.Count
376         else if RoundType = grtItem then
377                 Result := FItemList.Count;
378 end;
379
380 function TRoundList.GetRoundItem(Index: Integer; RoundType: TGikoRoundType): TRoundItem;
381 begin
382         Result := nil;
383         if RoundType = grtBoard then begin
384                 if (Index >= 0) and (Index < FBoardList.Count) then
385                         Result := TRoundItem(FBoardList[Index]);
386         end else if RoundType = grtItem then begin
387                 if (Index >= 0) and (Index < FItemList.Count) then
388                         Result := TRoundItem(FItemList[Index]);
389         end;
390 end;
391 procedure TRoundList.LoadRoundBoardFile;
392 var
393         i: Integer;
394         sl: TStringList;
395         FileName, bFileName: string;
396         errorSl: TStringList;
397         errorFileName: string;
398         //Item: TRoundItem;
399         delCount: Integer;
400 begin
401         sl := TStringList.Create;
402         errorSl := TStringList.Create;
403         errorSl.Duplicates := dupIgnore;
404         try
405                 //\83{\81[\83h\8f\84\89ñ\83t\83@\83C\83\8b\93Ç\82Ý\8d\9e\82Ý
406                 FileName := GikoSys.GetConfigDir + ROUND_BOARD_FILENAME;
407                 bFileName := GikoSys.GetConfigDir + '~' + ROUND_BOARD_FILENAME;
408                 //\83G\83\89\81[\8ds\95Û\91\83t\83@\83C\83\8b\93Ç\82Ý\8d\9e\82Ý
409                 errorFileName := GikoSys.GetConfigDir + ERROR_BOARD_FILENAME;
410
411                 if FileExists(FileName) then begin
412                         sl.LoadFromFile(FileName);
413                         if FileExists(bFileName) then
414                                 DeleteFile(bFileName);
415                         //\83o\83b\83N\83A\83b\83v\97p\82Ì\83t\83@\83C\83\8b\82ð\8dì\90¬\82·\82é
416                         sl.SaveToFile(bFileName);
417                         if FileExists(errorFileName) then begin
418                                 try
419                         errorSl.LoadFromFile(errorFileName);
420                 except
421                 end;
422             end;
423             //Item := TRoundItem.Create;
424             delCount := 0;
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                                         if not ParseRoundBoardLine(sl[i - delCount]) then begin
429                                                 errorSl.Add( sl[i - delCount] );
430                         sl.Delete(i- delCount);
431                         Inc(delCount);
432                     end;
433                                 end;
434             end else begin
435                 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Å
436                                         for i := 1 to sl.Count - 1 do begin
437                                                 if not ParseOldRoundBoardLine(sl[i - delCount]) then begin
438                                                         errorSl.Add( sl[i- delCount] );
439                                 sl.Delete(i- delCount);
440                             Inc(delCount);
441                         end;
442                                         end;
443                 end else
444                         FOldFileRead := true;
445             end;
446                 end;
447         if errorSl.Count > 0 then
448                 errorSl.SaveToFile(errorFileName);
449         finally
450         errorSl.Free;
451                 sl.Free;
452         end;
453 end;
454 procedure TRoundList.LoadRoundThreadFile;
455 var
456         i: Integer;
457 //    j: Integer;
458         sl: TStringList;
459         FileName, bFileName: string;
460     errorSl: TStringList;
461     errorFileName: string;
462 //      Item: TRoundItem;
463     delCount: Integer;
464 //    boardList : TStringList;
465 begin
466 //    boardList := TStringList.Create;
467 //    boardList.Duplicates := dupIgnore;
468     errorSl := TStringList.Create;
469         errorSl.Duplicates := dupIgnore;
470         sl := TStringList.Create;
471         try
472                 //\83X\83\8c\8f\84\89ñ\83t\83@\83C\83\8b\93Ç\82Ý\8d\9e\82Ý
473                 FileName := GikoSys.GetConfigDir + ROUND_ITEM_FILENAME;
474                 bFileName := GikoSys.GetConfigDir + '~' + ROUND_ITEM_FILENAME;
475                 //\83G\83\89\81[\8ds\95Û\91\83t\83@\83C\83\8b\93Ç\82Ý\8d\9e\82Ý
476         errorFileName := GikoSys.GetConfigDir + ERROR_ITEM_FILENAME;
477                 if FileExists(FileName) then begin
478                         sl.LoadFromFile(FileName);
479                         if FileExists(bFileName) then
480                                 DeleteFile(bFileName);
481                         sl.SaveToFile(bFileName);
482                         if FileExists(errorFileName) then begin
483                 try
484                         errorSl.LoadFromFile(errorFileName);
485                 except
486                 end;
487             end;
488             //Item := TRoundItem.Create;
489             delCount := 0;
490                         //\82P\8ds\96Ú\82Í\83o\81[\83W\83\87\83\93
491             if sl[0] = ROUND_INDEX_VERSION then begin
492                                 for i := 1 to sl.Count - 1 do begin
493                                         if not ParseRoundThreadLine(sl[i - delCount]) then begin
494                                                 errorSl.Add(sl[i - delCount]);
495                         sl.Delete(i - delCount);
496                         Inc(delCount);
497                     end;
498                 end;
499                         end else begin
500                                 LoadRoundBoardFile;
501                                 for i := 1 to sl.Count - 1 do begin
502                                         if not ParseOldRoundThreadLine(sl[i - delCount]) then begin
503                                                 errorSl.Add(sl[i - delCount]);
504                         sl.Delete(i - delCount);
505                         Inc(delCount);
506                     end;
507                                 end;
508             end;
509 //              j := boardList.Count - 1;
510 //          while j >= 0 do begin
511 //                      GikoSys.ReadSubjectFile( BBSsFindBoardFromURL( boardList[j] ) );
512 //                  boardList.Delete(j);
513 //              Dec(j);
514 //              end;
515             if errorSl.Count > 0 then
516                 errorSl.SaveToFile(errorFileName);
517                 end;
518         finally
519                 errorSl.Free;
520                 sl.Free;
521 //        boardList.Free;
522         end;
523 end;
524 procedure TRoundList.SaveRoundFile;
525 var
526         i: integer;
527         FileName: string;
528         sl: TStringList;
529         s: string;
530         Item: TRoundItem;
531 begin
532         GikoSys.ForceDirectoriesEx(GikoSys.GetConfigDir);
533
534         sl := TStringList.Create;
535         try
536                 FileName := GikoSys.GetConfigDir + ROUND_BOARD_FILENAME;
537                 sl.Add(ROUND_INDEX_VERSION);
538                 for i := 0 to FBoardList.Count - 1 do begin
539                         Item := TRoundItem(FBoardList[i]);
540                         try
541                                 if Item.TmpURL <> '' then begin
542                                         s := Item.TmpURL + #1
543                                                  + Item.BoardTitle + #1
544                                                  + Item.RoundName;
545                                 end else begin
546                                         s := Item.URL + #1
547                                                  + Item.BoardTitle + #1
548                                                  + Item.RoundName;
549                                 end;
550                                 sl.Add(s);
551                         except
552                         end;
553                 end;
554                 sl.SaveToFile(FileName);
555                 sl.Clear;
556                 FileName := GikoSys.GetConfigDir + ROUND_ITEM_FILENAME;
557                 sl.Add(ROUND_INDEX_VERSION);
558                 for i := 0 to FItemList.Count - 1 do begin
559                         Item := TRoundItem(FItemList[i]);
560                         try
561                                 if Item.TmpURL <> '' then begin
562                                         s := Item.TmpURL + #1
563                                          + Item.BoardTitle + #1
564                                          + Item.FileName + #1
565                                          + Item.ThreadTitle + #1
566                                          + Item.RoundName;
567                                 end else begin
568                                         s := Item.URL + #1
569                                          + Item.BoardTitle + #1
570                                          + Item.FileName + #1
571                                          + Item.ThreadTitle + #1
572                                          + Item.RoundName;
573                                 end;
574                                 sl.Add(s);
575                         except
576                         end;
577                 end;
578                 sl.SaveToFile(FileName);
579         finally
580                 sl.Free;
581         end;
582 end;
583 function TRoundList.ParseRoundBoardLine(Line: string): Boolean;
584 var
585         s: string;
586         roundname: string;
587         board: TBoard;
588         i: Integer;
589 begin
590         //Result := TRoundItem.Create;
591         //Result.ThreadTitle := '';
592         //Result.FileName := '';
593         //Result.RoundType := grtBoard;
594         board := nil;
595         for i := 0 to 2 do begin
596                 s := GikoSys.GetTokenIndex(Line, #1, i);
597                 try
598                         case i of
599                                 0:
600                                 begin
601                                         board := BBSsFindBoardFromURL(s);
602                                         //Result.URL := s;
603                                 end;
604                                 //1: Result.BoardTitle := s;
605                                 2: roundname := s;
606                         end;
607                 except
608                         Result := false;
609                         Exit;
610                 end;
611         end;
612         if( board <> nil ) then begin
613                 if not board.Round then begin
614                         board.RoundName := roundname;
615                         RoundNameList.Add(roundname);
616                         //RoundNameList.Find(roundname, i);
617                         //board.RoundName := PChar(RoundNameList[i]);
618                         board.Round := true;
619                 end;
620                 Result := true;
621         end else begin
622                 Result := false;
623         end;
624 end;
625
626 function TRoundList.ParseRoundThreadLine(Line: string): Boolean;
627 var
628         s: string;
629         roundname: string;
630         threadItem: TThreadItem;
631         i: Integer;
632 //    threadItem: TThreadItem;
633 begin
634         //Result := TRoundItem.Create;
635         //Result.RoundType := grtItem;
636         threadItem := nil;
637         for i := 0 to 4 do begin
638                 s := GikoSys.GetTokenIndex(Line, #1, i);
639                 try
640                         case i of
641                                 0:
642                                 begin
643                                         //Result.URL := s;
644                                         threadItem := BBSsFindThreadFromURL( s );
645                                         //if threadItem <> nil then begin
646                                         //    BoardList.Add( threadItem.ParentBoard.URL );
647                                         //end;
648                                 end;
649                                 //1: Result.BoardTitle := s;
650                                 //2: Result.FileName := s;
651                                 //3: Result.ThreadTitle := s;
652                                 4: roundname := s;
653                         end;
654                 except
655                         Result := false;
656                         Exit;
657                 end;
658         end;
659         if( threadItem <> nil ) then begin
660                 if not threadItem.Round then begin
661                         threadItem.RoundName := roundname;
662                         RoundNameList.Add(roundname);
663                         //RoundNameList.Find(roundname, i);
664                         //threadItem.RoundName := PChar(RoundNameList[i]);
665                         threadItem.Round := True;
666                 end;
667                 Result := true;
668         end else begin
669                 Result := false;
670         end;
671 end;
672
673 function TRoundList.ParseOldRoundBoardLine(Line: string): Boolean;
674         var
675         i: Integer;
676         s: string;
677         roundname: string;
678         board: TBoard;
679 begin
680         //Result := TRoundItem.Create;
681         //Result.ThreadTitle := '';
682         //Result.FileName := '';
683         //Result.RoundType := grtBoard;
684         board := nil;
685         for i := 0 to 2 do begin
686                 s := GikoSys.GetTokenIndex(Line, #1, i);
687                 try
688                         case i of
689                                 0:
690                                 begin
691                                         board := BBSs[ 0 ].FindBBSID( s );
692                                         if board = nil then begin
693                                                 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');
694                                         end;
695                                 end;
696                                 //1: Result.FBoardTitle := s;
697                                 2: roundname := s;
698                         end;
699                 except
700                         Result := false;
701                         Exit;
702                 end;
703         end;
704         if( board <> nil ) then begin
705                 if not board.Round then begin
706                         board.RoundName := roundname;
707                         RoundNameList.Add(roundname);
708                         //RoundNameList.Find(roundname, i);
709                         //board.RoundName := PChar(RoundNameList[i]);
710                         board.Round := true;
711                 end;
712                 Result := true;
713         end else begin
714                 Result := false;
715         end;
716 end;
717
718 function TRoundList.ParseOldRoundThreadLine(Line: string): Boolean;
719         var
720         i: Integer;
721         s: string;
722         roundname : string;
723         buf: string;
724         board: TBoard;
725         threadItem: TThreadItem;
726         bbsID: string;
727 begin
728 //      Result := TRoundItem.Create;
729 //      Result.RoundType := grtItem;
730         threadItem := nil;
731         for i := 0 to 4 do begin
732                 s := GikoSys.GetTokenIndex(Line, #1, i);
733                 try
734                         case i of
735                                 0: bbsID := s;
736                                 //1: Result.BoardTitle := s;
737                                 2:
738                                 begin
739                                         //Result.FileName := s;
740                                         board := BBSs[ 0 ].FindBBSID(bbsID);
741                                         if board <> nil then begin
742                                                 buf := Copy(board.GetSendURL,1,LastDelimiter('/', board.GetSendURL)-1);
743                                                 buf := buf + '/read.cgi/'+ board.BBSID+ '/' +ChangeFileExt(s,'') + '/l50';
744                                                 threadItem := BBSsFindThreadFromURL(buf);
745                                         end else begin
746                                                 raise Exception.Create('\82±\82Ì\8f\84\89ñ\82Í\93Ç\82Ý\8d\9e\82ß\82È\82¢\82æ');
747                                         end;
748                                 end;
749                                 //3: Result.ThreadTitle := s;
750                                 4: roundname := s;
751                         end;
752                 except
753                         Result := false;
754                         Exit;
755                 end;
756         end;
757         if( threadItem <> nil ) then begin
758                 if not threadItem.Round then begin
759                         threadItem.RoundName := roundname;
760                         RoundNameList.Add(roundname);
761                         //RoundNameList.Find(roundname, i);
762                         //threadItem.RoundName := PChar(RoundNameList[i]);
763                         threadItem.Round := true;
764                 end;
765                 Result := true;
766         end else begin
767                 Result := false;
768         end;
769
770 end;
771 procedure  TRoundList.URLReplace(oldURLs: TStringList; newURLs :TStringList);
772 var
773         i: Integer;
774         j: Integer;
775         tempString: string;
776         tmpURL: string;
777         oldHost: string;
778         oldBoardName: string;
779         newHost: string;
780         newBoardName: string;
781 begin
782         if oldURLs.Count <> newURLs.Count then
783                 Exit;
784         //\82±\82±\82©\82ç\81ABoard\82ÌURL\82Ì\95Ï\8dX
785         for j :=0 to oldURLs.Count - 1 do begin
786                 for i :=0 to FBoardList.Count - 1 do begin
787                         if TRoundItem(FBoardList[i]).URL = oldURLs[j] then
788                                 TRoundItem(FBoardList[i]).TmpURL := newURLs[j];
789                 end;
790         end;
791         //\82±\82±\82Ü\82Å\81ABoard\82ÌURL\82Ì\95Ï\8dX
792
793         //\82±\82±\82©\82ç\81AThread\82ÌURL\82Ì\95Ï\8dX
794         //\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
795         for i := 0 to oldURLs.Count - 1 do begin
796                 tmpURL                  := Copy(oldURLs[i], 1, Length(oldURLs[i]) -1);
797                 oldHost                 := Copy(tmpURL, 1, LastDelimiter('/', tmpURL) );
798                 oldBoardName    := Copy(tmpURL, LastDelimiter('/', tmpURL), Length(tmpURL) ) + '/';
799                 tmpURL                  := Copy(newURLs[i], 1, Length(newURLs[i]) -1);
800                 newHost                 := Copy(tmpURL, 1, LastDelimiter('/', tmpURL) );
801                 newBoardName    := Copy(tmpURL, LastDelimiter('/', tmpURL), Length(tmpURL) ) + '/';
802
803                 for j := 0 to FItemList.Count - 1 do begin
804                         tempString := TRoundItem(FItemList[j]).URL;
805                         if ( AnsiPos(oldBoardName, tempString) <> 0 ) and ( AnsiPos(oldHost, tempString ) <> 0 ) then begin
806                                 tempString := StringReplace(tempString, oldHost, newHost,[]);
807                                 TRoundItem(FItemList[j]).TmpURL := tempString;
808                         end;
809                 end;
810         end;
811         //\82±\82±\82Ü\82Å\81AThread\82ÌURL\82Ì\95Ï\8dX
812
813 end;
814
815 end.