15#include <AppKit/AppKit.h>
16#include <sys/utsname.h>
25 NSURL *url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:filePath.c_str()]];
27 throw VuoException(
"Couldn't move file '" + filePath +
"' to the trash: Couldn't create NSURL.");
30 bool success = [[NSFileManager defaultManager] trashItemAtURL:url resultingItemURL:nil error:&error];
32 throw VuoException(
string(
"Couldn't move file '" + filePath +
"' to the trash: ") + [[error localizedDescription] UTF8String]);
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];
141#pragma clang diagnostic push
142#pragma clang diagnostic ignored "-Wdeprecated-declarations"
143 ProcessSerialNumber psn;
144 OSErr ret = GetProcessForPID(pid, &psn);
147 VUserLog(
"GetProcessForPID(%d) failed: %d", pid, ret);
151 ret = SetFrontProcess(&psn);
154 VUserLog(
"SetFrontProcess(%d) failed: %d", pid, ret);
157#pragma clang diagnostic pop
165 return NSProcessInfo.processInfo.operatingSystemVersion.majorVersion;
173 return NSProcessInfo.processInfo.operatingSystemVersion.minorVersion;
183 throw VuoException(
"Couldn't look up the system's architecture: %s", strerror(errno));
194 CFStringRef path = CFStringCreateWithCString(NULL, filePath.c_str(), kCFStringEncodingUTF8);
195 CFURLRef url = CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle,
true);
197 if (!CFURLSetResourcePropertyForKey(url, kCFURLIsPackageKey, kCFBooleanTrue, &error))
199 CFStringRef errorString = CFErrorCopyDescription(error);
201 CFRelease(errorString);
215 CFStringRef cfpath = CFStringCreateWithCString(
nullptr, path.c_str(), kCFStringEncodingUTF8);
217 throw VuoException(
"Path \"" + path +
"\" isn't a valid UTF-8 string.");
220 CFURLRef url = CFURLCreateWithFileSystemPath(
nullptr, cfpath, kCFURLPOSIXPathStyle,
true);
222 throw VuoException(
"Path \"" + path +
"\" isn't a valid POSIX path.");
237 return CFURLCreateBookmarkDataFromFile(
nullptr, url,
nullptr);
251 CFRelease(aliasData);
264 throw VuoException(
"Path \"" + path +
"\" isn't a macOS Alias.");
265 VuoDefer(^{ CFRelease(aliasData); });
270 Boolean isStale =
false;
271 CFErrorRef error =
nullptr;
272 CFURLRef resolvedURL = CFURLCreateByResolvingBookmarkData(
nullptr, aliasData, kCFBookmarkResolutionWithoutUIMask, url,
nullptr, &isStale, &error);
275 CFStringRef desc = CFErrorCopyDescription(error);
279 VuoDefer(^{ CFRelease(resolvedURL); });
281 CFStringRef resolvedPath = CFURLCopyFileSystemPath(resolvedURL, kCFURLPOSIXPathStyle);
284 VuoDefer(^{ CFRelease(resolvedPath); });