Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. #import <Cocoa/Cocoa.h>
  2.  
  3. @protocol FilePath <NSObject>
  4. + (instancetype)filePathForPathString:(NSString *)path;
  5. @end
  6.  
  7. @protocol NamedVersion <NSObject>
  8. - (NSString *)name;
  9. @end
  10.  
  11. @protocol ToolsInfo <NSObject>
  12.  
  13. - (instancetype)initWithXcodeFilePath:(id<FilePath>)path error:(NSError **)error;
  14.  
  15. - (BOOL)isAppleInternal;
  16. - (BOOL)isBeta;
  17. - (NSUInteger)toolsBetaVersion;
  18. - (id<NamedVersion>)toolsVersion;
  19. - (id<NamedVersion>)toolsBuildVersion;
  20.  
  21. @end
  22.  
  23. int main(int argc, const char * argv[]) {
  24. @autoreleasepool {
  25. NSURL *xcode;
  26. if (argc < 2) {
  27. // no path passed in
  28. xcode = [[NSURL fileURLWithPath:@"/var/db/xcode_select_link"] URLByResolvingSymlinksInPath];
  29. } else {
  30. NSURL *currentFolder = [NSURL fileURLWithPath:[[NSFileManager defaultManager] currentDirectoryPath]];
  31. xcode = [NSURL fileURLWithPath:@(argv[1]) relativeToURL:currentFolder];
  32. }
  33. while ([[xcode lastPathComponent] hasSuffix:@".app"] == NO) {
  34. xcode = [xcode URLByDeletingLastPathComponent];
  35. }
  36.  
  37. NSURL *bundleURL = [NSURL fileURLWithPath:@"./Contents/SharedFrameworks/DVTFoundation.framework" relativeToURL:xcode];
  38. NSBundle *bundle = [NSBundle bundleWithURL:bundleURL];
  39. if (bundle == nil) { return -1; }
  40.  
  41. if ([bundle load] == NO) { return -1; }
  42.  
  43. id<FilePath> path = [NSClassFromString(@"DVTFilePath") filePathForPathString: [xcode absoluteURL].path];
  44. id<ToolsInfo> info = [[NSClassFromString(@"DVTToolsInfo") alloc] initWithXcodeFilePath:path error:nil];
  45. if (info == nil) { return -1; }
  46. if (info.toolsVersion.name == nil) { return -1; }
  47. if (info.toolsBuildVersion.name == nil) { return -1; }
  48.  
  49. NSString *final = [NSString stringWithFormat:@"{ \"beta\": %lu, \"version\": \"%@\", \"build\": \"%@\" }",
  50. (unsigned long)info.toolsBetaVersion,
  51. info.toolsVersion.name,
  52. info.toolsBuildVersion.name];
  53. printf("%s", final.UTF8String);
  54. }
  55. return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement