Use NSURL and writeObjects for pasteboard files

Create an NSURL from the path and write it to the general pasteboard
with writeObjects:. Add nil checks for the created NSURL and remove the
legacy NSFilenamesPboardType setPropertyList code.
This commit is contained in:
2026-01-31 02:10:20 +01:00
parent bd22ad5500
commit 1b646c1096
+5 -2
View File
@@ -13,10 +13,13 @@ int copyFileToPasteboard(char* path) {
NSString *strPath = [NSString stringWithUTF8String:path]; NSString *strPath = [NSString stringWithUTF8String:path];
if (!strPath) return 0; if (!strPath) return 0;
NSURL *url = [NSURL fileURLWithPath:strPath];
if (!url) return 0;
NSPasteboard *pb = [NSPasteboard generalPasteboard]; NSPasteboard *pb = [NSPasteboard generalPasteboard];
[pb clearContents]; [pb clearContents];
[pb declareTypes:@[NSFilenamesPboardType] owner:nil];
return [pb setPropertyList:@[strPath] forType:NSFilenamesPboardType] ? 1 : 0; return [pb writeObjects:@[url]] ? 1 : 0;
} }
} }
*/ */