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 procedure UpdateButtonClick(Sender: TObject);
30 procedure StopButtonClick(Sender: TObject);
31 procedure CloseButtonClick(Sender: TObject);
32 procedure FormCreate(Sender: TObject);
33 procedure EditIgnoreListsButtonClick(Sender: TObject);
34 procedure FormClose(Sender: TObject; var Action: TCloseAction);
37 IgnoreLists : TStringList;
39 function BoardDownload(const URL: String): TNewBoardItem;
40 function BoardLoardFromFile(const FilePath: String): String;
41 function UpdateURL(s: string): boolean;
42 procedure SetIgnoreCategory(b: boolean);
43 procedure EditIgnoreList(Sender: TObject);
44 procedure UpdateIgnoreList(Sender: TObject);
47 class procedure InitHTTPClient(client : TIdHTTP);
51 NewBoardDialog: TNewBoardDialog;
56 uses Giko, IdHeaderList, MojuUtils, GikoDataModule;
60 procedure TNewBoardDialog.UpdateButtonClick(Sender: TObject);
64 protocol, host, path, document, port, bookmark: String;
69 GikoSys.Setting.BoardURLSelected := BoardURLComboBox.ItemIndex + 1;
71 UpdateButton.Enabled := False;
72 StopButton.Enabled := True;
73 CloseButton.Enabled := False;
74 EditIgnoreListsButton.Enabled := False;
75 URL := BoardURLComboBox.Text;
76 GikoSys.ParseURI(URL, protocol, host, path, document, port, bookmark);
77 if (protocol = '') then begin
78 Item.FContent := BoardLoardFromFile(URL);
79 end else if (AnsiPos('http', protocol) > 0) then begin
80 Item := BoardDownload(URL);
82 StopButton.Enabled := False;
85 if Item.FContent <> '' then begin
86 TabURLs := TStringList.Create;
88 GikoDM.GetTabURLs(TabURLs);
89 if (UpdateURL(Item.FContent)) then begin
92 GikoDM.OpenURLs(TabURLs);
97 MessageMemo.Lines.Add('
\83_
\83E
\83\93\83\8d\81[
\83h
\82ª
\8e¸
\94s
\82µ
\82Ü
\82µ
\82½[' + IntToStr(Item.FResponseCode) + ']');
99 UpdateButton.Enabled := True;
100 StopButton.Enabled := False;
101 CloseButton.Enabled := True;
102 EditIgnoreListsButton.Enabled := True;
106 procedure TNewBoardDialog.StopButtonClick(Sender: TObject);
109 Indy.DisconnectSocket;
112 procedure TNewBoardDialog.CloseButtonClick(Sender: TObject);
117 function TNewBoardDialog.BoardDownload(const URL: String): TNewBoardItem;
119 Stream: TMemoryStream;
123 InitHTTPClient( Indy );
125 Indy.Request.UserAgent := GikoSys.GetUserAgent;
126 Indy.Request.Referer := '';
127 Indy.Request.AcceptEncoding := 'gzip';
129 Indy.Request.CacheControl := 'no-cache';
130 Indy.Request.CustomHeaders.Add('Pragma: no-cache');
133 Stream := TMemoryStream.Create;
136 MessageMemo.Lines.Add('
\88È
\89º
\82Ì
\8fê
\8f\8a\82©
\82ç
\8eæ
\93¾
\82µ
\82Ü
\82·');
137 //MessageMemo.Lines.Add(GikoSys.Setting.BoardURL2ch);
138 MessageMemo.Lines.Add(URL);
139 MessageMemo.Lines.Add('
\83_
\83E
\83\93\83\8d\81[
\83h
\82ð
\8aJ
\8en
\82µ
\82Ü
\82·');
140 IdAntiFreeze.Active := True;
142 Indy.Get(URL, Stream);
144 IdAntiFreeze.Active := False;
146 Result.FContent := GikoSys.GzipDecompress(Stream, Indy.Response.ContentEncoding);
147 MessageMemo.Lines.Add('
\83_
\83E
\83\93\83\8d\81[
\83h
\82ª
\8a®
\97¹
\82µ
\82Ü
\82µ
\82½');
149 on E: EIdConnectException do begin
150 MessageMemo.Lines.Add('');
151 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¢');
152 MessageMemo.Lines.Add('FW
\82ð
\93ü
\82ê
\82Ä
\82¢
\82é
\90l
\82Í
\90Ý
\92è
\82ð
\8am
\94F
\82µ
\82Ä
\82
\82¾
\82³
\82¢');
153 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·');
154 MessageMemo.Lines.Add('Message: ' + E.Message);
156 on E: Exception do begin
158 MessageMemo.Lines.Add('
\83_
\83E
\83\93\83\8d\81[
\83h
\82ð
\92\86\92f
\82µ
\82Ü
\82µ
\82½')
160 MessageMemo.Lines.Add('
\83_
\83E
\83\93\83\8d\81[
\83h
\82ª
\8e¸
\94s
\82µ
\82Ü
\82µ
\82½');
161 MessageMemo.Lines.Add('ResponseCode: ' + IntToStr(Indy.ResponseCode));
162 MessageMemo.Lines.Add('Message: ' + E.Message);
163 MessageMemo.Lines.Add('------------------------');
164 for i := 0 to Indy.Response.RawHeaders.Count - 1 do begin
165 s := Indy.Response.RawHeaders.Names[i];
166 s := s + ': ' + Indy.Response.RawHeaders.Values[s];
167 MessageMemo.Lines.Add(s);
169 MessageMemo.Lines.Add('------------------------');
173 Result.FResponseCode := Indy.ResponseCode;
179 function TNewBoardDialog.UpdateURL(s: string): boolean;
193 oldURLs : TStringList;
194 newURLs : TStringList;
197 MessageMemo.Lines.Add('
\90V
\94Â
\81A
\94ÂURL
\95Ï
\8dX
\83`
\83F
\83b
\83N
\82ð
\8aJ
\8en
\82µ
\82Ü
\82·');
198 MessageMemo.Lines.Add('');
199 s := CustomStringReplace(s, '<B>', '<b>', true);
200 s := CustomStringReplace(s, '<BR>', '<br>', true);
201 s := CustomStringReplace(s, '</B>', '</b>', true);
202 s := CustomStringReplace(s, '<A HREF', '<a href', true);
203 s := CustomStringReplace(s, '</A', '</a', true);
206 oldURLs := TStringList.Create;
207 newURLs := TStringList.Create;
211 GikoSys.ForceDirectoriesEx(GikoSys.GetConfigDir);
212 ini := TMemIniFile.Create(GikoSys.GetBoardFileName);
215 //
\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
220 idx1 := AnsiPos('<b>', s);
221 idx2 := AnsiPos('<a', s);
222 if (idx1 = 0) and (idx2 = 0) then Break;
224 if idx1 < idx2 then begin
226 idx := AnsiPos('</b>', s);
227 if idx = 0 then begin
228 s := Copy(s, idx1 + 4, Length(s));
231 tmp := Copy(s, idx1, (idx - idx1) + 4);
232 tmp := CustomStringReplace(tmp, '<b>', '');
233 tmp := CustomStringReplace(tmp, '</b>', '');
235 for i := 0 to IgnoreLists.Count - 1 do begin
236 if tmp = Trim(IgnoreLists[i]) then begin
238 s := Copy(s, idx + 5, Length(s));
246 if (tmp = '
\82¨
\82·
\82·
\82ß') or
247 (tmp = '
\93Á
\95Ê
\8aé
\89æ') or
248 (tmp = '
\82Ü
\82¿
\82a
\82a
\82r') or
249 (tmp = '
\83`
\83\83\83b
\83g') or
250 (tmp = '
\82¨
\8aG
\82©
\82«') or
251 (tmp = '
\89^
\89c
\88Ä
\93à') or
252 (tmp = '
\83c
\81[
\83\8b\97Þ') or
253 (tmp = '
\91¼
\82Ì
\83T
\83C
\83g') then begin
255 s := Copy(s, idx + 5, Length(s));
259 s := Copy(s, idx + 5, Length(s));
263 if cate = '' then begin
264 s := Copy(s, idx2 + 2, Length(s));
266 idx := AnsiPos('</a>', s);
267 tmp := Copy(s, idx2, (idx - idx2) + 4);
268 tmp := CustomStringReplace(tmp, '<a href=', '');
269 tmp := CustomStringReplace(tmp, '</a>', '');
270 tmp := CustomStringReplace(tmp, 'TARGET=_blank', '');
271 i := AnsiPos('>', tmp);
273 URL := Copy(tmp, 1, i - 1);
274 Title := Copy(tmp, i + 1, Length(tmp));
275 Board := BBSs[ 0 ].FindBoardFromTitle(Title);
276 if Board = nil then begin
277 MessageMemo.Lines.Add('
\90V
\94Â
\92Ç
\89Á
\81u' + Title + '(' + URL + ')
\81v');
278 ini.WriteString(cate, Title, URL);
281 if Board.URL <> URL then begin
282 MessageMemo.Lines.Add('URL
\95Ï
\8dX
\81u' + Board.Title + '(' + URL +')
\81v');
283 ini.WriteString(cate, Title, URL);
284 oldURLs.Add(Board.URL);
288 ini.WriteString(cate, Title, URL);
292 s := Copy(s, idx2 + 2, Length(s));
295 s := Copy(s, idx + 5, Length(s));
304 MessageMemo.Lines.Add('');
306 GikoForm.FavoritesURLReplace(oldURLs, newURLs);
307 GikoForm.RoundListURLReplace(oldURLs, newURLs);
308 GikoForm.TabFileURLReplace(oldURLs, newURLs);
309 MessageMemo.Lines.Add('
\90V
\94Â
\81A
\94ÂURL
\95Ï
\8dX
\83`
\83F
\83b
\83N
\82ª
\8a®
\97¹
\82µ
\82Ü
\82µ
\82½');
310 MessageMemo.Lines.Add('
\81u
\95Â
\82¶
\82é
\81v
\83{
\83^
\83\93\82ð
\89\9f\82µ
\82Ä
\82
\82¾
\82³
\82¢');
312 MessageMemo.Lines.Add('
\90V
\94Â
\81A
\94ÂURL
\95Ï
\8dX
\82Í
\82 \82è
\82Ü
\82¹
\82ñ
\82Å
\82µ
\82½');
320 procedure TNewBoardDialog.FormCreate(Sender: TObject);
322 StopButton.Enabled := False;
323 BoardURLComboBox.Clear;
324 BoardURLComboBox.Items.AddStrings(GikoSys.Setting.BoardURLs);
326 BoardURLComboBox.ItemIndex := GikoSys.Setting.BoardURLSelected - 1;
328 BoardURLComboBox.ItemIndex := 0;
330 SetIgnoreCategory(false);
332 //
\94Â
\8dX
\90V
\82Ì
\8f\9c\8aO
\83J
\83e
\83S
\83\8a\83\8a\83X
\83g
\82Ì
\93o
\98^
333 {['
\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']}
334 procedure TNewBoardDialog.SetIgnoreCategory(b: boolean);
336 IgnoreLists := TStringList.Create;
337 if not( FileExists(GikoSys.Setting.GetIgnoreFileName) ) or ( b )then begin
338 IgnoreLists.Add('
\82¨
\82·
\82·
\82ß');
339 IgnoreLists.Add('
\93Á
\95Ê
\8aé
\89æ');
340 IgnoreLists.Add('
\82Ü
\82¿
\82a
\82a
\82r');
341 IgnoreLists.Add('
\83`
\83\83\83b
\83g');
342 IgnoreLists.Add('
\82¨
\8aG
\82©
\82«');
343 IgnoreLists.Add('
\89^
\89c
\88Ä
\93à');
344 IgnoreLists.Add('
\83c
\81[
\83\8b\97Þ');
345 IgnoreLists.Add('
\91¼
\82Ì
\83T
\83C
\83g');
348 IgnoreLists.LoadFromFile(GikoSys.Setting.GetIgnoreFileName);
351 SetIgnoreCategory(true);
356 procedure TNewBoardDialog.EditIgnoreListsButtonClick(Sender: TObject);
358 EditIgnoreList(Sender);
359 EditIgnoreListsButton.OnClick := UpdateIgnoreList;
361 procedure TNewBoardDialog.EditIgnoreList(Sender: TObject);
365 EditIgnoreListsButton.Caption := '
\8f\9c\8aO
\83J
\83e
\83S
\83\8a\81[
\8dX
\90V';
366 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';
367 UpdateButton.Enabled := false;
368 //MessageMemo.ReadOnly := false;
370 for i := 0 to IgnoreLists.Count - 1 do
371 MessageMemo.Lines.Add(IgnoreLists[i]);
373 procedure TNewBoardDialog.UpdateIgnoreList(Sender: TObject);
377 Label2.Caption := '';
378 UpdateButton.Enabled := true;
379 EditIgnoreListsButton.Caption := '
\8f\9c\8aO
\83J
\83e
\83S
\83\8a\81[
\95Ò
\8fW';
381 for i := 0 to MessageMemo.Lines.Count - 1 do
382 IgnoreLists.Add(MessageMemo.Lines[i]);
383 IgnoreLists.SaveToFile(GikoSys.Setting.GetIgnoreFileName);
385 SetIgnoreCategory(false);
386 //MessageMemo.ReadOnly := true;
388 EditIgnoreListsButton.OnClick := EditIgnoreListsButtonClick;
391 procedure TNewBoardDialog.FormClose(Sender: TObject;
392 var Action: TCloseAction);
396 //!
\83\8d\81[
\83J
\83\8b\83t
\83@
\83C
\83\8b\82ð
\83\8d\81[
\83h
\82·
\82é
397 function TNewBoardDialog.BoardLoardFromFile(const FilePath: String): String;
402 //
\83t
\83@
\83C
\83\8b\82ª
\91¶
\8dÝ
\82µ
\82Ä
\82¢
\82é
\82©
\83`
\83F
\83b
\83N
403 if (FileExists(FilePath)) then begin
404 html := TStringList.Create();
406 html.LoadFromFile(FilePath);
414 class procedure TNewBoardDialog.InitHTTPClient(client : TIdHTTP);
416 client.Request.Clear;
417 client.Request.CustomHeaders.Clear;
418 client.RecvBufferSize := Gikosys.Setting.RecvBufferSize;
419 client.ProxyParams.BasicAuthentication := False;
420 if GikoSys.Setting.ReadProxy then begin
421 if GikoSys.Setting.ProxyProtocol then
422 client.ProtocolVersion := pv1_1
424 client.ProtocolVersion := pv1_0;
425 client.ProxyParams.ProxyServer := GikoSys.Setting.ReadProxyAddress;
426 client.ProxyParams.ProxyPort := GikoSys.Setting.ReadProxyPort;
427 client.ProxyParams.ProxyUsername := GikoSys.Setting.ReadProxyUserID;
428 client.ProxyParams.ProxyPassword := GikoSys.Setting.ReadProxyPassword;
429 if GikoSys.Setting.ReadProxyUserID <> '' then
430 client.ProxyParams.BasicAuthentication := True;
432 if GikoSys.Setting.Protocol then
433 client.ProtocolVersion := pv1_1
435 client.ProtocolVersion := pv1_0;
436 client.ProxyParams.ProxyServer := '';
437 client.ProxyParams.ProxyPort := 80;
438 client.ProxyParams.ProxyUsername := '';
439 client.ProxyParams.ProxyPassword := '';