| 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; //鐃緒申鐃緒申鐃緒申鐃緒申鐃?鐃緒申鐃緒申鐃緒申 |
| 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 |
Result := -1; |
| 96 |
idx := Find(Board); |
| 97 |
if idx = -1 then begin |
| 98 |
Item := TRoundItem.Create; |
| 99 |
// Item.BBSType := gbt2ch; //鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 100 |
Item.RoundType := grtBoard; |
| 101 |
Item.BBSID := Board.BBSID; |
| 102 |
Item.BoardTitle := Board.Title; |
| 103 |
Item.ThreadTitle := ''; |
| 104 |
Item.FileName := ''; |
| 105 |
Item.RoundName := Board.RoundName; |
| 106 |
Result := FBoardList.Add(Item); |
| 107 |
end; |
| 108 |
end; |
| 109 |
|
| 110 |
function TRoundList.Add(ThreadItem: TThreadItem): Integer; |
| 111 |
var |
| 112 |
idx: Integer; |
| 113 |
Item: TRoundItem; |
| 114 |
begin |
| 115 |
Result := -1; |
| 116 |
idx := Find(ThreadItem); |
| 117 |
if idx = -1 then begin |
| 118 |
Item := TRoundItem.Create; |
| 119 |
// Item.BBSType := gbt2ch; //鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 120 |
Item.RoundType := grtItem; |
| 121 |
Item.BBSID := ThreadItem.ParentBoard.BBSID; |
| 122 |
Item.BoardTitle := ThreadItem.ParentBoard.Title; |
| 123 |
Item.ThreadTitle := ThreadItem.Title; |
| 124 |
Item.FileName := ThreadItem.FileName; |
| 125 |
Item.RoundName := ThreadItem.RoundName; |
| 126 |
Result := FItemList.Add(Item); |
| 127 |
end; |
| 128 |
end; |
| 129 |
|
| 130 |
procedure TRoundList.Delete(Board: TBoard); |
| 131 |
var |
| 132 |
idx: Integer; |
| 133 |
Item: TRoundItem; |
| 134 |
begin |
| 135 |
idx := Find(Board); |
| 136 |
if idx <> -1 then begin |
| 137 |
Item := TRoundItem(FBoardList[idx]); |
| 138 |
Item.Free; |
| 139 |
FBoardList.Delete(idx); |
| 140 |
end; |
| 141 |
end; |
| 142 |
|
| 143 |
procedure TRoundList.Delete(ThreadItem: TThreadItem); |
| 144 |
var |
| 145 |
idx: Integer; |
| 146 |
Item: TRoundItem; |
| 147 |
begin |
| 148 |
idx := Find(ThreadItem); |
| 149 |
if idx <> -1 then begin |
| 150 |
Item := TRoundItem(FItemList[idx]); |
| 151 |
Item.Free; |
| 152 |
FItemList.Delete(idx); |
| 153 |
end; |
| 154 |
end; |
| 155 |
|
| 156 |
procedure TRoundList.Clear; |
| 157 |
var |
| 158 |
i: Integer; |
| 159 |
begin |
| 160 |
for i := FBoardList.Count - 1 downto 0 do begin |
| 161 |
TRoundItem(FBoardList[i]).Free; |
| 162 |
FBoardList.Delete(i); |
| 163 |
end; |
| 164 |
for i := FItemList.Count - 1 downto 0 do begin |
| 165 |
TRoundItem(FItemList[i]).Free; |
| 166 |
FItemList.Delete(i); |
| 167 |
end; |
| 168 |
end; |
| 169 |
|
| 170 |
function TRoundList.Find(Board: TBoard): Integer; |
| 171 |
var |
| 172 |
i: Integer; |
| 173 |
Item: TRoundItem; |
| 174 |
begin |
| 175 |
Result := -1; |
| 176 |
for i := 0 to FBoardList.Count - 1 do begin |
| 177 |
Item := TRoundItem(FBoardList[i]); |
| 178 |
if Item.FRoundType <> grtBoard then Continue; |
| 179 |
if Item.FBBSID = Board.BBSID then begin |
| 180 |
Result := i; |
| 181 |
Exit; |
| 182 |
end; |
| 183 |
end; |
| 184 |
end; |
| 185 |
|
| 186 |
function TRoundList.Find(ThreadItem: TThreadItem): Integer; |
| 187 |
var |
| 188 |
i: Integer; |
| 189 |
Item: TRoundItem; |
| 190 |
begin |
| 191 |
Result := -1; |
| 192 |
for i := 0 to FItemList.Count - 1 do begin |
| 193 |
Item := TRoundItem(FItemList[i]); |
| 194 |
if Item.FRoundType <> grtItem then Continue; |
| 195 |
if (Item.FBBSID = ThreadItem.ParentBoard.BBSID) and (Item.FFileName = ThreadItem.FileName) then begin |
| 196 |
Result := i; |
| 197 |
Exit; |
| 198 |
end; |
| 199 |
end; |
| 200 |
end; |
| 201 |
|
| 202 |
procedure TRoundList.SetRoundName(Board: TBoard; RoundName: string); |
| 203 |
var |
| 204 |
idx: Integer; |
| 205 |
Item: TRoundItem; |
| 206 |
begin |
| 207 |
idx := Find(Board); |
| 208 |
if idx <> -1 then begin |
| 209 |
Item := TRoundItem(FBoardList[idx]); |
| 210 |
Item.RoundName := RoundName; |
| 211 |
end; |
| 212 |
end; |
| 213 |
|
| 214 |
procedure TRoundList.SetRoundName(ThreadItem: TThreadItem; RoundName: string); |
| 215 |
var |
| 216 |
idx: Integer; |
| 217 |
Item: TRoundItem; |
| 218 |
begin |
| 219 |
idx := Find(ThreadItem); |
| 220 |
if idx <> -1 then begin |
| 221 |
Item := TRoundItem(FItemList[idx]); |
| 222 |
Item.RoundName := RoundName; |
| 223 |
end; |
| 224 |
end; |
| 225 |
|
| 226 |
function TRoundList.GetCount(RoundType: TGikoRoundType): Integer; |
| 227 |
begin |
| 228 |
Result := 0; |
| 229 |
if RoundType = grtBoard then |
| 230 |
Result := FBoardList.Count |
| 231 |
else if RoundType = grtItem then |
| 232 |
Result := FItemList.Count; |
| 233 |
end; |
| 234 |
|
| 235 |
function TRoundList.GetRoundItem(Index: Integer; RoundType: TGikoRoundType): TRoundItem; |
| 236 |
begin |
| 237 |
Result := nil; |
| 238 |
if RoundType = grtBoard then begin |
| 239 |
if (Index >= 0) and (Index < FBoardList.Count) then |
| 240 |
Result := TRoundItem(FBoardList[Index]); |
| 241 |
end else if RoundType = grtItem then begin |
| 242 |
if (Index >= 0) and (Index < FItemList.Count) then |
| 243 |
Result := TRoundItem(FItemList[Index]); |
| 244 |
end; |
| 245 |
end; |
| 246 |
|
| 247 |
procedure TRoundList.LoadRoundFile; |
| 248 |
var |
| 249 |
i: Integer; |
| 250 |
sl: TStringList; |
| 251 |
FileName: string; |
| 252 |
Item: TRoundItem; |
| 253 |
begin |
| 254 |
sl := TStringList.Create; |
| 255 |
try |
| 256 |
//鐃?鐃?鐃?鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 257 |
FileName := GikoSys.GetConfigDir + ROUND_BOARD_FILENAME; |
| 258 |
if FileExists(FileName) then begin |
| 259 |
sl.LoadFromFile(FileName); |
| 260 |
//鐃?鐃?鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 261 |
for i := 1 to sl.Count - 1 do begin |
| 262 |
Item := ParseRoundLine(sl[i], grtBoard); |
| 263 |
FBoardList.Add(Item); |
| 264 |
RoundNameList.Add(Item.RoundName); |
| 265 |
end; |
| 266 |
end; |
| 267 |
//鐃?鐃緒申鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 268 |
FileName := GikoSys.GetConfigDir + ROUND_ITEM_FILENAME; |
| 269 |
if FileExists(FileName) then begin |
| 270 |
sl.LoadFromFile(FileName); |
| 271 |
//鐃?鐃?鐃緒申鐃緒申鐃?鐃?鐃?鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申鐃緒申 |
| 272 |
for i := 1 to sl.Count - 1 do begin |
| 273 |
Item := ParseRoundLine(sl[i], grtItem); |
| 274 |
FItemList.Add(Item); |
| 275 |
RoundNameList.Add(Item.RoundName); |
| 276 |
end; |
| 277 |
end; |
| 278 |
finally |
| 279 |
sl.Free; |
| 280 |
end; |
| 281 |
end; |
| 282 |
|
| 283 |
procedure TRoundList.SaveRoundFile; |
| 284 |
var |
| 285 |
i: integer; |
| 286 |
FileName: string; |
| 287 |
sl: TStringList; |
| 288 |
s: string; |
| 289 |
Item: TRoundItem; |
| 290 |
begin |
| 291 |
GikoSys.ForceDirectoriesEx(GikoSys.GetConfigDir); |
| 292 |
|
| 293 |
sl := TStringList.Create; |
| 294 |
try |
| 295 |
FileName := GikoSys.GetConfigDir + ROUND_BOARD_FILENAME; |
| 296 |
sl.Add(ROUND_INDEX_VERSION); |
| 297 |
for i := 0 to FBoardList.Count - 1 do begin |
| 298 |
Item := TRoundItem(FBoardList[i]); |
| 299 |
s := Item.BBSID + #1 |
| 300 |
+ Item.BoardTitle + #1 |
| 301 |
+ Item.RoundName; |
| 302 |
sl.Add(s); |
| 303 |
end; |
| 304 |
sl.SaveToFile(FileName); |
| 305 |
sl.Clear; |
| 306 |
FileName := GikoSys.GetConfigDir + ROUND_ITEM_FILENAME; |
| 307 |
sl.Add(ROUND_INDEX_VERSION); |
| 308 |
for i := 0 to FItemList.Count - 1 do begin |
| 309 |
Item := TRoundItem(FItemList[i]); |
| 310 |
s := Item.BBSID + #1 |
| 311 |
+ Item.BoardTitle + #1 |
| 312 |
+ Item.FileName + #1 |
| 313 |
+ Item.ThreadTitle + #1 |
| 314 |
+ Item.RoundName; |
| 315 |
sl.Add(s); |
| 316 |
end; |
| 317 |
sl.SaveToFile(FileName); |
| 318 |
finally |
| 319 |
sl.Free; |
| 320 |
end; |
| 321 |
end; |
| 322 |
|
| 323 |
function TRoundList.ParseRoundLine(Line: string; RoundType: TGikoRoundType): TRoundItem; |
| 324 |
var |
| 325 |
s: string; |
| 326 |
i: Integer; |
| 327 |
begin |
| 328 |
Result := TRoundItem.Create; |
| 329 |
if RoundType = grtBoard then begin |
| 330 |
Result.ThreadTitle := ''; |
| 331 |
Result.FileName := ''; |
| 332 |
Result.RoundType := grtBoard; |
| 333 |
for i := 0 to 2 do begin |
| 334 |
s := GikoSys.GetTokenIndex(Line, #1, i); |
| 335 |
case i of |
| 336 |
0: Result.BBSID := s; |
| 337 |
1: Result.BoardTitle := s; |
| 338 |
2: Result.RoundName := s; |
| 339 |
end; |
| 340 |
end; |
| 341 |
end else if RoundType = grtItem then begin |
| 342 |
Result.RoundType := grtItem; |
| 343 |
for i := 0 to 4 do begin |
| 344 |
s := GikoSys.GetTokenIndex(Line, #1, i); |
| 345 |
case i of |
| 346 |
0: Result.BBSID := s; |
| 347 |
1: Result.BoardTitle := s; |
| 348 |
2: Result.FileName := s; |
| 349 |
3: Result.ThreadTitle := s; |
| 350 |
4: Result.RoundName := s; |
| 351 |
end; |
| 352 |
end; |
| 353 |
end; |
| 354 |
end; |
| 355 |
|
| 356 |
end. |