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.21 - (hide annotations) (download) (as text)
Sat Jun 25 13:01:32 2005 UTC (18 years, 9 months ago) by h677
Branch: MAIN
CVS Tags: v1_50_2_606, v1_51_0_612, v1_51_1_639, v1_50_0_595, marged-Bb50, v1_51_0_626, b51, v1_52_1_658, v1_51_0_622, v1_50_0_598, v1_50_0_590, v1_50_0_593, v1_50_0_596, v1_52_0_646, v1_51_0_611, v1_51_0_620, v1_52_0_644, v1_52_0_643, v1_51_0_634, v1_51_0_635, v1_51_0_636, v1_51_0_637, v1_51_0_632, v1_51_0_633, v1_50_0_603, v1_52_0_647, v1_50_0_604, v1_51_0_638, v1_52_0_648, v1_52_0_645, v1_52_0_651, v1_52_0_650, v1_50_0_606, v1_52_0_652, v1_52_0_642, v1_52_0_654, v1_51_0_616, v1_51_0_614, v1_51_0_615, v1_51_0_613, v1_51_1_640, v1_51_0_618, v1_51_0_619, b50, v1_50_0_600, v1_51_0_630, v1_51_0_631, root-of-draw, v1_50_2_604, v1_51_0_628, v1_51_0_617, root-of-Bb50, root-of-Bb51, v1_50_0_594, v1_52_1_657, v1_52_0_660, v1_50_0_602, v1_51_0_629, v1_51_0_627, v1_50_0_601, v1_51_0_625, v1_51_0_623, v1_50_0_605, v1_52_0_655, v1_52_0_656, v1_52_0_649, v1_50_0_599, v1_51_0_624, v1_51_1_641, v1_51_0_621
Branch point for: Bb52, Bb51, Bb50, Bdraw
Changes since 1.20: +28 -22 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.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 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 h677 1.20 //procedure SetRoundName(Board: TBoard; RoundName: string); overload;
42     //procedure SetRoundName(ThreadItem: TThreadItem; RoundName: string); overload;
43 hi_ 1.1
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.20 //
54     FItem : TObject;
55     FBBSType: TGikoBBSType;
56 hi_ 1.1 FRoundName: string;
57     FRoundType: TGikoRoundType;
58 h677 1.20 //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.20 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.20 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.20 //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.20 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.20 //RoundNameList.Add(Board.RoundName);
167 hi_ 1.1 if idx = -1 then begin
168     Item := TRoundItem.Create;
169 h677 1.20 Item.FItem := Board;
170 hi_ 1.1 // Item.BBSType := gbt2ch; //鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
171     Item.RoundType := grtBoard;
172 h677 1.6 // Item.Item := Board;
173 h677 1.20 //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.20 //RoundNameList.Add(ThreadItem.RoundName);
190 hi_ 1.1 if idx = -1 then begin
191     Item := TRoundItem.Create;
192 h677 1.20 Item.FItem := ThreadItem;
193 hi_ 1.1 // Item.BBSType := gbt2ch; //鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
194     Item.RoundType := grtItem;
195 h677 1.6 // Item.Item := ThreadItem;
196 h677 1.20 //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.20 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.20 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.20 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.20 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.20 if Item.URL = URL then begin
291 h677 1.14 Result := i;
292     Exit;
293     end;
294     end;
295 h677 1.20 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.20 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.20 board := TBoard(Item);
319 h677 1.14 Item.Free;
320     FBoardList.Delete(idx);
321 h677 1.20 //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.20 threadItem := TThreadItem(Item.FItem);
329 h677 1.14 Item.Free;
330     FItemList.Delete(idx);
331    
332 h677 1.20 //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 h677 1.20 {
341 hi_ 1.1 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 h677 1.20 }
353     {
354 hi_ 1.1 procedure TRoundList.SetRoundName(ThreadItem: TThreadItem; RoundName: string);
355     var
356     idx: Integer;
357     Item: TRoundItem;
358     begin
359     idx := Find(ThreadItem);
360     if idx <> -1 then begin
361     Item := TRoundItem(FItemList[idx]);
362     Item.RoundName := RoundName;
363     end;
364     end;
365 h677 1.20 }
366 hi_ 1.1 function TRoundList.GetCount(RoundType: TGikoRoundType): Integer;
367     begin
368     Result := 0;
369     if RoundType = grtBoard then
370     Result := FBoardList.Count
371     else if RoundType = grtItem then
372     Result := FItemList.Count;
373     end;
374    
375     function TRoundList.GetRoundItem(Index: Integer; RoundType: TGikoRoundType): TRoundItem;
376     begin
377     Result := nil;
378     if RoundType = grtBoard then begin
379     if (Index >= 0) and (Index < FBoardList.Count) then
380     Result := TRoundItem(FBoardList[Index]);
381     end else if RoundType = grtItem then begin
382     if (Index >= 0) and (Index < FItemList.Count) then
383     Result := TRoundItem(FItemList[Index]);
384     end;
385     end;
386 h677 1.5 procedure TRoundList.LoadRoundBoardFile;
387 hi_ 1.1 var
388     i: Integer;
389     sl: TStringList;
390 h677 1.19 FileName, bFileName: string;
391     errorSl: TStringList;
392     errorFileName: string;
393 h677 1.20 //Item: TRoundItem;
394 h677 1.19 delCount: Integer;
395 hi_ 1.1 begin
396     sl := TStringList.Create;
397 h677 1.19 errorSl := TStringList.Create;
398 h677 1.7 errorSl.Duplicates := dupIgnore;
399 hi_ 1.1 try
400     //鐃?鐃?鐃?鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
401     FileName := GikoSys.GetConfigDir + ROUND_BOARD_FILENAME;
402 h677 1.19 bFileName := GikoSys.GetConfigDir + '~' + ROUND_BOARD_FILENAME;
403     //鐃?鐃緒申鐃?鐃?鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
404     errorFileName := GikoSys.GetConfigDir + ERROR_BOARD_FILENAME;
405    
406 hi_ 1.1 if FileExists(FileName) then begin
407     sl.LoadFromFile(FileName);
408 h677 1.19 if FileExists(bFileName) then
409     DeleteFile(bFileName);
410     //鐃?鐃?鐃?鐃?鐃?鐃?鐃?鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
411     sl.SaveToFile(bFileName);
412     if FileExists(errorFileName) then begin
413     try
414 h677 1.7 errorSl.LoadFromFile(errorFileName);
415     except
416     end;
417     end;
418     //Item := TRoundItem.Create;
419 h677 1.15 delCount := 0;
420 h677 1.5 //鐃?鐃?鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申
421     if sl[0] = ROUND_INDEX_VERSION then begin
422 deux 1.13 for i := 1 to sl.Count - 1 do begin
423 h677 1.20 if not ParseRoundBoardLine(sl[i - delCount]) then begin
424     errorSl.Add( sl[i - delCount] );
425 h677 1.15 sl.Delete(i- delCount);
426     Inc(delCount);
427 h677 1.7 end;
428 h677 1.5 end;
429     end else begin
430 h677 1.6 if FOldFileRead then begin //鐃?鐃?鐃?鐃?鐃?鐃緒申鐃緒申鐃?鐃?鐃?鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
431 deux 1.13 for i := 1 to sl.Count - 1 do begin
432 h677 1.20 if not ParseOldRoundBoardLine(sl[i - delCount]) then begin
433     errorSl.Add( sl[i- delCount] );
434 h677 1.15 sl.Delete(i- delCount);
435     Inc(delCount);
436 h677 1.7 end;
437 h677 1.6 end;
438     end else
439     FOldFileRead := true;
440 h677 1.5 end;
441 hi_ 1.1 end;
442 h677 1.7 if errorSl.Count > 0 then
443     errorSl.SaveToFile(errorFileName);
444 h677 1.5 finally
445 h677 1.7 errorSl.Free;
446 h677 1.5 sl.Free;
447     end;
448     end;
449     procedure TRoundList.LoadRoundThreadFile;
450     var
451     i: Integer;
452 h677 1.12 // j: Integer;
453 h677 1.5 sl: TStringList;
454 h677 1.19 FileName, bFileName: string;
455 h677 1.7 errorSl: TStringList;
456     errorFileName: string;
457 h677 1.20 // Item: TRoundItem;
458 h677 1.15 delCount: Integer;
459 h677 1.8 // boardList : TStringList;
460 h677 1.5 begin
461 h677 1.8 // boardList := TStringList.Create;
462     // boardList.Duplicates := dupIgnore;
463 h677 1.7 errorSl := TStringList.Create;
464     errorSl.Duplicates := dupIgnore;
465 h677 1.5 sl := TStringList.Create;
466     try
467 hi_ 1.1 //鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
468     FileName := GikoSys.GetConfigDir + ROUND_ITEM_FILENAME;
469 h677 1.19 bFileName := GikoSys.GetConfigDir + '~' + ROUND_ITEM_FILENAME;
470     //鐃?鐃緒申鐃?鐃?鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
471 h677 1.7 errorFileName := GikoSys.GetConfigDir + ERROR_ITEM_FILENAME;
472 hi_ 1.1 if FileExists(FileName) then begin
473     sl.LoadFromFile(FileName);
474 h677 1.19 if FileExists(bFileName) then
475     DeleteFile(bFileName);
476     sl.SaveToFile(bFileName);
477     if FileExists(errorFileName) then begin
478 h677 1.7 try
479     errorSl.LoadFromFile(errorFileName);
480     except
481     end;
482     end;
483     //Item := TRoundItem.Create;
484 h677 1.15 delCount := 0;
485 h677 1.5 //鐃?鐃?鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申
486     if sl[0] = ROUND_INDEX_VERSION then begin
487 deux 1.13 for i := 1 to sl.Count - 1 do begin
488 h677 1.20 if not ParseRoundThreadLine(sl[i - delCount]) then begin
489     errorSl.Add(sl[i - delCount]);
490 h677 1.15 sl.Delete(i - delCount);
491     Inc(delCount);
492 h677 1.7 end;
493     end;
494 h677 1.20 end else begin
495     LoadRoundBoardFile;
496     for i := 1 to sl.Count - 1 do begin
497     if not ParseOldRoundThreadLine(sl[i - delCount]) then begin
498 h677 1.15 errorSl.Add(sl[i - delCount]);
499     sl.Delete(i - delCount);
500     Inc(delCount);
501 h677 1.7 end;
502 h677 1.5 end;
503     end;
504 h677 1.8 // j := boardList.Count - 1;
505     // while j >= 0 do begin
506     // GikoSys.ReadSubjectFile( BBSsFindBoardFromURL( boardList[j] ) );
507     // boardList.Delete(j);
508     // Dec(j);
509     // end;
510 h677 1.7 if errorSl.Count > 0 then
511     errorSl.SaveToFile(errorFileName);
512 hi_ 1.1 end;
513     finally
514 h677 1.20 errorSl.Free;
515 hi_ 1.1 sl.Free;
516 h677 1.8 // boardList.Free;
517 hi_ 1.1 end;
518     end;
519     procedure TRoundList.SaveRoundFile;
520     var
521     i: integer;
522     FileName: string;
523     sl: TStringList;
524     s: string;
525     Item: TRoundItem;
526     begin
527     GikoSys.ForceDirectoriesEx(GikoSys.GetConfigDir);
528    
529     sl := TStringList.Create;
530     try
531     FileName := GikoSys.GetConfigDir + ROUND_BOARD_FILENAME;
532     sl.Add(ROUND_INDEX_VERSION);
533 deux 1.13 for i := 0 to FBoardList.Count - 1 do begin
534 hi_ 1.1 Item := TRoundItem(FBoardList[i]);
535 h677 1.21 try
536     if Item.TmpURL <> '' then begin
537     s := Item.TmpURL + #1
538     + Item.BoardTitle + #1
539     + Item.RoundName;
540     end else begin
541     s := Item.URL + #1
542     + Item.BoardTitle + #1
543     + Item.RoundName;
544     end;
545     sl.Add(s);
546     except
547 h677 1.20 end;
548 hi_ 1.1 end;
549     sl.SaveToFile(FileName);
550     sl.Clear;
551     FileName := GikoSys.GetConfigDir + ROUND_ITEM_FILENAME;
552     sl.Add(ROUND_INDEX_VERSION);
553 deux 1.13 for i := 0 to FItemList.Count - 1 do begin
554 hi_ 1.1 Item := TRoundItem(FItemList[i]);
555 h677 1.21 try
556     if Item.TmpURL <> '' then begin
557     s := Item.TmpURL + #1
558     + Item.BoardTitle + #1
559     + Item.FileName + #1
560     + Item.ThreadTitle + #1
561     + Item.RoundName;
562     end else begin
563     s := Item.URL + #1
564     + Item.BoardTitle + #1
565     + Item.FileName + #1
566     + Item.ThreadTitle + #1
567     + Item.RoundName;
568     end;
569     sl.Add(s);
570     except
571 h677 1.20 end;
572 hi_ 1.1 end;
573     sl.SaveToFile(FileName);
574     finally
575     sl.Free;
576     end;
577     end;
578 h677 1.20 function TRoundList.ParseRoundBoardLine(Line: string): Boolean;
579 hi_ 1.1 var
580     s: string;
581 h677 1.20 roundname: string;
582     board: TBoard;
583 hi_ 1.1 i: Integer;
584     begin
585 h677 1.20 //Result := TRoundItem.Create;
586     //Result.ThreadTitle := '';
587     //Result.FileName := '';
588     //Result.RoundType := grtBoard;
589     board := nil;
590     for i := 0 to 2 do begin
591     s := GikoSys.GetTokenIndex(Line, #1, i);
592     try
593     case i of
594     0:
595     begin
596     board := BBSsFindBoardFromURL(s);
597     //Result.URL := s;
598     end;
599     //1: Result.BoardTitle := s;
600     2: roundname := s;
601     end;
602     except
603     Result := false;
604     Exit;
605     end;
606     end;
607     if( board <> nil ) then begin
608     if not board.Round then begin
609     board.RoundName := roundname;
610     RoundNameList.Add(roundname);
611     //RoundNameList.Find(roundname, i);
612     //board.RoundName := PChar(RoundNameList[i]);
613     board.Round := true;
614     end;
615     Result := true;
616     end else begin
617     Result := false;
618     end;
619 hi_ 1.1 end;
620 h677 1.5
621 h677 1.20 function TRoundList.ParseRoundThreadLine(Line: string): Boolean;
622 h677 1.4 var
623 h677 1.5 s: string;
624 h677 1.20 roundname: string;
625     threadItem: TThreadItem;
626 h677 1.4 i: Integer;
627 h677 1.12 // threadItem: TThreadItem;
628 h677 1.4 begin
629 h677 1.20 //Result := TRoundItem.Create;
630     //Result.RoundType := grtItem;
631     threadItem := nil;
632     for i := 0 to 4 do begin
633     s := GikoSys.GetTokenIndex(Line, #1, i);
634     try
635     case i of
636     0:
637     begin
638     //Result.URL := s;
639     threadItem := BBSsFindThreadFromURL( s );
640     //if threadItem <> nil then begin
641     // BoardList.Add( threadItem.ParentBoard.URL );
642     //end;
643     end;
644     //1: Result.BoardTitle := s;
645     //2: Result.FileName := s;
646     //3: Result.ThreadTitle := s;
647     4: roundname := s;
648     end;
649     except
650     Result := false;
651     Exit;
652     end;
653     end;
654     if( threadItem <> nil ) then begin
655     if not threadItem.Round then begin
656     threadItem.RoundName := roundname;
657     RoundNameList.Add(roundname);
658     //RoundNameList.Find(roundname, i);
659     //threadItem.RoundName := PChar(RoundNameList[i]);
660     threadItem.Round := True;
661     end;
662     Result := true;
663     end else begin
664     Result := false;
665     end;
666 h677 1.5 end;
667 h677 1.4
668 h677 1.20 function TRoundList.ParseOldRoundBoardLine(Line: string): Boolean;
669     var
670     i: Integer;
671 h677 1.4 s: string;
672 h677 1.20 roundname: string;
673     board: TBoard;
674 h677 1.4 begin
675 h677 1.20 //Result := TRoundItem.Create;
676     //Result.ThreadTitle := '';
677     //Result.FileName := '';
678     //Result.RoundType := grtBoard;
679     board := nil;
680     for i := 0 to 2 do begin
681     s := GikoSys.GetTokenIndex(Line, #1, i);
682     try
683     case i of
684     0:
685     begin
686     board := BBSs[ 0 ].FindBBSID( s );
687     if board = nil then begin
688     raise Exception.Create('鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃?');
689     end;
690     end;
691     //1: Result.FBoardTitle := s;
692     2: roundname := s;
693     end;
694     except
695     Result := false;
696     Exit;
697     end;
698     end;
699     if( board <> nil ) then begin
700     if not board.Round then begin
701     board.RoundName := roundname;
702     RoundNameList.Add(roundname);
703     //RoundNameList.Find(roundname, i);
704     //board.RoundName := PChar(RoundNameList[i]);
705     board.Round := true;
706     end;
707     Result := true;
708     end else begin
709     Result := false;
710     end;
711 h677 1.5 end;
712 h677 1.4
713 h677 1.20 function TRoundList.ParseOldRoundThreadLine(Line: string): Boolean;
714     var
715     i: Integer;
716 h677 1.4 s: string;
717 h677 1.20 roundname : string;
718 h677 1.4 buf: string;
719 h677 1.20 board: TBoard;
720     threadItem: TThreadItem;
721     bbsID: string;
722     begin
723     // Result := TRoundItem.Create;
724     // Result.RoundType := grtItem;
725     threadItem := nil;
726     for i := 0 to 4 do begin
727     s := GikoSys.GetTokenIndex(Line, #1, i);
728     try
729     case i of
730     0: bbsID := s;
731     //1: Result.BoardTitle := s;
732     2:
733     begin
734     //Result.FileName := s;
735     board := BBSs[ 0 ].FindBBSID(bbsID);
736     if board <> nil then begin
737     buf := Copy(board.GetSendURL,1,LastDelimiter('/', board.GetSendURL)-1);
738     buf := buf + '/read.cgi/'+ board.BBSID+ '/' +ChangeFileExt(s,'') + '/l50';
739     threadItem := BBSsFindThreadFromURL(buf);
740     end else begin
741     raise Exception.Create('鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申');
742     end;
743     end;
744     //3: Result.ThreadTitle := s;
745     4: roundname := s;
746     end;
747     except
748     Result := false;
749     Exit;
750     end;
751     end;
752     if( threadItem <> nil ) then begin
753     if not threadItem.Round then begin
754     threadItem.RoundName := roundname;
755     RoundNameList.Add(roundname);
756     //RoundNameList.Find(roundname, i);
757     //threadItem.RoundName := PChar(RoundNameList[i]);
758     threadItem.Round := true;
759     end;
760     Result := true;
761     end else begin
762     Result := false;
763     end;
764    
765 h677 1.17 end;
766     procedure TRoundList.URLReplace(oldURLs: TStringList; newURLs :TStringList);
767     var
768     i: Integer;
769 h677 1.20 j: Integer;
770     tempString: string;
771     tmpURL: string;
772     oldHost: string;
773     oldBoardName: string;
774     newHost: string;
775     newBoardName: string;
776     begin
777     if oldURLs.Count <> newURLs.Count then
778     Exit;
779     //鐃緒申鐃緒申鐃緒申鐃緒申鐃?Board鐃緒申URL鐃緒申鐃緒申鐃?
780     for j :=0 to oldURLs.Count - 1 do begin
781 h677 1.17 for i :=0 to FBoardList.Count - 1 do begin
782 h677 1.20 if TRoundItem(FBoardList[i]).URL = oldURLs[j] then
783     TRoundItem(FBoardList[i]).TmpURL := newURLs[j];
784     end;
785     end;
786     //鐃緒申鐃緒申鐃緒申鐃緒申鐃?Board鐃緒申URL鐃緒申鐃緒申鐃?
787 h677 1.17
788 h677 1.20 //鐃緒申鐃緒申鐃緒申鐃緒申鐃?Thread鐃緒申URL鐃緒申鐃緒申鐃?
789     //鐃緒申鐃?鐃緒申鐃緒申鐃緒申thread鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申URL鐃緒申鐃?鐃緒申鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃?
790     for i := 0 to oldURLs.Count - 1 do begin
791     tmpURL := Copy(oldURLs[i], 1, Length(oldURLs[i]) -1);
792     oldHost := Copy(tmpURL, 1, LastDelimiter('/', tmpURL) );
793     oldBoardName := Copy(tmpURL, LastDelimiter('/', tmpURL), Length(tmpURL) ) + '/';
794     tmpURL := Copy(newURLs[i], 1, Length(newURLs[i]) -1);
795     newHost := Copy(tmpURL, 1, LastDelimiter('/', tmpURL) );
796     newBoardName := Copy(tmpURL, LastDelimiter('/', tmpURL), Length(tmpURL) ) + '/';
797    
798     for j := 0 to FItemList.Count - 1 do begin
799     tempString := TRoundItem(FItemList[j]).URL;
800     if ( AnsiPos(oldBoardName, tempString) <> 0 ) and ( AnsiPos(oldHost, tempString ) <> 0 ) then begin
801     tempString := StringReplace(tempString, oldHost, newHost,[]);
802     TRoundItem(FItemList[j]).TmpURL := tempString;
803     end;
804     end;
805     end;
806     //鐃緒申鐃緒申鐃緒申鐃緒申鐃?Thread鐃緒申URL鐃緒申鐃緒申鐃?
807 h677 1.17
808 h677 1.4 end;
809 hi_ 1.1
810     end.

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