Skip to content

Commit

Permalink
More error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mxcl committed Mar 21, 2009
1 parent fcd418a commit beef1b2
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions playdar-prefpane/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
//TODO when launching, watch the NSTask, and say "Crashed :(" if early exit
//TODO otherwise check status of pid when window becomes key and update button
//TODO remember path that we scanned with defaults controller
//TODO memory leaks
//TODO log that stupid exception
//TODO while open auto restart playdar binary if using byo_bin and playdar binary is modified
//TODO defaults should use org.playdar.plist not com.apple.systempreferences.plist
Expand Down Expand Up @@ -144,16 +143,16 @@ -(void)onEnable:(id)sender
// if we can't kill playdar don't pretend we did, unless the problem is
// that our pid is invalid
// FIXME I'm not so sure if KILL is safe... what's CTRL-C do?
if(kill(pid, SIGKILL) == -1 && errno != ESRCH) {
if(pid>0 && kill(pid, SIGKILL)==-1 && errno!=ESRCH){
[enable setState:NSOnState];
//TODO beep, show message
return;
}
pid = 0;
pid=0;
}else{
pid = playdar_pid(); // for some reason assignment doesn't happen inside if statements..
if(!pid){
NSTask* task = [[NSTask alloc] init];
NSTask* task=[[NSTask alloc] init];
@try{
if([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask){
[task setLaunchPath:@"/usr/bin/open"];
Expand All @@ -169,9 +168,9 @@ -(void)onEnable:(id)sender
}
@catch(NSException* e)
{
NSString* msg = @"The file at \"";
NSString* msg = @"The file at ";
msg = [msg stringByAppendingString:[task launchPath]];
msg = [msg stringByAppendingString:@"\" could not be executed."];
msg = [msg stringByAppendingString:@" could not be executed."];

NSBeginAlertSheet(@"Could not start Playdar",
nil, nil, nil,
Expand Down Expand Up @@ -293,7 +292,7 @@ -(NSTask*)execScript:(NSString*)script_name withArgs:(NSArray*)args
}
@catch (NSException* e)
{
//TODO log - couldn't figure out easy way to do this
[[NSAlert alertWithMessageText:[e reason]] runModal];
}
return task;
}
Expand Down Expand Up @@ -358,13 +357,14 @@ -(void)writeDaemonScript
encoding:NSUTF8StringEncoding
error:&error];

if (!ok) {} //TODO

NSDictionary* dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithUnsignedInt:0755U]
forKey:NSFilePosixPermissions];

[[NSFileManager defaultManager] changeFileAttributes:dict
atPath:path];
if(ok){
NSDictionary* dict = [NSDictionary dictionaryWithObject:[NSNumber numberWithUnsignedInt:0755U]
forKey:NSFilePosixPermissions];
[[NSFileManager defaultManager] changeFileAttributes:dict
atPath:path];
}
else
[[NSAlert alertWithError:error] runModal];
}

-(IBAction)onDemos:(id)sender
Expand Down

0 comments on commit beef1b2

Please sign in to comment.