diff --git a/macosx/AddWindowController.h b/macosx/AddWindowController.h index 6e7e7fc50..e7ad1c6f4 100644 --- a/macosx/AddWindowController.h +++ b/macosx/AddWindowController.h @@ -45,7 +45,8 @@ Controller * fController; Torrent * fTorrent; - NSString * fDestination, * fTorrentFile; + NSURL * fTorrentFile; + NSString * fDestination; BOOL fLockDestination; BOOL fDeleteTorrentInitial, fDeleteEnableInitial; diff --git a/macosx/AddWindowController.m b/macosx/AddWindowController.m index 4f11dd1bb..e8672a779 100644 --- a/macosx/AddWindowController.m +++ b/macosx/AddWindowController.m @@ -65,7 +65,7 @@ fController = controller; - fTorrentFile = [[torrentFile stringByExpandingTildeInPath] retain]; + fTorrentFile = [[NSURL alloc] initFileURLWithPath: [torrentFile stringByExpandingTildeInPath]]; fDeleteTorrentInitial = deleteTorrent; fDeleteEnableInitial = canToggleDelete; diff --git a/macosx/Torrent.h b/macosx/Torrent.h index 93567b6d4..183be5a76 100644 --- a/macosx/Torrent.h +++ b/macosx/Torrent.h @@ -119,7 +119,7 @@ - (tr_priority_t) priority; - (void) setPriority: (tr_priority_t) priority; -+ (void) trashFile: (NSString *) path; ++ (void) trashFile: (NSURL *) fileURL; - (void) moveTorrentDataFileTo: (NSString *) folder; - (void) copyTorrentFileTo: (NSString *) path; diff --git a/macosx/Torrent.m b/macosx/Torrent.m index 6132557d3..64ea545a5 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -94,8 +94,12 @@ int trashDataFile(const char * filename) { @autoreleasepool { + NSLog(@"%s", filename); if (filename != NULL) - [Torrent trashFile: [NSString stringWithUTF8String: filename]]; + { + [Torrent trashFile: [NSURL fileURLWithPath: [NSString stringWithUTF8String: filename]]]; + NSLog(@"%@\n%@", [NSString stringWithUTF8String: filename], [NSURL fileURLWithPath: [NSString stringWithUTF8String: filename]]); + } } return 0; } @@ -114,7 +118,7 @@ int trashDataFile(const char * filename) if (self) { if (torrentDelete && ![[self torrentLocation] isEqualToString: path]) - [Torrent trashFile: path]; + [Torrent trashFile: [NSURL fileURLWithPath: path]]; } return self; } @@ -492,19 +496,12 @@ int trashDataFile(const char * filename) return tr_torrentSetPriority(fHandle, priority); } -#warning when 10.6-only use recycleURLs:completionHandler: -+ (void) trashFile: (NSString *) path ++ (void) trashFile: (NSURL *) fileURL { - //attempt to move to trash - if (![[NSWorkspace sharedWorkspace] performFileOperation: NSWorkspaceRecycleOperation - source: [path stringByDeletingLastPathComponent] destination: @"" - files: [NSArray arrayWithObject: [path lastPathComponent]] tag: nil]) - { - //if cannot trash, just delete it (will work if it's on a remote volume) - NSError * error; - if (![[NSFileManager defaultManager] removeItemAtPath: path error: &error]) - NSLog(@"Could not trash %@: %@", path, [error localizedDescription]); - } + [[NSWorkspace sharedWorkspace] recycleURLs: [NSArray arrayWithObject: fileURL] completionHandler: ^(NSDictionary * newURLs, NSError * error) { + if (error) + NSLog(@"Could not trash %@: %@", [fileURL path], [error localizedDescription]); + }]; } - (void) moveTorrentDataFileTo: (NSString *) folder