mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-24 04:38:16 +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.
273 lines
6.1 KiB
Objective-C
273 lines
6.1 KiB
Objective-C
//
|
|
// NTSynchronousTask.m
|
|
// CocoatechCore
|
|
//
|
|
// Created by Steve Gehrman on 9/29/05.
|
|
// Copyright 2005 Steve Gehrman. All rights reserved.
|
|
//
|
|
|
|
#import "SUUpdater.h"
|
|
|
|
#import "SUAppcast.h"
|
|
#import "SUAppcastItem.h"
|
|
#import "SUVersionComparisonProtocol.h"
|
|
#import "NTSynchronousTask.h"
|
|
|
|
@interface NTSynchronousTask (Private)
|
|
- (void)run:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input;
|
|
|
|
- (NSTask *)task;
|
|
- (void)setTask:(NSTask *)theTask;
|
|
|
|
- (NSPipe *)outputPipe;
|
|
- (void)setOutputPipe:(NSPipe *)theOutputPipe;
|
|
|
|
- (NSPipe *)inputPipe;
|
|
- (void)setInputPipe:(NSPipe *)theInputPipe;
|
|
|
|
- (NSData *)output;
|
|
- (void)setOutput:(NSData *)theOutput;
|
|
|
|
- (BOOL)done;
|
|
- (void)setDone:(BOOL)flag;
|
|
|
|
- (int)result;
|
|
- (void)setResult:(int)theResult;
|
|
@end
|
|
|
|
@implementation NTSynchronousTask
|
|
|
|
- (id)init;
|
|
{
|
|
self = [super init];
|
|
if (self)
|
|
{
|
|
[self setTask:[[[NSTask alloc] init] autorelease]];
|
|
[self setOutputPipe:[[[NSPipe alloc] init] autorelease]];
|
|
[self setInputPipe:[[[NSPipe alloc] init] autorelease]];
|
|
|
|
[[self task] setStandardInput:[self inputPipe]];
|
|
[[self task] setStandardOutput:[self outputPipe]];
|
|
[[self task] setStandardError:[self outputPipe]];
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
//----------------------------------------------------------
|
|
// dealloc
|
|
//----------------------------------------------------------
|
|
- (void)dealloc
|
|
{
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
|
[self setTask:nil];
|
|
[self setOutputPipe:nil];
|
|
[self setInputPipe:nil];
|
|
[self setOutput:nil];
|
|
|
|
[super dealloc];
|
|
}
|
|
|
|
+(int) task:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input output: (NSData**)outData
|
|
{
|
|
// we need this wacky pool here, otherwise we run out of pipes, the pipes are internally autoreleased
|
|
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
|
int taskResult = 0;
|
|
if( outData )
|
|
*outData = nil;
|
|
|
|
NS_DURING
|
|
{
|
|
NTSynchronousTask* task = [[NTSynchronousTask alloc] init];
|
|
|
|
[task run:toolPath directory:currentDirectory withArgs:args input:input];
|
|
|
|
taskResult = [task result];
|
|
if( outData )
|
|
*outData = [[task output] retain];
|
|
|
|
[task release];
|
|
}
|
|
NS_HANDLER;
|
|
taskResult = errCppGeneral;
|
|
NS_ENDHANDLER;
|
|
|
|
[pool drain];
|
|
|
|
// retained above
|
|
if( outData )
|
|
[*outData autorelease];
|
|
|
|
return taskResult;
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation NTSynchronousTask (Private)
|
|
|
|
- (void)run:(NSString*)toolPath directory:(NSString*)currentDirectory withArgs:(NSArray*)args input:(NSData*)input;
|
|
{
|
|
BOOL success = NO;
|
|
|
|
if (currentDirectory)
|
|
[[self task] setCurrentDirectoryPath: currentDirectory];
|
|
|
|
[[self task] setLaunchPath:toolPath];
|
|
[[self task] setArguments:args];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
selector:@selector(taskOutputAvailable:)
|
|
name:NSFileHandleReadToEndOfFileCompletionNotification
|
|
object:[[self outputPipe] fileHandleForReading]];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
selector:@selector(taskDidTerminate:)
|
|
name:NSTaskDidTerminateNotification
|
|
object:[self task]];
|
|
|
|
[[[self outputPipe] fileHandleForReading] readToEndOfFileInBackgroundAndNotifyForModes:[NSArray arrayWithObjects:NSDefaultRunLoopMode, NSModalPanelRunLoopMode, NSEventTrackingRunLoopMode, nil]];
|
|
|
|
NS_DURING
|
|
[[self task] launch];
|
|
success = YES;
|
|
NS_HANDLER
|
|
;
|
|
NS_ENDHANDLER
|
|
|
|
if (success)
|
|
{
|
|
if (input)
|
|
{
|
|
// feed the running task our input
|
|
[[[self inputPipe] fileHandleForWriting] writeData:input];
|
|
[[[self inputPipe] fileHandleForWriting] closeFile];
|
|
}
|
|
|
|
// loop until we are done receiving the data
|
|
if (![self done])
|
|
{
|
|
double resolution = 1;
|
|
BOOL isRunning;
|
|
NSDate* next;
|
|
|
|
do {
|
|
next = [NSDate dateWithTimeIntervalSinceNow:resolution];
|
|
|
|
isRunning = [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
|
|
beforeDate:next];
|
|
} while (isRunning && ![self done]);
|
|
}
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------
|
|
// task
|
|
//----------------------------------------------------------
|
|
- (NSTask *)task
|
|
{
|
|
return mv_task;
|
|
}
|
|
|
|
- (void)setTask:(NSTask *)theTask
|
|
{
|
|
if (mv_task != theTask) {
|
|
[mv_task release];
|
|
mv_task = [theTask retain];
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------
|
|
// outputPipe
|
|
//----------------------------------------------------------
|
|
- (NSPipe *)outputPipe
|
|
{
|
|
return mv_outputPipe;
|
|
}
|
|
|
|
- (void)setOutputPipe:(NSPipe *)theOutputPipe
|
|
{
|
|
if (mv_outputPipe != theOutputPipe) {
|
|
[mv_outputPipe release];
|
|
mv_outputPipe = [theOutputPipe retain];
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------
|
|
// inputPipe
|
|
//----------------------------------------------------------
|
|
- (NSPipe *)inputPipe
|
|
{
|
|
return mv_inputPipe;
|
|
}
|
|
|
|
- (void)setInputPipe:(NSPipe *)theInputPipe
|
|
{
|
|
if (mv_inputPipe != theInputPipe) {
|
|
[mv_inputPipe release];
|
|
mv_inputPipe = [theInputPipe retain];
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------
|
|
// output
|
|
//----------------------------------------------------------
|
|
- (NSData *)output
|
|
{
|
|
return mv_output;
|
|
}
|
|
|
|
- (void)setOutput:(NSData *)theOutput
|
|
{
|
|
if (mv_output != theOutput) {
|
|
[mv_output release];
|
|
mv_output = [theOutput retain];
|
|
}
|
|
}
|
|
|
|
//----------------------------------------------------------
|
|
// done
|
|
//----------------------------------------------------------
|
|
- (BOOL)done
|
|
{
|
|
return mv_done;
|
|
}
|
|
|
|
- (void)setDone:(BOOL)flag
|
|
{
|
|
mv_done = flag;
|
|
}
|
|
|
|
//----------------------------------------------------------
|
|
// result
|
|
//----------------------------------------------------------
|
|
- (int)result
|
|
{
|
|
return mv_result;
|
|
}
|
|
|
|
- (void)setResult:(int)theResult
|
|
{
|
|
mv_result = theResult;
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation NTSynchronousTask (Notifications)
|
|
|
|
- (void)taskOutputAvailable:(NSNotification*)note
|
|
{
|
|
[self setOutput:[[note userInfo] objectForKey:NSFileHandleNotificationDataItem]];
|
|
|
|
[self setDone:YES];
|
|
}
|
|
|
|
- (void)taskDidTerminate:(NSNotification*)note
|
|
{
|
|
[self setResult:[[self task] terminationStatus]];
|
|
}
|
|
|
|
@end
|
|
|
|
|