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.16 - (hide annotations) (download) (as text)
Mon Oct 25 11:39:50 2004 UTC (19 years, 5 months ago) by h677
Branch: MAIN
CVS Tags: bv1_49_0_563
Changes since 1.15: +1 -0 lines
File MIME type: text/x-pascal
TabFileURLReplaceの修正。板更新したときに、開いているタブを修復するようにしたい。

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

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