Develop and Download Open Source Software

Browse CVS Repository

Annotation of /gikonavigoeson/gikonavi/NewBoard.pas

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


Revision 1.19 - (hide annotations) (download) (as text)
Mon Jul 18 03:55:14 2005 UTC (18 years, 9 months ago) by h677
Branch: MAIN
CVS Tags: marged-Bb50
Changes since 1.18: +2 -2 lines
File MIME type: text/x-pascal
ハ゛タ50(1.50.1.599)までの変更分をマージ

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

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