Develop and Download Open Source Software

Browse CVS Repository

Contents of /gikonavigoeson/gikonavi/NewBoard.pas

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.24 - (show annotations) (download) (as text)
Tue Dec 20 15:19:50 2005 UTC (18 years, 4 months ago) by h677
Branch: MAIN
CVS Tags: v1_51_0_634, v1_51_0_633
Changes since 1.23: +0 -1 lines
File MIME type: text/x-pascal
デバッグ出力が残っていたのを削除

1 unit NewBoard;
2
3 interface
4
5 uses
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;
10
11 type
12 TNewBoardItem = record
13 FResponseCode: Integer;
14 FContent: string;
15 end;
16
17 TNewBoardDialog = class(TForm)
18 Label1: TLabel;
19 MessageMemo: TMemo;
20 UpdateButton: TButton;
21 CloseButton: TButton;
22 Indy: TIdHTTP;
23 IdAntiFreeze: TIdAntiFreeze;
24 StopButton: TButton;
25 BoardURLComboBox: TComboBox;
26 Label13: TLabel;
27 EditIgnoreListsButton: TButton;
28 Label2: TLabel;
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);
35 private
36 { Private ?辿?転 }
37 IgnoreLists : TStringList;
38 FAbort: Boolean;
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 public
46 { Public ?辿?転 }
47 end;
48
49 var
50 NewBoardDialog: TNewBoardDialog;
51
52
53 implementation
54
55 uses Giko, IdHeaderList, MojuUtils, GikoDataModule;
56
57 {$R *.dfm}
58
59 procedure TNewBoardDialog.UpdateButtonClick(Sender: TObject);
60 var
61 Item: TNewBoardItem;
62 URL : String;
63 protocol, host, path, document, port, bookmark: String;
64 begin
65 try
66 GikoSys.Setting.BoardURLSelected := BoardURLComboBox.ItemIndex + 1;
67 FAbort := False;
68 UpdateButton.Enabled := False;
69 StopButton.Enabled := True;
70 CloseButton.Enabled := False;
71 EditIgnoreListsButton.Enabled := False;
72 URL := BoardURLComboBox.Text;
73 GikoSys.ParseURI(URL, protocol, host, path, document, port, bookmark);
74 if (protocol = '') then begin
75 Item.FContent := BoardLoardFromFile(URL);
76 end else if (AnsiPos('http', protocol) > 0) then begin
77 Item := BoardDownload(URL);
78 end;
79 StopButton.Enabled := False;
80 if FAbort then
81 Exit;
82 if Item.FContent <> '' then begin
83 GikoDM.TabsSaveAction.Tag := 1;
84 GikoDM.TabsOpenAction.Tag := 1;
85 GikoDM.TabsSaveAction.Execute;
86 if (UpdateURL(Item.FContent)) then begin
87 GikoForm.ReloadBBS;
88 end;
89 GikoDM.TabsSaveAction.Tag := 0;
90 GikoDM.TabsOpenAction.Tag := 0;
91 end else
92 MessageMemo.Lines.Add('?_?E?????[?h???存?s?直???直??[' + IntToStr(Item.FResponseCode) + ']');
93 finally
94 UpdateButton.Enabled := True;
95 StopButton.Enabled := False;
96 CloseButton.Enabled := True;
97 EditIgnoreListsButton.Enabled := True;
98 end;
99 end;
100
101 procedure TNewBoardDialog.StopButtonClick(Sender: TObject);
102 begin
103 FAbort := True;
104 Indy.DisconnectSocket;
105 end;
106
107 procedure TNewBoardDialog.CloseButtonClick(Sender: TObject);
108 begin
109 Close;
110 end;
111
112 function TNewBoardDialog.BoardDownload(const URL: String): TNewBoardItem;
113 var
114 Stream: TMemoryStream;
115 s: string;
116 i: Integer;
117 begin
118 MessageMemo.Clear;
119 Indy.Request.Clear;
120 Indy.RecvBufferSize := Gikosys.Setting.RecvBufferSize;
121 Indy.ProxyParams.BasicAuthentication := False;
122 if GikoSys.Setting.ReadProxy then begin
123 if GikoSys.Setting.ProxyProtocol then
124 Indy.ProtocolVersion := pv1_1
125 else
126 Indy.ProtocolVersion := pv1_0;
127 Indy.ProxyParams.ProxyServer := GikoSys.Setting.ReadProxyAddress;
128 Indy.ProxyParams.ProxyPort := GikoSys.Setting.ReadProxyPort;
129 Indy.ProxyParams.ProxyUsername := GikoSys.Setting.ReadProxyUserID;
130 Indy.ProxyParams.ProxyPassword := GikoSys.Setting.ReadProxyPassword;
131 if GikoSys.Setting.ReadProxyUserID <> '' then
132 Indy.ProxyParams.BasicAuthentication := True;
133 end else begin
134 if GikoSys.Setting.Protocol then
135 Indy.ProtocolVersion := pv1_1
136 else
137 Indy.ProtocolVersion := pv1_0;
138 Indy.ProxyParams.ProxyServer := '';
139 Indy.ProxyParams.ProxyPort := 80;
140 Indy.ProxyParams.ProxyUsername := '';
141 Indy.ProxyParams.ProxyPassword := '';
142 end;
143 //URL := GikoSys.Setting.BoardURL2ch;
144 //URL := BoardURLComboBox.Text;
145 Indy.Request.UserAgent := GikoSys.GetUserAgent;
146 Indy.Request.Referer := '';
147 Indy.Request.AcceptEncoding := 'gzip';
148
149 Indy.Request.CacheControl := 'no-cache';
150 Indy.Request.CustomHeaders.Add('Pragma: no-cache');
151
152 // s := '';
153 Stream := TMemoryStream.Create;
154 try
155 try
156 MessageMemo.Lines.Add('?????????????巽???転?直????');
157 //MessageMemo.Lines.Add(GikoSys.Setting.BoardURL2ch);
158 MessageMemo.Lines.Add(URL);
159 MessageMemo.Lines.Add('?_?E?????[?h???J?n?直????');
160 IdAntiFreeze.Active := True;
161 try
162 Indy.Get(URL, Stream);
163 finally
164 IdAntiFreeze.Active := False;
165 end;
166 Result.FContent := GikoSys.GzipDecompress(Stream, Indy.Response.ContentEncoding);
167 MessageMemo.Lines.Add('?_?E?????[?h???貼?邸?直???直??');
168 except
169 on E: EIdConnectException do begin
170 MessageMemo.Lines.Add('');
171 MessageMemo.Lines.Add('???????存?s?直???直?? ???端?但?v???L?V?AFW???坦???????????足?転????');
172 MessageMemo.Lines.Add('FW???端???????辿?l?????????m?F?直???足?転????');
173 MessageMemo.Lines.Add('NEC??PC????????PC GATE???鼎?????直?????辿???\?鼎???????長??');
174 MessageMemo.Lines.Add('Message: ' + E.Message);
175 end;
176 on E: Exception do begin
177 if FAbort then
178 MessageMemo.Lines.Add('?_?E?????[?h?????f?直???直??')
179 else begin
180 MessageMemo.Lines.Add('?_?E?????[?h???存?s?直???直??');
181 MessageMemo.Lines.Add('ResponseCode: ' + IntToStr(Indy.ResponseCode));
182 MessageMemo.Lines.Add('Message: ' + E.Message);
183 MessageMemo.Lines.Add('------------------------');
184 for i := 0 to Indy.Response.RawHeaders.Count - 1 do begin
185 s := Indy.Response.RawHeaders.Names[i];
186 s := s + ': ' + Indy.Response.RawHeaders.Values[s];
187 MessageMemo.Lines.Add(s);
188 end;
189 MessageMemo.Lines.Add('------------------------');
190 end;
191 end;
192 end;
193 Result.FResponseCode := Indy.ResponseCode;
194 finally
195 Stream.Free;
196 end;
197 end;
198
199 function TNewBoardDialog.UpdateURL(s: string): boolean;
200 var
201 i: Integer;
202 idx: Integer;
203 idx1: Integer;
204 idx2: Integer;
205 tmp: string;
206 URL: string;
207 Title: string;
208 cate: string;
209 Board: TBoard;
210 Change: Boolean;
211 Ignore: Boolean;
212 ini: TMemIniFile;
213 oldURLs : TStringList;
214 newURLs : TStringList;
215 begin
216 Change := False;
217 MessageMemo.Lines.Add('?V???A??URL???X?`?F?b?N???J?n?直????');
218 MessageMemo.Lines.Add('');
219 s := CustomStringReplace(s, '<B>', '<b>', true);
220 s := CustomStringReplace(s, '<BR>', '<br>', true);
221 s := CustomStringReplace(s, '</B>', '</b>', true);
222 s := CustomStringReplace(s, '<A HREF', '<a href', true);
223 s := CustomStringReplace(s, '</A', '</a', true);
224 cate := '';
225
226 oldURLs := TStringList.Create;
227 newURLs := TStringList.Create;
228
229 try
230
231 GikoSys.ForceDirectoriesEx(GikoSys.GetConfigDir);
232 ini := TMemIniFile.Create(GikoSys.GetBoardFileName);
233 try
234 //
235 //?鱈???I?v?V???????I???????????辿???????N???A
236
237 ini.Clear;
238
239 while True do begin
240 idx1 := AnsiPos('<b>', s);
241 idx2 := AnsiPos('<a', s);
242 if (idx1 = 0) and (idx2 = 0) then Break;
243
244 if idx1 < idx2 then begin
245 //<br>
246 idx := AnsiPos('</b>', s);
247 if idx = 0 then begin
248 s := Copy(s, idx1 + 4, Length(s));
249 continue;
250 end;
251 tmp := Copy(s, idx1, (idx - idx1) + 4);
252 tmp := CustomStringReplace(tmp, '<b>', '');
253 tmp := CustomStringReplace(tmp, '</b>', '');
254 Ignore := false;
255 for i := 0 to IgnoreLists.Count - 1 do begin
256 if tmp = Trim(IgnoreLists[i]) then begin
257 cate := '';
258 s := Copy(s, idx + 5, Length(s));
259 Ignore := True;
260 break;
261 end;
262 end;
263 if Ignore then
264 Continue;
265 {
266 if (tmp = '?即??????') or
267 (tmp = '?????辿??') or
268 (tmp = '???甜?a?a?r') or
269 (tmp = '?`???b?g') or
270 (tmp = '?即?G???鼎') or
271 (tmp = '?^?c????') or
272 (tmp = '?c?[???鄭') or
273 (tmp = '?添???T?C?g') then begin
274 cate := '';
275 s := Copy(s, idx + 5, Length(s));
276 Continue;
277 end;
278 }
279 s := Copy(s, idx + 5, Length(s));
280 cate := tmp;
281 end else begin
282 //<a href=
283 if cate = '' then begin
284 s := Copy(s, idx2 + 2, Length(s));
285 end else begin
286 idx := AnsiPos('</a>', s);
287 tmp := Copy(s, idx2, (idx - idx2) + 4);
288 tmp := CustomStringReplace(tmp, '<a href=', '');
289 tmp := CustomStringReplace(tmp, '</a>', '');
290 tmp := CustomStringReplace(tmp, 'TARGET=_blank', '');
291 i := AnsiPos('>', tmp);
292 if i <> 0 then begin
293 URL := Copy(tmp, 1, i - 1);
294 Title := Copy(tmp, i + 1, Length(tmp));
295 Board := BBSs[ 0 ].FindBoardFromTitle(Title);
296 if Board = nil then begin
297 MessageMemo.Lines.Add('?V???????u' + Title + '(' + URL + ')?v');
298 ini.WriteString(cate, Title, URL);
299 Change := True;
300 end else begin
301 if Board.URL <> URL then begin
302 MessageMemo.Lines.Add('URL???X?u' + Board.Title + '(' + URL +')?v');
303 ini.WriteString(cate, Title, URL);
304 oldURLs.Add(Board.URL);
305 newURLs.Add(URL);
306 Change := True;
307 end else begin
308 ini.WriteString(cate, Title, URL);
309 end;
310 end;
311 end else begin
312 s := Copy(s, idx2 + 2, Length(s));
313 Continue;
314 end;
315 s := Copy(s, idx + 5, Length(s));
316 end;
317 end;
318 end;
319 finally
320 if Change then
321 ini.UpdateFile;
322 ini.Free;
323 end;
324 MessageMemo.Lines.Add('');
325 if Change then begin
326 GikoForm.FavoritesURLReplace(oldURLs, newURLs);
327 GikoForm.RoundListURLReplace(oldURLs, newURLs);
328 GikoForm.TabFileURLReplace(oldURLs, newURLs);
329 MessageMemo.Lines.Add('?V???A??URL???X?`?F?b?N???貼?邸?直???直??');
330 MessageMemo.Lines.Add('?u?????辿?v?{?^???????直???足?転????');
331 end else
332 MessageMemo.Lines.Add('?V???A??URL???X?? ???????邸???長?直??');
333 finally
334 oldURLs.Free;
335 newURLs.Free;
336 end;
337 Result := Change;
338 end;
339
340 procedure TNewBoardDialog.FormCreate(Sender: TObject);
341 begin
342 StopButton.Enabled := False;
343 BoardURLComboBox.Clear;
344 BoardURLComboBox.Items.AddStrings(GikoSys.Setting.BoardURLs);
345 try
346 BoardURLComboBox.ItemIndex := GikoSys.Setting.BoardURLSelected - 1;
347 except
348 BoardURLComboBox.ItemIndex := 0;
349 end;
350 SetIgnoreCategory(false);
351 end;
352 //???X?V?????O?J?e?S?????X?g???o?^
353 {['?即??????', '?????辿??', '???甜?a?a?r', '?`???b?g', '?即?G???鼎', '?^?c????', '?c?[???鄭', '?添???T?C?g']}
354 procedure TNewBoardDialog.SetIgnoreCategory(b: boolean);
355 begin
356 IgnoreLists := TStringList.Create;
357 if not( FileExists(GikoSys.Setting.GetIgnoreFileName) ) or ( b )then begin
358 IgnoreLists.Add('?即??????');
359 IgnoreLists.Add('?????辿??');
360 IgnoreLists.Add('???甜?a?a?r');
361 IgnoreLists.Add('?`???b?g');
362 IgnoreLists.Add('?即?G???鼎');
363 IgnoreLists.Add('?^?c????');
364 IgnoreLists.Add('?c?[???鄭');
365 IgnoreLists.Add('?添???T?C?g');
366 end else begin
367 try
368 IgnoreLists.LoadFromFile(GikoSys.Setting.GetIgnoreFileName);
369 except
370 IgnoreLists.Free;
371 SetIgnoreCategory(true);
372 end;
373 end;
374 end;
375
376 procedure TNewBoardDialog.EditIgnoreListsButtonClick(Sender: TObject);
377 begin
378 EditIgnoreList(Sender);
379 EditIgnoreListsButton.OnClick := UpdateIgnoreList;
380 end;
381 procedure TNewBoardDialog.EditIgnoreList(Sender: TObject);
382 var
383 i: Integer;
384 begin
385 EditIgnoreListsButton.Caption := '???O?J?e?S???[?X?V';
386 Label2.Caption := '?e?P?s???J?e?S???添???L?端?直???足?転?????B?i?端?s??Ctrl+Enter?j';
387 UpdateButton.Enabled := false;
388 //MessageMemo.ReadOnly := false;
389 MessageMemo.Clear;
390 for i := 0 to IgnoreLists.Count - 1 do
391 MessageMemo.Lines.Add(IgnoreLists[i]);
392 end;
393 procedure TNewBoardDialog.UpdateIgnoreList(Sender: TObject);
394 var
395 i: Integer;
396 begin
397 Label2.Caption := '';
398 UpdateButton.Enabled := true;
399 EditIgnoreListsButton.Caption := '???O?J?e?S???[???W';
400 IgnoreLists.Clear;
401 for i := 0 to MessageMemo.Lines.Count - 1 do
402 IgnoreLists.Add(MessageMemo.Lines[i]);
403 IgnoreLists.SaveToFile(GikoSys.Setting.GetIgnoreFileName);
404 IgnoreLists.Free;
405 SetIgnoreCategory(false);
406 //MessageMemo.ReadOnly := true;
407 MessageMemo.Clear;
408 EditIgnoreListsButton.OnClick := EditIgnoreListsButtonClick;
409 end;
410
411 procedure TNewBoardDialog.FormClose(Sender: TObject;
412 var Action: TCloseAction);
413 begin
414 IgnoreLists.Free;
415 end;
416 //! ???[?J???t?@?C???????[?h???辿
417 function TNewBoardDialog.BoardLoardFromFile(const FilePath: String): String;
418 var
419 html : TStringList;
420 begin
421 Result := '';
422 // ?t?@?C?????????直?????辿???`?F?b?N
423 if (FileExists(FilePath)) then begin
424 html := TStringList.Create();
425 try
426 html.LoadFromFile(FilePath);
427 Result := html.Text;
428 finally
429 html.Free;
430 end;
431 end;
432 end;
433 end.

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26