Develop and Download Open Source Software

Browse CVS Repository

Contents of /gikonavigoeson/gikonavi/RoundData.pas

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


Revision 1.5 - (show annotations) (download) (as text)
Tue Dec 9 19:26:29 2003 UTC (20 years, 4 months ago) by h677
Branch: MAIN
Changes since 1.4: +141 -159 lines
File MIME type: text/x-pascal
巡回ファイル関係の修正

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 FBoardList: TList;
16 FItemList: TList;
17 function GetCount(RoundType: TGikoRoundType): Integer;
18 function GetRoundItem(Index: Integer; RoundType: TGikoRoundType): TRoundItem;
19 function ParseRoundBoardLine(Line: string): TRoundItem;
20 function ParseRoundThreadLine(Line: string; var BoardList : TStringList): TRoundItem;
21 function ParseOldRoundBoardLine(Line: string): TRoundItem;
22 function ParseOldRoundThreadLine(Line: string; var BoardList : TStringList): TRoundItem;
23 public
24 RoundNameList: TStringList;
25
26 constructor Create;
27 destructor Destroy; override;
28 function Add(Board: TBoard): Integer; overload;
29 function Add(ThreadItem: TThreadItem): Integer; overload;
30 procedure Delete(Board: TBoard); overload;
31 procedure Delete(ThreadItem: TThreadItem); overload;
32 procedure Clear;
33 function Find(Board: TBoard): Integer; overload;
34 function Find(ThreadItem: TThreadItem): Integer; overload;
35 property Count[RoundType: TGikoRoundType]: Integer read GetCount;
36 property Items[Index: integer; RoundType: TGikoRoundType]: TRoundItem read GetRoundItem;
37 procedure SetRoundName(Board: TBoard; RoundName: string); overload;
38 procedure SetRoundName(ThreadItem: TThreadItem; RoundName: string); overload;
39
40 //procedure ConvertRoundFile; //bata44鐃緒申鐃?鐃緒申Roundfile鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
41 procedure LoadRoundBoardFile;
42 procedure LoadRoundThreadFile;
43 procedure SaveRoundFile;
44 end;
45
46 TRoundItem = class(TObject)
47 private
48 // FBBSType: TGikoBBSType;
49 FRoundName: string;
50 FRoundType: TGikoRoundType;
51 FItem : TObject;
52 FURL : string;
53 FBoardTitle: string;
54 FThreadTitle: string;
55 FFileName: string;
56 FBoolData: Boolean; //鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申
57 public
58 // property BBSType: TGikoBBSType read FBBSType write FBBSType;
59 property RoundName: string read FRoundName write FRoundName;
60 property RoundType: TGikoRoundType read FRoundType write FRoundType;
61 property Item : TObject read FItem write FItem;
62 property URL : string read FURL write FURL;
63 property BoardTitle: string read FBoardTitle write FBoardTitle;
64 property ThreadTitle: string read FThreadTitle write FThreadTitle;
65 property FileName: string read FFileName write FFileName;
66 property BoolData: Boolean read FBoolData write FBoolData;
67 end;
68
69 var
70 RoundList: TRoundList;
71
72 implementation
73 const
74 ROUND_BOARD_FILENAME: string = 'RoundBoard.2ch'; //鐃緒申鐃緒申鐃緒申BoardGroup鐃緒申鐃緒申鐃緒申
75 ROUND_ITEM_FILENAME: string = 'RoundItem.2ch'; //鐃緒申鐃緒申
76 ROUND_INDEX_VERSION: string = '2.00';
77
78 constructor TRoundList.Create;
79 begin
80 inherited;
81 FBoardList := TList.Create;
82 FItemList := TList.Create;
83 RoundNameList := TStringList.Create;
84 RoundNameList.Sorted := True;
85 RoundNameList.Duplicates := dupIgnore;
86 end;
87
88 destructor TRoundList.Destroy;
89 begin
90 RoundNameList.Free;
91 Clear;
92 FBoardList.Free;
93 FItemList.Free;
94 inherited;
95 end;
96
97 function TRoundList.Add(Board: TBoard): Integer;
98 var
99 idx: Integer;
100 Item: TRoundItem;
101 begin
102 Result := -1;
103 idx := Find(Board);
104 if idx = -1 then begin
105 Item := TRoundItem.Create;
106 // Item.BBSType := gbt2ch; //鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
107 Item.RoundType := grtBoard;
108 Item.Item := Board;
109 Item.URL := Board.URL;
110 Item.BoardTitle := Board.Title;
111 Item.ThreadTitle := '';
112 Item.FileName := '';
113 Item.RoundName := Board.RoundName;
114 Result := FBoardList.Add(Item);
115 end;
116 end;
117
118 function TRoundList.Add(ThreadItem: TThreadItem): Integer;
119 var
120 idx: Integer;
121 Item: TRoundItem;
122 begin
123 Result := -1;
124 idx := Find(ThreadItem);
125 if idx = -1 then begin
126 Item := TRoundItem.Create;
127 // Item.BBSType := gbt2ch; //鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
128 Item.RoundType := grtItem;
129 Item.Item := ThreadItem;
130 Item.URL := Threaditem.URL;
131 Item.BoardTitle := ThreadItem.ParentBoard.Title;
132 Item.ThreadTitle := ThreadItem.Title;
133 Item.FileName := ThreadItem.FileName;
134 Item.RoundName := ThreadItem.RoundName;
135 Result := FItemList.Add(Item);
136 end;
137 end;
138
139 procedure TRoundList.Delete(Board: TBoard);
140 var
141 idx: Integer;
142 Item: TRoundItem;
143 begin
144 idx := Find(Board);
145 if idx <> -1 then begin
146 Item := TRoundItem(FBoardList[idx]);
147 Item.Free;
148 FBoardList.Delete(idx);
149 end;
150 end;
151
152 procedure TRoundList.Delete(ThreadItem: TThreadItem);
153 var
154 idx: Integer;
155 Item: TRoundItem;
156 begin
157 idx := Find(ThreadItem);
158 if idx <> -1 then begin
159 Item := TRoundItem(FItemList[idx]);
160 Item.Free;
161 FItemList.Delete(idx);
162 end;
163 end;
164
165 procedure TRoundList.Clear;
166 var
167 i: Integer;
168 begin
169 for i := FBoardList.Count - 1 downto 0 do begin
170 TRoundItem(FBoardList[i]).Free;
171 FBoardList.Delete(i);
172 end;
173 for i := FItemList.Count - 1 downto 0 do begin
174 TRoundItem(FItemList[i]).Free;
175 FItemList.Delete(i);
176 end;
177 end;
178
179 function TRoundList.Find(Board: TBoard): Integer;
180 var
181 i: Integer;
182 Item: TRoundItem;
183 begin
184 Result := -1;
185 for i := 0 to FBoardList.Count - 1 do begin
186 Item := TRoundItem(FBoardList[i]);
187 if Item.FRoundType <> grtBoard then Continue;
188 if Item.FURL = Board.URL then begin
189 Result := i;
190 Exit;
191 end;
192 end;
193 end;
194
195 function TRoundList.Find(ThreadItem: TThreadItem): Integer;
196 var
197 i: Integer;
198 Item: TRoundItem;
199 begin
200 Result := -1;
201 for i := 0 to FItemList.Count - 1 do begin
202 Item := TRoundItem(FItemList[i]);
203 if Item.FRoundType <> grtItem then Continue;
204 if Item.FURL = ThreadItem.URL then begin
205 Result := i;
206 Exit;
207 end;
208 end;
209 end;
210
211 procedure TRoundList.SetRoundName(Board: TBoard; RoundName: string);
212 var
213 idx: Integer;
214 Item: TRoundItem;
215 begin
216 idx := Find(Board);
217 if idx <> -1 then begin
218 Item := TRoundItem(FBoardList[idx]);
219 Item.RoundName := RoundName;
220 end;
221 end;
222
223 procedure TRoundList.SetRoundName(ThreadItem: TThreadItem; RoundName: string);
224 var
225 idx: Integer;
226 Item: TRoundItem;
227 begin
228 idx := Find(ThreadItem);
229 if idx <> -1 then begin
230 Item := TRoundItem(FItemList[idx]);
231 Item.RoundName := RoundName;
232 end;
233 end;
234
235 function TRoundList.GetCount(RoundType: TGikoRoundType): Integer;
236 begin
237 Result := 0;
238 if RoundType = grtBoard then
239 Result := FBoardList.Count
240 else if RoundType = grtItem then
241 Result := FItemList.Count;
242 end;
243
244 function TRoundList.GetRoundItem(Index: Integer; RoundType: TGikoRoundType): TRoundItem;
245 begin
246 Result := nil;
247 if RoundType = grtBoard then begin
248 if (Index >= 0) and (Index < FBoardList.Count) then
249 Result := TRoundItem(FBoardList[Index]);
250 end else if RoundType = grtItem then begin
251 if (Index >= 0) and (Index < FItemList.Count) then
252 Result := TRoundItem(FItemList[Index]);
253 end;
254 end;
255 procedure TRoundList.LoadRoundBoardFile;
256 var
257 i: Integer;
258 sl: TStringList;
259 FileName: string;
260 Item: TRoundItem;
261 begin
262 sl := TStringList.Create;
263 try
264 //鐃?鐃?鐃?鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
265 FileName := GikoSys.GetConfigDir + ROUND_BOARD_FILENAME;
266 if FileExists(FileName) then begin
267 sl.LoadFromFile(FileName);
268 //鐃?鐃?鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申
269 if sl[0] = ROUND_INDEX_VERSION then begin
270 for i := 1 to sl.Count - 1 do begin
271 Item := ParseRoundBoardLine(sl[i]);
272 FBoardList.Add(Item);
273 RoundNameList.Add(Item.RoundName);
274 end;
275 end else begin
276 for i := 1 to sl.Count - 1 do begin
277 Item := ParseOldRoundBoardLine(sl[i]);
278 FBoardList.Add(Item);
279 RoundNameList.Add(Item.RoundName);
280 end;
281 end;
282 end;
283 finally
284 sl.Free;
285 end;
286 end;
287 procedure TRoundList.LoadRoundThreadFile;
288 var
289 i: Integer;
290 j: Integer;
291 sl: TStringList;
292 FileName: string;
293 Item: TRoundItem;
294 boardList : TStringList;
295 begin
296 boardList := TStringList.Create;
297 boardList.Duplicates := dupIgnore;
298 sl := TStringList.Create;
299 try
300 //鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申
301 FileName := GikoSys.GetConfigDir + ROUND_ITEM_FILENAME;
302 if FileExists(FileName) then begin
303 sl.LoadFromFile(FileName);
304 //鐃?鐃?鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申
305 if sl[0] = ROUND_INDEX_VERSION then begin
306 for i := 1 to sl.Count - 1 do begin
307 Item := ParseRoundThreadLine(sl[i], boardList);
308 FItemList.Add(Item);
309 RoundNameList.Add(Item.RoundName);
310 end;
311 end else begin
312 for i := 1 to sl.Count - 1 do begin
313 Item := ParseOldRoundThreadLine(sl[i], boardList);
314 FItemList.Add(Item);
315 RoundNameList.Add(Item.RoundName);
316 end;
317 end;
318 end;
319 j := boardList.Count - 1;
320 while j >= 0 do begin
321 GikoSys.ReadSubjectFile( BBSsFindBoardFromURL( boardList[j] ) );
322 boardList.Delete(j);
323 Dec(j);
324 end;
325 finally
326 sl.Free;
327 boardList.Free;
328 end;
329 end;
330 procedure TRoundList.SaveRoundFile;
331 var
332 i: integer;
333 FileName: string;
334 sl: TStringList;
335 s: string;
336 Item: TRoundItem;
337 begin
338 GikoSys.ForceDirectoriesEx(GikoSys.GetConfigDir);
339
340 sl := TStringList.Create;
341 try
342 FileName := GikoSys.GetConfigDir + ROUND_BOARD_FILENAME;
343 sl.Add(ROUND_INDEX_VERSION);
344 for i := 0 to FBoardList.Count - 1 do begin
345 Item := TRoundItem(FBoardList[i]);
346 s := Item.URL + #1
347 + Item.BoardTitle + #1
348 + Item.RoundName;
349 sl.Add(s);
350 end;
351 sl.SaveToFile(FileName);
352 sl.Clear;
353 FileName := GikoSys.GetConfigDir + ROUND_ITEM_FILENAME;
354 sl.Add(ROUND_INDEX_VERSION);
355 for i := 0 to FItemList.Count - 1 do begin
356 Item := TRoundItem(FItemList[i]);
357 s := Item.URL + #1
358 + Item.BoardTitle + #1
359 + Item.FileName + #1
360 + Item.ThreadTitle + #1
361 + Item.RoundName;
362 sl.Add(s);
363 end;
364 sl.SaveToFile(FileName);
365 finally
366 sl.Free;
367 end;
368 end;
369 function TRoundList.ParseRoundBoardLine(Line: string): TRoundItem;
370 var
371 s: string;
372 i: Integer;
373 begin
374 Result := TRoundItem.Create;
375 Result.ThreadTitle := '';
376 Result.FileName := '';
377 Result.RoundType := grtBoard;
378 for i := 0 to 2 do begin
379 s := GikoSys.GetTokenIndex(Line, #1, i);
380 case i of
381 0:
382 begin
383 Result.URL := s;
384 Result.Item := BBSsFindBoardFromURL( s );
385 end;
386 1: Result.BoardTitle := s;
387 2: Result.RoundName := s;
388 end;
389 end;
390 end;
391
392 function TRoundList.ParseRoundThreadLine(Line: string; var BoardList : TStringList): TRoundItem;
393 var
394 s: string;
395 i: Integer;
396 threadItem: TThreadItem;
397 begin
398 Result := TRoundItem.Create;
399 Result.RoundType := grtItem;
400 for i := 0 to 4 do begin
401 s := GikoSys.GetTokenIndex(Line, #1, i);
402 case i of
403 0:
404 begin
405 Result.URL := s;
406 threadItem := BBSsFindThreadFromURL( s );
407 if threadItem <> nil then begin
408 Result.Item := threadItem;
409 BoardList.Add( threadItem.ParentBoard.URL );
410 end;
411 end;
412 1: Result.BoardTitle := s;
413 2: Result.FileName := s;
414 3: Result.ThreadTitle := s;
415 4: Result.RoundName := s;
416 end;
417 end;
418 end;
419
420 function TRoundList.ParseOldRoundBoardLine(Line: string): TRoundItem;
421 var
422 i: Integer;
423 s: string;
424 buf: string;
425 board: TBoard;
426 threadItem: TThreadItem;
427 begin
428 Result := TRoundItem.Create;
429 Result.ThreadTitle := '';
430 Result.FileName := '';
431 Result.RoundType := grtBoard;
432 for i := 0 to 1 do begin
433 s := GikoSys.GetTokenIndex(Line, #1, i);
434 case i of
435 0:
436 begin
437 Result.BoardTitle := s;
438 board := BBSs[ 0 ].FindBBSID( s );
439 Result.URL := board.URL;
440 Result.Item := BBSsFindBoardFromURL( Result.URL );
441 end;
442 1: Result.RoundName := s;
443 end;
444 end;
445 end;
446
447 function TRoundList.ParseOldRoundThreadLine(Line: string; var BoardList : TStringList): TRoundItem;
448 var
449 i: Integer;
450 s: string;
451 buf: string;
452 board: TBoard;
453 threadItem: TThreadItem;
454 begin
455 Result := TRoundItem.Create;
456 Result.RoundType := grtItem;
457 for i := 0 to 3 do begin
458 s := GikoSys.GetTokenIndex(Line, #1, i);
459 case i of
460 0: Result.BoardTitle := s;
461 1:
462 begin
463 Result.FileName := s;
464 board := BBSs[ 0 ].FindBoardFromTitle(Result.BoardTitle);
465 if board <> nil then begin
466 BoardList.Add(board.URL);
467 buf := Copy(board.GetSendURL,1,LastDelimiter('/', board.GetSendURL)-1);
468 Result.URL := buf + '/read.cgi/'+ board.BBSID+ '/' +ChangeFileExt(s,'') + '/l50';
469 threadItem := BBSsFindThreadFromURL(Result.URL);
470 if threadItem <> nil then begin
471 Result.Item := threadItem;
472 end;
473 end;
474 end;
475 2: Result.ThreadTitle := s;
476 3: Result.RoundName := s;
477 end;
478 end;
479 end;
480
481 end.

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