OSDN Git Service

・スレタイの特定ワードを非表示にする機能に「©bbspink.com」も追加
[gikonavigoeson/gikonavi.git] / GikoSystem.pas
index 3b04cc1..827e109 100644 (file)
@@ -15,7 +15,7 @@ uses
        {HttpApp,} URLMon, IdGlobal, IdURI, {Masks,}
        Setting, BoardGroup, gzip, Dolib, bmRegExp, AbonUnit,
        ExternalBoardManager, ExternalBoardPlugInMain,
-       GikoBayesian, GikoMessage;
+       GikoBayesian, GikoMessage, Belib;
 
 type
        TVerResourceKey = (
@@ -112,6 +112,7 @@ type
                FBayesian       : TGikoBayesian;        //!< \83x\83C\83W\83A\83\93\83t\83B\83\8b\83^
                FVersion : String;                    //!< \83t\83@\83C\83\8b\83o\81[\83W\83\87\83\93
                FGikoMessage: TGikoMessage;
+        FBelib: TBelib;
                //! \82 \82é\83Z\83p\83\8c\81[\83^\82Å\8bæ\90Ø\82ç\82ê\82½\95\8e\9a\97ñ\82©\82ç\82\8e\94Ô\96Ú\82Ì\95\8e\9a\97ñ\82ð\8eæ\82è\8fo\82·
                function ChooseString(const Text, Separator: string; Index: integer): string;
         //! \88ê\8e\9e\83t\83@\83C\83\8b\82©\82ç\82Ì\95\9c\8b\8c
@@ -139,6 +140,7 @@ type
                function GetTempFolder: string;
                function GetSentFileName: string;
                function GetConfigDir: string;
+        function GetNGWordsDir: string;
                function GetSkinDir: string;
                function GetSkinHeaderFileName: string;
                function GetSkinFooterFileName: string;
@@ -165,6 +167,7 @@ type
                function DivideSubject(Line: string): TSubjectRec;
                property Setting: TSetting read FSetting write FSetting;
                property Dolib: TDolib read FDolib write FDolib;
+               property Belib: TBelib read FBelib write FBelib;
 
                function UrlToID(url: string): string;
                function UrlToServer(url: string): string;
@@ -181,10 +184,11 @@ type
 
                procedure MenuFont(Font: TFont);
 
-               function RemoveToken(var s:string; const delimiter:string):string;
+//             function RemoveToken(var s:string; const delimiter:string):string;
                function GetTokenIndex(s: string; delimiter: string; index: Integer): string;
 
                function GetShortName(const LongName: string; ALength: integer): string;
+               function TrimThreadTitle(const SrcTitle: string): string;
                function BoolToInt(b: Boolean): Integer;
                function IntToBool(i: Integer): Boolean;
                function GzipDecompress(ResStream: TStream; ContentEncoding: string): string;
@@ -255,6 +259,16 @@ type
         function GetExtpreviewFileName: String;
 
         procedure ShowRefCount(msg: String; unk: IUnknown);
+        //! \96`\8c¯\82Ì\8f\91Cookie\8eæ\93¾
+        function GetBoukenCookie(AURL: String): String;
+        //! \96`\8c¯\82Ì\8f\91Cookie\90Ý\92è
+        procedure SetBoukenCookie(ACookieValue, ADomain: String);
+        //! \96`\8c¯\82Ì\8f\91Cookie\8dí\8f\9c
+        procedure DelBoukenCookie(ADomain: String);
+        //! \96`\8c¯\82Ì\8f\91Domain\88ê\97\97\8eæ\93¾
+        procedure GetBoukenDomain(var ADomain: TStringList);
+        //! \96`\8c¯\82Ì\8f\91\83h\83\81\83C\83\93\96¼Cookie\8eæ\93¾
+        function GetBouken(AURL: String; var Domain: String): String;
        end;
 
 var
@@ -264,7 +278,7 @@ const
        ZERO_DATE: Integer      = 25569;
        BETA_VERSION_NAME_E = 'beta';
        BETA_VERSION_NAME_J = 'ÊÞÀ';
-       BETA_VERSION                            = 58;
+       BETA_VERSION                            = 68;
        BETA_VERSION_BUILD      = '';                           //!< debug\94Å\82È\82Ç
        APP_NAME                                                = 'gikoNavi';
        BE_PHP_URL = 'http://be.2ch.net/test/p.php?i=';
@@ -309,6 +323,7 @@ begin
     Inherited;
        FSetting := TSetting.Create;
        FDolib := TDolib.Create;
+    FBelib := TBelib.Create;
        FAWKStr := TAWKStr.Create(nil);
        if DirectoryExists(GetConfigDir) = false then begin
                CreateDir(GetConfigDir);
@@ -362,6 +377,7 @@ begin
        FreeAndNil(FSelectResFilter);
        FreeAndNil(FAbon);
        FreeAndNil(FAWKStr);
+    FreeAndNil(FBelib);
        FreeAndNil(FDolib);
        FreeAndNil(FSetting);
        inherited;
@@ -460,6 +476,12 @@ begin
        Result := Setting.GetConfigDir;
 end;
 
+function TGikoSys.GetNGWordsDir: string;
+begin
+       Result := Setting.GetConfigDir + NGWORDs_DIR_NAME;
+end;
+
+
 //! \83X\83^\83C\83\8b\83V\81[\83g\83t\83H\83\8b\83_
 function TGikoSys.GetStyleSheetDir: string;
 begin
@@ -645,7 +667,7 @@ begin
                                        end;
                                end;
 
-                               ThreadItem.BeginUpdate;
+                               //ThreadItem.BeginUpdate;
                                if (datFileCheck) and (islog) then
                                        FileList.Delete( Index );
 
@@ -670,7 +692,7 @@ begin
                                Node := FavoriteDM.TreeView.Items.AddChildObject( FavoriteDM.TreeView.Items.Item[0], ThreadItem.Title, FavoThreadItem);
                                *}
 
-                               ThreadItem.EndUpdate;
+                               //ThreadItem.EndUpdate;
                                Board.Add(ThreadItem);
 
                                if (ThreadItem.UnRead) and (ThreadItem.IsLogFile) then
@@ -699,7 +721,7 @@ begin
        Board.IsThreadDatRead := True;
 {$IFDEF DEBUG}
        rt := GetTickCount - st;
-       Writeln('Read Done.' + IntToStr(rt) + ' ms');
+       Writeln('Read Done.' + Board.Title + ':' + IntToStr(rt) + ' ms');
 {$ENDIF}
 end;
 {!
@@ -943,7 +965,7 @@ begin
        Result.FLastModified := IntToDateTime(StrToIntDef('$' + MojuUtils.RemoveToken(Line, #1), ZERO_DATE));
        Result.FKokomade := StrToIntDef('$' + MojuUtils.RemoveToken(Line, #1), -1);
        Result.FNewReceive := StrToIntDef('$' + MojuUtils.RemoveToken(Line, #1), 0);
-       RemoveToken(Line, #1);//9: ;    //\96¢\8eg\97p
+       MojuUtils.RemoveToken(Line, #1);//9: ;  //\96¢\8eg\97p
        Result.FUnRead := IntToBool(StrToIntDef('$' + MojuUtils.RemoveToken(Line, #1), 0));
        Result.FScrollTop := StrToIntDef('$' + MojuUtils.RemoveToken(Line, #1), 0);
        Result.FAllResCount := StrToIntDef('$' + MojuUtils.RemoveToken(Line, #1), 0);
@@ -1098,8 +1120,8 @@ begin
                Delim := ','
        else
                Delim := '<>';
-       Result.FFileName := RemoveToken(Line, Delim);
-       Result.FTitle := Trim(RemoveToken(Line, Delim));
+       Result.FFileName := MojuUtils.RemoveToken(Line, Delim);
+       Result.FTitle := Trim(MojuUtils.RemoveToken(Line, Delim));
 
        ws := Result.FTitle;
        if Copy(ws, Length(ws), 1) = ')' then begin
@@ -1363,7 +1385,7 @@ end;
 
 \82Ç\82±\82©\82Ì\83T\83C\83g\82©\82ç\82Ì\83p\83N\83\8a
 }
-function TGikoSys.RemoveToken(var s: string;const delimiter: string): string;
+{function TGikoSys.RemoveToken(var s: string;const delimiter: string): string;
 var
        p: Integer;
 begin
@@ -1374,7 +1396,7 @@ begin
                Result := Copy(s, 1, p - 1);
        Delete(s, 1, Length(Result) + Length(delimiter));
 end;
-
+}
 
 {!
 \brief n \8cÂ\96Ú\82Ì\83g\81[\83N\83\93\82ð\90Ø\82è\8fo\82µ
@@ -1390,7 +1412,7 @@ var
 begin
        Result := '';
        for i := 0 to index do
-               Result := RemoveToken(s, delimiter);
+               Result := MojuUtils.RemoveToken(s, delimiter);
 end;
 
 
@@ -1425,7 +1447,7 @@ var
        S : string;
        i : integer;
 begin
-       s := Trim(LongName);
+    s := TrimThreadTitle(Trim(LongName));
        if (Length(s) <= ALength) then begin
                Result := s;
        end else begin
@@ -1458,6 +1480,33 @@ begin
        end;
 end;
 
+function TGikoSys.TrimThreadTitle(const SrcTitle: string): string;
+const
+    TRIM_STRING: array [1..4] of String =
+        ('[\93]\8dÚ\8bÖ\8e~]', '&copy;2ch.net', '&copy;bbspink.com', #9);
+var
+    i: Integer;
+    Idx: Integer;
+    Len: Integer;
+    DstTitle: String;
+begin
+    if (Setting.ThreadTitleTrim = True) then begin
+        DstTitle := SrcTitle;
+               for i := Low(TRIM_STRING) to High(TRIM_STRING) do begin
+            Len := Length(TRIM_STRING[i]);
+            while (True) do begin
+                Idx := Pos(TRIM_STRING[i], DstTitle);
+                if (Idx < 1) then
+                    Break;
+                Delete(DstTitle, Idx, Len);
+            end;
+        end;
+        Result := Trim(DstTitle);
+    end else begin
+        Result := SrcTitle;
+    end;
+end;
+
 {!
 \brief Boolean \82ð Integer \82É\95Ï\8a·
 \return False..0, True..1
@@ -1632,7 +1681,7 @@ begin
        SI.cbReserved2 := 0;
        SI.lpReserved2 := nil;
        SI.dwysize               := 0;
-       Windows.CreateProcess(nil,
+    if Windows.CreateProcess(nil,
                                                                PChar(Path),
                                                                nil,
                                                                nil,
@@ -1641,7 +1690,11 @@ begin
                                                                nil,
                                                                nil,
                                                                SI,
-                                                               PI);
+                                                               PI) then
+    begin
+        CloseHandle(PI.hProcess);
+    end;
+
 end;
 
 {!
@@ -1650,14 +1703,45 @@ end;
 \param BrowserType \83u\83\89\83E\83U\82Ì\83^\83C\83v(IE \82©\82Ç\82¤\82©)
 }
 procedure TGikoSys.OpenBrowser(URL: string; BrowserType: TGikoBrowserType);
+var
+    i, j : Integer;
+    path, arg : String;
+    params : TStringList;
 begin
        case BrowserType of
                gbtIE:
                        HlinkNavigateString(nil, PWideChar(WideString(URL)));
                gbtUserApp, gbtAuto:
-                       if (Setting.URLApp) and (FileExists(Setting.URLAppFile)) then
-                               GikoSys.CreateProcess(Setting.URLAppFile, URL)
-                       else
+                       if (Setting.URLApp) then begin
+                if (FileExists(Setting.URLAppFile)) then begin
+                               GikoSys.CreateProcess(Setting.URLAppFile, URL)
+                end else begin
+                    // \8bN\93®\83p\83\89\83\81\81[\83^\95t\82«\91Î\8dô
+                    path := '';
+                    params := TStringList.Create;
+                    try
+                        params.Delimiter := ' ';
+                        params.DelimitedText := Setting.URLAppFile;
+                        for i := 0 to params.Count - 1 do begin
+                            path := TrimLeft(path + ' ' + params[i]);
+                            if (FileExists(path)) then begin
+                                arg := '';
+                                for j := i + 1 to params.Count - 1 do begin
+                                    arg := arg + ' ' + params[j];
+                                end;
+                                break;
+                            end;
+                        end;
+                        if i < params.Count then begin
+                            GikoSys.CreateProcess(path, arg + ' ' + URL);
+                        end else begin
+                            HlinkNavigateString(nil, PWideChar(WideString(URL)));
+                        end;
+                    finally
+                        params.Free;
+                    end;
+                end;
+                       end else
                                HlinkNavigateString(nil, PWideChar(WideString(URL)));
        end;
 end;
@@ -1794,7 +1878,7 @@ end;
 }
 function TGikoSys.Is2chHost(Host: string): Boolean;
 const
-       HOST_NAME: array[0..1] of string = ('2ch.net', 'bbspink.com');
+       HOST_NAME: array[0..1] of string = ('.2ch.net', '.bbspink.com');
 var
        i: Integer;
 //     Len: Integer;
@@ -1891,84 +1975,93 @@ http://2ch.net/
 \82Ì\8fê\8d\87 stRef = 32, endRes = 50 \82É\82È\82é
 }
 procedure TGikoSys.GetPopupResNumber(URL : string; var stRes, endRes : Int64);
+const
+    START_NAME : array[0..1] of String = ('st=', 'start=');
+    END_NAME : array[0..1] of String = ('to=', 'end=');
+    RES_NAME : array[0..0] of String = ('res=');
 var
        buf : String;
        convBuf : String;
        ps : Int64;
        pch : PChar;
+    bufList : TStringList;
+    i, j, idx : Integer;
 begin
        URL := Trim(LowerCase(URL));
-       if (AnsiPos('&st=', URL ) <> 0) and ( AnsiPos( '&to=',URL) <> 0 ) then begin
-               stRes := 0;
-               endRes := 0;
-               try
-                       buf := Copy( URL, AnsiPos('&st=', URL ) + 4, AnsiPos( '&to=',URL) - AnsiPos('&st=', URL ) - 4 );
-                       if buf <> '' then
-                               stRes := StrToInt64( buf );
-                       if AnsiPos( '&nofirst=',URL) <> 0 then begin
-                               buf := Copy( URL, AnsiPos('&to=', URL ) + 4, AnsiPos( '&nofirst=',URL) - AnsiPos('&to=', URL ) - 4);
-                       end else begin
-                               buf := Copy( URL, AnsiPos('&to=', URL ) + 4, Length( URL ) - AnsiPos('&to=', URL ) - 4 + 1 );
-                               ps := 0;
-                               pch := PChar(buf);
-                               while  ( ps < Length(buf) )and ( pch[ps] >= '0' ) and ( pch[ps] <= '9' ) do Inc(ps);
-                               buf := Copy( buf, 1, ps );
-                       end;
-                       try
-                               if buf <> '' then
-                                       endRes := StrToInt64(buf)
-                       except
-                               endRes := 0;
-                       end;
-               except
-                       stRes := 0;
-               end;
-               if (stRes <> 0) and (endRes = 0) then
-                       endRes := stRes + MAX_POPUP_RES
-               else if (stRes = 0) and (endRes <> 0) then begin
-                       stRes := endRes - MAX_POPUP_RES;
-                       if stRes < 1 then
-                               stRes := 1;
-               end;
-               GikoSys.GetBrowsableThreadURL( URL );
-       end else if( AnsiPos('&res=', URL ) <> 0 ) then begin
-               endRes := 0;
-               buf := Copy( URL, AnsiPos('&res=', URL ) + 5, Length( URL ) - AnsiPos('&res=', URL ) - 5 + 1 );
-               ps := 0;
-               pch := PChar(buf);
-               while  ( ps < Length(buf) )and ( pch[ps] >= '0' ) and ( pch[ps] <= '9' ) do Inc(ps);
-               buf := Copy( buf, 1, ps );
-               try
-                       if buf <> '' then
-                               stRes := StrToInt(buf)
-                       else begin
-                               stRes := 0;
-                       end;
-               except
-                       stRes := 0;
-               end;
-       end else if (AnsiPos('&start=', URL ) <> 0) and ( AnsiPos( '&end=',URL) <> 0 ) then begin
-               try
-                       stRes := StrToInt64( Copy( URL, AnsiPos('&start=', URL ) + 7, AnsiPos( '&end=',URL) - AnsiPos('&start=', URL ) - 7 ) );
-                       if AnsiPos( '&nofirst=',URL) <> 0 then begin
-                               buf := Copy( URL, AnsiPos('&end=', URL ) + 5, AnsiPos( '&nofirst=',URL) - AnsiPos('&end=', URL ) - 5);
-                       end else begin
-                               buf := Copy( URL, AnsiPos('&end=', URL ) + 5, Length( URL ) - AnsiPos('&to=', URL ) - 5 + 1 );
-                               ps := 0;
-                               pch := PChar(buf);
-                               while  ( ps < Length(buf) )and ( pch[ps] >= '0' ) and ( pch[ps] <= '9' ) do Inc(ps);
-                               buf := Copy( buf, 1, ps );
-                       end;
-                       try
-                               if buf <> '' then
-                                       endRes := StrToInt64(buf);
-                       except
-                               endRes := 0;
-                       end;
-               except
-                       stRes := 0;
-               end;
-       end else if ( AnsiPos('.html',URL) <> Length(URL) -4 ) and ( AnsiPos('.htm',URL) <> Length(URL) -3 ) then begin
+    for i := 0 to Length(START_NAME) -1 do begin
+        idx := AnsiPos(START_NAME[i], URL);
+        if (idx <> 0) then begin
+            break;
+        end;
+        idx := AnsiPos(END_NAME[i], URL);
+        if (idx <> 0) then begin
+            break;
+        end;
+
+    end;
+
+    if (idx <> 0) then begin
+        idx := AnsiPos('?', URL);
+        if (idx = 0) then begin
+            idx := LastDelimiter('/', URL);
+        end;
+        stRes := 0;
+        endRes := 0;
+        bufList := TStringList.Create();
+        try
+            bufList.Delimiter := '&';
+            bufList.DelimitedText := Copy(URL, idx + 1, Length(URL));
+            for  i := 0 to bufList.Count - 1 do begin
+                convBuf := '';
+                // \8aJ\8en\83\8c\83X\94Ô\82Ì\8c\9f\8dõ
+                if (stRes = 0) then begin
+                    for j := 0 to Length(START_NAME) - 1 do begin
+                        idx := AnsiPos(START_NAME[j], bufList[i]);
+                        if (idx = 1) then begin
+                            convBuf := Copy(bufList[i], idx + Length(START_NAME[j]), Length(bufList[i]));
+                            stRes := StrToInt64Def( convBuf, 0 );
+                            break;
+                        end;
+                    end;
+                end;
+                // \8fI\97¹\83\8c\83X\94Ô\82Ì\8c\9f\8dõ
+                if (convBuf = '') and (endRes = 0) then begin
+                    for j := 0 to Length(END_NAME) - 1 do begin
+                        idx := AnsiPos(END_NAME[j], bufList[i]);
+                        if (idx = 1) then begin
+                            convBuf := Copy(bufList[i], idx + Length(END_NAME[j]), Length(bufList[i]));
+                            endRes := StrToInt64Def( convBuf, 0 );
+                            break;
+                        end;
+                    end;
+                end;
+                // \83\8c\83X\94Ô\82Ì\8c\9f\8dõ
+                if ((stRes = 0) and (endRes = 0) and (convBuf = '')) then begin
+                  for j := 0 to Length(RES_NAME) - 1 do begin
+                      idx := AnsiPos(RES_NAME[j], bufList[i]);
+                      if (idx = 1) then begin
+                          convBuf := Copy(bufList[i], idx + Length(RES_NAME[j]), Length(bufList[i]));
+                          stRes := StrToInt64Def( convBuf, 0 );
+                          endRes := stRes;
+                          break;
+                      end;
+                  end;
+                end;
+            end;
+
+            if (stRes <> 0) and (endRes = 0) then begin
+                       endRes := stRes + MAX_POPUP_RES;
+               end else if (stRes = 0) and (endRes <> 0) then begin
+                stRes := endRes - MAX_POPUP_RES;
+                       if stRes < 1 then begin
+                               stRes := 1;
+                end;
+            end;
+        finally
+            bufList.clear;
+            bufList.free;
+        end;
+    end else if ( AnsiPos('.html',URL) <> Length(URL) -4 ) and ( AnsiPos('.htm',URL) <> Length(URL) -3 ) then begin
                buf := Copy(URL, LastDelimiter('/',URL)+1,Length(URL)-LastDelimiter('/',URL)+1);
                if  Length(buf) > 0 then begin
                        if AnsiPos('-', buf) = 1 then begin
@@ -1977,15 +2070,10 @@ begin
                                ps := 0;
                                pch := PChar(buf);
                                while  ( ps < Length(buf) )and ( pch[ps] >= '0' ) and ( pch[ps] <= '9' ) do Inc(ps);
-                               try
-                                       convBuf := Copy( buf, 1, ps );
-                                       if convBuf <> '' then
-                                               endRes := StrToInt64(convBuf)
-                                       else
-                                               endRes := 0;
-                               except
-                                       endRes := 0;
-                               end;
+                convBuf := Copy( buf, 1, ps );
+                if convBuf <> '' then begin
+                    endRes := StrToInt64Def(convBuf, 0);
+                end;
                                if endRes <> 0 then begin
                                        stRes := endRes - MAX_POPUP_RES;
                                        if stRes < 1 then
@@ -2003,15 +2091,10 @@ begin
                                                ps := 0;
                                                pch := PChar(buf);
                                                while  ( ps < Length(buf) )and ( pch[ps] >= '0' ) and ( pch[ps] <= '9' ) do Inc(ps);
-                                               try
-                                                       convBuf := Copy( buf, 1, ps );
-                                                       if convBuf <> '' then
-                                                               endRes := StrToInt64(convBuf)
-                                                       else
-                                                               endRes := 0;
-                                               except
-                                                       endRes := 0;
-                                               end;
+                        convBuf := Copy( buf, 1, ps );
+                        if convBuf <> '' then begin
+                            endRes := StrToInt64Def(convBuf, 0);
+                        end;
                                        end else begin
                                                stRes := 0;
                                        end;
@@ -2021,9 +2104,6 @@ begin
                                end;
                        end;
                end;
-       end else begin
-               //stRes := 0;
-               //endRes := 0;
        end;
 end;
 
@@ -3416,6 +3496,57 @@ begin
        end;
 {$ENDIF}
 end;
+function TGikoSys.GetBoukenCookie(AURL: String): String;
+var
+       Protocol, Host, Path, Document, Port,Bookmark : String;
+begin
+    Result := '';
+    GikoSys.ParseURI(AURL, Protocol, Host, Path, Document, Port,Bookmark);
+    if ( Length(Host) > 0 ) then begin
+        Result := Setting.GetBoukenCookie(Host);
+    end;
+end;
+procedure TGikoSys.SetBoukenCookie(ACookieValue, ADomain: String);
+begin
+    if ( Length(ADomain) > 0 ) then begin
+        Setting.SetBoukenCookie(ACookieValue, ADomain);
+    end;
+end;
+//! \96`\8c¯\82Ì\8f\91Domain\88ê\97\97\8eæ\93¾
+procedure TGikoSys.GetBoukenDomain(var ADomain: TStringList);
+var
+    i : Integer;
+begin
+    ADomain.Clear;
+    for i := 0 to Setting.BoukenCookieList.Count - 1 do begin
+        ADomain.Add( Setting.BoukenCookieList.Names[i] );
+    end;
+end;
+//! \96`\8c¯\82Ì\8f\91Cookie\8dí\8f\9c
+procedure TGikoSys.DelBoukenCookie(ADomain: String);
+var
+    i : Integer;
+begin
+    for i := 0 to Setting.BoukenCookieList.Count - 1 do begin
+        if ( Setting.BoukenCookieList.Names[i] = ADomain ) then begin
+            Setting.BoukenCookieList.Delete(i);
+            Break;
+        end;
+    end;
+end;
+function TGikoSys.GetBouken(AURL: String; var Domain: String): String;
+var
+       Protocol, Host, Path, Document, Port,Bookmark : String;
+    Cookie : String;
+begin
+    Domain := '';
+    Cookie := '';
+    GikoSys.ParseURI(AURL, Protocol, Host, Path, Document, Port,Bookmark);
+    if ( Length(Host) > 0 ) then begin
+        Setting.GetBouken(Host, Domain, Cookie);
+        Result := Cookie;
+    end;
+end;
 
 initialization
        GikoSys := TGikoSys.Create;