Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import <Cocoa/Cocoa.h>
- @protocol FilePath <NSObject>
- + (instancetype)filePathForPathString:(NSString *)path;
- @end
- @protocol NamedVersion <NSObject>
- - (NSString *)name;
- @end
- @protocol ToolsInfo <NSObject>
- - (instancetype)initWithXcodeFilePath:(id<FilePath>)path error:(NSError **)error;
- - (BOOL)isAppleInternal;
- - (BOOL)isBeta;
- - (NSUInteger)toolsBetaVersion;
- - (id<NamedVersion>)toolsVersion;
- - (id<NamedVersion>)toolsBuildVersion;
- @end
- int main(int argc, const char * argv[]) {
- @autoreleasepool {
- NSURL *xcode;
- if (argc < 2) {
- // no path passed in
- xcode = [[NSURL fileURLWithPath:@"/var/db/xcode_select_link"] URLByResolvingSymlinksInPath];
- } else {
- NSURL *currentFolder = [NSURL fileURLWithPath:[[NSFileManager defaultManager] currentDirectoryPath]];
- xcode = [NSURL fileURLWithPath:@(argv[1]) relativeToURL:currentFolder];
- }
- while ([[xcode lastPathComponent] hasSuffix:@".app"] == NO) {
- xcode = [xcode URLByDeletingLastPathComponent];
- }
- NSURL *bundleURL = [NSURL fileURLWithPath:@"./Contents/SharedFrameworks/DVTFoundation.framework" relativeToURL:xcode];
- NSBundle *bundle = [NSBundle bundleWithURL:bundleURL];
- if (bundle == nil) { return -1; }
- if ([bundle load] == NO) { return -1; }
- id<FilePath> path = [NSClassFromString(@"DVTFilePath") filePathForPathString: [xcode absoluteURL].path];
- id<ToolsInfo> info = [[NSClassFromString(@"DVTToolsInfo") alloc] initWithXcodeFilePath:path error:nil];
- if (info == nil) { return -1; }
- if (info.toolsVersion.name == nil) { return -1; }
- if (info.toolsBuildVersion.name == nil) { return -1; }
- NSString *final = [NSString stringWithFormat:@"{ \"beta\": %lu, \"version\": \"%@\", \"build\": \"%@\" }",
- (unsigned long)info.toolsBetaVersion,
- info.toolsVersion.name,
- info.toolsBuildVersion.name];
- printf("%s", final.UTF8String);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement