mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-25 04:47:55 +00:00
Prefer using HTTP expected content length over appcast item length
Also use (u)int64_t instead of NS(U)Integer
This commit is contained in:
1 parent
a82f5acdd6
commit
e3f68b70bf
13 files changed
+37
-47
No files matched your search
@@ -22,7 +22,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
- (void)downloaderDidReceiveExpectedContentLength:(int64_t)expectedContentLength;
|
||||
|
||||
// This is only invoked for persistent downloads
|
||||
- (void)downloaderDidReceiveDataOfLength:(NSUInteger)length;
|
||||
- (void)downloaderDidReceiveDataOfLength:(uint64_t)length;
|
||||
|
||||
// downloadData is nil if this is a persisent download, otherwise it's non-nil if it's a temporary download
|
||||
- (void)downloaderDidFinishWithTemporaryDownloadData:(SPUDownloadData * _Nullable)downloadData;
|
||||
|
||||
Vendored
+2
-2
@@ -31,9 +31,9 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (void)downloadDriverWillBeginDownload;
|
||||
|
||||
- (void)downloadDriverDidReceiveExpectedContentLength:(NSUInteger)expectedContentLength;
|
||||
- (void)downloadDriverDidReceiveExpectedContentLength:(uint64_t)expectedContentLength;
|
||||
|
||||
- (void)downloadDriverDidReceiveDataOfLength:(NSUInteger)length;
|
||||
- (void)downloadDriverDidReceiveDataOfLength:(uint64_t)length;
|
||||
|
||||
- (void)coreDriverDidStartExtractingUpdate;
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -183,14 +183,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)downloadDriverDidReceiveExpectedContentLength:(NSUInteger)expectedContentLength
|
||||
- (void)downloadDriverDidReceiveExpectedContentLength:(uint64_t)expectedContentLength
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(downloadDriverDidReceiveExpectedContentLength:)]) {
|
||||
[self.delegate downloadDriverDidReceiveExpectedContentLength:expectedContentLength];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)downloadDriverDidReceiveDataOfLength:(NSUInteger)length
|
||||
- (void)downloadDriverDidReceiveDataOfLength:(uint64_t)length
|
||||
{
|
||||
if ([self.delegate respondsToSelector:@selector(downloadDriverDidReceiveDataOfLength:)]) {
|
||||
[self.delegate downloadDriverDidReceiveDataOfLength:length];
|
||||
|
||||
Vendored
+2
-2
@@ -16,9 +16,9 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
- (void)downloadDriverWillBeginDownload;
|
||||
|
||||
- (void)downloadDriverDidReceiveExpectedContentLength:(NSUInteger)expectedContentLength;
|
||||
- (void)downloadDriverDidReceiveExpectedContentLength:(uint64_t)expectedContentLength;
|
||||
|
||||
- (void)downloadDriverDidReceiveDataOfLength:(NSUInteger)length;
|
||||
- (void)downloadDriverDidReceiveDataOfLength:(uint64_t)length;
|
||||
|
||||
- (void)downloadDriverDidDownloadUpdate:(SPUDownloadedUpdate *)downloadedUpdate;
|
||||
|
||||
|
||||
Vendored
+7
-12
@@ -34,8 +34,7 @@
|
||||
@property (nonatomic, copy) NSString *downloadName;
|
||||
@property (nonatomic, weak) id<SPUDownloadDriverDelegate> delegate;
|
||||
@property (nonatomic) BOOL retrievedDownloadResult;
|
||||
@property (nonatomic) BOOL retrievedDownloadResponse;
|
||||
@property (nonatomic) NSUInteger expectedContentLength;
|
||||
@property (nonatomic) uint64_t expectedContentLength;
|
||||
@property (nonatomic) BOOL cleaningUp;
|
||||
|
||||
@end
|
||||
@@ -51,7 +50,6 @@
|
||||
@synthesize downloadName = _downloadName;
|
||||
@synthesize delegate = _delegate;
|
||||
@synthesize retrievedDownloadResult = _retrievedDownloadResult;
|
||||
@synthesize retrievedDownloadResponse = _retrievedDownloadResponse;
|
||||
@synthesize expectedContentLength = _expectedContentLength;
|
||||
@synthesize cleaningUp = _cleaningUp;
|
||||
|
||||
@@ -140,7 +138,7 @@
|
||||
self.retrievedDownloadResult = YES;
|
||||
|
||||
if (self.expectedContentLength > 0 && self.updateItem.contentLength > 0 && self.expectedContentLength != self.updateItem.contentLength) {
|
||||
SULog(@"Warning: Downloader's expected content length (%lu) != Appcast item's length (%lu)", self.expectedContentLength, self.updateItem.contentLength);
|
||||
SULog(@"Warning: Downloader's expected content length (%llu) != Appcast item's length (%llu)", self.expectedContentLength, self.updateItem.contentLength);
|
||||
}
|
||||
|
||||
SPUDownloadedUpdate *downloadedUpdate = [[SPUDownloadedUpdate alloc] initWithAppcastItem:self.updateItem downloadName:self.downloadName temporaryDirectory:self.temporaryDirectory];
|
||||
@@ -186,21 +184,18 @@
|
||||
- (void)downloaderDidReceiveExpectedContentLength:(int64_t)expectedContentLength
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// We only notify the expected content length once and we try to use the content length from the appcast instead of from the downloader
|
||||
if (!self.retrievedDownloadResponse) {
|
||||
[self.delegate downloadDriverDidReceiveExpectedContentLength:(self.updateItem.contentLength > 0 ? self.updateItem.contentLength : (NSUInteger)expectedContentLength)];
|
||||
self.retrievedDownloadResponse = YES;
|
||||
}
|
||||
// Fallback to appcast item's content length if we don't get the length from HTTP header
|
||||
[self.delegate downloadDriverDidReceiveExpectedContentLength:expectedContentLength > 0 ? (uint64_t)expectedContentLength : self.updateItem.contentLength];
|
||||
|
||||
// Reset expected content length from downloader
|
||||
// Later we verify if the total length matches with the content length from the appcast
|
||||
if (expectedContentLength > 0 && expectedContentLength != NSURLResponseUnknownLength) {
|
||||
self.expectedContentLength = (NSUInteger)expectedContentLength;
|
||||
if (expectedContentLength > 0) {
|
||||
self.expectedContentLength = (uint64_t)expectedContentLength;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
- (void)downloaderDidReceiveDataOfLength:(NSUInteger)length
|
||||
- (void)downloaderDidReceiveDataOfLength:(uint64_t)length
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.delegate downloadDriverDidReceiveDataOfLength:length];
|
||||
|
||||
Vendored
+2
-2
@@ -320,7 +320,7 @@
|
||||
[self.coreComponent cancelDownloadStatus];
|
||||
}
|
||||
|
||||
- (void)showDownloadDidReceiveExpectedContentLength:(NSUInteger)expectedContentLength
|
||||
- (void)showDownloadDidReceiveExpectedContentLength:(uint64_t)expectedContentLength
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.statusController setMaxProgressValue:expectedContentLength];
|
||||
@@ -333,7 +333,7 @@
|
||||
countStyle:NSByteCountFormatterCountStyleFile];
|
||||
}
|
||||
|
||||
- (void)showDownloadDidReceiveDataOfLength:(NSUInteger)length
|
||||
- (void)showDownloadDidReceiveDataOfLength:(uint64_t)length
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.statusController setProgressValue:[self.statusController progressValue] + (double)length];
|
||||
|
||||
Vendored
+2
-2
@@ -181,12 +181,12 @@
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)downloadDriverDidReceiveExpectedContentLength:(NSUInteger)expectedContentLength
|
||||
- (void)downloadDriverDidReceiveExpectedContentLength:(uint64_t)expectedContentLength
|
||||
{
|
||||
[self.userDriver showDownloadDidReceiveExpectedContentLength:expectedContentLength];
|
||||
}
|
||||
|
||||
- (void)downloadDriverDidReceiveDataOfLength:(NSUInteger)length
|
||||
- (void)downloadDriverDidReceiveDataOfLength:(uint64_t)length
|
||||
{
|
||||
[self.userDriver showDownloadDidReceiveDataOfLength:length];
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -46,7 +46,7 @@
|
||||
{
|
||||
}
|
||||
|
||||
- (void)downloaderDidReceiveDataOfLength:(NSUInteger)__unused length
|
||||
- (void)downloaderDidReceiveDataOfLength:(uint64_t)__unused length
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Vendored
+2
-2
@@ -202,7 +202,7 @@ SU_EXPORT @protocol SPUUserDriver <NSObject>
|
||||
*
|
||||
* This can be called from any thread
|
||||
*/
|
||||
- (void)showDownloadDidReceiveExpectedContentLength:(NSUInteger)expectedContentLength;
|
||||
- (void)showDownloadDidReceiveExpectedContentLength:(uint64_t)expectedContentLength;
|
||||
|
||||
/*!
|
||||
* Show the user that the update download received more data
|
||||
@@ -212,7 +212,7 @@ SU_EXPORT @protocol SPUUserDriver <NSObject>
|
||||
*
|
||||
* This can be called from any thread
|
||||
*/
|
||||
- (void)showDownloadDidReceiveDataOfLength:(NSUInteger)length;
|
||||
- (void)showDownloadDidReceiveDataOfLength:(uint64_t)length;
|
||||
|
||||
/*!
|
||||
* Show the user that the update finished downloading and started extracting
|
||||
|
||||
Vendored
+1
-1
@@ -25,7 +25,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 (nonatomic, readonly) uint64_t contentLength;
|
||||
@property (copy, readonly) NSString *versionString;
|
||||
@property (copy, readonly) NSString *displayVersionString;
|
||||
@property (copy, readonly) NSDictionary *deltaUpdates;
|
||||
|
||||
Vendored
+5
-10
@@ -65,7 +65,7 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT
|
||||
_fileURL = [decoder decodeObjectOfClass:[NSURL class] forKey:SUAppcastItemFileURLKey];
|
||||
_infoURL = [decoder decodeObjectOfClass:[NSURL class] forKey:SUAppcastItemInfoURLKey];
|
||||
|
||||
_contentLength = (NSUInteger)[decoder decodeIntegerForKey:SUAppcastItemContentLengthKey];
|
||||
_contentLength = (uint64_t)[decoder decodeInt64ForKey:SUAppcastItemContentLengthKey];
|
||||
|
||||
_installationType = [decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastItemInstallationTypeKey];
|
||||
if (!SPUValidInstallationType(_installationType)) {
|
||||
@@ -106,7 +106,7 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT
|
||||
[encoder encodeObject:self.infoURL forKey:SUAppcastItemInfoURLKey];
|
||||
}
|
||||
|
||||
[encoder encodeInteger:(NSInteger)self.contentLength forKey:SUAppcastItemContentLengthKey];
|
||||
[encoder encodeInt64:(int64_t)self.contentLength forKey:SUAppcastItemContentLengthKey];
|
||||
|
||||
if (self.itemDescription != nil) {
|
||||
[encoder encodeObject:self.itemDescription forKey:SUAppcastItemDescriptionKey];
|
||||
@@ -232,16 +232,11 @@ static NSString *SUAppcastItemInstallationTypeKey = @"SUAppcastItemInstallationT
|
||||
|
||||
if (enclosureURLString) {
|
||||
NSString *enclosureLengthString = [enclosure objectForKey:SURSSAttributeLength];
|
||||
NSInteger contentLength = 0;
|
||||
long long contentLength = 0;
|
||||
if (enclosureLengthString != nil) {
|
||||
contentLength = [enclosureLengthString integerValue];
|
||||
} else {
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
SULog(@"warning: <%@> for URL '%@' is missing %@ attribute. Downloading progress may be unreliable. Please always specify %@", SURSSElementEnclosure, [enclosure objectForKey:SURSSAttributeURL], SURSSAttributeLength, SURSSAttributeLength);
|
||||
});
|
||||
contentLength = [enclosureLengthString longLongValue];
|
||||
}
|
||||
_contentLength = (contentLength > 0) ? (NSUInteger)contentLength : 0;
|
||||
_contentLength = (contentLength > 0) ? (uint64_t)contentLength : 0;
|
||||
}
|
||||
|
||||
if (enclosureURLString) {
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
@property (nonatomic) BOOL addedAccessory;
|
||||
@property (nonatomic) NSButton *updateButton;
|
||||
@property (nonatomic, copy) void (^updateButtonAction)(NSButton *);
|
||||
@property (nonatomic) NSUInteger expectedContentLength;
|
||||
@property (nonatomic) NSUInteger contentLengthDownloaded;
|
||||
@property (nonatomic) uint64_t expectedContentLength;
|
||||
@property (nonatomic) uint64_t contentLengthDownloaded;
|
||||
|
||||
@end
|
||||
|
||||
@@ -268,7 +268,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
- (void)showDownloadDidReceiveExpectedContentLength:(NSUInteger)expectedContentLength
|
||||
- (void)showDownloadDidReceiveExpectedContentLength:(uint64_t)expectedContentLength
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self addUpdateButtonWithTitle:@"Downloading…"];
|
||||
@@ -277,7 +277,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
- (void)showDownloadDidReceiveDataOfLength:(NSUInteger)length
|
||||
- (void)showDownloadDidReceiveDataOfLength:(uint64_t)length
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.contentLengthDownloaded += length;
|
||||
|
||||
@@ -19,8 +19,8 @@
|
||||
@property (nonatomic, readonly) BOOL deferInstallation;
|
||||
@property (nonatomic, readonly) BOOL verbose;
|
||||
@property (nonatomic, readonly) SPUUserDriverCoreComponent *coreComponent;
|
||||
@property (nonatomic) NSUInteger bytesDownloaded;
|
||||
@property (nonatomic) NSUInteger bytesToDownload;
|
||||
@property (nonatomic) uint64_t bytesDownloaded;
|
||||
@property (nonatomic) uint64_t bytesToDownload;
|
||||
|
||||
@end
|
||||
|
||||
@@ -215,23 +215,23 @@
|
||||
});
|
||||
}
|
||||
|
||||
- (void)showDownloadDidReceiveExpectedContentLength:(NSUInteger)expectedContentLength
|
||||
- (void)showDownloadDidReceiveExpectedContentLength:(uint64_t)expectedContentLength
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (self.verbose) {
|
||||
fprintf(stderr, "Downloading %lu bytes...\n", (unsigned long)expectedContentLength);
|
||||
fprintf(stderr, "Downloading %llu bytes...\n", expectedContentLength);
|
||||
}
|
||||
self.bytesDownloaded = 0;
|
||||
self.bytesToDownload = expectedContentLength;
|
||||
});
|
||||
}
|
||||
|
||||
- (void)showDownloadDidReceiveDataOfLength:(NSUInteger)length
|
||||
- (void)showDownloadDidReceiveDataOfLength:(uint64_t)length
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.bytesDownloaded += length;
|
||||
if (self.bytesToDownload > 0 && self.verbose) {
|
||||
fprintf(stderr, "Downloaded %lu out of %lu bytes (%.0f%%)\n", (unsigned long)self.bytesDownloaded, (unsigned long)self.bytesToDownload, (self.bytesDownloaded * 100.0 / self.bytesToDownload));
|
||||
fprintf(stderr, "Downloaded %llu out of %llu bytes (%.0f%%)\n", self.bytesDownloaded, self.bytesToDownload, (self.bytesDownloaded * 100.0 / self.bytesToDownload));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user