OSDN Git Service

お気に入りのURLを鯖移転時に自動で変更するようにしてみた。
authorh677 <h677>
Tue, 6 Jan 2004 16:14:39 +0000 (16:14 +0000)
committerh677 <h677>
Tue, 6 Jan 2004 16:14:39 +0000 (16:14 +0000)
Favorite.pas
Giko.pas
NewBoard.pas

index cee4eda..80e6269 100644 (file)
@@ -4,7 +4,8 @@ interface
 
 uses
        Messages, SysUtils, Classes, Contnrs, ComCtrls, {HttpApp,} YofUtils,
-       GikoSystem{, XMLIntf, XMLDoc}, GikoXMLDoc, BoardGroup, windows;
+       GikoSystem{, XMLIntf, XMLDoc}, GikoXMLDoc, BoardGroup, windows,
+    MojuUtils;
        {SAX, SAXHelpers, SAXComps, SAXKW;}
 
 type
@@ -61,6 +62,7 @@ type
                procedure SetFavTreeView(TreeView: TTreeView);
                procedure ReadFavorite;
                procedure WriteFavorite;
+        procedure URLReplace(oldURLs: TStringList; newURLs: TStringList);
                property TreeView: TTreeView read FTreeView;
        end;
 
@@ -537,6 +539,63 @@ begin
        end;
 end;
 
+procedure TFavoriteDM.URLReplace(oldURLs: TStringList; newURLs: TStringList);
+var
+       FavoriteFilePath: string;
+    tempStringList: TStringList;
+    i: Integer;
+    j: Integer;
+    tmpURL: string;
+    oldHost: string;
+    oldBoardName: string;
+    newHost: string;
+    newBoardName: string;
+    tempString: string;
+begin
+
+       FavoriteFilePath := GikoSys.GetConfigDir + FAVORITE_FILE_NAME;
+
+       if FileExists( FavoriteFilePath ) then begin
+               tempStringList := TStringList.Create;
+               try
+                       tempStringList.LoadFromFile( FavoriteFilePath );
+            if oldURLs.Count = newURLs.Count then begin
+                //\82±\82ê\82Å\81ABoard\82Í\91S\82Ä\90Ø\82è\91Ö\82í\82é
+                       for i := 0 to oldURLs.Count - 1 do begin
+                           CustomStringReplace(tempStringList,oldURLs[i],newURLs[i],true);
+                end;
+                //\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 tempStringList.Count - 1 do begin
+                                               tempString := tempStringList[j];
+                       if AnsiPos('favtype="thread"',tempString ) <> 0 then begin
+                               tempString := Copy(tempString, AnsiPos('url="',tempString ) + 5, AnsiPos('" title="',tempString ) -AnsiPos('url="',tempString ) - 5);
+                            if ( AnsiPos(oldBoardName, tempString) <> 0 ) and ( AnsiPos(oldHost, tempString ) <> 0 ) then begin
+                                tempString := StringReplace(tempStringList[j], oldHost, newHost,[]);
+                                //tempString := StringReplace(tempString, oldBoardName, newBoardName,[]);
+                                tempStringList[j] := tempString;
+                            end;
+
+                       end;
+                       end;
+                end;
+
+            end;
+
+                       tempStringList.SaveToFile( FavoriteFilePath );
+               finally
+                       tempStringList.Free;
+               end;
+       end;
+end;
+
 function TFavoriteDM.GetFavoriteFilePath() : String;
 begin
        Result := GikoSys.GetConfigDir + FAVORITE_FILE_NAME;
index 1c6c4d5..e4d3337 100644 (file)
--- a/Giko.pas
+++ b/Giko.pas
@@ -1000,6 +1000,8 @@ type
 //             property Favorite: TFavorite read FFavorite write FFavorite;
                procedure SetToolBarPopup;
                procedure ShowFavoriteAddDialog( Item : TObject );
+        procedure FavoritesURLReplace(oldURLs: TStringList; newURLs: TStringList);
+
                property ListViewBackGroundColor: TColor read FListViewBackGroundColor write SetListViewBackGroundColor;
                property UseOddResOddColor : Boolean read FUseOddResOddColor write FUseOddResOddColor;
                property OddColor : TColor read FOddColor write FOddColor;
@@ -8822,6 +8824,11 @@ begin
        AddRoundNameMenu(dummy1);
 end;
 
+procedure TGikoForm.FavoritesURLReplace(oldURLs: TStringList; newURLs: TStringList);
+begin
+       FavoriteDM.URLReplace(oldURLs, newURLs);
+end;
+
 initialization
                                OleInitialize(nil);
 finalization
index 288a028..2d6a52a 100644 (file)
@@ -6,7 +6,7 @@ uses
        Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
        Dialogs, IdAntiFreezeBase, IdAntiFreeze, IdBaseComponent, IdComponent,
        IdTCPConnection, IdTCPClient, IdHTTP, IDException, StdCtrls, IniFiles,
-       GikoSystem, BoardGroup;
+       GikoSystem, BoardGroup, MojuUtils;
 
 type
        TNewBoardItem = record
@@ -180,99 +180,115 @@ var
        Board: TBoard;
        Change: Boolean;
        ini: TMemIniFile;
+    oldURLs : TStringList;
+    newURLs : TStringList;
 begin
        Change := False;
        MessageMemo.Lines.Add('\90V\94Â\81A\94ÂURL\95Ï\8dX\83`\83F\83b\83N\82ð\8aJ\8en\82µ\82Ü\82·');
        MessageMemo.Lines.Add('');
-       s := StringReplace(s, '<B>', '<b>', [rfReplaceAll, rfIgnoreCase]);
-       s := StringReplace(s, '<BR>', '<br>', [rfReplaceAll, rfIgnoreCase]);
-       s := StringReplace(s, '</B>', '</b>', [rfReplaceAll, rfIgnoreCase]);
-       s := StringReplace(s, '<A HREF', '<a href', [rfReplaceAll, rfIgnoreCase]);
-       s := StringReplace(s, '</A', '</a', [rfReplaceAll, rfIgnoreCase]);
+       s := CustomStringReplace(s, '<B>', '<b>', true);
+       s := CustomStringReplace(s, '<BR>', '<br>', true);
+       s := CustomStringReplace(s, '</B>', '</b>', true);
+       s := CustomStringReplace(s, '<A HREF', '<a href', true);
+       s := CustomStringReplace(s, '</A', '</a', true);
        cate := '';
-       GikoSys.ForceDirectoriesEx(GikoSys.GetConfigDir);
-       ini := TMemIniFile.Create(GikoSys.GetBoardFileName);
+
+    oldURLs := TStringList.Create;
+    newURLs := TStringList.Create;
+
        try
-               //
-               //\8dí\8f\9c\83I\83v\83V\83\87\83\93\82ª\91I\91ð\82³\82ê\82Ä\82¢\82é\8fê\8d\87\82Í\83N\83\8a\83A
 
-               ini.Clear;
-               while True do begin
-                       idx1 := AnsiPos('<b>', s);
-                       idx2 := AnsiPos('<a', s);
-                       if (idx1 = 0) and (idx2 = 0) then Break;
+               GikoSys.ForceDirectoriesEx(GikoSys.GetConfigDir);
+               ini := TMemIniFile.Create(GikoSys.GetBoardFileName);
+               try
+                       //
+                       //\8dí\8f\9c\83I\83v\83V\83\87\83\93\82ª\91I\91ð\82³\82ê\82Ä\82¢\82é\8fê\8d\87\82Í\83N\83\8a\83A
+
+                       ini.Clear;
 
-                       if idx1 < idx2 then begin
-                               //<br>
-                               idx := AnsiPos('</b>', s);
-                               if idx = 0 then begin
-                                       s := Copy(s, idx1 + 4, Length(s));
-                                       continue;
-                               end;
-                               tmp := Copy(s, idx1, (idx - idx1) + 4);
-                               tmp := StringReplace(tmp, '<b>', '', [rfReplaceAll]);
-                               tmp := StringReplace(tmp, '</b>', '', [rfReplaceAll]);
+                       while True do begin
+                               idx1 := AnsiPos('<b>', s);
+                               idx2 := AnsiPos('<a', s);
+                               if (idx1 = 0) and (idx2 = 0) then Break;
+
+                               if idx1 < idx2 then begin
+                                       //<br>
+                                       idx := AnsiPos('</b>', s);
+                                       if idx = 0 then begin
+                                               s := Copy(s, idx1 + 4, Length(s));
+                                               continue;
+                                       end;
+                                       tmp := Copy(s, idx1, (idx - idx1) + 4);
+                                       tmp := CustomStringReplace(tmp, '<b>', '');
+                                       tmp := CustomStringReplace(tmp, '</b>', '');
 
-                               if (tmp = '\82¨\82·\82·\82ß') or
-                                        (tmp = '\93Á\95Ê\8aé\89æ') or
-                                        (tmp = '\82Ü\82¿\82a\82a\82r') or
-                                        (tmp = '\83`\83\83\83b\83g') or
-                                        (tmp = '\82¨\8aG\82©\82«') or
-                                        (tmp = '\89^\89c') or
-                                        (tmp = '\83c\81[\83\8b\97Þ') or
-                                        (tmp = '\91¼\82Ì\83T\83C\83g') then begin
-                                       cate := '';
+                                       if (tmp = '\82¨\82·\82·\82ß') or
+                                                (tmp = '\93Á\95Ê\8aé\89æ') or
+                                                (tmp = '\82Ü\82¿\82a\82a\82r') or
+                                                (tmp = '\83`\83\83\83b\83g') or
+                                                (tmp = '\82¨\8aG\82©\82«') or
+                                                (tmp = '\89^\89c') or
+                                                (tmp = '\83c\81[\83\8b\97Þ') or
+                                                (tmp = '\91¼\82Ì\83T\83C\83g') then begin
+                                               cate := '';
+                                               s := Copy(s, idx + 5, Length(s));
+                                               Continue;
+                                       end;
                                        s := Copy(s, idx + 5, Length(s));
-                                       Continue;
-                               end;
-                               s := Copy(s, idx + 5, Length(s));
-                               cate := tmp;
-                       end else begin
-                               //<a href=
-                               if cate = '' then begin
-                                       s := Copy(s, idx2 + 2, Length(s));
+                                       cate := tmp;
                                end else begin
-                                       idx := AnsiPos('</a>', s);
-                                       tmp := Copy(s, idx2, (idx - idx2) + 4);
-                                       tmp := StringReplace(tmp, '<a href=', '', [rfReplaceAll]);
-                                       tmp := StringReplace(tmp, '</a>', '', [rfReplaceAll]);
-                                       i := AnsiPos('>', tmp);
-                                       if i <> 0 then begin
-                                               URL := Copy(tmp, 1, i - 1);
-                                               Title := Copy(tmp, i + 1, Length(tmp));
-                                               Board := BBSs[ 0 ].FindBoardFromTitle(Title);
-                                               if Board = nil then begin
-                                                       MessageMemo.Lines.Add('\90V\94Â\92Ç\89Á\81u' + Title + '(' + URL + ')\81v');
-                                                       ini.WriteString(cate, Title, URL);
-                                                       Change := True;
-                                               end else begin
-                                                       if Board.URL <> URL then begin
-                                                               MessageMemo.Lines.Add('URL\95Ï\8dX\81u' + Board.Title + '(' + URL +')\81v');
+                                       //<a href=
+                                       if cate = '' then begin
+                                               s := Copy(s, idx2 + 2, Length(s));
+                                       end else begin
+                                               idx := AnsiPos('</a>', s);
+                                               tmp := Copy(s, idx2, (idx - idx2) + 4);
+                                               tmp := CustomStringReplace(tmp, '<a href=', '');
+                                               tmp := CustomStringReplace(tmp, '</a>', '');
+                                               i := AnsiPos('>', tmp);
+                                               if i <> 0 then begin
+                                                       URL := Copy(tmp, 1, i - 1);
+                                                       Title := Copy(tmp, i + 1, Length(tmp));
+                                                       Board := BBSs[ 0 ].FindBoardFromTitle(Title);
+                                                       if Board = nil then begin
+                                                               MessageMemo.Lines.Add('\90V\94Â\92Ç\89Á\81u' + Title + '(' + URL + ')\81v');
                                                                ini.WriteString(cate, Title, URL);
                                                                Change := True;
                                                        end else begin
-                                                               ini.WriteString(cate, Title, URL);
+                                                               if Board.URL <> URL then begin
+                                                                       MessageMemo.Lines.Add('URL\95Ï\8dX\81u' + Board.Title + '(' + URL +')\81v');
+                                                                       ini.WriteString(cate, Title, URL);
+                                    oldURLs.Add(Board.URL);
+                                                               newURLs.Add(URL);
+                                                                       Change := True;
+                                                               end else begin
+                                                                       ini.WriteString(cate, Title, URL);
+                                                               end;
                                                        end;
+                                               end else begin
+                                                       s := Copy(s, idx2 + 2, Length(s));
+                                                       Continue;
                                                end;
-                                       end else begin
-                                               s := Copy(s, idx2 + 2, Length(s));
-                                               Continue;
+                                               s := Copy(s, idx + 5, Length(s));
                                        end;
-                                       s := Copy(s, idx + 5, Length(s));
                                end;
                        end;
+               finally
+                       if Change then
+                               ini.UpdateFile;
+                       ini.Free;
                end;
-       finally
-               if Change then
-                       ini.UpdateFile;
-               ini.Free;
-       end;
-       MessageMemo.Lines.Add('');
-       if Change then begin
-               MessageMemo.Lines.Add('\90V\94Â\81A\94ÂURL\95Ï\8dX\83`\83F\83b\83N\82ª\8a®\97¹\82µ\82Ü\82µ\82½');
-               MessageMemo.Lines.Add('\81u\95Â\82\82é\81v\83{\83^\83\93\82ð\89\9f\82µ\82Ä\82­\82¾\82³\82¢');
-       end else
-               MessageMemo.Lines.Add('\90V\94Â\81A\94ÂURL\95Ï\8dX\82Í \82 \82è\82Ü\82¹\82ñ\82Å\82µ\82½');
+               MessageMemo.Lines.Add('');
+           if Change then begin
+            GikoForm.FavoritesURLReplace(oldURLs, newURLs);
+                       MessageMemo.Lines.Add('\90V\94Â\81A\94ÂURL\95Ï\8dX\83`\83F\83b\83N\82ª\8a®\97¹\82µ\82Ü\82µ\82½');
+                       MessageMemo.Lines.Add('\81u\95Â\82\82é\81v\83{\83^\83\93\82ð\89\9f\82µ\82Ä\82­\82¾\82³\82¢');
+               end else
+                       MessageMemo.Lines.Add('\90V\94Â\81A\94ÂURL\95Ï\8dX\82Í \82 \82è\82Ü\82¹\82ñ\82Å\82µ\82½');
+    finally
+       oldURLs.Free;
+       newURLs.Free;
+    end;
 end;
 
 procedure TNewBoardDialog.FormCreate(Sender: TObject);