15 #ifndef NS_RETURNS_INNER_POINTER
16 #define NS_RETURNS_INNER_POINTER
18 #include <Cocoa/Cocoa.h>
27 NSURL *url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:filePath.c_str()]];
29 throw VuoException(
"Couldn't move file '" + filePath +
"' to the trash: Couldn't create NSURL.");
32 bool success = [[NSFileManager defaultManager] trashItemAtURL:url resultingItemURL:nil error:&error];
34 throw VuoException(
string(
"Couldn't move file '" + filePath +
"' to the trash: ") + [[error localizedDescription] UTF8String]);
49 NSString *pathNS = [NSString stringWithUTF8String:path.c_str()];
51 throw VuoException(
"Path \"" + path +
"\" isn't a valid UTF-8 string.");
53 NSURL *baseURL = [NSURL fileURLWithPath:pathNS isDirectory:YES];
55 throw VuoException(
"Path \"" + path +
"\" isn't a valid directory.");
57 NSURL *temporaryDirectoryURL = nil;
61 temporaryDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSItemReplacementDirectory
62 inDomain:NSUserDomainMask
63 appropriateForURL:baseURL
68 NSError *underlyingError = [[error userInfo] objectForKey:NSUnderlyingErrorKey];
69 if ([[underlyingError domain] isEqualToString:NSPOSIXErrorDomain]
70 && [underlyingError code] == ENOENT)
73 baseURL = [baseURL URLByDeletingLastPathComponent];
76 throw VuoException((
string(
"Couldn't get a temp folder: ") + [[error localizedDescription] UTF8String]).c_str());
78 else if (!temporaryDirectoryURL)
79 throw VuoException(
"Couldn't get a temp folder for path \"" + path +
"\".");
84 return [[temporaryDirectoryURL path] UTF8String];
96 NSString *pathNS = [NSString stringWithUTF8String:path.c_str()];
98 throw VuoException(
"Path \"" + path +
"\" isn't a valid UTF-8 string.");
100 NSDictionary *fileAttributes;
103 NSError *error = nil;
104 fileAttributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:pathNS error:&error];
107 NSError *underlyingError = [[error userInfo] objectForKey:NSUnderlyingErrorKey];
108 if ([[underlyingError domain] isEqualToString:NSPOSIXErrorDomain]
109 && [underlyingError code] == ENOENT)
112 pathNS = [pathNS stringByDeletingLastPathComponent];
115 throw VuoException((
string(
"Couldn't get information about path: ") + [[error localizedDescription] UTF8String]).c_str());
117 else if (!fileAttributes)
118 throw VuoException(
"Couldn't get information about path \"" + path +
"\".");
123 unsigned long long freeSpace = [fileAttributes[NSFileSystemFreeSize] longLongValue];
134 NSRunningApplication *compositionApp = [NSRunningApplication runningApplicationWithProcessIdentifier:pid];
135 [compositionApp activateWithOptions: NSApplicationActivateAllWindows
136 | (force ? NSApplicationActivateIgnoringOtherApps : 0)];
144 return NSProcessInfo.processInfo.operatingSystemVersion.majorVersion;
152 return NSProcessInfo.processInfo.operatingSystemVersion.minorVersion;
160 NSImage *image = [[NSImage alloc] initWithContentsOfFile:[NSString stringWithUTF8String:imagePath.c_str()]];
161 [[NSWorkspace sharedWorkspace] setIcon:image forFile:[NSString stringWithUTF8String:filePath.c_str()] options:0];
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); });