@@ -67,10 +67,12 @@ char *_buffer; OFStream *_output; intmax_t _received, _length, _resumedFrom; ProgressBar *_progressBar; } + +- (void)downloadNextURL; @end OF_APPLICATION_DELEGATE(OFHTTP) static void @@ -625,10 +627,70 @@ @throw e; [self performSelector: @selector(downloadNextURL) afterDelay: 0]; } + +- (bool)stream: (OFHTTPResponse *)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]; + + [_progressBar setReceived: _received]; + + if ([response isAtEndOfStream] || + (_length >= 0 && _received >= _length)) { + [_progressBar stop]; + [_progressBar draw]; + [_progressBar release]; + _progressBar = nil; + + if (!_quiet) { + [of_stdout writeString: @"\n "]; + [of_stdout writeLine: + OF_LOCALIZED(@"download_done", @"Done!")]; + } + + goto next; + } + + return true; + +next: + [self performSelector: @selector(downloadNextURL) + afterDelay: 0]; + return false; +} - (void)client: (OFHTTPClient *)client didPerformRequest: (OFHTTPRequest *)request response: (OFHTTPResponse *)response context: (id)context @@ -795,70 +857,10 @@ [self performSelector: @selector(downloadNextURL) afterDelay: 0]; } -- (bool)stream: (OFHTTPResponse *)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]; - - [_progressBar setReceived: _received]; - - if ([response isAtEndOfStream] || - (_length >= 0 && _received >= _length)) { - [_progressBar stop]; - [_progressBar draw]; - [_progressBar release]; - _progressBar = nil; - - if (!_quiet) { - [of_stdout writeString: @"\n "]; - [of_stdout writeLine: - OF_LOCALIZED(@"download_done", @"Done!")]; - } - - goto next; - } - - return true; - -next: - [self performSelector: @selector(downloadNextURL) - afterDelay: 0]; - return false; -} - - (void)downloadNextURL { OFString *URLString = nil; OFURL *URL; OFMutableDictionary *clientHeaders;