Changeset 2209


Ignore:
Timestamp:
Jun 27, 2007, 10:12:10 PM (15 years ago)
Author:
livings124
Message:

commit my current work...still doesn't compile (calls some non-existent functions :))

Location:
trunk/macosx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r2205 r2209  
    708708    while ((torrentPath = [enumerator nextObject]))
    709709    {
    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]))
    711719            continue;
    712720       
     
    714722        [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: [NSURL fileURLWithPath: torrentPath]];
    715723       
    716         NSString * folder;
    717         if (path)
    718             folder = path;
    719         else if ([downloadChoice isEqualToString: @"Constant"])
    720             folder = [[fDefaults stringForKey: @"DownloadFolder"] stringByExpandingTildeInPath];
    721         else
    722             folder = [torrentPath stringByDeletingLastPathComponent];
    723        
    724         [torrent setDownloadFolder: folder];
    725724        [torrent update];
    726        
    727725        [fTorrents addObject: torrent];
    728726        [torrent release];
     
    773771- (void) openFilesAsk: (NSMutableArray *) files forceDeleteTorrent: (BOOL) delete
    774772{
     773    //determine the next file that can be opened
    775774    NSString * torrentPath;
    776     tr_torrent_t * tempTor;
    777     int error;
    778    
    779     //determine next file that can be opened
     775    int canAdd;
    780776    do
    781777    {
     
    789785   
    790786        torrentPath = [[files objectAtIndex: 0] retain];
    791         tempTor = tr_torrentInit(fLib, [torrentPath UTF8String], NULL, 0, &error);
    792        
    793787        [files removeObjectAtIndex: 0];
    794     } while (!tempTor);
     788    } while (tr_torrentCouldBeAdded(fLib, [torrentPath UTF8String]) != TR_OK);
    795789
    796790    NSOpenPanel * panel = [NSOpenPanel openPanel];
     
    802796    [panel setCanCreateDirectories: YES];
    803797
    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 \"%@\"",
    805800                        "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 "];
    807803   
    808804    NSDictionary * dictionary = [[NSDictionary alloc] initWithObjectsAndKeys: torrentPath, @"Path",
    809805                                    files, @"Files", [NSNumber numberWithBool: delete], @"Delete", nil];
    810806    [torrentPath release];
    811 
    812     tr_torrentClose(tempTor);
     807   
    813808    [panel beginSheetForDirectory: nil file: nil types: nil modalForWindow: fWindow modalDelegate: self
    814809            didEndSelector: @selector(folderChoiceClosed:returnCode:contextInfo:) contextInfo: dictionary];
     
    820815    {
    821816        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];
    824820       
    825821        //add it to the "File > Open Recent" menu
    826822        [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL: [NSURL fileURLWithPath: torrentPath]];
    827823       
    828         [torrent setDownloadFolder: [[openPanel filenames] objectAtIndex: 0]];
    829824        [torrent update];
    830        
    831825        [fTorrents addObject: torrent];
    832826        [torrent release];
     
    20242018        [self openFiles: newNames];
    20252019   
    2026     //create temporary torrents to check if an import fails because of an error
     2020    //check if an import fails because of an error so it can be tried again
    20272021    enumerator = [newNames objectEnumerator];
    2028     int error;
     2022    int canAdd;
    20292023    while ((file = [enumerator nextObject]))
    20302024    {
    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]];
    20382028    }
    20392029   
     
    21562146        NSEnumerator * enumerator = [files objectEnumerator];
    21572147        NSString * file;
    2158         tr_torrent_t * tempTor;
    21592148        BOOL torrent = NO;
     2149        int canAdd;
    21602150        while ((file = [enumerator nextObject]))
    21612151        {
    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)
    21642154            {
    2165                 tr_torrentClose(tempTor);
    2166                
    21672155                if (!fOverlayWindow)
    21682156                    fOverlayWindow = [[DragOverlayWindow alloc] initWithLib: fLib forWindow: fWindow];
     
    21712159                return NSDragOperationCopy;
    21722160            }
    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;
    21782164        }
    21792165       
     
    22232209        NSString * file;
    22242210        tr_torrent_t * tempTor;
     2211        int canAdd;
    22252212        while ((file = [enumerator nextObject]))
    22262213        {
    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)
    22292216            {
    22302217                tr_torrentClose(tempTor);
     
    22332220                torrent = YES;
    22342221            }
    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;
    22402225        }
    22412226       
  • trunk/macosx/Torrent.h

    r2172 r2209  
    7171}
    7272
    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;
    7474- (id) initWithHistory: (NSDictionary *) history lib: (tr_handle_t *) lib;
    7575
    7676- (NSDictionary *) history;
    7777
    78 - (void) setIncompleteFolder: (NSString *) folder;
    79 - (void) setDownloadFolder: (NSString *) folder;
    80 - (void) updateDownloadFolder;
     78- (void) changeIncompleteDownloadFolder: (NSString *) folder;
     79- (void) changeDownloadFolder: (NSString *) folder;
    8180- (NSString *) downloadFolder;
    8281
     
    8786- (NSDictionary *) infoForCurrentView;
    8887
    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;
    116114
    117115- (void) updateSpeedSetting;
     
    131129- (BOOL) alertForMoveFolderAvailable;
    132130
    133 - (NSImage *)   icon;
    134 - (NSImage *)   iconFlipped;
    135 - (NSImage *)   iconSmall;
     131- (NSImage *) icon;
     132- (NSImage *) iconFlipped;
     133- (NSImage *) iconSmall;
    136134
    137135- (NSString *) name;
    138 - (uint64_t)   size;
     136- (uint64_t) size;
    139137- (NSString *) trackerAddress;
    140138- (NSString *) trackerAddressAnnounce;
     
    142140- (NSString *) comment;
    143141- (NSString *) creator;
    144 - (NSDate *)   dateCreated;
    145 
    146 - (int)        pieceSize;
    147 - (int)        pieceCount;
     142- (NSDate *) dateCreated;
     143
     144- (int) pieceSize;
     145- (int) pieceCount;
    148146- (NSString *) hashString;
    149 - (BOOL)       privateTorrent;
     147- (BOOL) privateTorrent;
    150148
    151149- (NSString *) torrentLocation;
  • trunk/macosx/Torrent.m

    r2205 r2209  
    3737- (id) initWithHash: (NSString *) hashString path: (NSString *) path lib: (tr_handle_t *) lib
    3838        publicTorrent: (NSNumber *) publicTorrent
     39        downloadFolder: (NSString *) downloadFolder
     40        useIncompleteFolder: (NSNumber *) useIncompleteFolder incompleteFolder: (NSString *) incompleteFolder
    3941        dateAdded: (NSDate *) dateAdded dateCompleted: (NSDate *) dateCompleted
    4042        dateActivity: (NSDate *) dateActivity
     
    4850- (void) historyFilePriorities: (NSMutableArray *) history forItems: (NSArray *) items;
    4951
     52- (BOOL) shouldUseIncompleteFolder;
     53- (void) updateDownloadFolder;
     54
    5055- (void) createFileListShouldDownload: (NSArray *) filesShouldDownload priorities: (NSArray *) filePriorities;
    5156- (void) insertPath: (NSMutableArray *) components forSiblings: (NSMutableArray *) siblings
     
    7176                kWhite = BE(0xFFFFFFFF); //255, 255, 255
    7277
    73 - (id) initWithPath: (NSString *) path forceDeleteTorrent: (BOOL) delete lib: (tr_handle_t *) lib
     78- (id) initWithPath: (NSString *) path location: (NSString *) location forceDeleteTorrent: (BOOL) delete lib: (tr_handle_t *) lib
    7479{
    7580    self = [self initWithHash: nil path: path lib: lib
    7681            publicTorrent: delete ? [NSNumber numberWithBool: NO] : nil
     82            downloadFolder: location
     83            useIncompleteFolder: nil incompleteFolder: nil
    7784            dateAdded: nil dateCompleted: nil
    7885            dateActivity: nil
     
    8794    if (self)
    8895    {
    89         if ((fUseIncompleteFolder = [fDefaults boolForKey: @"UseIncompleteDownloadFolder"]))
    90             fIncompleteFolder = [[[fDefaults stringForKey: @"IncompleteDownloadFolder"] stringByExpandingTildeInPath] retain];
    91        
    9296        if (!fPublicTorrent)
    9397            [self trashFile: path];
     
    101105                path: [history objectForKey: @"TorrentPath"] lib: lib
    102106                publicTorrent: [history objectForKey: @"PublicCopy"]
     107                downloadFolder: [history objectForKey: @"DownloadFolder"]
     108                useIncompleteFolder: [history objectForKey: @"UseIncompleteFolder"]
     109                incompleteFolder: [history objectForKey: @"IncompleteFolder"]
    103110                dateAdded: [history objectForKey: @"Date"]
    104111                                dateCompleted: [history objectForKey: @"DateCompleted"]
     
    119126    if (self)
    120127    {
    121         //download folders
    122         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         else
    136             fUseIncompleteFolder = NO;
    137        
    138         [self updateDownloadFolder];
    139        
    140128        //start transfer
    141129        BOOL start = YES;
     
    164152                    fDownloadFolder, @"DownloadFolder",
    165153                    [NSNumber numberWithBool: fUseIncompleteFolder], @"UseIncompleteFolder",
     154                    fIncompleteFolder, @"IncompleteFolder",
    166155                    [NSNumber numberWithBool: [self isActive]], @"Active",
    167156                    fDateAdded, @"Date",
     
    191180    [self historyFilePriorities: filePriorities forItems: fFileList];
    192181    [history setObject: filePriorities forKey: @"FilePriorities"];
    193    
    194     if (fUseIncompleteFolder)
    195         [history setObject: fIncompleteFolder forKey: @"IncompleteFolder"];
    196182
    197183    if (fPublicTorrent)
     
    204190                [history setObject: fDateCompleted forKey: @"DateCompleted"];
    205191   
    206     NSDate * dateCompleted = [self dateActivity];
    207     if (dateCompleted)
    208                 [history setObject: dateCompleted forKey: @"DateActivity"];
     192    NSDate * dateActivity = [self dateActivity];
     193    if (dateActivity)
     194                [history setObject: dateActivity forKey: @"DateActivity"];
    209195       
    210196    return history;
     
    254240}
    255241
    256 - (void) setIncompleteFolder: (NSString *) folder
     242- (void) changeIncompleteDownloadFolder: (NSString *) folder
    257243{
    258244    fUseIncompleteFolder = folder != nil;
     
    269255}
    270256
    271 - (void) setDownloadFolder: (NSString *) folder
     257- (void) changeDownloadFolder: (NSString *) folder
    272258{
    273259    if (fDownloadFolder)
     
    276262   
    277263    [self updateDownloadFolder];
    278 }
    279 
    280 - (void) updateDownloadFolder
    281 {
    282     if (!fUseIncompleteFolder || [[NSFileManager defaultManager] fileExistsAtPath:
    283                                     [fDownloadFolder stringByAppendingPathComponent: [self name]]])
    284         tr_torrentSetFolder(fHandle, [fDownloadFolder UTF8String]);
    285     else
    286         tr_torrentSetFolder(fHandle, [fIncompleteFolder UTF8String]);
    287264}
    288265
     
    634611- (void) resetCache
    635612{
     613    #warning look over
    636614    BOOL paused = [self isPaused];
    637615   
    638616    if (!paused)
    639617        tr_torrentStop(fHandle);
    640     tr_torrentRemoveFastResume(fHandle);
     618    tr_torrentRecheck(fHandle);
    641619    if (!paused)
    642620        tr_torrentStart(fHandle);
     
    818796                fIncompleteFolder = nil;
    819797            }
    820             [self setDownloadFolder: folder];
     798            [self changeDownloadFolder: folder];
    821799           
    822800            [[NSNotificationCenter defaultCenter] postNotificationName: @"UpdateInfoSettings" object: nil];
     
    929907    NSString * folder = [[openPanel filenames] objectAtIndex: 0];
    930908    if (fUseIncompleteFolder)
    931         [self setIncompleteFolder: folder];
     909        [self changeDownloadFolder: folder];
    932910    else
    933         [self setDownloadFolder: folder];
     911        [self changeDownloadFolder: folder];
    934912   
    935913    [self startTransfer];
     
    14981476- (id) initWithHash: (NSString *) hashString path: (NSString *) path lib: (tr_handle_t *) lib
    14991477        publicTorrent: (NSNumber *) publicTorrent
     1478        downloadFolder: (NSString *) downloadFolder
     1479        useIncompleteFolder: (NSNumber *) useIncompleteFolder incompleteFolder: (NSString *) incompleteFolder
    15001480        dateAdded: (NSDate *) dateAdded dateCompleted: (NSDate *) dateCompleted
    15011481        dateActivity: (NSDate *) dateActivity
     
    15201500    if (fPublicTorrent)
    15211501        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   
    15231515    int error;
    15241516    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);
    15261518   
    15271519    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);
    15291521
    15301522    if (!fHandle)
     
    17161708}
    17171709
     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
    17181722#warning move?
    17191723- (NSImage *) advancedBar
Note: See TracChangeset for help on using the changeset viewer.