| 6 |
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, |
| 7 |
Dialogs, IdAntiFreezeBase, IdAntiFreeze, IdBaseComponent, IdComponent, |
Dialogs, IdAntiFreezeBase, IdAntiFreeze, IdBaseComponent, IdComponent, |
| 8 |
IdTCPConnection, IdTCPClient, IdHTTP, IDException, StdCtrls, IniFiles, |
IdTCPConnection, IdTCPClient, IdHTTP, IDException, StdCtrls, IniFiles, |
| 9 |
GikoSystem, BoardGroup, MojuUtils; |
GikoSystem, BoardGroup; |
| 10 |
|
|
| 11 |
type |
type |
| 12 |
TNewBoardItem = record |
TNewBoardItem = record |
| 22 |
Indy: TIdHTTP; |
Indy: TIdHTTP; |
| 23 |
IdAntiFreeze: TIdAntiFreeze; |
IdAntiFreeze: TIdAntiFreeze; |
| 24 |
StopButton: TButton; |
StopButton: TButton; |
|
Label2: TLabel; |
|
| 25 |
BoardURLComboBox: TComboBox; |
BoardURLComboBox: TComboBox; |
| 26 |
Label13: TLabel; |
Label13: TLabel; |
| 27 |
EditIgnoreListsButton: TButton; |
EditIgnoreListsButton: TButton; |
| 28 |
|
Label2: TLabel; |
| 29 |
procedure UpdateButtonClick(Sender: TObject); |
procedure UpdateButtonClick(Sender: TObject); |
| 30 |
procedure StopButtonClick(Sender: TObject); |
procedure StopButtonClick(Sender: TObject); |
| 31 |
procedure CloseButtonClick(Sender: TObject); |
procedure CloseButtonClick(Sender: TObject); |
| 32 |
procedure FormCreate(Sender: TObject); |
procedure FormCreate(Sender: TObject); |
| 33 |
procedure EditIgnoreListsButtonClick(Sender: TObject); |
procedure EditIgnoreListsButtonClick(Sender: TObject); |
| 34 |
procedure FormClose(Sender: TObject; var Action: TCloseAction); |
procedure FormClose(Sender: TObject; var Action: TCloseAction); |
| 35 |
private |
private |
| 36 |
{ Private 宣言 } |
{ Private 宣言 } |
| 37 |
IgnoreLists : TStringList; |
IgnoreLists : TStringList; |
| 38 |
FAbort: Boolean; |
FAbort: Boolean; |
| 39 |
function BoardDownload: TNewBoardItem; |
function BoardDownload(const URL: String): TNewBoardItem; |
| 40 |
procedure UpdateURL(s: string); |
function BoardLoardFromFile(const FilePath: String): String; |
| 41 |
|
function UpdateURL(s: string): boolean; |
| 42 |
procedure SetIgnoreCategory(b: boolean); |
procedure SetIgnoreCategory(b: boolean); |
| 43 |
procedure EditIgnoreList(Sender: TObject); |
procedure EditIgnoreList(Sender: TObject); |
| 44 |
procedure UpdateIgnoreList(Sender: TObject); |
procedure UpdateIgnoreList(Sender: TObject); |
| 45 |
|
function CheckDeleteItem(ini: TMemIniFile): Boolean; |
| 46 |
public |
public |
| 47 |
{ Public 宣言 } |
{ Public 宣言 } |
| 48 |
|
class procedure InitHTTPClient(client : TIdHTTP); |
| 49 |
end; |
end; |
| 50 |
|
|
| 51 |
var |
var |
| 54 |
|
|
| 55 |
implementation |
implementation |
| 56 |
|
|
| 57 |
uses Giko, IdHeaderList; |
uses Giko, IdHeaderList, MojuUtils, GikoDataModule; |
| 58 |
|
|
| 59 |
{$R *.dfm} |
{$R *.dfm} |
| 60 |
|
|
| 61 |
procedure TNewBoardDialog.UpdateButtonClick(Sender: TObject); |
procedure TNewBoardDialog.UpdateButtonClick(Sender: TObject); |
| 62 |
var |
var |
| 63 |
Item: TNewBoardItem; |
Item: TNewBoardItem; |
| 64 |
|
URL : String; |
| 65 |
|
protocol, host, path, document, port, bookmark: String; |
| 66 |
|
TabURLs: TStringList; |
| 67 |
begin |
begin |
| 68 |
try |
try |
| 69 |
GikoSys.Setting.BoardURLSelected := BoardURLComboBox.ItemIndex + 1; |
MessageMemo.Clear; |
| 70 |
|
GikoSys.Setting.BoardURLSelected := BoardURLComboBox.ItemIndex + 1; |
| 71 |
FAbort := False; |
FAbort := False; |
| 72 |
UpdateButton.Enabled := False; |
UpdateButton.Enabled := False; |
| 73 |
StopButton.Enabled := True; |
StopButton.Enabled := True; |
| 74 |
CloseButton.Enabled := False; |
CloseButton.Enabled := False; |
| 75 |
Item := BoardDownload; |
EditIgnoreListsButton.Enabled := False; |
| 76 |
|
URL := BoardURLComboBox.Text; |
| 77 |
|
GikoSys.ParseURI(URL, protocol, host, path, document, port, bookmark); |
| 78 |
|
if (protocol = '') then begin |
| 79 |
|
Item.FContent := BoardLoardFromFile(URL); |
| 80 |
|
end else if (AnsiPos('http', protocol) > 0) then begin |
| 81 |
|
Item := BoardDownload(URL); |
| 82 |
|
end; |
| 83 |
StopButton.Enabled := False; |
StopButton.Enabled := False; |
| 84 |
if FAbort then |
if FAbort then |
| 85 |
Exit; |
Exit; |
| 86 |
if Item.FContent <> '' then begin |
if Item.FContent <> '' then begin |
| 87 |
UpdateURL(Item.FContent); |
TabURLs := TStringList.Create; |
| 88 |
GikoForm.ReloadBBS; |
try |
| 89 |
|
GikoDM.GetTabURLs(TabURLs); |
| 90 |
|
if (UpdateURL(Item.FContent)) then begin |
| 91 |
|
GikoForm.ReloadBBS; |
| 92 |
|
end; |
| 93 |
|
GikoDM.OpenURLs(TabURLs); |
| 94 |
|
finally |
| 95 |
|
TabURLs.Free; |
| 96 |
|
end; |
| 97 |
end else |
end else |
| 98 |
MessageMemo.Lines.Add('ダウンロードが失敗しました[' + IntToStr(Item.FResponseCode) + ']'); |
MessageMemo.Lines.Add('ダウンロードが失敗しました[' + IntToStr(Item.FResponseCode) + ']'); |
| 99 |
finally |
finally |
| 100 |
UpdateButton.Enabled := True; |
UpdateButton.Enabled := True; |
| 101 |
StopButton.Enabled := False; |
StopButton.Enabled := False; |
| 102 |
CloseButton.Enabled := True; |
CloseButton.Enabled := True; |
| 103 |
|
EditIgnoreListsButton.Enabled := True; |
| 104 |
end; |
end; |
| 105 |
end; |
end; |
| 106 |
|
|
| 115 |
Close; |
Close; |
| 116 |
end; |
end; |
| 117 |
|
|
| 118 |
function TNewBoardDialog.BoardDownload: TNewBoardItem; |
function TNewBoardDialog.BoardDownload(const URL: String): TNewBoardItem; |
| 119 |
var |
var |
|
URL: string; |
|
| 120 |
Stream: TMemoryStream; |
Stream: TMemoryStream; |
| 121 |
s: string; |
s: string; |
| 122 |
i: Integer; |
i: Integer; |
| 123 |
begin |
begin |
| 124 |
MessageMemo.Clear; |
InitHTTPClient( Indy ); |
| 125 |
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; |
|
| 126 |
Indy.Request.UserAgent := GikoSys.GetUserAgent; |
Indy.Request.UserAgent := GikoSys.GetUserAgent; |
| 127 |
Indy.Request.Referer := ''; |
Indy.Request.Referer := ''; |
| 128 |
Indy.Request.AcceptEncoding := 'gzip'; |
Indy.Request.AcceptEncoding := 'gzip'; |
| 136 |
try |
try |
| 137 |
MessageMemo.Lines.Add('以下の場所から取得します'); |
MessageMemo.Lines.Add('以下の場所から取得します'); |
| 138 |
//MessageMemo.Lines.Add(GikoSys.Setting.BoardURL2ch); |
//MessageMemo.Lines.Add(GikoSys.Setting.BoardURL2ch); |
| 139 |
MessageMemo.Lines.Add(URL); |
MessageMemo.Lines.Add(URL); |
| 140 |
MessageMemo.Lines.Add('ダウンロードを開始します'); |
MessageMemo.Lines.Add('ダウンロードを開始します'); |
| 141 |
Indy.Get(URL, Stream); |
IdAntiFreeze.Active := True; |
| 142 |
|
try |
| 143 |
|
Indy.Get(URL, Stream); |
| 144 |
|
finally |
| 145 |
|
IdAntiFreeze.Active := False; |
| 146 |
|
end; |
| 147 |
Result.FContent := GikoSys.GzipDecompress(Stream, Indy.Response.ContentEncoding); |
Result.FContent := GikoSys.GzipDecompress(Stream, Indy.Response.ContentEncoding); |
| 148 |
MessageMemo.Lines.Add('ダウンロードが完了しました'); |
MessageMemo.Lines.Add('ダウンロードが完了しました'); |
| 149 |
except |
except |
| 177 |
end; |
end; |
| 178 |
end; |
end; |
| 179 |
|
|
| 180 |
procedure TNewBoardDialog.UpdateURL(s: string); |
function TNewBoardDialog.UpdateURL(s: string): boolean; |
| 181 |
var |
var |
| 182 |
i: Integer; |
i: Integer; |
|
// j: Integer; |
|
| 183 |
idx: Integer; |
idx: Integer; |
| 184 |
idx1: Integer; |
idx1: Integer; |
| 185 |
idx2: Integer; |
idx2: Integer; |
| 271 |
tmp := CustomStringReplace(tmp, 'TARGET=_blank', ''); |
tmp := CustomStringReplace(tmp, 'TARGET=_blank', ''); |
| 272 |
i := AnsiPos('>', tmp); |
i := AnsiPos('>', tmp); |
| 273 |
if i <> 0 then begin |
if i <> 0 then begin |
| 274 |
URL := Copy(tmp, 1, i - 1); |
URL := Trim(Copy(tmp, 1, i - 1)); |
| 275 |
Title := Copy(tmp, i + 1, Length(tmp)); |
Title := Copy(tmp, i + 1, Length(tmp)); |
| 276 |
Board := BBSs[ 0 ].FindBoardFromTitle(Title); |
// BBSsが空対策 |
| 277 |
|
if Length(BBSs) = 0 then begin |
| 278 |
|
Board := nil; |
| 279 |
|
end else begin |
| 280 |
|
Board := BBSs[ 0 ].FindBoardFromTitle(Title); |
| 281 |
|
end; |
| 282 |
if Board = nil then begin |
if Board = nil then begin |
| 283 |
MessageMemo.Lines.Add('新板追加「' + Title + '(' + URL + ')」'); |
MessageMemo.Lines.Add('新板追加「' + Title + '(' + URL + ')」'); |
| 284 |
ini.WriteString(cate, Title, URL); |
ini.WriteString(cate, Title, URL); |
| 302 |
end; |
end; |
| 303 |
end; |
end; |
| 304 |
end; |
end; |
| 305 |
|
// カテゴリ/板が減っただけだとChangeフラグがたたないときの対策 |
| 306 |
|
if not Change then begin |
| 307 |
|
Change := CheckDeleteItem(ini); |
| 308 |
|
end; |
| 309 |
finally |
finally |
| 310 |
if Change then |
if Change then |
| 311 |
ini.UpdateFile; |
ini.UpdateFile; |
| 315 |
if Change then begin |
if Change then begin |
| 316 |
GikoForm.FavoritesURLReplace(oldURLs, newURLs); |
GikoForm.FavoritesURLReplace(oldURLs, newURLs); |
| 317 |
GikoForm.RoundListURLReplace(oldURLs, newURLs); |
GikoForm.RoundListURLReplace(oldURLs, newURLs); |
| 318 |
// GikoForm.TabFileURLReplace(oldURLs, newURLs); |
GikoForm.TabFileURLReplace(oldURLs, newURLs); |
| 319 |
MessageMemo.Lines.Add('新板、板URL変更チェックが完了しました'); |
MessageMemo.Lines.Add('新板、板URL変更チェックが完了しました'); |
| 320 |
MessageMemo.Lines.Add('「閉じる」ボタンを押してください'); |
MessageMemo.Lines.Add('「閉じる」ボタンを押してください'); |
| 321 |
end else |
end else |
| 324 |
oldURLs.Free; |
oldURLs.Free; |
| 325 |
newURLs.Free; |
newURLs.Free; |
| 326 |
end; |
end; |
| 327 |
|
Result := Change; |
| 328 |
|
end; |
| 329 |
|
//! 削除カテゴリ/板チェック |
| 330 |
|
function TNewBoardDialog.CheckDeleteItem(ini: TMemIniFile): Boolean; |
| 331 |
|
var |
| 332 |
|
URL: string; |
| 333 |
|
Title: string; |
| 334 |
|
orgini: TMemIniFile; |
| 335 |
|
orgStrings, newStrings: TStringList; |
| 336 |
|
i: Integer; |
| 337 |
|
begin |
| 338 |
|
orgini := TMemIniFile.Create(GikoSys.GetBoardFileName); |
| 339 |
|
orgStrings := TStringList.Create; |
| 340 |
|
newStrings := TStringList.Create; |
| 341 |
|
try |
| 342 |
|
ini.ReadSections(newStrings); |
| 343 |
|
orgini.ReadSections(orgStrings); |
| 344 |
|
if (newStrings.Count <> orgStrings.Count) then begin |
| 345 |
|
//カテゴリ追加は、板が追加になるのでチェックしなくてもいい |
| 346 |
|
//カテゴリの削除チェック |
| 347 |
|
for i := 0 to orgStrings.Count - 1 do begin |
| 348 |
|
if (newStrings.IndexOf(orgStrings[i]) = -1) then begin |
| 349 |
|
MessageMemo.Lines.Add('カテゴリ削除「' + orgStrings[i] + '」'); |
| 350 |
|
end; |
| 351 |
|
end; |
| 352 |
|
Result := True; |
| 353 |
|
end else begin |
| 354 |
|
// 板の数チェック |
| 355 |
|
ini.GetStrings(newStrings); |
| 356 |
|
orgini.GetStrings(orgStrings); |
| 357 |
|
if (newStrings.Count <> orgStrings.Count) then begin |
| 358 |
|
// 板の削除チェック |
| 359 |
|
for i := 0 to orgStrings.Count - 1 do begin |
| 360 |
|
if (newStrings.IndexOf(orgStrings[i]) = -1) then begin |
| 361 |
|
Title := Copy(orgStrings[i], 1 , AnsiPos('=',orgStrings[i]) - 1); |
| 362 |
|
URL := Copy(orgStrings[i], |
| 363 |
|
AnsiPos('=',orgStrings[i]) + 1, Length(orgStrings[i])); |
| 364 |
|
MessageMemo.Lines.Add('板削除「' + Title + '(' + URL +')」'); |
| 365 |
|
end; |
| 366 |
|
end; |
| 367 |
|
Result := True; |
| 368 |
|
end; |
| 369 |
|
end; |
| 370 |
|
finally |
| 371 |
|
orgStrings.Free; |
| 372 |
|
newStrings.Free; |
| 373 |
|
orgini.Free; |
| 374 |
|
end; |
| 375 |
end; |
end; |
|
|
|
| 376 |
procedure TNewBoardDialog.FormCreate(Sender: TObject); |
procedure TNewBoardDialog.FormCreate(Sender: TObject); |
| 377 |
begin |
begin |
| 378 |
StopButton.Enabled := False; |
StopButton.Enabled := False; |
| 430 |
var |
var |
| 431 |
i: Integer; |
i: Integer; |
| 432 |
begin |
begin |
| 433 |
Label2.Caption := '※現在、開いているタブやヒストリなどは板更新時にクリアされます'; |
Label2.Caption := ''; |
| 434 |
UpdateButton.Enabled := true; |
UpdateButton.Enabled := true; |
| 435 |
EditIgnoreListsButton.Caption := '除外カテゴリー編集'; |
EditIgnoreListsButton.Caption := '除外カテゴリー編集'; |
| 436 |
IgnoreLists.Clear; |
IgnoreLists.Clear; |
| 449 |
begin |
begin |
| 450 |
IgnoreLists.Free; |
IgnoreLists.Free; |
| 451 |
end; |
end; |
| 452 |
|
//! ローカルファイルをロードする |
| 453 |
|
function TNewBoardDialog.BoardLoardFromFile(const FilePath: String): String; |
| 454 |
|
var |
| 455 |
|
html : TStringList; |
| 456 |
|
begin |
| 457 |
|
Result := ''; |
| 458 |
|
// ファイルが存在しているかチェック |
| 459 |
|
if (FileExists(FilePath)) then begin |
| 460 |
|
html := TStringList.Create(); |
| 461 |
|
try |
| 462 |
|
html.LoadFromFile(FilePath); |
| 463 |
|
Result := html.Text; |
| 464 |
|
finally |
| 465 |
|
html.Free; |
| 466 |
|
end; |
| 467 |
|
end; |
| 468 |
|
end; |
| 469 |
|
|
| 470 |
|
class procedure TNewBoardDialog.InitHTTPClient(client : TIdHTTP); |
| 471 |
|
begin |
| 472 |
|
client.Request.Clear; |
| 473 |
|
client.Request.CustomHeaders.Clear; |
| 474 |
|
client.Request.UserAgent := GikoSys.GetUserAgent; |
| 475 |
|
client.RecvBufferSize := Gikosys.Setting.RecvBufferSize; |
| 476 |
|
client.ProxyParams.BasicAuthentication := False; |
| 477 |
|
client.ReadTimeout := GikoSys.Setting.ReadTimeOut; |
| 478 |
|
|
| 479 |
|
if GikoSys.Setting.ReadProxy then begin |
| 480 |
|
if GikoSys.Setting.ProxyProtocol then |
| 481 |
|
client.ProtocolVersion := pv1_1 |
| 482 |
|
else |
| 483 |
|
client.ProtocolVersion := pv1_0; |
| 484 |
|
client.ProxyParams.ProxyServer := GikoSys.Setting.ReadProxyAddress; |
| 485 |
|
client.ProxyParams.ProxyPort := GikoSys.Setting.ReadProxyPort; |
| 486 |
|
client.ProxyParams.ProxyUsername := GikoSys.Setting.ReadProxyUserID; |
| 487 |
|
client.ProxyParams.ProxyPassword := GikoSys.Setting.ReadProxyPassword; |
| 488 |
|
if GikoSys.Setting.ReadProxyUserID <> '' then |
| 489 |
|
client.ProxyParams.BasicAuthentication := True; |
| 490 |
|
end else begin |
| 491 |
|
if GikoSys.Setting.Protocol then |
| 492 |
|
client.ProtocolVersion := pv1_1 |
| 493 |
|
else |
| 494 |
|
client.ProtocolVersion := pv1_0; |
| 495 |
|
client.ProxyParams.ProxyServer := ''; |
| 496 |
|
client.ProxyParams.ProxyPort := 80; |
| 497 |
|
client.ProxyParams.ProxyUsername := ''; |
| 498 |
|
client.ProxyParams.ProxyPassword := ''; |
| 499 |
|
end; |
| 500 |
|
end; |
| 501 |
end. |
end. |