Changeset 310


Ignore:
Timestamp:
Jun 9, 2006, 7:53:35 PM (15 years ago)
Author:
joshe
Message:

Add support to libtransmission and the MacOS X GUI for saving private copies of

torrent files.

Location:
trunk
Files:
26 edited

Legend:

Unmodified
Added
Removed
  • trunk/cli/transmissioncli.c

    r264 r310  
    110110
    111111    /* Open and parse torrent file */
    112     if( !( tor = tr_torrentInit( h, torrentPath, &error ) ) )
     112    if( !( tor = tr_torrentInit( h, torrentPath, 0, &error ) ) )
    113113    {
    114114        printf( "Failed opening torrent file `%s'\n", torrentPath );
  • trunk/gtk/tr_torrent.c

    r269 r310  
    271271  errcode = -1;
    272272  handle = tr_torrentInit(tr_backend_handle(TR_BACKEND(backend)),
    273                           torrent, &errcode);
     273                          torrent, 0, &errcode);
    274274  if(NULL == handle) {
    275275    switch(errcode) {
  • trunk/libtransmission/fastresume.h

    r261 r310  
    6464static char * fastResumeFileName( tr_io_t * io )
    6565{
    66     char * ret, * p;
    67     int i;
    68 
    69     asprintf( &ret, "%s/resume.%40d", tr_getPrefsDirectory(), 0 );
    70 
    71     p = &ret[ strlen( ret ) - 2 * SHA_DIGEST_LENGTH ];
    72     for( i = 0; i < SHA_DIGEST_LENGTH; i++ )
    73     {
    74         sprintf( p, "%02x", io->tor->info.hash[i] );
    75         p += 2;
    76     }
     66    char * ret;
     67
     68    asprintf( &ret, "%s/resume.%s", tr_getCacheDirectory(),
     69              io->tor->info.hashString );
    7770
    7871    return ret;
  • trunk/libtransmission/inout.c

    r261 r310  
    217217
    218218        /* Create folders */
    219         p = path;
    220         while( ( p = strchr( p, '/' ) ) )
     219        if( NULL != ( p = strrchr( path, '/' ) ) )
    221220        {
    222221            *p = '\0';
    223             if( stat( path, &sb ) )
     222            if( tr_mkdir( path ) )
    224223            {
    225                 /* Folder doesn't exist yet */
    226                 mkdir( path, 0777 );
    227             }
    228             else if( ( sb.st_mode & S_IFMT ) != S_IFDIR )
    229             {
    230                 /* Node exists but isn't a folder */
    231                 printf( "Remove %s, it's in the way.\n", path );
    232224                free( path );
    233225                return 1;
    234226            }
    235227            *p = '/';
    236             p++;
    237228        }
    238229
  • trunk/libtransmission/internal.h

    r261 r310  
    4646#include <netinet/in.h>
    4747#include <fcntl.h>
     48#include <assert.h>
    4849#ifdef BEOS_NETSERVER
    4950#  define in_port_t uint16_t
  • trunk/libtransmission/metainfo.c

    r261 r310  
    3535 *
    3636 **********************************************************************/
    37 int tr_metainfoParse( tr_info_t * inf, const char * path )
     37int tr_metainfoParse( tr_info_t * inf, const char * path,
     38                      const char * savedHash, int saveCopy )
    3839{
    3940    FILE       * file;
     
    4445    struct stat sb;
    4546
    46     snprintf( inf->torrent, MAX_PATH_LENGTH, "%s", path );
     47    assert( NULL == path || NULL == savedHash );
     48    /* if savedHash isn't null, saveCopy should be false */
     49    assert( NULL == savedHash || !saveCopy );
     50
     51    if ( NULL != savedHash )
     52    {
     53        snprintf( inf->torrent, MAX_PATH_LENGTH, "%s/%s",
     54                  tr_getTorrentsDirectory(), savedHash );
     55        path = inf->torrent;
     56    }
    4757
    4858    if( stat( path, &sb ) )
     
    98108    SHA1( (uint8_t *) beInfo->begin,
    99109          (long) beInfo->end - (long) beInfo->begin, inf->hash );
    100 
    101     /* No that we got the hash, we won't need this anymore */
     110    for( i = 0; i < SHA_DIGEST_LENGTH; i++ )
     111    {
     112        sprintf( inf->hashString + i * 2, "%02x", inf->hash[i] );
     113    }
     114
     115    if( saveCopy )
     116    {
     117        /* Save a copy of the torrent file in the private torrent directory */
     118        snprintf( inf->torrent, MAX_PATH_LENGTH, "%s/%s",
     119                  tr_getTorrentsDirectory(), inf->hashString );
     120        file = fopen( inf->torrent, "wb" );
     121        if( !file )
     122        {
     123            fprintf( stderr, "Could not open file (%s) (%s)\n", inf->torrent, strerror(errno) );
     124            tr_bencFree( &meta );
     125            free( buf );
     126            return 1;
     127        }
     128        fseek( file, 0, SEEK_SET );
     129        if( fwrite( buf, sb.st_size, 1, file ) != 1 )
     130        {
     131            fprintf( stderr, "Write error (%s)\n", inf->torrent );
     132            tr_bencFree( &meta );
     133            free( buf );
     134            fclose( file );
     135            return 1;
     136        }
     137        fclose( file );
     138    }
     139    else
     140    {
     141        snprintf( inf->torrent, MAX_PATH_LENGTH, "%s", path );
     142    }
     143
     144    /* We won't need this anymore */
    102145    free( buf );
    103146
     
    225268}
    226269
     270void tr_metainfoRemoveSaved( const char * hashString )
     271{
     272    char file[MAX_PATH_LENGTH];
     273
     274    snprintf( file, MAX_PATH_LENGTH, "%s/%s",
     275              tr_getTorrentsDirectory(), hashString );
     276    unlink(file);
     277}
     278
    227279/***********************************************************************
    228280 * strcatUTF8
  • trunk/libtransmission/metainfo.h

    r261 r310  
    2626#define TR_METAINFO_H 1
    2727
    28 int tr_metainfoParse( tr_info_t *, const char * );
     28int tr_metainfoParse( tr_info_t *, const char * path,
     29                      const char * savedHash, int saveCopy );
    2930
     31void tr_metainfoRemoveSaved( const char * hashString );
    3032#endif
  • trunk/libtransmission/platform.c

    r261 r310  
    2727  #include <FindDirectory.h>
    2828#endif
    29 #ifdef SYS_DARWIN
    30   #include <sys/types.h>
    31   #include <dirent.h>
    32 #endif
     29#include <sys/types.h>
     30#include <dirent.h>
    3331
    3432#include "transmission.h"
     33
     34static void
     35tr_migrateResume( const char *oldDirectory, const char *newDirectory )
     36{
     37    DIR * dirh;
     38    struct dirent * dirp;
     39    char oldFile[MAX_PATH_LENGTH];
     40    char newFile[MAX_PATH_LENGTH];
     41
     42    if( ( dirh = opendir( oldDirectory ) ) )
     43    {
     44        while( ( dirp = readdir( dirh ) ) )
     45        {
     46            if( strncmp( "resume.", dirp->d_name, 7 ) )
     47            {
     48                continue;
     49            }
     50            snprintf( oldFile, MAX_PATH_LENGTH, "%s/%s",
     51                      oldDirectory, dirp->d_name );
     52            snprintf( newFile, MAX_PATH_LENGTH, "%s/%s",
     53                      newDirectory, dirp->d_name );
     54            rename( oldFile, newFile );
     55        }
     56
     57        closedir( dirh );
     58    }
     59}
    3560
    3661char * tr_getPrefsDirectory()
     
    5681#endif
    5782
    58         mkdir( prefsDirectory, 0755 );
     83    tr_mkdir( prefsDirectory );
    5984    init = 1;
    6085
    6186#ifdef SYS_DARWIN
    62     DIR * dirh;
    63     struct dirent * dirp;
    6487    char oldDirectory[MAX_PATH_LENGTH];
    65     char oldFile[MAX_PATH_LENGTH];
    66     char newFile[MAX_PATH_LENGTH];
    6788    snprintf( oldDirectory, MAX_PATH_LENGTH, "%s/.transmission",
    6889              getenv( "HOME" ) );
    69     if( ( dirh = opendir( oldDirectory ) ) )
    70     {
    71         while( ( dirp = readdir( dirh ) ) )
    72         {
    73             if( !strcmp( ".", dirp->d_name ) ||
    74                 !strcmp( "..", dirp->d_name ) )
    75             {
    76                 continue;
    77             }
    78             snprintf( oldFile, MAX_PATH_LENGTH, "%s/%s",
    79                       oldDirectory, dirp->d_name );
    80             snprintf( newFile, MAX_PATH_LENGTH, "%s/%s",
    81                       prefsDirectory, dirp->d_name );
    82             rename( oldFile, newFile );
    83         }
    84 
    85         closedir( dirh );
    86         rmdir( oldDirectory );
    87     }
     90    tr_migrateResume( oldDirectory, prefsDirectory );
     91    rmdir( oldDirectory );
    8892#endif
    8993
    9094    return prefsDirectory;
     95}
     96
     97char * tr_getCacheDirectory()
     98{
     99    static char cacheDirectory[MAX_PATH_LENGTH];
     100    static int  init = 0;
     101
     102    if( init )
     103    {
     104        return cacheDirectory;
     105    }
     106
     107#ifdef SYS_BEOS
     108    /* XXX hey Bryan, is this fine with you? */
     109    snprintf( cacheDirectory, MAX_PATH_LENGTH, "%s/Cache",
     110              tr_getPrefsDirectory() );
     111#elif defined( SYS_DARWIN )
     112    snprintf( cacheDirectory, MAX_PATH_LENGTH, "%s",
     113              tr_getPrefsDirectory() );
     114#else
     115    snprintf( cacheDirectory, MAX_PATH_LENGTH, "%s/cache",
     116              tr_getPrefsDirectory() );
     117#endif
     118
     119    tr_mkdir( cacheDirectory );
     120    init = 1;
     121
     122    if( strcmp( tr_getPrefsDirectory(), cacheDirectory ) )
     123    {
     124        tr_migrateResume( tr_getPrefsDirectory(), cacheDirectory );
     125    }
     126
     127    return cacheDirectory;
     128}
     129
     130char * tr_getTorrentsDirectory()
     131{
     132    static char torrentsDirectory[MAX_PATH_LENGTH];
     133    static int  init = 0;
     134
     135    if( init )
     136    {
     137        return torrentsDirectory;
     138    }
     139
     140#ifdef SYS_BEOS
     141    /* XXX hey Bryan, is this fine with you? */
     142    snprintf( torrentsDirectory, MAX_PATH_LENGTH, "%s/Torrents",
     143              tr_getPrefsDirectory() );
     144#elif defined( SYS_DARWIN )
     145    snprintf( torrentsDirectory, MAX_PATH_LENGTH,
     146              "%s/Library/Application Support/Transmission/Torrents",
     147              getenv( "HOME" ) );
     148#else
     149    snprintf( torrentsDirectory, MAX_PATH_LENGTH, "%s/torrents",
     150              tr_getPrefsDirectory() );
     151#endif
     152
     153    tr_mkdir( torrentsDirectory );
     154    init = 1;
     155
     156    return torrentsDirectory;
    91157}
    92158
  • trunk/libtransmission/platform.h

    r261 r310  
    3535#endif
    3636
     37char * tr_getCacheDirectory();
     38char * tr_getTorrentsDirectory();
     39
    3740void tr_threadCreate ( tr_thread_t *, void (*func)(void *), void * arg );
    3841void tr_threadJoin   ( tr_thread_t * );
  • trunk/libtransmission/transmission.c

    r261 r310  
    2828 * Local prototypes
    2929 **********************************************************************/
     30static tr_torrent_t * torrentRealInit( tr_handle_t *, tr_torrent_t * tor,
     31                                       int flags, int * error );
    3032static void torrentReallyStop( tr_torrent_t * );
    3133static void  downloadLoop( void * );
     
    175177}
    176178
     179tr_torrent_t * tr_torrentInit( tr_handle_t * h, const char * path,
     180                               int flags, int * error )
     181{
     182    tr_torrent_t  * tor = calloc( sizeof( tr_torrent_t ), 1 );
     183    int             saveCopy = ( TR_FSAVEPRIVATE & flags );
     184
     185    /* Parse torrent file */
     186    if( tr_metainfoParse( &tor->info, path, NULL, saveCopy ) )
     187    {
     188        *error = TR_EINVALID;
     189        free( tor );
     190        return NULL;
     191    }
     192
     193    return torrentRealInit( h, tor, flags, error );
     194}
     195
     196tr_torrent_t * tr_torrentInitSaved( tr_handle_t * h, const char * hashStr,
     197                                    int flags, int * error )
     198{
     199    tr_torrent_t  * tor = calloc( sizeof( tr_torrent_t ), 1 );
     200
     201    /* Parse torrent file */
     202    if( tr_metainfoParse( &tor->info, NULL, hashStr, 0 ) )
     203    {
     204        *error = TR_EINVALID;
     205        free( tor );
     206        return NULL;
     207    }
     208
     209    return torrentRealInit( h, tor, ( TR_FSAVEPRIVATE | flags ), error );
     210}
     211
    177212/***********************************************************************
    178213 * tr_torrentInit
     
    181216 * to fill it.
    182217 **********************************************************************/
    183 tr_torrent_t * tr_torrentInit( tr_handle_t * h, const char * path,
    184                                int * error )
    185 {
    186     tr_torrent_t  * tor, * tor_tmp;
     218static tr_torrent_t * torrentRealInit( tr_handle_t * h, tr_torrent_t * tor,
     219                                       int flags, int * error )
     220{
     221    tr_torrent_t  * tor_tmp;
    187222    tr_info_t     * inf;
    188223    int             i;
    189224    char          * s1, * s2;
    190225
    191     tor = calloc( sizeof( tr_torrent_t ), 1 );
    192     inf = &tor->info;
    193 
    194     /* Parse torrent file */
    195     if( tr_metainfoParse( inf, path ) )
    196     {
    197         *error = TR_EINVALID;
    198         free( tor );
    199         return NULL;
    200     }
     226    inf        = &tor->info;
     227    inf->flags = flags;
    201228
    202229    /* Make sure this torrent is not already open */
     
    480507    }
    481508    tr_lockUnlock( &tor->lock );
     509}
     510
     511void tr_torrentRemoveSaved( tr_torrent_t * tor ) {
     512    tr_metainfoRemoveSaved( tor->info.hashString );
    482513}
    483514
  • trunk/libtransmission/transmission.h

    r264 r310  
    6060 * tr_getPrefsDirectory
    6161 ***********************************************************************
    62  * Returns the full path to the directory used by libtransmission to
    63  * store the resume files. The string belongs to libtransmission, do
    64  * not free it.
     62 * Returns the full path to a directory which can be used to store
     63 * preferences. The string belongs to libtransmission, do not free it.
    6564 **********************************************************************/
    6665char * tr_getPrefsDirectory();
     
    124123 * valid torrent file, returns an handle and adds it to the list of
    125124 * torrents (but doesn't start it). Returns NULL and sets *error
    126  * otherwise.
     125 * otherwise.  If the TR_FSAVEPRIVATE flag is passed then a private copy
     126 * of the torrent file will be saved.
    127127 **********************************************************************/
    128128#define TR_EINVALID     1
     
    131131#define TR_EOTHER       666
    132132tr_torrent_t * tr_torrentInit( tr_handle_t *, const char * path,
    133                                int * error );
     133                               int flags, int * error );
     134
     135/***********************************************************************
     136 * tr_torrentInitSaved
     137 ***********************************************************************
     138 * Opens and parses a torrent file as with tr_torrentInit, only taking
     139 * the hash string of a saved torrent file instead of a filename.  There
     140 * are currently no valid flags for this function.
     141 **********************************************************************/
     142tr_torrent_t * tr_torrentInitSaved( tr_handle_t *, const char * hashStr,
     143                                    int flags, int * error );
    134144
    135145typedef struct tr_info_s tr_info_t;
     
    202212
    203213/***********************************************************************
     214 * tr_torrentRemoveSaved
     215 ***********************************************************************
     216 * Removes the private saved copy of a torrent file for torrents which
     217 * the TR_FSAVEPRIVATE flag is set.
     218 **********************************************************************/
     219void tr_torrentRemoveSaved( tr_torrent_t * );
     220
     221/***********************************************************************
    204222 * tr_torrentClose
    205223 ***********************************************************************
     
    208226 **********************************************************************/
    209227void tr_torrentClose( tr_handle_t *, tr_torrent_t * );
    210 
    211228
    212229/***********************************************************************
     
    226243    /* General info */
    227244    uint8_t     hash[SHA_DIGEST_LENGTH];
     245    char        hashString[2*SHA_DIGEST_LENGTH+1];
    228246    char        name[MAX_PATH_LENGTH];
     247
     248    /* Flags */
     249#define TR_FSAVEPRIVATE 0x01    /* save a private copy of the torrent */
     250    int         flags;
    229251
    230252    /* Tracker info */
  • trunk/libtransmission/utils.c

    r261 r310  
    9494    return NULL;
    9595}
     96
     97int tr_mkdir( char * path )
     98{
     99    char      * p, * pp;
     100    struct stat sb;
     101    int done;
     102
     103    p = path;
     104    while( '/' == *p )
     105      p++;
     106    pp = p;
     107    done = 0;
     108    while( ( p = strchr( pp, '/' ) ) || ( p = strchr( pp, '\0' ) ) )
     109    {
     110        if( '\0' == *p)
     111        {
     112            done = 1;
     113        }
     114        else
     115        {
     116            *p = '\0';
     117        }
     118        if( stat( path, &sb ) )
     119        {
     120            /* Folder doesn't exist yet */
     121            if( mkdir( path, 0777 ) )
     122            {
     123                tr_err( "Could not create directory %s (%s)", path,
     124                        strerror( errno ) );
     125                *p = '/';
     126                return 1;
     127            }
     128        }
     129        else if( ( sb.st_mode & S_IFMT ) != S_IFDIR )
     130        {
     131            /* Node exists but isn't a folder */
     132            tr_err( "Remove %s, it's in the way.", path );
     133            *p = '/';
     134            return 1;
     135        }
     136        if( done )
     137        {
     138            break;
     139        }
     140        *p = '/';
     141        p++;
     142        pp = p;
     143    }
     144
     145    return 0;
     146}
  • trunk/libtransmission/utils.h

    r261 r310  
    3737
    3838void * tr_memmem( const void *, size_t, const void *, size_t );
     39
     40/***********************************************************************
     41 * tr_mkdir
     42 ***********************************************************************
     43 * Create a directory and any needed parent directories.
     44 * Note that the string passed in must be writable!
     45 **********************************************************************/
     46int tr_mkdir( char * path );
    3947
    4048/***********************************************************************
  • trunk/macosx/Controller.h

    r292 r310  
    9797
    9898- (void) removeTorrent:                 (id) sender;
    99 - (void) removeTorrentDeleteTorrent:    (id) sender;
    10099- (void) removeTorrentDeleteData:       (id) sender;
    101 - (void) removeTorrentDeleteBoth:       (id) sender;
    102100- (void) removeTorrentWithIndex:        (NSIndexSet *) indexSet
    103                 deleteTorrent:          (BOOL) deleteTorrent
    104101                deleteData:             (BOOL) deleteData;
    105102               
     
    107104                        contextInfo: (NSDictionary *) dict;
    108105- (void) confirmRemoveTorrents: (NSArray *) torrents
    109             deleteTorrent: (BOOL) deleteTorrent
    110106            deleteData: (BOOL) deleteData;
    111107
  • trunk/macosx/Controller.m

    r309 r310  
    525525
    526526- (void) removeTorrentWithIndex: (NSIndexSet *) indexSet
    527                   deleteTorrent: (BOOL) deleteTorrent
    528527                     deleteData: (BOOL) deleteData
    529528{
     
    541540        NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys:
    542541            torrents, @"Torrents",
    543             [NSNumber numberWithBool: deleteTorrent], @"DeleteTorrent",
    544542            [NSNumber numberWithBool: deleteData], @"DeleteData",
    545543            nil];
     
    552550            title = [NSString stringWithFormat: @"Comfirm Removal of \"%@\"",
    553551                        [[fTorrents objectAtIndex: [fTableView selectedRow]] name]];
    554             message = @"This torrent is active. Do you really want to remove it?";
     552            message = @"This transfer is active."
     553                        " Onced removed, continuing the transfer will require the torrent file."
     554                        " Do you really want to remove it?";
    555555        }
    556556        else
     
    559559            if (selected == active)
    560560                message = [NSString stringWithFormat:
    561                     @"There are %d active torrents. Do you really want to remove them?", active];
     561                    @"There are %d active transfers.", active];
    562562            else
    563563                message = [NSString stringWithFormat:
    564                     @"There are %d torrents (%d active). Do you really want to remove them?", selected, active];
     564                    @"There are %d transfers (%d active).", selected, active];
     565            message = [message stringByAppendingString:
     566                @" Onced removed, continuing the transfers will require the torrent files."
     567                " Do you really want to remove them?"];
    565568        }
    566569
     
    573576    {
    574577        [self confirmRemoveTorrents: torrents
    575                 deleteTorrent: deleteTorrent
    576578                deleteData: deleteData];
    577579    }
     
    584586
    585587    NSArray * torrents = [dict objectForKey: @"Torrents"];
    586     BOOL deleteTorrent = [[dict objectForKey: @"DeleteTorrent"] boolValue];
    587588    BOOL deleteData = [[dict objectForKey: @"DeleteData"] boolValue];
    588589    [dict release];
     
    591592    {
    592593        [self confirmRemoveTorrents: torrents
    593             deleteTorrent: deleteTorrent
    594594            deleteData: deleteData];
    595595    }
     
    599599
    600600- (void) confirmRemoveTorrents: (NSArray *) torrents
    601             deleteTorrent: (BOOL) deleteTorrent
    602601            deleteData: (BOOL) deleteData
    603602{
     
    610609        if( deleteData )
    611610            [torrent trashData];
    612            
    613         if( deleteTorrent )
    614             [torrent trashTorrent];
    615 
     611
     612        [torrent removeForever];
    616613        [fTorrents removeObject: torrent];
    617614    }
     
    626623- (void) removeTorrent: (id) sender
    627624{
    628     [self removeTorrentWithIndex: [fTableView selectedRowIndexes] deleteTorrent: NO deleteData: NO];
    629 }
    630 
    631 - (void) removeTorrentDeleteTorrent: (id) sender
    632 {
    633     [self removeTorrentWithIndex: [fTableView selectedRowIndexes] deleteTorrent: YES deleteData: NO];
     625    [self removeTorrentWithIndex: [fTableView selectedRowIndexes] deleteData: NO];
    634626}
    635627
    636628- (void) removeTorrentDeleteData: (id) sender
    637629{
    638     [self removeTorrentWithIndex: [fTableView selectedRowIndexes] deleteTorrent: NO deleteData: YES];
    639 }
    640 
    641 - (void) removeTorrentDeleteBoth: (id) sender
    642 {
    643     [self removeTorrentWithIndex: [fTableView selectedRowIndexes] deleteTorrent: YES deleteData: YES];
     630    [self removeTorrentWithIndex: [fTableView selectedRowIndexes] deleteData: YES];
    644631}
    645632
     
    12081195
    12091196    //enable remove items
    1210     if (action == @selector(removeTorrent:)
    1211         || action == @selector(removeTorrentDeleteTorrent:)
    1212         || action == @selector(removeTorrentDeleteData:)
    1213         || action == @selector(removeTorrentDeleteBoth:))
     1197    if (action == @selector(removeTorrent:) || action == @selector(removeTorrentDeleteData:))
    12141198    {
    12151199        BOOL active = NO;
  • trunk/macosx/Defaults.plist

    r292 r310  
    1919        <key>CheckUpload</key>
    2020        <true/>
     21        <key>DeleteOriginalTorrent</key>
     22        <false/>
    2123        <key>DownloadChoice</key>
    2224        <string>Constant</string>
     
    4143        <key>SUScheduledCheckInterval</key>
    4244        <integer>86400</integer>
     45        <key>SavePrivateTorrent</key>
     46        <true/>
    4347        <key>ShowInspector</key>
    4448        <false/>
  • trunk/macosx/English.lproj/MainMenu.nib/classes.nib

    r292 r310  
    1010                openShowSheet = id;
    1111                removeTorrent = id;
    12                 removeTorrentDeleteBoth = id;
    1312                removeTorrentDeleteData = id;
    14                 removeTorrentDeleteTorrent = id;
    1513                resumeAllTorrents = id;
    1614                resumeTorrent = id;
  • trunk/macosx/English.lproj/MainMenu.nib/info.nib

    r292 r310  
    1010                <string>344 478 208 99 0 0 1152 842 </string>
    1111                <key>1480</key>
    12                 <string>366 548 420 60 0 0 1152 842 </string>
     12                <string>423 269 420 60 0 0 1152 842 </string>
    1313                <key>29</key>
    14                 <string>154 771 451 44 0 0 1152 842 </string>
     14                <string>195 519 451 44 0 0 1152 842 </string>
    1515                <key>456</key>
    16                 <string>212 488 144 137 0 0 1152 842 </string>
     16                <string>212 488 153 168 0 0 1152 842 </string>
    1717                <key>581</key>
    1818                <string>324 628 112 68 0 0 1152 842 </string>
     
    3131        <array>
    3232                <integer>21</integer>
    33                 <integer>1480</integer>
    3433        </array>
    3534        <key>IBSystem Version</key>
  • trunk/macosx/English.lproj/PrefsWindow.nib/classes.nib

    r292 r310  
    1111                setLimit = id;
    1212                setLimitCheck = id;
     13                setMoveTorrent = id;
    1314                setPort = id;
    1415                setRatio = id;
     
    2324                fBadgeDownloadRateCheck = NSButton;
    2425                fBadgeUploadRateCheck = NSButton;
     26                fCopyTorrentCheck = NSButton;
     27                fDeleteOriginalTorrentCheck = NSButton;
    2528                fDownloadCheck = NSButton;
    2629                fDownloadField = NSTextField;
  • trunk/macosx/English.lproj/PrefsWindow.nib/info.nib

    r292 r310  
    88        <dict>
    99                <key>28</key>
    10                 <string>347 472 462 212 0 0 1152 842 </string>
     10                <string>345 472 462 212 0 0 1152 842 </string>
    1111                <key>41</key>
    12                 <string>345 461 462 234 0 0 1152 842 </string>
     12                <string>345 423 462 310 0 0 1152 842 </string>
    1313                <key>66</key>
    1414                <string>347 526 462 104 0 0 1152 842 </string>
     
    1616        <key>IBFramework Version</key>
    1717        <string>446.1</string>
     18        <key>IBOpenObjects</key>
     19        <array>
     20                <integer>41</integer>
     21        </array>
    1822        <key>IBSystem Version</key>
    1923        <string>8I127</string>
  • trunk/macosx/PrefsController.h

    r292 r310  
    3737    IBOutlet NSButton       * fQuitCheck, * fRemoveCheck,
    3838                            * fBadgeDownloadRateCheck, * fBadgeUploadRateCheck,
    39                             * fAutoStartCheck;                           
     39                            * fAutoStartCheck, * fCopyTorrentCheck, * fDeleteOriginalTorrentCheck;
    4040    IBOutlet NSPopUpButton  * fUpdatePopUp;
    4141
     
    5959- (void) checkUpdate;
    6060- (void) setAutoStart:          (id) sender;
     61- (void) setMoveTorrent:        (id) sender;
    6162- (void) setDownloadLocation:   (id) sender;
    6263- (void) folderSheetShow:       (id) sender;
  • trunk/macosx/PrefsController.m

    r292 r310  
    117117    int uploadLimit = [fDefaults integerForKey: @"UploadLimit"];
    118118   
    119     [fUploadCheck setState: checkUpload ? NSOnState : NSOffState];
     119    [fUploadCheck setState: checkUpload];
    120120    [fUploadField setIntValue: uploadLimit];
    121121    [fUploadField setEnabled: checkUpload];
     
    127127    int downloadLimit = [fDefaults integerForKey: @"DownloadLimit"];
    128128   
    129     [fDownloadCheck setState: checkDownload ? NSOnState : NSOffState];
     129    [fDownloadCheck setState: checkDownload];
    130130    [fDownloadField setIntValue: downloadLimit];
    131131    [fDownloadField setEnabled: checkDownload];
     
    135135    //set ratio limit
    136136    BOOL ratioCheck = [fDefaults boolForKey: @"RatioCheck"];
    137     [fRatioCheck setState: ratioCheck ? NSOnState : NSOffState];
     137    [fRatioCheck setState: ratioCheck];
    138138    [fRatioField setEnabled: ratioCheck];
    139139    [fRatioField setFloatValue: [fDefaults floatForKey: @"RatioLimit"]];
    140140   
    141141    //set remove and quit prompts
    142     [fQuitCheck setState: [fDefaults boolForKey: @"CheckQuit"] ?
    143         NSOnState : NSOffState];
    144     [fRemoveCheck setState: [fDefaults boolForKey: @"CheckRemove"] ?
    145         NSOnState : NSOffState];
     142    [fQuitCheck setState: [fDefaults boolForKey: @"CheckQuit"]];
     143    [fRemoveCheck setState: [fDefaults boolForKey: @"CheckRemove"]];
    146144
    147145    //set dock badging
     
    151149    //set auto start
    152150    [fAutoStartCheck setState: [fDefaults boolForKey: @"AutoStartDownload"]];
     151   
     152    //set private torrents
     153    BOOL copyTorrents = [fDefaults boolForKey: @"SavePrivateTorrent"];
     154    [fCopyTorrentCheck setState: copyTorrents];
     155   
     156    [fDeleteOriginalTorrentCheck setEnabled: copyTorrents];
     157    [fDeleteOriginalTorrentCheck setState: [fDefaults boolForKey: @"DeleteOriginalTorrent"]];
    153158
    154159    //set update check
     
    418423{
    419424    [fDefaults setBool: [sender state] forKey: @"AutoStartDownload"];
     425}
     426
     427- (void) setMoveTorrent: (id) sender
     428{
     429    int state = [sender state];
     430    if (sender == fCopyTorrentCheck)
     431    {
     432        [fDefaults setBool: state forKey: @"SavePrivateTorrent"];
     433       
     434        [fDeleteOriginalTorrentCheck setEnabled: state];
     435        if (state == NSOffState)
     436        {
     437            [fDeleteOriginalTorrentCheck setState: NSOffState];
     438            [fDefaults setBool: NO forKey: @"DeleteOriginalTorrent"];
     439        }
     440    }
     441    else
     442        [fDefaults setBool: state forKey: @"DeleteOriginalTorrent"];
    420443}
    421444
  • trunk/macosx/Torrent.h

    r292 r310  
    3636    tr_info_t    * fInfo;
    3737    tr_stat_t    * fStat;
     38   
    3839    BOOL         fResumeOnWake;
    3940    NSDate       * fDate;
     41   
     42    BOOL        fPrivateTorrent;
    4043
    4144    NSUserDefaults  * fDefaults;
     
    5659- (void)       getAvailability: (int8_t *) tab size: (int) size;
    5760
    58 - (void)       update;
    59 - (void)       start;
    60 - (void)       stop;
    61 - (void)       sleep;
    62 - (void)       wakeUp;
     61- (void)        update;
     62- (void)        start;
     63- (void)        stop;
     64- (void)        removeForever;
     65- (void)        sleep;
     66- (void)        wakeUp;
    6367
    6468- (float)       ratio;
     
    6973
    7074- (void)        reveal;
    71 - (void)        trashTorrent;
    7275- (void)        trashData;
    7376
  • trunk/macosx/Torrent.m

    r292 r310  
    2929@interface Torrent (Private)
    3030
    31 - (void) trashPath: (NSString *) path;
    3231- (id) initWithPath: (NSString *) path lib: (tr_handle_t *) lib date: (NSDate *) date
    3332        stopRatioSetting: (NSNumber *) stopRatioSetting ratioLimit: (NSNumber *) ratioLimit;
     33- (id) initWithHash: (NSString *) hashString lib: (tr_handle_t *) lib date: (NSDate *) date
     34        stopRatioSetting: (NSNumber *) stopRatioSetting ratioLimit: (NSNumber *) ratioLimit;
     35- (id) initForSuccessWithDate: (NSDate *) date stopRatioSetting: (NSNumber *)
     36            stopRatioSetting ratioLimit: (NSNumber *) ratioLimit;
     37
     38- (void) trashPath: (NSString *) path;
    3439
    3540@end
     
    4045- (id) initWithPath: (NSString *) path lib: (tr_handle_t *) lib
    4146{
    42     return [self initWithPath: path lib: lib
    43             date: nil stopRatioSetting: nil
    44             ratioLimit: nil];
     47    id torrent = [self initWithPath: path lib: lib date: nil
     48                    stopRatioSetting: nil ratioLimit: nil];
     49                   
     50    if (!torrent)
     51        return nil;
     52
     53    if (fPrivateTorrent && [fDefaults boolForKey: @"DeleteOriginalTorrent"])
     54        [self trashPath: path];
     55   
     56    return torrent;
    4557}
    4658
    4759- (id) initWithHistory: (NSDictionary *) history lib: (tr_handle_t *) lib
    4860{
    49     self = [self initWithPath: [history objectForKey: @"TorrentPath"]
     61    //load from saved torrent file if set to, otherwise try to load from where torrent file should be
     62    NSNumber * privateCopy;
     63    if ((privateCopy = [history objectForKey: @"PrivateCopy"]) && [privateCopy boolValue])
     64        self = [self initWithHash: [history objectForKey: @"TorrentHash"]
     65            lib: lib date: [history objectForKey: @"Date"]
     66            stopRatioSetting: [history objectForKey: @"StopRatioSetting"]
     67            ratioLimit: [history objectForKey: @"RatioLimit"]];
     68    else
     69        self = [self initWithPath: [history objectForKey: @"TorrentPath"]
    5070            lib: lib date: [history objectForKey: @"Date"]
    5171            stopRatioSetting: [history objectForKey: @"StopRatioSetting"]
     
    6989- (NSDictionary *) history
    7090{
    71     return [NSDictionary dictionaryWithObjectsAndKeys:
    72             [self torrentLocation], @"TorrentPath",
    73             [self downloadFolder], @"DownloadFolder",
    74             [self isActive] ? @"NO" : @"YES", @"Paused",
    75             [self date], @"Date",
    76             [NSNumber numberWithInt: fStopRatioSetting], @"StopRatioSetting",
    77             [NSNumber numberWithFloat: fRatioLimit], @"RatioLimit", nil];
     91    NSMutableDictionary * history = [NSMutableDictionary dictionaryWithObjectsAndKeys:
     92                    [NSNumber numberWithBool: fPrivateTorrent], @"PrivateCopy",
     93                    [self downloadFolder], @"DownloadFolder",
     94                    [self isActive] ? @"NO" : @"YES", @"Paused",
     95                    [self date], @"Date",
     96                    [NSNumber numberWithInt: fStopRatioSetting], @"StopRatioSetting",
     97                    [NSNumber numberWithFloat: fRatioLimit], @"RatioLimit", nil];
     98           
     99    if (fPrivateTorrent)
     100        [history setObject: [self hashString] forKey: @"TorrentHash"];
     101    else
     102        [history setObject: [self torrentLocation] forKey: @"TorrentPath"];
     103   
     104    return history;
    78105}
    79106
     
    128155    [fProgressString setString: @""];
    129156    if ([self progress] < 1.0)
    130         [fProgressString appendFormat: @"%@ of %@ completed (%.2f%%)", [NSString stringForFileSize:
     157        [fProgressString appendFormat: @"%@ of %@ (%.2f%%)", [NSString stringForFileSize:
    131158                [self downloaded]], [NSString stringForFileSize: [self size]], 100 * [self progress]];
    132159    else
     
    213240}
    214241
     242- (void) removeForever
     243{
     244    if (fInfo->flags & TR_FSAVEPRIVATE)
     245        tr_torrentRemoveSaved(fHandle);
     246}
     247
    215248- (void) sleep
    216249{
     
    262295}
    263296
    264 - (void) trashTorrent
    265 {
    266     [self trashPath: [self torrentLocation]];
    267 }
    268 
    269297- (void) trashData
    270298{
     
    315343- (NSString *) hashString
    316344{
    317     NSMutableString * string = [NSMutableString
    318         stringWithCapacity: SHA_DIGEST_LENGTH];
    319     int i;
    320     for( i = 0; i < SHA_DIGEST_LENGTH; i++ )
    321     {
    322         [string appendFormat: @"%02x", fInfo->hash[i]];
    323     }
    324     return string;
     345    return [NSString stringWithUTF8String: fInfo->hashString];
    325346}
    326347
    327348- (NSString *) torrentLocation
    328349{
    329     return [NSString stringWithUTF8String: fInfo->torrent];;
     350    return [NSString stringWithUTF8String: fInfo->torrent];
    330351}
    331352
     
    488509
    489510    fLib = lib;
     511    fDefaults = [NSUserDefaults standardUserDefaults];
     512
     513    fPrivateTorrent = [fDefaults boolForKey: @"SavePrivateTorrent"];
    490514
    491515    int error;
    492     if (!path || !(fHandle = tr_torrentInit(fLib, [path UTF8String], &error)))
     516    if (!path || !(fHandle = tr_torrentInit(fLib, [path UTF8String],
     517                    fPrivateTorrent ? TR_FSAVEPRIVATE : 0, & error)))
    493518    {
    494519        [self release];
    495520        return nil;
    496521    }
    497    
     522
     523    return [self initForSuccessWithDate: date stopRatioSetting: stopRatioSetting ratioLimit: ratioLimit];
     524}
     525
     526- (id) initWithHash: (NSString *) hashString lib: (tr_handle_t *) lib date: (NSDate *) date
     527        stopRatioSetting: (NSNumber *) stopRatioSetting ratioLimit: (NSNumber *) ratioLimit
     528{
     529    if (!(self = [super init]))
     530        return nil;
     531
     532    fLib = lib;
     533    fDefaults = [NSUserDefaults standardUserDefaults];
     534   
     535    fPrivateTorrent = YES;
     536
     537    int error;
     538    if (!hashString || !(fHandle = tr_torrentInitSaved(fLib, [hashString UTF8String], TR_FSAVEPRIVATE, & error)))
     539    {
     540        [self release];
     541        return nil;
     542    }
     543   
     544    return [self initForSuccessWithDate: date stopRatioSetting: stopRatioSetting ratioLimit: ratioLimit];
     545}
     546
     547- (id) initForSuccessWithDate: (NSDate *) date stopRatioSetting: (NSNumber *)
     548            stopRatioSetting ratioLimit: (NSNumber *) ratioLimit
     549{
    498550    fInfo = tr_torrentInfo( fHandle );
    499    
    500     fDefaults = [NSUserDefaults standardUserDefaults];
    501551
    502552    fDate = date ? [date retain] : [[NSDate alloc] init];
     
    518568    return self;
    519569}
     570
    520571
    521572- (void) trashPath: (NSString *) path
Note: See TracChangeset for help on using the changeset viewer.