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.3 - (hide annotations) (download) (as text)
Fri Nov 21 17:24:50 2003 UTC (20 years, 5 months ago) by yoffy
Branch: MAIN
CVS Tags: b44
Changes since 1.2: +20 -10 lines
File MIME type: text/x-pascal
・今まで 1 つ固定であった BBS が複数持てるようになった。
 これにより、多くの2ちゃんねる特有の処理が排除され使えなくなった可能性がある。

以下注意。
 お気に入りファイルのフォーマットが変更になった(確定)。
 巡回ファイルのフォーマットが変更になったかもしれない(不明)。
 他にもあるかも。

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

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