Changeset 365


Ignore:
Timestamp:
Jun 15, 2006, 5:30:08 AM (16 years ago)
Author:
livings124
Message:

Make sure nil is returned on failure.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Torrent.m

    r364 r365  
    2929
    3030- (id) initWithHash: (NSString *) hashString path: (NSString *) path lib: (tr_handle_t *) lib
     31        privateTorrent: (NSNumber *) privateTorrent publicTorrent: (NSNumber *) publicTorrent
    3132        date: (NSDate *) date stopRatioSetting: (NSNumber *) stopRatioSetting
    3233        ratioLimit: (NSNumber *) ratioLimit;
     
    4142- (id) initWithPath: (NSString *) path lib: (tr_handle_t *) lib
    4243{
    43     fDefaults = [NSUserDefaults standardUserDefaults];
    44 
    45     fPrivateTorrent = [fDefaults boolForKey: @"SavePrivateTorrent"];
    46     fPublicTorrent = !fPrivateTorrent || ![fDefaults boolForKey: @"DeleteOriginalTorrent"];
    47 
    48     id torrent = [self initWithHash: nil path: path lib: lib date: nil
    49                     stopRatioSetting: nil ratioLimit: nil];
    50    
    51     if (torrent)
     44    if ((self = [self initWithHash: nil path: path lib: lib
     45        privateTorrent: nil publicTorrent: nil
     46        date: nil stopRatioSetting: nil ratioLimit: nil]))
    5247    {
    5348        if (!fPublicTorrent)
    54         {
    5549            [self trashFile: path];
    56            
    57             [fPublicTorrentLocation release];
    58             fPublicTorrentLocation = nil;
    59         }
    60     }
    61    
    62     return torrent;
     50    }
     51   
     52    return self;
    6353}
    6454
    6555- (id) initWithHistory: (NSDictionary *) history lib: (tr_handle_t *) lib
    6656{
    67     fDefaults = [NSUserDefaults standardUserDefaults];
    68 
    69     NSNumber * privateCopy, * publicCopy;
    70     fPrivateTorrent = (privateCopy = [history objectForKey: @"PrivateCopy"]) && [privateCopy boolValue];
    71     fPublicTorrent = !fPrivateTorrent || ((publicCopy = [history objectForKey: @"PublicCopy"])
    72                                             && [publicCopy boolValue]);
    73    
    74     //load from saved torrent file if set to, otherwise try to load from where torrent file should be
    75     id torrent;
    76     torrent = [self initWithHash: [history objectForKey: @"TorrentHash"]
    77                 path: [history objectForKey: @"TorrentPath"]
    78                 lib: lib date: [history objectForKey: @"Date"]
     57    if ((self = [self initWithHash: [history objectForKey: @"TorrentHash"]
     58                path: [history objectForKey: @"TorrentPath"] lib: lib
     59                privateTorrent: [history objectForKey: @"PrivateCopy"]
     60                publicTorrent: [history objectForKey: @"PublicCopy"]
     61                date: [history objectForKey: @"Date"]
    7962                stopRatioSetting: [history objectForKey: @"StopRatioSetting"]
    80                 ratioLimit: [history objectForKey: @"RatioLimit"]];
    81            
    82     if (torrent)
     63                ratioLimit: [history objectForKey: @"RatioLimit"]]))
    8364    {
    8465        NSString * downloadFolder;
     
    9273            [self start];
    9374    }
    94     return torrent;
     75   
     76    return self;
    9577}
    9678
     
    543525@implementation Torrent (Private)
    544526
     527//if a hash is given, attempt to load that; otherwise, attempt to open file at path
    545528- (id) initWithHash: (NSString *) hashString path: (NSString *) path lib: (tr_handle_t *) lib
    546             date: (NSDate *) date stopRatioSetting: (NSNumber *) stopRatioSetting
    547             ratioLimit: (NSNumber *) ratioLimit
     529        privateTorrent: (NSNumber *) privateTorrent publicTorrent: (NSNumber *) publicTorrent
     530        date: (NSDate *) date stopRatioSetting: (NSNumber *) stopRatioSetting
     531        ratioLimit: (NSNumber *) ratioLimit
    548532{
    549533    if (!(self = [super init]))
     
    551535
    552536    fLib = lib;
     537    fDefaults = [NSUserDefaults standardUserDefaults];
     538
     539    fPrivateTorrent = privateTorrent ? [privateTorrent boolValue] : [fDefaults boolForKey: @"SavePrivateTorrent"];
     540    fPublicTorrent = !fPrivateTorrent || (publicTorrent ? [publicTorrent boolValue]
     541                                            : ![fDefaults boolForKey: @"DeleteOriginalTorrent"]);
    553542
    554543    int error;
    555     if (hashString)
     544    if (fPrivateTorrent && hashString)
    556545        fHandle = tr_torrentInitSaved(fLib, [hashString UTF8String], TR_FSAVEPRIVATE, & error);
    557546    else if (path)
    558547        fHandle = tr_torrentInit(fLib, [path UTF8String], fPrivateTorrent ? TR_FSAVEPRIVATE : 0, & error);
    559     else
    560         fHandle = nil;
    561        
     548    else;
     549
    562550    if (!fHandle)
    563551    {
     
    568556    fInfo = tr_torrentInfo( fHandle );
    569557
    570     if (path)
     558    if (fPublicTorrent)
    571559        fPublicTorrentLocation = [path retain];
    572560
Note: See TracChangeset for help on using the changeset viewer.