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];
132 NSRunningApplication *compositionApp = [NSRunningApplication runningApplicationWithProcessIdentifier:pid];
133 [compositionApp activateWithOptions: NSApplicationActivateAllWindows
134 | (force ? NSApplicationActivateIgnoringOtherApps : 0)];
142 return NSProcessInfo.processInfo.operatingSystemVersion.majorVersion;
150 return NSProcessInfo.processInfo.operatingSystemVersion.minorVersion;
160 throw VuoException(
"Couldn't look up the system's architecture: %s", strerror(errno));
171 CFStringRef path = CFStringCreateWithCString(NULL, filePath.c_str(), kCFStringEncodingUTF8);
172 CFURLRef url = CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle,
true);
174 if (!CFURLSetResourcePropertyForKey(url, kCFURLIsPackageKey, kCFBooleanTrue, &error))
176 CFStringRef errorString = CFErrorCopyDescription(error);
178 CFRelease(errorString);
192 CFStringRef cfpath = CFStringCreateWithCString(
nullptr, path.c_str(), kCFStringEncodingUTF8);
194 throw VuoException(
"Path \"" + path +
"\" isn't a valid UTF-8 string.");
197 CFURLRef url = CFURLCreateWithFileSystemPath(
nullptr, cfpath, kCFURLPOSIXPathStyle,
true);
199 throw VuoException(
"Path \"" + path +
"\" isn't a valid POSIX path.");
214 return CFURLCreateBookmarkDataFromFile(
nullptr, url,
nullptr);
228 CFRelease(aliasData);
241 throw VuoException(
"Path \"" + path +
"\" isn't a macOS Alias.");
242 VuoDefer(^{ CFRelease(aliasData); });
247 Boolean isStale =
false;
248 CFErrorRef error =
nullptr;
249 CFURLRef resolvedURL = CFURLCreateByResolvingBookmarkData(
nullptr, aliasData, kCFBookmarkResolutionWithoutUIMask, url,
nullptr, &isStale, &error);
252 CFStringRef desc = CFErrorCopyDescription(error);
256 VuoDefer(^{ CFRelease(resolvedURL); });
258 CFStringRef resolvedPath = CFURLCopyFileSystemPath(resolvedURL, kCFURLPOSIXPathStyle);
261 VuoDefer(^{ CFRelease(resolvedPath); });