Permalink
Browse files

Testing of plugin installer

  • Loading branch information...
Marcus S. Zarra
Marcus S. Zarra committed Jun 5, 2010
1 parent c311a9f commit a7c949e53d1ff87ea0c1db0a935d0cacf1baa9ca
@@ -26,7 +26,7 @@
// OTHER DEALINGS IN THE SOFTWARE.
//
-@interface AppDelegate : NSObject <NSApplicationDelegate>
+@interface AppDelegate : NSObject
{
NSStatusItem *statusItem;
}
@@ -1,7 +1,22 @@
#import "ZSyncDaemon.h"
+#define ZSyncVersionNumber @"ZSyncVersionNumber"
+
@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
{
//Build our standard install path
@@ -56,10 +71,7 @@ + (BOOL)isDaemonInstalled:(NSError**)error;
if (error) {
return NO;
}
- if (![[NSFileManager defaultManager] createDirectoryAtPath:basePath
- withIntermediateDirectories:YES
- attributes:nil
- error:error]) {
+ if (![[NSFileManager defaultManager] createDirectoryAtPath:basePath withIntermediateDirectories:YES attributes:nil error:error]) {
return NO;
}
}
@@ -69,22 +81,36 @@ + (BOOL)isDaemonInstalled:(NSError**)error;
+ (BOOL)installDaemon:(NSError**)error;
{
- NSString *myBundlePath = [[NSBundle mainBundle] bundlePath];
- NSString *applicationPath = [self applicationPath];
+ NSString *basePath = [self basePath];
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];
}
+ (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];
NSAppleScript *quitScript;
quitScript = [[NSAppleScript alloc] initWithSource:command];
NSDictionary *errorDict = nil;
// TODO: This should be turned into an NSError response
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;
return NO;
}
@@ -94,11 +120,11 @@ + (BOOL)stopDaemon:(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;
- NSString *myBundlePath = [[NSBundle mainBundle] bundlePath];
+ NSString *myBundlePath = [[self myBundle] bundlePath];
NSString *applicationPath = [self applicationPath];
NSString *basePath = [self basePath];
@@ -164,7 +190,7 @@ + (BOOL)installPluginAtPath:(NSString*)path intoDaemonWithError:(NSError**)error
if (!isDaemonInstalled) {
if (![self installDaemon:error]) return NO;
} else {
- NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
+ NSDictionary *infoDictionary = [[self daemonBundle] infoDictionary];
NSInteger currentVersionNumber = [[infoDictionary objectForKey:ZSyncVersionNumber] integerValue];
NSBundle *installed = [NSBundle bundleWithPath:[self applicationPath]];
@@ -184,8 +210,22 @@ + (BOOL)installPluginAtPath:(NSString*)path intoDaemonWithError:(NSError**)error
}
//Install the plugin
- NSString *pluginPath = [[self pluginPath] stringByAppendingPathComponent:[path lastPathComponent]];
+ NSString *pluginPath = [self pluginPath];
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]) {
return NO;
}
@@ -198,7 +238,7 @@ + (BOOL)installPluginAtPath:(NSString*)path intoDaemonWithError:(NSError**)error
+ (BOOL)isDaemonRunning;
{
- NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
+ NSDictionary *infoDictionary = [[self daemonBundle] infoDictionary];
NSString *myBundleID = [infoDictionary objectForKey:@"CFBundleIdentifier"];
NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
@@ -212,7 +252,7 @@ + (BOOL)isDaemonRunning;
+ (void)startDaemon;
{
- NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
+ NSDictionary *infoDictionary = [[self myBundle] infoDictionary];
NSString *appName = [infoDictionary objectForKey:@"CFBundleExecutable"];
NSWorkspace *workspace = [NSWorkspace sharedWorkspace];
@@ -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>
View
@@ -1,36 +1,59 @@
<?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>NSMainNibFile</key>
- <string>MainMenu</string>
- <key>CFBundleDevelopmentRegion</key>
- <string>English</string>
- <key>CFBundleExecutable</key>
- <string>${EXECUTABLE_NAME}</string>
- <key>CFBundleIconFile</key>
- <string></string>
- <key>CFBundleIdentifier</key>
- <string>com.yourcompany.${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>CFBundleSignature</key>
- <string>????</string>
- <key>CFBundleShortVersionString</key>
- <string>1.0</string>
- <key>LSMinimumSystemVersion</key>
- <string>${MACOSX_DEPLOYMENT_TARGET}</string>
- <key>CFBundleVersion</key>
- <string>1</string>
- <key>NSPrincipalClass</key>
- <string>NSApplication</string>
- <key>LSUIElement</key>
- <true/>
- <key>ZSyncVersionNumber</key>
- <string>1</string>
-</dict>
+ <dict>
+
+ <key>UTExportedTypeDeclarations</key>
+ <array>
+ <dict>
+ <key>UTTypeConformsTo</key>
+ <array>
+ <string>com.apple.bundle</string>
+ </array>
+ <key>UTTypeDescription</key>
+ <string>ZSync Plugin</string>
+ <key>UTTypeIdentifier</key>
+ <string>com.zarrastudios.zsync.plugin</string>
+ <key>UTTypeTagSpecification</key>
+ <dict>
+ <key>public.filename-extension</key>
+ <array>
+ <string>zsyncPlugin</string>
+ </array>
+ </dict>
+ </dict>
+ </array>
+
+
+ <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>NSMainNibFile</key>
+ <string>MainMenu</string>
+ <key>NSPrincipalClass</key>
+ <string>NSApplication</string>
+ <key>ZSyncVersionNumber</key>
+ <string>1</string>
+ </dict>
</plist>
View
@@ -2,6 +2,4 @@
#import <Cocoa/Cocoa.h>
#import <CoreData/CoreData.h>
#import "ZSync.h"
-#endif
-
-#define ZSyncVersionNumber @"ZSyncVersionNumber"
+#endif
Oops, something went wrong.

0 comments on commit a7c949e

Please sign in to comment.