TRoundList = class(TObject)
private
+ FOldFileRead: Boolean;
FBoardList: TList;
FItemList: TList;
function GetCount(RoundType: TGikoRoundType): Integer;
function GetRoundItem(Index: Integer; RoundType: TGikoRoundType): TRoundItem;
- function ParseRoundLine(Line: string; RoundType: TGikoRoundType): TRoundItem;
+ function ParseRoundBoardLine(Line: string): TRoundItem;
+ function ParseRoundThreadLine(Line: string): TRoundItem;
+ function ParseOldRoundBoardLine(Line: string): TRoundItem;
+ function ParseOldRoundThreadLine(Line: string): TRoundItem;
public
RoundNameList: TStringList;
function Add(ThreadItem: TThreadItem): Integer; overload;
procedure Delete(Board: TBoard); overload;
procedure Delete(ThreadItem: TThreadItem); overload;
+ procedure Delete(URL: string; RoundType: TGikoRoundType); overload;
procedure Clear;
function Find(Board: TBoard): Integer; overload;
function Find(ThreadItem: TThreadItem): Integer; overload;
+ function Find(URL: string; RoundType: TGikoRoundType): Integer; overload;
property Count[RoundType: TGikoRoundType]: Integer read GetCount;
+ property OldFileRead: Boolean read FOldFileRead;
property Items[Index: integer; RoundType: TGikoRoundType]: TRoundItem read GetRoundItem;
procedure SetRoundName(Board: TBoard; RoundName: string); overload;
procedure SetRoundName(ThreadItem: TThreadItem; RoundName: string); overload;
- procedure LoadRoundFile;
+ procedure LoadRoundBoardFile;
+ procedure LoadRoundThreadFile;
procedure SaveRoundFile;
+
+ procedure URLReplace(oldURLs: TStringList; newURLs :TStringList);
end;
TRoundItem = class(TObject)
// FBBSType: TGikoBBSType;
FRoundName: string;
FRoundType: TGikoRoundType;
- FBBSID: string;
+ //Item : TObject;
+ FURL : string;
FBoardTitle: string;
FThreadTitle: string;
FFileName: string;
FBoolData: Boolean; //\82¢\82ë\82¢\82ë\8eg\82¤\82å\82£
public
-// property BBSType: TGikoBBSType read FBBSType write FBBSType;
+
+ constructor Create;
+ //property BBSType: TGikoBBSType read FBBSType write FBBSType;
property RoundName: string read FRoundName write FRoundName;
property RoundType: TGikoRoundType read FRoundType write FRoundType;
- property BBSID: string read FBBSID write FBBSID;
+ //property Item : TObject read FItem write FItem;
+ property URL : string read FURL write FURL;
property BoardTitle: string read FBoardTitle write FBoardTitle;
property ThreadTitle: string read FThreadTitle write FThreadTitle;
property FileName: string read FFileName write FFileName;
const
ROUND_BOARD_FILENAME: string = 'RoundBoard.2ch'; //\82 \82Æ\82ÅBoardGroup\82Ö\88Ú\93®
ROUND_ITEM_FILENAME: string = 'RoundItem.2ch'; //\93¯\8fã
- ROUND_INDEX_VERSION: string = '1.00';
-
+ ROUND_INDEX_VERSION: string = '2.00';
+ ERROR_BOARD_FILENAME: string = 'ErrorBoard.2ch'; //Error\8ds\82ð\95Û\8aÇ\82·\82é
+ ERROR_ITEM_FILENAME: string = 'ErrorItem.2ch'; //Error\8ds\82ð\95Û\8aÇ\82·\82é
+constructor TRoundItem.Create;
+begin
+ inherited Create;
+end;
constructor TRoundList.Create;
begin
inherited;
RoundNameList := TStringList.Create;
RoundNameList.Sorted := True;
RoundNameList.Duplicates := dupIgnore;
+ FOldFileRead := false;
end;
destructor TRoundList.Destroy;
Clear;
FBoardList.Free;
FItemList.Free;
- inherited;
+ //inherited;
end;
function TRoundList.Add(Board: TBoard): Integer;
idx: Integer;
Item: TRoundItem;
begin
+ Result := -1;
idx := Find(Board);
if idx = -1 then begin
Item := TRoundItem.Create;
// Item.BBSType := gbt2ch; //\82Æ\82è\82 \82¦\82¸
Item.RoundType := grtBoard;
- Item.BBSID := Board.BBSID;
+// Item.Item := Board;
+ Item.URL := Board.URL;
Item.BoardTitle := Board.Title;
Item.ThreadTitle := '';
Item.FileName := '';
Item.RoundName := Board.RoundName;
- FBoardList.Add(Item);
+ Result := FBoardList.Add(Item);
end;
end;
idx: Integer;
Item: TRoundItem;
begin
+ Result := -1;
idx := Find(ThreadItem);
if idx = -1 then begin
Item := TRoundItem.Create;
// Item.BBSType := gbt2ch; //\82Æ\82è\82 \82¦\82¸
Item.RoundType := grtItem;
- Item.BBSID := ThreadItem.ParentBoard.BBSID;
+// Item.Item := ThreadItem;
+ Item.URL := Threaditem.URL;
Item.BoardTitle := ThreadItem.ParentBoard.Title;
Item.ThreadTitle := ThreadItem.Title;
Item.FileName := ThreadItem.FileName;
Item.RoundName := ThreadItem.RoundName;
- FItemList.Add(Item);
+ Result := FItemList.Add(Item);
end;
end;
procedure TRoundList.Delete(Board: TBoard);
var
idx: Integer;
- Item: TRoundItem;
+// Item: TRoundItem;
begin
idx := Find(Board);
if idx <> -1 then begin
- Item := TRoundItem(FBoardList[idx]);
- Item.Free;
+ TRoundItem(FBoardList[idx]).Free;
FBoardList.Delete(idx);
end;
end;
procedure TRoundList.Delete(ThreadItem: TThreadItem);
var
idx: Integer;
- Item: TRoundItem;
+// Item: TRoundItem;
begin
idx := Find(ThreadItem);
if idx <> -1 then begin
- Item := TRoundItem(FItemList[idx]);
- Item.Free;
+ TRoundItem(FItemList[idx]).Free;
FItemList.Delete(idx);
end;
end;
i: Integer;
begin
for i := FBoardList.Count - 1 downto 0 do begin
- TRoundItem(FBoardList[i]).Free;
+ if FBoardList[i] <> nil then
+ TRoundItem(FBoardList[i]).Free;
FBoardList.Delete(i);
end;
+ FBoardList.Capacity := FBoardList.Count;
for i := FItemList.Count - 1 downto 0 do begin
- TRoundItem(FItemList[i]).Free;
+ if FItemList[i] <> nil then
+ TRoundItem(FItemList[i]).Free;
FItemList.Delete(i);
end;
+ FItemList.Capacity := FItemList.Count;
end;
function TRoundList.Find(Board: TBoard): Integer;
for i := 0 to FBoardList.Count - 1 do begin
Item := TRoundItem(FBoardList[i]);
if Item.FRoundType <> grtBoard then Continue;
- if Item.FBBSID = Board.BBSID then begin
+ if Item.FURL = Board.URL then begin
Result := i;
Exit;
end;
for i := 0 to FItemList.Count - 1 do begin
Item := TRoundItem(FItemList[i]);
if Item.FRoundType <> grtItem then Continue;
- if (Item.FBBSID = ThreadItem.ParentBoard.BBSID) and (Item.FFileName = ThreadItem.FileName) then begin
+ if Item.FURL = ThreadItem.URL then begin
Result := i;
Exit;
end;
end;
end;
+function TRoundList.Find(URL: string; RoundType: TGikoRoundType): Integer;
+var
+ i: Integer;
+ Item: TRoundItem;
+begin
+ Result := -1;
+ if RoundType = grtItem then begin
+ for i := 0 to FItemList.Count - 1 do begin
+ Item := TRoundItem(FItemList[i]);
+ if Item.FRoundType <> RoundType then Continue;
+ if Item.FURL = URL then begin
+ Result := i;
+ Exit;
+ end;
+ end;
+ end else begin
+ for i := 0 to FBoardList.Count - 1 do begin
+ Item := TRoundItem(FBoardList[i]);
+ if Item.FRoundType <> RoundType then Continue;
+ if Item.FURL = URL then begin
+ Result := i;
+ Exit;
+ end;
+ end;
+ end;
+end;
+procedure TRoundList.Delete(URL: string; RoundType: TGikoRoundType);
+var
+ idx: Integer;
+ Item: TRoundItem;
+ board: TBoard;
+ threadItem: TThreadItem;
+begin
+ idx := Find(URL, RoundType);
+ if idx <> -1 then begin
+
+ if RoundType = grtBoard then begin
+ Item := TRoundItem(FBoardList[idx]);
+ Item.Free;
+ FBoardList.Delete(idx);
+ board := BBSsFindBoardFromURL(URL);
+ if board <> nil then begin
+ board.Round := False;
+ board.RoundName := '';
+ end;
+ end else begin
+ Item := TRoundItem(FItemList[idx]);
+ Item.Free;
+ FItemList.Delete(idx);
+
+ threadItem := BBSsFindThreadFromURL(URL);
+ if threadItem <> nil then begin
+ threadItem.Round := false;
+ threadItem.RoundName := '';
+ end;
+ end;
+ end;
+end;
procedure TRoundList.SetRoundName(Board: TBoard; RoundName: string);
var
Result := TRoundItem(FItemList[Index]);
end;
end;
-
-procedure TRoundList.LoadRoundFile;
+procedure TRoundList.LoadRoundBoardFile;
var
i: Integer;
sl: TStringList;
FileName: string;
+ errorSl: TStringList;
+ errorFileName: string;
Item: TRoundItem;
+ delCount: Integer;
begin
sl := TStringList.Create;
+ errorSl := TStringList.Create;
+ errorSl.Duplicates := dupIgnore;
try
//\83{\81[\83h\8f\84\89ñ\83t\83@\83C\83\8b\93Ç\82Ý\8d\9e\82Ý
FileName := GikoSys.GetConfigDir + ROUND_BOARD_FILENAME;
+ //\83G\83\89\81[\8ds\95Û\91¶\83t\83@\83C\83\8b\93Ç\82Ý\8d\9e\82Ý
+ errorFileName := GikoSys.GetConfigDir + ERROR_BOARD_FILENAME;
if FileExists(FileName) then begin
sl.LoadFromFile(FileName);
- //\82P\8ds\96Ú\82Í\83o\81[\83W\83\87\83\93\82È\82Ì\82Å\96³\8e\8b
- for i := 1 to sl.Count - 1 do begin
- Item := ParseRoundLine(sl[i], grtBoard);
- FBoardList.Add(Item);
- RoundNameList.Add(Item.RoundName);
- end;
+ if FileExists(errorFileName) then begin
+ try
+ errorSl.LoadFromFile(errorFileName);
+ except
+ end;
+ end;
+ //Item := TRoundItem.Create;
+ delCount := 0;
+ //\82P\8ds\96Ú\82Í\83o\81[\83W\83\87\83\93
+ if sl[0] = ROUND_INDEX_VERSION then begin
+ for i := 1 to sl.Count - 1 do begin
+ Item := ParseRoundBoardLine(sl[i - delCount]);
+ if Item <> nil then begin
+ FBoardList.Add(Item);
+ RoundNameList.Add(Item.RoundName);
+ end else begin
+ errorSl.Add( sl[i - delCount] );
+ sl.Delete(i- delCount);
+ Inc(delCount);
+ end;
+ end;
+ end else begin
+ if FOldFileRead then begin //\83M\83R\83i\83r\96{\91Ì\82ª\83{\81[\83h\83t\83@\83C\83\8b\82ð\82æ\82Ý\82Æ\82Á\82½\8cã\82¶\82á\82È\82¢\82Æ\83N\83\89\83b\83V\83\85\82·\82é\82Ì\82Å
+ for i := 1 to sl.Count - 1 do begin
+ Item := ParseOldRoundBoardLine(sl[i - delCount]);
+ if Item <> nil then begin
+ FBoardList.Add(Item);
+ RoundNameList.Add(Item.RoundName);
+ end else begin
+ errorSl.Add( sl[i- delCount] );
+ sl.Delete(i- delCount);
+ Inc(delCount);
+ end;
+ end;
+ end else
+ FOldFileRead := true;
+ end;
end;
+ if errorSl.Count > 0 then
+ errorSl.SaveToFile(errorFileName);
+ finally
+ errorSl.Free;
+ sl.Free;
+ end;
+end;
+procedure TRoundList.LoadRoundThreadFile;
+var
+ i: Integer;
+// j: Integer;
+ sl: TStringList;
+ FileName: string;
+ errorSl: TStringList;
+ errorFileName: string;
+ Item: TRoundItem;
+ delCount: Integer;
+// boardList : TStringList;
+begin
+// boardList := TStringList.Create;
+// boardList.Duplicates := dupIgnore;
+ errorSl := TStringList.Create;
+ errorSl.Duplicates := dupIgnore;
+ sl := TStringList.Create;
+ try
//\83X\83\8c\8f\84\89ñ\83t\83@\83C\83\8b\93Ç\82Ý\8d\9e\82Ý
FileName := GikoSys.GetConfigDir + ROUND_ITEM_FILENAME;
+ //\83G\83\89\81[\8ds\95Û\91¶\83t\83@\83C\83\8b\93Ç\82Ý\8d\9e\82Ý
+ errorFileName := GikoSys.GetConfigDir + ERROR_ITEM_FILENAME;
if FileExists(FileName) then begin
sl.LoadFromFile(FileName);
- //\82P\8ds\96Ú\82Í\83o\81[\83W\83\87\83\93\82È\82Ì\82Å\96³\8e\8b
- for i := 1 to sl.Count - 1 do begin
- Item := ParseRoundLine(sl[i], grtItem);
- FItemList.Add(Item);
- RoundNameList.Add(Item.RoundName);
- end;
+ if FileExists(errorFileName) then begin
+ try
+ errorSl.LoadFromFile(errorFileName);
+ except
+ end;
+ end;
+ //Item := TRoundItem.Create;
+ delCount := 0;
+ //\82P\8ds\96Ú\82Í\83o\81[\83W\83\87\83\93
+ if sl[0] = ROUND_INDEX_VERSION then begin
+ for i := 1 to sl.Count - 1 do begin
+ Item := ParseRoundThreadLine(sl[i - delCount]);
+ if Item <> nil then begin
+ FItemList.Add(Item);
+ RoundNameList.Add(Item.RoundName);
+ end else begin
+ errorSl.Add(sl[i - delCount]);
+ sl.Delete(i - delCount);
+ Inc(delCount);
+ end;
+ end;
+ end else begin
+ LoadRoundBoardFile;
+ for i := 1 to sl.Count - 1 do begin
+ Item := ParseOldRoundThreadLine(sl[i - delCount]);
+ if Item <> nil then begin
+ FItemList.Add(Item);
+ RoundNameList.Add(Item.RoundName);
+ end else begin
+ errorSl.Add(sl[i - delCount]);
+ sl.Delete(i - delCount);
+ Inc(delCount);
+ end;
+ end;
+ end;
+// j := boardList.Count - 1;
+// while j >= 0 do begin
+// GikoSys.ReadSubjectFile( BBSsFindBoardFromURL( boardList[j] ) );
+// boardList.Delete(j);
+// Dec(j);
+// end;
+ if errorSl.Count > 0 then
+ errorSl.SaveToFile(errorFileName);
end;
finally
+ errorSl.Free;
sl.Free;
+// boardList.Free;
end;
end;
-
procedure TRoundList.SaveRoundFile;
var
i: integer;
sl.Add(ROUND_INDEX_VERSION);
for i := 0 to FBoardList.Count - 1 do begin
Item := TRoundItem(FBoardList[i]);
- s := Item.BBSID + #1
+ s := Item.URL + #1
+ Item.BoardTitle + #1
+ Item.RoundName;
sl.Add(s);
sl.Add(ROUND_INDEX_VERSION);
for i := 0 to FItemList.Count - 1 do begin
Item := TRoundItem(FItemList[i]);
- s := Item.BBSID + #1
+ s := Item.URL + #1
+ Item.BoardTitle + #1
+ Item.FileName + #1
+ Item.ThreadTitle + #1
sl.Free;
end;
end;
+function TRoundList.ParseRoundBoardLine(Line: string): TRoundItem;
+var
+ s: string;
+ i: Integer;
+begin
+ Result := TRoundItem.Create;
+ Result.ThreadTitle := '';
+ Result.FileName := '';
+ Result.RoundType := grtBoard;
+ for i := 0 to 2 do begin
+ s := GikoSys.GetTokenIndex(Line, #1, i);
+ try
+ case i of
+ 0:
+ begin
+ Result.URL := s;
+ end;
+ 1: Result.BoardTitle := s;
+ 2: Result.RoundName := s;
+ end;
+ except
+ Result := nil;
+ Exit;
+ end;
+ end;
+end;
-function TRoundList.ParseRoundLine(Line: string; RoundType: TGikoRoundType): TRoundItem;
+function TRoundList.ParseRoundThreadLine(Line: string): TRoundItem;
var
s: string;
i: Integer;
+// threadItem: TThreadItem;
+begin
+ Result := TRoundItem.Create;
+ Result.RoundType := grtItem;
+ for i := 0 to 4 do begin
+ s := GikoSys.GetTokenIndex(Line, #1, i);
+ try
+ case i of
+ 0:
+ begin
+ Result.URL := s;
+ //threadItem := BBSsFindThreadFromURL( s );
+ //if threadItem <> nil then begin
+ // BoardList.Add( threadItem.ParentBoard.URL );
+ //end;
+ end;
+ 1: Result.BoardTitle := s;
+ 2: Result.FileName := s;
+ 3: Result.ThreadTitle := s;
+ 4: Result.RoundName := s;
+ end;
+ except
+ Result := nil;
+ Exit;
+ end;
+ end;
+end;
+
+function TRoundList.ParseOldRoundBoardLine(Line: string): TRoundItem;
+ var
+ i: Integer;
+ s: string;
+ board: TBoard;
begin
Result := TRoundItem.Create;
- if RoundType = grtBoard then begin
- Result.ThreadTitle := '';
- Result.FileName := '';
- Result.RoundType := grtBoard;
- for i := 0 to 2 do begin
- s := GikoSys.GetTokenIndex(Line, #1, i);
- case i of
- 0: Result.BBSID := s;
- 1: Result.BoardTitle := s;
- 2: Result.RoundName := s;
- end;
- end;
- end else if RoundType = grtItem then begin
- Result.RoundType := grtItem;
- for i := 0 to 4 do begin
- s := GikoSys.GetTokenIndex(Line, #1, i);
- case i of
- 0: Result.BBSID := s;
- 1: Result.BoardTitle := s;
- 2: Result.FileName := s;
- 3: Result.ThreadTitle := s;
- 4: Result.RoundName := s;
- end;
- end;
- end;
+ Result.ThreadTitle := '';
+ Result.FileName := '';
+ Result.RoundType := grtBoard;
+ for i := 0 to 2 do begin
+ s := GikoSys.GetTokenIndex(Line, #1, i);
+ try
+ case i of
+ 0:
+ begin
+ board := BBSs[ 0 ].FindBBSID( s );
+ if board <> nil then begin
+ Result.URL := board.URL;
+ end else begin
+ raise Exception.Create('\82±\82Ì\8f\84\89ñ\82Í\93Ç\82Ý\8d\9e\82ß\82È\82¢\82æ\81i\91½\95ª\8aO\95\94\94Â\81j');
+ end;
+ end;
+ 1: Result.FBoardTitle := s;
+ 2: Result.RoundName := s;
+ end;
+ except
+ Result := nil;
+ Exit;
+ end;
+ end;
+end;
+
+function TRoundList.ParseOldRoundThreadLine(Line: string): TRoundItem;
+ var
+ i: Integer;
+ s: string;
+ buf: string;
+ board: TBoard;
+// threadItem: TThreadItem;
+ bbsID: string;
+begin
+ Result := TRoundItem.Create;
+ Result.RoundType := grtItem;
+ for i := 0 to 4 do begin
+ s := GikoSys.GetTokenIndex(Line, #1, i);
+ try
+ case i of
+ 0: bbsID := s;
+ 1: Result.BoardTitle := s;
+ 2:
+ begin
+ Result.FileName := s;
+ board := BBSs[ 0 ].FindBBSID(bbsID);
+ if board <> nil then begin
+ buf := Copy(board.GetSendURL,1,LastDelimiter('/', board.GetSendURL)-1);
+ Result.URL := buf + '/read.cgi/'+ board.BBSID+ '/' +ChangeFileExt(s,'') + '/l50';
+ end else begin
+ raise Exception.Create('\82±\82Ì\8f\84\89ñ\82Í\93Ç\82Ý\8d\9e\82ß\82È\82¢\82æ');
+ end;
+ end;
+ 3: Result.ThreadTitle := s;
+ 4: Result.RoundName := s;
+ end;
+ except
+ Result := nil;
+ break;
+ end;
+ end;
+end;
+procedure TRoundList.URLReplace(oldURLs: TStringList; newURLs :TStringList);
+var
+ i: Integer;
+ j: Integer;
+ tempString: string;
+ tmpURL: string;
+ oldHost: string;
+ oldBoardName: string;
+ newHost: string;
+ newBoardName: string;
+begin
+ if oldURLs.Count <> newURLs.Count then
+ Exit;
+ //\82±\82±\82©\82ç\81ABoard\82ÌURL\82Ì\95Ï\8dX
+ for j :=0 to oldURLs.Count - 1 do begin
+ for i :=0 to FBoardList.Count - 1 do begin
+ if TRoundItem(FBoardList[i]).FURL = oldURLs[i] then
+ TRoundItem(FBoardList[i]).FURL := newURLs[i];
+ end;
+ end;
+ //\82±\82±\82Ü\82Å\81ABoard\82ÌURL\82Ì\95Ï\8dX
+
+ //\82±\82±\82©\82ç\81AThread\82ÌURL\82Ì\95Ï\8dX
+ //\96Ê\93|\82¾\82¯\82Çthread\82Í\82»\82ê\82¼\82êURL\82ð\83`\83\83\83b\83N\82µ\82È\82ª\82ç\82â\82Á\82Ä\82©\82È\82«\82á\82¢\82¯\82È\82¢\81B
+ for i := 0 to oldURLs.Count - 1 do begin
+ tmpURL := Copy(oldURLs[i], 1, Length(oldURLs[i]) -1);
+ oldHost := Copy(tmpURL, 1, LastDelimiter('/', tmpURL) );
+ oldBoardName := Copy(tmpURL, LastDelimiter('/', tmpURL), Length(tmpURL) ) + '/';
+ tmpURL := Copy(newURLs[i], 1, Length(newURLs[i]) -1);
+ newHost := Copy(tmpURL, 1, LastDelimiter('/', tmpURL) );
+ newBoardName := Copy(tmpURL, LastDelimiter('/', tmpURL), Length(tmpURL) ) + '/';
+
+ for j := 0 to FItemList.Count - 1 do begin
+ tempString := TRoundItem(FItemList[j]).FURL;
+ if ( AnsiPos(oldBoardName, tempString) <> 0 ) and ( AnsiPos(oldHost, tempString ) <> 0 ) then begin
+ tempString := StringReplace(tempString, oldHost, newHost,[]);
+ TRoundItem(FItemList[j]).FURL := tempString;
+ end;
+ end;
+ end;
+ //\82±\82±\82Ü\82Å\81AThread\82ÌURL\82Ì\95Ï\8dX
+
end;
end.