From 105bb3e0f50dd6b03f7e001d20d5ca13456bb938 Mon Sep 17 00:00:00 2001 From: Casey Fleser Date: Wed, 10 Sep 2014 11:08:47 -0500 Subject: [PATCH] initial commit --- SimDirs/AppDelegate.h | 1 - SimDirs/AppDelegate.m | 99 ++++- SimDirs/Base.lproj/MainMenu.xib | 636 ++++---------------------------- 3 files changed, 156 insertions(+), 580 deletions(-) diff --git a/SimDirs/AppDelegate.h b/SimDirs/AppDelegate.h index 228debb..daf955f 100644 --- a/SimDirs/AppDelegate.h +++ b/SimDirs/AppDelegate.h @@ -10,6 +10,5 @@ @interface AppDelegate : NSObject - @end diff --git a/SimDirs/AppDelegate.m b/SimDirs/AppDelegate.m index 190e49b..52ba1c6 100644 --- a/SimDirs/AppDelegate.m +++ b/SimDirs/AppDelegate.m @@ -10,17 +10,106 @@ @interface AppDelegate () -@property (weak) IBOutlet NSWindow *window; +@property (nonatomic, weak) IBOutlet NSWindow *window; +@property (nonatomic, weak) IBOutlet NSTableView *locationTable; +@property (nonatomic, strong) NSMutableArray *simLocations; + @end @implementation AppDelegate -- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { - // Insert code here to initialize your application +- (void) applicationDidFinishLaunching: (NSNotification *) inNotification +{ + [self.locationTable setDoubleAction: @selector(handleRowSelect:)]; + [self discoverSimLocations]; + [self.locationTable reloadData]; } -- (void)applicationWillTerminate:(NSNotification *)aNotification { - // Insert code here to tear down your application +- (void) applicationWillTerminate: (NSNotification *) inNotification +{ +} + +- (void) discoverSimLocations +{ + NSFileManager *fileManager = [NSFileManager defaultManager]; + NSURL *libraryDirURL = [[fileManager URLsForDirectory: NSLibraryDirectory inDomains: NSUserDomainMask] firstObject]; + + self.simLocations = [NSMutableArray array]; + + if (libraryDirURL != nil) { + libraryDirURL = [libraryDirURL URLByAppendingPathComponent: @"Developer/CoreSimulator/Devices"]; + if (libraryDirURL != nil) { + NSDirectoryEnumerator *dirEnum = [fileManager enumeratorAtURL: libraryDirURL includingPropertiesForKeys: nil options: NSDirectoryEnumerationSkipsSubdirectoryDescendants | NSDirectoryEnumerationSkipsHiddenFiles errorHandler: nil]; + NSURL *baseInfoURL; + + while ((baseInfoURL = [dirEnum nextObject])) { + NSURL *deviceInfoURL = [baseInfoURL URLByAppendingPathComponent: @"device.plist"]; + + if (deviceInfoURL != nil && [fileManager fileExistsAtPath: [deviceInfoURL path]]) { + NSData *plistData = [NSData dataWithContentsOfURL: deviceInfoURL]; + + if (plistData != nil) { + NSDictionary *plistInfo; + + plistInfo = [NSPropertyListSerialization propertyListWithData: plistData options: NSPropertyListImmutable format: nil error: nil]; + if (plistInfo != nil) { + NSString *name = plistInfo[@"name"]; + NSString *runtime = plistInfo[@"runtime"]; + NSRange runtimeRange; + + runtimeRange = [runtime rangeOfString: @"iOS.*" options: NSRegularExpressionSearch]; + if (runtimeRange.location != NSNotFound) { + NSArray *versionComponents = [[runtime substringWithRange: runtimeRange] componentsSeparatedByString: @"-"]; + + [self.simLocations addObject: @{ + @"path" : [baseInfoURL path], + @"title" : [NSString stringWithFormat: @"%@: %@ %@.%@", name, versionComponents[0], versionComponents[1], versionComponents[2]], + }]; + } + } + } + } + } + } + } +} + +#pragma mark - Handlers + +- (IBAction) handleRowSelect: (id) inSender +{ + if (inSender == self.locationTable) { + NSInteger clickedRow = [self.locationTable clickedRow]; + + if (clickedRow != -1) { + NSDictionary *rowInfo = [self.simLocations objectAtIndex: clickedRow]; + NSURL *devicePathURL = [[NSURL alloc] initFileURLWithPath: rowInfo[@"path"]]; + + if (devicePathURL != nil) { + [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs: @[ devicePathURL ]]; + } + } + } +} + +#pragma mark - NSTableViewDataSource + +- (NSInteger) numberOfRowsInTableView: (NSTableView *) inTableView +{ + return [self.simLocations count]; +} + +- (id) tableView: (NSTableView *) inTableView + objectValueForTableColumn: (NSTableColumn *) inTableColumn + row: (NSInteger) inRow +{ + id cellValue = nil; + + if ([inTableColumn.identifier isEqualToString: @"title"]) { + cellValue = [[self.simLocations objectAtIndex: inRow] objectForKey: @"title"]; + } + + return cellValue; } @end diff --git a/SimDirs/Base.lproj/MainMenu.xib b/SimDirs/Base.lproj/MainMenu.xib index db95d37..b6e9c17 100644 --- a/SimDirs/Base.lproj/MainMenu.xib +++ b/SimDirs/Base.lproj/MainMenu.xib @@ -1,7 +1,7 @@ - + - + @@ -10,9 +10,10 @@ - - + + + @@ -29,8 +30,6 @@ - - @@ -63,567 +62,15 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Default - - - - - - - Left to Right - - - - - - - Right to Left - - - - - - - - - - - Default - - - - - - - Left to Right - - - - - - - Right to Left - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -652,29 +99,70 @@ - - - - - - - - - - - - - + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +