Files
Sparkle/sparkle-cli/SUCommandLineDriver.m
T
Zorg a4157e5989 Add checknow flag to check for updates immediately
What is new is that we can now disable checking for updates immediately.
sparkle-cli is not intended to be run for a long time, so if the next update check is not soon, we exit.
A client can now launch sparkle-cli without having to necessarily check for updates, so that they don't check for updates too soon.
2016-05-01 02:46:22 -04:00

77 lines
2.4 KiB
Objective-C

//
// SUCommandLineDriver.m
// sparkle-cli
//
// Created by Mayur Pawashe on 4/10/16.
// Copyright © 2016 Sparkle Project. All rights reserved.
//
#import "SUCommandLineDriver.h"
#import <Sparkle/Sparkle.h>
#import "SUCommandLineUserDriver.h"
@interface SUCommandLineDriver () <SUUpdaterDelegate>
@property (nonatomic, readonly) SUUpdater *updater;
@property (nonatomic, readonly) NSString *applicationBundlePath;
@end
@implementation SUCommandLineDriver
@synthesize updater = _updater;
@synthesize applicationBundlePath = _applicationBundlePath;
- (instancetype)initWithUpdateBundlePath:(NSString *)updateBundlePath applicationBundlePath:(nullable NSString *)applicationBundlePath deferInstallation:(BOOL)deferInstallation verbose:(BOOL)verbose
{
self = [super init];
if (self != nil) {
NSBundle *updateBundle = [NSBundle bundleWithPath:updateBundlePath];
if (updateBundle == nil) {
return nil;
}
NSBundle *applicationBundle = nil;
if (applicationBundlePath == nil) {
applicationBundle = updateBundle;
} else {
applicationBundle = [NSBundle bundleWithPath:(NSString * _Nonnull)applicationBundlePath];
if (applicationBundle == nil) {
return nil;
}
}
_applicationBundlePath = applicationBundle.bundlePath;
id <SUUserDriver> userDriver = [[SUCommandLineUserDriver alloc] initWithApplicationBundle:applicationBundle deferInstallation:deferInstallation verbose:verbose];
_updater = [[SUUpdater alloc] initWithHostBundle:updateBundle userDriver:userDriver delegate:self];
}
return self;
}
- (BOOL)updaterShouldInheritInstallPrivileges:(SUUpdater *)__unused updater
{
return YES;
}
- (NSString *)pathToRelaunchForUpdater:(SUUpdater *)__unused updater
{
return self.applicationBundlePath;
}
- (void)runAndCheckForUpdatesNow:(BOOL)checkForUpdatesNow
{
if (checkForUpdatesNow) {
// When we start the updater, this scheduled check will start afterwards too
[self.updater checkForUpdates];
}
NSError *updaterError = nil;
if (![self.updater startUpdater:&updaterError]) {
fprintf(stderr, "Error: Failed to initialize updater with error (%ld): %s\n", updaterError.code, updaterError.localizedDescription.UTF8String);
exit(EXIT_FAILURE);
}
}
@end