X-Git-Url: http://git.osdn.net/view?a=blobdiff_plain;f=NewBoard.pas;h=a242402bc23a4090216c23230272090ae7bcb636;hb=refs%2Fheads%2FBb55;hp=212f2618e955324584b80acae57f8ab5b0d76f98;hpb=d840f0f349151c002fc7ef696a314177119d2d42;p=gikonavigoeson%2Fgikonavi.git diff --git a/NewBoard.pas b/NewBoard.pas index 212f261..a242402 100644 --- a/NewBoard.pas +++ b/NewBoard.pas @@ -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, MojuUtils; + GikoSystem, BoardGroup; type TNewBoardItem = record @@ -22,27 +22,29 @@ type Indy: TIdHTTP; IdAntiFreeze: TIdAntiFreeze; StopButton: TButton; - Label2: TLabel; BoardURLComboBox: TComboBox; Label13: TLabel; EditIgnoreListsButton: TButton; + Label2: TLabel; procedure UpdateButtonClick(Sender: TObject); procedure StopButtonClick(Sender: TObject); procedure CloseButtonClick(Sender: TObject); procedure FormCreate(Sender: TObject); procedure EditIgnoreListsButtonClick(Sender: TObject); - procedure FormClose(Sender: TObject; var Action: TCloseAction); + procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private éŒ¾ } IgnoreLists : TStringList; FAbort: Boolean; - function BoardDownload: TNewBoardItem; - procedure UpdateURL(s: string); + function BoardDownload(const URL: String): TNewBoardItem; + function BoardLoardFromFile(const FilePath: String): String; + function UpdateURL(s: string): boolean; procedure SetIgnoreCategory(b: boolean); procedure EditIgnoreList(Sender: TObject); procedure UpdateIgnoreList(Sender: TObject); public { Public éŒ¾ } + class procedure InitHTTPClient(client : TIdHTTP); end; var @@ -51,34 +53,53 @@ var implementation -uses Giko, IdHeaderList; +uses Giko, IdHeaderList, MojuUtils, GikoDataModule; {$R *.dfm} procedure TNewBoardDialog.UpdateButtonClick(Sender: TObject); var Item: TNewBoardItem; + URL : String; + protocol, host, path, document, port, bookmark: String; + TabURLs: TStringList; begin try - GikoSys.Setting.BoardURLSelected := BoardURLComboBox.ItemIndex + 1; + MessageMemo.Clear; + GikoSys.Setting.BoardURLSelected := BoardURLComboBox.ItemIndex + 1; FAbort := False; UpdateButton.Enabled := False; StopButton.Enabled := True; CloseButton.Enabled := False; - Item := BoardDownload; + EditIgnoreListsButton.Enabled := False; + URL := BoardURLComboBox.Text; + GikoSys.ParseURI(URL, protocol, host, path, document, port, bookmark); + if (protocol = '') then begin + Item.FContent := BoardLoardFromFile(URL); + end else if (AnsiPos('http', protocol) > 0) then begin + Item := BoardDownload(URL); + end; StopButton.Enabled := False; if FAbort then Exit; if Item.FContent <> '' then begin - GikoForm.TabsSaveAction.Execute; - UpdateURL(Item.FContent); - GikoForm.ReloadBBS; + TabURLs := TStringList.Create; + try + GikoDM.GetTabURLs(TabURLs); + if (UpdateURL(Item.FContent)) then begin + GikoForm.ReloadBBS; + end; + GikoDM.OpenURLs(TabURLs); + finally + TabURLs.Free; + end; end else MessageMemo.Lines.Add('ƒ_ƒEƒ“ƒ[ƒh‚ªŽ¸”s‚µ‚Ü‚µ‚½[' + IntToStr(Item.FResponseCode) + ']'); finally UpdateButton.Enabled := True; StopButton.Enabled := False; CloseButton.Enabled := True; + EditIgnoreListsButton.Enabled := True; end; end; @@ -93,40 +114,14 @@ begin Close; end; -function TNewBoardDialog.BoardDownload: TNewBoardItem; +function TNewBoardDialog.BoardDownload(const URL: String): TNewBoardItem; var - URL: string; Stream: TMemoryStream; s: string; i: Integer; begin - MessageMemo.Clear; - Indy.Request.Clear; - Indy.RecvBufferSize := Gikosys.Setting.RecvBufferSize; - Indy.ProxyParams.BasicAuthentication := False; - if GikoSys.Setting.ReadProxy then begin - if GikoSys.Setting.ProxyProtocol then - Indy.ProtocolVersion := pv1_1 - else - Indy.ProtocolVersion := pv1_0; - Indy.ProxyParams.ProxyServer := GikoSys.Setting.ReadProxyAddress; - Indy.ProxyParams.ProxyPort := GikoSys.Setting.ReadProxyPort; - Indy.ProxyParams.ProxyUsername := GikoSys.Setting.ReadProxyUserID; - Indy.ProxyParams.ProxyPassword := GikoSys.Setting.ReadProxyPassword; - if GikoSys.Setting.ReadProxyUserID <> '' then - Indy.ProxyParams.BasicAuthentication := True; - end else begin - if GikoSys.Setting.Protocol then - Indy.ProtocolVersion := pv1_1 - else - Indy.ProtocolVersion := pv1_0; - Indy.ProxyParams.ProxyServer := ''; - Indy.ProxyParams.ProxyPort := 80; - Indy.ProxyParams.ProxyUsername := ''; - Indy.ProxyParams.ProxyPassword := ''; - end; - //URL := GikoSys.Setting.BoardURL2ch; - URL := BoardURLComboBox.Text; + InitHTTPClient( Indy ); + Indy.Request.UserAgent := GikoSys.GetUserAgent; Indy.Request.Referer := ''; Indy.Request.AcceptEncoding := 'gzip'; @@ -140,9 +135,14 @@ begin try MessageMemo.Lines.Add('ˆÈ‰º‚̏ꏊ‚©‚çŽæ“¾‚µ‚Ü‚·'); //MessageMemo.Lines.Add(GikoSys.Setting.BoardURL2ch); - MessageMemo.Lines.Add(URL); + MessageMemo.Lines.Add(URL); MessageMemo.Lines.Add('ƒ_ƒEƒ“ƒ[ƒh‚ðŠJŽn‚µ‚Ü‚·'); - Indy.Get(URL, Stream); + IdAntiFreeze.Active := True; + try + Indy.Get(URL, Stream); + finally + IdAntiFreeze.Active := False; + end; Result.FContent := GikoSys.GzipDecompress(Stream, Indy.Response.ContentEncoding); MessageMemo.Lines.Add('ƒ_ƒEƒ“ƒ[ƒh‚ªŠ®—¹‚µ‚Ü‚µ‚½'); except @@ -176,10 +176,9 @@ begin end; end; -procedure TNewBoardDialog.UpdateURL(s: string); +function TNewBoardDialog.UpdateURL(s: string): boolean; var i: Integer; -// j: Integer; idx: Integer; idx1: Integer; idx2: Integer; @@ -315,6 +314,7 @@ begin oldURLs.Free; newURLs.Free; end; + Result := Change; end; procedure TNewBoardDialog.FormCreate(Sender: TObject); @@ -374,7 +374,7 @@ procedure TNewBoardDialog.UpdateIgnoreList(Sender: TObject); var i: Integer; begin - Label2.Caption := '¦Œ»ÝAŠJ‚¢‚Ä‚¢‚éƒ^ƒu‚âƒqƒXƒgƒŠ‚Ȃǂ͔XVŽž‚ɃNƒŠƒA‚³‚ê‚Ü‚·'; + Label2.Caption := ''; UpdateButton.Enabled := true; EditIgnoreListsButton.Caption := 'œŠOƒJƒeƒSƒŠ[•ÒW'; IgnoreLists.Clear; @@ -393,5 +393,50 @@ procedure TNewBoardDialog.FormClose(Sender: TObject; begin IgnoreLists.Free; end; +//! ƒ[ƒJƒ‹ƒtƒ@ƒCƒ‹‚ðƒ[ƒh‚·‚é +function TNewBoardDialog.BoardLoardFromFile(const FilePath: String): String; +var + html : TStringList; +begin + Result := ''; + // ƒtƒ@ƒCƒ‹‚ª‘¶Ý‚µ‚Ä‚¢‚é‚©ƒ`ƒFƒbƒN + if (FileExists(FilePath)) then begin + html := TStringList.Create(); + try + html.LoadFromFile(FilePath); + Result := html.Text; + finally + html.Free; + end; + end; +end; +class procedure TNewBoardDialog.InitHTTPClient(client : TIdHTTP); +begin + client.Request.Clear; + client.Request.CustomHeaders.Clear; + client.RecvBufferSize := Gikosys.Setting.RecvBufferSize; + client.ProxyParams.BasicAuthentication := False; + if GikoSys.Setting.ReadProxy then begin + if GikoSys.Setting.ProxyProtocol then + client.ProtocolVersion := pv1_1 + else + client.ProtocolVersion := pv1_0; + client.ProxyParams.ProxyServer := GikoSys.Setting.ReadProxyAddress; + client.ProxyParams.ProxyPort := GikoSys.Setting.ReadProxyPort; + client.ProxyParams.ProxyUsername := GikoSys.Setting.ReadProxyUserID; + client.ProxyParams.ProxyPassword := GikoSys.Setting.ReadProxyPassword; + if GikoSys.Setting.ReadProxyUserID <> '' then + client.ProxyParams.BasicAuthentication := True; + end else begin + if GikoSys.Setting.Protocol then + client.ProtocolVersion := pv1_1 + else + client.ProtocolVersion := pv1_0; + client.ProxyParams.ProxyServer := ''; + client.ProxyParams.ProxyPort := 80; + client.ProxyParams.ProxyUsername := ''; + client.ProxyParams.ProxyPassword := ''; + end; +end; end.