Develop and Download Open Source Software

Browse CVS Repository

Annotation of /gikonavigoeson/gikonavi/RoundData.pas

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.19.2.1 - (hide annotations) (download) (as text)
Wed May 18 14:36:10 2005 UTC (18 years, 11 months ago) by h677
Branch: remodeling
Changes since 1.19: +312 -210 lines
File MIME type: text/x-pascal
巡回の管理の最適化

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

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26