14 #ifndef NS_RETURNS_INNER_POINTER
15 #define NS_RETURNS_INNER_POINTER
17 #include <Cocoa/Cocoa.h>
26 NSURL *url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:filePath.c_str()]];
28 throw VuoException(
"Couldn't move file '" + filePath +
"' to the trash: Couldn't create NSURL.");
31 bool success = [[NSFileManager defaultManager] trashItemAtURL:url resultingItemURL:nil error:&error];
33 throw VuoException(
string(
"Couldn't move file '" + filePath +
"' to the trash: ") + [[error localizedDescription] UTF8String]);
48 NSString *pathNS = [NSString stringWithUTF8String:path.c_str()];
50 throw VuoException(
"Path \"" + path +
"\" isn't a valid UTF-8 string.");
52 NSURL *baseURL = [NSURL fileURLWithPath:pathNS isDirectory:YES];
54 throw VuoException(
"Path \"" + path +
"\" isn't a valid directory.");
56 NSURL *temporaryDirectoryURL = nil;
60 temporaryDirectoryURL = [[NSFileManager defaultManager] URLForDirectory:NSItemReplacementDirectory
61 inDomain:NSUserDomainMask
62 appropriateForURL:baseURL
67 NSError *underlyingError = [[error userInfo] objectForKey:NSUnderlyingErrorKey];
68 if ([[underlyingError domain] isEqualToString:NSPOSIXErrorDomain]
69 && [underlyingError code] == ENOENT)
72 baseURL = [baseURL URLByDeletingLastPathComponent];
75 throw VuoException((
string(
"Couldn't get a temp folder: ") + [[error localizedDescription] UTF8String]).c_str());
77 else if (!temporaryDirectoryURL)
78 throw VuoException(
"Couldn't get a temp folder for path \"" + path +
"\".");
83 return [[temporaryDirectoryURL path] UTF8String];
95 NSString *pathNS = [NSString stringWithUTF8String:path.c_str()];
97 throw VuoException(
"Path \"" + path +
"\" isn't a valid UTF-8 string.");
99 NSDictionary *fileAttributes;
102 NSError *error = nil;
103 fileAttributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:pathNS error:&error];
106 NSError *underlyingError = [[error userInfo] objectForKey:NSUnderlyingErrorKey];
107 if ([[underlyingError domain] isEqualToString:NSPOSIXErrorDomain]
108 && [underlyingError code] == ENOENT)
111 pathNS = [pathNS stringByDeletingLastPathComponent];
114 throw VuoException((
string(
"Couldn't get information about path: ") + [[error localizedDescription] UTF8String]).c_str());
116 else if (!fileAttributes)
117 throw VuoException(
"Couldn't get information about path \"" + path +
"\".");
122 unsigned long long freeSpace = [fileAttributes[NSFileSystemFreeSize] longLongValue];
133 NSRunningApplication *compositionApp = [NSRunningApplication runningApplicationWithProcessIdentifier:pid];
134 [compositionApp activateWithOptions: NSApplicationActivateAllWindows
135 | (force ? NSApplicationActivateIgnoringOtherApps : 0)];
143 return NSProcessInfo.processInfo.operatingSystemVersion.minorVersion;
151 NSImage *image = [[NSImage alloc] initWithContentsOfFile:[NSString stringWithUTF8String:imagePath.c_str()]];
152 [[NSWorkspace sharedWorkspace] setIcon:image forFile:[NSString stringWithUTF8String:filePath.c_str()] options:0];
162 CFStringRef path = CFStringCreateWithCString(NULL, filePath.c_str(), kCFStringEncodingUTF8);
163 CFURLRef url = CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle,
true);
165 if (!CFURLSetResourcePropertyForKey(url, kCFURLIsPackageKey, kCFBooleanTrue, &error))
167 CFStringRef errorString = CFErrorCopyDescription(error);
168 CFIndex errorLength = CFStringGetLength(errorString);
169 char *errorCString = (
char *)malloc(errorLength+1);
170 CFStringGetCString(errorString, errorCString, errorLength+1, kCFStringEncodingUTF8);
171 VUserLog(
"Warning: Couldn't set kCFURLIsPackageKey on this bundle: %s", errorCString);
173 CFRelease(errorString);
187 CFStringRef cfpath = CFStringCreateWithCString(
nullptr, path.c_str(), kCFStringEncodingUTF8);
189 throw VuoException(
"Path \"" + path +
"\" isn't a valid UTF-8 string.");
192 CFURLRef url = CFURLCreateWithFileSystemPath(
nullptr, cfpath, kCFURLPOSIXPathStyle,
true);
194 throw VuoException(
"Path \"" + path +
"\" isn't a valid POSIX path.");
209 return CFURLCreateBookmarkDataFromFile(
nullptr, url,
nullptr);
223 CFRelease(aliasData);
232 const char *useUTF8StringPtr = NULL;
233 char *freeUTF8StringPtr = NULL;
235 if ((useUTF8StringPtr = CFStringGetCStringPtr(cfString, kCFStringEncodingUTF8)) == NULL)
237 CFIndex stringLength = CFStringGetLength(cfString);
238 CFIndex maxBytes = 4 * stringLength + 1;
239 freeUTF8StringPtr = (
char *)malloc(maxBytes);
240 CFStringGetCString(cfString, freeUTF8StringPtr, maxBytes, kCFStringEncodingUTF8);
241 useUTF8StringPtr = freeUTF8StringPtr;
244 string stdString(useUTF8StringPtr);
246 if (freeUTF8StringPtr != NULL)
247 free(freeUTF8StringPtr);
261 throw VuoException(
"Path \"" + path +
"\" isn't a macOS Alias.");
262 VuoDefer(^{ CFRelease(aliasData); });
267 Boolean isStale =
false;
268 CFErrorRef error =
nullptr;
269 CFURLRef resolvedURL = CFURLCreateByResolvingBookmarkData(
nullptr, aliasData, kCFBookmarkResolutionWithoutUIMask, url,
nullptr, &isStale, &error);
272 CFStringRef desc = CFErrorCopyDescription(error);
276 VuoDefer(^{ CFRelease(resolvedURL); });
278 CFStringRef resolvedPath = CFURLCopyFileSystemPath(resolvedURL, kCFURLPOSIXPathStyle);
281 VuoDefer(^{ CFRelease(resolvedPath); });