macOS: move deleted file to Trash

As opposed to permanently deleting it.  As requested:

  https://sourceforge.net/p/tuxpaint/feature-requests/148/
This commit is contained in:
Mark Kim 2022-07-02 22:03:41 -04:00
parent d289d407ad
commit ed885f887d
5 changed files with 30 additions and 7 deletions

View file

@ -221,3 +221,19 @@ const char *apple_picturesPath(void)
return p;
}
int apple_trash(const char *path)
{
NSFileManager *manager = [NSFileManager defaultManager];
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:path]];
NSURL *trash = nil;
NSError *error = nil;
[manager trashItemAtURL:url resultingItemURL:&trash error:&error];
if(error) {
DEBUG_PRINTF("%s\n", [[error localizedDescription] UTF8String]);
return -1;
}
return 0;
}