mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-27 05:04:27 +00:00
- Changed NTSynchronousTask to also give the status return value and direct stderror output to the outputData. - Changed includes so this builds as part of an app, too, not just as a framework - Made sure SUAppcast's dealloc releases some leaked ivars. - Added infoURL, extracted from link, that can point to a "more Info" page for download-less URLs - Added support for version attribute on item so we can support update notifications that don't include an enclosure (e.g. paid upgrades, or upgrades that would require a system update) - Added/improved a few description methods to ease debugging. - Added SULog so one can ask for a special log with additional information when there are update issues. - Added mayUpdateAndRestart for apps that absolutely, positively can't restart right now (e.g. cuz they're burning a CD and would produce a coaster). - Added updaterWillRelaunchApplication delegate method, analogous to the notification. Useful to have app delegate quit helper apps during installation. - Made SUBasicUpdateDriver's abortUpdate implicitly retain/autorelease the update driver, because the notification center otherwise releases it and it goes away, causing crashes in superclass's abortUpdate. - Merge of SUKeepDownloadOnFailedInstallKey and SUFixedHTMLDisplaySizeKey. - Avoid a few warnings about missing prototypes - Be paranoid, hdiutil can verify the download again, so let it. Better for internal apps where we turn off DSA checks, too. - SUHost has an -installationPath now, independent from the bundlePath, so one can normalize the app name from "MyApp 1.1b4" back to "MyApp" Users assume the file name contains the correct version number when there is one in it. Saves support a few round-trips each time. - Be better at threading: Try calling non-thread-safe methods on main thread only, and don't assume delegates know when they need to be thread-safe, call them on main thread where possible. - Added a method to put the old copy of the app in the trash. 1.5git changed in this spot, so I didn't actually merge the code that uses it back in yet. - Fix version comparison so it doesn't get confused by bracketed build numbers in version strings - Make sure cancel button is disabled during extraction, otherwise user would crash. - Don't put auto-update window at floating window level. It's huge and can't be switched to background! If you're an NSBGOnly where you need that, turn it on only in that case, but don't generally do such nonsense. - Hide release notes view if there aren't any. - Test whether we are on dial-up before checking for updates in background. It's not nice to cause (possibly expensive) dial-up periodically. - Temporarily comment out DSA complaints for easier testing. - Don't store (possibly already invalidated) one-shot NSTimers in an ivar. It's bad style. Retain it instead. - Decompress some monster expressions with nested method calls in ternary operators and nested in method calls again. - Don't use implicit "id" for params or return types. - finish_installation now puts up a progress window, so user knows update is still not finished. - Use ThreadSafePreferences (included dummy version that uses regular prefs for projects that don't use ThreadSafePreferences). - Todo later: Change finish_installation to be prettier.
167 lines
5.2 KiB
Objective-C
167 lines
5.2 KiB
Objective-C
//
|
|
// SUInstaller.m
|
|
// Sparkle
|
|
//
|
|
// Created by Andy Matuschak on 4/10/08.
|
|
// Copyright 2008 Andy Matuschak. All rights reserved.
|
|
//
|
|
|
|
#import "SUInstaller.h"
|
|
#import "SUPlainInstaller.h"
|
|
#import "SUPackageInstaller.h"
|
|
#import "SUHost.h"
|
|
#import "SUConstants.h"
|
|
#import "SULog.h"
|
|
|
|
|
|
@implementation SUInstaller
|
|
|
|
static NSString* sUpdateFolder = nil;
|
|
|
|
+(NSString*) updateFolder
|
|
{
|
|
return sUpdateFolder;
|
|
}
|
|
|
|
+ (BOOL)_isAliasFolderAtPath:(NSString *)path
|
|
{
|
|
FSRef fileRef;
|
|
OSStatus err = noErr;
|
|
Boolean aliasFileFlag, folderFlag;
|
|
NSURL *fileURL = [NSURL fileURLWithPath:path];
|
|
|
|
if (FALSE == CFURLGetFSRef((CFURLRef)fileURL, &fileRef))
|
|
err = coreFoundationUnknownErr;
|
|
|
|
if (noErr == err)
|
|
err = FSIsAliasFile(&fileRef, &aliasFileFlag, &folderFlag);
|
|
|
|
if (noErr == err)
|
|
return (BOOL)(aliasFileFlag && folderFlag);
|
|
else
|
|
return NO;
|
|
}
|
|
|
|
|
|
+ (void)installFromUpdateFolder:(NSString *)inUpdateFolder overHost:(SUHost *)host delegate:delegate synchronously:(BOOL)synchronously versionComparator:(id <SUVersionComparison>)comparator
|
|
{
|
|
// Search subdirectories for the application
|
|
NSString *currentFile,
|
|
*newAppDownloadPath = nil,
|
|
*bundleFileName = [[host bundlePath] lastPathComponent],
|
|
*alternateBundleFileName = [[host name] stringByAppendingPathExtension:[[host bundlePath] pathExtension]];
|
|
BOOL isPackage = NO;
|
|
NSString *fallbackPackagePath = nil;
|
|
NSDirectoryEnumerator *dirEnum = [[NSFileManager defaultManager] enumeratorAtPath: inUpdateFolder];
|
|
|
|
[sUpdateFolder release];
|
|
sUpdateFolder = [inUpdateFolder retain];
|
|
|
|
while ((currentFile = [dirEnum nextObject]))
|
|
{
|
|
NSString *currentPath = [inUpdateFolder stringByAppendingPathComponent:currentFile];
|
|
if ([[currentFile lastPathComponent] isEqualToString:bundleFileName] ||
|
|
[[currentFile lastPathComponent] isEqualToString:alternateBundleFileName]) // We found one!
|
|
{
|
|
isPackage = NO;
|
|
newAppDownloadPath = currentPath;
|
|
break;
|
|
}
|
|
else if ([[currentFile pathExtension] isEqualToString:@"pkg"] ||
|
|
[[currentFile pathExtension] isEqualToString:@"mpkg"])
|
|
{
|
|
if ([[[currentFile lastPathComponent] stringByDeletingPathExtension] isEqualToString:[bundleFileName stringByDeletingPathExtension]])
|
|
{
|
|
isPackage = YES;
|
|
newAppDownloadPath = currentPath;
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
// Remember any other non-matching packages we have seen should we need to use one of them as a fallback.
|
|
fallbackPackagePath = currentPath;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// Try matching on bundle identifiers in case the user has changed the name of the host app
|
|
NSBundle *incomingBundle = [NSBundle bundleWithPath:currentPath];
|
|
if(incomingBundle && [[incomingBundle bundleIdentifier] isEqualToString:[[host bundle] bundleIdentifier]])
|
|
{
|
|
isPackage = NO;
|
|
newAppDownloadPath = currentPath;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// Some DMGs have symlinks into /Applications! That's no good!
|
|
if ([self _isAliasFolderAtPath:currentPath])
|
|
[dirEnum skipDescendents];
|
|
}
|
|
|
|
// We don't have a valid path. Try to use the fallback package.
|
|
|
|
if (newAppDownloadPath == nil && fallbackPackagePath != nil)
|
|
{
|
|
isPackage = YES;
|
|
newAppDownloadPath = fallbackPackagePath;
|
|
}
|
|
|
|
if (newAppDownloadPath == nil)
|
|
{
|
|
[self _finishInstallationWithResult:NO host:host error:[NSError errorWithDomain:SUSparkleErrorDomain code:SUMissingUpdateError userInfo:[NSDictionary dictionaryWithObject:@"Couldn't find an appropriate update in the downloaded package." forKey:NSLocalizedDescriptionKey]] delegate:delegate];
|
|
}
|
|
else
|
|
{
|
|
[(isPackage ? [SUPackageInstaller class] : [SUPlainInstaller class]) performInstallationWithPath:newAppDownloadPath host:host delegate:delegate synchronously:synchronously versionComparator:comparator];
|
|
}
|
|
}
|
|
|
|
+ (void)_mdimportHost:(SUHost *)host
|
|
{
|
|
// *** GETS CALLED ON NON-MAIN THREAD!
|
|
|
|
NSTask *mdimport = [[[NSTask alloc] init] autorelease];
|
|
[mdimport setLaunchPath:@"/usr/bin/mdimport"];
|
|
[mdimport setArguments:[NSArray arrayWithObject:[host installationPath]]];
|
|
@try
|
|
{
|
|
[mdimport launch];
|
|
}
|
|
@catch (NSException * launchException)
|
|
{
|
|
// No big deal.
|
|
SULog(@"Sparkle Error: %@", [launchException description]);
|
|
}
|
|
}
|
|
|
|
|
|
#define SUNotifyDictHostKey @"SUNotifyDictHost"
|
|
#define SUNotifyDictErrorKey @"SUNotifyDictError"
|
|
#define SUNotifyDictDelegateKey @"SUNotifyDictDelegate"
|
|
|
|
+ (void)_finishInstallationWithResult:(BOOL)result host:(SUHost *)host error:(NSError *)error delegate:delegate
|
|
{
|
|
// *** GETS CALLED ON NON-MAIN THREAD!
|
|
|
|
if (result == YES)
|
|
{
|
|
[self _mdimportHost:host];
|
|
if ([delegate respondsToSelector:@selector(installerFinishedForHost:)])
|
|
[delegate performSelectorOnMainThread: @selector(installerFinishedForHost:) withObject: host waitUntilDone: NO];
|
|
}
|
|
else
|
|
{
|
|
if ([delegate respondsToSelector:@selector(installerForHost:failedWithError:)])
|
|
[self performSelectorOnMainThread: @selector(notifyDelegateOfFailure:) withObject: [NSDictionary dictionaryWithObjectsAndKeys: host, SUNotifyDictHostKey, error, SUNotifyDictErrorKey, delegate, SUNotifyDictDelegateKey, nil] waitUntilDone: NO];
|
|
}
|
|
}
|
|
|
|
|
|
+(void) notifyDelegateOfFailure: (NSDictionary*)dict
|
|
{
|
|
[[dict objectForKey: SUNotifyDictDelegateKey] installerForHost: [dict objectForKey: SUNotifyDictHostKey] failedWithError: [dict objectForKey: SUNotifyDictErrorKey]];
|
|
}
|
|
|
|
@end
|