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.1.1.1 - (show annotations) (download) (as text) (vendor branch)
Sat Aug 9 13:51:10 2003 UTC (20 years, 8 months ago) by hi_
Branch: hi
CVS Tags: c33_4, b34, b35, b36, b33
Changes since 1.1: +0 -0 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 ParseRoundLine(Line: string; RoundType: TGikoRoundType): TRoundItem;
20 public
21 RoundNameList: TStringList;
22
23 constructor Create;
24 destructor Destroy; override;
25 function Add(Board: TBoard): Integer; overload;
26 function Add(ThreadItem: TThreadItem): Integer; overload;
27 procedure Delete(Board: TBoard); overload;
28 procedure Delete(ThreadItem: TThreadItem); overload;
29 procedure Clear;
30 function Find(Board: TBoard): Integer; overload;
31 function Find(ThreadItem: TThreadItem): Integer; overload;
32 property Count[RoundType: TGikoRoundType]: Integer read GetCount;
33 property Items[Index: integer; RoundType: TGikoRoundType]: TRoundItem read GetRoundItem;
34 procedure SetRoundName(Board: TBoard; RoundName: string); overload;
35 procedure SetRoundName(ThreadItem: TThreadItem; RoundName: string); overload;
36
37 procedure LoadRoundFile;
38 procedure SaveRoundFile;
39 end;
40
41 TRoundItem = class(TObject)
42 private
43 // FBBSType: TGikoBBSType;
44 FRoundName: string;
45 FRoundType: TGikoRoundType;
46 FBBSID: string;
47 FBoardTitle: string;
48 FThreadTitle: string;
49 FFileName: string;
50 FBoolData: Boolean; //?ス?ス?ス?ス?ス?ス?ス?ス?スg?ス?ス?ス?ス?ス?ス
51 public
52 // property BBSType: TGikoBBSType read FBBSType write FBBSType;
53 property RoundName: string read FRoundName write FRoundName;
54 property RoundType: TGikoRoundType read FRoundType write FRoundType;
55 property BBSID: string read FBBSID write FBBSID;
56 property BoardTitle: string read FBoardTitle write FBoardTitle;
57 property ThreadTitle: string read FThreadTitle write FThreadTitle;
58 property FileName: string read FFileName write FFileName;
59 property BoolData: Boolean read FBoolData write FBoolData;
60 end;
61
62 var
63 RoundList: TRoundList;
64
65 implementation
66 const
67 ROUND_BOARD_FILENAME: string = 'RoundBoard.2ch'; //?ス?ス?ス?ス?ス?スBoardGroup?ス?ス?ス?ス?ス?ス
68 ROUND_ITEM_FILENAME: string = 'RoundItem.2ch'; //?ス?ス?ス?ス
69 ROUND_INDEX_VERSION: string = '1.00';
70
71 constructor TRoundList.Create;
72 begin
73 inherited;
74 FBoardList := TList.Create;
75 FItemList := TList.Create;
76 RoundNameList := TStringList.Create;
77 RoundNameList.Sorted := True;
78 RoundNameList.Duplicates := dupIgnore;
79 end;
80
81 destructor TRoundList.Destroy;
82 begin
83 RoundNameList.Free;
84 Clear;
85 FBoardList.Free;
86 FItemList.Free;
87 inherited;
88 end;
89
90 function TRoundList.Add(Board: TBoard): Integer;
91 var
92 idx: Integer;
93 Item: TRoundItem;
94 begin
95 idx := Find(Board);
96 if idx = -1 then begin
97 Item := TRoundItem.Create;
98 // Item.BBSType := gbt2ch; //?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス
99 Item.RoundType := grtBoard;
100 Item.BBSID := Board.BBSID;
101 Item.BoardTitle := Board.Title;
102 Item.ThreadTitle := '';
103 Item.FileName := '';
104 Item.RoundName := Board.RoundName;
105 FBoardList.Add(Item);
106 end;
107 end;
108
109 function TRoundList.Add(ThreadItem: TThreadItem): Integer;
110 var
111 idx: Integer;
112 Item: TRoundItem;
113 begin
114 idx := Find(ThreadItem);
115 if idx = -1 then begin
116 Item := TRoundItem.Create;
117 // Item.BBSType := gbt2ch; //?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス
118 Item.RoundType := grtItem;
119 Item.BBSID := ThreadItem.ParentBoard.BBSID;
120 Item.BoardTitle := ThreadItem.ParentBoard.Title;
121 Item.ThreadTitle := ThreadItem.Title;
122 Item.FileName := ThreadItem.FileName;
123 Item.RoundName := ThreadItem.RoundName;
124 FItemList.Add(Item);
125 end;
126 end;
127
128 procedure TRoundList.Delete(Board: TBoard);
129 var
130 idx: Integer;
131 Item: TRoundItem;
132 begin
133 idx := Find(Board);
134 if idx <> -1 then begin
135 Item := TRoundItem(FBoardList[idx]);
136 Item.Free;
137 FBoardList.Delete(idx);
138 end;
139 end;
140
141 procedure TRoundList.Delete(ThreadItem: TThreadItem);
142 var
143 idx: Integer;
144 Item: TRoundItem;
145 begin
146 idx := Find(ThreadItem);
147 if idx <> -1 then begin
148 Item := TRoundItem(FItemList[idx]);
149 Item.Free;
150 FItemList.Delete(idx);
151 end;
152 end;
153
154 procedure TRoundList.Clear;
155 var
156 i: Integer;
157 begin
158 for i := FBoardList.Count - 1 downto 0 do begin
159 TRoundItem(FBoardList[i]).Free;
160 FBoardList.Delete(i);
161 end;
162 for i := FItemList.Count - 1 downto 0 do begin
163 TRoundItem(FItemList[i]).Free;
164 FItemList.Delete(i);
165 end;
166 end;
167
168 function TRoundList.Find(Board: TBoard): Integer;
169 var
170 i: Integer;
171 Item: TRoundItem;
172 begin
173 Result := -1;
174 for i := 0 to FBoardList.Count - 1 do begin
175 Item := TRoundItem(FBoardList[i]);
176 if Item.FRoundType <> grtBoard then Continue;
177 if Item.FBBSID = Board.BBSID then begin
178 Result := i;
179 Exit;
180 end;
181 end;
182 end;
183
184 function TRoundList.Find(ThreadItem: TThreadItem): Integer;
185 var
186 i: Integer;
187 Item: TRoundItem;
188 begin
189 Result := -1;
190 for i := 0 to FItemList.Count - 1 do begin
191 Item := TRoundItem(FItemList[i]);
192 if Item.FRoundType <> grtItem then Continue;
193 if (Item.FBBSID = ThreadItem.ParentBoard.BBSID) and (Item.FFileName = ThreadItem.FileName) then begin
194 Result := i;
195 Exit;
196 end;
197 end;
198 end;
199
200 procedure TRoundList.SetRoundName(Board: TBoard; RoundName: string);
201 var
202 idx: Integer;
203 Item: TRoundItem;
204 begin
205 idx := Find(Board);
206 if idx <> -1 then begin
207 Item := TRoundItem(FBoardList[idx]);
208 Item.RoundName := RoundName;
209 end;
210 end;
211
212 procedure TRoundList.SetRoundName(ThreadItem: TThreadItem; RoundName: string);
213 var
214 idx: Integer;
215 Item: TRoundItem;
216 begin
217 idx := Find(ThreadItem);
218 if idx <> -1 then begin
219 Item := TRoundItem(FItemList[idx]);
220 Item.RoundName := RoundName;
221 end;
222 end;
223
224 function TRoundList.GetCount(RoundType: TGikoRoundType): Integer;
225 begin
226 Result := 0;
227 if RoundType = grtBoard then
228 Result := FBoardList.Count
229 else if RoundType = grtItem then
230 Result := FItemList.Count;
231 end;
232
233 function TRoundList.GetRoundItem(Index: Integer; RoundType: TGikoRoundType): TRoundItem;
234 begin
235 Result := nil;
236 if RoundType = grtBoard then begin
237 if (Index >= 0) and (Index < FBoardList.Count) then
238 Result := TRoundItem(FBoardList[Index]);
239 end else if RoundType = grtItem then begin
240 if (Index >= 0) and (Index < FItemList.Count) then
241 Result := TRoundItem(FItemList[Index]);
242 end;
243 end;
244
245 procedure TRoundList.LoadRoundFile;
246 var
247 i: Integer;
248 sl: TStringList;
249 FileName: string;
250 Item: TRoundItem;
251 begin
252 sl := TStringList.Create;
253 try
254 //?ス{?ス[?スh?ス?ス?ス?ス?スt?ス@?スC?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス
255 FileName := GikoSys.GetConfigDir + ROUND_BOARD_FILENAME;
256 if FileExists(FileName) then begin
257 sl.LoadFromFile(FileName);
258 //?スP?スs?ス?ス?ス?ス?スo?ス[?スW?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス
259 for i := 1 to sl.Count - 1 do begin
260 Item := ParseRoundLine(sl[i], grtBoard);
261 FBoardList.Add(Item);
262 RoundNameList.Add(Item.RoundName);
263 end;
264 end;
265 //?スX?ス?ス?ス?ス?ス?ス?スt?ス@?スC?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス
266 FileName := GikoSys.GetConfigDir + ROUND_ITEM_FILENAME;
267 if FileExists(FileName) then begin
268 sl.LoadFromFile(FileName);
269 //?スP?スs?ス?ス?ス?ス?スo?ス[?スW?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス?ス
270 for i := 1 to sl.Count - 1 do begin
271 Item := ParseRoundLine(sl[i], grtItem);
272 FItemList.Add(Item);
273 RoundNameList.Add(Item.RoundName);
274 end;
275 end;
276 finally
277 sl.Free;
278 end;
279 end;
280
281 procedure TRoundList.SaveRoundFile;
282 var
283 i: integer;
284 FileName: string;
285 sl: TStringList;
286 s: string;
287 Item: TRoundItem;
288 begin
289 GikoSys.ForceDirectoriesEx(GikoSys.GetConfigDir);
290
291 sl := TStringList.Create;
292 try
293 FileName := GikoSys.GetConfigDir + ROUND_BOARD_FILENAME;
294 sl.Add(ROUND_INDEX_VERSION);
295 for i := 0 to FBoardList.Count - 1 do begin
296 Item := TRoundItem(FBoardList[i]);
297 s := Item.BBSID + #1
298 + Item.BoardTitle + #1
299 + Item.RoundName;
300 sl.Add(s);
301 end;
302 sl.SaveToFile(FileName);
303 sl.Clear;
304 FileName := GikoSys.GetConfigDir + ROUND_ITEM_FILENAME;
305 sl.Add(ROUND_INDEX_VERSION);
306 for i := 0 to FItemList.Count - 1 do begin
307 Item := TRoundItem(FItemList[i]);
308 s := Item.BBSID + #1
309 + Item.BoardTitle + #1
310 + Item.FileName + #1
311 + Item.ThreadTitle + #1
312 + Item.RoundName;
313 sl.Add(s);
314 end;
315 sl.SaveToFile(FileName);
316 finally
317 sl.Free;
318 end;
319 end;
320
321 function TRoundList.ParseRoundLine(Line: string; RoundType: TGikoRoundType): TRoundItem;
322 var
323 s: string;
324 i: Integer;
325 begin
326 Result := TRoundItem.Create;
327 if RoundType = grtBoard then begin
328 Result.ThreadTitle := '';
329 Result.FileName := '';
330 Result.RoundType := grtBoard;
331 for i := 0 to 2 do begin
332 s := GikoSys.GetTokenIndex(Line, #1, i);
333 case i of
334 0: Result.BBSID := s;
335 1: Result.BoardTitle := s;
336 2: Result.RoundName := s;
337 end;
338 end;
339 end else if RoundType = grtItem then begin
340 Result.RoundType := grtItem;
341 for i := 0 to 4 do begin
342 s := GikoSys.GetTokenIndex(Line, #1, i);
343 case i of
344 0: Result.BBSID := s;
345 1: Result.BoardTitle := s;
346 2: Result.FileName := s;
347 3: Result.ThreadTitle := s;
348 4: Result.RoundName := s;
349 end;
350 end;
351 end;
352 end;
353
354 end.

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