Changeset 2209
- Timestamp:
- Jun 27, 2007, 10:12:10 PM (15 years ago)
- Location:
- trunk/macosx
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/macosx/Controller.m
r2205 r2209 708 708 while ((torrentPath = [enumerator nextObject])) 709 709 { 710 if (!(torrent = [[Torrent alloc] initWithPath: torrentPath forceDeleteTorrent: delete lib: fLib])) 710 NSString * location; 711 if (path) 712 location = path; 713 else if ([downloadChoice isEqualToString: @"Constant"]) 714 location = [[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath]; 715 else 716 location = [torrentPath stringByDeletingLastPathComponent]; 717 718 if (!(torrent = [[Torrent alloc] initWithPath: torrentPath location: location forceDeleteTorrent: delete lib: fLib])) 711 719 continue; 712 720 … … 714 722 [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: [NSURL fileURLWithPath: torrentPath]]; 715 723 716 NSString * folder;717 if (path)718 folder = path;719 else if ([downloadChoice isEqualToString: @"Constant"])720 folder = [[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath];721 else722 folder = [torrentPath stringByDeletingLastPathComponent];723 724 [torrent setDownloadFolder: folder];725 724 [torrent update]; 726 727 725 [fTorrents addObject: torrent]; 728 726 [torrent release]; … … 773 771 - (void) openFilesAsk: (NSMutableArray *) files forceDeleteTorrent: (BOOL) delete 774 772 { 773 //determine the next file that can be opened 775 774 NSString * torrentPath; 776 tr_torrent_t * tempTor; 777 int error; 778 779 //determine next file that can be opened 775 int canAdd; 780 776 do 781 777 { … … 789 785 790 786 torrentPath = [[files objectAtIndex: 0] retain]; 791 tempTor = tr_torrentInit(fLib, [torrentPath UTF8String], NULL, 0, &error);792 793 787 [files removeObjectAtIndex: 0]; 794 } while ( !tempTor);788 } while (tr_torrentCouldBeAdded(fLib, [torrentPath UTF8String]) != TR_OK); 795 789 796 790 NSOpenPanel * panel = [NSOpenPanel openPanel]; … … 802 796 [panel setCanCreateDirectories: YES]; 803 797 804 [panel setMessage: [NSString stringWithFormat: NSLocalizedString(@"Select the download folder for \"%@\"", 798 #warning fix!!! 799 /*[panel setMessage: [NSString stringWithFormat: NSLocalizedString(@"Select the download folder for \"%@\"", 805 800 "Open torrent -> select destination folder"), 806 [NSString stringWithUTF8String: tr_torrentInfo(tempTor)->name]]]; 801 [NSString stringWithUTF8String: tr_torrentInfo(tempTor)->name]]];*/ 802 [panel setMessage: @"Select the download folder "]; 807 803 808 804 NSDictionary * dictionary = [[NSDictionary alloc] initWithObjectsAndKeys: torrentPath, @"Path", 809 805 files, @"Files", [NSNumber numberWithBool: delete], @"Delete", nil]; 810 806 [torrentPath release]; 811 812 tr_torrentClose(tempTor); 807 813 808 [panel beginSheetForDirectory: nil file: nil types: nil modalForWindow: fWindow modalDelegate: self 814 809 didEndSelector: @selector(folderChoiceClosed:returnCode:contextInfo:) contextInfo: dictionary]; … … 820 815 { 821 816 NSString * torrentPath = [dictionary objectForKey: @"Path"]; 822 Torrent * torrent = [[Torrent alloc] initWithPath: torrentPath forceDeleteTorrent: 823 [[dictionary objectForKey: @"Delete"] boolValue] lib: fLib]; 817 Torrent * torrent = [[Torrent alloc] initWithPath: torrentPath 818 location: [[openPanel filenames] objectAtIndex: 0] 819 forceDeleteTorrent: [[dictionary objectForKey: @"Delete"] boolValue] lib: fLib]; 824 820 825 821 //add it to the "File > Open Recent" menu 826 822 [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: [NSURL fileURLWithPath: torrentPath]]; 827 823 828 [torrent setDownloadFolder: [[openPanel filenames] objectAtIndex: 0]];829 824 [torrent update]; 830 831 825 [fTorrents addObject: torrent]; 832 826 [torrent release]; … … 2024 2018 [self openFiles: newNames]; 2025 2019 2026 //c reate temporary torrents to check if an import fails because of an error2020 //check if an import fails because of an error so it can be tried again 2027 2021 enumerator = [newNames objectEnumerator]; 2028 int error;2022 int canAdd; 2029 2023 while ((file = [enumerator nextObject])) 2030 2024 { 2031 tr_torrent_t * tempTor = tr_torrentInit(fLib, [file UTF8String], NULL, 0, &error); 2032 2033 if (tempTor) 2034 tr_torrentClose(tempTor); 2035 else if (error != TR_EUNSUPPORTED && error != TR_EDUPLICATE) 2036 [fAutoImportedNames removeObject: [file lastPathComponent]]; //can try to import later 2037 else; 2025 canAdd = tr_torrentCouldBeAdded(fLib, [file UTF8String]); 2026 if (canAdd == TR_EINVALID || canAdd == TR_EOTHER) 2027 [fAutoImportedNames removeObject: [file lastPathComponent]]; 2038 2028 } 2039 2029 … … 2156 2146 NSEnumerator * enumerator = [files objectEnumerator]; 2157 2147 NSString * file; 2158 tr_torrent_t * tempTor;2159 2148 BOOL torrent = NO; 2149 int canAdd; 2160 2150 while ((file = [enumerator nextObject])) 2161 2151 { 2162 int error;2163 if ( (tempTor = tr_torrentInit(fLib, [file UTF8String], NULL, 0, &error)))2152 canAdd = tr_torrentCouldBeAdded(fLib, [file UTF8String]); 2153 if (canAdd == TR_OK) 2164 2154 { 2165 tr_torrentClose(tempTor);2166 2167 2155 if (!fOverlayWindow) 2168 2156 fOverlayWindow = [[DragOverlayWindow alloc] initWithLib: fLib forWindow: fWindow]; … … 2171 2159 return NSDragOperationCopy; 2172 2160 } 2173 else 2174 { 2175 if (error == TR_EUNSUPPORTED || error == TR_EDUPLICATE) 2176 torrent = YES; 2177 } 2161 else if (canAdd == TR_EUNSUPPORTED || canAdd == TR_EDUPLICATE) 2162 torrent = YES; 2163 else; 2178 2164 } 2179 2165 … … 2223 2209 NSString * file; 2224 2210 tr_torrent_t * tempTor; 2211 int canAdd; 2225 2212 while ((file = [enumerator nextObject])) 2226 2213 { 2227 int error;2228 if ( (tempTor = tr_torrentInit(fLib, [file UTF8String], NULL, 0, &error)))2214 canAdd = tr_torrentCouldBeAdded(fLib, [file UTF8String]); 2215 if (canAdd == TR_OK) 2229 2216 { 2230 2217 tr_torrentClose(tempTor); … … 2233 2220 torrent = YES; 2234 2221 } 2235 else 2236 { 2237 if (error == TR_EUNSUPPORTED || error == TR_EDUPLICATE) 2238 torrent = YES; 2239 } 2222 else if (canAdd == TR_EUNSUPPORTED || canAdd == TR_EDUPLICATE) 2223 torrent = YES; 2224 else; 2240 2225 } 2241 2226 -
trunk/macosx/Torrent.h
r2172 r2209 71 71 } 72 72 73 - (id) initWithPath: (NSString *) path forceDeleteTorrent: (BOOL) delete lib: (tr_handle_t *) lib;73 - (id) initWithPath: (NSString *) path location: (NSString *) location forceDeleteTorrent: (BOOL) delete lib: (tr_handle_t *) lib; 74 74 - (id) initWithHistory: (NSDictionary *) history lib: (tr_handle_t *) lib; 75 75 76 76 - (NSDictionary *) history; 77 77 78 - (void) setIncompleteFolder: (NSString *) folder; 79 - (void) setDownloadFolder: (NSString *) folder; 80 - (void) updateDownloadFolder; 78 - (void) changeIncompleteDownloadFolder: (NSString *) folder; 79 - (void) changeDownloadFolder: (NSString *) folder; 81 80 - (NSString *) downloadFolder; 82 81 … … 87 86 - (NSDictionary *) infoForCurrentView; 88 87 89 - (void) startTransfer; 90 - (void) stopTransfer; 91 - (void) stopTransferForQuit; 92 - (void) sleep; 93 - (void) wakeUp; 94 95 - (void) announce; 96 - (NSDate *) announceDate; 97 98 - (void) resetCache; 99 100 - (float) ratio; 101 - (int) ratioSetting; 102 - (void) setRatioSetting: (int) setting; 103 - (float) ratioLimit; 104 - (void) setRatioLimit: (float) limit; 105 - (float) actualStopRatio; //returns INVALID if will not stop 106 - (float) progressStopRatio; 107 108 - (int) checkUpload; 109 - (void) setCheckUpload: (int) setting; 110 - (int) uploadLimit; 111 - (void) setUploadLimit: (int) limit; 112 - (int) checkDownload; 113 - (void) setCheckDownload: (int) setting; 114 - (int) downloadLimit; 115 - (void) setDownloadLimit: (int) limit; 88 - (void) startTransfer; 89 - (void) stopTransfer; 90 - (void) sleep; 91 - (void) wakeUp; 92 93 - (void) announce; 94 - (NSDate *) announceDate; 95 96 - (void) resetCache; 97 98 - (float) ratio; 99 - (int) ratioSetting; 100 - (void) setRatioSetting: (int) setting; 101 - (float) ratioLimit; 102 - (void) setRatioLimit: (float) limit; 103 - (float) actualStopRatio; //returns INVALID if will not stop 104 - (float) progressStopRatio; 105 106 - (int) checkUpload; 107 - (void) setCheckUpload: (int) setting; 108 - (int) uploadLimit; 109 - (void) setUploadLimit: (int) limit; 110 - (int) checkDownload; 111 - (void) setCheckDownload: (int) setting; 112 - (int) downloadLimit; 113 - (void) setDownloadLimit: (int) limit; 116 114 117 115 - (void) updateSpeedSetting; … … 131 129 - (BOOL) alertForMoveFolderAvailable; 132 130 133 - (NSImage *) 134 - (NSImage *) 135 - (NSImage *) 131 - (NSImage *) icon; 132 - (NSImage *) iconFlipped; 133 - (NSImage *) iconSmall; 136 134 137 135 - (NSString *) name; 138 - (uint64_t) 136 - (uint64_t) size; 139 137 - (NSString *) trackerAddress; 140 138 - (NSString *) trackerAddressAnnounce; … … 142 140 - (NSString *) comment; 143 141 - (NSString *) creator; 144 - (NSDate *) 145 146 - (int) 147 - (int) 142 - (NSDate *) dateCreated; 143 144 - (int) pieceSize; 145 - (int) pieceCount; 148 146 - (NSString *) hashString; 149 - (BOOL) 147 - (BOOL) privateTorrent; 150 148 151 149 - (NSString *) torrentLocation; -
trunk/macosx/Torrent.m
r2205 r2209 37 37 - (id) initWithHash: (NSString *) hashString path: (NSString *) path lib: (tr_handle_t *) lib 38 38 publicTorrent: (NSNumber *) publicTorrent 39 downloadFolder: (NSString *) downloadFolder 40 useIncompleteFolder: (NSNumber *) useIncompleteFolder incompleteFolder: (NSString *) incompleteFolder 39 41 dateAdded: (NSDate *) dateAdded dateCompleted: (NSDate *) dateCompleted 40 42 dateActivity: (NSDate *) dateActivity … … 48 50 - (void) historyFilePriorities: (NSMutableArray *) history forItems: (NSArray *) items; 49 51 52 - (BOOL) shouldUseIncompleteFolder; 53 - (void) updateDownloadFolder; 54 50 55 - (void) createFileListShouldDownload: (NSArray *) filesShouldDownload priorities: (NSArray *) filePriorities; 51 56 - (void) insertPath: (NSMutableArray *) components forSiblings: (NSMutableArray *) siblings … … 71 76 kWhite = BE(0xFFFFFFFF); //255, 255, 255 72 77 73 - (id) initWithPath: (NSString *) path forceDeleteTorrent: (BOOL) delete lib: (tr_handle_t *) lib78 - (id) initWithPath: (NSString *) path location: (NSString *) location forceDeleteTorrent: (BOOL) delete lib: (tr_handle_t *) lib 74 79 { 75 80 self = [self initWithHash: nil path: path lib: lib 76 81 publicTorrent: delete ? [NSNumber numberWithBool: NO] : nil 82 downloadFolder: location 83 useIncompleteFolder: nil incompleteFolder: nil 77 84 dateAdded: nil dateCompleted: nil 78 85 dateActivity: nil … … 87 94 if (self) 88 95 { 89 if ((fUseIncompleteFolder = [fDefaults boolForKey: @"UseIncompleteDownloadFolder"]))90 fIncompleteFolder = [[[fDefaults stringForKey: @"IncompleteDownloadFolder"] stringByExpandingTildeInPath] retain];91 92 96 if (!fPublicTorrent) 93 97 [self trashFile: path]; … … 101 105 path: [history objectForKey: @"TorrentPath"] lib: lib 102 106 publicTorrent: [history objectForKey: @"PublicCopy"] 107 downloadFolder: [history objectForKey: @"DownloadFolder"] 108 useIncompleteFolder: [history objectForKey: @"UseIncompleteFolder"] 109 incompleteFolder: [history objectForKey: @"IncompleteFolder"] 103 110 dateAdded: [history objectForKey: @"Date"] 104 111 dateCompleted: [history objectForKey: @"DateCompleted"] … … 119 126 if (self) 120 127 { 121 //download folders122 if (!(fDownloadFolder = [history objectForKey: @"DownloadFolder"]))123 fDownloadFolder = [[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath];124 [fDownloadFolder retain];125 126 NSNumber * statusIncompleteFolder;127 if ((statusIncompleteFolder = [history objectForKey: @"UseIncompleteFolder"])128 && (fUseIncompleteFolder = [statusIncompleteFolder boolValue]))129 {130 if (!(fIncompleteFolder = [history objectForKey: @"IncompleteFolder"]))131 fIncompleteFolder = [[fDefaults stringForKey: @"IncompleteDownloadFolder"]132 stringByExpandingTildeInPath];133 [fIncompleteFolder retain];134 }135 else136 fUseIncompleteFolder = NO;137 138 [self updateDownloadFolder];139 140 128 //start transfer 141 129 BOOL start = YES; … … 164 152 fDownloadFolder, @"DownloadFolder", 165 153 [NSNumber numberWithBool: fUseIncompleteFolder], @"UseIncompleteFolder", 154 fIncompleteFolder, @"IncompleteFolder", 166 155 [NSNumber numberWithBool: [self isActive]], @"Active", 167 156 fDateAdded, @"Date", … … 191 180 [self historyFilePriorities: filePriorities forItems: fFileList]; 192 181 [history setObject: filePriorities forKey: @"FilePriorities"]; 193 194 if (fUseIncompleteFolder)195 [history setObject: fIncompleteFolder forKey: @"IncompleteFolder"];196 182 197 183 if (fPublicTorrent) … … 204 190 [history setObject: fDateCompleted forKey: @"DateCompleted"]; 205 191 206 NSDate * date Completed= [self dateActivity];207 if (date Completed)208 [history setObject: date CompletedforKey: @"DateActivity"];192 NSDate * dateActivity = [self dateActivity]; 193 if (dateActivity) 194 [history setObject: dateActivity forKey: @"DateActivity"]; 209 195 210 196 return history; … … 254 240 } 255 241 256 - (void) setIncompleteFolder: (NSString *) folder242 - (void) changeIncompleteDownloadFolder: (NSString *) folder 257 243 { 258 244 fUseIncompleteFolder = folder != nil; … … 269 255 } 270 256 271 - (void) setDownloadFolder: (NSString *) folder257 - (void) changeDownloadFolder: (NSString *) folder 272 258 { 273 259 if (fDownloadFolder) … … 276 262 277 263 [self updateDownloadFolder]; 278 }279 280 - (void) updateDownloadFolder281 {282 if (!fUseIncompleteFolder || [[NSFileManager defaultManager] fileExistsAtPath:283 [fDownloadFolder stringByAppendingPathComponent: [self name]]])284 tr_torrentSetFolder(fHandle, [fDownloadFolder UTF8String]);285 else286 tr_torrentSetFolder(fHandle, [fIncompleteFolder UTF8String]);287 264 } 288 265 … … 634 611 - (void) resetCache 635 612 { 613 #warning look over 636 614 BOOL paused = [self isPaused]; 637 615 638 616 if (!paused) 639 617 tr_torrentStop(fHandle); 640 tr_torrentRe moveFastResume(fHandle);618 tr_torrentRecheck(fHandle); 641 619 if (!paused) 642 620 tr_torrentStart(fHandle); … … 818 796 fIncompleteFolder = nil; 819 797 } 820 [self setDownloadFolder: folder];798 [self changeDownloadFolder: folder]; 821 799 822 800 [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateInfoSettings" object: nil]; … … 929 907 NSString * folder = [[openPanel filenames] objectAtIndex: 0]; 930 908 if (fUseIncompleteFolder) 931 [self setIncompleteFolder: folder];909 [self changeDownloadFolder: folder]; 932 910 else 933 [self setDownloadFolder: folder];911 [self changeDownloadFolder: folder]; 934 912 935 913 [self startTransfer]; … … 1498 1476 - (id) initWithHash: (NSString *) hashString path: (NSString *) path lib: (tr_handle_t *) lib 1499 1477 publicTorrent: (NSNumber *) publicTorrent 1478 downloadFolder: (NSString *) downloadFolder 1479 useIncompleteFolder: (NSNumber *) useIncompleteFolder incompleteFolder: (NSString *) incompleteFolder 1500 1480 dateAdded: (NSDate *) dateAdded dateCompleted: (NSDate *) dateCompleted 1501 1481 dateActivity: (NSDate *) dateActivity … … 1520 1500 if (fPublicTorrent) 1521 1501 fPublicTorrentLocation = [path retain]; 1522 1502 1503 fDownloadFolder = downloadFolder ? downloadFolder : [fDefaults stringForKey: @"DownloadFolder"]; 1504 fDownloadFolder = [[fDownloadFolder stringByExpandingTildeInPath] retain]; 1505 1506 fUseIncompleteFolder = useIncompleteFolder ? [useIncompleteFolder boolValue] 1507 : [fDefaults boolForKey: @"UseIncompleteDownloadFolder"]; 1508 if (fUseIncompleteFolder) 1509 { 1510 fIncompleteFolder = incompleteFolder ? incompleteFolder : [fDefaults stringForKey: @"IncompleteDownloadFolder"]; 1511 fIncompleteFolder = [[fIncompleteFolder stringByExpandingTildeInPath] retain]; 1512 } 1513 NSString * currentDownloadFolder = [self shouldUseIncompleteFolder] ? fIncompleteFolder : fDownloadFolder; 1514 1523 1515 int error; 1524 1516 if (hashString) 1525 fHandle = tr_torrentInitSaved(fLib, [hashString UTF8String], TR_FLAG_SAVE, & error);1517 fHandle = tr_torrentInitSaved(fLib, [hashString UTF8String], [currentDownloadFolder UTF8String], TR_FLAG_SAVE, & error); 1526 1518 1527 1519 if (!fHandle && path) 1528 fHandle = tr_torrentInit(fLib, [path UTF8String], NULL, TR_FLAG_SAVE, & error);1520 fHandle = tr_torrentInit(fLib, [path UTF8String], [currentDownloadFolder UTF8String], TR_FLAG_SAVE, & error); 1529 1521 1530 1522 if (!fHandle) … … 1716 1708 } 1717 1709 1710 - (BOOL) shouldUseIncompleteFolder 1711 { 1712 return fUseIncompleteFolder && 1713 ![[NSFileManager defaultManager] fileExistsAtPath: [fDownloadFolder stringByAppendingPathComponent: [self name]]]; 1714 } 1715 1716 - (void) updateDownloadFolder 1717 { 1718 NSString * folder = [self shouldUseIncompleteFolder] ? fIncompleteFolder : fDownloadFolder; 1719 tr_torrentSetFolder(fHandle, [folder UTF8String]); 1720 } 1721 1718 1722 #warning move? 1719 1723 - (NSImage *) advancedBar
Note: See TracChangeset
for help on using the changeset viewer.