47 NSString *pathNS = [NSString stringWithUTF8String:path.c_str()];
49 throw VuoException(
"Path \"" + path +
"\" isn't a valid UTF-8 string.");
51 NSURL *baseURL = [NSURL fileURLWithPath:pathNS isDirectory:YES];
53 throw VuoException(
"Path \"" + path +
"\" isn't a valid directory.");
55 NSURL *temporaryDirectoryURL = nil;
59 temporaryDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSItemReplacementDirectory
60 inDomain:NSUserDomainMask
61 appropriateForURL:baseURL
66 NSError *underlyingError = [[error userInfo] objectForKey:NSUnderlyingErrorKey];
67 if ([[underlyingError domain] isEqualToString:NSPOSIXErrorDomain]
68 && [underlyingError code] == ENOENT)
71 baseURL = [baseURL URLByDeletingLastPathComponent];
74 throw VuoException((
string(
"Couldn't get a temp folder: ") + [[error localizedDescription] UTF8String]).c_str());
76 else if (!temporaryDirectoryURL)
77 throw VuoException(
"Couldn't get a temp folder for path \"" + path +
"\".");
82 return [[temporaryDirectoryURL path] UTF8String];
94 NSString *pathNS = [NSString stringWithUTF8String:path.c_str()];
96 throw VuoException(
"Path \"" + path +
"\" isn't a valid UTF-8 string.");
98 NSDictionary *fileAttributes;
101 NSError *error = nil;
102 fileAttributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:pathNS error:&error];
105 NSError *underlyingError = [[error userInfo] objectForKey:NSUnderlyingErrorKey];
106 if ([[underlyingError domain] isEqualToString:NSPOSIXErrorDomain]
107 && [underlyingError code] == ENOENT)
110 pathNS = [pathNS stringByDeletingLastPathComponent];
113 throw VuoException((
string(
"Couldn't get information about path: ") + [[error localizedDescription] UTF8String]).c_str());
115 else if (!fileAttributes)
116 throw VuoException(
"Couldn't get information about path \"" + path +
"\".");
121 unsigned long long freeSpace = [fileAttributes[NSFileSystemFreeSize] longLongValue];
132 if ([NSApp respondsToSelector:
@selector(yieldActivationToApplication:)])
134 NSRunningApplication *compositionApp = [NSRunningApplication runningApplicationWithProcessIdentifier:pid];
135 [NSApp performSelector:
@selector(yieldActivationToApplication:) withObject:compositionApp];
148#pragma clang diagnostic push
149#pragma clang diagnostic ignored "-Wdeprecated-declarations"
150 ProcessSerialNumber psn;
151 OSErr ret = GetProcessForPID(pid, &psn);
154 VUserLog(
"GetProcessForPID(%d) failed: %d", pid, ret);
158 ret = SetFrontProcess(&psn);
161 VUserLog(
"SetFrontProcess(%d) failed: %d", pid, ret);
164#pragma clang diagnostic pop
196 int majorVersion = -1;
197 int minorVersion = -1;
198 sscanf(NSProcessInfo.processInfo.operatingSystemVersionString.UTF8String,
"Version %d.%d", &majorVersion, &minorVersion);
200 if (majorVersion != -1 && minorVersion != -1)
203 return NSProcessInfo.processInfo.operatingSystemVersion.minorVersion;
224 CFStringRef path = CFStringCreateWithCString(NULL, filePath.c_str(), kCFStringEncodingUTF8);
225 CFURLRef url = CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle,
true);
227 if (!CFURLSetResourcePropertyForKey(url, kCFURLIsPackageKey, kCFBooleanTrue, &error))
229 CFStringRef errorString = CFErrorCopyDescription(error);
231 CFRelease(errorString);
245 CFStringRef cfpath = CFStringCreateWithCString(
nullptr, path.c_str(), kCFStringEncodingUTF8);
247 throw VuoException(
"Path \"" + path +
"\" isn't a valid UTF-8 string.");
250 CFURLRef url = CFURLCreateWithFileSystemPath(
nullptr, cfpath, kCFURLPOSIXPathStyle,
true);
252 throw VuoException(
"Path \"" + path +
"\" isn't a valid POSIX path.");
294 throw VuoException(
"Path \"" + path +
"\" isn't a macOS Alias.");
295 VuoDefer(^{ CFRelease(aliasData); });
300 Boolean isStale =
false;
301 CFErrorRef error =
nullptr;
302 CFURLRef resolvedURL = CFURLCreateByResolvingBookmarkData(
nullptr, aliasData, kCFBookmarkResolutionWithoutUIMask, url,
nullptr, &isStale, &error);
305 CFStringRef desc = CFErrorCopyDescription(error);
309 VuoDefer(^{ CFRelease(resolvedURL); });
311 CFStringRef resolvedPath = CFURLCopyFileSystemPath(resolvedURL, kCFURLPOSIXPathStyle);
314 VuoDefer(^{ CFRelease(resolvedPath); });