diff --git a/Sparkle/SUAppcastItem.h b/Sparkle/SUAppcastItem.h index 51b9393f..9ed52c9e 100644 --- a/Sparkle/SUAppcastItem.h +++ b/Sparkle/SUAppcastItem.h @@ -25,6 +25,7 @@ SU_EXPORT @interface SUAppcastItem : NSObject @property (copy, readonly) NSString *minimumSystemVersion; @property (copy, readonly) NSString *maximumSystemVersion; @property (strong, readonly) NSURL *fileURL; +@property (nonatomic, readonly) uint64_t contentLength; @property (copy, readonly) NSString *versionString; @property (copy, readonly) NSString *displayVersionString; @property (copy, readonly) NSDictionary *deltaUpdates; diff --git a/Sparkle/SUAppcastItem.m b/Sparkle/SUAppcastItem.m index e6a6fb6f..164b5bad 100644 --- a/Sparkle/SUAppcastItem.m +++ b/Sparkle/SUAppcastItem.m @@ -32,6 +32,7 @@ @synthesize displayVersionString; @synthesize DSASignature; @synthesize fileURL; +@synthesize contentLength = _contentLength; @synthesize infoURL; @synthesize itemDescription; @synthesize maximumSystemVersion; @@ -129,6 +130,15 @@ } return nil; } + + if (enclosureURLString) { + NSString *enclosureLengthString = [enclosure objectForKey:SURSSAttributeLength]; + long long contentLength = 0; + if (enclosureLengthString != nil) { + contentLength = [enclosureLengthString longLongValue]; + } + _contentLength = (contentLength > 0) ? (uint64_t)contentLength : 0; + } if (enclosureURLString) { // Sparkle used to always URL-encode, so for backwards compatibility spaces in URLs must be forgiven. diff --git a/Sparkle/SUConstants.h b/Sparkle/SUConstants.h index fe2dfd2c..33abaab6 100644 --- a/Sparkle/SUConstants.h +++ b/Sparkle/SUConstants.h @@ -73,6 +73,7 @@ extern NSString *const SUAppcastElementReleaseNotesLink; extern NSString *const SUAppcastElementTags; extern NSString *const SURSSAttributeURL; +extern NSString *const SURSSAttributeLength; extern NSString *const SURSSElementDescription; extern NSString *const SURSSElementEnclosure; diff --git a/Sparkle/SUConstants.m b/Sparkle/SUConstants.m index 768d0b0d..f5e73fda 100644 --- a/Sparkle/SUConstants.m +++ b/Sparkle/SUConstants.m @@ -61,6 +61,7 @@ NSString *const SUAppcastElementReleaseNotesLink = @"sparkle:releaseNotesLink"; NSString *const SUAppcastElementTags = @"sparkle:tags"; NSString *const SURSSAttributeURL = @"url"; +NSString *const SURSSAttributeLength = @"length"; NSString *const SURSSElementDescription = @"description"; NSString *const SURSSElementEnclosure = @"enclosure"; diff --git a/Sparkle/SUUIBasedUpdateDriver.m b/Sparkle/SUUIBasedUpdateDriver.m index 6b602b44..99d4ddba 100644 --- a/Sparkle/SUUIBasedUpdateDriver.m +++ b/Sparkle/SUUIBasedUpdateDriver.m @@ -161,7 +161,8 @@ - (void)download:(NSURLDownload *)__unused download didReceiveResponse:(NSURLResponse *)response { - [self.statusController setMaxProgressValue:[response expectedContentLength]]; + long long expectedContentLength = [response expectedContentLength]; + [self.statusController setMaxProgressValue:expectedContentLength > 0 ? expectedContentLength : self.updateItem.contentLength]; } - (NSString *)localizedStringFromByteCount:(long long)value @@ -196,7 +197,14 @@ - (void)download:(NSURLDownload *)__unused download didReceiveDataOfLength:(NSUInteger)length { - [self.statusController setProgressValue:[self.statusController progressValue] + (double)length]; + double newProgressValue = [self.statusController progressValue] + (double)length; + + // In case our expected content length was incorrect + if (newProgressValue > [self.statusController maxProgressValue]) { + [self.statusController setMaxProgressValue:newProgressValue]; + } + + [self.statusController setProgressValue:newProgressValue]; if ([self.statusController maxProgressValue] > 0.0) [self.statusController setStatusText:[NSString stringWithFormat:SULocalizedString(@"%@ of %@", nil), [self localizedStringFromByteCount:(long long)self.statusController.progressValue], [self localizedStringFromByteCount:(long long)self.statusController.maxProgressValue]]]; else