From 32d9fd6526b4ed84366086580f4e9e596a9e4ffb Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 13 Aug 2016 20:54:52 -0400 Subject: [PATCH] Add flag for custom feed URL to sparkle-cli This may be useful if user defaults can't be relied on for the feed URL. For example, if an app is sandboxed, its user defaults may differ from the defaults sparkle-cli looks up. --- Sparkle/SPUUpdaterDelegate.h | 2 +- sparkle-cli/SPUCommandLineDriver.h | 2 +- sparkle-cli/SPUCommandLineDriver.m | 12 +++++++++--- sparkle-cli/main.m | 14 +++++++++++++- 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/Sparkle/SPUUpdaterDelegate.h b/Sparkle/SPUUpdaterDelegate.h index 18c6d35f..0ff8775d 100644 --- a/Sparkle/SPUUpdaterDelegate.h +++ b/Sparkle/SPUUpdaterDelegate.h @@ -88,7 +88,7 @@ SU_EXPORT extern NSString *const SUUpdaterAppcastNotificationKey; \param updater The updater instance. */ -- (NSString *)feedURLStringForUpdater:(SPUUpdater *)updater; +- (nullable NSString *)feedURLStringForUpdater:(SPUUpdater *)updater; /*! Returns whether Sparkle should prompt the user about automatic update checks. diff --git a/sparkle-cli/SPUCommandLineDriver.h b/sparkle-cli/SPUCommandLineDriver.h index 8af60ae8..60cea990 100644 --- a/sparkle-cli/SPUCommandLineDriver.h +++ b/sparkle-cli/SPUCommandLineDriver.h @@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN @interface SPUCommandLineDriver : NSObject -- (nullable instancetype)initWithUpdateBundlePath:(NSString *)updateBundlePath applicationBundlePath:(nullable NSString *)applicationBundlePath updatePermission:(nullable SPUUpdatePermission *)updatePermission deferInstallation:(BOOL)deferInstallation interactiveInstallation:(BOOL)interactiveInstallation verbose:(BOOL)verbose; +- (nullable instancetype)initWithUpdateBundlePath:(NSString *)updateBundlePath applicationBundlePath:(nullable NSString *)applicationBundlePath customFeedURL:(nullable NSString *)customFeedURL updatePermission:(nullable SPUUpdatePermission *)updatePermission deferInstallation:(BOOL)deferInstallation interactiveInstallation:(BOOL)interactiveInstallation verbose:(BOOL)verbose; - (void)runAndCheckForUpdatesNow:(BOOL)checkForUpdatesNow; diff --git a/sparkle-cli/SPUCommandLineDriver.m b/sparkle-cli/SPUCommandLineDriver.m index 638a8e87..13c50362 100644 --- a/sparkle-cli/SPUCommandLineDriver.m +++ b/sparkle-cli/SPUCommandLineDriver.m @@ -18,6 +18,7 @@ void _SULogDisableStandardErrorStream(void); @property (nonatomic, readonly) BOOL verbose; @property (nonatomic) BOOL probingForUpdates; @property (nonatomic, readonly) BOOL interactive; +@property (nonatomic, copy, readonly, nullable) NSString *customFeedURL; @end @@ -27,8 +28,9 @@ void _SULogDisableStandardErrorStream(void); @synthesize verbose = _verbose; @synthesize probingForUpdates = _probingForUpdates; @synthesize interactive = _interactive; +@synthesize customFeedURL = _customFeedURL; -- (instancetype)initWithUpdateBundlePath:(NSString *)updateBundlePath applicationBundlePath:(nullable NSString *)applicationBundlePath updatePermission:(nullable SPUUpdatePermission *)updatePermission deferInstallation:(BOOL)deferInstallation interactiveInstallation:(BOOL)interactiveInstallation verbose:(BOOL)verbose +- (instancetype)initWithUpdateBundlePath:(NSString *)updateBundlePath applicationBundlePath:(nullable NSString *)applicationBundlePath customFeedURL:(nullable NSString *)customFeedURL updatePermission:(nullable SPUUpdatePermission *)updatePermission deferInstallation:(BOOL)deferInstallation interactiveInstallation:(BOOL)interactiveInstallation verbose:(BOOL)verbose { self = [super init]; if (self != nil) { @@ -49,6 +51,7 @@ void _SULogDisableStandardErrorStream(void); _verbose = verbose; _interactive = interactiveInstallation; + _customFeedURL = [customFeedURL copy]; #ifndef DEBUG _SULogDisableStandardErrorStream(); @@ -83,6 +86,11 @@ void _SULogDisableStandardErrorStream(void); return self.interactive; } +- (nullable NSString *)feedURLStringForUpdater:(SPUUpdater *)__unused updater +{ + return self.customFeedURL; +} + // In case we find an update during probing, otherwise we leave this to the user driver - (void)updater:(SPUUpdater *)__unused updater didFindValidUpdate:(SUAppcastItem *)__unused item { @@ -94,7 +102,6 @@ void _SULogDisableStandardErrorStream(void); } } -// In case we fail during probing, otherwise we leave error handling to the user driver - (void)updaterDidNotFindUpdate:(SPUUpdater *)__unused updater __attribute__((noreturn)) { if (self.verbose) { @@ -103,7 +110,6 @@ void _SULogDisableStandardErrorStream(void); exit(EXIT_FAILURE); } -// In case we fail during probing, otherwise we leave error handling to the user driver - (void)updater:(SPUUpdater *)__unused updater didAbortWithError:(NSError *)error __attribute__((noreturn)) { if (self.verbose) { diff --git a/sparkle-cli/main.m b/sparkle-cli/main.m index 0c248f8d..ac92ff3a 100644 --- a/sparkle-cli/main.m +++ b/sparkle-cli/main.m @@ -19,6 +19,7 @@ #define SEND_PROFILE_FLAG "send-profile" #define PROBE_FLAG "probe" #define INTERACTIVE_FLAG "interactive" +#define FEED_URL_FLAG "feed-url" static void printUsage(char **argv) { @@ -35,6 +36,7 @@ static void printUsage(char **argv) fprintf(stderr, " --%s\n Path to the application to watch for termination and to relaunch.\n If not provided, this is assumed to be the same as the bundle.\n", APPLICATION_FLAG); fprintf(stderr, " --%s\n Immediately checks for updates to install.\n Without this, updates are checked only when needed on a scheduled basis.\n", CHECK_NOW_FLAG); fprintf(stderr, " --%s\n Probe for updates. Check if any updates are available but do not install.\n An exit status of 0 is returned if a new update is available.\n", PROBE_FLAG); + fprintf(stderr, " --%s\n URL for appcast feed. This URL will be used for the feed instead of the one\n in the bundle's Info.plist or in the bundle's user defaults.\n", FEED_URL_FLAG); fprintf(stderr, " --%s\n Allows prompting the user for an authorization dialog prompt if the\n installer needs elevated privileges, or allows performing an interactive\n installer package.\n", INTERACTIVE_FLAG); fprintf(stderr, " --%s\n If update permission is requested, this enables automatic update checks.\n Note that this behavior may overwrite the user's defaults for the bundle.\n This option has no effect if --%s is passed, or if the\n user has replied to this request already, or if the developer configured\n to skip it.\n", GRANT_AUTOMATIC_CHECKING_FLAG, CHECK_NOW_FLAG); fprintf(stderr, " --%s\n Choose to send system profile information if update permission is requested.\n This option can only take effect if --%s is passed.\n", SEND_PROFILE_FLAG, GRANT_AUTOMATIC_CHECKING_FLAG); @@ -53,6 +55,7 @@ int main(int argc, char **argv) struct option longOptions[] = { {APPLICATION_FLAG, required_argument, NULL, 0}, + {FEED_URL_FLAG, required_argument, NULL, 0}, {DEFER_FLAG, no_argument, NULL, 0}, {VERBOSE_FLAG, no_argument, NULL, 0}, {CHECK_NOW_FLAG, no_argument, NULL, 0}, @@ -64,6 +67,7 @@ int main(int argc, char **argv) }; NSString *applicationPath = nil; + NSString *feedURL = nil; BOOL deferInstall = NO; BOOL verbose = NO; BOOL checkForUpdatesNow = NO; @@ -88,6 +92,14 @@ int main(int argc, char **argv) printUsage(argv); return EXIT_FAILURE; } + } else if (strcmp(FEED_URL_FLAG, longOptions[optionIndex].name) == 0) { + assert(optarg != NULL); + + feedURL = [[NSString alloc] initWithUTF8String:optarg]; + if (feedURL == nil) { + printUsage(argv); + return EXIT_FAILURE; + } } else if (strcmp(DEFER_FLAG, longOptions[optionIndex].name) == 0) { deferInstall = YES; } else if (strcmp(VERBOSE_FLAG, longOptions[optionIndex].name) == 0) { @@ -134,7 +146,7 @@ int main(int argc, char **argv) updatePermission = [SPUUpdatePermission updatePermissionWithChoice:SUAutomaticallyCheck sendProfile:sendProfile]; } - SPUCommandLineDriver *driver = [[SPUCommandLineDriver alloc] initWithUpdateBundlePath:updatePath applicationBundlePath:applicationPath updatePermission:updatePermission deferInstallation:deferInstall interactiveInstallation:interactive verbose:verbose]; + SPUCommandLineDriver *driver = [[SPUCommandLineDriver alloc] initWithUpdateBundlePath:updatePath applicationBundlePath:applicationPath customFeedURL:feedURL updatePermission:updatePermission deferInstallation:deferInstall interactiveInstallation:interactive verbose:verbose]; if (driver == nil) { fprintf(stderr, "Error: Failed to initialize updater. Are the bundle paths provided valid?\n"); return EXIT_FAILURE;