mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-26 04:57:54 +00:00
Use Appcast's content length when downloader doesn't retrieve an expected length
This commit is contained in:
1 parent
80267f22b5
commit
f62285ff3b
14 files changed
+56
-18
No files matched your search
Vendored
+1
@@ -21,6 +21,7 @@ SU_EXPORT @interface SUAppcastItem : NSObject<NSSecureCoding>
|
||||
@property (copy, readonly) NSString *minimumSystemVersion;
|
||||
@property (copy, readonly) NSString *maximumSystemVersion;
|
||||
@property (strong, readonly) NSURL *fileURL;
|
||||
@property (nonatomic, readonly) NSUInteger contentLength;
|
||||
@property (copy, readonly) NSString *versionString;
|
||||
@property (copy, readonly) NSString *displayVersionString;
|
||||
@property (copy, readonly) NSDictionary *deltaUpdates;
|
||||
|
||||
Vendored
+27
@@ -24,6 +24,7 @@
|
||||
@property (copy, readwrite) NSString *minimumSystemVersion;
|
||||
@property (copy, readwrite) NSString *maximumSystemVersion;
|
||||
@property (strong, readwrite) NSURL *fileURL;
|
||||
@property (nonatomic) NSUInteger contentLength;
|
||||
@property (copy, readwrite) NSString *versionString;
|
||||
@property (copy, readwrite) NSString *displayVersionString;
|
||||
@property (copy, readwrite) NSDictionary *deltaUpdates;
|
||||
@@ -37,6 +38,7 @@
|
||||
@synthesize displayVersionString;
|
||||
@synthesize DSASignature;
|
||||
@synthesize fileURL;
|
||||
@synthesize contentLength = _contentLength;
|
||||
@synthesize infoURL;
|
||||
@synthesize itemDescription;
|
||||
@synthesize maximumSystemVersion;
|
||||
@@ -61,6 +63,12 @@
|
||||
self.DSASignature = [decoder decodeObjectOfClass:[NSString class] forKey:@"DSASignature"];
|
||||
self.fileURL = [decoder decodeObjectOfClass:[NSURL class] forKey:@"fileURL"];
|
||||
self.infoURL = [decoder decodeObjectOfClass:[NSURL class] forKey:@"infoURL"];
|
||||
|
||||
self.contentLength = (NSUInteger)[decoder decodeIntegerForKey:@"contentLength"];
|
||||
if (self.contentLength == 0) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
self.itemDescription = [decoder decodeObjectOfClass:[NSString class] forKey:@"itemDescription"];
|
||||
self.maximumSystemVersion = [decoder decodeObjectOfClass:[NSString class] forKey:@"maximumSystemVersion"];
|
||||
self.minimumSystemVersion = [decoder decodeObjectOfClass:[NSString class] forKey:@"minimumSystemVersion"];
|
||||
@@ -95,6 +103,8 @@
|
||||
[encoder encodeObject:self.infoURL forKey:@"infoURL"];
|
||||
}
|
||||
|
||||
[encoder encodeInteger:(NSInteger)self.contentLength forKey:@"contentLength"];
|
||||
|
||||
if (self.itemDescription != nil) {
|
||||
[encoder encodeObject:self.itemDescription forKey:@"itemDescription"];
|
||||
}
|
||||
@@ -212,6 +222,23 @@
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSString *enclosureLengthString = [enclosure objectForKey:SURSSAttributeLength];
|
||||
NSInteger contentLength = 0;
|
||||
if (enclosureLengthString != nil) {
|
||||
contentLength = [enclosureLengthString integerValue];
|
||||
}
|
||||
if (contentLength > 0) {
|
||||
self.contentLength = (NSUInteger)contentLength;
|
||||
} else {
|
||||
// content length is important enough to require
|
||||
// developers copying the sample appcast should be using it already,
|
||||
// and we can get away with assuming the content length provided is valid
|
||||
if (error != NULL) {
|
||||
*error = @"Feed item's enclosure lacks length";
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
if (enclosureURLString) {
|
||||
// Sparkle used to always URL-encode, so for backwards compatibility spaces in URLs must be forgiven.
|
||||
|
||||
Vendored
+1
@@ -75,6 +75,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;
|
||||
|
||||
Vendored
+1
@@ -73,6 +73,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";
|
||||
|
||||
Vendored
+1
-1
@@ -33,7 +33,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (void)downloadDriverWillBeginDownload;
|
||||
|
||||
- (void)downloadDriverDidReceiveExpectedContentLength:(int64_t)expectedContentLength;
|
||||
- (void)downloadDriverDidReceiveExpectedContentLength:(NSUInteger)expectedContentLength;
|
||||
|
||||
- (void)downloadDriverDidReceiveDataOfLength:(NSUInteger)length;
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -141,7 +141,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)downloadDriverDidReceiveExpectedContentLength:(int64_t)expectedContentLength
|
||||
- (void)downloadDriverDidReceiveExpectedContentLength:(NSUInteger)expectedContentLength
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(downloadDriverDidReceiveExpectedContentLength:)]) {
|
||||
[self.delegate downloadDriverDidReceiveExpectedContentLength:expectedContentLength];
|
||||
|
||||
Vendored
+1
-1
@@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (void)downloadDriverWillBeginDownload;
|
||||
|
||||
- (void)downloadDriverDidReceiveExpectedContentLength:(int64_t)expectedContentLength;
|
||||
- (void)downloadDriverDidReceiveExpectedContentLength:(NSUInteger)expectedContentLength;
|
||||
|
||||
- (void)downloadDriverDidReceiveDataOfLength:(NSUInteger)length;
|
||||
|
||||
|
||||
Vendored
+14
-1
@@ -181,7 +181,20 @@
|
||||
- (void)downloaderDidReceiveExpectedContentLength:(int64_t)expectedContentLength
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.delegate downloadDriverDidReceiveExpectedContentLength:expectedContentLength];
|
||||
BOOL validExpectedContentLength = (expectedContentLength > 0 && expectedContentLength != NSURLResponseUnknownLength);
|
||||
NSUInteger expectedLength = (NSUInteger)expectedContentLength;
|
||||
NSUInteger updateItemContentLength = self.updateItem.contentLength;
|
||||
|
||||
NSUInteger contentLength =
|
||||
validExpectedContentLength ?
|
||||
updateItemContentLength :
|
||||
expectedLength;
|
||||
|
||||
if (validExpectedContentLength && updateItemContentLength != expectedLength) {
|
||||
SULog(@"Warning: Downloader's expected content length (%lu) != Appcast item's length (%lu)", expectedLength, updateItemContentLength);
|
||||
}
|
||||
|
||||
[self.delegate downloadDriverDidReceiveExpectedContentLength:contentLength];
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -317,7 +317,7 @@
|
||||
[self.coreComponent cancelDownloadStatus];
|
||||
}
|
||||
|
||||
- (void)showDownloadDidReceiveExpectedContentLength:(int64_t)expectedContentLength
|
||||
- (void)showDownloadDidReceiveExpectedContentLength:(NSUInteger)expectedContentLength
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.statusController setMaxProgressValue:expectedContentLength];
|
||||
|
||||
Vendored
+1
-1
@@ -147,7 +147,7 @@
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)downloadDriverDidReceiveExpectedContentLength:(int64_t)expectedContentLength
|
||||
- (void)downloadDriverDidReceiveExpectedContentLength:(NSUInteger)expectedContentLength
|
||||
{
|
||||
[self.userDriver showDownloadDidReceiveExpectedContentLength:expectedContentLength];
|
||||
}
|
||||
|
||||
Vendored
+2
-3
@@ -203,12 +203,11 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
/*!
|
||||
* Show the user the content length of the new update that will be downloaded
|
||||
*
|
||||
* @param expectedContentLength The expected content length of the new update being downloaded.
|
||||
* This is NSURLResponseUnknownLength if the length is unknown.
|
||||
* @param expectedContentLength The expected content length of the new update being downloaded. This will be greater than 0.
|
||||
*
|
||||
* This can be called from any thread
|
||||
*/
|
||||
- (void)showDownloadDidReceiveExpectedContentLength:(int64_t)expectedContentLength;
|
||||
- (void)showDownloadDidReceiveExpectedContentLength:(NSUInteger)expectedContentLength;
|
||||
|
||||
/*!
|
||||
* Show the user that the update download received more data
|
||||
|
||||
@@ -268,16 +268,12 @@
|
||||
});
|
||||
}
|
||||
|
||||
- (void)showDownloadDidReceiveExpectedContentLength:(int64_t)expectedContentLength
|
||||
- (void)showDownloadDidReceiveExpectedContentLength:(NSUInteger)expectedContentLength
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self addUpdateButtonWithTitle:@"Downloading…"];
|
||||
self.contentLengthDownloaded = 0;
|
||||
self.expectedContentLength = (NSUInteger)expectedContentLength;
|
||||
if (self.expectedContentLength == 0) {
|
||||
// don't divide by zero ever
|
||||
self.expectedContentLength = 1;
|
||||
}
|
||||
self.expectedContentLength = expectedContentLength;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@
|
||||
|
||||
- (void)showDownloadInitiatedWithCompletion:(void (^)(SUDownloadUpdateStatus))__unused downloadUpdateStatusCompletion {}
|
||||
|
||||
- (void)showDownloadDidReceiveExpectedContentLength:(int64_t)__unused expectedContentLength {}
|
||||
- (void)showDownloadDidReceiveExpectedContentLength:(NSUInteger)__unused expectedContentLength {}
|
||||
|
||||
- (void)showDownloadDidReceiveDataOfLength:(NSUInteger)__unused length {}
|
||||
|
||||
|
||||
@@ -190,14 +190,14 @@
|
||||
});
|
||||
}
|
||||
|
||||
- (void)showDownloadDidReceiveExpectedContentLength:(int64_t)expectedContentLength
|
||||
- (void)showDownloadDidReceiveExpectedContentLength:(NSUInteger)expectedContentLength
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (self.verbose) {
|
||||
fprintf(stderr, "Downloading %llu bytes...\n", expectedContentLength);
|
||||
}
|
||||
self.bytesDownloaded = 0;
|
||||
self.bytesToDownload = (NSUInteger)expectedContentLength;
|
||||
self.bytesToDownload = expectedContentLength;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user