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);
45 function CheckDeleteItem(ini: TMemIniFile): Boolean;
48 class procedure InitHTTPClient(client : TIdHTTP);
52 NewBoardDialog: TNewBoardDialog;
57 uses Giko, IdHeaderList, MojuUtils, GikoDataModule;
61 procedure TNewBoardDialog.UpdateButtonClick(Sender: TObject);
65 protocol, host, path, document, port, bookmark: String;
70 GikoSys.Setting.BoardURLSelected := BoardURLComboBox.ItemIndex + 1;
72 UpdateButton.Enabled := False;
73 StopButton.Enabled := True;
74 CloseButton.Enabled := False;
75 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);
83 StopButton.Enabled := False;
86 if Item.FContent <> '' then begin
87 TabURLs := TStringList.Create;
89 GikoDM.GetTabURLs(TabURLs);
90 if (UpdateURL(Item.FContent)) then begin
93 GikoDM.OpenURLs(TabURLs);
98 MessageMemo.Lines.Add('
\83_
\83E
\83\93\83\8d\81[
\83h
\82ª
\8e¸
\94s
\82µ
\82Ü
\82µ
\82½[' + IntToStr(Item.FResponseCode) + ']');
100 UpdateButton.Enabled := True;
101 StopButton.Enabled := False;
102 CloseButton.Enabled := True;
103 EditIgnoreListsButton.Enabled := True;
107 procedure TNewBoardDialog.StopButtonClick(Sender: TObject);
110 Indy.DisconnectSocket;
113 procedure TNewBoardDialog.CloseButtonClick(Sender: TObject);
118 function TNewBoardDialog.BoardDownload(const URL: String): TNewBoardItem;
120 Stream: TMemoryStream;
124 InitHTTPClient( Indy );
126 Indy.Request.UserAgent := GikoSys.GetUserAgent;
127 Indy.Request.Referer := '';
128 Indy.Request.AcceptEncoding := 'gzip';
130 Indy.Request.CacheControl := 'no-cache';
131 Indy.Request.CustomHeaders.Add('Pragma: no-cache');
134 Stream := TMemoryStream.Create;
137 MessageMemo.Lines.Add('
\88È
\89º
\82Ì
\8fê
\8f\8a\82©
\82ç
\8eæ
\93¾
\82µ
\82Ü
\82·');
138 //MessageMemo.Lines.Add(GikoSys.Setting.BoardURL2ch);
139 MessageMemo.Lines.Add(URL);
140 MessageMemo.Lines.Add('
\83_
\83E
\83\93\83\8d\81[
\83h
\82ð
\8aJ
\8en
\82µ
\82Ü
\82·');
141 IdAntiFreeze.Active := True;
143 Indy.Get(URL, Stream);
145 IdAntiFreeze.Active := False;
147 Result.FContent := GikoSys.GzipDecompress(Stream, Indy.Response.ContentEncoding);
148 MessageMemo.Lines.Add('
\83_
\83E
\83\93\83\8d\81[
\83h
\82ª
\8a®
\97¹
\82µ
\82Ü
\82µ
\82½');
150 on E: EIdConnectException do begin
151 MessageMemo.Lines.Add('');
152 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¢');
153 MessageMemo.Lines.Add('FW
\82ð
\93ü
\82ê
\82Ä
\82¢
\82é
\90l
\82Í
\90Ý
\92è
\82ð
\8am
\94F
\82µ
\82Ä
\82
\82¾
\82³
\82¢');
154 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·');
155 MessageMemo.Lines.Add('Message: ' + E.Message);
157 on E: Exception do begin
159 MessageMemo.Lines.Add('
\83_
\83E
\83\93\83\8d\81[
\83h
\82ð
\92\86\92f
\82µ
\82Ü
\82µ
\82½')
161 MessageMemo.Lines.Add('
\83_
\83E
\83\93\83\8d\81[
\83h
\82ª
\8e¸
\94s
\82µ
\82Ü
\82µ
\82½');
162 MessageMemo.Lines.Add('ResponseCode: ' + IntToStr(Indy.ResponseCode));
163 MessageMemo.Lines.Add('Message: ' + E.Message);
164 MessageMemo.Lines.Add('------------------------');
165 for i := 0 to Indy.Response.RawHeaders.Count - 1 do begin
166 s := Indy.Response.RawHeaders.Names[i];
167 s := s + ': ' + Indy.Response.RawHeaders.Values[s];
168 MessageMemo.Lines.Add(s);
170 MessageMemo.Lines.Add('------------------------');
174 Result.FResponseCode := Indy.ResponseCode;
180 function TNewBoardDialog.UpdateURL(s: string): boolean;
194 oldURLs : TStringList;
195 newURLs : TStringList;
198 MessageMemo.Lines.Add('
\90V
\94Â
\81A
\94ÂURL
\95Ï
\8dX
\83`
\83F
\83b
\83N
\82ð
\8aJ
\8en
\82µ
\82Ü
\82·');
199 MessageMemo.Lines.Add('');
200 s := CustomStringReplace(s, '<B>', '<b>', true);
201 s := CustomStringReplace(s, '<BR>', '<br>', true);
202 s := CustomStringReplace(s, '</B>', '</b>', true);
203 s := CustomStringReplace(s, '<A HREF', '<a href', true);
204 s := CustomStringReplace(s, '</A', '</a', true);
207 oldURLs := TStringList.Create;
208 newURLs := TStringList.Create;
212 GikoSys.ForceDirectoriesEx(GikoSys.GetConfigDir);
213 ini := TMemIniFile.Create(GikoSys.GetBoardFileName);
216 //
\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
221 idx1 := AnsiPos('<b>', s);
222 idx2 := AnsiPos('<a', s);
223 if (idx1 = 0) and (idx2 = 0) then Break;
225 if idx1 < idx2 then begin
227 idx := AnsiPos('</b>', s);
228 if idx = 0 then begin
229 s := Copy(s, idx1 + 4, Length(s));
232 tmp := Copy(s, idx1, (idx - idx1) + 4);
233 tmp := CustomStringReplace(tmp, '<b>', '');
234 tmp := CustomStringReplace(tmp, '</b>', '');
236 for i := 0 to IgnoreLists.Count - 1 do begin
237 if tmp = Trim(IgnoreLists[i]) then begin
239 s := Copy(s, idx + 5, Length(s));
247 if (tmp = '
\82¨
\82·
\82·
\82ß') or
248 (tmp = '
\93Á
\95Ê
\8aé
\89æ') or
249 (tmp = '
\82Ü
\82¿
\82a
\82a
\82r') or
250 (tmp = '
\83`
\83\83\83b
\83g') or
251 (tmp = '
\82¨
\8aG
\82©
\82«') or
252 (tmp = '
\89^
\89c
\88Ä
\93à') or
253 (tmp = '
\83c
\81[
\83\8b\97Þ') or
254 (tmp = '
\91¼
\82Ì
\83T
\83C
\83g') then begin
256 s := Copy(s, idx + 5, Length(s));
260 s := Copy(s, idx + 5, Length(s));
264 if cate = '' then begin
265 s := Copy(s, idx2 + 2, Length(s));
267 idx := AnsiPos('</a>', s);
268 tmp := Copy(s, idx2, (idx - idx2) + 4);
269 tmp := CustomStringReplace(tmp, '<a href=', '');
270 tmp := CustomStringReplace(tmp, '</a>', '');
271 tmp := CustomStringReplace(tmp, 'TARGET=_blank', '');
272 i := AnsiPos('>', tmp);
274 URL := Trim(Copy(tmp, 1, i - 1));
275 Title := Copy(tmp, i + 1, Length(tmp));
276 // BBSs
\82ª
\8bó
\91Î
\8dô
277 if Length(BBSs) = 0 then begin
280 Board := BBSs[ 0 ].FindBoardFromTitle(Title);
282 if Board = nil then begin
283 MessageMemo.Lines.Add('
\90V
\94Â
\92Ç
\89Á
\81u' + Title + '(' + URL + ')
\81v');
284 ini.WriteString(cate, Title, URL);
287 if Board.URL <> URL then begin
288 MessageMemo.Lines.Add('URL
\95Ï
\8dX
\81u' + Board.Title + '(' + URL +')
\81v');
289 ini.WriteString(cate, Title, URL);
290 oldURLs.Add(Board.URL);
294 ini.WriteString(cate, Title, URL);
298 s := Copy(s, idx2 + 2, Length(s));
301 s := Copy(s, idx + 5, Length(s));
305 //
\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ô
306 if not Change then begin
307 Change := CheckDeleteItem(ini);
314 MessageMemo.Lines.Add('');
316 GikoForm.FavoritesURLReplace(oldURLs, newURLs);
317 GikoForm.RoundListURLReplace(oldURLs, newURLs);
318 GikoForm.TabFileURLReplace(oldURLs, newURLs);
319 MessageMemo.Lines.Add('
\90V
\94Â
\81A
\94ÂURL
\95Ï
\8dX
\83`
\83F
\83b
\83N
\82ª
\8a®
\97¹
\82µ
\82Ü
\82µ
\82½');
320 MessageMemo.Lines.Add('
\81u
\95Â
\82¶
\82é
\81v
\83{
\83^
\83\93\82ð
\89\9f\82µ
\82Ä
\82
\82¾
\82³
\82¢');
322 MessageMemo.Lines.Add('
\90V
\94Â
\81A
\94ÂURL
\95Ï
\8dX
\82Í
\82 \82è
\82Ü
\82¹
\82ñ
\82Å
\82µ
\82½');
329 //!
\8dí
\8f\9c\83J
\83e
\83S
\83\8a/
\94Â
\83`
\83F
\83b
\83N
330 function TNewBoardDialog.CheckDeleteItem(ini: TMemIniFile): Boolean;
335 orgStrings, newStrings: TStringList;
338 orgini := TMemIniFile.Create(GikoSys.GetBoardFileName);
339 orgStrings := TStringList.Create;
340 newStrings := TStringList.Create;
342 ini.ReadSections(newStrings);
343 orgini.ReadSections(orgStrings);
344 if (newStrings.Count <> orgStrings.Count) then begin
345 //
\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¢
346 //
\83J
\83e
\83S
\83\8a\82Ì
\8dí
\8f\9c\83`
\83F
\83b
\83N
347 for i := 0 to orgStrings.Count - 1 do begin
348 if (newStrings.IndexOf(orgStrings[i]) = -1) then begin
349 MessageMemo.Lines.Add('
\83J
\83e
\83S
\83\8a\8dí
\8f\9c\81u' + orgStrings[i] + '
\81v');
354 //
\94Â
\82Ì
\90\94\83`
\83F
\83b
\83N
355 ini.GetStrings(newStrings);
356 orgini.GetStrings(orgStrings);
357 if (newStrings.Count <> orgStrings.Count) then begin
358 //
\94Â
\82Ì
\8dí
\8f\9c\83`
\83F
\83b
\83N
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('
\94Â
\8dí
\8f\9c\81u' + Title + '(' + URL +')
\81v');
376 procedure TNewBoardDialog.FormCreate(Sender: TObject);
378 StopButton.Enabled := False;
379 BoardURLComboBox.Clear;
380 BoardURLComboBox.Items.AddStrings(GikoSys.Setting.BoardURLs);
382 BoardURLComboBox.ItemIndex := GikoSys.Setting.BoardURLSelected - 1;
384 BoardURLComboBox.ItemIndex := 0;
386 SetIgnoreCategory(false);
388 //
\94Â
\8dX
\90V
\82Ì
\8f\9c\8aO
\83J
\83e
\83S
\83\8a\83\8a\83X
\83g
\82Ì
\93o
\98^
389 {['
\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']}
390 procedure TNewBoardDialog.SetIgnoreCategory(b: boolean);
392 IgnoreLists := TStringList.Create;
393 if not( FileExists(GikoSys.Setting.GetIgnoreFileName) ) or ( b )then begin
394 IgnoreLists.Add('
\82¨
\82·
\82·
\82ß');
395 IgnoreLists.Add('
\93Á
\95Ê
\8aé
\89æ');
396 IgnoreLists.Add('
\82Ü
\82¿
\82a
\82a
\82r');
397 IgnoreLists.Add('
\83`
\83\83\83b
\83g');
398 IgnoreLists.Add('
\82¨
\8aG
\82©
\82«');
399 IgnoreLists.Add('
\89^
\89c
\88Ä
\93à');
400 IgnoreLists.Add('
\83c
\81[
\83\8b\97Þ');
401 IgnoreLists.Add('
\91¼
\82Ì
\83T
\83C
\83g');
404 IgnoreLists.LoadFromFile(GikoSys.Setting.GetIgnoreFileName);
407 SetIgnoreCategory(true);
412 procedure TNewBoardDialog.EditIgnoreListsButtonClick(Sender: TObject);
414 EditIgnoreList(Sender);
415 EditIgnoreListsButton.OnClick := UpdateIgnoreList;
417 procedure TNewBoardDialog.EditIgnoreList(Sender: TObject);
421 EditIgnoreListsButton.Caption := '
\8f\9c\8aO
\83J
\83e
\83S
\83\8a\81[
\8dX
\90V';
422 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';
423 UpdateButton.Enabled := false;
424 //MessageMemo.ReadOnly := false;
426 for i := 0 to IgnoreLists.Count - 1 do
427 MessageMemo.Lines.Add(IgnoreLists[i]);
429 procedure TNewBoardDialog.UpdateIgnoreList(Sender: TObject);
433 Label2.Caption := '';
434 UpdateButton.Enabled := true;
435 EditIgnoreListsButton.Caption := '
\8f\9c\8aO
\83J
\83e
\83S
\83\8a\81[
\95Ò
\8fW';
437 for i := 0 to MessageMemo.Lines.Count - 1 do
438 IgnoreLists.Add(MessageMemo.Lines[i]);
439 IgnoreLists.SaveToFile(GikoSys.Setting.GetIgnoreFileName);
441 SetIgnoreCategory(false);
442 //MessageMemo.ReadOnly := true;
444 EditIgnoreListsButton.OnClick := EditIgnoreListsButtonClick;
447 procedure TNewBoardDialog.FormClose(Sender: TObject;
448 var Action: TCloseAction);
452 //!
\83\8d\81[
\83J
\83\8b\83t
\83@
\83C
\83\8b\82ð
\83\8d\81[
\83h
\82·
\82é
453 function TNewBoardDialog.BoardLoardFromFile(const FilePath: String): String;
458 //
\83t
\83@
\83C
\83\8b\82ª
\91¶
\8dÝ
\82µ
\82Ä
\82¢
\82é
\82©
\83`
\83F
\83b
\83N
459 if (FileExists(FilePath)) then begin
460 html := TStringList.Create();
462 html.LoadFromFile(FilePath);
470 class procedure TNewBoardDialog.InitHTTPClient(client : TIdHTTP);
472 client.Request.Clear;
473 client.Request.CustomHeaders.Clear;
474 client.RecvBufferSize := Gikosys.Setting.RecvBufferSize;
475 client.ProxyParams.BasicAuthentication := False;
476 if GikoSys.Setting.ReadProxy then begin
477 if GikoSys.Setting.ProxyProtocol then
478 client.ProtocolVersion := pv1_1
480 client.ProtocolVersion := pv1_0;
481 client.ProxyParams.ProxyServer := GikoSys.Setting.ReadProxyAddress;
482 client.ProxyParams.ProxyPort := GikoSys.Setting.ReadProxyPort;
483 client.ProxyParams.ProxyUsername := GikoSys.Setting.ReadProxyUserID;
484 client.ProxyParams.ProxyPassword := GikoSys.Setting.ReadProxyPassword;
485 if GikoSys.Setting.ReadProxyUserID <> '' then
486 client.ProxyParams.BasicAuthentication := True;
488 if GikoSys.Setting.Protocol then
489 client.ProtocolVersion := pv1_1
491 client.ProtocolVersion := pv1_0;
492 client.ProxyParams.ProxyServer := '';
493 client.ProxyParams.ProxyPort := 80;
494 client.ProxyParams.ProxyUsername := '';
495 client.ProxyParams.ProxyPassword := '';