| 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 |
GikoSystem, BoardGroup; |
| 10 |
|
| 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 |
CloseButton: TButton; |
| 22 |
Indy: TIdHTTP; |
| 23 |
IdAntiFreeze: TIdAntiFreeze; |
| 24 |
StopButton: TButton; |
| 25 |
Label2: TLabel; |
| 26 |
BoardURLComboBox: TComboBox; |
| 27 |
Label13: TLabel; |
| 28 |
procedure UpdateButtonClick(Sender: TObject); |
| 29 |
procedure StopButtonClick(Sender: TObject); |
| 30 |
procedure CloseButtonClick(Sender: TObject); |
| 31 |
procedure FormCreate(Sender: TObject); |
| 32 |
private |
| 33 |
{ Private ?辿?転 } |
| 34 |
FAbort: Boolean; |
| 35 |
function BoardDownload: TNewBoardItem; |
| 36 |
procedure UpdateURL(s: string); |
| 37 |
public |
| 38 |
{ Public ?辿?転 } |
| 39 |
end; |
| 40 |
|
| 41 |
var |
| 42 |
NewBoardDialog: TNewBoardDialog; |
| 43 |
|
| 44 |
implementation |
| 45 |
|
| 46 |
uses Giko, IdHeaderList; |
| 47 |
|
| 48 |
{$R *.dfm} |
| 49 |
|
| 50 |
procedure TNewBoardDialog.UpdateButtonClick(Sender: TObject); |
| 51 |
var |
| 52 |
Item: TNewBoardItem; |
| 53 |
begin |
| 54 |
try |
| 55 |
GikoSys.Setting.BoardURLSelected := BoardURLComboBox.ItemIndex + 1; |
| 56 |
FAbort := False; |
| 57 |
UpdateButton.Enabled := False; |
| 58 |
StopButton.Enabled := True; |
| 59 |
CloseButton.Enabled := False; |
| 60 |
Item := BoardDownload; |
| 61 |
StopButton.Enabled := False; |
| 62 |
if FAbort then |
| 63 |
Exit; |
| 64 |
if Item.FContent <> '' then begin |
| 65 |
UpdateURL(Item.FContent); |
| 66 |
GikoForm.ReloadBBS; |
| 67 |
end else |
| 68 |
MessageMemo.Lines.Add('?_?E?????[?h???存?s?直???直??[' + IntToStr(Item.FResponseCode) + ']'); |
| 69 |
finally |
| 70 |
UpdateButton.Enabled := True; |
| 71 |
StopButton.Enabled := False; |
| 72 |
CloseButton.Enabled := True; |
| 73 |
end; |
| 74 |
end; |
| 75 |
|
| 76 |
procedure TNewBoardDialog.StopButtonClick(Sender: TObject); |
| 77 |
begin |
| 78 |
FAbort := True; |
| 79 |
Indy.DisconnectSocket; |
| 80 |
end; |
| 81 |
|
| 82 |
procedure TNewBoardDialog.CloseButtonClick(Sender: TObject); |
| 83 |
begin |
| 84 |
Close; |
| 85 |
end; |
| 86 |
|
| 87 |
function TNewBoardDialog.BoardDownload: TNewBoardItem; |
| 88 |
var |
| 89 |
URL: string; |
| 90 |
Stream: TMemoryStream; |
| 91 |
s: string; |
| 92 |
i: Integer; |
| 93 |
begin |
| 94 |
MessageMemo.Clear; |
| 95 |
Indy.Request.Clear; |
| 96 |
Indy.RecvBufferSize := Gikosys.Setting.RecvBufferSize; |
| 97 |
Indy.ProxyParams.BasicAuthentication := False; |
| 98 |
if GikoSys.Setting.ReadProxy then begin |
| 99 |
if GikoSys.Setting.ProxyProtocol then |
| 100 |
Indy.ProtocolVersion := pv1_1 |
| 101 |
else |
| 102 |
Indy.ProtocolVersion := pv1_0; |
| 103 |
Indy.ProxyParams.ProxyServer := GikoSys.Setting.ReadProxyAddress; |
| 104 |
Indy.ProxyParams.ProxyPort := GikoSys.Setting.ReadProxyPort; |
| 105 |
Indy.ProxyParams.ProxyUsername := GikoSys.Setting.ReadProxyUserID; |
| 106 |
Indy.ProxyParams.ProxyPassword := GikoSys.Setting.ReadProxyPassword; |
| 107 |
if GikoSys.Setting.ReadProxyUserID <> '' then |
| 108 |
Indy.ProxyParams.BasicAuthentication := True; |
| 109 |
end else begin |
| 110 |
if GikoSys.Setting.Protocol then |
| 111 |
Indy.ProtocolVersion := pv1_1 |
| 112 |
else |
| 113 |
Indy.ProtocolVersion := pv1_0; |
| 114 |
Indy.ProxyParams.ProxyServer := ''; |
| 115 |
Indy.ProxyParams.ProxyPort := 80; |
| 116 |
Indy.ProxyParams.ProxyUsername := ''; |
| 117 |
Indy.ProxyParams.ProxyPassword := ''; |
| 118 |
end; |
| 119 |
//URL := GikoSys.Setting.BoardURL2ch; |
| 120 |
URL := BoardURLComboBox.Text; |
| 121 |
Indy.Request.UserAgent := GikoSys.GetUserAgent; |
| 122 |
Indy.Request.Referer := ''; |
| 123 |
Indy.Request.AcceptEncoding := 'gzip'; |
| 124 |
|
| 125 |
Indy.Request.CacheControl := 'no-cache'; |
| 126 |
Indy.Request.CustomHeaders.Add('Pragma: no-cache'); |
| 127 |
|
| 128 |
// s := ''; |
| 129 |
Stream := TMemoryStream.Create; |
| 130 |
try |
| 131 |
try |
| 132 |
MessageMemo.Lines.Add('?????????????巽???転?直????'); |
| 133 |
//MessageMemo.Lines.Add(GikoSys.Setting.BoardURL2ch); |
| 134 |
MessageMemo.Lines.Add(URL); |
| 135 |
MessageMemo.Lines.Add('?_?E?????[?h???J?n?直????'); |
| 136 |
Indy.Get(URL, Stream); |
| 137 |
Result.FContent := GikoSys.GzipDecompress(Stream, Indy.Response.ContentEncoding); |
| 138 |
MessageMemo.Lines.Add('?_?E?????[?h???貼?邸?直???直??'); |
| 139 |
except |
| 140 |
on E: EIdConnectException do begin |
| 141 |
MessageMemo.Lines.Add(''); |
| 142 |
MessageMemo.Lines.Add('???????存?s?直???直?? ???端?但?v???L?V?AFW???坦???????????足?転????'); |
| 143 |
MessageMemo.Lines.Add('FW???端???????辿?l?????????m?F?直???足?転????'); |
| 144 |
MessageMemo.Lines.Add('NEC??PC????????PC GATE???鼎?????直?????辿???\?鼎???????長??'); |
| 145 |
MessageMemo.Lines.Add('Message: ' + E.Message); |
| 146 |
end; |
| 147 |
on E: Exception do begin |
| 148 |
if FAbort then |
| 149 |
MessageMemo.Lines.Add('?_?E?????[?h?????f?直???直??') |
| 150 |
else begin |
| 151 |
MessageMemo.Lines.Add('?_?E?????[?h???存?s?直???直??'); |
| 152 |
MessageMemo.Lines.Add('ResponseCode: ' + IntToStr(Indy.ResponseCode)); |
| 153 |
MessageMemo.Lines.Add('Message: ' + E.Message); |
| 154 |
MessageMemo.Lines.Add('------------------------'); |
| 155 |
for i := 0 to Indy.Response.RawHeaders.Count - 1 do begin |
| 156 |
s := Indy.Response.RawHeaders.Names[i]; |
| 157 |
s := s + ': ' + Indy.Response.RawHeaders.Values[s]; |
| 158 |
MessageMemo.Lines.Add(s); |
| 159 |
end; |
| 160 |
MessageMemo.Lines.Add('------------------------'); |
| 161 |
end; |
| 162 |
end; |
| 163 |
end; |
| 164 |
Result.FResponseCode := Indy.ResponseCode; |
| 165 |
finally |
| 166 |
Stream.Free; |
| 167 |
end; |
| 168 |
end; |
| 169 |
|
| 170 |
procedure TNewBoardDialog.UpdateURL(s: string); |
| 171 |
var |
| 172 |
i: Integer; |
| 173 |
idx: Integer; |
| 174 |
idx1: Integer; |
| 175 |
idx2: Integer; |
| 176 |
tmp: string; |
| 177 |
URL: string; |
| 178 |
Title: string; |
| 179 |
cate: string; |
| 180 |
Board: TBoard; |
| 181 |
Change: Boolean; |
| 182 |
ini: TMemIniFile; |
| 183 |
begin |
| 184 |
Change := False; |
| 185 |
MessageMemo.Lines.Add('?V???A??URL???X?`?F?b?N???J?n?直????'); |
| 186 |
MessageMemo.Lines.Add(''); |
| 187 |
s := StringReplace(s, '<B>', '<b>', [rfReplaceAll, rfIgnoreCase]); |
| 188 |
s := StringReplace(s, '<BR>', '<br>', [rfReplaceAll, rfIgnoreCase]); |
| 189 |
s := StringReplace(s, '</B>', '</b>', [rfReplaceAll, rfIgnoreCase]); |
| 190 |
s := StringReplace(s, '<A HREF', '<a href', [rfReplaceAll, rfIgnoreCase]); |
| 191 |
s := StringReplace(s, '</A', '</a', [rfReplaceAll, rfIgnoreCase]); |
| 192 |
cate := ''; |
| 193 |
GikoSys.ForceDirectoriesEx(GikoSys.GetConfigDir); |
| 194 |
ini := TMemIniFile.Create(GikoSys.GetBoardFileName); |
| 195 |
try |
| 196 |
// |
| 197 |
//?鱈???I?v?V???????I???????????辿???????N???A |
| 198 |
|
| 199 |
ini.Clear; |
| 200 |
while True do begin |
| 201 |
idx1 := AnsiPos('<b>', s); |
| 202 |
idx2 := AnsiPos('<a', s); |
| 203 |
if (idx1 = 0) and (idx2 = 0) then Break; |
| 204 |
|
| 205 |
if idx1 < idx2 then begin |
| 206 |
//<br> |
| 207 |
idx := AnsiPos('</b>', s); |
| 208 |
if idx = 0 then begin |
| 209 |
s := Copy(s, idx1 + 4, Length(s)); |
| 210 |
continue; |
| 211 |
end; |
| 212 |
tmp := Copy(s, idx1, (idx - idx1) + 4); |
| 213 |
tmp := StringReplace(tmp, '<b>', '', [rfReplaceAll]); |
| 214 |
tmp := StringReplace(tmp, '</b>', '', [rfReplaceAll]); |
| 215 |
|
| 216 |
if (tmp = '?即??????') or |
| 217 |
(tmp = '?????辿??') or |
| 218 |
(tmp = '???甜?a?a?r') or |
| 219 |
(tmp = '?`???b?g') or |
| 220 |
(tmp = '?即?G???鼎') or |
| 221 |
(tmp = '?^?c') or |
| 222 |
(tmp = '?c?[???鄭') or |
| 223 |
(tmp = '?添???T?C?g') then begin |
| 224 |
cate := ''; |
| 225 |
s := Copy(s, idx + 5, Length(s)); |
| 226 |
Continue; |
| 227 |
end; |
| 228 |
s := Copy(s, idx + 5, Length(s)); |
| 229 |
cate := tmp; |
| 230 |
end else begin |
| 231 |
//<a href= |
| 232 |
if cate = '' then begin |
| 233 |
s := Copy(s, idx2 + 2, Length(s)); |
| 234 |
end else begin |
| 235 |
idx := AnsiPos('</a>', s); |
| 236 |
tmp := Copy(s, idx2, (idx - idx2) + 4); |
| 237 |
tmp := StringReplace(tmp, '<a href=', '', [rfReplaceAll]); |
| 238 |
tmp := StringReplace(tmp, '</a>', '', [rfReplaceAll]); |
| 239 |
i := AnsiPos('>', tmp); |
| 240 |
if i <> 0 then begin |
| 241 |
URL := Copy(tmp, 1, i - 1); |
| 242 |
Title := Copy(tmp, i + 1, Length(tmp)); |
| 243 |
Board := BBS2ch.FindBoardFromTitle(Title); |
| 244 |
if Board = nil then begin |
| 245 |
MessageMemo.Lines.Add('?V???????u' + Title + '(' + URL + ')?v'); |
| 246 |
ini.WriteString(cate, Title, URL); |
| 247 |
Change := True; |
| 248 |
end else begin |
| 249 |
if Board.URL <> URL then begin |
| 250 |
MessageMemo.Lines.Add('URL???X?u' + Board.Title + '(' + URL +')?v'); |
| 251 |
ini.WriteString(cate, Title, URL); |
| 252 |
Change := True; |
| 253 |
end else begin |
| 254 |
ini.WriteString(cate, Title, URL); |
| 255 |
end; |
| 256 |
end; |
| 257 |
end else begin |
| 258 |
s := Copy(s, idx2 + 2, Length(s)); |
| 259 |
Continue; |
| 260 |
end; |
| 261 |
s := Copy(s, idx + 5, Length(s)); |
| 262 |
end; |
| 263 |
end; |
| 264 |
end; |
| 265 |
finally |
| 266 |
if Change then |
| 267 |
ini.UpdateFile; |
| 268 |
ini.Free; |
| 269 |
end; |
| 270 |
MessageMemo.Lines.Add(''); |
| 271 |
if Change then begin |
| 272 |
MessageMemo.Lines.Add('?V???A??URL???X?`?F?b?N???貼?邸?直???直??'); |
| 273 |
MessageMemo.Lines.Add('?u?????辿?v?{?^???????直???足?転????'); |
| 274 |
end else |
| 275 |
MessageMemo.Lines.Add('?V???A??URL???X?? ???????邸???長?直??'); |
| 276 |
end; |
| 277 |
|
| 278 |
procedure TNewBoardDialog.FormCreate(Sender: TObject); |
| 279 |
begin |
| 280 |
StopButton.Enabled := False; |
| 281 |
BoardURLComboBox.Clear; |
| 282 |
BoardURLComboBox.Items.AddStrings(GikoSys.Setting.BoardURLs); |
| 283 |
try |
| 284 |
BoardURLComboBox.ItemIndex := GikoSys.Setting.BoardURLSelected - 1; |
| 285 |
except |
| 286 |
BoardURLComboBox.ItemIndex := 0; |
| 287 |
end; |
| 288 |
end; |
| 289 |
|
| 290 |
end. |