| 60 |
inFileName : PChar // スレッドファイル名 |
inFileName : PChar // スレッドファイル名 |
| 61 |
) : PChar; stdcall; // スレッドの URL |
) : PChar; stdcall; // スレッドの URL |
| 62 |
|
|
| 63 |
|
|
| 64 |
function CreateResultString( |
function CreateResultString( |
| 65 |
resultStr : string |
resultStr : string |
| 66 |
) : PChar; stdcall; |
) : PChar; stdcall; |
| 69 |
resultStr : PChar |
resultStr : PChar |
| 70 |
); stdcall; |
); stdcall; |
| 71 |
|
|
| 72 |
|
var |
| 73 |
|
socket : TIdHTTP; |
| 74 |
|
|
| 75 |
implementation |
implementation |
| 76 |
|
|
| 77 |
uses ExternalBoardManager, ExternalThreadItem, GikoSystem, BoardGroup, Giko; |
uses ExternalBoardManager, ExternalThreadItem, GikoSystem, BoardGroup, Giko; |
| 226 |
inRangeEnd : DWORD // 終了位置 |
inRangeEnd : DWORD // 終了位置 |
| 227 |
) : Longint; stdcall; // レスポンスコード |
) : Longint; stdcall; // レスポンスコード |
| 228 |
var |
var |
| 229 |
httpSocket : TIdHTTP; |
// httpSocket : TIdHTTP; |
| 230 |
resStream : TMemoryStream; |
resStream : TMemoryStream; |
| 231 |
content : string; |
content : string; |
| 232 |
begin |
begin |
| 234 |
{$IFDEF DEBUG} |
{$IFDEF DEBUG} |
| 235 |
Writeln('ExternalBoardManager.InternalDownload'); |
Writeln('ExternalBoardManager.InternalDownload'); |
| 236 |
{$ENDIF} |
{$ENDIF} |
| 237 |
Result := -1; |
// Result := -1; |
| 238 |
|
|
| 239 |
httpSocket := TIdHTTP.Create( nil ); |
socket := TIdHTTP.Create( nil ); |
| 240 |
try |
try |
| 241 |
InitializeSocket( httpSocket ); |
InitializeSocket( socket ); |
| 242 |
|
|
| 243 |
httpSocket.Request.ContentRangeStart := inRangeStart; |
socket.Request.ContentRangeStart := inRangeStart; |
| 244 |
httpSocket.Request.ContentRangeEnd := inRangeEnd; |
socket.Request.ContentRangeEnd := inRangeEnd; |
| 245 |
if (ioModified <> 0) and (ioModified <> ZERO_DATE) then |
if (ioModified <> 0) and (ioModified <> ZERO_DATE) then |
| 246 |
httpSocket.Request.LastModified := ioModified - OffsetFromUTC; |
socket.Request.LastModified := ioModified - OffsetFromUTC; |
| 247 |
if inRangeStart = 0 then |
if inRangeStart = 0 then |
| 248 |
httpSocket.Request.AcceptEncoding := 'gzip' |
socket.Request.AcceptEncoding := 'gzip' |
| 249 |
else |
else |
| 250 |
httpSocket.Request.AcceptEncoding := ''; |
socket.Request.AcceptEncoding := ''; |
| 251 |
httpSocket.Request.Accept := 'text/html'; |
socket.Request.Accept := 'text/html'; |
| 252 |
|
|
| 253 |
resStream := TMemoryStream.Create; |
resStream := TMemoryStream.Create; |
| 254 |
try |
try |
| 255 |
try |
try |
| 256 |
resStream.Clear; |
resStream.Clear; |
|
|
|
| 257 |
{$IFDEF DEBUG} |
{$IFDEF DEBUG} |
| 258 |
Writeln('URL: ' + inURL); |
Writeln('URL: ' + inURL); |
| 259 |
{$ENDIF} |
{$ENDIF} |
| 260 |
httpSocket.Get( inURL, resStream ); |
socket.Get( inURL, resStream ); |
| 261 |
{$IFDEF DEBUG} |
{$IFDEF DEBUG} |
| 262 |
Writeln('取得で例外なし'); |
Writeln('取得で例外なし'); |
| 263 |
{$ENDIF} |
{$ENDIF} |
| 264 |
|
|
| 265 |
content := GikoSys.GzipDecompress( resStream, httpSocket.Response.ContentEncoding ); |
content := GikoSys.GzipDecompress( resStream, socket.Response.ContentEncoding ); |
|
ioModified := httpSocket.Response.LastModified; |
|
| 266 |
|
|
| 267 |
Result := httpSocket.ResponseCode; |
ioModified := socket.Response.LastModified; |
| 268 |
|
|
| 269 |
|
Result := socket.ResponseCode; |
| 270 |
if (Length( content ) = 0) and (Result = 206) then |
if (Length( content ) = 0) and (Result = 206) then |
| 271 |
Result := 304; |
Result := 304; |
| 272 |
|
|
| 275 |
on E: EIdSocketError do begin |
on E: EIdSocketError do begin |
| 276 |
ioModified := ZERO_DATE; |
ioModified := ZERO_DATE; |
| 277 |
outResultData := nil; |
outResultData := nil; |
| 278 |
|
Result := socket.ResponseCode; |
| 279 |
end; |
end; |
| 280 |
on E: EIdConnectException do begin |
on E: EIdConnectException do begin |
| 281 |
ioModified := ZERO_DATE; |
ioModified := ZERO_DATE; |
| 282 |
outResultData := nil; |
outResultData := nil; |
| 283 |
|
Result := socket.ResponseCode; |
| 284 |
//Item.ErrText := E.Message; |
//Item.ErrText := E.Message; |
| 285 |
end; |
end; |
| 286 |
|
//中断されたときココに入る |
| 287 |
|
on E: EIdClosedSocket do begin |
| 288 |
|
ioModified := ZERO_DATE; |
| 289 |
|
outResultData := nil; |
| 290 |
|
Result := 408; //既に一部DL成功しているとレスポンスコードが200のままに |
| 291 |
|
//なってしまうので、明示的にエラーコードを返す |
| 292 |
|
end; |
| 293 |
on E: Exception do begin |
on E: Exception do begin |
| 294 |
{$IFDEF DEBUG} |
{$IFDEF DEBUG} |
| 295 |
Writeln('取得で例外あり'); |
Writeln('取得で例外あり'); |
| 297 |
{$ENDIF} |
{$ENDIF} |
| 298 |
ioModified := ZERO_DATE; |
ioModified := ZERO_DATE; |
| 299 |
outResultData := nil; |
outResultData := nil; |
| 300 |
Result := httpSocket.ResponseCode; |
Result := socket.ResponseCode; |
| 301 |
//Item.ErrText := E.Message; |
//Item.ErrText := E.Message; |
| 302 |
end; |
end; |
| 303 |
end; |
end; |
| 306 |
end; |
end; |
| 307 |
|
|
| 308 |
finally |
finally |
| 309 |
httpSocket.Free; |
socket.Free; |
| 310 |
|
socket := nil; |
| 311 |
end; |
end; |
| 312 |
|
|
| 313 |
end; |
end; |