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.17 - (hide annotations) (download) (as text)
Fri Nov 5 14:25:48 2004 UTC (19 years, 5 months ago) by h677
Branch: MAIN
CVS Tags: bv1_49_0_564, bv1_49_0_565
Changes since 1.16: +4 -0 lines
File MIME type: text/x-pascal
板更新時にタブが無いときにメッセージを出さないようにした。

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

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