diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 3717b102..a933f6d4 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -323,13 +323,13 @@ 72F9EBE31D517E2F004AC8B6 /* SUUpdater.m in Sources */ = {isa = PBXBuildFile; fileRef = 72F9EBE11D517E2F004AC8B6 /* SUUpdater.m */; }; 72F9EC341D5BF542004AC8B6 /* SUFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5E41D3D90AA00D1BF90 /* SUFileManager.m */; }; 72F9EC351D5BF54E004AC8B6 /* SUFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5E41D3D90AA00D1BF90 /* SUFileManager.m */; }; - 72F9EC381D5C04A9004AC8B6 /* SPUTemporaryDownload.h in Headers */ = {isa = PBXBuildFile; fileRef = 72F9EC361D5C04A9004AC8B6 /* SPUTemporaryDownload.h */; }; - 72F9EC3A1D5C04A9004AC8B6 /* SPUTemporaryDownload.m in Sources */ = {isa = PBXBuildFile; fileRef = 72F9EC371D5C04A9004AC8B6 /* SPUTemporaryDownload.m */; }; 72F9EC3B1D5C15D0004AC8B6 /* SUConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A5F09CA6EB100B7442F /* SUConstants.m */; }; - 72F9EC3C1D5C15EF004AC8B6 /* SPUTemporaryDownload.m in Sources */ = {isa = PBXBuildFile; fileRef = 72F9EC371D5C04A9004AC8B6 /* SPUTemporaryDownload.m */; }; 72F9EC3F1D5E823F004AC8B6 /* SPUUpdaterTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 72F9EC3D1D5E823F004AC8B6 /* SPUUpdaterTimer.h */; }; 72F9EC401D5E823F004AC8B6 /* SPUUpdaterTimer.m in Sources */ = {isa = PBXBuildFile; fileRef = 72F9EC3E1D5E823F004AC8B6 /* SPUUpdaterTimer.m */; }; 72F9EC411D5E823F004AC8B6 /* SPUUpdaterTimer.m in Sources */ = {isa = PBXBuildFile; fileRef = 72F9EC3E1D5E823F004AC8B6 /* SPUUpdaterTimer.m */; }; + 72F9EC441D5E9ED8004AC8B6 /* SPUDownloadData.h in Headers */ = {isa = PBXBuildFile; fileRef = 72F9EC421D5E9ED8004AC8B6 /* SPUDownloadData.h */; settings = {ATTRIBUTES = (Public, ); }; }; + 72F9EC451D5E9ED8004AC8B6 /* SPUDownloadData.m in Sources */ = {isa = PBXBuildFile; fileRef = 72F9EC431D5E9ED8004AC8B6 /* SPUDownloadData.m */; }; + 72F9EC461D5E9ED8004AC8B6 /* SPUDownloadData.m in Sources */ = {isa = PBXBuildFile; fileRef = 72F9EC431D5E9ED8004AC8B6 /* SPUDownloadData.m */; }; C23E885B1BE7B24F0050BB73 /* SparkleTestCodeSignApp.enc.dmg in Resources */ = {isa = PBXBuildFile; fileRef = C23E88591BE7AF890050BB73 /* SparkleTestCodeSignApp.enc.dmg */; }; F8761EB11ADC5068000C9034 /* SUCodeSigningVerifierTest.m in Sources */ = {isa = PBXBuildFile; fileRef = F8761EB01ADC5068000C9034 /* SUCodeSigningVerifierTest.m */; }; F8761EB31ADC50EB000C9034 /* SparkleTestCodeSignApp.zip in Resources */ = {isa = PBXBuildFile; fileRef = F8761EB21ADC50EB000C9034 /* SparkleTestCodeSignApp.zip */; }; @@ -1025,10 +1025,10 @@ 72F94F571CC44DE1002DEE68 /* SPUXPCServiceInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUXPCServiceInfo.m; sourceTree = ""; }; 72F9EBE01D517E2F004AC8B6 /* SUUpdater.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdater.h; sourceTree = ""; }; 72F9EBE11D517E2F004AC8B6 /* SUUpdater.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUpdater.m; sourceTree = ""; }; - 72F9EC361D5C04A9004AC8B6 /* SPUTemporaryDownload.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SPUTemporaryDownload.h; path = TemporaryDownloader/SPUTemporaryDownload.h; sourceTree = SOURCE_ROOT; }; - 72F9EC371D5C04A9004AC8B6 /* SPUTemporaryDownload.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SPUTemporaryDownload.m; path = TemporaryDownloader/SPUTemporaryDownload.m; sourceTree = SOURCE_ROOT; }; 72F9EC3D1D5E823F004AC8B6 /* SPUUpdaterTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUUpdaterTimer.h; sourceTree = ""; }; 72F9EC3E1D5E823F004AC8B6 /* SPUUpdaterTimer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUUpdaterTimer.m; sourceTree = ""; }; + 72F9EC421D5E9ED8004AC8B6 /* SPUDownloadData.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUDownloadData.h; sourceTree = ""; }; + 72F9EC431D5E9ED8004AC8B6 /* SPUDownloadData.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUDownloadData.m; sourceTree = ""; }; 8DC2EF5A0486A6940098B216 /* Sparkle-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Sparkle-Info.plist"; sourceTree = ""; }; 8DC2EF5B0486A6940098B216 /* Sparkle.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Sparkle.framework; sourceTree = BUILT_PRODUCTS_DIR; }; A5BF4F1B1BC7668B007A052A /* SUTestWebServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUTestWebServer.h; sourceTree = ""; }; @@ -1433,6 +1433,8 @@ 72B09CE61CE6BCBD0052EF9E /* SPUURLDownload.m */, 7293A1AC1CEE933800B957A7 /* SPUURLRequest.h */, 7293A1AD1CEE933800B957A7 /* SPUURLRequest.m */, + 72F9EC421D5E9ED8004AC8B6 /* SPUDownloadData.h */, + 72F9EC431D5E9ED8004AC8B6 /* SPUDownloadData.m */, 61A225A20D1C4AC000430CCD /* SUStandardVersionComparator.h */, 61A225A30D1C4AC000430CCD /* SUStandardVersionComparator.m */, 61A2279A0D1CEE7600430CCD /* SUSystemProfiler.h */, @@ -1725,8 +1727,6 @@ 724A0A351CF7AEEA00D8C3D5 /* main.m */, 724A0A371CF7AEEA00D8C3D5 /* SUTemporaryDownloader.h */, 724A0A381CF7AEEA00D8C3D5 /* SUTemporaryDownloader.m */, - 72F9EC361D5C04A9004AC8B6 /* SPUTemporaryDownload.h */, - 72F9EC371D5C04A9004AC8B6 /* SPUTemporaryDownload.m */, 724A0A391CF7AEEA00D8C3D5 /* SUTemporaryDownloaderProtocol.h */, ); name = TemporaryDownloader; @@ -1850,6 +1850,7 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( + 72F9EC441D5E9ED8004AC8B6 /* SPUDownloadData.h in Headers */, 725F977B1C8A896F00265BE4 /* SPUUserDriverCoreComponent.h in Headers */, 72F9EBE21D517E2F004AC8B6 /* SUUpdater.h in Headers */, 726E078D1CA891E9001A286B /* SPUUpdaterSettings.h in Headers */, @@ -1906,7 +1907,6 @@ 61B5F8ED09C4CE3C00B25A18 /* SPUUpdater.h in Headers */, 61A2259E0D1C495D00430CCD /* SUVersionComparisonProtocol.h in Headers */, 3772FEA913DE0B6B00F79537 /* SUVersionDisplayProtocol.h in Headers */, - 72F9EC381D5C04A9004AC8B6 /* SPUTemporaryDownload.h in Headers */, 7267E5E51D3D90AA00D1BF90 /* SUFileManager.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; @@ -2742,8 +2742,8 @@ buildActionMask = 2147483647; files = ( 72F9EC3B1D5C15D0004AC8B6 /* SUConstants.m in Sources */, - 72F9EC3A1D5C04A9004AC8B6 /* SPUTemporaryDownload.m in Sources */, 72F9EC411D5E823F004AC8B6 /* SPUUpdaterTimer.m in Sources */, + 72F9EC461D5E9ED8004AC8B6 /* SPUDownloadData.m in Sources */, 724A0A3B1CF7AEEA00D8C3D5 /* main.m in Sources */, 7293A1B01CEE9B9800B957A7 /* SPUURLRequest.m in Sources */, 724A0A3D1CF7AEEA00D8C3D5 /* SUTemporaryDownloader.m in Sources */, @@ -2804,7 +2804,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 72F9EC3C1D5C15EF004AC8B6 /* SPUTemporaryDownload.m in Sources */, 7267E5DF1D3D8FFA00D1BF90 /* SPUInstallationInputData.m in Sources */, 724BB3B01D3482BA005D534A /* SPUSystemAuthorization.m in Sources */, 724BB3AA1D3347C2005D534A /* SUInstallerStatus.m in Sources */, @@ -2815,6 +2814,7 @@ 723B5DAA1CF7AB6A00365F95 /* SUPersistentDownloader.m in Sources */, 72F94F5A1CC450DE002DEE68 /* SUInstallerLauncher.m in Sources */, 724BB3A91D33461B005D534A /* SUXPCInstallerStatus.m in Sources */, + 72F9EC451D5E9ED8004AC8B6 /* SPUDownloadData.m in Sources */, 72B767E31C9CE90A00A07552 /* SUCoreBasedUpdateDriver.m in Sources */, 72B767E71C9CFD7200A07552 /* SUAutomaticUpdateDriver.m in Sources */, 7267E5E61D3D90AA00D1BF90 /* SUFileManager.m in Sources */, diff --git a/Sparkle/SPUDownloadData.h b/Sparkle/SPUDownloadData.h new file mode 100644 index 00000000..9d426ab1 --- /dev/null +++ b/Sparkle/SPUDownloadData.h @@ -0,0 +1,38 @@ +// +// SPUDownloadData.h +// Sparkle +// +// Created by Mayur Pawashe on 8/10/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import +#import "SUExport.h" + +NS_ASSUME_NONNULL_BEGIN + +/*! + * A class for containing downloaded data along with some information about it. + */ +SU_EXPORT @interface SPUDownloadData : NSObject + +- (instancetype)initWithData:(NSData *)data textEncodingName:(NSString * _Nullable)textEncodingName MIMEType:(NSString * _Nullable)MIMEType; + +/*! + * The raw data that was downloaded. + */ +@property (nonatomic, readonly) NSData *data; + +/*! + * The IANA charset encoding name if available. Eg: "utf-8" + */ +@property (nonatomic, readonly, nullable, copy) NSString *textEncodingName; + +/*! + * The MIME type if available. Eg: "text/plain" + */ +@property (nonatomic, readonly, nullable, copy) NSString *MIMEType; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Sparkle/SPUDownloadData.m b/Sparkle/SPUDownloadData.m new file mode 100644 index 00000000..cf97cf8e --- /dev/null +++ b/Sparkle/SPUDownloadData.m @@ -0,0 +1,64 @@ +// +// SPUDownloadData.m +// Sparkle +// +// Created by Mayur Pawashe on 8/10/16. +// Copyright © 2016 Sparkle Project. All rights reserved. +// + +#import "SPUDownloadData.h" + +static NSString *SPUDownloadDataKey = @"SPUDownloadData"; +static NSString *SPUDownloadTextEncodingKey = @"SPUDownloadTextEncoding"; +static NSString *SPUDownloadMIMETypeKey = @"SPUDownloadMIMEType"; + +@implementation SPUDownloadData + +@synthesize data = _data; +@synthesize textEncodingName = _textEncodingName; +@synthesize MIMEType = _MIMEType; + ++ (BOOL)supportsSecureCoding +{ + return YES; +} + +- (instancetype)initWithData:(NSData *)data textEncodingName:(NSString * _Nullable)textEncodingName MIMEType:(NSString *)MIMEType +{ + self = [super init]; + if (self != nil) { + _data = data; + _textEncodingName = textEncodingName; + _MIMEType = MIMEType; + } + return self; +} + +- (void)encodeWithCoder:(NSCoder *)coder +{ + [coder encodeObject:self.data forKey:SPUDownloadDataKey]; + + if (self.textEncodingName != nil) { + [coder encodeObject:self.textEncodingName forKey:SPUDownloadTextEncodingKey]; + } + + if (self.MIMEType != nil) { + [coder encodeObject:self.MIMEType forKey:SPUDownloadMIMETypeKey]; + } +} + +- (nullable instancetype)initWithCoder:(NSCoder *)decoder +{ + NSData *data = [decoder decodeObjectOfClass:[NSData class] forKey:SPUDownloadDataKey]; + if (data == nil) { + return nil; + } + + NSString *textEncodingName = [decoder decodeObjectOfClass:[NSString class] forKey:SPUDownloadTextEncodingKey]; + + NSString *MIMEType = [decoder decodeObjectOfClass:[NSString class] forKey:SPUDownloadMIMETypeKey]; + + return [self initWithData:data textEncodingName:textEncodingName MIMEType:MIMEType]; +} + +@end diff --git a/Sparkle/SPUStandardUserDriver.m b/Sparkle/SPUStandardUserDriver.m index 6a130557..3a68e067 100644 --- a/Sparkle/SPUStandardUserDriver.m +++ b/Sparkle/SPUStandardUserDriver.m @@ -17,6 +17,7 @@ #import "SUUpdateAlert.h" #import "SULocalizations.h" #import "SPUApplicationInfo.h" +#import "SPUDownloadData.h" @interface SPUStandardUserDriver () @@ -155,10 +156,10 @@ }]; } -- (void)showUpdateReleaseNotesWithData:(NSData *)releaseNotesData textEncodingName:(NSString * _Nullable)textEncodingName MIMEType:(NSString * _Nullable)MIMEType +- (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData { dispatch_async(dispatch_get_main_queue(), ^{ - [self.activeUpdateAlert showUpdateReleaseNotesWithData:releaseNotesData textEncodingName:textEncodingName MIMEType:MIMEType]; + [self.activeUpdateAlert showUpdateReleaseNotesWithDownloadData:downloadData]; }); } diff --git a/Sparkle/SPUURLDownload.h b/Sparkle/SPUURLDownload.h index 8651488e..bfc7565d 100644 --- a/Sparkle/SPUURLDownload.h +++ b/Sparkle/SPUURLDownload.h @@ -10,10 +10,10 @@ NS_ASSUME_NONNULL_BEGIN -@class SPUTemporaryDownload; +@class SPUDownloadData; // From the completion block, either data or error can be nil, but not both // The completion block returns on the main queue -void SPUDownloadURLWithRequest(NSURLRequest * request, void (^completionBlock)(SPUTemporaryDownload * _Nullable download, NSError * _Nullable error)); +void SPUDownloadURLWithRequest(NSURLRequest * request, void (^completionBlock)(SPUDownloadData * _Nullable download, NSError * _Nullable error)); NS_ASSUME_NONNULL_END diff --git a/Sparkle/SPUURLDownload.m b/Sparkle/SPUURLDownload.m index 92121c15..7a2a6cfa 100644 --- a/Sparkle/SPUURLDownload.m +++ b/Sparkle/SPUURLDownload.m @@ -11,10 +11,10 @@ #import "SUTemporaryDownloader.h" #import "SUTemporaryDownloaderProtocol.h" #import "SPUURLRequest.h" -#import "SPUTemporaryDownload.h" +#import "SPUDownloadData.h" #import "SUErrors.h" -void SPUDownloadURLWithRequest(NSURLRequest * request, void (^completionBlock)(SPUTemporaryDownload * _Nullable, NSError * _Nullable)) +void SPUDownloadURLWithRequest(NSURLRequest * request, void (^completionBlock)(SPUDownloadData * _Nullable, NSError * _Nullable)) { id downloader = nil; NSXPCConnection *connection = nil; @@ -58,15 +58,15 @@ void SPUDownloadURLWithRequest(NSURLRequest * request, void (^completionBlock)(S downloader = connection.remoteObjectProxy; } - [downloader startDownloadWithRequest:[SPUURLRequest URLRequestWithRequest:request] completion:^(SPUTemporaryDownload * _Nullable download, NSError * _Nullable error) { + [downloader startDownloadWithRequest:[SPUURLRequest URLRequestWithRequest:request] completion:^(SPUDownloadData * _Nullable downloadData, NSError * _Nullable error) { dispatch_async(dispatch_get_main_queue(), ^{ retrievedDownloadResult = YES; [connection invalidate]; - if (download == nil || download.data == nil) { + if (downloadData == nil || downloadData.data == nil) { completionBlock(nil, error); } else { - completionBlock(download, nil); + completionBlock(downloadData, nil); } }); }]; diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index 1cea2038..9da7eebc 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -12,7 +12,7 @@ NS_ASSUME_NONNULL_BEGIN -@class SPUUpdatePermission, SUAppcastItem; +@class SPUUpdatePermission, SUAppcastItem, SPUDownloadData; /*! The API in Sparkle for controlling the user interaction. @@ -127,13 +127,11 @@ SU_EXPORT @protocol SPUUserDriver * This is only applicable if the release notes are linked from the appcast, and are not directly embedded inside of the appcast file. * That is, this may be invoked if the releaseNotesURL from the appcast item is non-nil. * - * @param releaseNotesData The data for the release notes that was downloaded from the new update's appcast. - * @param textEncodingName The text encoding name (eg: "utf-8"). This may be nil if one wasn't retrieved. - * @param MIMEType The MIME type that was retrieved from the download. This may be nil if one wasn't retrieved. + * @param downloadData The data for the release notes that was downloaded from the new update's appcast. * * This can be called from any thread */ -- (void)showUpdateReleaseNotesWithData:(NSData *)releaseNotesData textEncodingName:(NSString * _Nullable)textEncodingName MIMEType:(NSString * _Nullable)MIMEType; +- (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData; /*! * Show the user that the new update's release notes could not be downloaded diff --git a/Sparkle/SUAppcast.m b/Sparkle/SUAppcast.m index de9e9368..c4056e24 100644 --- a/Sparkle/SUAppcast.m +++ b/Sparkle/SUAppcast.m @@ -15,7 +15,7 @@ #import "SULocalizations.h" #import "SPUXPCServiceInfo.h" #import "SPUURLDownload.h" -#import "SPUTemporaryDownload.h" +#import "SPUDownloadData.h" #ifdef _APPKITDEFINES_H #error This is a "core" class and should NOT import AppKit @@ -77,10 +77,10 @@ [request setValue:@"application/rss+xml,*/*;q=0.1" forHTTPHeaderField:@"Accept"]; - SPUDownloadURLWithRequest(request, ^(SPUTemporaryDownload * _Nullable download, NSError * _Nullable error) { - if (download != nil) { + SPUDownloadURLWithRequest(request, ^(SPUDownloadData * _Nullable downloadData, NSError * _Nullable error) { + if (downloadData != nil) { NSError *parseError = nil; - NSArray *appcastItems = [self parseAppcastItemsFromXMLData:download.data error:&parseError]; + NSArray *appcastItems = [self parseAppcastItemsFromXMLData:downloadData.data error:&parseError]; if (appcastItems != nil) { self.items = appcastItems; diff --git a/Sparkle/SUUIBasedUpdateDriver.m b/Sparkle/SUUIBasedUpdateDriver.m index a0968b16..df97fcb7 100644 --- a/Sparkle/SUUIBasedUpdateDriver.m +++ b/Sparkle/SUUIBasedUpdateDriver.m @@ -15,7 +15,7 @@ #import "SUAppcastItem.h" #import "SUErrors.h" #import "SPUURLDownload.h" -#import "SPUTemporaryDownload.h" +#import "SPUDownloadData.h" #ifdef _APPKITDEFINES_H #error This is a "core" class and should NOT import AppKit @@ -145,10 +145,9 @@ NSURLRequest *request = [NSURLRequest requestWithURL:updateItem.releaseNotesURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30]; id userDriver = self.userDriver; - SPUDownloadURLWithRequest(request, ^(SPUTemporaryDownload * _Nullable download, NSError * _Nullable error) { - if (download != nil) { - SPUTemporaryDownload *nonnullDownload = download; - [userDriver showUpdateReleaseNotesWithData:nonnullDownload.data textEncodingName:nonnullDownload.textEncoding MIMEType:nonnullDownload.MIMEType]; + SPUDownloadURLWithRequest(request, ^(SPUDownloadData * _Nullable downloadData, NSError * _Nullable error) { + if (downloadData != nil) { + [userDriver showUpdateReleaseNotesWithDownloadData:(SPUDownloadData * _Nonnull)downloadData]; } else { [userDriver showUpdateReleaseNotesFailedToDownloadWithError:(NSError * _Nonnull)error]; } diff --git a/Sparkle/SUUpdateAlert.h b/Sparkle/SUUpdateAlert.h index ca16978c..bac9ac0a 100644 --- a/Sparkle/SUUpdateAlert.h +++ b/Sparkle/SUUpdateAlert.h @@ -15,7 +15,7 @@ @protocol SUUpdateAlertDelegate; -@class SUAppcastItem, SUHost; +@class SUAppcastItem, SPUDownloadData, SUHost; @interface SUUpdateAlert : NSWindowController @property (nonatomic, weak, readonly) id versionDisplayer; @@ -24,7 +24,7 @@ - (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost versionDisplayer:(id )aVersionDisplayer resumableCompletionBlock:(void (^)(SUInstallUpdateStatus))block; -- (void)showUpdateReleaseNotesWithData:(NSData *)releaseNotesData textEncodingName:(NSString *)textEncodingName MIMEType:(NSString *)MIMEType; +- (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData; - (void)showReleaseNotesFailedToDownload; - (IBAction)installUpdate:sender; diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index dc502a11..1a06a29d 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -19,6 +19,7 @@ #import "SULog.h" #import "SULocalizations.h" #import "SUAppcastItem.h" +#import "SPUDownloadData.h" #import "SPUApplicationInfo.h" #import "SPUUpdaterSettings.h" @@ -199,16 +200,16 @@ } } -- (void)showUpdateReleaseNotesWithData:(NSData *)releaseNotesData textEncodingName:(NSString * _Nullable)textEncodingName MIMEType:(NSString * _Nullable)MIMEType +- (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData { if (!self.webViewFinishedLoading) { NSURL *baseURL = self.updateItem.releaseNotesURL.URLByDeletingLastPathComponent; // If a MIME type isn't provided, we will pick html as the default, as opposed to plain text. Questionable decision.. - NSString *chosenMIMEType = (MIMEType != nil) ? MIMEType : @"text/html"; + NSString *chosenMIMEType = (downloadData.MIMEType != nil) ? downloadData.MIMEType : @"text/html"; // We'll pick utf-8 as the default text encoding name if one isn't provided which I think is reasonable - NSString *chosenTextEncodingName = (textEncodingName != nil) ? textEncodingName : @"utf-8"; + NSString *chosenTextEncodingName = (downloadData.textEncodingName != nil) ? downloadData.textEncodingName : @"utf-8"; - [[self.releaseNotesView mainFrame] loadData:releaseNotesData MIMEType:chosenMIMEType textEncodingName:chosenTextEncodingName baseURL:baseURL]; + [[self.releaseNotesView mainFrame] loadData:downloadData.data MIMEType:chosenMIMEType textEncodingName:chosenTextEncodingName baseURL:baseURL]; } } diff --git a/Sparkle/Sparkle.h b/Sparkle/Sparkle.h index fa875bee..dddd429a 100644 --- a/Sparkle/Sparkle.h +++ b/Sparkle/Sparkle.h @@ -27,6 +27,7 @@ #import "SPUStandardUserDriver.h" #import "SPUStandardUserDriverDelegate.h" #import "SPUUserDriverCoreComponent.h" +#import "SPUDownloadData.h" #import "SUUpdater.h" // deprecated diff --git a/TemporaryDownloader/SPUTemporaryDownload.h b/TemporaryDownloader/SPUTemporaryDownload.h deleted file mode 100644 index a91c507b..00000000 --- a/TemporaryDownloader/SPUTemporaryDownload.h +++ /dev/null @@ -1,23 +0,0 @@ -// -// SPUTemporaryDownload.h -// Sparkle -// -// Created by Mayur Pawashe on 8/10/16. -// Copyright © 2016 Sparkle Project. All rights reserved. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -@interface SPUTemporaryDownload : NSObject - -- (instancetype)initWithData:(NSData *)data textEncoding:(NSString * _Nullable)textEncoding MIMEType:(NSString * _Nullable)MIMEType; - -@property (nonatomic, readonly) NSData *data; -@property (nonatomic, readonly, nullable, copy) NSString *textEncoding; -@property (nonatomic, readonly, nullable, copy) NSString *MIMEType; - -@end - -NS_ASSUME_NONNULL_END diff --git a/TemporaryDownloader/SPUTemporaryDownload.m b/TemporaryDownloader/SPUTemporaryDownload.m deleted file mode 100644 index a746b515..00000000 --- a/TemporaryDownloader/SPUTemporaryDownload.m +++ /dev/null @@ -1,63 +0,0 @@ -// -// SPUTemporaryDownload.m -// Sparkle -// -// Created by Mayur Pawashe on 8/10/16. -// Copyright © 2016 Sparkle Project. All rights reserved. -// - -#import "SPUTemporaryDownload.h" - -static NSString *SPUTemporaryDownloadDataKey = @"SPUTemporaryDownloadData"; -static NSString *SPUTemporaryDownloadTextEncodingKey = @"SPUTemporaryDownloadTextEncoding"; -static NSString *SPUTemporaryDownloadMIMETypeKey = @"SPUTemporaryDownloadMIMEType"; - -@implementation SPUTemporaryDownload - -@synthesize data = _data; -@synthesize textEncoding = _textEncoding; -@synthesize MIMEType = _MIMEType; - -+ (BOOL)supportsSecureCoding -{ - return YES; -} - -- (instancetype)initWithData:(NSData *)data textEncoding:(NSString * _Nullable)textEncoding MIMEType:(NSString *)MIMEType -{ - self = [super init]; - if (self != nil) { - _data = data; - _textEncoding = textEncoding; - _MIMEType = MIMEType; - } - return self; -} - -- (void)encodeWithCoder:(NSCoder *)coder -{ - [coder encodeObject:self.data forKey:SPUTemporaryDownloadDataKey]; - - if (self.textEncoding != nil) { - [coder encodeObject:self.textEncoding forKey:SPUTemporaryDownloadTextEncodingKey]; - } - - if (self.MIMEType != nil) { - [coder encodeObject:self.MIMEType forKey:SPUTemporaryDownloadMIMETypeKey]; - } -} - -- (nullable instancetype)initWithCoder:(NSCoder *)decoder -{ - NSData *data = [decoder decodeObjectOfClass:[NSData class] forKey:SPUTemporaryDownloadDataKey]; - if (data == nil) { - return nil; - } - - NSString *textEncoding = [decoder decodeObjectOfClass:[NSString class] forKey:SPUTemporaryDownloadTextEncodingKey]; - NSString *MIMEType = [decoder decodeObjectOfClass:[NSString class] forKey:SPUTemporaryDownloadMIMETypeKey]; - - return [self initWithData:data textEncoding:textEncoding MIMEType:MIMEType]; -} - -@end diff --git a/TemporaryDownloader/SUTemporaryDownloader.m b/TemporaryDownloader/SUTemporaryDownloader.m index 6efdd6c4..d94c241f 100644 --- a/TemporaryDownloader/SUTemporaryDownloader.m +++ b/TemporaryDownloader/SUTemporaryDownloader.m @@ -7,14 +7,14 @@ // #import "SUTemporaryDownloader.h" -#import "SPUTemporaryDownload.h" +#import "SPUDownloadData.h" #import "SPUURLRequest.h" #import "SUErrors.h" #import "SUConstants.h" @interface SUTemporaryDownloader () -@property (nonatomic, copy) void (^completionBlock)(SPUTemporaryDownload * _Nullable download, NSError * _Nullable error); +@property (nonatomic, copy) void (^completionBlock)(SPUDownloadData * _Nullable downloadData, NSError * _Nullable error); @property (nonatomic) NSURLDownload *download; @property (nonatomic, copy) NSString *downloadFilename; @property (nonatomic) NSURLResponse *response; @@ -28,7 +28,7 @@ @synthesize downloadFilename = _downloadFilename; @synthesize response = _response; -- (void)startDownloadWithRequest:(SPUURLRequest *)request completion:(void (^)(SPUTemporaryDownload * _Nullable download, NSError * _Nullable error))completionBlock +- (void)startDownloadWithRequest:(SPUURLRequest *)request completion:(void (^)(SPUDownloadData * _Nullable downloadData, NSError * _Nullable error))completionBlock { dispatch_async(dispatch_get_main_queue(), ^{ self.completionBlock = completionBlock; @@ -78,8 +78,8 @@ NSData *data = [NSData dataWithContentsOfFile:self.downloadFilename]; if (data != nil) { // See SUPersistentDownloader as to why sending the NSURLResponse object over is not a good idea - SPUTemporaryDownload *download = [[SPUTemporaryDownload alloc] initWithData:data textEncoding:self.response.textEncodingName MIMEType:self.response.MIMEType]; - self.completionBlock(download, nil); + SPUDownloadData *downloadData = [[SPUDownloadData alloc] initWithData:data textEncodingName:self.response.textEncodingName MIMEType:self.response.MIMEType]; + self.completionBlock(downloadData, nil); } else { self.completionBlock(nil, [NSError errorWithDomain:SUSparkleErrorDomain code:SUDownloadError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to read temporary downloaded data from %@", self.downloadFilename] }]); } diff --git a/TemporaryDownloader/SUTemporaryDownloaderProtocol.h b/TemporaryDownloader/SUTemporaryDownloaderProtocol.h index c6fccf71..27c4b43c 100644 --- a/TemporaryDownloader/SUTemporaryDownloaderProtocol.h +++ b/TemporaryDownloader/SUTemporaryDownloaderProtocol.h @@ -11,12 +11,12 @@ NS_ASSUME_NONNULL_BEGIN @class SPUURLRequest; -@class SPUTemporaryDownload; +@class SPUDownloadData; // The protocol that this service will vend as its API. This header file will also need to be visible to the process hosting the service. @protocol SUTemporaryDownloaderProtocol -- (void)startDownloadWithRequest:(SPUURLRequest *)request completion:(void (^)(SPUTemporaryDownload * _Nullable download, NSError * _Nullable error))completionBlock; +- (void)startDownloadWithRequest:(SPUURLRequest *)request completion:(void (^)(SPUDownloadData * _Nullable downloadData, NSError * _Nullable error))completionBlock; @end diff --git a/TestApplication/SUPopUpTitlebarUserDriver.m b/TestApplication/SUPopUpTitlebarUserDriver.m index f0b31956..1e5a44f3 100644 --- a/TestApplication/SUPopUpTitlebarUserDriver.m +++ b/TestApplication/SUPopUpTitlebarUserDriver.m @@ -10,6 +10,7 @@ #import "SPUStandardUserDriverDelegate.h" #import "SPUUserDriverCoreComponent.h" #import "SUInstallUpdateViewController.h" +#import "SPUDownloadData.h" @interface SUPopUpTitlebarUserDriver() @@ -178,7 +179,7 @@ }); } -- (void)showUpdateReleaseNotesWithData:(NSData *)__unused releaseNotesData textEncodingName:(NSString * _Nullable)__unused textEncodingName MIMEType:(NSString * _Nullable)__unused MIMEType +- (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)__unused downloadData { // todo: this should really be implemented } diff --git a/Tests/SUUpdaterTest.m b/Tests/SUUpdaterTest.m index 680d32d4..3c7a9d4c 100644 --- a/Tests/SUUpdaterTest.m +++ b/Tests/SUUpdaterTest.m @@ -33,7 +33,7 @@ - (void)showResumableUpdateFoundWithAppcastItem:(SUAppcastItem *)__unused appcastItem reply:(void (^)(SUInstallUpdateStatus))__unused reply {} -- (void)showUpdateReleaseNotesWithData:(NSData *)__unused releaseNotesData textEncodingName:(NSString * _Nullable)__unused textEncodingName MIMEType:(NSString * _Nullable)__unused MIMEType {} +- (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)__unused downloadData {} - (void)showUpdateReleaseNotesFailedToDownloadWithError:(NSError *)__unused error {} diff --git a/sparkle-cli/SPUCommandLineUserDriver.m b/sparkle-cli/SPUCommandLineUserDriver.m index 512308ea..6990c748 100644 --- a/sparkle-cli/SPUCommandLineUserDriver.m +++ b/sparkle-cli/SPUCommandLineUserDriver.m @@ -9,6 +9,7 @@ #import "SPUCommandLineUserDriver.h" #import #import "SPUApplicationInfo.h" +#import "SPUDownloadData.h" #define SCHEDULED_UPDATE_TIMER_THRESHOLD 2.0 // seconds @@ -54,39 +55,6 @@ }); } -- (void)idleOnUpdateChecks:(BOOL)shouldIdleOnUpdateChecks -{ - dispatch_async(dispatch_get_main_queue(), ^{ - if (shouldIdleOnUpdateChecks) { - fprintf(stderr, "Error: Automatic update checking is disabled.\n"); - exit(EXIT_FAILURE); - } - - [self.coreComponent idleOnUpdateChecks:shouldIdleOnUpdateChecks]; - }); -} - -- (void)startUpdateCheckTimerWithNextTimeInterval:(NSTimeInterval)timeInterval reply:(void (^)(SUUpdateCheckTimerStatus))reply -{ - dispatch_async(dispatch_get_main_queue(), ^{ - if (timeInterval > SCHEDULED_UPDATE_TIMER_THRESHOLD) { - if (self.verbose) { - fprintf(stderr, "Too early to check for new updates. Next check is in %f seconds. Exiting.\n", timeInterval); - } - exit(EXIT_SUCCESS); - } else { - [self.coreComponent startUpdateCheckTimerWithNextTimeInterval:timeInterval reply:reply]; - } - }); -} - -- (void)invalidateUpdateCheckTimer -{ - dispatch_async(dispatch_get_main_queue(), ^{ - [self.coreComponent invalidateUpdateCheckTimer]; - }); -} - - (void)requestUpdatePermissionWithSystemProfile:(NSArray *)__unused systemProfile reply:(void (^)(SPUUpdatePermission *))reply { dispatch_async(dispatch_get_main_queue(), ^{ @@ -187,25 +155,25 @@ }); } -- (void)showUpdateReleaseNotesWithData:(NSData *)releaseNotesData textEncodingName:(NSString * _Nullable)textEncodingName MIMEType:(NSString * _Nullable)MIMEType +- (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData { dispatch_async(dispatch_get_main_queue(), ^{ if (self.verbose) { - if ([MIMEType isEqualToString:@"text/plain"]) { + if (downloadData.MIMEType != nil && [downloadData.MIMEType isEqualToString:@"text/plain"]) { NSStringEncoding encoding; - if (textEncodingName == nil) { + if (downloadData.textEncodingName == nil) { encoding = NSUTF8StringEncoding; } else { - CFStringEncoding cfEncoding = CFStringConvertIANACharSetNameToEncoding((CFStringRef)textEncodingName); + CFStringEncoding cfEncoding = CFStringConvertIANACharSetNameToEncoding((CFStringRef)downloadData.textEncodingName); if (cfEncoding != kCFStringEncodingInvalidId) { encoding = CFStringConvertEncodingToNSStringEncoding(cfEncoding); } else { encoding = NSUTF8StringEncoding; } } - [self displayPlainTextReleaseNotes:releaseNotesData encoding:encoding]; + [self displayPlainTextReleaseNotes:downloadData.data encoding:encoding]; } else { - [self displayHTMLReleaseNotes:releaseNotesData]; + [self displayHTMLReleaseNotes:downloadData.data]; } } });