Skip to content

Commit 71e14be

Browse files
authored
Merge pull request #228 from Vrixyz/master
Added support for AppleTV OS
2 parents 022fd28 + 978b1bb commit 71e14be

File tree

1 file changed

+47
-26
lines changed

1 file changed

+47
-26
lines changed

src/ios-deploy/ios-deploy.m

Lines changed: 47 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -185,23 +185,14 @@ Boolean path_exists(CFTypeRef path) {
185185

186186
CFStringRef find_path(CFStringRef rootPath, CFStringRef namePattern, CFStringRef expression) {
187187
FILE *fpipe = NULL;
188-
CFStringRef quotedRootPath = rootPath;
189188
CFStringRef cf_command;
190189
CFRange slashLocation;
191190

192-
if (CFStringGetCharacterAtIndex(rootPath, 0) != '`') {
193-
quotedRootPath = CFStringCreateWithFormat(NULL, NULL, CFSTR("'%@'"), rootPath);
194-
}
195-
196191
slashLocation = CFStringFind(namePattern, CFSTR("/"), 0);
197192
if (slashLocation.location == kCFNotFound) {
198-
cf_command = CFStringCreateWithFormat(NULL, NULL, CFSTR("find %@ -name '%@' %@ 2>/dev/null | sort | tail -n 1"), quotedRootPath, namePattern, expression);
193+
cf_command = CFStringCreateWithFormat(NULL, NULL, CFSTR("find %@ -name '%@' %@ 2>/dev/null | sort | tail -n 1"), rootPath, namePattern, expression);
199194
} else {
200-
cf_command = CFStringCreateWithFormat(NULL, NULL, CFSTR("find %@ -path '%@' %@ 2>/dev/null | sort | tail -n 1"), quotedRootPath, namePattern, expression);
201-
}
202-
203-
if (quotedRootPath != rootPath) {
204-
CFRelease(quotedRootPath);
195+
cf_command = CFStringCreateWithFormat(NULL, NULL, CFSTR("find %@ -path '%@' %@ 2>/dev/null | sort | tail -n 1"), rootPath, namePattern, expression);
205196
}
206197

207198
char command[1024] = { '\0' };
@@ -457,25 +448,39 @@ CFMutableArrayRef get_device_product_version_parts(AMDeviceRef device) {
457448
CFStringRef copy_device_support_path(AMDeviceRef device) {
458449
CFStringRef version = NULL;
459450
CFStringRef build = AMDeviceCopyValue(device, 0, CFSTR("BuildVersion"));
451+
CFStringRef deviceClass = AMDeviceCopyValue(device, 0, CFSTR("DeviceClass"));
460452
CFStringRef path = NULL;
461453
CFMutableArrayRef version_parts = get_device_product_version_parts(device);
462454

455+
NSLogVerbose(@"Device Class: %@", deviceClass);
456+
NSLogVerbose(@"build: %@", build);
457+
458+
CFStringRef deviceClassPath_platform;
459+
CFStringRef deviceClassPath_alt;
460+
if (CFStringCompare(CFSTR("AppleTV"), deviceClass, 0) == kCFCompareEqualTo) {
461+
deviceClassPath_platform = CFSTR("Platforms/AppleTVOS.platform/DeviceSupport");
462+
deviceClassPath_alt = CFSTR("tvOS\\ DeviceSupport");
463+
} else {
464+
deviceClassPath_platform = CFSTR("Platforms/iPhoneOS.platform/DeviceSupport");
465+
deviceClassPath_alt = CFSTR("iOS\\ DeviceSupport");
466+
}
463467
while (CFArrayGetCount(version_parts) > 0) {
464468
version = CFStringCreateByCombiningStrings(NULL, version_parts, CFSTR("."));
469+
NSLogVerbose(@"version: %@", version);
465470
if (path == NULL) {
466-
path = copy_xcode_path_for(CFSTR("iOS DeviceSupport"), CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ (%@)"), version, build));
471+
path = copy_xcode_path_for(deviceClassPath_alt, CFStringCreateWithFormat(NULL, NULL, CFSTR("%@\\ \\(%@\\)"), version, build));
467472
}
468473
if (path == NULL) {
469-
path = copy_xcode_path_for(CFSTR("Platforms/iPhoneOS.platform/DeviceSupport"), CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ (%@)"), version, build));
474+
path = copy_xcode_path_for(deviceClassPath_platform, CFStringCreateWithFormat(NULL, NULL, CFSTR("%@\\ \\(%@\\)"), version, build));
470475
}
471476
if (path == NULL) {
472-
path = copy_xcode_path_for(CFSTR("Platforms/iPhoneOS.platform/DeviceSupport"), CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ (*)"), version));
477+
path = copy_xcode_path_for(deviceClassPath_platform, CFStringCreateWithFormat(NULL, NULL, CFSTR("%@\\ \\(*\\)"), version));
473478
}
474479
if (path == NULL) {
475-
path = copy_xcode_path_for(CFSTR("Platforms/iPhoneOS.platform/DeviceSupport"), version);
480+
path = copy_xcode_path_for(deviceClassPath_platform, version);
476481
}
477482
if (path == NULL) {
478-
path = copy_xcode_path_for(CFSTR("Platforms/iPhoneOS.platform/DeviceSupport/Latest"), CFSTR(""));
483+
path = copy_xcode_path_for(CFStringCreateWithFormat(NULL, NULL, CFSTR("%@%@"), deviceClassPath_platform, CFSTR("/Latest")), CFSTR(""));
479484
}
480485
CFRelease(version);
481486
if (path != NULL) {
@@ -486,7 +491,7 @@ CFStringRef copy_device_support_path(AMDeviceRef device) {
486491

487492
CFRelease(version_parts);
488493
CFRelease(build);
489-
494+
CFRelease(deviceClass);
490495
if (path == NULL)
491496
on_error(@"Unable to locate DeviceSupport directory. This probably means you don't have Xcode installed, you will need to launch the app manually and logging output will not be shown!");
492497

@@ -496,25 +501,40 @@ CFStringRef copy_device_support_path(AMDeviceRef device) {
496501
CFStringRef copy_developer_disk_image_path(AMDeviceRef device) {
497502
CFStringRef version = NULL;
498503
CFStringRef build = AMDeviceCopyValue(device, 0, CFSTR("BuildVersion"));
504+
CFStringRef deviceClass = AMDeviceCopyValue(device, 0, CFSTR("DeviceClass"));
499505
CFStringRef path = NULL;
500506
CFMutableArrayRef version_parts = get_device_product_version_parts(device);
501507

508+
NSLogVerbose(@"Device Class: %@", deviceClass);
509+
NSLogVerbose(@"build: %@", build);
510+
CFStringRef deviceClassPath_platform;
511+
CFStringRef deviceClassPath_alt;
512+
if (CFStringCompare(CFSTR("AppleTV"), deviceClass, 0) == kCFCompareEqualTo) {
513+
deviceClassPath_platform = CFSTR("Platforms/AppleTVOS.platform/DeviceSupport");
514+
deviceClassPath_alt = CFSTR("tvOS\\ DeviceSupport");
515+
} else {
516+
deviceClassPath_platform = CFSTR("Platforms/iPhoneOS.platform/DeviceSupport");
517+
deviceClassPath_alt = CFSTR("iOS\\ DeviceSupport");
518+
}
519+
// path = getPathForTVOS(device);
502520
while (CFArrayGetCount(version_parts) > 0) {
503521
version = CFStringCreateByCombiningStrings(NULL, version_parts, CFSTR("."));
504-
if (path == NULL) {
505-
path = copy_xcode_path_for(CFSTR("iOS DeviceSupport"), CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ (%@)/DeveloperDiskImage.dmg"), version, build));
522+
NSLogVerbose(@"version: %@", version);
523+
524+
if (path == NULL) {
525+
path = copy_xcode_path_for(CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/%@\\ \\(%@\\)"), deviceClassPath_alt, version, build), CFSTR("DeveloperDiskImage.dmg"));
506526
}
507527
if (path == NULL) {
508-
path = copy_xcode_path_for(CFSTR("Platforms/iPhoneOS.platform/DeviceSupport"), CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ (%@)/DeveloperDiskImage.dmg"), version, build));
509-
}
528+
path = copy_xcode_path_for(deviceClassPath_platform, CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ (%@)/DeveloperDiskImage.dmg"), version, build));
529+
}
510530
if (path == NULL) {
511-
path = copy_xcode_path_for(CFSTR("Platforms/iPhoneOS.platform/DeviceSupport"), CFStringCreateWithFormat(NULL, NULL, CFSTR("*/%@ (*)/DeveloperDiskImage.dmg"), version));
531+
path = copy_xcode_path_for(CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/%@\\ \\(*\\)"), deviceClassPath_platform, version), CFSTR("DeveloperDiskImage.dmg"));
512532
}
513533
if (path == NULL) {
514-
path = copy_xcode_path_for(CFSTR("Platforms/iPhoneOS.platform/DeviceSupport"), CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/DeveloperDiskImage.dmg"), version));
534+
path = copy_xcode_path_for(deviceClassPath_platform, CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/DeveloperDiskImage.dmg"), version));
515535
}
516536
if (path == NULL) {
517-
path = copy_xcode_path_for(CFSTR("Platforms/iPhoneOS.platform/DeviceSupport/Latest"), CFSTR("DeveloperDiskImage.dmg"));
537+
path = copy_xcode_path_for(CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/Latest"), deviceClassPath_platform), CFSTR("/DeveloperDiskImage.dmg"));
518538
}
519539
CFRelease(version);
520540
if (path != NULL) {
@@ -525,6 +545,7 @@ CFStringRef copy_developer_disk_image_path(AMDeviceRef device) {
525545

526546
CFRelease(version_parts);
527547
CFRelease(build);
548+
CFRelease(deviceClass);
528549
if (path == NULL)
529550
on_error(@"Unable to locate DeveloperDiskImage.dmg. This probably means you don't have Xcode installed, you will need to launch the app manually and logging output will not be shown!");
530551

@@ -655,7 +676,7 @@ CFStringRef copy_disk_app_identifier(CFURLRef disk_app_url) {
655676
CFURLRef plist_url = CFURLCreateCopyAppendingPathComponent(NULL, disk_app_url, CFSTR("Info.plist"), false);
656677
CFReadStreamRef plist_stream = CFReadStreamCreateWithFile(NULL, plist_url);
657678
if (!CFReadStreamOpen(plist_stream)) {
658-
on_error(@"Cannot read Info.plist file: %@", plist_url);
679+
on_error(@"Cannot read Info.plist file: %@", plist_url);
659680
}
660681

661682
CFPropertyListRef plist = CFPropertyListCreateWithStream(NULL, plist_stream, 0, kCFPropertyListImmutable, NULL, NULL);
@@ -1688,7 +1709,7 @@ void device_callback(struct am_device_notification_callback_info *info, void *ar
16881709
switch (info->msg) {
16891710
case ADNCI_MSG_CONNECTED:
16901711
if(device_id != NULL || !debug || AMDeviceGetInterfaceType(info->dev) != 2) {
1691-
if (no_wifi && AMDeviceGetInterfaceType(info->dev) == 2)
1712+
if (no_wifi && AMDeviceGetInterfaceType(info->dev) == 2)
16921713
{
16931714
NSLogVerbose(@"Skipping wifi device (type: %d)", AMDeviceGetInterfaceType(info->dev));
16941715
}

0 commit comments

Comments
 (0)