Skip to content

Commit

Permalink
Testing of plugin installer
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcus S. Zarra committed Jun 5, 2010
1 parent c311a9f commit a7c949e
Show file tree
Hide file tree
Showing 15 changed files with 487 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Daemon/Classes/AppDelegate.h
Expand Up @@ -26,7 +26,7 @@
// OTHER DEALINGS IN THE SOFTWARE. // OTHER DEALINGS IN THE SOFTWARE.
// //


@interface AppDelegate : NSObject <NSApplicationDelegate> @interface AppDelegate : NSObject
{ {
NSStatusItem *statusItem; NSStatusItem *statusItem;
} }
Expand Down
68 changes: 54 additions & 14 deletions Daemon/Classes/ZSyncDaemon.m
@@ -1,7 +1,22 @@
#import "ZSyncDaemon.h" #import "ZSyncDaemon.h"


#define ZSyncVersionNumber @"ZSyncVersionNumber"

@implementation ZSyncDaemon @implementation ZSyncDaemon


+ (NSBundle*)myBundle
{
NSString *path = [[NSBundle mainBundle] pathForResource:@"ZSyncInstaller" ofType:@"bundle"];
return [NSBundle bundleWithPath:path];
}

+ (NSBundle*)daemonBundle
{
NSBundle *myBundle = [self myBundle];
NSString *path = [myBundle pathForResource:@"ZSyncDaemon" ofType:@"app"];
return [NSBundle bundleWithPath:path];
}

+ (NSString*)basePath + (NSString*)basePath
{ {
//Build our standard install path //Build our standard install path
Expand Down Expand Up @@ -56,10 +71,7 @@ + (BOOL)isDaemonInstalled:(NSError**)error;
if (error) { if (error) {
return NO; return NO;
} }
if (![[NSFileManager defaultManager] createDirectoryAtPath:basePath if (![[NSFileManager defaultManager] createDirectoryAtPath:basePath withIntermediateDirectories:YES attributes:nil error:error]) {
withIntermediateDirectories:YES
attributes:nil
error:error]) {
return NO; return NO;
} }
} }
Expand All @@ -69,22 +81,36 @@ + (BOOL)isDaemonInstalled:(NSError**)error;


+ (BOOL)installDaemon:(NSError**)error; + (BOOL)installDaemon:(NSError**)error;
{ {
NSString *myBundlePath = [[NSBundle mainBundle] bundlePath]; NSString *basePath = [self basePath];
NSString *applicationPath = [self applicationPath];
NSFileManager *fileManager = [NSFileManager defaultManager]; NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL isDirectory = NO;

if (![fileManager fileExistsAtPath:basePath isDirectory:&isDirectory]) {
if (![[NSFileManager defaultManager] createDirectoryAtPath:basePath withIntermediateDirectories:YES attributes:nil error:error]) {
return NO;
}
} else if (!isDirectory) {
NSString *errorDesc = [NSString stringWithFormat:@"Unknown file at base installation path: %@", basePath];
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:errorDesc forKey:NSLocalizedDescriptionKey];
*error = [NSError errorWithDomain:@"ZSync" code:1123 userInfo:dictionary];
return NO;
}

NSString *myBundlePath = [[self daemonBundle] bundlePath];
NSString *applicationPath = [self applicationPath];
return [fileManager copyItemAtPath:myBundlePath toPath:applicationPath error:error]; return [fileManager copyItemAtPath:myBundlePath toPath:applicationPath error:error];
} }


+ (BOOL)stopDaemon:(NSError**)error + (BOOL)stopDaemon:(NSError**)error
{ {
NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleExecutable"]; NSString *appName = [[[self myBundle] infoDictionary] objectForKey:@"CFBundleExecutable"];
NSString *command = [NSString stringWithFormat:@"tell application \"%@\" to quit", appName]; NSString *command = [NSString stringWithFormat:@"tell application \"%@\" to quit", appName];
NSAppleScript *quitScript; NSAppleScript *quitScript;
quitScript = [[NSAppleScript alloc] initWithSource:command]; quitScript = [[NSAppleScript alloc] initWithSource:command];
NSDictionary *errorDict = nil; NSDictionary *errorDict = nil;
// TODO: This should be turned into an NSError response // TODO: This should be turned into an NSError response
if (![quitScript executeAndReturnError:&errorDict]) { if (![quitScript executeAndReturnError:&errorDict]) {
ALog(@"Failure. What does it look like: %@", errorDict); NSAssert1(NO, @"Failure. What does it look like: %@", errorDict);
[quitScript release], quitScript = nil; [quitScript release], quitScript = nil;
return NO; return NO;
} }
Expand All @@ -94,11 +120,11 @@ + (BOOL)stopDaemon:(NSError**)error


+ (BOOL)updateInstalledApplication:(NSError**)error; + (BOOL)updateInstalledApplication:(NSError**)error;
{ {
NSString *appName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleExecutable"]; NSString *appName = [[[self myBundle] infoDictionary] objectForKey:@"CFBundleExecutable"];


if ([self isDaemonRunning] && ![self stopDaemon:error]) return NO; if ([self isDaemonRunning] && ![self stopDaemon:error]) return NO;


NSString *myBundlePath = [[NSBundle mainBundle] bundlePath]; NSString *myBundlePath = [[self myBundle] bundlePath];


NSString *applicationPath = [self applicationPath]; NSString *applicationPath = [self applicationPath];
NSString *basePath = [self basePath]; NSString *basePath = [self basePath];
Expand Down Expand Up @@ -164,7 +190,7 @@ + (BOOL)installPluginAtPath:(NSString*)path intoDaemonWithError:(NSError**)error
if (!isDaemonInstalled) { if (!isDaemonInstalled) {
if (![self installDaemon:error]) return NO; if (![self installDaemon:error]) return NO;
} else { } else {
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; NSDictionary *infoDictionary = [[self daemonBundle] infoDictionary];
NSInteger currentVersionNumber = [[infoDictionary objectForKey:ZSyncVersionNumber] integerValue]; NSInteger currentVersionNumber = [[infoDictionary objectForKey:ZSyncVersionNumber] integerValue];


NSBundle *installed = [NSBundle bundleWithPath:[self applicationPath]]; NSBundle *installed = [NSBundle bundleWithPath:[self applicationPath]];
Expand All @@ -184,8 +210,22 @@ + (BOOL)installPluginAtPath:(NSString*)path intoDaemonWithError:(NSError**)error
} }


//Install the plugin //Install the plugin
NSString *pluginPath = [[self pluginPath] stringByAppendingPathComponent:[path lastPathComponent]]; NSString *pluginPath = [self pluginPath];
NSFileManager *fileManager = [NSFileManager defaultManager]; NSFileManager *fileManager = [NSFileManager defaultManager];
BOOL isDirectory = NO;

if (![fileManager fileExistsAtPath:pluginPath isDirectory:&isDirectory]) {
if (![[NSFileManager defaultManager] createDirectoryAtPath:pluginPath withIntermediateDirectories:YES attributes:nil error:error]) {
return NO;
}
} else if (!isDirectory) {
NSString *errorDesc = [NSString stringWithFormat:@"Unknown file at base installation path: %@", pluginPath];
NSDictionary *dictionary = [NSDictionary dictionaryWithObject:errorDesc forKey:NSLocalizedDescriptionKey];
*error = [NSError errorWithDomain:@"ZSync" code:1123 userInfo:dictionary];
return NO;
}

pluginPath = [pluginPath stringByAppendingPathComponent:[path lastPathComponent]];
if (![fileManager copyItemAtPath:path toPath:pluginPath error:error]) { if (![fileManager copyItemAtPath:path toPath:pluginPath error:error]) {
return NO; return NO;
} }
Expand All @@ -198,7 +238,7 @@ + (BOOL)installPluginAtPath:(NSString*)path intoDaemonWithError:(NSError**)error


+ (BOOL)isDaemonRunning; + (BOOL)isDaemonRunning;
{ {
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; NSDictionary *infoDictionary = [[self daemonBundle] infoDictionary];
NSString *myBundleID = [infoDictionary objectForKey:@"CFBundleIdentifier"]; NSString *myBundleID = [infoDictionary objectForKey:@"CFBundleIdentifier"];


NSWorkspace *workspace = [NSWorkspace sharedWorkspace]; NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
Expand All @@ -212,7 +252,7 @@ + (BOOL)isDaemonRunning;


+ (void)startDaemon; + (void)startDaemon;
{ {
NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary]; NSDictionary *infoDictionary = [[self myBundle] infoDictionary];
NSString *appName = [infoDictionary objectForKey:@"CFBundleExecutable"]; NSString *appName = [infoDictionary objectForKey:@"CFBundleExecutable"];


NSWorkspace *workspace = [NSWorkspace sharedWorkspace]; NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
Expand Down
34 changes: 34 additions & 0 deletions Daemon/Info-Installer.plist
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string>icon.icns</string>
<key>CFBundleIdentifier</key>
<string>com.zarrastudios.zsync.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>LSUIElement</key>
<true/>
<key>NSPrincipalClass</key>
<string>ZSyncDaemon</string>
<key>ZSyncVersionNumber</key>
<string>1</string>
</dict>
</plist>
87 changes: 55 additions & 32 deletions Daemon/Info.plist
@@ -1,36 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0"> <plist version="1.0">
<dict> <dict>
<key>NSMainNibFile</key>
<string>MainMenu</string> <key>UTExportedTypeDeclarations</key>
<key>CFBundleDevelopmentRegion</key> <array>
<string>English</string> <dict>
<key>CFBundleExecutable</key> <key>UTTypeConformsTo</key>
<string>${EXECUTABLE_NAME}</string> <array>
<key>CFBundleIconFile</key> <string>com.apple.bundle</string>
<string></string> </array>
<key>CFBundleIdentifier</key> <key>UTTypeDescription</key>
<string>com.yourcompany.${PRODUCT_NAME:rfc1034identifier}</string> <string>ZSync Plugin</string>
<key>CFBundleInfoDictionaryVersion</key> <key>UTTypeIdentifier</key>
<string>6.0</string> <string>com.zarrastudios.zsync.plugin</string>
<key>CFBundleName</key> <key>UTTypeTagSpecification</key>
<string>${PRODUCT_NAME}</string> <dict>
<key>CFBundlePackageType</key> <key>public.filename-extension</key>
<string>APPL</string> <array>
<key>CFBundleSignature</key> <string>zsyncPlugin</string>
<string>????</string> </array>
<key>CFBundleShortVersionString</key> </dict>
<string>1.0</string> </dict>
<key>LSMinimumSystemVersion</key> </array>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>CFBundleVersion</key>
<string>1</string> <key>CFBundleDevelopmentRegion</key>
<key>NSPrincipalClass</key> <string>English</string>
<string>NSApplication</string> <key>CFBundleExecutable</key>
<key>LSUIElement</key> <string>${EXECUTABLE_NAME}</string>
<true/> <key>CFBundleIconFile</key>
<key>ZSyncVersionNumber</key> <string>icon.icns</string>
<string>1</string> <key>CFBundleIdentifier</key>
</dict> <string>com.zarrastudios.zsync.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>LSUIElement</key>
<true/>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>ZSyncVersionNumber</key>
<string>1</string>
</dict>
</plist> </plist>
4 changes: 1 addition & 3 deletions Daemon/Prefix.pch
Expand Up @@ -2,6 +2,4 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#import <CoreData/CoreData.h> #import <CoreData/CoreData.h>
#import "ZSync.h" #import "ZSync.h"
#endif #endif

#define ZSyncVersionNumber @"ZSyncVersionNumber"

0 comments on commit a7c949e

Please sign in to comment.