@@ -51,11 +51,12 @@ #define GIBIBYTE (1024 * 1024 * 1024) #define MEBIBYTE (1024 * 1024) #define KIBIBYTE (1024) -@interface OFHTTP: OFObject +@interface OFHTTP: OFObject { OFArray OF_GENERIC(OFString *) *_URLs; size_t _URLIndex; int _errorCode; OFString *_outputPath, *_currentFileName; @@ -650,39 +651,14 @@ [self performSelector: @selector(downloadNextURL) afterDelay: 0]; } -- (bool)stream: (OFHTTPResponse *)response +- (bool)stream: (OF_KINDOF(OFStream *))response didReadIntoBuffer: (void *)buffer length: (size_t)length - context: (id)context - exception: (OFException *)e -{ - if (e != nil) { - OFString *URL; - - [_progressBar stop]; - [_progressBar draw]; - [_progressBar release]; - _progressBar = nil; - - if (!_quiet) - [of_stdout writeString: @"\n Error!\n"]; - - URL = [_URLs objectAtIndex: _URLIndex - 1]; - [of_stderr writeLine: - OF_LOCALIZED(@"download_failed_exception", - @"%[prog]: Failed to download <%[url]>: %[exception]", - @"prog", [OFApplication programName], - @"url", URL, - @"exception", e)]; - - _errorCode = 1; - goto next; - } - +{ _received += length; [_output writeBuffer: buffer length: length]; @@ -699,19 +675,42 @@ [of_stdout writeString: @"\n "]; [of_stdout writeLine: OF_LOCALIZED(@"download_done", @"Done!")]; } - goto next; + [self performSelector: @selector(downloadNextURL) + afterDelay: 0]; + return false; } return true; +} + +- (void)stream: (OF_KINDOF(OFStream *))response + didFailWithException: (id)exception +{ + OFString *URL; + + [_progressBar stop]; + [_progressBar draw]; + [_progressBar release]; + _progressBar = nil; + + if (!_quiet) + [of_stdout writeString: @"\n Error!\n"]; + + URL = [_URLs objectAtIndex: _URLIndex - 1]; + [of_stderr writeLine: OF_LOCALIZED( + @"download_failed_exception", + @"%[prog]: Failed to download <%[url]>: %[exception]", + @"prog", [OFApplication programName], + @"url", URL, + @"exception", exception)]; -next: + _errorCode = 1; [self performSelector: @selector(downloadNextURL) afterDelay: 0]; - return false; } - (void)client: (OFHTTPClient *)client didReceiveHeaders: (OFDictionary OF_GENERIC(OFString *, OFString *) *)headers statusCode: (int)statusCode @@ -865,17 +864,13 @@ } [_currentFileName release]; _currentFileName = nil; + [response setDelegate: self]; [response asyncReadIntoBuffer: _buffer - length: [OFSystemInfo pageSize] - target: self - selector: @selector(stream:didReadIntoBuffer: - length:context:exception:) - context: nil]; - + length: [OFSystemInfo pageSize]]; return; next: [_currentFileName release]; _currentFileName = nil;