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.24 - (hide annotations) (download) (as text)
Sat Jul 22 20:34:39 2006 UTC (17 years, 9 months ago) by h677
Branch: MAIN
CVS Tags: v1_59_0_771, v1_59_0_770, v1_59_0_772, v1_56_0_715, v1_57_0_737, v1_57_0_735, v1_57_0_734, v1_57_0_733, v1_57_0_732, v1_57_0_731, v1_57_0_730, v1_57_0_739, v1_57_0_738, v1_59_1_765, v1_53_0_671, v1_54_0_677, v1_54_0_676, v1_58_0_748, v1_58_0_745, v1_58_0_746, v1_54_0_678, v1_56_0_707, v1_59_0_767, v1_56_0_705, v1_56_0_704, v1_56_0_703, v1_56_0_702, v1_56_0_701, v1_56_0_700, v1_57_0_723, v1_59_0_768, v1_59_0_769, v1_57_0_725, v1_57_0_726, v1_57_0_727, v1_57_0_720, v1_57_0_722, v1_57_1_744, v1_57_0_728, v1_57_0_729, v1_57_0_736, v1_58_0_752, v1_58_0_750, v1_58_0_751, v1_58_0_756, v1_58_0_757, v1_58_0_754, v1_58_0_755, v1_58_0_759, v1_57_0_719, v1_57_0_718, v1_56_0_716, v1_54_0_687, v1_56_0_710, v1_56_0_711, v1_56_1_717, v1_56_1_716, v1_54_0_688, v1_54_0_689, v1_54_0_684, v1_54_0_685, v1_53_0_669, v1_53_0_668, v1_55_0_692, v1_55_0_693, v1_55_0_696, v1_55_0_697, v1_55_0_694, v1_55_0_695, v1_54_1_691, v1_56_2_724, v1_56_2_722, v1_55_1_697, v1_56_0_714, v1_53_0_672, v1_53_0_670, v1_54_0_686, v1_54_0_680, v1_54_0_681, v1_56_0_712, v1_56_0_713, v1_54_0_682, v1_56_0_721, v1_54_0_683, v1_58_0_747, v1_54_0_679, marged_bRESPOPUP, v1_54_0_675, v1_56_0_706, root-of-Bb53, v1_54_0_674, v1_54_0_690, v1_58_0_763, v1_58_0_762, v1_58_0_761, v1_58_0_760, v1_57_2_749, v1_57_0_742, v1_57_0_743, v1_57_0_740, v1_57_0_741, v1_56_0_709, v1_57_0_744, v1_56_0_708, v1_53_1_673, v1_56_0_699, v1_56_0_698
Branch point for: Bb57, Bb56, Bb55, Bb53, Bb58, bRESPOPUP, bListSU, Bb54
Changes since 1.23: +21 -71 lines
File MIME type: text/x-pascal
無効なIDの判定を修正。
ほかコメント追加したり,コメントアウトしたソースを削除したり。

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

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