Skip to content

Commit 978b1bb

Browse files
committed
added support for AppleTV OS ; simplified find_path() to avoid quoting root_path (some paths weren't working)
1 parent 76e8d08 commit 978b1bb

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' };
@@ -445,25 +436,39 @@ CFMutableArrayRef get_device_product_version_parts(AMDeviceRef device) {
445436
CFStringRef copy_device_support_path(AMDeviceRef device) {
446437
CFStringRef version = NULL;
447438
CFStringRef build = AMDeviceCopyValue(device, 0, CFSTR("BuildVersion"));
439+
CFStringRef deviceClass = AMDeviceCopyValue(device, 0, CFSTR("DeviceClass"));
448440
CFStringRef path = NULL;
449441
CFMutableArrayRef version_parts = get_device_product_version_parts(device);
450442

443+
NSLogVerbose(@"Device Class: %@", deviceClass);
444+
NSLogVerbose(@"build: %@", build);
445+
446+
CFStringRef deviceClassPath_platform;
447+
CFStringRef deviceClassPath_alt;
448+
if (CFStringCompare(CFSTR("AppleTV"), deviceClass, 0) == kCFCompareEqualTo) {
449+
deviceClassPath_platform = CFSTR("Platforms/AppleTVOS.platform/DeviceSupport");
450+
deviceClassPath_alt = CFSTR("tvOS\\ DeviceSupport");
451+
} else {
452+
deviceClassPath_platform = CFSTR("Platforms/iPhoneOS.platform/DeviceSupport");
453+
deviceClassPath_alt = CFSTR("iOS\\ DeviceSupport");
454+
}
451455
while (CFArrayGetCount(version_parts) > 0) {
452456
version = CFStringCreateByCombiningStrings(NULL, version_parts, CFSTR("."));
457+
NSLogVerbose(@"version: %@", version);
453458
if (path == NULL) {
454-
path = copy_xcode_path_for(CFSTR("iOS DeviceSupport"), CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ (%@)"), version, build));
459+
path = copy_xcode_path_for(deviceClassPath_alt, CFStringCreateWithFormat(NULL, NULL, CFSTR("%@\\ \\(%@\\)"), version, build));
455460
}
456461
if (path == NULL) {
457-
path = copy_xcode_path_for(CFSTR("Platforms/iPhoneOS.platform/DeviceSupport"), CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ (%@)"), version, build));
462+
path = copy_xcode_path_for(deviceClassPath_platform, CFStringCreateWithFormat(NULL, NULL, CFSTR("%@\\ \\(%@\\)"), version, build));
458463
}
459464
if (path == NULL) {
460-
path = copy_xcode_path_for(CFSTR("Platforms/iPhoneOS.platform/DeviceSupport"), CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ (*)"), version));
465+
path = copy_xcode_path_for(deviceClassPath_platform, CFStringCreateWithFormat(NULL, NULL, CFSTR("%@\\ \\(*\\)"), version));
461466
}
462467
if (path == NULL) {
463-
path = copy_xcode_path_for(CFSTR("Platforms/iPhoneOS.platform/DeviceSupport"), version);
468+
path = copy_xcode_path_for(deviceClassPath_platform, version);
464469
}
465470
if (path == NULL) {
466-
path = copy_xcode_path_for(CFSTR("Platforms/iPhoneOS.platform/DeviceSupport/Latest"), CFSTR(""));
471+
path = copy_xcode_path_for(CFStringCreateWithFormat(NULL, NULL, CFSTR("%@%@"), deviceClassPath_platform, CFSTR("/Latest")), CFSTR(""));
467472
}
468473
CFRelease(version);
469474
if (path != NULL) {
@@ -474,7 +479,7 @@ CFStringRef copy_device_support_path(AMDeviceRef device) {
474479

475480
CFRelease(version_parts);
476481
CFRelease(build);
477-
482+
CFRelease(deviceClass);
478483
if (path == NULL)
479484
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!");
480485

@@ -484,25 +489,40 @@ CFStringRef copy_device_support_path(AMDeviceRef device) {
484489
CFStringRef copy_developer_disk_image_path(AMDeviceRef device) {
485490
CFStringRef version = NULL;
486491
CFStringRef build = AMDeviceCopyValue(device, 0, CFSTR("BuildVersion"));
492+
CFStringRef deviceClass = AMDeviceCopyValue(device, 0, CFSTR("DeviceClass"));
487493
CFStringRef path = NULL;
488494
CFMutableArrayRef version_parts = get_device_product_version_parts(device);
489495

496+
NSLogVerbose(@"Device Class: %@", deviceClass);
497+
NSLogVerbose(@"build: %@", build);
498+
CFStringRef deviceClassPath_platform;
499+
CFStringRef deviceClassPath_alt;
500+
if (CFStringCompare(CFSTR("AppleTV"), deviceClass, 0) == kCFCompareEqualTo) {
501+
deviceClassPath_platform = CFSTR("Platforms/AppleTVOS.platform/DeviceSupport");
502+
deviceClassPath_alt = CFSTR("tvOS\\ DeviceSupport");
503+
} else {
504+
deviceClassPath_platform = CFSTR("Platforms/iPhoneOS.platform/DeviceSupport");
505+
deviceClassPath_alt = CFSTR("iOS\\ DeviceSupport");
506+
}
507+
// path = getPathForTVOS(device);
490508
while (CFArrayGetCount(version_parts) > 0) {
491509
version = CFStringCreateByCombiningStrings(NULL, version_parts, CFSTR("."));
492-
if (path == NULL) {
493-
path = copy_xcode_path_for(CFSTR("iOS DeviceSupport"), CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ (%@)/DeveloperDiskImage.dmg"), version, build));
510+
NSLogVerbose(@"version: %@", version);
511+
512+
if (path == NULL) {
513+
path = copy_xcode_path_for(CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/%@\\ \\(%@\\)"), deviceClassPath_alt, version, build), CFSTR("DeveloperDiskImage.dmg"));
494514
}
495515
if (path == NULL) {
496-
path = copy_xcode_path_for(CFSTR("Platforms/iPhoneOS.platform/DeviceSupport"), CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ (%@)/DeveloperDiskImage.dmg"), version, build));
497-
}
516+
path = copy_xcode_path_for(deviceClassPath_platform, CFStringCreateWithFormat(NULL, NULL, CFSTR("%@ (%@)/DeveloperDiskImage.dmg"), version, build));
517+
}
498518
if (path == NULL) {
499-
path = copy_xcode_path_for(CFSTR("Platforms/iPhoneOS.platform/DeviceSupport"), CFStringCreateWithFormat(NULL, NULL, CFSTR("*/%@ (*)/DeveloperDiskImage.dmg"), version));
519+
path = copy_xcode_path_for(CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/%@\\ \\(*\\)"), deviceClassPath_platform, version), CFSTR("DeveloperDiskImage.dmg"));
500520
}
501521
if (path == NULL) {
502-
path = copy_xcode_path_for(CFSTR("Platforms/iPhoneOS.platform/DeviceSupport"), CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/DeveloperDiskImage.dmg"), version));
522+
path = copy_xcode_path_for(deviceClassPath_platform, CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/DeveloperDiskImage.dmg"), version));
503523
}
504524
if (path == NULL) {
505-
path = copy_xcode_path_for(CFSTR("Platforms/iPhoneOS.platform/DeviceSupport/Latest"), CFSTR("DeveloperDiskImage.dmg"));
525+
path = copy_xcode_path_for(CFStringCreateWithFormat(NULL, NULL, CFSTR("%@/Latest"), deviceClassPath_platform), CFSTR("/DeveloperDiskImage.dmg"));
506526
}
507527
CFRelease(version);
508528
if (path != NULL) {
@@ -513,6 +533,7 @@ CFStringRef copy_developer_disk_image_path(AMDeviceRef device) {
513533

514534
CFRelease(version_parts);
515535
CFRelease(build);
536+
CFRelease(deviceClass);
516537
if (path == NULL)
517538
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!");
518539

@@ -643,7 +664,7 @@ CFStringRef copy_disk_app_identifier(CFURLRef disk_app_url) {
643664
CFURLRef plist_url = CFURLCreateCopyAppendingPathComponent(NULL, disk_app_url, CFSTR("Info.plist"), false);
644665
CFReadStreamRef plist_stream = CFReadStreamCreateWithFile(NULL, plist_url);
645666
if (!CFReadStreamOpen(plist_stream)) {
646-
on_error(@"Cannot read Info.plist file: %@", plist_url);
667+
on_error(@"Cannot read Info.plist file: %@", plist_url);
647668
}
648669

649670
CFPropertyListRef plist = CFPropertyListCreateWithStream(NULL, plist_stream, 0, kCFPropertyListImmutable, NULL, NULL);
@@ -1676,7 +1697,7 @@ void device_callback(struct am_device_notification_callback_info *info, void *ar
16761697
switch (info->msg) {
16771698
case ADNCI_MSG_CONNECTED:
16781699
if(device_id != NULL || !debug || AMDeviceGetInterfaceType(info->dev) != 2) {
1679-
if (no_wifi && AMDeviceGetInterfaceType(info->dev) == 2)
1700+
if (no_wifi && AMDeviceGetInterfaceType(info->dev) == 2)
16801701
{
16811702
NSLogVerbose(@"Skipping wifi device (type: %d)", AMDeviceGetInterfaceType(info->dev));
16821703
}

0 commit comments

Comments
 (0)