Changeset 9342


Ignore:
Timestamp:
Oct 21, 2009, 1:01:14 PM (13 years ago)
Author:
livings124
Message:

use libtransmission for moving, incomplete directory, and directory controlling in general (still rough around the edges)

Location:
trunk/macosx
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/AddWindowController.m

    r9288 r9342  
    255255        fDestination = [destination retain];
    256256       
    257         [fTorrent changeDownloadFolder: fDestination];
     257        [fTorrent changeDownloadFolderBeforeUsing: fDestination];
    258258    }
    259259   
  • trunk/macosx/Controller.m

    r9328 r9342  
    264264       
    265265        tr_benc settings;
    266         tr_bencInitDict(&settings, 34);
     266        tr_bencInitDict(&settings, 36);
    267267        const char * configDir = tr_getDefaultConfigDir("Transmission");
    268268        tr_sessionGetDefaultSettings(configDir, &settings);
     
    291291        tr_bencDictAddStr(&settings, TR_PREFS_KEY_DOWNLOAD_DIR, [[[fDefaults stringForKey: @"DownloadFolder"]
    292292                                                                    stringByExpandingTildeInPath] UTF8String]);
     293        tr_bencDictAddStr(&settings, TR_PREFS_KEY_INCOMPLETE_DIR, [[[fDefaults stringForKey: @"IncompleteDownloadFolder"]
     294                                                                    stringByExpandingTildeInPath] UTF8String]);
     295        tr_bencDictAddBool(&settings, TR_PREFS_KEY_INCOMPLETE_DIR_ENABLED, [fDefaults boolForKey: @"UseIncompleteDownloadFolder"]);
    293296       
    294297        tr_bencDictAddInt(&settings, TR_PREFS_KEY_MSGLEVEL, [fDefaults integerForKey: @"MessageLevel"]);
     
    941944            continue;
    942945       
    943         //change the location if the group calls for it (this has to wait until after the torrent is create)
     946        //change the location if the group calls for it (this has to wait until after the torrent is created)
    944947        if (!lockDestination && [[GroupsController groups] usesCustomDownloadLocationForIndex: [torrent groupValue]])
    945948        {
    946949            location = [[GroupsController groups] customDownloadLocationForIndex: [torrent groupValue]];
    947             [torrent changeDownloadFolder: location];
     950            [torrent changeDownloadFolderBeforeUsing: location];
    948951        }
    949952       
     
    14651468        NSMutableArray * paths = [NSMutableArray arrayWithCapacity: [selected count]];
    14661469        for (Torrent * torrent in [fTableView selectedTorrents])
    1467             [paths addObject: [NSURL fileURLWithPath: [torrent dataLocation]]];
     1470        {
     1471            NSString * location = [torrent dataLocation];
     1472            if (location)
     1473                [paths addObject: [NSURL fileURLWithPath: location]];
     1474        }
    14681475       
    14691476        [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs: paths];
     
    14721479    {
    14731480        for (Torrent * torrent in selected)
    1474             [[NSWorkspace sharedWorkspace] selectFile: [torrent dataLocation] inFileViewerRootedAtPath: nil];
     1481        {
     1482            NSString * location = [torrent dataLocation];
     1483            if (location)
     1484                [[NSWorkspace sharedWorkspace] selectFile: location inFileViewerRootedAtPath: nil];
     1485        }
    14751486    }
    14761487}
     
    17701781        }
    17711782       
     1783        #warning dataLocation could return nil
    17721784        NSDictionary * clickContext = [NSDictionary dictionaryWithObjectsAndKeys: GROWL_DOWNLOAD_COMPLETE, @"Type",
    17731785                                        [torrent dataLocation] , @"Location", nil];
     
    17811793        //bounce download stack
    17821794        [[NSDistributedNotificationCenter defaultCenter] postNotificationName: @"com.apple.DownloadFileFinished"
    1783             object: [[torrent downloadFolder] stringByAppendingPathComponent: [torrent name]]];
     1795            object: [torrent dataLocation]];
    17841796       
    17851797        if ([fDefaults boolForKey: @"QueueSeed"] && [self numToStartFromQueue: NO] == 0)
     
    18311843    }
    18321844   
     1845    #warning dataLocation could return nil
    18331846    NSDictionary * clickContext = [NSDictionary dictionaryWithObjectsAndKeys: GROWL_SEEDING_COMPLETE, @"Type",
    18341847                                    [torrent dataLocation], @"Location", nil];
     
    31433156   
    31443157    for (Torrent * torrent in selectedTorrents)
    3145         if (([torrent isFolder] || [torrent isComplete]) && [[NSFileManager defaultManager] fileExistsAtPath: [torrent dataLocation]])
     3158        if (([torrent isFolder] || [torrent isComplete]) && [torrent dataLocation])
    31463159            [qlArray addObject: torrent];
    31473160   
  • trunk/macosx/FileListNode.h

    r7659 r9342  
    4545- (BOOL) isFolder;
    4646- (NSString *) name;
    47 - (NSString *) fullPath;
     47- (NSString *) path;
    4848- (NSIndexSet *) indexes;
    4949
  • trunk/macosx/FileListNode.m

    r9324 r9342  
    9999}
    100100
    101 - (NSString *) fullPath
     101- (NSString *) path
    102102{
    103103    return fPath;
     
    138138        fIsFolder = isFolder;
    139139        fName = [name retain];
    140         fPath = [[path stringByAppendingPathComponent: name] retain];
     140        fPath = [path retain];
    141141       
    142142        fIndexes = [[NSMutableIndexSet alloc] init];
  • trunk/macosx/FileOutlineController.m

    r9300 r9342  
    212212    NSString * ident = [tableColumn identifier];
    213213    if ([ident isEqualToString: @"Name"])
    214         return [[fTorrent downloadFolder] stringByAppendingPathComponent: [(FileListNode *)item fullPath]];
     214        return [fTorrent fileLocation: item];
    215215    else if ([ident isEqualToString: @"Check"])
    216216    {
     
    315315- (void) revealFile: (id) sender
    316316{
    317     NSString * folder = [fTorrent downloadFolder];
    318317    NSIndexSet * indexes = [fOutline selectedRowIndexes];
    319318    if ([NSApp isOnSnowLeopardOrBetter])
     
    321320        NSMutableArray * paths = [NSMutableArray arrayWithCapacity: [indexes count]];
    322321        for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
    323             [paths addObject: [NSURL fileURLWithPath: [folder stringByAppendingPathComponent: [[fOutline itemAtRow: i] fullPath]]]];
     322        {
     323            NSString * path = [fTorrent fileLocation: [fOutline itemAtRow: i]];
     324            if (path)
     325                [paths addObject: [NSURL fileURLWithPath: path]];
     326        }
    324327       
    325328        [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs: paths];
     
    328331    {
    329332        for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
    330             [[NSWorkspace sharedWorkspace] selectFile: [folder stringByAppendingPathComponent: [[fOutline itemAtRow: i] fullPath]]
    331                 inFileViewerRootedAtPath: nil];
     333        {
     334            NSString * path = [fTorrent fileLocation: [fOutline itemAtRow: i]];
     335            if (path)
     336                [[NSWorkspace sharedWorkspace] selectFile: path inFileViewerRootedAtPath: nil];
     337        }
    332338    }
    333339}
     
    343349    if (action == @selector(revealFile:))
    344350    {
    345         NSString * downloadFolder = [fTorrent downloadFolder];
    346351        NSIndexSet * indexSet = [fOutline selectedRowIndexes];
    347352        for (NSInteger i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
    348             if ([[NSFileManager defaultManager] fileExistsAtPath:
    349                     [downloadFolder stringByAppendingPathComponent: [[fFileList objectAtIndex: i] fullPath]]])
     353            if ([fTorrent fileLocation: [fFileList objectAtIndex: i]] != nil)
    350354                return YES;
    351355        return NO;
  • trunk/macosx/InfoWindowController.m

    r9304 r9342  
    11301130    FileOutlineView * fileOutlineView = [fFileController outlineView];
    11311131    Torrent * torrent = [fTorrents objectAtIndex: 0];
    1132     NSString * folder = [torrent downloadFolder];
    11331132    NSIndexSet * indexes = [fileOutlineView selectedRowIndexes];
    11341133    NSMutableArray * urlArray = [NSMutableArray arrayWithCapacity: [indexes count]];
     
    11381137        FileListNode * item = [fileOutlineView itemAtRow: i];
    11391138        if ([self canQuickLookFile: item])
    1140             [urlArray addObject: [NSURL fileURLWithPath: [folder stringByAppendingPathComponent: [item fullPath]]]];
     1139            [urlArray addObject: [torrent fileLocation: item]];
    11411140    }
    11421141   
     
    11681167    FileOutlineView * fileOutlineView = [fFileController outlineView];
    11691168   
    1170     NSString * fullPath = [(NSURL *) item path];
    1171     NSString * folder = [[fTorrents objectAtIndex: 0] downloadFolder];
     1169    NSString * fullPath = [(NSURL *)item path];
     1170    Torrent * torrent = [fTorrents objectAtIndex: 0];
    11721171    NSRange visibleRows = [fileOutlineView rowsInRect: [fileOutlineView bounds]];
    11731172   
     
    11751174    {
    11761175        FileListNode * rowItem = [fileOutlineView itemAtRow: row];
    1177         if ([[folder stringByAppendingPathComponent: [rowItem fullPath]] isEqualToString: fullPath])
     1176        if ([[torrent fileLocation: rowItem] isEqualToString: fullPath])
    11781177        {
    11791178            NSRect frame = [fileOutlineView iconRectForRow: row];
     
    13731372   
    13741373    NSString * location = [torrent dataLocation];
    1375     [fDataLocationField setStringValue: [location stringByAbbreviatingWithTildeInPath]];
    1376     [fDataLocationField setToolTip: location];
     1374    [fDataLocationField setStringValue: location ? [location stringByAbbreviatingWithTildeInPath] : @""];
     1375    [fDataLocationField setToolTip: location ? location : @""];
    13771376}
    13781377
     
    16631662{
    16641663    Torrent * torrent = [fTorrents objectAtIndex: 0];
    1665    
    1666     if (![[NSFileManager defaultManager] fileExistsAtPath: [[torrent downloadFolder] stringByAppendingPathComponent: [item fullPath]]])
    1667         return NO;
    1668    
    1669     return [item isFolder] || [torrent fileProgress: item] >= 1.0;
     1664    return [torrent fileLocation: item] != nil && ([item isFolder] || [torrent fileProgress: item] >= 1.0);
    16701665}
    16711666
  • trunk/macosx/MessageWindowController.m

    r9327 r9342  
    2424
    2525#import "MessageWindowController.h"
     26#import "NSApplicationAdditions.h"
    2627#import "NSStringAdditions.h"
    2728#import <transmission.h>
  • trunk/macosx/PrefsController.h

    r8461 r9342  
    105105- (void) folderSheetShow: (id) sender;
    106106- (void) incompleteFolderSheetShow: (id) sender;
     107- (void) setUseIncompleteFolder: (id) sender;
    107108
    108109- (void) applyRatioSetting: (id) sender;
  • trunk/macosx/PrefsController.m

    r9232 r9342  
    742742}
    743743
     744- (void) setUseIncompleteFolder: (id) sender
     745{
     746    tr_sessionSetIncompleteDirEnabled(fHandle, [fDefaults boolForKey: @"UseIncompleteDownloadFolder"]);
     747}
     748
    744749- (void) setAutoImport: (id) sender
    745750{
     
    10921097    [fDefaults setObject: downloadLocation forKey: @"DownloadFolder"];
    10931098   
     1099    NSString * incompleteLocation = [[NSString stringWithUTF8String: tr_sessionGetIncompleteDir(fHandle)] stringByStandardizingPath];
     1100    [fDefaults setObject: incompleteLocation forKey: @"IncompleteDownloadFolder"];
     1101   
     1102    const BOOL useIncomplete = tr_sessionIsIncompleteDirEnabled(fHandle);
     1103    [fDefaults setBool: useIncomplete forKey: @"UseIncompleteDownloadFolder"];
     1104   
    10941105    //peers
    10951106    const uint16_t peersTotal = tr_sessionGetPeerLimit(fHandle);
     
    13001311{
    13011312    if (code == NSOKButton)
    1302         [fDefaults setObject: [[openPanel filenames] objectAtIndex: 0] forKey: @"IncompleteDownloadFolder"];
     1313    {
     1314        NSString * folder = [[openPanel filenames] objectAtIndex: 0];
     1315        [fDefaults setObject: folder forKey: @"IncompleteDownloadFolder"];
     1316       
     1317        tr_sessionSetIncompleteDir(fHandle, [folder UTF8String]);
     1318    }
    13031319    [fIncompleteFolderPopUp selectItemAtIndex: 0];
    13041320}
  • trunk/macosx/Torrent.h

    r9316 r9342  
    3535    const tr_info * fInfo;
    3636    const tr_stat * fStat;
    37    
    38     BOOL fResumeOnWake;
    39    
    40     BOOL fUseIncompleteFolder;
    41     NSString * fDownloadFolder, * fIncompleteFolder;
    4237       
    4338    NSUserDefaults * fDefaults;
     
    5752    NSInteger fGroupValue;
    5853   
    59     NSDictionary * fQuickPauseDict;
     54    BOOL fResumeOnWake;
     55   
     56    NSString * fTimeMachineExclude;
    6057}
    6158
     
    6966- (void) closeRemoveTorrent;
    7067
    71 - (void) changeIncompleteDownloadFolder: (NSString *) folder;
    72 - (void) changeDownloadFolder: (NSString *) folder;
    73 - (NSString *) downloadFolder;
     68- (void) changeDownloadFolderBeforeUsing: (NSString *) folder;
     69
     70- (NSString *) currentDirectory;
    7471
    7572- (void) getAvailability: (int8_t *) tab size: (NSInteger) size;
     
    120117
    121118- (BOOL) alertForRemainingDiskSpace;
    122 - (BOOL) alertForFolderAvailable;
    123 - (BOOL) alertForMoveFolderAvailable;
    124119
    125120- (NSImage *) icon;
     
    145140
    146141- (NSString *) torrentLocation;
     142#warning needed?
    147143- (NSString *) dataLocation;
     144- (NSString *) fileLocation: (FileListNode *) node;
    148145
    149146- (CGFloat) progress;
  • trunk/macosx/Torrent.m

    r9324 r9342  
    3333
    3434- (id) initWithPath: (NSString *) path hash: (NSString *) hashString torrentStruct: (tr_torrent *) torrentStruct lib: (tr_session *) lib
    35         downloadFolder: (NSString *) downloadFolder
    36         useIncompleteFolder: (NSNumber *) useIncompleteFolder incompleteFolder: (NSString *) incompleteFolder
     35        downloadFolder: (NSString *) downloadFolder incompleteFolder: (NSString *) incompleteFolder
    3736        waitToStart: (NSNumber *) waitToStart
    3837        groupValue: (NSNumber *) groupValue;
    39 
    40 - (BOOL) shouldUseIncompleteFolderForName: (NSString *) name;
    41 - (void) updateDownloadFolder;
    4238
    4339- (void) createFileList;
     
    4945- (void) ratioLimitHit;
    5046
    51 - (void) quickPause;
    52 - (void) endQuickPause;
    53 
    5447- (NSString *) etaString;
    5548
     49- (void) updateTimeMachineExclude;
    5650- (void) setTimeMachineExclude: (BOOL) exclude forPath: (NSString *) path;
    5751
     
    8175{
    8276    self = [self initWithPath: path hash: nil torrentStruct: NULL lib: lib
    83             downloadFolder: location
    84             useIncompleteFolder: nil incompleteFolder: nil
     77            downloadFolder: location incompleteFolder: nil
    8578            waitToStart: nil groupValue: nil];
    8679   
     
    9689{
    9790    self = [self initWithPath: nil hash: nil torrentStruct: torrentStruct lib: lib
    98             downloadFolder: location
    99             useIncompleteFolder: nil incompleteFolder: nil
     91            downloadFolder: location incompleteFolder: nil
    10092            waitToStart: nil groupValue: nil];
    10193   
     
    108100                hash: [history objectForKey: @"TorrentHash"]
    109101                torrentStruct: NULL lib: lib
    110                 downloadFolder: [history objectForKey: @"DownloadFolder"]
    111                 useIncompleteFolder: [history objectForKey: @"UseIncompleteFolder"]
    112                 incompleteFolder: [history objectForKey: @"IncompleteFolder"]
     102                downloadFolder: [history objectForKey: @"DownloadFolder"] //upgrading from versions < 1.80
     103                incompleteFolder: [[history objectForKey: @"UseIncompleteFolder"] boolValue] //upgrading from versions < 1.80
     104                                    ? [history objectForKey: @"IncompleteFolder"] : nil
    113105                waitToStart: [history objectForKey: @"WaitToStart"]
    114106                groupValue: [history objectForKey: @"GroupValue"]];
     
    153145- (NSDictionary *) history
    154146{
    155     NSMutableDictionary * history = [NSMutableDictionary dictionaryWithObjectsAndKeys:
    156                     [self torrentLocation], @"InternalTorrentPath",
    157                     [self hashString], @"TorrentHash",
    158                     fDownloadFolder, @"DownloadFolder",
    159                     [NSNumber numberWithBool: fUseIncompleteFolder], @"UseIncompleteFolder",
    160                     [NSNumber numberWithBool: [self isActive]], @"Active",
    161                     [NSNumber numberWithBool: fWaitToStart], @"WaitToStart",
    162                     [NSNumber numberWithInt: fGroupValue], @"GroupValue", nil];
    163    
    164     if (fIncompleteFolder)
    165         [history setObject: fIncompleteFolder forKey: @"IncompleteFolder"];
    166        
    167     return history;
     147    return [NSDictionary dictionaryWithObjectsAndKeys:
     148                [self torrentLocation], @"InternalTorrentPath",
     149                [self hashString], @"TorrentHash",
     150                [NSNumber numberWithBool: [self isActive]], @"Active",
     151                [NSNumber numberWithBool: fWaitToStart], @"WaitToStart",
     152                [NSNumber numberWithInt: fGroupValue], @"GroupValue", nil];
    168153}
    169154
     
    181166    [fHashString release];
    182167   
    183     [fDownloadFolder release];
    184     [fIncompleteFolder release];
    185    
    186168    [fIcon release];
    187169   
     
    189171    [fFlatFileList release];
    190172   
    191     [fQuickPauseDict release];
     173    [fTimeMachineExclude release];
    192174   
    193175    [super dealloc];
     
    202184{
    203185    //allow the file to be index by Time Machine
    204     [self setTimeMachineExclude: NO forPath: [[self downloadFolder] stringByAppendingPathComponent: [self name]]];
     186    if (fTimeMachineExclude)
     187        [self setTimeMachineExclude: NO forPath: fTimeMachineExclude];
    205188   
    206189    tr_torrentRemove(fHandle);
    207190}
    208191
    209 - (void) changeIncompleteDownloadFolder: (NSString *) folder
    210 {
    211     fUseIncompleteFolder = folder != nil;
    212    
    213     [fIncompleteFolder release];
    214     fIncompleteFolder = fUseIncompleteFolder ? [folder retain] : nil;
    215    
    216     [self updateDownloadFolder];
    217 }
    218 
    219 - (void) changeDownloadFolder: (NSString *) folder
    220 {
    221     if (fDownloadFolder && [folder isEqualToString: fDownloadFolder])
    222         return;
    223    
    224     [fDownloadFolder release];
    225     fDownloadFolder = [folder retain];
    226    
    227     [self updateDownloadFolder];
    228 }
    229 
    230 - (NSString *) downloadFolder
    231 {
    232     return [NSString stringWithUTF8String: tr_torrentGetDownloadDir(fHandle)];
     192- (void) changeDownloadFolderBeforeUsing: (NSString *) folder
     193{
     194     tr_torrentSetDownloadDir(fHandle, [folder UTF8String]);
     195     [self updateTimeMachineExclude];
     196}
     197
     198- (NSString *) currentDirectory
     199{
     200    return [NSString stringWithUTF8String: tr_torrentGetCurrentDir(fHandle)];
    233201}
    234202
     
    281249    if ((wasChecking && ![self isChecking]) || (wasStalled != fStalled) || (!wasError && [self isError] && [self isActive]))
    282250        [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateQueue" object: self];
     251   
     252    //when the data first appears, update time machine exclusion
     253    #warning perhaps always check to get if the file is moved through rpc
     254    if (!fTimeMachineExclude)
     255        [self updateTimeMachineExclude];
    283256}
    284257
     
    288261    fFinishedSeeding = NO;
    289262   
    290     if (![self isActive] && [self alertForFolderAvailable] && [self alertForRemainingDiskSpace])
     263    if (![self isActive] && /*[self alertForFolderAvailable] &&*/ [self alertForRemainingDiskSpace])
    291264    {
    292265        tr_torrentStart(fHandle);
     
    456429- (void) moveTorrentDataFileTo: (NSString *) folder
    457430{
    458     NSString * oldFolder = [self downloadFolder];
    459     if (![oldFolder isEqualToString: folder] || ![fDownloadFolder isEqualToString: folder])
    460     {
    461         //check if moving inside itself
    462         NSArray * oldComponents = [oldFolder pathComponents],
    463                 * newComponents = [folder pathComponents];
    464         NSInteger count;
    465        
    466         if ((count = [oldComponents count]) < [newComponents count]
    467                 && [[newComponents objectAtIndex: count] isEqualToString: [self name]]
    468                 && [oldComponents isEqualToArray:
    469                         [newComponents objectsAtIndexes: [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, count)]]])
    470         {
    471             NSAlert * alert = [[NSAlert alloc] init];
    472             [alert setMessageText: NSLocalizedString(@"A folder cannot be moved to inside itself.",
    473                                                         "Move inside itself alert -> title")];
    474             [alert setInformativeText: [NSString stringWithFormat:
    475                             NSLocalizedString(@"The move operation of \"%@\" cannot be done.",
    476                                                 "Move inside itself alert -> message"), [self name]]];
    477             [alert addButtonWithTitle: NSLocalizedString(@"OK", "Move inside itself alert -> button")];
    478            
    479             [alert runModal];
    480             [alert release];
    481            
    482             return;
    483         }
    484        
    485         [self quickPause];
    486        
    487         //allow if file can be moved or does not exist
    488         if ([[NSFileManager defaultManager] moveItemAtPath: [oldFolder stringByAppendingPathComponent: [self name]]
    489                             toPath: [folder stringByAppendingPathComponent: [self name]] error: NULL]
    490             || ![[NSFileManager defaultManager] fileExistsAtPath: [oldFolder stringByAppendingPathComponent: [self name]]])
    491         {
    492             //get rid of both incomplete folder and old download folder, even if move failed
    493             fUseIncompleteFolder = NO;
    494             if (fIncompleteFolder)
    495             {
    496                 [fIncompleteFolder release];
    497                 fIncompleteFolder = nil;
    498             }
    499             [self changeDownloadFolder: folder];
    500            
    501             [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateStats" object: nil];
    502            
    503             [self endQuickPause];
    504         }
    505         else
    506         {
    507             [self endQuickPause];
    508        
    509             NSAlert * alert = [[NSAlert alloc] init];
    510             [alert setMessageText: NSLocalizedString(@"There was an error moving the data file.", "Move error alert -> title")];
    511             [alert setInformativeText: [NSString stringWithFormat:
    512                             NSLocalizedString(@"The move operation of \"%@\" cannot be done.",
    513                                                 "Move error alert -> message"), [self name]]];
    514             [alert addButtonWithTitle: NSLocalizedString(@"OK", "Move error alert -> button")];
    515            
    516             [alert runModal];
    517             [alert release];
    518         }
     431    #warning fix
     432    /*NSString * oldFolder = [self downloadFolder];
     433    if ([oldFolder isEqualToString: folder])
     434        return;
     435   
     436    //check if moving inside itself
     437    NSArray * oldComponents = [oldFolder pathComponents],
     438            * newComponents = [folder pathComponents];
     439    NSInteger count;
     440   
     441    if ((count = [oldComponents count]) < [newComponents count]
     442            && [[newComponents objectAtIndex: count] isEqualToString: [self name]]
     443            && [oldComponents isEqualToArray:
     444                    [newComponents objectsAtIndexes: [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, count)]]])
     445    {
     446        NSAlert * alert = [[NSAlert alloc] init];
     447        [alert setMessageText: NSLocalizedString(@"A folder cannot be moved to inside itself.",
     448                                                    "Move inside itself alert -> title")];
     449        [alert setInformativeText: [NSString stringWithFormat:
     450                        NSLocalizedString(@"The move operation of \"%@\" cannot be done.",
     451                                            "Move inside itself alert -> message"), [self name]]];
     452        [alert addButtonWithTitle: NSLocalizedString(@"OK", "Move inside itself alert -> button")];
     453       
     454        [alert runModal];
     455        [alert release];
     456       
     457        return;
     458    }*/
     459   
     460    #warning doesn't block?
     461    int status;
     462    tr_torrentSetLocation(fHandle, [folder UTF8String], YES, NULL, &status);
     463   
     464    if (status == TR_LOC_DONE)
     465        [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateStats" object: nil];
     466    else
     467    {
     468        return;
     469        NSAlert * alert = [[NSAlert alloc] init];
     470        [alert setMessageText: NSLocalizedString(@"There was an error moving the data file.", "Move error alert -> title")];
     471        [alert setInformativeText: [NSString stringWithFormat:
     472                        NSLocalizedString(@"The move operation of \"%@\" cannot be done.",
     473                                            "Move error alert -> message"), [self name]]];
     474        [alert addButtonWithTitle: NSLocalizedString(@"OK", "Move error alert -> button")];
     475       
     476        [alert runModal];
     477        [alert release];
    519478    }
    520479}
     
    530489        return YES;
    531490   
     491    #warning fix
     492    return YES;
    532493    NSFileManager * fileManager = [NSFileManager defaultManager];
    533494    NSString * downloadFolder = [self downloadFolder];
     
    567528}
    568529
    569 - (BOOL) alertForFolderAvailable
     530#warning is this needed?
     531/*- (BOOL) alertForFolderAvailable
    570532{
    571533    #warning check for change from incomplete to download folder first
     
    619581   
    620582    [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateStats" object: nil];
    621 }
    622 
    623 - (BOOL) alertForMoveFolderAvailable
    624 {
    625     if (access([fDownloadFolder UTF8String], 0))
    626     {
    627         NSAlert * alert = [[NSAlert alloc] init];
    628         [alert setMessageText: [NSString stringWithFormat:
    629                                 NSLocalizedString(@"The folder for moving the completed \"%@\" cannot be used.",
    630                                     "Move folder cannot be used alert -> title"), [self name]]];
    631         [alert setInformativeText: [NSString stringWithFormat:
    632                                 NSLocalizedString(@"\"%@\" cannot be used. The file will remain in its current location.",
    633                                     "Move folder cannot be used alert -> message"), fDownloadFolder]];
    634         [alert addButtonWithTitle: NSLocalizedString(@"OK", "Move folder cannot be used alert -> button")];
    635        
    636         [alert runModal];
    637         [alert release];
    638        
    639         return NO;
    640     }
    641    
    642     return YES;
    643 }
     583}*/
    644584
    645585- (NSImage *) icon
     
    647587    if (!fIcon)
    648588        fIcon = [[[NSWorkspace sharedWorkspace] iconForFileType: [self isFolder] ? NSFileTypeForHFSTypeCode('fldr')
    649                                                 : [[self name] pathExtension]] retain];
     589                                                                                : [[self name] pathExtension]] retain];
    650590    return fIcon;
    651591}
     
    790730}
    791731
     732#warning returning nil causes the info field to not change - check all uses of data location
    792733- (NSString *) dataLocation
    793734{
    794     return [[self downloadFolder] stringByAppendingPathComponent: [self name]];
     735    if ([self isFolder])
     736    {
     737        NSString * dataLocation = [[self currentDirectory] stringByAppendingPathComponent: [self name]];
     738       
     739        if (![[NSFileManager defaultManager] fileExistsAtPath: dataLocation])
     740            return nil;
     741       
     742        return dataLocation;
     743    }
     744    else
     745    {
     746        char * location = tr_torrentFindFile(fHandle, 0);
     747        if (location == NULL)
     748            return nil;
     749       
     750        NSString * dataLocation = [NSString stringWithUTF8String: location];
     751        free(location);
     752       
     753        return dataLocation;
     754    }
     755}
     756
     757- (NSString *) fileLocation: (FileListNode *) node
     758{
     759    if ([node isFolder])
     760    {
     761        NSString * basePath = [[node path] stringByAppendingPathComponent: [node name]];
     762        NSString * dataLocation = [[self currentDirectory] stringByAppendingPathComponent: basePath];
     763       
     764        if (![[NSFileManager defaultManager] fileExistsAtPath: dataLocation])
     765            return nil;
     766       
     767        return dataLocation;
     768    }
     769    else
     770    {
     771        char * location = tr_torrentFindFile(fHandle, [[node indexes] firstIndex]);
     772        if (location == NULL)
     773            return nil;
     774       
     775        NSString * dataLocation = [NSString stringWithUTF8String: location];
     776        free(location);
     777       
     778        return dataLocation;
     779    }
    795780}
    796781
     
    15091494- (NSURL *) previewItemURL
    15101495{
    1511     return [NSURL fileURLWithPath: [self dataLocation]];
     1496    NSString * location = [self dataLocation];
     1497    return location ? [NSURL fileURLWithPath: location] : nil;
    15121498}
    15131499
     
    15171503
    15181504- (id) initWithPath: (NSString *) path hash: (NSString *) hashString torrentStruct: (tr_torrent *) torrentStruct lib: (tr_session *) lib
    1519         downloadFolder: (NSString *) downloadFolder
    1520         useIncompleteFolder: (NSNumber *) useIncompleteFolder incompleteFolder: (NSString *) incompleteFolder
     1505        downloadFolder: (NSString *) downloadFolder incompleteFolder: (NSString *) incompleteFolder
    15211506        waitToStart: (NSNumber *) waitToStart
    15221507        groupValue: (NSNumber *) groupValue
     
    15271512    fDefaults = [NSUserDefaults standardUserDefaults];
    15281513   
    1529     fDownloadFolder = downloadFolder ? downloadFolder : [fDefaults stringForKey: @"DownloadFolder"];
    1530     fDownloadFolder = [[fDownloadFolder stringByExpandingTildeInPath] retain];
    1531    
    1532     fUseIncompleteFolder = useIncompleteFolder ? [useIncompleteFolder boolValue]
    1533                                 : [fDefaults boolForKey: @"UseIncompleteDownloadFolder"];
    1534     if (fUseIncompleteFolder)
    1535     {
    1536         fIncompleteFolder = incompleteFolder ? incompleteFolder : [fDefaults stringForKey: @"IncompleteDownloadFolder"];
    1537         fIncompleteFolder = [[fIncompleteFolder stringByExpandingTildeInPath] retain];
    1538     }
    1539    
    15401514    if (torrentStruct)
    15411515    {
    15421516        fHandle = torrentStruct;
    15431517        fInfo = tr_torrentInfo(fHandle);
    1544        
    1545         NSString * currentDownloadFolder = [self shouldUseIncompleteFolderForName: [NSString stringWithUTF8String: fInfo->name]]
    1546                                                 ? fIncompleteFolder : fDownloadFolder;
    1547         tr_torrentSetDownloadDir(fHandle, [currentDownloadFolder UTF8String]);
    15481518    }
    15491519    else
     
    15691539            if (result == TR_PARSE_OK)
    15701540            {
    1571                 NSString * currentDownloadFolder = [self shouldUseIncompleteFolderForName: [NSString stringWithUTF8String: info.name]]
    1572                                                     ? fIncompleteFolder : fDownloadFolder;
    1573                 tr_ctorSetDownloadDir(ctor, TR_FORCE, [currentDownloadFolder UTF8String]);
     1541                if (downloadFolder)
     1542                    tr_ctorSetDownloadDir(ctor, TR_FORCE, [downloadFolder UTF8String]);
     1543                if (incompleteFolder)
     1544                    tr_ctorSetIncompleteDir(ctor, [incompleteFolder UTF8String]);
    15741545               
    15751546                fHandle = tr_torrentNew(ctor, NULL);
     
    16081579        name: @"GroupValueRemoved" object: nil];
    16091580   
     1581    fTimeMachineExclude = nil;
    16101582    [self update];
    1611    
    1612     //mark incomplete files to be ignored by Time Machine
    1613     [self setTimeMachineExclude: ![self allDownloaded] forPath: [[self downloadFolder] stringByAppendingPathComponent: [self name]]];
    16141583   
    16151584    return self;
     
    16941663    if (!node)
    16951664    {
     1665        NSString * path = [[parent path] stringByAppendingPathComponent: [parent name]];
    16961666        if (isFolder)
    1697             node = [[FileListNode alloc] initWithFolderName: name path: [parent fullPath]];
     1667            node = [[FileListNode alloc] initWithFolderName: name path: path];
    16981668        else
    16991669        {
    1700             node = [[FileListNode alloc] initWithFileName: name path: [parent fullPath] size: size index: index];
     1670            node = [[FileListNode alloc] initWithFileName: name path: path size: size index: index];
    17011671            [flatFileList addObject: node];
    17021672        }
     
    17151685}
    17161686
    1717 - (BOOL) shouldUseIncompleteFolderForName: (NSString *) name
    1718 {
    1719     return fUseIncompleteFolder &&
    1720         ![[NSFileManager defaultManager] fileExistsAtPath: [fDownloadFolder stringByAppendingPathComponent: name]];
    1721 }
    1722 
    1723 - (void) updateDownloadFolder
    1724 {
    1725     //remove old Time Machine location
    1726     [self setTimeMachineExclude: NO forPath: [[self downloadFolder] stringByAppendingPathComponent: [self name]]];
    1727    
    1728     NSString * folder = [self shouldUseIncompleteFolderForName: [self name]] ? fIncompleteFolder : fDownloadFolder;
    1729     tr_torrentSetDownloadDir(fHandle, [folder UTF8String]);
    1730    
    1731     [self setTimeMachineExclude: ![self allDownloaded] forPath: [folder stringByAppendingPathComponent: [self name]]];
    1732 }
    1733 
    17341687//status has been retained
    17351688- (void) completenessChange: (NSNumber *) status
     
    17421695        case TR_SEED:
    17431696        case TR_PARTIAL_SEED:
    1744             canMove = YES;
    1745            
    1746             //move file from incomplete folder to download folder
    1747             if (fUseIncompleteFolder && ![[self downloadFolder] isEqualToString: fDownloadFolder]
    1748                 && (canMove = [self alertForMoveFolderAvailable]))
    1749             {
    1750                 [self quickPause];
    1751                
    1752                 if ([[NSFileManager defaultManager] moveItemAtPath: [[self downloadFolder] stringByAppendingPathComponent: [self name]]
    1753                                         toPath: [fDownloadFolder stringByAppendingPathComponent: [self name]] error: NULL])
    1754                     [self updateDownloadFolder];
    1755                 else
    1756                     canMove = NO;
    1757                
    1758                 [self endQuickPause];
    1759             }
    1760            
    1761             if (!canMove)
    1762             {
    1763                 fUseIncompleteFolder = NO;
    1764                
    1765                 [fDownloadFolder release];
    1766                 fDownloadFolder = fIncompleteFolder;
    1767                 fIncompleteFolder = nil;
    1768             }
    1769            
    1770             //allow to be backed up by Time Machine
    1771             [self setTimeMachineExclude: NO forPath: [[self downloadFolder] stringByAppendingPathComponent: [self name]]];
    1772            
    17731697            [[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentFinishedDownloading" object: self];
    17741698            break;
    17751699       
    17761700        case TR_LEECH:
    1777             //do not allow to be backed up by Time Machine
    1778             [self setTimeMachineExclude: YES forPath: [[self downloadFolder] stringByAppendingPathComponent: [self name]]];
    1779            
    17801701            [[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentRestartedDownloading" object: self];
    17811702            break;
     
    17841705   
    17851706    [self update];
     1707    [self updateTimeMachineExclude];
    17861708}
    17871709
     
    17931715   
    17941716    fFinishedSeeding = YES;
    1795 }
    1796 
    1797 - (void) quickPause
    1798 {
    1799     if (fQuickPauseDict)
    1800         return;
    1801 
    1802     fQuickPauseDict = [[NSDictionary alloc] initWithObjectsAndKeys:
    1803                     [NSNumber numberWithInt: [self usesSpeedLimit: YES]], @"UploadUsesSpeedLimit",
    1804                     [NSNumber numberWithInt: [self speedLimit: YES]], @"UploadSpeedLimit",
    1805                     [NSNumber numberWithInt: [self usesSpeedLimit: NO]], @"DownloadUsesSpeedLimit",
    1806                     [NSNumber numberWithInt: [self speedLimit: NO]], @"DownloadSpeedLimit", nil];
    1807    
    1808     [self setUseSpeedLimit: YES upload: YES];
    1809     [self setSpeedLimit: 0 upload: YES];
    1810     [self setUseSpeedLimit: YES upload: NO];
    1811     [self setSpeedLimit: 0 upload: NO];
    1812 }
    1813 
    1814 - (void) endQuickPause
    1815 {
    1816     if (!fQuickPauseDict)
    1817         return;
    1818    
    1819     [self setUseSpeedLimit: [[fQuickPauseDict objectForKey: @"UploadUsesSpeedLimit"] intValue] upload: YES];
    1820     [self setSpeedLimit: [[fQuickPauseDict objectForKey: @"UploadSpeedLimit"] intValue] upload: YES];
    1821     [self setUseSpeedLimit: [[fQuickPauseDict objectForKey: @"DownloadUsesSpeedLimit"] intValue] upload: NO];
    1822     [self setSpeedLimit: [[fQuickPauseDict objectForKey: @"DownloadSpeedLimit"] intValue] upload: NO];
    1823    
    1824     [fQuickPauseDict release];
    1825     fQuickPauseDict = nil;
    18261717}
    18271718
     
    18401731}
    18411732
     1733- (void) updateTimeMachineExclude
     1734{
     1735    NSString * newLocation = [self dataLocation];
     1736   
     1737    if (fTimeMachineExclude && newLocation && [fTimeMachineExclude isEqualToString: newLocation] && ![self allDownloaded])
     1738        return;
     1739   
     1740    if (fTimeMachineExclude)
     1741    {
     1742        [self setTimeMachineExclude: NO forPath: fTimeMachineExclude];
     1743        fTimeMachineExclude = nil;
     1744    }
     1745   
     1746    if (newLocation && ![self allDownloaded])
     1747    {
     1748        [self setTimeMachineExclude: YES forPath: newLocation];
     1749        fTimeMachineExclude = [newLocation retain];
     1750    }
     1751}
     1752
    18421753- (void) setTimeMachineExclude: (BOOL) exclude forPath: (NSString *) path
    18431754{
  • trunk/macosx/TorrentCell.m

    r9321 r9342  
    299299        if ([NSApp isOnSnowLeopardOrBetter])
    300300        {
    301             NSURL * file = [NSURL fileURLWithPath: [[self representedObject] dataLocation]];
    302             [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs: [NSArray arrayWithObject: file]];
     301            NSString * location = [[self representedObject] dataLocation];
     302            if (location)
     303            {
     304                NSURL * file = [NSURL fileURLWithPath: location];
     305                [[NSWorkspace sharedWorkspace] activateFileViewerSelectingURLs: [NSArray arrayWithObject: file]];
     306            }
    303307        }
    304308        else
    305             [[NSWorkspace sharedWorkspace] selectFile: [[self representedObject] dataLocation] inFileViewerRootedAtPath: nil];
     309        {
     310            NSString * location = [[self representedObject] dataLocation];
     311            if (location)
     312                [[NSWorkspace sharedWorkspace] selectFile: location inFileViewerRootedAtPath: nil];
     313        }
    306314    }
    307315    else;
  • trunk/macosx/en.lproj/PrefsWindow.xib

    r9150 r9342  
    44                <int key="IBDocument.SystemTarget">1050</int>
    55                <string key="IBDocument.SystemVersion">10B504</string>
    6                 <string key="IBDocument.InterfaceBuilderVersion">732</string>
     6                <string key="IBDocument.InterfaceBuilderVersion">740</string>
    77                <string key="IBDocument.AppKitVersion">1038.2</string>
    88                <string key="IBDocument.HIToolboxVersion">437.00</string>
    99                <object class="NSMutableDictionary" key="IBDocument.PluginVersions">
    1010                        <string key="NS.key.0">com.apple.InterfaceBuilder.CocoaPlugin</string>
    11                         <string key="NS.object.0">732</string>
     11                        <string key="NS.object.0">740</string>
    1212                </object>
    1313                <object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
    1414                        <bool key="EncodedWithXMLCoder">YES</bool>
     15                        <integer value="255"/>
     16                        <integer value="1361"/>
     17                        <integer value="1760"/>
     18                        <integer value="28"/>
    1519                        <integer value="153"/>
    16                         <integer value="1760"/>
    17                         <integer value="1361"/>
    1820                </object>
    1921                <object class="NSArray" key="IBDocument.PluginDependencies">
     
    6163                        </object>
    6264                        <object class="NSCustomView" id="249126185">
    63                                 <nil key="NSNextResponder"/>
     65                                <reference key="NSNextResponder"/>
    6466                                <int key="NSvFlags">256</int>
    6567                                <object class="NSMutableArray" key="NSSubviews">
     
    393395                                </object>
    394396                                <string key="NSFrameSize">{542, 291}</string>
     397                                <reference key="NSSuperview"/>
    395398                                <string key="NSClassName">NSView</string>
    396399                                <string key="NSExtension">NSResponder</string>
    397400                        </object>
    398401                        <object class="NSCustomView" id="314557528">
    399                                 <nil key="NSNextResponder"/>
     402                                <reference key="NSNextResponder"/>
    400403                                <int key="NSvFlags">256</int>
    401404                                <object class="NSMutableArray" key="NSSubviews">
     
    15431546                                </object>
    15441547                                <string key="NSFrameSize">{542, 288}</string>
     1548                                <reference key="NSSuperview"/>
    15451549                                <string key="NSClassName">NSView</string>
    15461550                                <string key="NSExtension">NSResponder</string>
     
    77817785                                        </object>
    77827786                                        <int key="connectionID">1928</int>
     7787                                </object>
     7788                                <object class="IBConnectionRecord">
     7789                                        <object class="IBActionConnection" key="connection">
     7790                                                <string key="label">setUseIncompleteFolder:</string>
     7791                                                <reference key="source" ref="511492310"/>
     7792                                                <reference key="destination" ref="615763784"/>
     7793                                        </object>
     7794                                        <int key="connectionID">1929</int>
    77837795                                </object>
    77847796                        </object>
     
    1161211624                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
    1161311625                                        <real value="1"/>
    11614                                         <string>{{189, 274}, {542, 288}}</string>
     11626                                        <string>{{333, 406}, {542, 288}}</string>
    1161511627                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
    1161611628                                        <real value="1"/>
     
    1173011742                        </object>
    1173111743                        <nil key="sourceID"/>
    11732                         <int key="maxID">1928</int>
     11744                        <int key="maxID">1929</int>
    1173311745                </object>
    1173411746                <object class="IBClassDescriber" key="IBDocument.Classes">
     
    1192911941                                                        <string>setStalled:</string>
    1193011942                                                        <string>setStalledMinutes:</string>
     11943                                                        <string>setUseIncompleteFolder:</string>
    1193111944                                                        <string>updateBlocklist:</string>
    1193211945                                                </object>
     
    1198611999                                                        <string>id</string>
    1198712000                                                        <string>id</string>
     12001                                                        <string>id</string>
    1198812002                                                </object>
    1198912003                                        </object>
Note: See TracChangeset for help on using the changeset viewer.