Changeset 1092 for trunk/macosx


Ignore:
Timestamp:
Nov 16, 2006, 7:32:01 PM (15 years ago)
Author:
livings124
Message:

attempt to determine if volume is available....i need feedback on this one

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Torrent.h

    r1084 r1092  
    9696- (void)    trashTorrent;
    9797
    98 - (BOOL) remainingDiskSpaceForTorrent;
     98- (BOOL) alertForRemainingDiskSpace;
     99- (BOOL) alertForDriveAvailable;
    99100
    100101- (NSImage *)   icon;
  • trunk/macosx/Torrent.m

    r1091 r1092  
    211211    {
    212212        //move file from incomplete folder to download folder
     213        #warning check if volume exists
    213214        if (fUseIncompleteFolder && ![[self downloadFolder] isEqualToString: fDownloadFolder])
    214215        {
     
    413414    fFinishedSeeding = NO;
    414415   
    415     if (![self isActive] && [self remainingDiskSpaceForTorrent])
     416    if (![self isActive] && [self alertForDriveAvailable] && [self alertForRemainingDiskSpace])
    416417        tr_torrentStart(fHandle);
    417418}
     
    514515}
    515516
    516 - (BOOL) remainingDiskSpaceForTorrent
     517- (BOOL) alertForRemainingDiskSpace
    517518{
    518519    if ([self progress] >= 1.0)
    519520        return YES;
    520521   
    521     NSString * location = [self dataLocation],
    522                 * volume = [[[NSFileManager defaultManager] componentsToDisplayForPath: location] objectAtIndex: 0];
    523     NSDictionary * fsAttributes = [[NSFileManager defaultManager] fileSystemAttributesAtPath: location];
     522    NSString * volumeName = [[[NSFileManager defaultManager] componentsToDisplayForPath: [self downloadFolder]]
     523                                                                                                objectAtIndex: 0];
     524    NSDictionary * fsAttributes = [[NSFileManager defaultManager] fileSystemAttributesAtPath: [self dataLocation]];
    524525    uint64_t remainingSpace = [[fsAttributes objectForKey: NSFileSystemFreeSize] unsignedLongLongValue],
    525526            torrentRemaining = [self size] - (uint64_t)[self downloadedValid];
    526527   
    527     /*NSLog(@"Volume: %@", volume);
     528    /*NSLog(@"Volume: %@", volumeName);
    528529    NSLog(@"Remaining disk space: %qu (%@)", remainingSpace, [NSString stringForFileSize: remainingSpace]);
    529530    NSLog(@"Torrent remaining size: %qu (%@)", torrentRemaining, [NSString stringForFileSize: torrentRemaining]);*/
    530531   
    531     if (volume && remainingSpace <= torrentRemaining)
     532    if (volumeName && remainingSpace <= torrentRemaining)
    532533    {
    533534        NSAlert * alert = [[NSAlert alloc] init];
     
    536537                                    "Torrent file disk space alert -> title"), [self name]]];
    537538        [alert setInformativeText: [NSString stringWithFormat:
    538                         NSLocalizedString(@"The transfer will be paused. Clear up space on %@ to continue.",
    539                                             "Torrent file disk space alert -> message"), volume]];
     539                        NSLocalizedString(@"The transfer will be paused. Clear up space on \"%@\" to continue.",
     540                                            "Torrent file disk space alert -> message"), volumeName]];
    540541        [alert addButtonWithTitle: NSLocalizedString(@"OK", "Torrent file disk space alert -> button")];
    541542        [alert addButtonWithTitle: NSLocalizedString(@"Download Anyway", "Torrent file disk space alert -> button")];
     
    549550            return YES;
    550551    }
     552    return YES;
     553}
     554
     555- (BOOL) alertForDriveAvailable
     556{
     557    NSArray * pathComponents = [[self downloadFolder] pathComponents];
     558    if ([pathComponents count] < 3)
     559        return YES;
     560   
     561    NSString * volume = [[[pathComponents objectAtIndex: 0] stringByAppendingPathComponent:
     562                    [pathComponents objectAtIndex: 1]] stringByAppendingPathComponent: [pathComponents objectAtIndex: 2]];
     563    NSString * volumeName = [pathComponents objectAtIndex: 2];
     564   
     565    /*NSLog(@"%@", [self downloadFolder]);
     566    NSLog(@"Volume: %@", volume);*/
     567   
     568    if (![[NSFileManager defaultManager] fileExistsAtPath: volume])
     569    {
     570        NSAlert * alert = [[NSAlert alloc] init];
     571        [alert setMessageText: [NSString stringWithFormat:
     572                                NSLocalizedString(@"The volume for downloading \"%@\" cannot be found.",
     573                                    "Volume cannot be found alert -> title"), [self name]]];
     574        [alert setInformativeText: [NSString stringWithFormat:
     575                        NSLocalizedString(@"The transfer will be paused. Mount the volume \"%@\" to continue.",
     576                                            "Volume cannot be found alert -> message"), volumeName]];
     577        [alert addButtonWithTitle: NSLocalizedString(@"OK", "Volume cannot be found alert -> button")];
     578        #warning should choose new directory
     579        [alert addButtonWithTitle: NSLocalizedString(@"Download Anyway", "Volume cannot be found alert -> button")];
     580       
     581        if ([alert runModal] == NSAlertFirstButtonReturn)
     582        {
     583            [[NSNotificationCenter defaultCenter] postNotificationName: @"StoppedDownloading" object: self];
     584            return NO;
     585        }
     586        else
     587            return YES;
     588    }
     589   
    551590    return YES;
    552591}
Note: See TracChangeset for help on using the changeset viewer.