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.22 - (hide annotations) (download) (as text)
Sun Nov 20 14:58:02 2005 UTC (18 years, 5 months ago) by h677
Branch: MAIN
CVS Tags: v1_51_0_626, v1_51_0_622, v1_51_0_620, v1_51_0_618, v1_51_0_619, v1_51_0_630, v1_51_0_631, v1_51_0_628, v1_51_0_629, v1_51_0_627, v1_51_0_625, v1_51_0_623, v1_51_0_624, v1_51_0_621
Changes since 1.21: +6 -6 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.21 GikoSystem, BoardGroup;
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.21 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 h677 1.21 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 h677 1.22 uses Giko, IdHeaderList, MojuUtils, GikoDataModule;
55 hi_ 1.1
56     {$R *.dfm}
57    
58     procedure TNewBoardDialog.UpdateButtonClick(Sender: TObject);
59     var
60     Item: TNewBoardItem;
61     begin
62     try
63 h677 1.21 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.22 GikoDM.TabsSaveAction.Tag := 1;
75     GikoDM.TabsOpenAction.Tag := 1;
76     GikoDM.TabsSaveAction.Execute;
77 hi_ 1.1 UpdateURL(Item.FContent);
78     GikoForm.ReloadBBS;
79 h677 1.22 GikoDM.TabsSaveAction.Tag := 0;
80     GikoDM.TabsOpenAction.Tag := 0;
81 hi_ 1.1 end else
82     MessageMemo.Lines.Add('ツダツウツδ督δ債ーツドツで楪篠クツ敗ツてセツづ慊てセツね拏' + 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('ツ案個嫁淞て堋焼卍渉環で?ツづァツ柴?毒セツてセツづ慊ね?#39;);
148 h677 1.3 //MessageMemo.Lines.Add(GikoSys.Setting.BoardURL2ch);
149 h677 1.20 MessageMemo.Lines.Add(URL);
150 hi_ 1.1 MessageMemo.Lines.Add('ツダツウツδ督δ債ーツドツて堕開ツ始ツてセツづ慊ね?#39;);
151 h677 1.20 IdAntiFreeze.Active := True;
152     try
153     Indy.Get(URL, Stream);
154     finally
155     IdAntiFreeze.Active := False;
156     end;
157 hi_ 1.1 Result.FContent := GikoSys.GzipDecompress(Stream, Indy.Response.ContentEncoding);
158     MessageMemo.Lines.Add('ツダツウツδ督δ債ーツドツで楪看スツ稜。ツてセツづ慊てセツね?#39;);
159     except
160     on E: EIdConnectException do begin
161     MessageMemo.Lines.Add('');
162 yoffy 1.2 MessageMemo.Lines.Add('ツ静堋惰?で楪篠クツ敗ツてセツづ慊てセツね ツ嫁?静シツづ「ツプツδ債キツシツ、FWツて堋湘ウツ妥板て堕塚崢づ猟づ?つュツでセツでつね?#39;);
163     MessageMemo.Lines.Add('FWツて堕禿シツて卍づ?ね伉づゥツ人ツづ債静敖墜債て堕確ツ認ツてセツづ?つュツでセツでつね?#39;);
164     MessageMemo.Lines.Add('NECツて啀Cツて堋焼卍債?づ恒C GATEツで楪闇、ツでつて堕てセツづ?ね伉づゥツ嘉つ能ツ税、ツで楪債つね伉てケツね?#39;);
165 hi_ 1.1 MessageMemo.Lines.Add('Message: ' + E.Message);
166     end;
167     on E: Exception do begin
168     if FAbort then
169     MessageMemo.Lines.Add('ツダツウツδ督δ債ーツドツて堕陳?断ツてセツづ慊てセツね?#39;)
170     else begin
171     MessageMemo.Lines.Add('ツダツウツδ督δ債ーツドツで楪篠クツ敗ツてセツづ慊てセツね?#39;);
172     MessageMemo.Lines.Add('ResponseCode: ' + IntToStr(Indy.ResponseCode));
173     MessageMemo.Lines.Add('Message: ' + E.Message);
174     MessageMemo.Lines.Add('------------------------');
175     for i := 0 to Indy.Response.RawHeaders.Count - 1 do begin
176     s := Indy.Response.RawHeaders.Names[i];
177     s := s + ': ' + Indy.Response.RawHeaders.Values[s];
178     MessageMemo.Lines.Add(s);
179     end;
180     MessageMemo.Lines.Add('------------------------');
181     end;
182     end;
183     end;
184     Result.FResponseCode := Indy.ResponseCode;
185     finally
186     Stream.Free;
187     end;
188     end;
189    
190     procedure TNewBoardDialog.UpdateURL(s: string);
191     var
192     i: Integer;
193 h677 1.13 // j: Integer;
194 hi_ 1.1 idx: Integer;
195     idx1: Integer;
196     idx2: Integer;
197     tmp: string;
198     URL: string;
199     Title: string;
200     cate: string;
201     Board: TBoard;
202     Change: Boolean;
203 h677 1.12 Ignore: Boolean;
204 hi_ 1.1 ini: TMemIniFile;
205 h677 1.12 oldURLs : TStringList;
206     newURLs : TStringList;
207 hi_ 1.1 begin
208     Change := False;
209     MessageMemo.Lines.Add('ツ新ツ氾つ、ツ氾6RLツ米篠更ツチツェツッツクツて堕開ツ始ツてセツづ慊ね?#39;);
210     MessageMemo.Lines.Add('');
211 h677 1.6 s := CustomStringReplace(s, '<B>', '<b>', true);
212     s := CustomStringReplace(s, '<BR>', '<br>', true);
213     s := CustomStringReplace(s, '</B>', '</b>', true);
214     s := CustomStringReplace(s, '<A HREF', '<a href', true);
215     s := CustomStringReplace(s, '</A', '</a', true);
216 hi_ 1.1 cate := '';
217 h677 1.6
218 h677 1.12 oldURLs := TStringList.Create;
219     newURLs := TStringList.Create;
220 h677 1.6
221 hi_ 1.1 try
222    
223 h677 1.6 GikoSys.ForceDirectoriesEx(GikoSys.GetConfigDir);
224     ini := TMemIniFile.Create(GikoSys.GetBoardFileName);
225     try
226     //
227     //ツ催ュツ渉慊オツプツシツδ?δ督で楪選ツ惰堕でつて卍づ?ね伉づゥツ焼卍債?づ債クツδ環ア
228    
229     ini.Clear;
230    
231     while True do begin
232     idx1 := AnsiPos('<b>', s);
233     idx2 := AnsiPos('<a', s);
234     if (idx1 = 0) and (idx2 = 0) then Break;
235    
236     if idx1 < idx2 then begin
237     //<br>
238     idx := AnsiPos('</b>', s);
239     if idx = 0 then begin
240     s := Copy(s, idx1 + 4, Length(s));
241     continue;
242     end;
243     tmp := Copy(s, idx1, (idx - idx1) + 4);
244     tmp := CustomStringReplace(tmp, '<b>', '');
245     tmp := CustomStringReplace(tmp, '</b>', '');
246 h677 1.12 Ignore := false;
247     for i := 0 to IgnoreLists.Count - 1 do begin
248     if tmp = Trim(IgnoreLists[i]) then begin
249     cate := '';
250     s := Copy(s, idx + 5, Length(s));
251     Ignore := True;
252     break;
253     end;
254     end;
255     if Ignore then
256     Continue;
257     {
258 h677 1.6 if (tmp = 'ツつィツね?ね?づ?#39;) or
259     (tmp = 'ツ禿?米伉甘ゥツ夏?#39;) or
260 h677 1.8 (tmp = 'ツづ慊でシツBツBツS') or
261 h677 1.6 (tmp = 'ツチツδδッツト') or
262     (tmp = 'ツつィツ絵ツで?ツで、') or
263 h677 1.9 (tmp = 'ツ運ツ営ツ暗?毒?#39;) or
264 h677 1.6 (tmp = 'ツツツーツδ仰稜「') or
265     (tmp = 'ツ打コツて堋サツイツト') then begin
266     cate := '';
267     s := Copy(s, idx + 5, Length(s));
268     Continue;
269     end;
270 h677 1.12 }
271 hi_ 1.1 s := Copy(s, idx + 5, Length(s));
272 h677 1.6 cate := tmp;
273 hi_ 1.1 end else begin
274 h677 1.6 //<a href=
275     if cate = '' then begin
276     s := Copy(s, idx2 + 2, Length(s));
277     end else begin
278     idx := AnsiPos('</a>', s);
279     tmp := Copy(s, idx2, (idx - idx2) + 4);
280     tmp := CustomStringReplace(tmp, '<a href=', '');
281     tmp := CustomStringReplace(tmp, '</a>', '');
282 h677 1.7 tmp := CustomStringReplace(tmp, 'TARGET=_blank', '');
283 h677 1.6 i := AnsiPos('>', tmp);
284     if i <> 0 then begin
285     URL := Copy(tmp, 1, i - 1);
286     Title := Copy(tmp, i + 1, Length(tmp));
287 h677 1.8 Board := BBSs[ 0 ].FindBoardFromTitle(Title);
288     if Board = nil then begin
289     MessageMemo.Lines.Add('ツ新ツ氾つ津?嘉?「' + Title + '(' + URL + ')ツ」');
290     ini.WriteString(cate, Title, URL);
291     Change := True;
292     end else begin
293     if Board.URL <> URL then begin
294     MessageMemo.Lines.Add('URLツ米篠更ツ「' + Board.Title + '(' + URL +')ツ」');
295     ini.WriteString(cate, Title, URL);
296 h677 1.6 oldURLs.Add(Board.URL);
297 h677 1.8 newURLs.Add(URL);
298     Change := True;
299     end else begin
300     ini.WriteString(cate, Title, URL);
301     end;
302     end;
303 h677 1.6 end else begin
304     s := Copy(s, idx2 + 2, Length(s));
305     Continue;
306 hi_ 1.1 end;
307 h677 1.6 s := Copy(s, idx + 5, Length(s));
308 hi_ 1.1 end;
309     end;
310     end;
311 h677 1.6 finally
312     if Change then
313     ini.UpdateFile;
314     ini.Free;
315 hi_ 1.1 end;
316 h677 1.6 MessageMemo.Lines.Add('');
317     if Change then begin
318     GikoForm.FavoritesURLReplace(oldURLs, newURLs);
319 h677 1.11 GikoForm.RoundListURLReplace(oldURLs, newURLs);
320 genyakun 1.15 GikoForm.TabFileURLReplace(oldURLs, newURLs);
321 h677 1.6 MessageMemo.Lines.Add('ツ新ツ氾つ、ツ氾6RLツ米篠更ツチツェツッツクツで楪看スツ稜。ツてセツづ慊てセツね?#39;);
322     MessageMemo.Lines.Add('ツ「ツ陛つで崢づゥツ」ツボツタツδ督て堕可淞てセツづ?つュツでセツでつね?#39;);
323     end else
324     MessageMemo.Lines.Add('ツ新ツ氾つ、ツ氾6RLツ米篠更ツづ ツつ?ツて債づ慊で。ツで?てケツてセツね?#39;);
325     finally
326     oldURLs.Free;
327     newURLs.Free;
328 h677 1.12 end;
329 hi_ 1.1 end;
330    
331     procedure TNewBoardDialog.FormCreate(Sender: TObject);
332     begin
333     StopButton.Enabled := False;
334 h677 1.12 BoardURLComboBox.Clear;
335     BoardURLComboBox.Items.AddStrings(GikoSys.Setting.BoardURLs);
336     try
337     BoardURLComboBox.ItemIndex := GikoSys.Setting.BoardURLSelected - 1;
338     except
339     BoardURLComboBox.ItemIndex := 0;
340     end;
341     SetIgnoreCategory(false);
342     end;
343     //ツ氾つ更ツ新ツて堋渉慊外ツカツテツゴツδ環δ環スツトツて堋登ツ録
344     {['ツつィツね?ね?づ?#39;, 'ツ禿?米伉甘ゥツ夏?#39;, 'ツづ慊でシツBツBツS', 'ツチツδδッツト', 'ツつィツ絵ツで?ツで、', 'ツ運ツ営ツ暗?毒?#39;, 'ツツツーツδ仰稜「', 'ツ打コツて堋サツイツト']}
345     procedure TNewBoardDialog.SetIgnoreCategory(b: boolean);
346     begin
347     IgnoreLists := TStringList.Create;
348     if not( FileExists(GikoSys.Setting.GetIgnoreFileName) ) or ( b )then begin
349     IgnoreLists.Add('ツつィツね?ね?づ?#39;);
350     IgnoreLists.Add('ツ禿?米伉甘ゥツ夏?#39;);
351     IgnoreLists.Add('ツづ慊でシツBツBツS');
352     IgnoreLists.Add('ツチツδδッツト');
353     IgnoreLists.Add('ツつィツ絵ツで?ツで、');
354     IgnoreLists.Add('ツ運ツ営ツ暗?毒?#39;);
355     IgnoreLists.Add('ツツツーツδ仰稜「');
356     IgnoreLists.Add('ツ打コツて堋サツイツト');
357     end else begin
358     try
359     IgnoreLists.LoadFromFile(GikoSys.Setting.GetIgnoreFileName);
360     except
361     IgnoreLists.Free;
362     SetIgnoreCategory(true);
363     end;
364     end;
365     end;
366    
367     procedure TNewBoardDialog.EditIgnoreListsButtonClick(Sender: TObject);
368     begin
369     EditIgnoreList(Sender);
370     EditIgnoreListsButton.OnClick := UpdateIgnoreList;
371     end;
372     procedure TNewBoardDialog.EditIgnoreList(Sender: TObject);
373     var
374     i: Integer;
375     begin
376     EditIgnoreListsButton.Caption := 'ツ渉慊外ツカツテツゴツδ環ーツ更ツ新';
377     Label2.Caption := 'ツ各ツ1ツ行ツづ可カツテツゴツδ環滅コツて堕記ツ禿シツてセツづ?つュツでセツでつね伉。ツ(ツ嘉シツ行ツづ垢trl+Enterツ)';
378     UpdateButton.Enabled := false;
379     //MessageMemo.ReadOnly := false;
380     MessageMemo.Clear;
381     for i := 0 to IgnoreLists.Count - 1 do
382     MessageMemo.Lines.Add(IgnoreLists[i]);
383     end;
384     procedure TNewBoardDialog.UpdateIgnoreList(Sender: TObject);
385     var
386     i: Integer;
387     begin
388 h677 1.19 Label2.Caption := '';
389 h677 1.12 UpdateButton.Enabled := true;
390     EditIgnoreListsButton.Caption := 'ツ渉慊外ツカツテツゴツδ環ーツ頁?集';
391     IgnoreLists.Clear;
392     for i := 0 to MessageMemo.Lines.Count - 1 do
393     IgnoreLists.Add(MessageMemo.Lines[i]);
394     IgnoreLists.SaveToFile(GikoSys.Setting.GetIgnoreFileName);
395     IgnoreLists.Free;
396     SetIgnoreCategory(false);
397     //MessageMemo.ReadOnly := true;
398     MessageMemo.Clear;
399     EditIgnoreListsButton.OnClick := EditIgnoreListsButtonClick;
400     end;
401    
402     procedure TNewBoardDialog.FormClose(Sender: TObject;
403     var Action: TCloseAction);
404     begin
405     IgnoreLists.Free;
406 hi_ 1.1 end;
407    
408     end.

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