X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=RoundData.pas;h=90ebfd667954c5e1e538c0d94e5633e1124612c5;hb=1b2959cad53beb8917583092d06901b855770190;hp=f8f35d05921f407d9ada3a42604674608da514c6;hpb=30a763d59b4cb7b3f982d19d4f6416b07477493a;p=gikonavigoeson%2Fgikonavi.git diff --git a/RoundData.pas b/RoundData.pas index f8f35d0..90ebfd6 100644 --- a/RoundData.pas +++ b/RoundData.pas @@ -12,14 +12,15 @@ type TRoundList = class(TObject) private + FOldFileRead: Boolean; FBoardList: TList; FItemList: TList; function GetCount(RoundType: TGikoRoundType): Integer; function GetRoundItem(Index: Integer; RoundType: TGikoRoundType): TRoundItem; function ParseRoundBoardLine(Line: string): TRoundItem; - function ParseRoundThreadLine(Line: string; var BoardList : TStringList): TRoundItem; + function ParseRoundThreadLine(Line: string): TRoundItem; function ParseOldRoundBoardLine(Line: string): TRoundItem; - function ParseOldRoundThreadLine(Line: string; var BoardList : TStringList): TRoundItem; + function ParseOldRoundThreadLine(Line: string): TRoundItem; public RoundNameList: TStringList; @@ -29,18 +30,22 @@ type 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 ConvertRoundFile; //bata44ˆÈ‘O‚ÌRoundfile‚ð•ÏŠ·‚·‚é procedure LoadRoundBoardFile; procedure LoadRoundThreadFile; procedure SaveRoundFile; + + procedure URLReplace(oldURLs: TStringList; newURLs :TStringList); end; TRoundItem = class(TObject) @@ -48,17 +53,19 @@ type // FBBSType: TGikoBBSType; FRoundName: string; FRoundType: TGikoRoundType; - FItem : TObject; + //Item : TObject; FURL : string; FBoardTitle: string; FThreadTitle: string; FFileName: string; FBoolData: Boolean; //‚¢‚ë‚¢‚ëŽg‚¤‚å‚£ 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 Item : TObject read FItem write FItem; + //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; @@ -74,7 +81,12 @@ const ROUND_BOARD_FILENAME: string = 'RoundBoard.2ch'; //‚ ‚Æ‚ÅBoardGroup‚ÖˆÚ“® ROUND_ITEM_FILENAME: string = 'RoundItem.2ch'; //“¯ã ROUND_INDEX_VERSION: string = '2.00'; - + ERROR_BOARD_FILENAME: string = 'ErrorBoard.2ch'; //Errors‚ð•ÛŠÇ‚·‚é + ERROR_ITEM_FILENAME: string = 'ErrorItem.2ch'; //Errors‚ð•ÛŠÇ‚·‚é +constructor TRoundItem.Create; +begin + inherited Create; +end; constructor TRoundList.Create; begin inherited; @@ -83,6 +95,7 @@ begin RoundNameList := TStringList.Create; RoundNameList.Sorted := True; RoundNameList.Duplicates := dupIgnore; + FOldFileRead := false; end; destructor TRoundList.Destroy; @@ -91,7 +104,7 @@ begin Clear; FBoardList.Free; FItemList.Free; - inherited; + //inherited; end; function TRoundList.Add(Board: TBoard): Integer; @@ -105,7 +118,7 @@ begin Item := TRoundItem.Create; // Item.BBSType := gbt2ch; //‚Æ‚è‚ ‚¦‚¸ Item.RoundType := grtBoard; - Item.Item := Board; +// Item.Item := Board; Item.URL := Board.URL; Item.BoardTitle := Board.Title; Item.ThreadTitle := ''; @@ -126,7 +139,7 @@ begin Item := TRoundItem.Create; // Item.BBSType := gbt2ch; //‚Æ‚è‚ ‚¦‚¸ Item.RoundType := grtItem; - Item.Item := ThreadItem; +// Item.Item := ThreadItem; Item.URL := Threaditem.URL; Item.BoardTitle := ThreadItem.ParentBoard.Title; Item.ThreadTitle := ThreadItem.Title; @@ -139,12 +152,11 @@ 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; @@ -152,12 +164,11 @@ 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; @@ -167,13 +178,17 @@ var 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; @@ -207,6 +222,64 @@ begin 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 @@ -257,74 +330,138 @@ 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 //ƒ{[ƒh„‰ñƒtƒ@ƒCƒ‹“ǂݍž‚Ý FileName := GikoSys.GetConfigDir + ROUND_BOARD_FILENAME; + //ƒGƒ‰[s•Û‘¶ƒtƒ@ƒCƒ‹“ǂݍž‚Ý + errorFileName := GikoSys.GetConfigDir + ERROR_BOARD_FILENAME; if FileExists(FileName) then begin sl.LoadFromFile(FileName); + if FileExists(errorFileName) then begin + try + errorSl.LoadFromFile(errorFileName); + except + end; + end; + //Item := TRoundItem.Create; + delCount := 0; //‚Ps–ڂ̓o[ƒWƒ‡ƒ“ if sl[0] = ROUND_INDEX_VERSION then begin for i := 1 to sl.Count - 1 do begin - Item := ParseRoundBoardLine(sl[i]); - FBoardList.Add(Item); - RoundNameList.Add(Item.RoundName); + 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 - for i := 1 to sl.Count - 1 do begin - Item := ParseOldRoundBoardLine(sl[i]); - FBoardList.Add(Item); - RoundNameList.Add(Item.RoundName); - end; + if FOldFileRead then begin //ƒMƒRƒiƒr–{‘Ì‚ªƒ{[ƒhƒtƒ@ƒCƒ‹‚ð‚æ‚Ý‚Æ‚Á‚½Œã‚¶‚á‚È‚¢‚ƃNƒ‰ƒbƒVƒ…‚·‚é‚Ì‚Å + 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; +// j: Integer; sl: TStringList; FileName: string; + errorSl: TStringList; + errorFileName: string; Item: TRoundItem; - boardList : TStringList; + delCount: Integer; +// boardList : TStringList; begin - boardList := TStringList.Create; - boardList.Duplicates := dupIgnore; +// boardList := TStringList.Create; +// boardList.Duplicates := dupIgnore; + errorSl := TStringList.Create; + errorSl.Duplicates := dupIgnore; sl := TStringList.Create; try //ƒXƒŒ„‰ñƒtƒ@ƒCƒ‹“ǂݍž‚Ý FileName := GikoSys.GetConfigDir + ROUND_ITEM_FILENAME; + //ƒGƒ‰[s•Û‘¶ƒtƒ@ƒCƒ‹“ǂݍž‚Ý + errorFileName := GikoSys.GetConfigDir + ERROR_ITEM_FILENAME; if FileExists(FileName) then begin sl.LoadFromFile(FileName); + if FileExists(errorFileName) then begin + try + errorSl.LoadFromFile(errorFileName); + except + end; + end; + //Item := TRoundItem.Create; + delCount := 0; //‚Ps–ڂ̓o[ƒWƒ‡ƒ“ if sl[0] = ROUND_INDEX_VERSION then begin for i := 1 to sl.Count - 1 do begin - Item := ParseRoundThreadLine(sl[i], boardList); - FItemList.Add(Item); - RoundNameList.Add(Item.RoundName); - end; + 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], boardList); - FItemList.Add(Item); - RoundNameList.Add(Item.RoundName); + 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; - j := boardList.Count - 1; - while j >= 0 do begin - GikoSys.ReadSubjectFile( BBSsFindBoardFromURL( boardList[j] ) ); - boardList.Delete(j); - Dec(j); - end; finally + errorSl.Free; sl.Free; - boardList.Free; +// boardList.Free; end; end; procedure TRoundList.SaveRoundFile; @@ -377,42 +514,50 @@ begin Result.RoundType := grtBoard; for i := 0 to 2 do begin s := GikoSys.GetTokenIndex(Line, #1, i); - case i of + try + case i of 0: - begin - Result.URL := s; - Result.Item := BBSsFindBoardFromURL( s ); - end; - 1: Result.BoardTitle := s; - 2: Result.RoundName := s; + begin + Result.URL := s; + end; + 1: Result.BoardTitle := s; + 2: Result.RoundName := s; + end; + except + Result := nil; + Exit; end; end; end; -function TRoundList.ParseRoundThreadLine(Line: string; var BoardList : TStringList): TRoundItem; +function TRoundList.ParseRoundThreadLine(Line: string): TRoundItem; var s: string; i: Integer; - threadItem: TThreadItem; +// threadItem: TThreadItem; begin Result := TRoundItem.Create; Result.RoundType := grtItem; for i := 0 to 4 do begin s := GikoSys.GetTokenIndex(Line, #1, i); - case i of - 0: - begin - Result.URL := s; - threadItem := BBSsFindThreadFromURL( s ); - if threadItem <> nil then begin - Result.Item := threadItem; - BoardList.Add( threadItem.ParentBoard.URL ); + try + case i of + 0: + begin + Result.URL := s; + //threadItem := BBSsFindThreadFromURL( s ); + //if threadItem <> nil then begin + // BoardList.Add( threadItem.ParentBoard.URL ); + //end; end; - end; - 1: Result.BoardTitle := s; - 2: Result.FileName := s; - 3: Result.ThreadTitle := s; - 4: Result.RoundName := s; + 1: Result.BoardTitle := s; + 2: Result.FileName := s; + 3: Result.ThreadTitle := s; + 4: Result.RoundName := s; + end; + except + Result := nil; + Exit; end; end; end; @@ -421,61 +566,114 @@ function TRoundList.ParseOldRoundBoardLine(Line: string): TRoundItem; var i: Integer; s: string; - buf: string; board: TBoard; - threadItem: TThreadItem; begin Result := TRoundItem.Create; Result.ThreadTitle := ''; Result.FileName := ''; Result.RoundType := grtBoard; - for i := 0 to 1 do begin + for i := 0 to 2 do begin s := GikoSys.GetTokenIndex(Line, #1, i); - case i of - 0: - begin - Result.BoardTitle := s; - board := BBSs[ 0 ].FindBBSID( s ); - Result.URL := board.URL; - Result.Item := BBSsFindBoardFromURL( Result.URL ); - end; - 1: Result.RoundName := s; + 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('‚±‚̏„‰ñ‚͓ǂݍž‚ß‚È‚¢‚æi‘½•ªŠO•””j'); + end; + end; + 1: Result.FBoardTitle := s; + 2: Result.RoundName := s; + end; + except + Result := nil; + Exit; end; end; end; -function TRoundList.ParseOldRoundThreadLine(Line: string; var BoardList : TStringList): TRoundItem; +function TRoundList.ParseOldRoundThreadLine(Line: string): TRoundItem; var i: Integer; s: string; buf: string; board: TBoard; - threadItem: TThreadItem; +// threadItem: TThreadItem; + bbsID: string; begin Result := TRoundItem.Create; Result.RoundType := grtItem; - for i := 0 to 3 do begin + for i := 0 to 4 do begin s := GikoSys.GetTokenIndex(Line, #1, i); - case i of - 0: Result.BoardTitle := s; - 1: - begin - Result.FileName := s; - board := BBSs[ 0 ].FindBoardFromTitle(Result.BoardTitle); - if board <> nil then begin - BoardList.Add(board.URL); - buf := Copy(board.GetSendURL,1,LastDelimiter('/', board.GetSendURL)-1); - Result.URL := buf + '/read.cgi/'+ board.BBSID+ '/' +ChangeFileExt(s,'') + '/l50'; - threadItem := BBSsFindThreadFromURL(Result.URL); - if threadItem <> nil then begin - Result.Item := threadItem; + 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('‚±‚̏„‰ñ‚͓ǂݍž‚ß‚È‚¢‚æ'); end; - 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; + //‚±‚±‚©‚çABoard‚ÌURL‚̕ύX + 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; + //‚±‚±‚܂ŁABoard‚ÌURL‚̕ύX + + //‚±‚±‚©‚çAThread‚ÌURL‚̕ύX + //–Ê“|‚¾‚¯‚Çthread‚Í‚»‚ꂼ‚êURL‚ðƒ`ƒƒƒbƒN‚µ‚È‚ª‚ç‚â‚Á‚Ä‚©‚È‚«‚á‚¢‚¯‚È‚¢B + 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; - 2: Result.ThreadTitle := s; - 3: Result.RoundName := s; end; end; + //‚±‚±‚܂ŁAThread‚ÌURL‚̕ύX + end; end.