1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 09:13:06 +00:00

#4924 Use recycleURLs:completionHandler: to trash files

This commit is contained in:
Mitchell Livingston 2012-05-29 01:53:36 +00:00
parent c1f2085715
commit 5c1feaf937
4 changed files with 15 additions and 17 deletions

View file

@ -45,7 +45,8 @@
Controller * fController;
Torrent * fTorrent;
NSString * fDestination, * fTorrentFile;
NSURL * fTorrentFile;
NSString * fDestination;
BOOL fLockDestination;
BOOL fDeleteTorrentInitial, fDeleteEnableInitial;

View file

@ -65,7 +65,7 @@
fController = controller;
fTorrentFile = [[torrentFile stringByExpandingTildeInPath] retain];
fTorrentFile = [[NSURL alloc] initFileURLWithPath: [torrentFile stringByExpandingTildeInPath]];
fDeleteTorrentInitial = deleteTorrent;
fDeleteEnableInitial = canToggleDelete;

View file

@ -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;

View file

@ -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