From 07c773ace28f0d69cba25e6b41d7e62f5f6039bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kornel=20Lesi=C5=84ski?= Date: Thu, 23 Jul 2015 11:28:20 +0100 Subject: [PATCH] Move sparkleBundle from SUHost to SUUpdater --- Sparkle/SUBasicUpdateDriver.m | 2 +- Sparkle/SUHost.h | 1 - Sparkle/SUHost.m | 10 ++-------- Sparkle/SUUpdater.h | 1 + Sparkle/SUUpdater.m | 11 ++++++++++- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index 82d9b56b..c092f49c 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -419,7 +419,7 @@ [updaterDelegate updater:self.updater willInstallUpdate:self.updateItem]; } - NSBundle *sparkleBundle = self.host.sparkleBundle; + NSBundle *sparkleBundle = self.updater.sparkleBundle; // Copy the relauncher into a temporary directory so we can get to it after the new version's installed. // Only the paranoid survive: if there's already a stray copy of relaunch there, we would have problems. diff --git a/Sparkle/SUHost.h b/Sparkle/SUHost.h index 6fc82ee6..92925e7d 100644 --- a/Sparkle/SUHost.h +++ b/Sparkle/SUHost.h @@ -14,7 +14,6 @@ @interface SUHost : NSObject @property (strong, readonly) NSBundle *bundle; -@property (strong, readonly) NSBundle *sparkleBundle; + (NSString *)systemVersionString; diff --git a/Sparkle/SUHost.m b/Sparkle/SUHost.m index 496f1760..ea5cf66b 100644 --- a/Sparkle/SUHost.m +++ b/Sparkle/SUHost.m @@ -25,7 +25,7 @@ typedef struct { @interface SUHost () -@property (strong, readwrite) NSBundle *bundle, *sparkleBundle; +@property (strong, readwrite) NSBundle *bundle; @property (copy) NSString *defaultsDomain; @property (assign) BOOL usesStandardUserDefaults; @@ -33,7 +33,7 @@ typedef struct { @implementation SUHost -@synthesize bundle, sparkleBundle; +@synthesize bundle; @synthesize defaultsDomain; @synthesize usesStandardUserDefaults; @@ -47,12 +47,6 @@ typedef struct { SULog(@"Error: the bundle being updated at %@ has no %@! This will cause preference read/write to not work properly.", self.bundle, kCFBundleIdentifierKey); } - self.sparkleBundle = [NSBundle bundleForClass:[self class]]; - if (!self.sparkleBundle) { - SULog(@"Error: SUHost can't find Sparkle.framework it belongs to"); - return nil; - } - self.defaultsDomain = [self.bundle objectForInfoDictionaryKey:SUDefaultsDomainKey]; if (!self.defaultsDomain) { self.defaultsDomain = [self.bundle bundleIdentifier]; diff --git a/Sparkle/SUUpdater.h b/Sparkle/SUUpdater.h index 3ac4828a..ce07a142 100644 --- a/Sparkle/SUUpdater.h +++ b/Sparkle/SUUpdater.h @@ -33,6 +33,7 @@ SU_EXPORT @interface SUUpdater : NSObject - (instancetype)initForBundle:(NSBundle *)bundle; @property (readonly, strong) NSBundle *hostBundle; +@property (strong, readonly) NSBundle *sparkleBundle; @property BOOL automaticallyChecksForUpdates; diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index 2235f32f..5e0557f0 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -29,6 +29,8 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification @interface SUUpdater () @property (strong) NSTimer *checkTimer; +@property (strong) NSBundle *sparkleBundle; + - (instancetype)initForBundle:(NSBundle *)bundle; - (void)startUpdateCycle; - (void)checkForUpdatesWithDriver:(SUUpdateDriver *)updateDriver; @@ -54,6 +56,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification @synthesize httpHeaders; @synthesize driver; @synthesize host; +@synthesize sparkleBundle; static NSMutableDictionary *sharedUpdaters = nil; static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObservationContext"; @@ -80,6 +83,12 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults self = [super init]; if (bundle == nil) bundle = [NSBundle mainBundle]; + self.sparkleBundle = [NSBundle bundleForClass:[self class]]; + if (!self.sparkleBundle) { + SULog(@"Error: SUUpdater can't find Sparkle.framework it belongs to"); + return nil; + } + // Register as observer straight away to avoid exceptions on -dealloc when -unregisterAsObserver is called: if (self) { [self registerAsObserver]; @@ -465,7 +474,7 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults return customUserAgentString; } - NSString *version = [self.host.sparkleBundle objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]; + NSString *version = [self.sparkleBundle objectForInfoDictionaryKey:(__bridge NSString *)kCFBundleVersionKey]; NSString *userAgent = [NSString stringWithFormat:@"%@/%@ Sparkle/%@", [self.host name], [self.host displayVersion], version ? version : @"?"]; NSData *cleanedAgent = [userAgent dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; return [[NSString alloc] initWithData:cleanedAgent encoding:NSASCIIStringEncoding];