OSDN Git Service

This commit was manufactured by cvs2svn to create branch 'Bb62'.
[gikonavigoeson/gikonavi.git] / GikoSystem.pas
index c9bc046..2c1e4d7 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
@@ -165,6 +166,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,7 +183,7 @@ 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;
@@ -255,6 +257,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 +276,7 @@ const
        ZERO_DATE: Integer      = 25569;
        BETA_VERSION_NAME_E = 'beta';
        BETA_VERSION_NAME_J = 'ÊÞÀ';
-       BETA_VERSION                            = 59;
+       BETA_VERSION                            = 62;
        BETA_VERSION_BUILD      = '';                           //!< debug\94Å\82È\82Ç
        APP_NAME                                                = 'gikoNavi';
        BE_PHP_URL = 'http://be.2ch.net/test/p.php?i=';
@@ -309,6 +321,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 +375,7 @@ begin
        FreeAndNil(FSelectResFilter);
        FreeAndNil(FAbon);
        FreeAndNil(FAWKStr);
+    FreeAndNil(FBelib);
        FreeAndNil(FDolib);
        FreeAndNil(FSetting);
        inherited;
@@ -645,7 +659,7 @@ begin
                                        end;
                                end;
 
-                               ThreadItem.BeginUpdate;
+                               //ThreadItem.BeginUpdate;
                                if (datFileCheck) and (islog) then
                                        FileList.Delete( Index );
 
@@ -670,7 +684,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 +713,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 +957,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 +1112,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 +1377,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 +1388,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 +1404,7 @@ var
 begin
        Result := '';
        for i := 0 to index do
-               Result := RemoveToken(s, delimiter);
+               Result := MojuUtils.RemoveToken(s, delimiter);
 end;
 
 
@@ -1632,7 +1646,7 @@ begin
        SI.cbReserved2 := 0;
        SI.lpReserved2 := nil;
        SI.dwysize               := 0;
-       Windows.CreateProcess(nil,
+    if Windows.CreateProcess(nil,
                                                                PChar(Path),
                                                                nil,
                                                                nil,
@@ -1641,7 +1655,11 @@ begin
                                                                nil,
                                                                nil,
                                                                SI,
-                                                               PI);
+                                                               PI) then
+    begin
+        CloseHandle(PI.hProcess);
+    end;
+
 end;
 
 {!
@@ -1650,14 +1668,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;
@@ -1904,8 +1953,23 @@ var
     i, j, idx : Integer;
 begin
        URL := Trim(LowerCase(URL));
-    idx := AnsiPos('?', URL);
+    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();
@@ -1915,19 +1979,21 @@ begin
             for  i := 0 to bufList.Count - 1 do begin
                 convBuf := '';
                 // \8aJ\8en\83\8c\83X\94Ô\82Ì\8c\9f\8dõ
-                for j := 0 to Length(START_NAME) - 1 do begin
-                    idx := AnsiPos(START_NAME[j], bufList[i]);
-                    if (idx <> 0) then begin
-                        convBuf := Copy(bufList[i], idx + Length(START_NAME[j]), Length(bufList[i]));
-                        stRes := StrToInt64Def( convBuf, 0 );
-                        break;
+                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 = '') then begin
+                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 <> 0) then begin
+                        if (idx = 1) then begin
                             convBuf := Copy(bufList[i], idx + Length(END_NAME[j]), Length(bufList[i]));
                             endRes := StrToInt64Def( convBuf, 0 );
                             break;
@@ -1938,7 +2004,7 @@ begin
                 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 <> 0) then begin
+                      if (idx = 1) then begin
                           convBuf := Copy(bufList[i], idx + Length(RES_NAME[j]), Length(bufList[i]));
                           stRes := StrToInt64Def( convBuf, 0 );
                           endRes := stRes;
@@ -3395,6 +3461,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;