Changeset 364


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

Simplify the code a bit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Torrent.m

    r363 r364  
    2828@interface Torrent (Private)
    2929
    30 - (id) initWithPath: (NSString *) path lib: (tr_handle_t *) lib date: (NSDate *) date
    31         stopRatioSetting: (NSNumber *) stopRatioSetting ratioLimit: (NSNumber *) ratioLimit;
    3230- (id) initWithHash: (NSString *) hashString path: (NSString *) path lib: (tr_handle_t *) lib
    3331        date: (NSDate *) date stopRatioSetting: (NSNumber *) stopRatioSetting
    3432        ratioLimit: (NSNumber *) ratioLimit;
    35 - (id) initForSuccessWithPath: (NSString *) path date: (NSDate *) date stopRatioSetting: (NSNumber *)
    36             stopRatioSetting ratioLimit: (NSNumber *) ratioLimit;
    3733
    3834- (void) trashFile: (NSString *) path;
     
    5046    fPublicTorrent = !fPrivateTorrent || ![fDefaults boolForKey: @"DeleteOriginalTorrent"];
    5147
    52     id torrent = [self initWithPath: path lib: lib date: nil
     48    id torrent = [self initWithHash: nil path: path lib: lib date: nil
    5349                    stopRatioSetting: nil ratioLimit: nil];
    5450   
     
    7167    fDefaults = [NSUserDefaults standardUserDefaults];
    7268
    73     id torrent;
    7469    NSNumber * privateCopy, * publicCopy;
    7570    fPrivateTorrent = (privateCopy = [history objectForKey: @"PrivateCopy"]) && [privateCopy boolValue];
     
    7873   
    7974    //load from saved torrent file if set to, otherwise try to load from where torrent file should be
    80     if (fPrivateTorrent)
    81         torrent = [self initWithHash: [history objectForKey: @"TorrentHash"]
    82             path: [history objectForKey: @"TorrentPath"]
    83             lib: lib date: [history objectForKey: @"Date"]
    84             stopRatioSetting: [history objectForKey: @"StopRatioSetting"]
    85             ratioLimit: [history objectForKey: @"RatioLimit"]];
    86     else
    87         torrent = [self initWithPath: [history objectForKey: @"TorrentPath"]
    88             lib: lib date: [history objectForKey: @"Date"]
    89             stopRatioSetting: [history objectForKey: @"StopRatioSetting"]
    90             ratioLimit: [history objectForKey: @"RatioLimit"]];
     75    id torrent;
     76    torrent = [self initWithHash: [history objectForKey: @"TorrentHash"]
     77                path: [history objectForKey: @"TorrentPath"]
     78                lib: lib date: [history objectForKey: @"Date"]
     79                stopRatioSetting: [history objectForKey: @"StopRatioSetting"]
     80                ratioLimit: [history objectForKey: @"RatioLimit"]];
    9181           
    9282    if (torrent)
     
    553543@implementation Torrent (Private)
    554544
    555 - (id) initWithPath: (NSString *) path lib: (tr_handle_t *) lib date: (NSDate *) date
    556         stopRatioSetting: (NSNumber *) stopRatioSetting ratioLimit: (NSNumber *) ratioLimit
    557 {
    558     if (!(self = [super init]))
    559         return nil;
    560 
    561     fLib = lib;
    562 
    563     int error;
    564     if (!path || !(fHandle = tr_torrentInit(fLib, [path UTF8String],
    565                     fPrivateTorrent ? TR_FSAVEPRIVATE : 0, & error)))
    566     {
    567         [self release];
    568         return nil;
    569     }
    570 
    571     return [self initForSuccessWithPath: path date: date stopRatioSetting: stopRatioSetting ratioLimit: ratioLimit];
    572 }
    573 
    574545- (id) initWithHash: (NSString *) hashString path: (NSString *) path lib: (tr_handle_t *) lib
    575546            date: (NSDate *) date stopRatioSetting: (NSNumber *) stopRatioSetting
     
    582553
    583554    int error;
    584     if (!hashString || !(fHandle = tr_torrentInitSaved(fLib, [hashString UTF8String], TR_FSAVEPRIVATE, & error)))
     555    if (hashString)
     556        fHandle = tr_torrentInitSaved(fLib, [hashString UTF8String], TR_FSAVEPRIVATE, & error);
     557    else if (path)
     558        fHandle = tr_torrentInit(fLib, [path UTF8String], fPrivateTorrent ? TR_FSAVEPRIVATE : 0, & error);
     559    else
     560        fHandle = nil;
     561       
     562    if (!fHandle)
    585563    {
    586564        [self release];
     
    588566    }
    589567   
    590     return [self initForSuccessWithPath: path date: date stopRatioSetting: stopRatioSetting ratioLimit: ratioLimit];
    591 }
    592 
    593 - (id) initForSuccessWithPath: (NSString *) path date: (NSDate *) date stopRatioSetting: (NSNumber *)
    594             stopRatioSetting ratioLimit: (NSNumber *) ratioLimit
    595 {
    596568    fInfo = tr_torrentInfo( fHandle );
    597569
     
    619591    return self;
    620592}
    621 
    622593
    623594- (void) trashFile: (NSString *) path
Note: See TracChangeset for help on using the changeset viewer.