Changeset 13327


Ignore:
Timestamp:
May 29, 2012, 1:53:36 AM (9 years ago)
Author:
livings124
Message:

#4924 Use recycleURLs:completionHandler: to trash files

Location:
trunk/macosx
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/AddWindowController.h

    r13324 r13327  
    4646   
    4747    Torrent * fTorrent;
    48     NSString * fDestination, * fTorrentFile;
     48    NSURL * fTorrentFile;
     49    NSString * fDestination;
    4950    BOOL fLockDestination;
    5051   
  • trunk/macosx/AddWindowController.m

    r13324 r13327  
    6666        fController = controller;
    6767       
    68         fTorrentFile = [[torrentFile stringByExpandingTildeInPath] retain];
     68        fTorrentFile = [[NSURL alloc] initFileURLWithPath: [torrentFile stringByExpandingTildeInPath]];
    6969       
    7070        fDeleteTorrentInitial = deleteTorrent;
  • trunk/macosx/Torrent.h

    r13162 r13327  
    120120- (void) setPriority: (tr_priority_t) priority;
    121121
    122 + (void) trashFile: (NSString *) path;
     122+ (void) trashFile: (NSURL *) fileURL;
    123123- (void) moveTorrentDataFileTo: (NSString *) folder;
    124124- (void) copyTorrentFileTo: (NSString *) path;
  • trunk/macosx/Torrent.m

    r13251 r13327  
    9595    @autoreleasepool
    9696    {
     97        NSLog(@"%s", filename);
    9798        if (filename != NULL)
    98             [Torrent trashFile: [NSString stringWithUTF8String: filename]];
     99        {
     100            [Torrent trashFile: [NSURL fileURLWithPath: [NSString stringWithUTF8String: filename]]];
     101            NSLog(@"%@\n%@", [NSString stringWithUTF8String: filename], [NSURL fileURLWithPath: [NSString stringWithUTF8String: filename]]);
     102        }
    99103    }
    100104    return 0;
     
    115119    {
    116120        if (torrentDelete && ![[self torrentLocation] isEqualToString: path])
    117             [Torrent trashFile: path];
     121            [Torrent trashFile: [NSURL fileURLWithPath: path]];
    118122    }
    119123    return self;
     
    493497}
    494498
    495 #warning when 10.6-only use recycleURLs:completionHandler:
    496 + (void) trashFile: (NSString *) path
    497 {
    498     //attempt to move to trash
    499     if (![[NSWorkspace sharedWorkspace] performFileOperation: NSWorkspaceRecycleOperation
    500         source: [path stringByDeletingLastPathComponent] destination: @""
    501         files: [NSArray arrayWithObject: [path lastPathComponent]] tag: nil])
    502     {
    503         //if cannot trash, just delete it (will work if it's on a remote volume)
    504         NSError * error;
    505         if (![[NSFileManager defaultManager] removeItemAtPath: path error: &error])
    506             NSLog(@"Could not trash %@: %@", path, [error localizedDescription]);
    507     }
     499+ (void) trashFile: (NSURL *) fileURL
     500{
     501    [[NSWorkspace sharedWorkspace] recycleURLs: [NSArray arrayWithObject: fileURL] completionHandler: ^(NSDictionary * newURLs, NSError * error) {
     502        if (error)
     503            NSLog(@"Could not trash %@: %@", [fileURL path], [error localizedDescription]);
     504    }];
    508505}
    509506
Note: See TracChangeset for help on using the changeset viewer.