X-Git-Url: http://git.ithinksw.org/ITFoundation.git/blobdiff_plain/c40f5440e35326e867b0fa87ec9963d41205380c..82f3d7a2c51dd64ff663cdef7399d50cad4cca6b:/ITLoginItem.m diff --git a/ITLoginItem.m b/ITLoginItem.m index fe49255..05a16b0 100755 --- a/ITLoginItem.m +++ b/ITLoginItem.m @@ -1,8 +1,8 @@ /* - * ITLoginItem.c + * ITLoginItem.m * ITFoundation * - * Created by Kent Sutherland on Sun May 16 2004. + * Created by Kent Sutherland on Mon May 17 2004. * Copyright (c) 2004 __MyCompanyName__. All rights reserved. * */ @@ -10,43 +10,70 @@ #import "ITLoginItem.h" #import "ITDebug.h" -BOOL ITSetLaunchApplicationOnLogin(NSString *path, BOOL flag) +void ITSetApplicationLaunchOnLogin(NSString *path, BOOL flag) { + if ( (flag && ITDoesApplicationLaunchOnLogin(path)) || ![[NSFileManager defaultManager] fileExistsAtPath:path] ) { + return; + } NSUserDefaults *df = [NSUserDefaults standardUserDefaults]; NSMutableDictionary *loginwindow; NSMutableArray *loginarray; - FSRef fileRef; - AliasHandle alias; - NSData *aliasData; - ITDebugLog(@"Set if MenuPrefs launches at login to %i.", flag); + ITDebugLog(@"Set if \"%@\" launches at login to %i.", path, flag); [df synchronize]; loginwindow = [[df persistentDomainForName:@"loginwindow"] mutableCopy]; - loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"]; - - //Create the alias data - FSMakeRefWithPath([path UTF8String], &fileRef); - FSNewAlias(NULL, &fileRef, &alias); - aliasData = [NSData dataWithBytes:&alias length:sizeof(alias)]; + loginarray = [[loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"] mutableCopy]; if (flag) { + /*FSRef fileRef; + AliasHandle alias; + NSData *aliasData; + FSPathMakeRef([path UTF8String], &fileRef, NULL); + FSNewAlias(NULL, &fileRef, &alias); + aliasData = [NSData dataWithBytes:&alias length:GetHandleSize((Handle)alias)];*/ + + if (!loginarray) { //If there is no loginarray of autolaunch items, create one + loginarray = [[[NSMutableArray alloc] init] autorelease]; + } NSDictionary *itemDict = [NSDictionary dictionaryWithObjectsAndKeys: - [[NSBundle mainBundle] bundlePath], @"Path", - [NSNumber numberWithInt:0], @"Hide", - aliasData, @"AliasData", nil, nil]; + [[NSBundle mainBundle] bundlePath], @"Path", + [NSNumber numberWithInt:0], @"Hide", + [NSData data], @"AliasData", nil, nil]; [loginarray addObject:itemDict]; } else { int i; for (i = 0; i < [loginarray count]; i++) { NSDictionary *tempDict = [loginarray objectAtIndex:i]; - if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[[[NSBundle mainBundle] bundlePath] lastPathComponent]]) { + if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:[path lastPathComponent]]) { [loginarray removeObjectAtIndex:i]; break; } } } + [loginwindow setObject:loginarray forKey:@"AutoLaunchedApplicationDictionary"]; [df setPersistentDomain:loginwindow forName:@"loginwindow"]; [df synchronize]; [loginwindow release]; - return YES; + [loginarray release]; +} + +BOOL ITDoesApplicationLaunchOnLogin(NSString *path) +{ + NSUserDefaults *df = [NSUserDefaults standardUserDefaults]; + NSDictionary *loginwindow; + NSMutableArray *loginarray; + NSEnumerator *loginEnum; + id anItem; + ITDebugLog(@"Checking if \"%@\" launches at login.", path); + [df synchronize]; + loginwindow = [df persistentDomainForName:@"loginwindow"]; + loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"]; + + loginEnum = [loginarray objectEnumerator]; + while ( (anItem = [loginEnum nextObject]) ) { + if ( [[[anItem objectForKey:@"Path"] lastPathComponent] isEqualToString:[path lastPathComponent]] ) { + return YES; + } + } + return NO; } \ No newline at end of file