+
+ //Here we set whether we will launch at login by modifying loginwindow.plist
+ if ([launchAtLoginCheckbox state] == NSOnState)
+ {
+ NSMutableDictionary *loginwindow;
+ NSMutableArray *loginarray;
+ int i;
+ BOOL skip = NO;
+
+ [defaults synchronize];
+ loginwindow = [[defaults persistentDomainForName:@"loginwindow"] mutableCopy];
+ loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
+
+ for (i = 0; i < [loginarray count]; i++)
+ {
+ NSDictionary *tempDict = [loginarray objectAtIndex:i];
+
+ //Here we are seeing if our program is already in loginwindow.plist.
+ //See the problem below for this problem here. We will do the same thing.
+
+ if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:@"VocabularyBuilder.app"])
+ {
+ skip = YES;
+ }
+ }
+
+ if (!skip)
+ {
+ [loginarray addObject:[NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], @"Hide", [[NSBundle mainBundle] bundlePath], @"Path", nil]];
+
+ [defaults setPersistentDomain:loginwindow forName:@"loginwindow"];
+ [defaults synchronize];
+ }
+ }
+ else
+ {
+ NSMutableDictionary *loginwindow;
+ NSMutableArray *loginarray;
+ int i;
+
+ [[NSUserDefaults standardUserDefaults] synchronize];
+ loginwindow = [[[NSUserDefaults standardUserDefaults] persistentDomainForName:@"loginwindow"] mutableCopy];
+ loginarray = [loginwindow objectForKey:@"AutoLaunchedApplicationDictionary"];
+
+ for (i = 0; i < [loginarray count]; i++)
+ {
+ NSDictionary *tempDict = [loginarray objectAtIndex:i];
+
+ if ([[[tempDict objectForKey:@"Path"] lastPathComponent] isEqualToString:@"VocabularyBuilder.app"])
+ {
+ [loginarray removeObjectAtIndex:i];
+ [defaults setPersistentDomain:loginwindow forName:@"loginwindow"];
+ [defaults synchronize];
+ break;
+ }
+ }
+ }