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.3.2.2 - (hide annotations) (download) (as text)
Thu Sep 9 16:20:33 2004 UTC (19 years, 7 months ago) by yoffy
Branch: stable
Changes since 1.3.2.1: +104 -16 lines
File MIME type: text/x-pascal
・ミ・ソ48、ヒ・゙。シ・ク。」

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 yoffy 1.3.2.1 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 yoffy 1.3.2.2 CloseButton: TButton;
22 hi_ 1.1 Indy: TIdHTTP;
23     IdAntiFreeze: TIdAntiFreeze;
24     StopButton: TButton;
25     Label2: TLabel;
26 yoffy 1.3.2.2 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 yoffy 1.3.2.2 procedure EditIgnoreListsButtonClick(Sender: TObject);
34     procedure FormClose(Sender: TObject; var Action: TCloseAction);
35 hi_ 1.1 private
36     { Private ツ静ゥツ固セ }
37 yoffy 1.3.2.2 IgnoreLists : TStringList;
38 hi_ 1.1 FAbort: Boolean;
39     function BoardDownload: TNewBoardItem;
40     procedure UpdateURL(s: string);
41 yoffy 1.3.2.2 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 yoffy 1.3.2.2
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     UpdateURL(Item.FContent);
74     GikoForm.ReloadBBS;
75     end else
76     MessageMemo.Lines.Add('ツダツウツδ督δ債ーツドツで楪篠クツ敗ツてセツづ慊てセツね拏' + IntToStr(Item.FResponseCode) + ']');
77     finally
78     UpdateButton.Enabled := True;
79     StopButton.Enabled := False;
80     CloseButton.Enabled := True;
81     end;
82     end;
83    
84     procedure TNewBoardDialog.StopButtonClick(Sender: TObject);
85     begin
86     FAbort := True;
87     Indy.DisconnectSocket;
88     end;
89    
90     procedure TNewBoardDialog.CloseButtonClick(Sender: TObject);
91     begin
92     Close;
93     end;
94    
95     function TNewBoardDialog.BoardDownload: TNewBoardItem;
96     var
97     URL: string;
98     Stream: TMemoryStream;
99     s: string;
100     i: Integer;
101     begin
102     MessageMemo.Clear;
103     Indy.Request.Clear;
104     Indy.RecvBufferSize := Gikosys.Setting.RecvBufferSize;
105     Indy.ProxyParams.BasicAuthentication := False;
106     if GikoSys.Setting.ReadProxy then begin
107     if GikoSys.Setting.ProxyProtocol then
108     Indy.ProtocolVersion := pv1_1
109     else
110     Indy.ProtocolVersion := pv1_0;
111     Indy.ProxyParams.ProxyServer := GikoSys.Setting.ReadProxyAddress;
112     Indy.ProxyParams.ProxyPort := GikoSys.Setting.ReadProxyPort;
113     Indy.ProxyParams.ProxyUsername := GikoSys.Setting.ReadProxyUserID;
114     Indy.ProxyParams.ProxyPassword := GikoSys.Setting.ReadProxyPassword;
115     if GikoSys.Setting.ReadProxyUserID <> '' then
116     Indy.ProxyParams.BasicAuthentication := True;
117     end else begin
118     if GikoSys.Setting.Protocol then
119     Indy.ProtocolVersion := pv1_1
120     else
121     Indy.ProtocolVersion := pv1_0;
122     Indy.ProxyParams.ProxyServer := '';
123     Indy.ProxyParams.ProxyPort := 80;
124     Indy.ProxyParams.ProxyUsername := '';
125     Indy.ProxyParams.ProxyPassword := '';
126     end;
127 h677 1.3 //URL := GikoSys.Setting.BoardURL2ch;
128     URL := BoardURLComboBox.Text;
129 hi_ 1.1 Indy.Request.UserAgent := GikoSys.GetUserAgent;
130     Indy.Request.Referer := '';
131     Indy.Request.AcceptEncoding := 'gzip';
132    
133     Indy.Request.CacheControl := 'no-cache';
134     Indy.Request.CustomHeaders.Add('Pragma: no-cache');
135    
136     // s := '';
137     Stream := TMemoryStream.Create;
138     try
139     try
140     MessageMemo.Lines.Add('ツ案個嫁淞て堋焼卍渉環で?ツづァツ柴?毒セツてセツづ慊ね?#39;);
141 h677 1.3 //MessageMemo.Lines.Add(GikoSys.Setting.BoardURL2ch);
142     MessageMemo.Lines.Add(URL);
143 hi_ 1.1 MessageMemo.Lines.Add('ツダツウツδ督δ債ーツドツて堕開ツ始ツてセツづ慊ね?#39;);
144     Indy.Get(URL, Stream);
145     Result.FContent := GikoSys.GzipDecompress(Stream, Indy.Response.ContentEncoding);
146     MessageMemo.Lines.Add('ツダツウツδ督δ債ーツドツで楪看スツ稜。ツてセツづ慊てセツね?#39;);
147     except
148     on E: EIdConnectException do begin
149     MessageMemo.Lines.Add('');
150 yoffy 1.2 MessageMemo.Lines.Add('ツ静堋惰?で楪篠クツ敗ツてセツづ慊てセツね ツ嫁?静シツづ「ツプツδ債キツシツ、FWツて堋湘ウツ妥板て堕塚崢づ猟づ?つュツでセツでつね?#39;);
151     MessageMemo.Lines.Add('FWツて堕禿シツて卍づ?ね伉づゥツ人ツづ債静敖墜債て堕確ツ認ツてセツづ?つュツでセツでつね?#39;);
152     MessageMemo.Lines.Add('NECツて啀Cツて堋焼卍債?づ恒C GATEツで楪闇、ツでつて堕てセツづ?ね伉づゥツ嘉つ能ツ税、ツで楪債つね伉てケツね?#39;);
153 hi_ 1.1 MessageMemo.Lines.Add('Message: ' + E.Message);
154     end;
155     on E: Exception do begin
156     if FAbort then
157     MessageMemo.Lines.Add('ツダツウツδ督δ債ーツドツて堕陳?断ツてセツづ慊てセツね?#39;)
158     else begin
159     MessageMemo.Lines.Add('ツダツウツδ督δ債ーツドツで楪篠クツ敗ツてセツづ慊てセツね?#39;);
160     MessageMemo.Lines.Add('ResponseCode: ' + IntToStr(Indy.ResponseCode));
161     MessageMemo.Lines.Add('Message: ' + E.Message);
162     MessageMemo.Lines.Add('------------------------');
163     for i := 0 to Indy.Response.RawHeaders.Count - 1 do begin
164     s := Indy.Response.RawHeaders.Names[i];
165     s := s + ': ' + Indy.Response.RawHeaders.Values[s];
166     MessageMemo.Lines.Add(s);
167     end;
168     MessageMemo.Lines.Add('------------------------');
169     end;
170     end;
171     end;
172     Result.FResponseCode := Indy.ResponseCode;
173     finally
174     Stream.Free;
175     end;
176     end;
177    
178     procedure TNewBoardDialog.UpdateURL(s: string);
179     var
180     i: Integer;
181 yoffy 1.3.2.2 // j: Integer;
182 hi_ 1.1 idx: Integer;
183     idx1: Integer;
184     idx2: Integer;
185     tmp: string;
186     URL: string;
187     Title: string;
188     cate: string;
189     Board: TBoard;
190     Change: Boolean;
191 yoffy 1.3.2.2 Ignore: Boolean;
192 hi_ 1.1 ini: TMemIniFile;
193 yoffy 1.3.2.2 oldURLs : TStringList;
194     newURLs : TStringList;
195 hi_ 1.1 begin
196     Change := False;
197     MessageMemo.Lines.Add('ツ新ツ氾つ、ツ氾6RLツ米篠更ツチツェツッツクツて堕開ツ始ツてセツづ慊ね?#39;);
198     MessageMemo.Lines.Add('');
199 yoffy 1.3.2.1 s := CustomStringReplace(s, '<B>', '<b>', true);
200     s := CustomStringReplace(s, '<BR>', '<br>', true);
201     s := CustomStringReplace(s, '</B>', '</b>', true);
202     s := CustomStringReplace(s, '<A HREF', '<a href', true);
203     s := CustomStringReplace(s, '</A', '</a', true);
204 hi_ 1.1 cate := '';
205 yoffy 1.3.2.1
206 yoffy 1.3.2.2 oldURLs := TStringList.Create;
207     newURLs := TStringList.Create;
208 yoffy 1.3.2.1
209 hi_ 1.1 try
210    
211 yoffy 1.3.2.1 GikoSys.ForceDirectoriesEx(GikoSys.GetConfigDir);
212     ini := TMemIniFile.Create(GikoSys.GetBoardFileName);
213     try
214     //
215     //ツ催ュツ渉慊オツプツシツδ?δ督で楪選ツ惰堕でつて卍づ?ね伉づゥツ焼卍債?づ債クツδ環ア
216    
217     ini.Clear;
218    
219     while True do begin
220     idx1 := AnsiPos('<b>', s);
221     idx2 := AnsiPos('<a', s);
222     if (idx1 = 0) and (idx2 = 0) then Break;
223    
224     if idx1 < idx2 then begin
225     //<br>
226     idx := AnsiPos('</b>', s);
227     if idx = 0 then begin
228     s := Copy(s, idx1 + 4, Length(s));
229     continue;
230     end;
231     tmp := Copy(s, idx1, (idx - idx1) + 4);
232     tmp := CustomStringReplace(tmp, '<b>', '');
233     tmp := CustomStringReplace(tmp, '</b>', '');
234 yoffy 1.3.2.2 Ignore := false;
235     for i := 0 to IgnoreLists.Count - 1 do begin
236     if tmp = Trim(IgnoreLists[i]) then begin
237     cate := '';
238     s := Copy(s, idx + 5, Length(s));
239     Ignore := True;
240     break;
241     end;
242     end;
243     if Ignore then
244     Continue;
245     {
246 yoffy 1.3.2.1 if (tmp = 'ツつィツね?ね?づ?#39;) or
247     (tmp = 'ツ禿?米伉甘ゥツ夏?#39;) or
248     (tmp = 'ツづ慊でシツBツBツS') or
249     (tmp = 'ツチツδδッツト') or
250     (tmp = 'ツつィツ絵ツで?ツで、') or
251     (tmp = 'ツ運ツ営ツ暗?毒?#39;) or
252     (tmp = 'ツツツーツδ仰稜「') or
253     (tmp = 'ツ打コツて堋サツイツト') then begin
254     cate := '';
255     s := Copy(s, idx + 5, Length(s));
256     Continue;
257     end;
258 yoffy 1.3.2.2 }
259 hi_ 1.1 s := Copy(s, idx + 5, Length(s));
260 yoffy 1.3.2.1 cate := tmp;
261 hi_ 1.1 end else begin
262 yoffy 1.3.2.1 //<a href=
263     if cate = '' then begin
264     s := Copy(s, idx2 + 2, Length(s));
265     end else begin
266     idx := AnsiPos('</a>', s);
267     tmp := Copy(s, idx2, (idx - idx2) + 4);
268     tmp := CustomStringReplace(tmp, '<a href=', '');
269     tmp := CustomStringReplace(tmp, '</a>', '');
270     tmp := CustomStringReplace(tmp, 'TARGET=_blank', '');
271     i := AnsiPos('>', tmp);
272     if i <> 0 then begin
273     URL := Copy(tmp, 1, i - 1);
274     Title := Copy(tmp, i + 1, Length(tmp));
275     Board := BBSs[ 0 ].FindBoardFromTitle(Title);
276     if Board = nil then begin
277     MessageMemo.Lines.Add('ツ新ツ氾つ津?嘉?「' + Title + '(' + URL + ')ツ」');
278     ini.WriteString(cate, Title, URL);
279     Change := True;
280     end else begin
281     if Board.URL <> URL then begin
282     MessageMemo.Lines.Add('URLツ米篠更ツ「' + Board.Title + '(' + URL +')ツ」');
283     ini.WriteString(cate, Title, URL);
284     oldURLs.Add(Board.URL);
285     newURLs.Add(URL);
286     Change := True;
287     end else begin
288     ini.WriteString(cate, Title, URL);
289     end;
290     end;
291 hi_ 1.1 end else begin
292 yoffy 1.3.2.1 s := Copy(s, idx2 + 2, Length(s));
293     Continue;
294 hi_ 1.1 end;
295 yoffy 1.3.2.1 s := Copy(s, idx + 5, Length(s));
296 hi_ 1.1 end;
297     end;
298     end;
299 yoffy 1.3.2.1 finally
300     if Change then
301     ini.UpdateFile;
302     ini.Free;
303 hi_ 1.1 end;
304 yoffy 1.3.2.1 MessageMemo.Lines.Add('');
305     if Change then begin
306     GikoForm.FavoritesURLReplace(oldURLs, newURLs);
307     GikoForm.RoundListURLReplace(oldURLs, newURLs);
308 yoffy 1.3.2.2 // GikoForm.TabFileURLReplace(oldURLs, newURLs);
309 yoffy 1.3.2.1 MessageMemo.Lines.Add('ツ新ツ氾つ、ツ氾6RLツ米篠更ツチツェツッツクツで楪看スツ稜。ツてセツづ慊てセツね?#39;);
310     MessageMemo.Lines.Add('ツ「ツ陛つで崢づゥツ」ツボツタツδ督て堕可淞てセツづ?つュツでセツでつね?#39;);
311     end else
312     MessageMemo.Lines.Add('ツ新ツ氾つ、ツ氾6RLツ米篠更ツづ ツつ?ツて債づ慊で。ツで?てケツてセツね?#39;);
313     finally
314     oldURLs.Free;
315     newURLs.Free;
316 yoffy 1.3.2.2 end;
317 hi_ 1.1 end;
318    
319     procedure TNewBoardDialog.FormCreate(Sender: TObject);
320     begin
321     StopButton.Enabled := False;
322 yoffy 1.3.2.2 BoardURLComboBox.Clear;
323     BoardURLComboBox.Items.AddStrings(GikoSys.Setting.BoardURLs);
324     try
325     BoardURLComboBox.ItemIndex := GikoSys.Setting.BoardURLSelected - 1;
326     except
327     BoardURLComboBox.ItemIndex := 0;
328     end;
329     SetIgnoreCategory(false);
330     end;
331     //ツ氾つ更ツ新ツて堋渉慊外ツカツテツゴツδ環δ環スツトツて堋登ツ録
332     {['ツつィツね?ね?づ?#39;, 'ツ禿?米伉甘ゥツ夏?#39;, 'ツづ慊でシツBツBツS', 'ツチツδδッツト', 'ツつィツ絵ツで?ツで、', 'ツ運ツ営ツ暗?毒?#39;, 'ツツツーツδ仰稜「', 'ツ打コツて堋サツイツト']}
333     procedure TNewBoardDialog.SetIgnoreCategory(b: boolean);
334     begin
335     IgnoreLists := TStringList.Create;
336     if not( FileExists(GikoSys.Setting.GetIgnoreFileName) ) or ( b )then begin
337     IgnoreLists.Add('ツつィツね?ね?づ?#39;);
338     IgnoreLists.Add('ツ禿?米伉甘ゥツ夏?#39;);
339     IgnoreLists.Add('ツづ慊でシツBツBツS');
340     IgnoreLists.Add('ツチツδδッツト');
341     IgnoreLists.Add('ツつィツ絵ツで?ツで、');
342     IgnoreLists.Add('ツ運ツ営ツ暗?毒?#39;);
343     IgnoreLists.Add('ツツツーツδ仰稜「');
344     IgnoreLists.Add('ツ打コツて堋サツイツト');
345     end else begin
346     try
347     IgnoreLists.LoadFromFile(GikoSys.Setting.GetIgnoreFileName);
348     except
349     IgnoreLists.Free;
350     SetIgnoreCategory(true);
351     end;
352     end;
353     end;
354    
355     procedure TNewBoardDialog.EditIgnoreListsButtonClick(Sender: TObject);
356     begin
357     EditIgnoreList(Sender);
358     EditIgnoreListsButton.OnClick := UpdateIgnoreList;
359     end;
360     procedure TNewBoardDialog.EditIgnoreList(Sender: TObject);
361     var
362     i: Integer;
363     begin
364     EditIgnoreListsButton.Caption := 'ツ渉慊外ツカツテツゴツδ環ーツ更ツ新';
365     Label2.Caption := 'ツ各ツ1ツ行ツづ可カツテツゴツδ環滅コツて堕記ツ禿シツてセツづ?つュツでセツでつね伉。ツ(ツ嘉シツ行ツづ垢trl+Enterツ)';
366     UpdateButton.Enabled := false;
367     //MessageMemo.ReadOnly := false;
368     MessageMemo.Clear;
369     for i := 0 to IgnoreLists.Count - 1 do
370     MessageMemo.Lines.Add(IgnoreLists[i]);
371     end;
372     procedure TNewBoardDialog.UpdateIgnoreList(Sender: TObject);
373     var
374     i: Integer;
375     begin
376     Label2.Caption := 'ツ?堋固・ツ催敖、ツ開ツね伉づ?ね伉づゥツタツブツづ「ツヒツスツトツδ環て個づ?づ債氾つ更ツ新ツ篠楪づ可クツδ環アツでつて卍づ慊ね?#39;;
377     UpdateButton.Enabled := true;
378     EditIgnoreListsButton.Caption := 'ツ渉慊外ツカツテツゴツδ環ーツ頁?集';
379     IgnoreLists.Clear;
380     for i := 0 to MessageMemo.Lines.Count - 1 do
381     IgnoreLists.Add(MessageMemo.Lines[i]);
382     IgnoreLists.SaveToFile(GikoSys.Setting.GetIgnoreFileName);
383     IgnoreLists.Free;
384     SetIgnoreCategory(false);
385     //MessageMemo.ReadOnly := true;
386     MessageMemo.Clear;
387     EditIgnoreListsButton.OnClick := EditIgnoreListsButtonClick;
388     end;
389    
390     procedure TNewBoardDialog.FormClose(Sender: TObject;
391     var Action: TCloseAction);
392     begin
393     IgnoreLists.Free;
394 hi_ 1.1 end;
395    
396     end.

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