Changeset 5937


Ignore:
Timestamp:
May 26, 2008, 11:23:07 PM (14 years ago)
Author:
livings124
Message:

prepare Torrent.[mh] for rpc

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Torrent.h

    r5858 r5937  
    7373- (id) initWithPath: (NSString *) path location: (NSString *) location deleteTorrentFile: (torrentFileState) torrentDelete
    7474        lib: (tr_handle *) lib;
    75 - (id) initWithData: (NSData *) data location: (NSString *) location lib: (tr_handle *) lib;
     75- (id) initWithTorrentStruct: (tr_torrent *) torrentStruct location: (NSString *) location lib: (tr_handle *) lib;
    7676- (id) initWithHistory: (NSDictionary *) history lib: (tr_handle *) lib;
    7777
  • trunk/macosx/Torrent.m

    r5922 r5937  
    3131@interface Torrent (Private)
    3232
    33 - (id) initWithHash: (NSString *) hashString path: (NSString *) path data: (NSData *) data lib: (tr_handle *) lib
     33- (id) initWithHash: (NSString *) hashString path: (NSString *) path torrentStruct: (tr_torrent *) torrentStruct lib: (tr_handle *) lib
    3434        publicTorrent: (NSNumber *) publicTorrent
    3535        downloadFolder: (NSString *) downloadFolder
     
    7171        lib: (tr_handle *) lib
    7272{
    73     self = [self initWithHash: nil path: path data: nil lib: lib
     73    self = [self initWithHash: nil path: path torrentStruct: NULL lib: lib
    7474            publicTorrent: torrentDelete != TORRENT_FILE_DEFAULT
    7575                            ? [NSNumber numberWithBool: torrentDelete == TORRENT_FILE_SAVE] : nil
     
    8989}
    9090
    91 - (id) initWithData: (NSData *) data location: (NSString *) location lib: (tr_handle *) lib
    92 {
    93     self = [self initWithHash: nil path: nil data: data lib: lib
    94             publicTorrent: nil
     91- (id) initWithTorrentStruct: (tr_torrent *) torrentStruct location: (NSString *) location lib: (tr_handle *) lib
     92{
     93    self = [self initWithHash: nil path: nil torrentStruct: torrentStruct lib: lib
     94            publicTorrent: [NSNumber numberWithBool: NO]
    9595            downloadFolder: location
    9696            useIncompleteFolder: nil incompleteFolder: nil
     
    106106{
    107107    self = [self initWithHash: [history objectForKey: @"TorrentHash"]
    108                 path: [history objectForKey: @"TorrentPath"] data: nil lib: lib
     108                path: [history objectForKey: @"TorrentPath"] torrentStruct: NULL lib: lib
    109109                publicTorrent: [history objectForKey: @"PublicCopy"]
    110110                downloadFolder: [history objectForKey: @"DownloadFolder"]
     
    15261526
    15271527//if a hash is given, attempt to load that; otherwise, attempt to open file at path
    1528 - (id) initWithHash: (NSString *) hashString path: (NSString *) path data: (NSData *) data lib: (tr_handle *) lib
     1528- (id) initWithHash: (NSString *) hashString path: (NSString *) path torrentStruct: (tr_torrent *) torrentStruct lib: (tr_handle *) lib
    15291529        publicTorrent: (NSNumber *) publicTorrent
    15301530        downloadFolder: (NSString *) downloadFolder
     
    15561556    }
    15571557   
    1558     //set libtransmission settings for initialization
    1559     tr_ctor * ctor = tr_ctorNew(lib);
    1560     tr_ctorSetPaused(ctor, TR_FORCE, YES);
    1561     tr_ctorSetPeerLimit(ctor, TR_FALLBACK, [fDefaults integerForKey: @"PeersTorrent"]);
    1562    
    1563     tr_info info;
    1564     int error;
    1565     if (hashString)
    1566     {
    1567         tr_ctorSetMetainfoFromHash(ctor, [hashString UTF8String]);
    1568         if (tr_torrentParse(lib, ctor, &info) == TR_OK)
    1569         {
    1570             NSString * currentDownloadFolder = [self shouldUseIncompleteFolderForName: [NSString stringWithUTF8String: info.name]]
     1558    if (torrentStruct)
     1559    {
     1560        fHandle = torrentStruct;
     1561       
     1562        const tr_info * info = tr_torrentInfo(fHandle);
     1563        NSString * currentDownloadFolder = [self shouldUseIncompleteFolderForName: [NSString stringWithUTF8String: info->name]]
    15711564                                                ? fIncompleteFolder : fDownloadFolder;
    1572             tr_ctorSetDownloadDir(ctor, TR_FORCE, [currentDownloadFolder UTF8String]);
    1573            
    1574             fHandle = tr_torrentNew(lib, ctor, &error);
    1575         }
    1576         tr_metainfoFree(&info);
    1577     }
    1578     if (!fHandle && path)
    1579     {
    1580         tr_ctorSetMetainfoFromFile(ctor, [path UTF8String]);
    1581         if (tr_torrentParse(lib, ctor, &info) == TR_OK)
    1582         {
    1583             NSString * currentDownloadFolder = [self shouldUseIncompleteFolderForName: [NSString stringWithUTF8String: info.name]]
    1584                                                 ? fIncompleteFolder : fDownloadFolder;
    1585             tr_ctorSetDownloadDir(ctor, TR_FORCE, [currentDownloadFolder UTF8String]);
    1586            
    1587             fHandle = tr_torrentNew(lib, ctor, &error);
    1588         }
    1589         tr_metainfoFree(&info);
    1590     }
    1591     if (!fHandle && data)
    1592     {
    1593         tr_ctorSetMetainfo(ctor, [data bytes], [data length]);
    1594         if (tr_torrentParse(lib, ctor, &info) == TR_OK)
    1595         {
    1596             NSString * currentDownloadFolder = [self shouldUseIncompleteFolderForName: [NSString stringWithUTF8String: info.name]]
    1597                                                 ? fIncompleteFolder : fDownloadFolder;
    1598             tr_ctorSetDownloadDir(ctor, TR_FORCE, [currentDownloadFolder UTF8String]);
    1599            
    1600             fHandle = tr_torrentNew(lib, ctor, &error);
    1601         }
    1602         tr_metainfoFree(&info);
    1603     }
    1604    
    1605     tr_ctorFree(ctor);
    1606    
    1607     if (!fHandle)
    1608     {
    1609         [self release];
    1610         return nil;
     1565        tr_torrentSetDownloadDir(fHandle, [currentDownloadFolder UTF8String]);
     1566        tr_metainfoFree(info);
     1567    }
     1568    else
     1569    {
     1570        //set libtransmission settings for initialization
     1571        tr_ctor * ctor = tr_ctorNew(lib);
     1572        tr_ctorSetPaused(ctor, TR_FORCE, YES);
     1573        tr_ctorSetPeerLimit(ctor, TR_FALLBACK, [fDefaults integerForKey: @"PeersTorrent"]);
     1574       
     1575        tr_info info;
     1576        if (hashString)
     1577        {
     1578            tr_ctorSetMetainfoFromHash(ctor, [hashString UTF8String]);
     1579            if (tr_torrentParse(lib, ctor, &info) == TR_OK)
     1580            {
     1581                NSString * currentDownloadFolder = [self shouldUseIncompleteFolderForName: [NSString stringWithUTF8String: info.name]]
     1582                                                    ? fIncompleteFolder : fDownloadFolder;
     1583                tr_ctorSetDownloadDir(ctor, TR_FORCE, [currentDownloadFolder UTF8String]);
     1584               
     1585                fHandle = tr_torrentNew(lib, ctor, NULL);
     1586            }
     1587            tr_metainfoFree(&info);
     1588        }
     1589        if (!fHandle && path)
     1590        {
     1591            tr_ctorSetMetainfoFromFile(ctor, [path UTF8String]);
     1592            if (tr_torrentParse(lib, ctor, &info) == TR_OK)
     1593            {
     1594                NSString * currentDownloadFolder = [self shouldUseIncompleteFolderForName: [NSString stringWithUTF8String: info.name]]
     1595                                                    ? fIncompleteFolder : fDownloadFolder;
     1596                tr_ctorSetDownloadDir(ctor, TR_FORCE, [currentDownloadFolder UTF8String]);
     1597               
     1598                fHandle = tr_torrentNew(lib, ctor, NULL);
     1599            }
     1600            tr_metainfoFree(&info);
     1601        }
     1602       
     1603        tr_ctorFree(ctor);
     1604       
     1605        if (!fHandle)
     1606        {
     1607            [self release];
     1608            return nil;
     1609        }
    16111610    }
    16121611   
Note: See TracChangeset for help on using the changeset viewer.