diff --git a/source/Common.h b/source/Common.h index 66a049c..a9d634d 100644 --- a/source/Common.h +++ b/source/Common.h @@ -54,7 +54,7 @@ #define VALUES_KEYPATH(X) [NSString stringWithFormat:@"values.%@", (X)] -// let's make things a bit less verbose +// Let's make things a bit less verbose #define FILEMGR [NSFileManager defaultManager] #define DEFAULTS [NSUserDefaults standardUserDefaults] #define WORKSPACE [NSWorkspace sharedWorkspace] diff --git a/source/InfoPanelController.m b/source/InfoPanelController.m index a877262..2f48b36 100644 --- a/source/InfoPanelController.m +++ b/source/InfoPanelController.m @@ -75,7 +75,7 @@ - (void)setItem:(NSDictionary *)itemDict { BOOL isFileOrFolder = [type isEqualToString:@"File"] || [type isEqualToString:@"Directory"]; BOOL isIPSocket = [type isEqualToString:@"IP Socket"]; - // name + // Name NSString *name = isFileOrFolder ? [itemDict[@"name"] lastPathComponent] : itemDict[@"name"]; if (name == nil || [name isEqualToString:@""]) { name = [NSString stringWithFormat:@"Unnamed %@", type]; @@ -86,7 +86,7 @@ - (void)setItem:(NSDictionary *)itemDict { [self.window setTitle:name]; [self.nameTextField setStringValue:name]; - // path + // Path NSString *path = @"—"; if (isFileOrFolder || isProcess) { NSString *p = [itemDict[@"type"] isEqualToString:@"Process"] ? itemDict[@"bundlepath"] : itemDict[@"name"]; @@ -95,7 +95,7 @@ - (void)setItem:(NSDictionary *)itemDict { self.path = path; [self.pathTextField setStringValue:path]; - // icon + // Icon NSImage *img = isFileOrFolder ? [WORKSPACE iconForFile:path] : [itemDict[@"image"] copy]; [img setSize:NSMakeSize(48,48)]; [self.iconView setImage:img]; @@ -106,7 +106,7 @@ - (void)setItem:(NSDictionary *)itemDict { } [self.sizeTextField setStringValue:sizeStr]; - // type + // Type NSString *typeStr = type; if (isProcess) { register struct passwd *pw; @@ -119,7 +119,7 @@ - (void)setItem:(NSDictionary *)itemDict { } [self.itemTypeTextField setStringValue:typeStr]; - // owned by + // Owned by if (isProcess) { NSString *pidStr = [NSString stringWithFormat:@"PID: %@", itemDict[@"pid"]]; [self.usedByTextField setStringValue:@"—"]; @@ -129,13 +129,13 @@ - (void)setItem:(NSDictionary *)itemDict { [self.usedByTextField setStringValue:ownedByStr]; } - // access mode + // Access mode NSString *access = [self accessModeDescriptionForMode:itemDict[@"accessmode"]]; if (access == nil) { if (itemDict[@"fd"] == nil) { access = @"—"; } else { - // try to scan int to see if we have a file descriptor number + // Try to scan int to see if we have a file descriptor number int num; BOOL isInteger = [[NSScanner scannerWithString:itemDict[@"fd"]] scanInt:&num]; if (isInteger) { @@ -147,7 +147,7 @@ - (void)setItem:(NSDictionary *)itemDict { } [self.accessModeTextField setStringValue:access]; - // the other fields + // The other fields if ((!isFileOrFolder && (!isProcess || (isProcess && itemDict[@"bundlepath"] == nil))) || (isFileOrFolder && ![FILEMGR fileExistsAtPath:itemDict[@"name"]])) { [self.filetypeTextField setStringValue:@"—"]; @@ -164,7 +164,7 @@ - (void)setItem:(NSDictionary *)itemDict { [self.permissionsTextField setStringValue:permString]; } - // buttons + // Buttons BOOL workablePath = isFileOrFolder || (isProcess && [FILEMGR fileExistsAtPath:path]); [self.showInFinderButton setEnabled:workablePath]; [self.getFinderInfoButton setEnabled:workablePath]; @@ -199,12 +199,12 @@ - (NSString *)permissionsStringForPath:(NSString *)filePath { [result appendString:@"-"]; } - // loop through POSIX permissions, starting at user, then group, then other. + // Loop through POSIX permissions, starting at user, then group, then other. for (int i = 2; i >= 0; i--) { - // this creates an index from 0 to 7 + // This creates an index from 0 to 7 unsigned long thisPart = (perms >> (i * 3)) & 0x7; - // we look up this index in our permissions array and append it. + // We look up this index in our permissions array and append it. [result appendString:[permsArray objectAtIndex:thisPart]]; } @@ -240,7 +240,7 @@ - (NSString *)fileInfoForPath:(NSString *)filePath { if (![FILEMGR fileExistsAtPath:filePath]) { return @""; } - // run file command and get output + // Run 'file' command and get output NSTask *task = [[NSTask alloc] init]; [task setLaunchPath:@"/usr/bin/file"]; [task setArguments:@[@"-b", filePath]]; @@ -264,7 +264,7 @@ - (NSString *)fileSizeStringForPath:(NSString *)filePath { return @"—"; } - UInt64 size = [self fileOrFolderSize:filePath]; + UInt64 size = [self fileSizeAtPath:filePath]; NSString *humanSize = [self sizeAsHumanReadable:size]; NSString *finalString = humanSize; @@ -344,8 +344,8 @@ - (BOOL)runAppleScript:(NSString *)scriptSource { } } -- (UInt64)fileOrFolderSize:(NSString *)path { - // returns size 0 for directories +- (UInt64)fileSizeAtPath:(NSString *)path { + // Return size 0 for directories BOOL isDir; if (path == nil || ![FILEMGR fileExistsAtPath:path isDirectory:&isDir] || isDir) { return 0; diff --git a/source/SlothController.m b/source/SlothController.m index ab2900a..71d98a2 100644 --- a/source/SlothController.m +++ b/source/SlothController.m @@ -176,7 +176,7 @@ - (BOOL)AEWPFunctionExists { - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { - // put application icon in window title bar + // Put application icon in window title bar [window setRepresentedURL:[NSURL URLWithString:@""]]; NSButton *button = [window standardWindowButton:NSWindowDocumentIconButton]; [button setImage:[NSApp applicationIconImage]]; @@ -226,7 +226,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { } [window makeKeyAndOrderFront:self]; - // automatically refresh when app is launched + // Automatically refresh when app is launched [self performSelector:@selector(refresh:) withObject:self afterDelay:0.05]; } @@ -235,12 +235,12 @@ - (void)applicationWillTerminate:(NSNotification *)aNotification { } - (BOOL)window:(NSWindow *)window shouldPopUpDocumentPathMenu:(NSMenu *)menu { - // prevent popup menu when window icon/title is cmd-clicked + // Prevent popup menu when window icon/title is cmd-clicked return NO; } - (BOOL)window:(NSWindow *)window shouldDragDocumentWithEvent:(NSEvent *)event from:(NSPoint)dragImageLocation withPasteboard:(NSPasteboard *)pasteboard { - // prevent dragging of title bar icon + // Prevent dragging of title bar icon return NO; } @@ -252,19 +252,19 @@ - (void)updateFiltering { } //NSLog(@"Filtering"); - // filter content + // Filter content int matchingFilesCount = 0; self.content = [self filterContent:self.unfilteredContent numberOfMatchingFiles:&matchingFilesCount]; - // update header + // Update header NSString *headerTitle = [NSString stringWithFormat:@"%d processes", (int)[self.content count]]; [[[outlineView tableColumnWithIdentifier:@"children"] headerCell] setStringValue:headerTitle]; - // update label + // Update label NSString *str = [NSString stringWithFormat:@"Showing %d out of %d items", matchingFilesCount, self.totalFileCount]; [numItemsTextField setStringValue:str]; - // reload + // Reload [outlineView reloadData]; if ([DEFAULTS boolForKey:@"disclosure"]) { @@ -285,7 +285,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N if ([VALUES_KEYPATH(@"interfaceSize") isEqualToString:keyPath]) { [outlineView reloadData]; } - // the default that changed was one of the filters + // The default that changed was one of the filters else { [self updateFiltering]; } @@ -353,7 +353,7 @@ - (NSMutableArray *)filterContent:(NSMutableArray *)unfilteredContent numberOfMa for (NSDictionary *file in process[@"children"]) { - // let's see if it gets filtered by type + // Let's see if it gets filtered by type if (showAllFileTypes == NO) { if (showHomeFolderOnly && ![file[@"name"] hasPrefix:homeDirPath]) { @@ -375,7 +375,7 @@ - (NSMutableArray *)filterContent:(NSMutableArray *)unfilteredContent numberOfMa } } - // see if it matches regex in search field filter + // See if it matches regex in search field filter if (hasRegexFilter) { int matchCount = 0; @@ -425,7 +425,7 @@ - (IBAction)refresh:(id)sender { [progressIndicator setUsesThreadedAnimation:TRUE]; [progressIndicator startAnimation:self]; - // update in background + // Update in background dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ @autoreleasepool { @@ -435,7 +435,7 @@ - (IBAction)refresh:(id)sender { self.unfilteredContent = [self parseLsofOutput:output numFiles:&fileCount]; self.totalFileCount = fileCount; - // then update UI on main thread + // Then update UI on main thread dispatch_async(dispatch_get_main_queue(), ^{ // Re-enable controls @@ -461,14 +461,14 @@ - (NSString *)lsofPath { - (NSMutableArray *)lsofArguments { NSMutableArray *arguments = [PROGRAM_LSOF_ARGS mutableCopy]; if ([DEFAULTS boolForKey:@"dnsLookup"] == NO) { - // add arguments to disable dns and port name lookup + // Add arguments to disable dns and port name lookup [arguments addObjectsFromArray:PROGRAM_LSOF_NO_DNS_ARGS]; } return arguments; } - (NSString *)runLsof:(BOOL)isAuthenticated { - // our command is: lsof -F pcnt +c0 + // Our command is: lsof -F pcnt +c0 NSData *outputData; if (isAuthenticated) { @@ -484,7 +484,7 @@ - (NSString *)runLsof:(BOOL)isAuthenticated { char *args[numberOfArguments + 1]; FILE *outputFile; - // first, construct an array of c strings from NSArray w. arguments + // First, construct an array of c strings from NSArray w. arguments for (int i = 0; i < numberOfArguments; i++) { NSString *argString = arguments[i]; NSUInteger stringLength = [argString length]; @@ -494,10 +494,10 @@ - (NSString *)runLsof:(BOOL)isAuthenticated { } args[numberOfArguments] = NULL; - //use Authorization Reference to execute script with privileges + // Use Authorization Reference to execute script with privileges _AuthExecuteWithPrivsFn(authorizationRef, toolPath, kAuthorizationFlagDefaults, args, &outputFile); - // free the malloc'd argument strings + // Free malloc'd argument strings for (int i = 0; i < numberOfArguments; i++) { free(args[i]); } @@ -543,7 +543,7 @@ - (NSMutableArray *)parseLsofOutput:(NSString *)outputString numFiles:(int *)num NSString *fd = @""; BOOL skip; - // parse each line + // Parse each line for (NSString *line in lines) { if ([line length] == 0) { @@ -681,20 +681,20 @@ - (NSMutableArray *)parseLsofOutput:(NSString *)outputString numFiles:(int *)num - (void)updateProcessInfo:(NSMutableDictionary *)p { - // update display name to show number of open files for process + // Update display name to show number of open files for process NSString *procString = [NSString stringWithFormat:@"%@ (%d)", p[@"pname"], (int)[p[@"children"] count]]; p[@"displayname"] = procString; - // get icon for process + // Get icon for process if (!p[@"image"]) { ProcessSerialNumber psn; GetProcessForPID([p[@"pid"] intValue], &psn); NSDictionary *pInfoDict = (__bridge_transfer NSDictionary *)ProcessInformationCopyDictionary(&psn, kProcessDictionaryIncludeAllInformationMask); - if (pInfoDict[@"BundlePath"]) { // it's a bundle + if (pInfoDict[@"BundlePath"]) { // It's a bundle p[@"image"] = [WORKSPACE iconForFile:pInfoDict[@"BundlePath"]]; - // check if it's an app bundle + // Check if it's an app bundle NSString *fileType = [WORKSPACE typeOfFile:pInfoDict[@"BundlePath"] error:nil]; if ([WORKSPACE type:fileType conformsToType:APPLICATION_UTI]) { p[@"app"] = @YES; @@ -715,7 +715,7 @@ - (BOOL)killProcess:(int)pid asRoot:(BOOL)asRoot { return (kill(pid, SIGKILL) == 0); } - // kill process as root + // Kill process as root const char *toolPath = [@"/bin/kill" fileSystemRepresentation]; AuthorizationRef authRef; @@ -723,19 +723,19 @@ - (BOOL)killProcess:(int)pid asRoot:(BOOL)asRoot { AuthorizationRights myRights = { 1, &myItems }; AuthorizationFlags flags = kAuthorizationFlagDefaults | kAuthorizationFlagInteractionAllowed | kAuthorizationFlagPreAuthorize | kAuthorizationFlagExtendRights; - // create authorization reference + // Create authorization reference OSStatus err = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &authRef); if (err != errAuthorizationSuccess) { return NO; } - // pre-authorize the privileged operation + // Pre-authorize the privileged operation err = AuthorizationCopyRights(authRef, &myRights, kAuthorizationEmptyEnvironment, flags, NULL); if (err != errAuthorizationSuccess) { return NO; } - // construct c strings array of arguments + // Construct c strings array of arguments // /bin/kill -9 1234 char *args[3]; args[0] = malloc(4); @@ -744,15 +744,15 @@ - (BOOL)killProcess:(int)pid asRoot:(BOOL)asRoot { sprintf(args[1], "%d", pid); args[2] = NULL; - // use Authorization Reference to execute /bin/kill with root privileges + // Use Authorization Reference to execute /bin/kill with root privileges err = _AuthExecuteWithPrivsFn(authRef, toolPath, kAuthorizationFlagDefaults, args, NULL); - // cleanup + // Cleanup free(args[0]); free(args[1]); AuthorizationFree(authRef, kAuthorizationFlagDestroyRights); - // we return err if execution failed + // We return err if execution failed if (err != errAuthorizationSuccess) { return NO; } @@ -862,11 +862,10 @@ - (IBAction)getInfo:(id)sender { } - (void)showGetInfoForItem:(NSDictionary *)item { - // create info panel lazily + // Create info panel lazily if (infoPanelController == nil) { infoPanelController = [[InfoPanelController alloc] initWithWindowNibName:@"InfoPanel"]; } - // show it [infoPanelController setItem:item]; [infoPanelController showWindow:self]; } @@ -975,13 +974,13 @@ - (OSStatus)authenticate { AuthorizationRights myRights = { 1, &myItems }; AuthorizationFlags flags = kAuthorizationFlagDefaults | kAuthorizationFlagInteractionAllowed | kAuthorizationFlagPreAuthorize | kAuthorizationFlagExtendRights; - // create authorization reference + // Create authorization reference err = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment, kAuthorizationFlagDefaults, &authorizationRef); if (err != errAuthorizationSuccess) { return err; } - // pre-authorize the privileged operation + // Pre-authorize the privileged operation err = AuthorizationCopyRights(authorizationRef, &myRights, kAuthorizationEmptyEnvironment, flags, NULL); if (err != errAuthorizationSuccess) { return err; @@ -1017,7 +1016,7 @@ - (void)outlineViewSelectionDidChange:(NSNotification *)notification { [killButton setEnabled:YES]; [infoPanelController setItem:item]; - // we make the file path red if file has been moved or deleted + // We make the file path red if file has been moved or deleted if ([item[@"type"] isEqualToString:@"File"] || [item[@"type"] isEqualToString:@"Directory"]) { NSColor *color = canReveal ? [NSColor blackColor] : [NSColor redColor]; item[@"displayname"] = [[NSAttributedString alloc] initWithString:item[@"name"] @@ -1140,7 +1139,7 @@ - (IBAction)find:(id)sender { - (BOOL)validateMenuItem:(NSMenuItem *)anItem { NSInteger selectedRow = [outlineView clickedRow] == -1 ? [outlineView selectedRow] : [outlineView clickedRow]; - //reveal in finder / kill process only enabled when something is selected + // Reveal in finder / kill process should only ebe nabled when something is selected if (( [[anItem title] isEqualToString:@"Show in Finder"] || [[anItem title] isEqualToString:@"Kill Process"] || [[anItem title] isEqualToString:@"Get Info"]) && selectedRow < 0) { return NO; } diff --git a/source/SlothImageView.m b/source/SlothImageView.m index 0421a0e..fd4c241 100644 --- a/source/SlothImageView.m +++ b/source/SlothImageView.m @@ -11,7 +11,7 @@ @implementation SlothImageView - (void)mouseDown:(NSEvent *)theEvent { - // see http://www.cocoabuilder.com/archive/cocoa/115981-nsimageview-subclass-and-mouseup.html + // See http://www.cocoabuilder.com/archive/cocoa/115981-nsimageview-subclass-and-mouseup.html if (theEvent.type != NSLeftMouseDown) { [super mouseDown:theEvent]; }