prepare Torrent.[mh] for rpc

This commit is contained in:
Mitchell Livingston 2008-05-26 23:23:07 +00:00
parent 8417a114a2
commit c939cc4b98
2 changed files with 52 additions and 53 deletions

View File

@ -72,7 +72,7 @@ typedef enum
- (id) initWithPath: (NSString *) path location: (NSString *) location deleteTorrentFile: (torrentFileState) torrentDelete
lib: (tr_handle *) lib;
- (id) initWithData: (NSData *) data location: (NSString *) location lib: (tr_handle *) lib;
- (id) initWithTorrentStruct: (tr_torrent *) torrentStruct location: (NSString *) location lib: (tr_handle *) lib;
- (id) initWithHistory: (NSDictionary *) history lib: (tr_handle *) lib;
- (NSDictionary *) history;

View File

@ -30,7 +30,7 @@
@interface Torrent (Private)
- (id) initWithHash: (NSString *) hashString path: (NSString *) path data: (NSData *) data lib: (tr_handle *) lib
- (id) initWithHash: (NSString *) hashString path: (NSString *) path torrentStruct: (tr_torrent *) torrentStruct lib: (tr_handle *) lib
publicTorrent: (NSNumber *) publicTorrent
downloadFolder: (NSString *) downloadFolder
useIncompleteFolder: (NSNumber *) useIncompleteFolder incompleteFolder: (NSString *) incompleteFolder
@ -70,7 +70,7 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
- (id) initWithPath: (NSString *) path location: (NSString *) location deleteTorrentFile: (torrentFileState) torrentDelete
lib: (tr_handle *) lib
{
self = [self initWithHash: nil path: path data: nil lib: lib
self = [self initWithHash: nil path: path torrentStruct: NULL lib: lib
publicTorrent: torrentDelete != TORRENT_FILE_DEFAULT
? [NSNumber numberWithBool: torrentDelete == TORRENT_FILE_SAVE] : nil
downloadFolder: location
@ -88,10 +88,10 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
return self;
}
- (id) initWithData: (NSData *) data location: (NSString *) location lib: (tr_handle *) lib
- (id) initWithTorrentStruct: (tr_torrent *) torrentStruct location: (NSString *) location lib: (tr_handle *) lib
{
self = [self initWithHash: nil path: nil data: data lib: lib
publicTorrent: nil
self = [self initWithHash: nil path: nil torrentStruct: torrentStruct lib: lib
publicTorrent: [NSNumber numberWithBool: NO]
downloadFolder: location
useIncompleteFolder: nil incompleteFolder: nil
dateAdded: nil dateCompleted: nil
@ -105,7 +105,7 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
- (id) initWithHistory: (NSDictionary *) history lib: (tr_handle *) lib
{
self = [self initWithHash: [history objectForKey: @"TorrentHash"]
path: [history objectForKey: @"TorrentPath"] data: nil lib: lib
path: [history objectForKey: @"TorrentPath"] torrentStruct: NULL lib: lib
publicTorrent: [history objectForKey: @"PublicCopy"]
downloadFolder: [history objectForKey: @"DownloadFolder"]
useIncompleteFolder: [history objectForKey: @"UseIncompleteFolder"]
@ -1525,7 +1525,7 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
@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 data: (NSData *) data lib: (tr_handle *) lib
- (id) initWithHash: (NSString *) hashString path: (NSString *) path torrentStruct: (tr_torrent *) torrentStruct lib: (tr_handle *) lib
publicTorrent: (NSNumber *) publicTorrent
downloadFolder: (NSString *) downloadFolder
useIncompleteFolder: (NSNumber *) useIncompleteFolder incompleteFolder: (NSString *) incompleteFolder
@ -1555,59 +1555,58 @@ void completenessChangeCallback(tr_torrent * torrent, cp_status_t status, void *
fIncompleteFolder = [[fIncompleteFolder stringByExpandingTildeInPath] retain];
}
//set libtransmission settings for initialization
tr_ctor * ctor = tr_ctorNew(lib);
tr_ctorSetPaused(ctor, TR_FORCE, YES);
tr_ctorSetPeerLimit(ctor, TR_FALLBACK, [fDefaults integerForKey: @"PeersTorrent"]);
tr_info info;
int error;
if (hashString)
if (torrentStruct)
{
tr_ctorSetMetainfoFromHash(ctor, [hashString UTF8String]);
if (tr_torrentParse(lib, ctor, &info) == TR_OK)
{
NSString * currentDownloadFolder = [self shouldUseIncompleteFolderForName: [NSString stringWithUTF8String: info.name]]
fHandle = torrentStruct;
const tr_info * info = tr_torrentInfo(fHandle);
NSString * currentDownloadFolder = [self shouldUseIncompleteFolderForName: [NSString stringWithUTF8String: info->name]]
? fIncompleteFolder : fDownloadFolder;
tr_ctorSetDownloadDir(ctor, TR_FORCE, [currentDownloadFolder UTF8String]);
fHandle = tr_torrentNew(lib, ctor, &error);
}
tr_metainfoFree(&info);
tr_torrentSetDownloadDir(fHandle, [currentDownloadFolder UTF8String]);
tr_metainfoFree(info);
}
if (!fHandle && path)
else
{
tr_ctorSetMetainfoFromFile(ctor, [path UTF8String]);
if (tr_torrentParse(lib, ctor, &info) == TR_OK)
//set libtransmission settings for initialization
tr_ctor * ctor = tr_ctorNew(lib);
tr_ctorSetPaused(ctor, TR_FORCE, YES);
tr_ctorSetPeerLimit(ctor, TR_FALLBACK, [fDefaults integerForKey: @"PeersTorrent"]);
tr_info info;
if (hashString)
{
NSString * currentDownloadFolder = [self shouldUseIncompleteFolderForName: [NSString stringWithUTF8String: info.name]]
? fIncompleteFolder : fDownloadFolder;
tr_ctorSetDownloadDir(ctor, TR_FORCE, [currentDownloadFolder UTF8String]);
fHandle = tr_torrentNew(lib, ctor, &error);
tr_ctorSetMetainfoFromHash(ctor, [hashString UTF8String]);
if (tr_torrentParse(lib, ctor, &info) == TR_OK)
{
NSString * currentDownloadFolder = [self shouldUseIncompleteFolderForName: [NSString stringWithUTF8String: info.name]]
? fIncompleteFolder : fDownloadFolder;
tr_ctorSetDownloadDir(ctor, TR_FORCE, [currentDownloadFolder UTF8String]);
fHandle = tr_torrentNew(lib, ctor, NULL);
}
tr_metainfoFree(&info);
}
tr_metainfoFree(&info);
}
if (!fHandle && data)
{
tr_ctorSetMetainfo(ctor, [data bytes], [data length]);
if (tr_torrentParse(lib, ctor, &info) == TR_OK)
if (!fHandle && path)
{
NSString * currentDownloadFolder = [self shouldUseIncompleteFolderForName: [NSString stringWithUTF8String: info.name]]
? fIncompleteFolder : fDownloadFolder;
tr_ctorSetDownloadDir(ctor, TR_FORCE, [currentDownloadFolder UTF8String]);
fHandle = tr_torrentNew(lib, ctor, &error);
tr_ctorSetMetainfoFromFile(ctor, [path UTF8String]);
if (tr_torrentParse(lib, ctor, &info) == TR_OK)
{
NSString * currentDownloadFolder = [self shouldUseIncompleteFolderForName: [NSString stringWithUTF8String: info.name]]
? fIncompleteFolder : fDownloadFolder;
tr_ctorSetDownloadDir(ctor, TR_FORCE, [currentDownloadFolder UTF8String]);
fHandle = tr_torrentNew(lib, ctor, NULL);
}
tr_metainfoFree(&info);
}
tr_ctorFree(ctor);
if (!fHandle)
{
[self release];
return nil;
}
tr_metainfoFree(&info);
}
tr_ctorFree(ctor);
if (!fHandle)
{
[self release];
return nil;
}
tr_torrentSetStatusCallback(fHandle, completenessChangeCallback, self);