1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 17:47:37 +00:00

Make sure nil is returned on failure.

This commit is contained in:
Mitchell Livingston 2006-06-15 05:30:08 +00:00
parent fb875a5409
commit 78753134fa

View file

@ -28,6 +28,7 @@
@interface Torrent (Private) @interface Torrent (Private)
- (id) initWithHash: (NSString *) hashString path: (NSString *) path lib: (tr_handle_t *) lib - (id) initWithHash: (NSString *) hashString path: (NSString *) path lib: (tr_handle_t *) lib
privateTorrent: (NSNumber *) privateTorrent publicTorrent: (NSNumber *) publicTorrent
date: (NSDate *) date stopRatioSetting: (NSNumber *) stopRatioSetting date: (NSDate *) date stopRatioSetting: (NSNumber *) stopRatioSetting
ratioLimit: (NSNumber *) ratioLimit; ratioLimit: (NSNumber *) ratioLimit;
@ -40,46 +41,26 @@
- (id) initWithPath: (NSString *) path lib: (tr_handle_t *) lib - (id) initWithPath: (NSString *) path lib: (tr_handle_t *) lib
{ {
fDefaults = [NSUserDefaults standardUserDefaults]; if ((self = [self initWithHash: nil path: path lib: lib
privateTorrent: nil publicTorrent: nil
fPrivateTorrent = [fDefaults boolForKey: @"SavePrivateTorrent"]; date: nil stopRatioSetting: nil ratioLimit: nil]))
fPublicTorrent = !fPrivateTorrent || ![fDefaults boolForKey: @"DeleteOriginalTorrent"];
id torrent = [self initWithHash: nil path: path lib: lib date: nil
stopRatioSetting: nil ratioLimit: nil];
if (torrent)
{ {
if (!fPublicTorrent) if (!fPublicTorrent)
{
[self trashFile: path]; [self trashFile: path];
[fPublicTorrentLocation release];
fPublicTorrentLocation = nil;
}
} }
return torrent; return self;
} }
- (id) initWithHistory: (NSDictionary *) history lib: (tr_handle_t *) lib - (id) initWithHistory: (NSDictionary *) history lib: (tr_handle_t *) lib
{ {
fDefaults = [NSUserDefaults standardUserDefaults]; if ((self = [self initWithHash: [history objectForKey: @"TorrentHash"]
path: [history objectForKey: @"TorrentPath"] lib: lib
NSNumber * privateCopy, * publicCopy; privateTorrent: [history objectForKey: @"PrivateCopy"]
fPrivateTorrent = (privateCopy = [history objectForKey: @"PrivateCopy"]) && [privateCopy boolValue]; publicTorrent: [history objectForKey: @"PublicCopy"]
fPublicTorrent = !fPrivateTorrent || ((publicCopy = [history objectForKey: @"PublicCopy"]) date: [history objectForKey: @"Date"]
&& [publicCopy boolValue]);
//load from saved torrent file if set to, otherwise try to load from where torrent file should be
id torrent;
torrent = [self initWithHash: [history objectForKey: @"TorrentHash"]
path: [history objectForKey: @"TorrentPath"]
lib: lib date: [history objectForKey: @"Date"]
stopRatioSetting: [history objectForKey: @"StopRatioSetting"] stopRatioSetting: [history objectForKey: @"StopRatioSetting"]
ratioLimit: [history objectForKey: @"RatioLimit"]]; ratioLimit: [history objectForKey: @"RatioLimit"]]))
if (torrent)
{ {
NSString * downloadFolder; NSString * downloadFolder;
if (!(downloadFolder = [history objectForKey: @"DownloadFolder"])) if (!(downloadFolder = [history objectForKey: @"DownloadFolder"]))
@ -91,7 +72,8 @@
if (!(paused = [history objectForKey: @"Paused"]) || [paused isEqualToString: @"NO"]) if (!(paused = [history objectForKey: @"Paused"]) || [paused isEqualToString: @"NO"])
[self start]; [self start];
} }
return torrent;
return self;
} }
- (NSDictionary *) history - (NSDictionary *) history
@ -542,23 +524,29 @@
@implementation Torrent (Private) @implementation Torrent (Private)
//if a hash is given, attempt to load that; otherwise, attempt to open file at path
- (id) initWithHash: (NSString *) hashString path: (NSString *) path lib: (tr_handle_t *) lib - (id) initWithHash: (NSString *) hashString path: (NSString *) path lib: (tr_handle_t *) lib
date: (NSDate *) date stopRatioSetting: (NSNumber *) stopRatioSetting privateTorrent: (NSNumber *) privateTorrent publicTorrent: (NSNumber *) publicTorrent
ratioLimit: (NSNumber *) ratioLimit date: (NSDate *) date stopRatioSetting: (NSNumber *) stopRatioSetting
ratioLimit: (NSNumber *) ratioLimit
{ {
if (!(self = [super init])) if (!(self = [super init]))
return nil; return nil;
fLib = lib; fLib = lib;
fDefaults = [NSUserDefaults standardUserDefaults];
fPrivateTorrent = privateTorrent ? [privateTorrent boolValue] : [fDefaults boolForKey: @"SavePrivateTorrent"];
fPublicTorrent = !fPrivateTorrent || (publicTorrent ? [publicTorrent boolValue]
: ![fDefaults boolForKey: @"DeleteOriginalTorrent"]);
int error; int error;
if (hashString) if (fPrivateTorrent && hashString)
fHandle = tr_torrentInitSaved(fLib, [hashString UTF8String], TR_FSAVEPRIVATE, & error); fHandle = tr_torrentInitSaved(fLib, [hashString UTF8String], TR_FSAVEPRIVATE, & error);
else if (path) else if (path)
fHandle = tr_torrentInit(fLib, [path UTF8String], fPrivateTorrent ? TR_FSAVEPRIVATE : 0, & error); fHandle = tr_torrentInit(fLib, [path UTF8String], fPrivateTorrent ? TR_FSAVEPRIVATE : 0, & error);
else else;
fHandle = nil;
if (!fHandle) if (!fHandle)
{ {
[self release]; [self release];
@ -567,7 +555,7 @@
fInfo = tr_torrentInfo( fHandle ); fInfo = tr_torrentInfo( fHandle );
if (path) if (fPublicTorrent)
fPublicTorrentLocation = [path retain]; fPublicTorrentLocation = [path retain];
fDate = date ? [date retain] : [[NSDate alloc] init]; fDate = date ? [date retain] : [[NSDate alloc] init];