From 280cb54a3620e0eed0f809a88f3c140999c5e8cc Mon Sep 17 00:00:00 2001 From: Eric Petit Date: Tue, 28 Mar 2006 06:26:13 +0000 Subject: [PATCH] Finder-independent trashPath: method --- macosx/Torrent.m | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/macosx/Torrent.m b/macosx/Torrent.m index 4c4233552..28d279bd3 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -370,21 +370,21 @@ - (void) trashPath: (NSString *) path { - NSString * string; - NSAppleScript * appleScript; - NSDictionary * error; - - string = [NSString stringWithFormat: - @"tell application \"Finder\"\n" - " move (POSIX file \"%@\") to trash\n" - "end tell", path]; - - appleScript = [[NSAppleScript alloc] initWithSource: string]; - if( ![appleScript executeAndReturnError: &error] ) + if( ![[NSWorkspace sharedWorkspace] performFileOperation: + NSWorkspaceRecycleOperation source: + [path stringByDeletingLastPathComponent] + destination: @"" + files: [NSArray arrayWithObject: [path lastPathComponent]] + tag: nil] ) { - printf( "trashPath failed\n" ); + /* We can't move it to the trash, let's try just to delete it + (will work if it is on a remote volume) */ + if( ![[NSFileManager defaultManager] + removeFileAtPath: path handler: nil] ) + { + printf( "Could not trash `%s'\n", [path UTF8String] ); + } } - [appleScript release]; } @end