6 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
7 Dialogs, IdAntiFreezeBase, IdAntiFreeze, IdBaseComponent, IdComponent,
8 IdTCPConnection, IdTCPClient, IdHTTP, IDException, StdCtrls, IniFiles,
9 GikoSystem, BoardGroup;
12 TNewBoardItem = record
13 FResponseCode: Integer;
17 TNewBoardDialog = class(TForm)
20 UpdateButton: TButton;
23 IdAntiFreeze: TIdAntiFreeze;
25 BoardURLComboBox: TComboBox;
27 EditIgnoreListsButton: TButton;
29 SakuCheckBox: TCheckBox;
30 procedure UpdateButtonClick(Sender: TObject);
31 procedure StopButtonClick(Sender: TObject);
32 procedure CloseButtonClick(Sender: TObject);
33 procedure FormCreate(Sender: TObject);
34 procedure EditIgnoreListsButtonClick(Sender: TObject);
35 procedure FormClose(Sender: TObject; var Action: TCloseAction);
38 IgnoreLists : TStringList;
40 function BoardDownload(const URL: String): TNewBoardItem;
41 function BoardLoardFromFile(const FilePath: String): String;
42 function UpdateURL(s: string): boolean;
43 procedure SetIgnoreCategory(b: boolean);
44 procedure EditIgnoreList(Sender: TObject);
45 procedure UpdateIgnoreList(Sender: TObject);
46 function CheckDeleteItem(ini: TMemIniFile): Boolean;
49 class procedure InitHTTPClient(client : TIdHTTP);
53 NewBoardDialog: TNewBoardDialog;
58 uses Giko, IdHeaderList, MojuUtils, GikoDataModule;
62 procedure TNewBoardDialog.UpdateButtonClick(Sender: TObject);
66 protocol, host, path, document, port, bookmark: String;
71 GikoSys.Setting.BoardURLSelected := BoardURLComboBox.ItemIndex + 1;
73 UpdateButton.Enabled := False;
74 StopButton.Enabled := True;
75 CloseButton.Enabled := False;
76 EditIgnoreListsButton.Enabled := False;
77 URL := BoardURLComboBox.Text;
78 GikoSys.ParseURI(URL, protocol, host, path, document, port, bookmark);
79 if (protocol = '') then begin
80 Item.FContent := BoardLoardFromFile(URL);
81 end else if (AnsiPos('http', protocol) > 0) then begin
82 Item := BoardDownload(URL);
84 StopButton.Enabled := False;
87 if Item.FContent <> '' then begin
88 TabURLs := TStringList.Create;
90 GikoDM.GetTabURLs(TabURLs);
91 if (UpdateURL(Item.FContent)) then begin
94 GikoDM.OpenURLs(TabURLs);
99 MessageMemo.Lines.Add('
\83_
\83E
\83\93\83\8d\81[
\83h
\82ª
\8e¸
\94s
\82µ
\82Ü
\82µ
\82½[' + IntToStr(Item.FResponseCode) + ']');
101 UpdateButton.Enabled := True;
102 StopButton.Enabled := False;
103 CloseButton.Enabled := True;
104 EditIgnoreListsButton.Enabled := True;
108 procedure TNewBoardDialog.StopButtonClick(Sender: TObject);
111 Indy.DisconnectSocket;
114 procedure TNewBoardDialog.CloseButtonClick(Sender: TObject);
119 function TNewBoardDialog.BoardDownload(const URL: String): TNewBoardItem;
121 Stream: TMemoryStream;
125 InitHTTPClient( Indy );
127 Indy.Request.UserAgent := GikoSys.GetUserAgent;
128 Indy.Request.Referer := '';
129 Indy.Request.AcceptEncoding := 'gzip';
131 Indy.Request.CacheControl := 'no-cache';
132 Indy.Request.CustomHeaders.Add('Pragma: no-cache');
135 Stream := TMemoryStream.Create;
138 MessageMemo.Lines.Add('
\88È
\89º
\82Ì
\8fê
\8f\8a\82©
\82ç
\8eæ
\93¾
\82µ
\82Ü
\82·');
139 //MessageMemo.Lines.Add(GikoSys.Setting.BoardURL2ch);
140 MessageMemo.Lines.Add(URL);
141 MessageMemo.Lines.Add('
\83_
\83E
\83\93\83\8d\81[
\83h
\82ð
\8aJ
\8en
\82µ
\82Ü
\82·');
142 IdAntiFreeze.Active := True;
144 Indy.Get(URL, Stream);
146 IdAntiFreeze.Active := False;
148 Result.FContent := GikoSys.GzipDecompress(Stream, Indy.Response.ContentEncoding);
149 MessageMemo.Lines.Add('
\83_
\83E
\83\93\83\8d\81[
\83h
\82ª
\8a®
\97¹
\82µ
\82Ü
\82µ
\82½');
151 on E: EIdConnectException do begin
152 MessageMemo.Lines.Add('');
153 MessageMemo.Lines.Add('
\90Ú
\91±
\82ª
\8e¸
\94s
\82µ
\82Ü
\82µ
\82½
\89ñ
\90ü
\82â
\83v
\83\8d\83L
\83V
\81AFW
\82Ì
\8fó
\91Ô
\82ð
\92²
\82×
\82Ä
\82
\82¾
\82³
\82¢');
154 MessageMemo.Lines.Add('FW
\82ð
\93ü
\82ê
\82Ä
\82¢
\82é
\90l
\82Í
\90Ý
\92è
\82ð
\8am
\94F
\82µ
\82Ä
\82
\82¾
\82³
\82¢');
155 MessageMemo.Lines.Add('NEC
\82ÌPC
\82Ì
\8fê
\8d\87\82ÍPC GATE
\82ª
\88«
\82³
\82ð
\82µ
\82Ä
\82¢
\82é
\89Â
\94\
\90«
\82ª
\8d\82\82¢
\82Å
\82·');
156 MessageMemo.Lines.Add('Message: ' + E.Message);
158 on E: Exception do begin
160 MessageMemo.Lines.Add('
\83_
\83E
\83\93\83\8d\81[
\83h
\82ð
\92\86\92f
\82µ
\82Ü
\82µ
\82½')
162 MessageMemo.Lines.Add('
\83_
\83E
\83\93\83\8d\81[
\83h
\82ª
\8e¸
\94s
\82µ
\82Ü
\82µ
\82½');
163 MessageMemo.Lines.Add('ResponseCode: ' + IntToStr(Indy.ResponseCode));
164 MessageMemo.Lines.Add('Message: ' + E.Message);
165 MessageMemo.Lines.Add('------------------------');
166 for i := 0 to Indy.Response.RawHeaders.Count - 1 do begin
167 s := Indy.Response.RawHeaders.Names[i];
168 s := s + ': ' + Indy.Response.RawHeaders.Values[s];
169 MessageMemo.Lines.Add(s);
171 MessageMemo.Lines.Add('------------------------');
175 Result.FResponseCode := Indy.ResponseCode;
181 function TNewBoardDialog.UpdateURL(s: string): boolean;
195 oldURLs : TStringList;
196 newURLs : TStringList;
200 MessageMemo.Lines.Add('
\90V
\94Â
\81A
\94ÂURL
\95Ï
\8dX
\83`
\83F
\83b
\83N
\82ð
\8aJ
\8en
\82µ
\82Ü
\82·');
201 MessageMemo.Lines.Add('');
202 s := CustomStringReplace(s, '<B>', '<b>', true);
203 s := CustomStringReplace(s, '<BR>', '<br>', true);
204 s := CustomStringReplace(s, '</B>', '</b>', true);
205 s := CustomStringReplace(s, '<A HREF', '<a href', true);
206 s := CustomStringReplace(s, '</A', '</a', true);
209 oldURLs := TStringList.Create;
210 newURLs := TStringList.Create;
214 GikoSys.ForceDirectoriesEx(GikoSys.GetConfigDir);
215 ini := TMemIniFile.Create(GikoSys.GetBoardFileName);
218 //
\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
223 idx1 := AnsiPos('<b>', s);
224 idx2 := AnsiPos('<a', s);
225 if (idx1 = 0) and (idx2 = 0) then Break;
227 if idx1 < idx2 then begin
229 idx := AnsiPos('</b>', s);
230 if idx = 0 then begin
231 s := Copy(s, idx1 + 4, Length(s));
234 tmp := Copy(s, idx1, (idx - idx1) + 4);
235 tmp := CustomStringReplace(tmp, '<b>', '');
236 tmp := CustomStringReplace(tmp, '</b>', '');
238 for i := 0 to IgnoreLists.Count - 1 do begin
239 if tmp = Trim(IgnoreLists[i]) then begin
241 s := Copy(s, idx + 5, Length(s));
249 if (tmp = '
\82¨
\82·
\82·
\82ß') or
250 (tmp = '
\93Á
\95Ê
\8aé
\89æ') or
251 (tmp = '
\82Ü
\82¿
\82a
\82a
\82r') or
252 (tmp = '
\83`
\83\83\83b
\83g') or
253 (tmp = '
\82¨
\8aG
\82©
\82«') or
254 (tmp = '
\89^
\89c
\88Ä
\93à') or
255 (tmp = '
\83c
\81[
\83\8b\97Þ') or
256 (tmp = '
\91¼
\82Ì
\83T
\83C
\83g') then begin
258 s := Copy(s, idx + 5, Length(s));
262 s := Copy(s, idx + 5, Length(s));
266 if cate = '' then begin
267 s := Copy(s, idx2 + 2, Length(s));
269 idx := AnsiPos('</a>', s);
270 tmp := Copy(s, idx2, (idx - idx2) + 4);
271 tmp := CustomStringReplace(tmp, '<a href=', '');
272 tmp := CustomStringReplace(tmp, '</a>', '');
273 tmp := CustomStringReplace(tmp, 'TARGET=_blank', '');
274 i := AnsiPos('>', tmp);
276 URL := Trim(Copy(tmp, 1, i - 1));
277 Title := Copy(tmp, i + 1, Length(tmp));
278 if (SakuCheckBox.Checked = True) and (Title = '
\8dí
\8f\9c\97v
\90¿') then begin
279 SakuIdx := Pos('.2ch.net/saku/', URL);
280 if (SakuIdx > 0) then
281 URL := Copy(URL, 1, SakuIdx - 1) + '.2ch.net/saku2ch/';
283 // BBSs
\82ª
\8bó
\91Î
\8dô
284 if Length(BBSs) = 0 then begin
287 Board := BBSs[ 0 ].FindBoardFromTitleAndCategory(cate, Title);
289 if Board = nil then begin
290 MessageMemo.Lines.Add('
\90V
\94Â
\92Ç
\89Á
\81u' + Title + '(' + URL + ')
\81v');
291 ini.WriteString(cate, Title, URL);
294 if Board.URL <> URL then begin
295 MessageMemo.Lines.Add('URL
\95Ï
\8dX
\81u' + Board.Title + '(' + URL +')
\81v');
296 ini.WriteString(cate, Title, URL);
297 oldURLs.Add(Board.URL);
301 ini.WriteString(cate, Title, URL);
305 s := Copy(s, idx2 + 2, Length(s));
308 s := Copy(s, idx + 5, Length(s));
312 //
\83J
\83e
\83S
\83\8a/
\94Â
\82ª
\8c¸
\82Á
\82½
\82¾
\82¯
\82¾
\82ÆChange
\83t
\83\89\83O
\82ª
\82½
\82½
\82È
\82¢
\82Æ
\82«
\82Ì
\91Î
\8dô
313 if not Change then begin
314 Change := CheckDeleteItem(ini);
321 MessageMemo.Lines.Add('');
323 GikoForm.FavoritesURLReplace(oldURLs, newURLs);
324 GikoForm.RoundListURLReplace(oldURLs, newURLs);
325 GikoForm.TabFileURLReplace(oldURLs, newURLs);
326 MessageMemo.Lines.Add('
\90V
\94Â
\81A
\94ÂURL
\95Ï
\8dX
\83`
\83F
\83b
\83N
\82ª
\8a®
\97¹
\82µ
\82Ü
\82µ
\82½');
327 MessageMemo.Lines.Add('
\81u
\95Â
\82¶
\82é
\81v
\83{
\83^
\83\93\82ð
\89\9f\82µ
\82Ä
\82
\82¾
\82³
\82¢');
329 MessageMemo.Lines.Add('
\90V
\94Â
\81A
\94ÂURL
\95Ï
\8dX
\82Í
\82 \82è
\82Ü
\82¹
\82ñ
\82Å
\82µ
\82½');
336 //!
\8dí
\8f\9c\83J
\83e
\83S
\83\8a/
\94Â
\83`
\83F
\83b
\83N
337 function TNewBoardDialog.CheckDeleteItem(ini: TMemIniFile): Boolean;
342 orgStrings, newStrings: TStringList;
345 orgini := TMemIniFile.Create(GikoSys.GetBoardFileName);
346 orgStrings := TStringList.Create;
347 newStrings := TStringList.Create;
349 ini.ReadSections(newStrings);
350 orgini.ReadSections(orgStrings);
351 if (newStrings.Count <> orgStrings.Count) then begin
352 //
\83J
\83e
\83S
\83\8a\92Ç
\89Á
\82Í
\81A
\94Â
\82ª
\92Ç
\89Á
\82É
\82È
\82é
\82Ì
\82Å
\83`
\83F
\83b
\83N
\82µ
\82È
\82
\82Ä
\82à
\82¢
\82¢
353 //
\83J
\83e
\83S
\83\8a\82Ì
\8dí
\8f\9c\83`
\83F
\83b
\83N
354 for i := 0 to orgStrings.Count - 1 do begin
355 if (newStrings.IndexOf(orgStrings[i]) = -1) then begin
356 MessageMemo.Lines.Add('
\83J
\83e
\83S
\83\8a\8dí
\8f\9c\81u' + orgStrings[i] + '
\81v');
361 //
\94Â
\82Ì
\90\94\83`
\83F
\83b
\83N
362 ini.GetStrings(newStrings);
363 orgini.GetStrings(orgStrings);
364 if (newStrings.Count <> orgStrings.Count) then begin
365 //
\94Â
\82Ì
\8dí
\8f\9c\83`
\83F
\83b
\83N
366 for i := 0 to orgStrings.Count - 1 do begin
367 if (newStrings.IndexOf(orgStrings[i]) = -1) then begin
368 Title := Copy(orgStrings[i], 1 , AnsiPos('=',orgStrings[i]) - 1);
369 URL := Copy(orgStrings[i],
370 AnsiPos('=',orgStrings[i]) + 1, Length(orgStrings[i]));
371 MessageMemo.Lines.Add('
\94Â
\8dí
\8f\9c\81u' + Title + '(' + URL +')
\81v');
383 procedure TNewBoardDialog.FormCreate(Sender: TObject);
385 CenterForm: TCustomForm;
387 CenterForm := TCustomForm(Owner);
388 if Assigned(CenterForm) then begin
389 Left := ((CenterForm.Width - Width) div 2) + CenterForm.Left;
390 Top := ((CenterForm.Height - Height) div 2) + CenterForm.Top;
392 Left := (Screen.Width - Width) div 2;
393 Top := (Screen.Height - Height) div 2;
396 StopButton.Enabled := False;
397 BoardURLComboBox.Clear;
398 BoardURLComboBox.Items.AddStrings(GikoSys.Setting.BoardURLs);
400 BoardURLComboBox.ItemIndex := GikoSys.Setting.BoardURLSelected - 1;
402 BoardURLComboBox.ItemIndex := 0;
404 SetIgnoreCategory(false);
406 SakuCheckBox.Checked := GikoSys.Setting.SakuBoard;
408 //
\94Â
\8dX
\90V
\82Ì
\8f\9c\8aO
\83J
\83e
\83S
\83\8a\83\8a\83X
\83g
\82Ì
\93o
\98^
409 {['
\82¨
\82·
\82·
\82ß', '
\93Á
\95Ê
\8aé
\89æ', '
\82Ü
\82¿
\82a
\82a
\82r', '
\83`
\83\83\83b
\83g', '
\82¨
\8aG
\82©
\82«', '
\89^
\89c
\88Ä
\93à', '
\83c
\81[
\83\8b\97Þ', '
\91¼
\82Ì
\83T
\83C
\83g']}
410 procedure TNewBoardDialog.SetIgnoreCategory(b: boolean);
412 IgnoreLists := TStringList.Create;
413 if not( FileExists(GikoSys.Setting.GetIgnoreFileName) ) or ( b )then begin
414 IgnoreLists.Add('
\82¨
\82·
\82·
\82ß');
415 IgnoreLists.Add('
\93Á
\95Ê
\8aé
\89æ');
416 IgnoreLists.Add('
\82Ü
\82¿
\82a
\82a
\82r');
417 IgnoreLists.Add('
\83`
\83\83\83b
\83g');
418 IgnoreLists.Add('
\82¨
\8aG
\82©
\82«');
419 IgnoreLists.Add('
\89^
\89c
\88Ä
\93à');
420 IgnoreLists.Add('
\83c
\81[
\83\8b\97Þ');
421 IgnoreLists.Add('
\91¼
\82Ì
\83T
\83C
\83g');
424 IgnoreLists.LoadFromFile(GikoSys.Setting.GetIgnoreFileName);
427 SetIgnoreCategory(true);
432 procedure TNewBoardDialog.EditIgnoreListsButtonClick(Sender: TObject);
434 EditIgnoreList(Sender);
435 EditIgnoreListsButton.OnClick := UpdateIgnoreList;
437 procedure TNewBoardDialog.EditIgnoreList(Sender: TObject);
441 EditIgnoreListsButton.Caption := '
\8f\9c\8aO
\83J
\83e
\83S
\83\8a\81[
\8dX
\90V';
442 Label2.Caption := '
\8ae
\82P
\8ds
\82É
\83J
\83e
\83S
\83\8a\96¼
\82ð
\8bL
\93ü
\82µ
\82Ä
\82
\82¾
\82³
\82¢
\81B
\81i
\89ü
\8ds
\82ÍCtrl+Enter
\81j';
443 UpdateButton.Enabled := false;
444 //MessageMemo.ReadOnly := false;
446 for i := 0 to IgnoreLists.Count - 1 do
447 MessageMemo.Lines.Add(IgnoreLists[i]);
449 procedure TNewBoardDialog.UpdateIgnoreList(Sender: TObject);
453 Label2.Caption := '';
454 UpdateButton.Enabled := true;
455 EditIgnoreListsButton.Caption := '
\8f\9c\8aO
\83J
\83e
\83S
\83\8a\81[
\95Ò
\8fW';
457 for i := 0 to MessageMemo.Lines.Count - 1 do
458 IgnoreLists.Add(MessageMemo.Lines[i]);
459 IgnoreLists.SaveToFile(GikoSys.Setting.GetIgnoreFileName);
461 SetIgnoreCategory(false);
462 //MessageMemo.ReadOnly := true;
464 EditIgnoreListsButton.OnClick := EditIgnoreListsButtonClick;
467 procedure TNewBoardDialog.FormClose(Sender: TObject;
468 var Action: TCloseAction);
470 GikoSys.Setting.SakuBoard := SakuCheckBox.Checked;
473 //!
\83\8d\81[
\83J
\83\8b\83t
\83@
\83C
\83\8b\82ð
\83\8d\81[
\83h
\82·
\82é
474 function TNewBoardDialog.BoardLoardFromFile(const FilePath: String): String;
479 //
\83t
\83@
\83C
\83\8b\82ª
\91¶
\8dÝ
\82µ
\82Ä
\82¢
\82é
\82©
\83`
\83F
\83b
\83N
480 if (FileExists(FilePath)) then begin
481 html := TStringList.Create();
483 html.LoadFromFile(FilePath);
491 class procedure TNewBoardDialog.InitHTTPClient(client : TIdHTTP);
493 client.Request.Clear;
494 client.Request.CustomHeaders.Clear;
495 client.Request.UserAgent := GikoSys.GetUserAgent;
496 client.RecvBufferSize := Gikosys.Setting.RecvBufferSize;
497 client.ProxyParams.BasicAuthentication := False;
498 client.ReadTimeout := GikoSys.Setting.ReadTimeOut;
499 client.ConnectTimeout := GikoSys.Setting.ReadTimeOut;
501 if GikoSys.Setting.ReadProxy then begin
502 if GikoSys.Setting.ProxyProtocol then
503 client.ProtocolVersion := pv1_1
505 client.ProtocolVersion := pv1_0;
506 client.ProxyParams.ProxyServer := GikoSys.Setting.ReadProxyAddress;
507 client.ProxyParams.ProxyPort := GikoSys.Setting.ReadProxyPort;
508 client.ProxyParams.ProxyUsername := GikoSys.Setting.ReadProxyUserID;
509 client.ProxyParams.ProxyPassword := GikoSys.Setting.ReadProxyPassword;
510 if GikoSys.Setting.ReadProxyUserID <> '' then
511 client.ProxyParams.BasicAuthentication := True;
513 if GikoSys.Setting.Protocol then
514 client.ProtocolVersion := pv1_1
516 client.ProtocolVersion := pv1_0;
517 client.ProxyParams.ProxyServer := '';
518 client.ProxyParams.ProxyPort := 80;
519 client.ProxyParams.ProxyUsername := '';
520 client.ProxyParams.ProxyPassword := '';