From d7cf93dcf4c06cf1c1c10134a481344c28871633 Mon Sep 17 00:00:00 2001 From: catlan Date: Sun, 11 Nov 2007 04:35:53 +0000 Subject: [PATCH] #76 compare pathExtension with [utilities hostAppExtension] instead of @"app" --- SUUpdater.m | 13 +++++++------ SUUtilities.h | 1 + SUUtilities.m | 5 +++++ 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/SUUpdater.m b/SUUpdater.m index e995b4e1..c6c147cd 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -578,6 +578,7 @@ - (IBAction)installAndRestart:sender { NSString *currentAppPath = [[NSBundle mainBundle] bundlePath]; + NSString *currentBundlePath = [updateBundle bundlePath]; NSString *newAppDownloadPath = [[downloadPath stringByDeletingLastPathComponent] stringByAppendingPathComponent:[[utilities unlocalizedInfoValueForKey:@"CFBundleName"] stringByAppendingPathExtension:@"app"]]; @try { @@ -597,7 +598,7 @@ if (![utilities unlocalizedInfoValueForKey:@"CFBundleName"]) { [NSException raise:@"SUInstallException" format:@"This application has no CFBundleName! This key must be set to the application's name."]; } // Search subdirectories for the application - NSString *file, *appName = [[utilities unlocalizedInfoValueForKey:@"CFBundleName"] stringByAppendingPathExtension:@"app"]; + NSString *file, *appName = [[utilities unlocalizedInfoValueForKey:@"CFBundleName"] stringByAppendingPathExtension:[utilities hostAppExtension]]; NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath:[downloadPath stringByDeletingLastPathComponent]]; while ((file = [dirEnum nextObject])) { @@ -609,13 +610,13 @@ newAppDownloadPath = [[downloadPath stringByDeletingLastPathComponent] stringByAppendingPathComponent:file]; break; } - if ([[file pathExtension] isEqualToString:@".app"]) // No point in looking in app bundles. + if ([[file pathExtension] isEqualToString:[utilities hostAppExtension]]) // No point in looking in app bundles. [dirEnum skipDescendents]; } if (!newAppDownloadPath || ![[NSFileManager defaultManager] fileExistsAtPath:newAppDownloadPath]) { - [NSException raise:@"SUInstallException" format:@"The update archive didn't contain an application with the proper name: %@. Remember, the updated app's file name must be identical to {CFBundleString}.app", [[utilities unlocalizedInfoValueForKey:@"CFBundleName"] stringByAppendingPathExtension:@"app"]]; + [NSException raise:@"SUInstallException" format:@"The update archive didn't contain an application with the proper name: %@. Remember, the updated app's file name must be identical to {CFBundleString}.{Extension}", [[utilities unlocalizedInfoValueForKey:@"CFBundleName"] stringByAppendingPathExtension:[utilities hostAppExtension]]]; } } @catch(NSException *e) @@ -629,8 +630,8 @@ if ([self isAutomaticallyUpdating]) // Don't do authentication if we're automatically updating; that'd be surprising. { int tag = 0; - BOOL result = [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:[currentAppPath stringByDeletingLastPathComponent] destination:@"" files:[NSArray arrayWithObject:[currentAppPath lastPathComponent]] tag:&tag]; - result &= [[NSFileManager defaultManager] movePath:newAppDownloadPath toPath:currentAppPath handler:nil]; + BOOL result = [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation source:[currentBundlePath stringByDeletingLastPathComponent] destination:@"" files:[NSArray arrayWithObject:[currentBundlePath lastPathComponent]] tag:&tag]; + result &= [[NSFileManager defaultManager] movePath:newAppDownloadPath toPath:currentBundlePath handler:nil]; if (!result) { [self abandonUpdate]; @@ -640,7 +641,7 @@ else // But if we're updating by the action of the user, do an authenticated move. { // Outside of the @try block because we want to be a little more informative on this error. - if (![[NSFileManager defaultManager] movePathWithAuthentication:newAppDownloadPath toPath:currentAppPath]) + if (![[NSFileManager defaultManager] movePathWithAuthentication:newAppDownloadPath toPath:currentBundlePath]) { [self showUpdateErrorAlertWithInfo:[NSString stringWithFormat:SULocalizedString(@"%@ does not have permission to write to the application's directory! Are you running off a disk image? If not, ask your system administrator for help.", nil), [utilities hostAppDisplayName]]]; [self abandonUpdate]; diff --git a/SUUtilities.h b/SUUtilities.h index 412f8fdd..0925c92e 100644 --- a/SUUtilities.h +++ b/SUUtilities.h @@ -25,6 +25,7 @@ - (NSString *)hostAppVersionString; - (NSString *)hostAppID; - (NSImage *)hostAppIcon; +- (NSString *)hostAppExtension; - (SUBundleDefaults *)standardBundleDefaults; @end diff --git a/SUUtilities.m b/SUUtilities.m index 5c770c28..a1fa467a 100644 --- a/SUUtilities.m +++ b/SUUtilities.m @@ -105,6 +105,11 @@ return iconImage; } +- (NSString *)hostAppExtension +{ + return [[[NSFileManager defaultManager] displayNameAtPath:[[updater updateBundle] bundlePath]] pathExtension]; +} + - (SUBundleDefaults *)standardBundleDefaults { return [[defaults retain] autorelease];