OSDN Git Service

旧ファイルフォーマット読み込み時のエラー処理追加
[gikonavigoeson/gikonavi.git] / RoundData.pas
index a75d1e3..11b78c8 100644 (file)
@@ -79,7 +79,8 @@ 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 = '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;
@@ -305,35 +306,59 @@ var
        i: Integer;
        sl: TStringList;
        FileName: string;
+    errorSl: TStringList;
+    errorFileName: string;
        Item: TRoundItem;
 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);
-            Item := TRoundItem.Create;
+            if FileExists(errorFileName) then begin
+               try
+                       errorSl.LoadFromFile(errorFileName);
+                except
+                end;
+            end;
+            //Item := TRoundItem.Create;
             //\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
-
+                               for i := sl.Count - 1 downto 1 do begin
                                        Item := ParseRoundBoardLine(sl[i]);
-                                       FBoardList.Add(Item);
-                                       RoundNameList.Add(Item.RoundName);
+                    if Item <> nil then begin
+                                               FBoardList.Add(Item);
+                                               RoundNameList.Add(Item.RoundName);
+                    end else begin
+                       errorSl.Add( sl[i] );
+                        sl.Delete(i);
+                    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
+                                       for i := sl.Count - 1 downto  1 do begin
                                                Item := ParseOldRoundBoardLine(sl[i]);
-                                               FBoardList.Add(Item);
-                                               RoundNameList.Add(Item.RoundName);
+                        if Item <> nil then begin
+                                                       FBoardList.Add(Item);
+                                                       RoundNameList.Add(Item.RoundName);
+                        end else begin
+                               errorSl.Add( sl[i] );
+                               sl.Delete(i);
+                        end;
                                        end;
                 end else
                        FOldFileRead := true;
             end;
                end;
+        if errorSl.Count > 0 then
+               errorSl.SaveToFile(errorFileName);
        finally
+       errorSl.Free;
                sl.Free;
        end;
 end;
@@ -343,41 +368,64 @@ var
     j: Integer;
        sl: TStringList;
        FileName: string;
+    errorSl: TStringList;
+    errorFileName: string;
        Item: TRoundItem;
     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);
-            Item := TRoundItem.Create;
+            if FileExists(errorFileName) then begin
+               try
+                       errorSl.LoadFromFile(errorFileName);
+                except
+                end;
+            end;
+            //Item := TRoundItem.Create;
                        //\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
-
+                               for i := sl.Count - 1 downto 1 do begin
                                        Item := ParseRoundThreadLine(sl[i], boardList);
-                                       FItemList.Add(Item);
-                                       RoundNameList.Add(Item.RoundName);
-                               end;
+                    if Item <> nil then begin
+                                               FItemList.Add(Item);
+                                               RoundNameList.Add(Item.RoundName);
+                                       end else begin
+                        errorSl.Add(sl[i]);
+                        sl.Delete(i);
+                    end;
+                end;
             end else begin
                 LoadRoundBoardFile;
-                for i := 1 to sl.Count - 1 do begin
+                for i := sl.Count - 1 downto 1 do begin
                                        Item := ParseOldRoundThreadLine(sl[i], boardList);
-                                       FItemList.Add(Item);
-                                       RoundNameList.Add(Item.RoundName);
+                    if Item <> nil then begin
+                                               FItemList.Add(Item);
+                                               RoundNameList.Add(Item.RoundName);
+                    end else begin
+                                               errorSl.Add(sl[i]);
+                        sl.Delete(i);
+                    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
                sl.Free;
         boardList.Free;
@@ -433,13 +481,18 @@ 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;
-               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;
@@ -454,19 +507,24 @@ begin
        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
-                       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;
@@ -483,14 +541,23 @@ begin
     Result.RoundType := grtBoard;
     for i := 0 to 2 do begin
        s := GikoSys.GetTokenIndex(Line, #1, i);
-        case i of
-               0:
-               begin
-               board := BBSs[ 0 ].FindBBSID( s );
-                       Result.URL := board.URL;
-               end;
-            1: Result.FBoardTitle := s;
-            2: 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('\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;
@@ -501,28 +568,35 @@ function TRoundList.ParseOldRoundThreadLine(Line: string; var BoardList : TStrin
        s: string;
        buf: string;
     board: TBoard;
-    threadItem: TThreadItem;
+//    threadItem: TThreadItem;
     bbsID: string;
 begin
        Result := TRoundItem.Create;
     Result.RoundType := grtItem;
     for i := 0 to 4 do begin
        s := GikoSys.GetTokenIndex(Line, #1, i);
-        case i of
-            0: bbsID := s;
-            1: Result.BoardTitle := s;
-            2:
-               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';
-                end;
-            end;
-            3: Result.ThreadTitle := s;
-            4: Result.RoundName := s;
+        try
+               case i of
+               0: bbsID := s;
+                   1: Result.BoardTitle := s;
+               2:
+                       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';
+                   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;
+               3: Result.ThreadTitle := s;
+                   4: Result.RoundName := s;
+               end;
+        except
+               Result := nil;
+            Exit;
         end;
     end;
 end;