1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 01:03:01 +00:00

#2287 Remove options to delete torrent file when removing, and remove internal storing of torrent file location

This commit is contained in:
Mitchell Livingston 2009-07-20 00:40:01 +00:00
parent 30502116f6
commit 91bb087731
5 changed files with 36 additions and 100 deletions

View file

@ -40,7 +40,7 @@
Controller * fController;
Torrent * fTorrent;
NSString * fDestination;
NSString * fDestination, * fTorrentFile;
BOOL fLockDestination;
BOOL fDeleteTorrent, fDeleteEnable;
@ -50,7 +50,8 @@
}
- (id) initWithTorrent: (Torrent *) torrent destination: (NSString *) path lockDestination: (BOOL) lockDestination
controller: (Controller *) controller deleteTorrent: (torrentFileState) deleteTorrent;
controller: (Controller *) controller torrentFile: (NSString *) torrentFile
deleteTorrent: (BOOL) deleteTorrent canToggleDelete: (BOOL) canToggleDelete;
- (Torrent *) torrent;

View file

@ -49,20 +49,21 @@
@implementation AddWindowController
- (id) initWithTorrent: (Torrent *) torrent destination: (NSString *) path lockDestination: (BOOL) lockDestination
controller: (Controller *) controller deleteTorrent: (torrentFileState) deleteTorrent
controller: (Controller *) controller torrentFile: (NSString *) torrentFile
deleteTorrent: (BOOL) deleteTorrent canToggleDelete: (BOOL) canToggleDelete
{
if ((self = [super initWithWindowNibName: @"AddWindow"]))
{
fTorrent = torrent;
if (path)
fDestination = [[path stringByExpandingTildeInPath] retain];
fLockDestination = lockDestination;
fController = controller;
fDeleteTorrent = deleteTorrent == TORRENT_FILE_DELETE || (deleteTorrent == TORRENT_FILE_DEFAULT
&& [[NSUserDefaults standardUserDefaults] boolForKey: @"DeleteOriginalTorrent"]);
fDeleteEnable = deleteTorrent == TORRENT_FILE_DEFAULT;
fTorrentFile = [[torrentFile stringByExpandingTildeInPath] retain];
fDeleteTorrent = deleteTorrent;
fDeleteEnable = canToggleDelete;
fGroupValue = [torrent groupValue];
}
@ -238,8 +239,8 @@
[fTorrent setWaitToStart: [fStartCheck state] == NSOnState];
[fTorrent setGroupValue: fGroupValue];
if ([fDeleteCheck state] == NSOnState)
[fTorrent trashTorrent];
if (fTorrentFile && [fDeleteCheck state] == NSOnState)
[Torrent trashFile: fTorrentFile];
[fFileController setTorrent: nil]; //avoid a crash when window tries to update

View file

@ -776,17 +776,18 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
return;
}
torrentFileState deleteTorrentFile;
BOOL deleteTorrentFile, canToggleDelete = NO;
switch (type)
{
case ADD_CREATED:
deleteTorrentFile = TORRENT_FILE_SAVE;
deleteTorrentFile = NO;
break;
case ADD_URL:
deleteTorrentFile = TORRENT_FILE_DELETE;
deleteTorrentFile = YES;
break;
default:
deleteTorrentFile = TORRENT_FILE_DEFAULT;
deleteTorrentFile = [fDefaults boolForKey: @"DeleteOriginalTorrent"];
canToggleDelete = YES;
}
tr_info info;
@ -838,7 +839,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
Torrent * torrent;
if (!(torrent = [[Torrent alloc] initWithPath: torrentPath location: location
deleteTorrentFile: showWindow ? TORRENT_FILE_SAVE : deleteTorrentFile lib: fLib]))
deleteTorrentFile: showWindow ? NO : deleteTorrentFile lib: fLib]))
continue;
//change the location if the group calls for it (this has to wait until after the torrent is create)
@ -859,7 +860,8 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
if (showWindow || !location)
{
AddWindowController * addController = [[AddWindowController alloc] initWithTorrent: torrent destination: location
lockDestination: lockDestination controller: self deleteTorrent: deleteTorrentFile];
lockDestination: lockDestination controller: self torrentFile: torrentPath
deleteTorrent: deleteTorrentFile canToggleDelete: canToggleDelete];
[addController showWindow: self];
}
else

View file

@ -27,13 +27,6 @@
@class FileListNode;
typedef enum
{
TORRENT_FILE_DELETE,
TORRENT_FILE_SAVE,
TORRENT_FILE_DEFAULT
} torrentFileState;
#define STAT_TIME_NONE -1
#define STAT_TIME_NOW -2
@ -48,9 +41,6 @@ typedef enum
BOOL fUseIncompleteFolder;
NSString * fDownloadFolder, * fIncompleteFolder;
BOOL fPublicTorrent;
NSString * fPublicTorrentLocation;
NSUserDefaults * fDefaults;
NSImage * fIcon;
@ -72,7 +62,7 @@ typedef enum
NSDictionary * fQuickPauseDict;
}
- (id) initWithPath: (NSString *) path location: (NSString *) location deleteTorrentFile: (torrentFileState) torrentDelete
- (id) initWithPath: (NSString *) path location: (NSString *) location deleteTorrentFile: (BOOL) torrentDelete
lib: (tr_session *) lib;
- (id) initWithTorrentStruct: (tr_torrent *) torrentStruct location: (NSString *) location lib: (tr_session *) lib;
- (id) initWithHistory: (NSDictionary *) history lib: (tr_session *) lib forcePause: (BOOL) pause;
@ -127,9 +117,8 @@ typedef enum
- (void) setPriority: (tr_priority_t) priority;
- (void) revealData;
- (void) revealPublicTorrent;
+ (void) trashFile: (NSString *) path;
- (void) trashData;
- (void) trashTorrent;
- (void) moveTorrentDataFileTo: (NSString *) folder;
- (void) copyTorrentFileTo: (NSString *) path;
@ -170,11 +159,8 @@ typedef enum
- (BOOL) privateTorrent;
- (NSString *) torrentLocation;
- (NSString *) publicTorrentLocation;
- (NSString *) dataLocation;
- (BOOL) publicTorrent;
- (CGFloat) progress;
- (CGFloat) progressDone;
- (CGFloat) progressLeft;

View file

@ -31,7 +31,6 @@
@interface Torrent (Private)
- (id) initWithPath: (NSString *) path hash: (NSString *) hashString torrentStruct: (tr_torrent *) torrentStruct lib: (tr_session *) lib
publicTorrent: (NSNumber *) publicTorrent publicTorrentLocation: (NSString *) publicTorrentLoc
downloadFolder: (NSString *) downloadFolder
useIncompleteFolder: (NSNumber *) useIncompleteFolder incompleteFolder: (NSString *) incompleteFolder
waitToStart: (NSNumber *) waitToStart
@ -55,8 +54,6 @@
- (void) updateAllTrackers: (NSMutableArray *) trackers;
+ (void) trashFile: (NSString *) path;
- (void) setTimeMachineExclude: (BOOL) exclude forPath: (NSString *) path;
@end
@ -80,28 +77,18 @@ int trashDataFile(const char * filename)
@implementation Torrent
- (id) initWithPath: (NSString *) path location: (NSString *) location deleteTorrentFile: (torrentFileState) torrentDelete
- (id) initWithPath: (NSString *) path location: (NSString *) location deleteTorrentFile: (BOOL) torrentDelete
lib: (tr_session *) lib
{
self = [self initWithPath: path hash: nil torrentStruct: NULL lib: lib
publicTorrent: torrentDelete != TORRENT_FILE_DEFAULT ? [NSNumber numberWithBool: torrentDelete == TORRENT_FILE_SAVE] : nil
publicTorrentLocation: path
downloadFolder: location
useIncompleteFolder: nil incompleteFolder: nil
waitToStart: nil groupValue: nil addedTrackers: nil];
if (self)
{
//if the public and private torrent files are the same, then there is no public torrent
if ([[self torrentLocation] isEqualToString: path])
{
fPublicTorrent = NO;
[fPublicTorrentLocation release];
fPublicTorrentLocation = nil;
}
else if (!fPublicTorrent)
if (torrentDelete && [[self torrentLocation] isEqualToString: path])
[Torrent trashFile: path];
else;
}
return self;
}
@ -109,7 +96,6 @@ int trashDataFile(const char * filename)
- (id) initWithTorrentStruct: (tr_torrent *) torrentStruct location: (NSString *) location lib: (tr_session *) lib
{
self = [self initWithPath: nil hash: nil torrentStruct: torrentStruct lib: lib
publicTorrent: [NSNumber numberWithBool: NO] publicTorrentLocation: nil
downloadFolder: location
useIncompleteFolder: nil incompleteFolder: nil
waitToStart: nil groupValue: nil addedTrackers: nil];
@ -122,8 +108,6 @@ int trashDataFile(const char * filename)
self = [self initWithPath: [history objectForKey: @"InternalTorrentPath"]
hash: [history objectForKey: @"TorrentHash"]
torrentStruct: NULL lib: lib
publicTorrent: [history objectForKey: @"PublicCopy"]
publicTorrentLocation: [history objectForKey: @"TorrentPath"]
downloadFolder: [history objectForKey: @"DownloadFolder"]
useIncompleteFolder: [history objectForKey: @"UseIncompleteFolder"]
incompleteFolder: [history objectForKey: @"IncompleteFolder"]
@ -173,7 +157,6 @@ int trashDataFile(const char * filename)
NSMutableDictionary * history = [NSMutableDictionary dictionaryWithObjectsAndKeys:
[self torrentLocation], @"InternalTorrentPath",
[self hashString], @"TorrentHash",
[NSNumber numberWithBool: fPublicTorrent], @"PublicCopy",
fDownloadFolder, @"DownloadFolder",
[NSNumber numberWithBool: fUseIncompleteFolder], @"UseIncompleteFolder",
[NSNumber numberWithBool: [self isActive]], @"Active",
@ -184,9 +167,6 @@ int trashDataFile(const char * filename)
if (fIncompleteFolder)
[history setObject: fIncompleteFolder forKey: @"IncompleteFolder"];
if (fPublicTorrent)
[history setObject: [self publicTorrentLocation] forKey: @"TorrentPath"];
return history;
}
@ -206,8 +186,6 @@ int trashDataFile(const char * filename)
[fDownloadFolder release];
[fIncompleteFolder release];
[fPublicTorrentLocation release];
[fIcon release];
[fFileList release];
@ -463,10 +441,19 @@ int trashDataFile(const char * filename)
[[NSWorkspace sharedWorkspace] selectFile: [self dataLocation] inFileViewerRootedAtPath: nil];
}
- (void) revealPublicTorrent
#warning should be somewhere else?
+ (void) trashFile: (NSString *) path
{
if (fPublicTorrent)
[[NSWorkspace sharedWorkspace] selectFile: fPublicTorrentLocation inFileViewerRootedAtPath: nil];
//attempt to move to trash
if (![[NSWorkspace sharedWorkspace] performFileOperation: NSWorkspaceRecycleOperation
source: [path stringByDeletingLastPathComponent] destination: @""
files: [NSArray arrayWithObject: [path lastPathComponent]] tag: nil])
{
//if cannot trash, just delete it (will work if it's on a remote volume)
NSError * error;
if (![[NSFileManager defaultManager] removeItemAtPath: path error: &error])
NSLog(@"Could not trash %@: %@", path, [error localizedDescription]);
}
}
- (void) trashData
@ -474,18 +461,6 @@ int trashDataFile(const char * filename)
tr_torrentDeleteLocalData(fHandle, trashDataFile);
}
- (void) trashTorrent
{
if (fPublicTorrent)
{
[Torrent trashFile: fPublicTorrentLocation];
[fPublicTorrentLocation release];
fPublicTorrentLocation = nil;
fPublicTorrent = NO;
}
}
- (void) moveTorrentDataFileTo: (NSString *) folder
{
NSString * oldFolder = [self downloadFolder];
@ -878,21 +853,11 @@ int trashDataFile(const char * filename)
return [NSString stringWithUTF8String: fInfo->torrent];
}
- (NSString *) publicTorrentLocation
{
return fPublicTorrentLocation;
}
- (NSString *) dataLocation
{
return [[self downloadFolder] stringByAppendingPathComponent: [self name]];
}
- (BOOL) publicTorrent
{
return fPublicTorrent;
}
- (CGFloat) progress
{
return fStat->percentComplete;
@ -1595,7 +1560,6 @@ int trashDataFile(const char * filename)
@implementation Torrent (Private)
- (id) initWithPath: (NSString *) path hash: (NSString *) hashString torrentStruct: (tr_torrent *) torrentStruct lib: (tr_session *) lib
publicTorrent: (NSNumber *) publicTorrent publicTorrentLocation: (NSString *) publicTorrentLoc
downloadFolder: (NSString *) downloadFolder
useIncompleteFolder: (NSNumber *) useIncompleteFolder incompleteFolder: (NSString *) incompleteFolder
waitToStart: (NSNumber *) waitToStart
@ -1606,10 +1570,6 @@ int trashDataFile(const char * filename)
fDefaults = [NSUserDefaults standardUserDefaults];
fPublicTorrent = publicTorrentLoc && (publicTorrent ? [publicTorrent boolValue] : ![fDefaults boolForKey: @"DeleteOriginalTorrent"]);
if (fPublicTorrent)
fPublicTorrentLocation = [publicTorrentLoc retain];
fDownloadFolder = downloadFolder ? downloadFolder : [fDefaults stringForKey: @"DownloadFolder"];
fDownloadFolder = [[fDownloadFolder stringByExpandingTildeInPath] retain];
@ -1952,20 +1912,6 @@ int trashDataFile(const char * filename)
tr_free(trackerStructs);
}
+ (void) trashFile: (NSString *) path
{
//attempt to move to trash
if (![[NSWorkspace sharedWorkspace] performFileOperation: NSWorkspaceRecycleOperation
source: [path stringByDeletingLastPathComponent] destination: @""
files: [NSArray arrayWithObject: [path lastPathComponent]] tag: nil])
{
//if cannot trash, just delete it (will work if it's on a remote volume)
NSError * error;
if (![[NSFileManager defaultManager] removeItemAtPath: path error: &error])
NSLog(@"Could not trash %@: %@", path, [error localizedDescription]);
}
}
- (void) setTimeMachineExclude: (BOOL) exclude forPath: (NSString *) path
{
CSBackupSetItemExcluded((CFURLRef)[NSURL fileURLWithPath: path], exclude, true);