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