- Timestamp:
- Jun 9, 2006, 7:53:35 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 26 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/cli/transmissioncli.c
r264 r310 110 110 111 111 /* Open and parse torrent file */ 112 if( !( tor = tr_torrentInit( h, torrentPath, &error ) ) )112 if( !( tor = tr_torrentInit( h, torrentPath, 0, &error ) ) ) 113 113 { 114 114 printf( "Failed opening torrent file `%s'\n", torrentPath ); -
trunk/gtk/tr_torrent.c
r269 r310 271 271 errcode = -1; 272 272 handle = tr_torrentInit(tr_backend_handle(TR_BACKEND(backend)), 273 torrent, &errcode);273 torrent, 0, &errcode); 274 274 if(NULL == handle) { 275 275 switch(errcode) { -
trunk/libtransmission/fastresume.h
r261 r310 64 64 static char * fastResumeFileName( tr_io_t * io ) 65 65 { 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 ); 77 70 78 71 return ret; -
trunk/libtransmission/inout.c
r261 r310 217 217 218 218 /* Create folders */ 219 p = path; 220 while( ( p = strchr( p, '/' ) ) ) 219 if( NULL != ( p = strrchr( path, '/' ) ) ) 221 220 { 222 221 *p = '\0'; 223 if( stat( path, &sb) )222 if( tr_mkdir( path ) ) 224 223 { 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 );232 224 free( path ); 233 225 return 1; 234 226 } 235 227 *p = '/'; 236 p++;237 228 } 238 229 -
trunk/libtransmission/internal.h
r261 r310 46 46 #include <netinet/in.h> 47 47 #include <fcntl.h> 48 #include <assert.h> 48 49 #ifdef BEOS_NETSERVER 49 50 # define in_port_t uint16_t -
trunk/libtransmission/metainfo.c
r261 r310 35 35 * 36 36 **********************************************************************/ 37 int tr_metainfoParse( tr_info_t * inf, const char * path ) 37 int tr_metainfoParse( tr_info_t * inf, const char * path, 38 const char * savedHash, int saveCopy ) 38 39 { 39 40 FILE * file; … … 44 45 struct stat sb; 45 46 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 } 47 57 48 58 if( stat( path, &sb ) ) … … 98 108 SHA1( (uint8_t *) beInfo->begin, 99 109 (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 */ 102 145 free( buf ); 103 146 … … 225 268 } 226 269 270 void 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 227 279 /*********************************************************************** 228 280 * strcatUTF8 -
trunk/libtransmission/metainfo.h
r261 r310 26 26 #define TR_METAINFO_H 1 27 27 28 int tr_metainfoParse( tr_info_t *, const char * ); 28 int tr_metainfoParse( tr_info_t *, const char * path, 29 const char * savedHash, int saveCopy ); 29 30 31 void tr_metainfoRemoveSaved( const char * hashString ); 30 32 #endif -
trunk/libtransmission/platform.c
r261 r310 27 27 #include <FindDirectory.h> 28 28 #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> 33 31 34 32 #include "transmission.h" 33 34 static void 35 tr_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 } 35 60 36 61 char * tr_getPrefsDirectory() … … 56 81 #endif 57 82 58 mkdir( prefsDirectory, 0755);83 tr_mkdir( prefsDirectory ); 59 84 init = 1; 60 85 61 86 #ifdef SYS_DARWIN 62 DIR * dirh;63 struct dirent * dirp;64 87 char oldDirectory[MAX_PATH_LENGTH]; 65 char oldFile[MAX_PATH_LENGTH];66 char newFile[MAX_PATH_LENGTH];67 88 snprintf( oldDirectory, MAX_PATH_LENGTH, "%s/.transmission", 68 89 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 ); 88 92 #endif 89 93 90 94 return prefsDirectory; 95 } 96 97 char * 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 130 char * 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; 91 157 } 92 158 -
trunk/libtransmission/platform.h
r261 r310 35 35 #endif 36 36 37 char * tr_getCacheDirectory(); 38 char * tr_getTorrentsDirectory(); 39 37 40 void tr_threadCreate ( tr_thread_t *, void (*func)(void *), void * arg ); 38 41 void tr_threadJoin ( tr_thread_t * ); -
trunk/libtransmission/transmission.c
r261 r310 28 28 * Local prototypes 29 29 **********************************************************************/ 30 static tr_torrent_t * torrentRealInit( tr_handle_t *, tr_torrent_t * tor, 31 int flags, int * error ); 30 32 static void torrentReallyStop( tr_torrent_t * ); 31 33 static void downloadLoop( void * ); … … 175 177 } 176 178 179 tr_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 196 tr_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 177 212 /*********************************************************************** 178 213 * tr_torrentInit … … 181 216 * to fill it. 182 217 **********************************************************************/ 183 tr_torrent_t * tr_torrentInit( tr_handle_t * h, const char * path,184 int * error )185 { 186 tr_torrent_t * tor , * tor_tmp;218 static tr_torrent_t * torrentRealInit( tr_handle_t * h, tr_torrent_t * tor, 219 int flags, int * error ) 220 { 221 tr_torrent_t * tor_tmp; 187 222 tr_info_t * inf; 188 223 int i; 189 224 char * s1, * s2; 190 225 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; 201 228 202 229 /* Make sure this torrent is not already open */ … … 480 507 } 481 508 tr_lockUnlock( &tor->lock ); 509 } 510 511 void tr_torrentRemoveSaved( tr_torrent_t * tor ) { 512 tr_metainfoRemoveSaved( tor->info.hashString ); 482 513 } 483 514 -
trunk/libtransmission/transmission.h
r264 r310 60 60 * tr_getPrefsDirectory 61 61 *********************************************************************** 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. 65 64 **********************************************************************/ 66 65 char * tr_getPrefsDirectory(); … … 124 123 * valid torrent file, returns an handle and adds it to the list of 125 124 * 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. 127 127 **********************************************************************/ 128 128 #define TR_EINVALID 1 … … 131 131 #define TR_EOTHER 666 132 132 tr_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 **********************************************************************/ 142 tr_torrent_t * tr_torrentInitSaved( tr_handle_t *, const char * hashStr, 143 int flags, int * error ); 134 144 135 145 typedef struct tr_info_s tr_info_t; … … 202 212 203 213 /*********************************************************************** 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 **********************************************************************/ 219 void tr_torrentRemoveSaved( tr_torrent_t * ); 220 221 /*********************************************************************** 204 222 * tr_torrentClose 205 223 *********************************************************************** … … 208 226 **********************************************************************/ 209 227 void tr_torrentClose( tr_handle_t *, tr_torrent_t * ); 210 211 228 212 229 /*********************************************************************** … … 226 243 /* General info */ 227 244 uint8_t hash[SHA_DIGEST_LENGTH]; 245 char hashString[2*SHA_DIGEST_LENGTH+1]; 228 246 char name[MAX_PATH_LENGTH]; 247 248 /* Flags */ 249 #define TR_FSAVEPRIVATE 0x01 /* save a private copy of the torrent */ 250 int flags; 229 251 230 252 /* Tracker info */ -
trunk/libtransmission/utils.c
r261 r310 94 94 return NULL; 95 95 } 96 97 int 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 37 37 38 38 void * 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 **********************************************************************/ 46 int tr_mkdir( char * path ); 39 47 40 48 /*********************************************************************** -
trunk/macosx/Controller.h
r292 r310 97 97 98 98 - (void) removeTorrent: (id) sender; 99 - (void) removeTorrentDeleteTorrent: (id) sender;100 99 - (void) removeTorrentDeleteData: (id) sender; 101 - (void) removeTorrentDeleteBoth: (id) sender;102 100 - (void) removeTorrentWithIndex: (NSIndexSet *) indexSet 103 deleteTorrent: (BOOL) deleteTorrent104 101 deleteData: (BOOL) deleteData; 105 102 … … 107 104 contextInfo: (NSDictionary *) dict; 108 105 - (void) confirmRemoveTorrents: (NSArray *) torrents 109 deleteTorrent: (BOOL) deleteTorrent110 106 deleteData: (BOOL) deleteData; 111 107 -
trunk/macosx/Controller.m
r309 r310 525 525 526 526 - (void) removeTorrentWithIndex: (NSIndexSet *) indexSet 527 deleteTorrent: (BOOL) deleteTorrent528 527 deleteData: (BOOL) deleteData 529 528 { … … 541 540 NSDictionary * dict = [[NSDictionary alloc] initWithObjectsAndKeys: 542 541 torrents, @"Torrents", 543 [NSNumber numberWithBool: deleteTorrent], @"DeleteTorrent",544 542 [NSNumber numberWithBool: deleteData], @"DeleteData", 545 543 nil]; … … 552 550 title = [NSString stringWithFormat: @"Comfirm Removal of \"%@\"", 553 551 [[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?"; 555 555 } 556 556 else … … 559 559 if (selected == active) 560 560 message = [NSString stringWithFormat: 561 @"There are %d active t orrents. Do you really want to remove them?", active];561 @"There are %d active transfers.", active]; 562 562 else 563 563 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?"]; 565 568 } 566 569 … … 573 576 { 574 577 [self confirmRemoveTorrents: torrents 575 deleteTorrent: deleteTorrent576 578 deleteData: deleteData]; 577 579 } … … 584 586 585 587 NSArray * torrents = [dict objectForKey: @"Torrents"]; 586 BOOL deleteTorrent = [[dict objectForKey: @"DeleteTorrent"] boolValue];587 588 BOOL deleteData = [[dict objectForKey: @"DeleteData"] boolValue]; 588 589 [dict release]; … … 591 592 { 592 593 [self confirmRemoveTorrents: torrents 593 deleteTorrent: deleteTorrent594 594 deleteData: deleteData]; 595 595 } … … 599 599 600 600 - (void) confirmRemoveTorrents: (NSArray *) torrents 601 deleteTorrent: (BOOL) deleteTorrent602 601 deleteData: (BOOL) deleteData 603 602 { … … 610 609 if( deleteData ) 611 610 [torrent trashData]; 612 613 if( deleteTorrent ) 614 [torrent trashTorrent]; 615 611 612 [torrent removeForever]; 616 613 [fTorrents removeObject: torrent]; 617 614 } … … 626 623 - (void) removeTorrent: (id) sender 627 624 { 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]; 634 626 } 635 627 636 628 - (void) removeTorrentDeleteData: (id) sender 637 629 { 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]; 644 631 } 645 632 … … 1208 1195 1209 1196 //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:)) 1214 1198 { 1215 1199 BOOL active = NO; -
trunk/macosx/Defaults.plist
r292 r310 19 19 <key>CheckUpload</key> 20 20 <true/> 21 <key>DeleteOriginalTorrent</key> 22 <false/> 21 23 <key>DownloadChoice</key> 22 24 <string>Constant</string> … … 41 43 <key>SUScheduledCheckInterval</key> 42 44 <integer>86400</integer> 45 <key>SavePrivateTorrent</key> 46 <true/> 43 47 <key>ShowInspector</key> 44 48 <false/> -
trunk/macosx/English.lproj/MainMenu.nib/classes.nib
r292 r310 10 10 openShowSheet = id; 11 11 removeTorrent = id; 12 removeTorrentDeleteBoth = id;13 12 removeTorrentDeleteData = id; 14 removeTorrentDeleteTorrent = id;15 13 resumeAllTorrents = id; 16 14 resumeTorrent = id; -
trunk/macosx/English.lproj/MainMenu.nib/info.nib
r292 r310 10 10 <string>344 478 208 99 0 0 1152 842 </string> 11 11 <key>1480</key> 12 <string> 366 548420 60 0 0 1152 842 </string>12 <string>423 269 420 60 0 0 1152 842 </string> 13 13 <key>29</key> 14 <string>1 54 771451 44 0 0 1152 842 </string>14 <string>195 519 451 44 0 0 1152 842 </string> 15 15 <key>456</key> 16 <string>212 488 1 44 1370 0 1152 842 </string>16 <string>212 488 153 168 0 0 1152 842 </string> 17 17 <key>581</key> 18 18 <string>324 628 112 68 0 0 1152 842 </string> … … 31 31 <array> 32 32 <integer>21</integer> 33 <integer>1480</integer>34 33 </array> 35 34 <key>IBSystem Version</key> -
trunk/macosx/English.lproj/PrefsWindow.nib/classes.nib
r292 r310 11 11 setLimit = id; 12 12 setLimitCheck = id; 13 setMoveTorrent = id; 13 14 setPort = id; 14 15 setRatio = id; … … 23 24 fBadgeDownloadRateCheck = NSButton; 24 25 fBadgeUploadRateCheck = NSButton; 26 fCopyTorrentCheck = NSButton; 27 fDeleteOriginalTorrentCheck = NSButton; 25 28 fDownloadCheck = NSButton; 26 29 fDownloadField = NSTextField; -
trunk/macosx/English.lproj/PrefsWindow.nib/info.nib
r292 r310 8 8 <dict> 9 9 <key>28</key> 10 <string>34 7472 462 212 0 0 1152 842 </string>10 <string>345 472 462 212 0 0 1152 842 </string> 11 11 <key>41</key> 12 <string>345 4 61 462 2340 0 1152 842 </string>12 <string>345 423 462 310 0 0 1152 842 </string> 13 13 <key>66</key> 14 14 <string>347 526 462 104 0 0 1152 842 </string> … … 16 16 <key>IBFramework Version</key> 17 17 <string>446.1</string> 18 <key>IBOpenObjects</key> 19 <array> 20 <integer>41</integer> 21 </array> 18 22 <key>IBSystem Version</key> 19 23 <string>8I127</string> -
trunk/macosx/PrefsController.h
r292 r310 37 37 IBOutlet NSButton * fQuitCheck, * fRemoveCheck, 38 38 * fBadgeDownloadRateCheck, * fBadgeUploadRateCheck, 39 * fAutoStartCheck ;39 * fAutoStartCheck, * fCopyTorrentCheck, * fDeleteOriginalTorrentCheck; 40 40 IBOutlet NSPopUpButton * fUpdatePopUp; 41 41 … … 59 59 - (void) checkUpdate; 60 60 - (void) setAutoStart: (id) sender; 61 - (void) setMoveTorrent: (id) sender; 61 62 - (void) setDownloadLocation: (id) sender; 62 63 - (void) folderSheetShow: (id) sender; -
trunk/macosx/PrefsController.m
r292 r310 117 117 int uploadLimit = [fDefaults integerForKey: @"UploadLimit"]; 118 118 119 [fUploadCheck setState: checkUpload ? NSOnState : NSOffState];119 [fUploadCheck setState: checkUpload]; 120 120 [fUploadField setIntValue: uploadLimit]; 121 121 [fUploadField setEnabled: checkUpload]; … … 127 127 int downloadLimit = [fDefaults integerForKey: @"DownloadLimit"]; 128 128 129 [fDownloadCheck setState: checkDownload ? NSOnState : NSOffState];129 [fDownloadCheck setState: checkDownload]; 130 130 [fDownloadField setIntValue: downloadLimit]; 131 131 [fDownloadField setEnabled: checkDownload]; … … 135 135 //set ratio limit 136 136 BOOL ratioCheck = [fDefaults boolForKey: @"RatioCheck"]; 137 [fRatioCheck setState: ratioCheck ? NSOnState : NSOffState];137 [fRatioCheck setState: ratioCheck]; 138 138 [fRatioField setEnabled: ratioCheck]; 139 139 [fRatioField setFloatValue: [fDefaults floatForKey: @"RatioLimit"]]; 140 140 141 141 //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"]]; 146 144 147 145 //set dock badging … … 151 149 //set auto start 152 150 [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"]]; 153 158 154 159 //set update check … … 418 423 { 419 424 [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"]; 420 443 } 421 444 -
trunk/macosx/Torrent.h
r292 r310 36 36 tr_info_t * fInfo; 37 37 tr_stat_t * fStat; 38 38 39 BOOL fResumeOnWake; 39 40 NSDate * fDate; 41 42 BOOL fPrivateTorrent; 40 43 41 44 NSUserDefaults * fDefaults; … … 56 59 - (void) getAvailability: (int8_t *) tab size: (int) size; 57 60 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; 63 67 64 68 - (float) ratio; … … 69 73 70 74 - (void) reveal; 71 - (void) trashTorrent;72 75 - (void) trashData; 73 76 -
trunk/macosx/Torrent.m
r292 r310 29 29 @interface Torrent (Private) 30 30 31 - (void) trashPath: (NSString *) path;32 31 - (id) initWithPath: (NSString *) path lib: (tr_handle_t *) lib date: (NSDate *) date 33 32 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; 34 39 35 40 @end … … 40 45 - (id) initWithPath: (NSString *) path lib: (tr_handle_t *) lib 41 46 { 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; 45 57 } 46 58 47 59 - (id) initWithHistory: (NSDictionary *) history lib: (tr_handle_t *) lib 48 60 { 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"] 50 70 lib: lib date: [history objectForKey: @"Date"] 51 71 stopRatioSetting: [history objectForKey: @"StopRatioSetting"] … … 69 89 - (NSDictionary *) history 70 90 { 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; 78 105 } 79 106 … … 128 155 [fProgressString setString: @""]; 129 156 if ([self progress] < 1.0) 130 [fProgressString appendFormat: @"%@ of %@ completed(%.2f%%)", [NSString stringForFileSize:157 [fProgressString appendFormat: @"%@ of %@ (%.2f%%)", [NSString stringForFileSize: 131 158 [self downloaded]], [NSString stringForFileSize: [self size]], 100 * [self progress]]; 132 159 else … … 213 240 } 214 241 242 - (void) removeForever 243 { 244 if (fInfo->flags & TR_FSAVEPRIVATE) 245 tr_torrentRemoveSaved(fHandle); 246 } 247 215 248 - (void) sleep 216 249 { … … 262 295 } 263 296 264 - (void) trashTorrent265 {266 [self trashPath: [self torrentLocation]];267 }268 269 297 - (void) trashData 270 298 { … … 315 343 - (NSString *) hashString 316 344 { 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]; 325 346 } 326 347 327 348 - (NSString *) torrentLocation 328 349 { 329 return [NSString stringWithUTF8String: fInfo->torrent]; ;350 return [NSString stringWithUTF8String: fInfo->torrent]; 330 351 } 331 352 … … 488 509 489 510 fLib = lib; 511 fDefaults = [NSUserDefaults standardUserDefaults]; 512 513 fPrivateTorrent = [fDefaults boolForKey: @"SavePrivateTorrent"]; 490 514 491 515 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))) 493 518 { 494 519 [self release]; 495 520 return nil; 496 521 } 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 { 498 550 fInfo = tr_torrentInfo( fHandle ); 499 500 fDefaults = [NSUserDefaults standardUserDefaults];501 551 502 552 fDate = date ? [date retain] : [[NSDate alloc] init]; … … 518 568 return self; 519 569 } 570 520 571 521 572 - (void) trashPath: (NSString *) path
Note: See TracChangeset
for help on using the changeset viewer.