Changeset 940


Ignore:
Timestamp:
Sep 28, 2006, 12:32:26 AM (15 years ago)
Author:
livings124
Message:

First attempts at warning about not enough disk space (and stopping the offending torrents). Right now this occurs when the torrent is started.

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Torrent.h

    r855 r940  
    8787- (void)    trashTorrent;
    8888
     89- (BOOL) remainingDiskSpaceForTorrent;
     90
    8991- (NSImage *)   icon;
    9092- (NSImage *)   iconFlipped;
  • trunk/macosx/Torrent.m

    r933 r940  
    318318- (void) startTransfer
    319319{
    320     if (![self isActive])
    321     {
     320    fWaitToStart = NO;
     321    fFinishedSeeding = NO;
     322   
     323    if (![self isActive] && [self remainingDiskSpaceForTorrent])
    322324        tr_torrentStart(fHandle);
    323 
    324         fFinishedSeeding = NO;
    325         fWaitToStart = NO;
    326     }
    327325}
    328326
     
    415413    if (fPublicTorrent)
    416414        [self trashFile: [self publicTorrentLocation]];
     415}
     416
     417- (BOOL) remainingDiskSpaceForTorrent
     418{
     419    if ([self progress] >= 1.0)
     420        return YES;
     421   
     422    NSDictionary * fsAttributes = [[NSFileManager defaultManager] fileSystemAttributesAtPath: [self dataLocation]];
     423    float remainingSpace = [[fsAttributes objectForKey: NSFileSystemFreeSize] floatValue],
     424            torrentRemaining = (float)[self size] * (1.0 - [self progress]);
     425   
     426    NSLog(@"Remaining disk space: %f", remainingSpace);
     427    NSLog(@"Torrent remaining size: %f", torrentRemaining);
     428   
     429    if (remainingSpace - torrentRemaining <= 10240.0)
     430    {
     431        NSAlert * alert = [[NSAlert alloc] init];
     432        [alert setMessageText: [NSString stringWithFormat: @"Not enough remaining disk space to download \"%@\" completely.",
     433                                    [self name]]];
     434        [alert setInformativeText: @"The transfer has been paused. Clear up space on your disk to continue."];
     435       
     436        [alert runModal];
     437       
     438        return NO;
     439    }
     440   
     441    return YES;
    417442}
    418443
Note: See TracChangeset for help on using the changeset viewer.