#562 display an error message when opening broken torrent file

This commit is contained in:
Mitchell Livingston 2008-06-18 16:25:30 +00:00
parent daa2c6fbd8
commit abf1349f91
7 changed files with 60 additions and 21 deletions

View File

@ -123,6 +123,7 @@ typedef enum
- (void) openFilesWithDict: (NSDictionary *) dictionary;
- (void) openShowSheet: (id) sender;
- (void) invalidOpenAlert: (NSString *) filename;
- (void) duplicateOpenAlert: (NSString *) name;
- (void) openURL: (NSURL *) torrentURL;

View File

@ -769,13 +769,24 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
//ensure torrent doesn't already exist
tr_ctor * ctor = tr_ctorNew(fLib);
tr_ctorSetMetainfoFromFile(ctor, [torrentPath UTF8String]);
if (tr_torrentParse(fLib, ctor, &info) == TR_EDUPLICATE)
int result = tr_torrentParse(fLib, ctor, &info);
if (result != TR_OK)
{
[self duplicateOpenAlert: [NSString stringWithUTF8String: info.name]];
if (result == TR_EDUPLICATE)
[self duplicateOpenAlert: [NSString stringWithUTF8String: info.name]];
else if (result == TR_EINVALID)
{
if (type != ADD_AUTO)
[self invalidOpenAlert: [torrentPath lastPathComponent]];
}
else //this shouldn't happen
NSLog(@"Unknown error when attempting to open \"%@\"", torrentPath);
tr_ctorFree(ctor);
tr_metainfoFree(&info);
continue;
}
tr_ctorFree(ctor);
//determine download location
@ -915,6 +926,32 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
}
}
- (void) invalidOpenAlert: (NSString *) filename
{
if (![fDefaults boolForKey: @"WarningInvalidOpen"])
return;
NSAlert * alert = [[NSAlert alloc] init];
[alert setMessageText: [NSString stringWithFormat: NSLocalizedString(@"\"%@\" is not a valid torrent file.",
"Open invalid alert -> title"), filename]];
[alert setInformativeText:
NSLocalizedString(@"The torrent file cannot be opened because it contains invalid data.",
"Open invalid alert -> message")];
[alert setAlertStyle: NSWarningAlertStyle];
[alert addButtonWithTitle: NSLocalizedString(@"OK", "Open invalid alert -> button")];
BOOL onLeopard = [NSApp isOnLeopardOrBetter];
if (onLeopard)
[alert setShowsSuppressionButton: YES];
else
[alert addButtonWithTitle: NSLocalizedString(@"Don't Alert Again", "Open duplicate alert -> button")];
NSInteger result = [alert runModal];
if ((onLeopard ? [[alert suppressionButton] state] == NSOnState : result == NSAlertSecondButtonReturn))
[fDefaults setBool: NO forKey: @"WarningInvalidOpen"];
[alert release];
}
- (void) duplicateOpenAlert: (NSString *) name
{
if (![fDefaults boolForKey: @"WarningDuplicate"])
@ -1450,7 +1487,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
{
//set rates
float downloadRate, uploadRate;
tr_sessionGetSpeed(fLib, & downloadRate, & uploadRate);
tr_sessionGetSpeed(fLib, &downloadRate, &uploadRate);
[fTotalDLField setStringValue: [NSString stringForSpeed: downloadRate]];
[fTotalULField setStringValue: [NSString stringForSpeed: uploadRate]];
@ -1466,7 +1503,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
else
tr_sessionGetStats(fLib, &stats);
statusString = [NSString stringWithFormat: @"%@: %@", NSLocalizedString(@"Ratio", "status bar -> status label"),
statusString = [NSLocalizedString(@"Ratio", "status bar -> status label") stringByAppendingFormat: @": %@",
[NSString stringForRatio: stats.ratio]];
}
else //STATUS_TRANSFER_TOTAL or STATUS_TRANSFER_SESSION

View File

@ -193,8 +193,7 @@
if (fInfo)
tr_metaInfoBuilderFree(fInfo);
if (fTimer)
[fTimer invalidate];
[fTimer invalidate];
[super dealloc];
}

View File

@ -172,6 +172,8 @@
<true/>
<key>WarningFolderDataSameName</key>
<true/>
<key>WarningInvalidOpen</key>
<true/>
<key>WarningRemainingSpace</key>
<true/>
<key>WarningRemoveBuiltInTracker</key>

View File

@ -8,7 +8,7 @@
<string key="IBDocument.HIToolboxVersion">352.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="1481"/>
<integer value="41"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@ -359,7 +359,7 @@
<string key="NSExtension">NSResponder</string>
</object>
<object class="NSCustomView" id="314557528">
<nil key="NSNextResponder"/>
<reference key="NSNextResponder"/>
<int key="NSvFlags">256</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
@ -372,7 +372,7 @@
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSTabViewItem" id="73412354">
<object class="NSView" key="NSView" id="833882848">
<nil key="NSNextResponder"/>
<reference key="NSNextResponder" ref="463462813"/>
<int key="NSvFlags">256</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
@ -843,6 +843,7 @@
</object>
</object>
<string key="NSFrame">{{10, 33}, {489, 226}}</string>
<reference key="NSSuperview" ref="463462813"/>
</object>
<string key="NSLabel">Adding</string>
<reference key="NSColor" ref="977951849"/>
@ -850,7 +851,7 @@
</object>
<object class="NSTabViewItem" id="298493360">
<object class="NSView" key="NSView" id="159788047">
<reference key="NSNextResponder" ref="463462813"/>
<nil key="NSNextResponder"/>
<int key="NSvFlags">256</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
@ -1494,25 +1495,25 @@
</object>
</object>
<string key="NSFrame">{{10, 33}, {489, 226}}</string>
<reference key="NSSuperview" ref="463462813"/>
</object>
<string key="NSLabel">Management</string>
<reference key="NSColor" ref="977951849"/>
<reference key="NSTabView" ref="463462813"/>
</object>
</object>
<reference key="NSSelectedTabViewItem" ref="298493360"/>
<reference key="NSSelectedTabViewItem" ref="73412354"/>
<reference key="NSFont" ref="86725571"/>
<int key="NSTvFlags">0</int>
<bool key="NSAllowTruncatedLabels">YES</bool>
<bool key="NSDrawsBackground">YES</bool>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
<reference ref="159788047"/>
<reference ref="833882848"/>
</object>
</object>
</object>
<string key="NSFrameSize">{535, 288}</string>
<reference key="NSSuperview"/>
<string key="NSClassName">NSView</string>
<string key="NSExtension">NSResponder</string>
</object>
@ -3025,7 +3026,7 @@ AAABAAAAAQ</bytes>
<string key="NSExtension">NSResponder</string>
</object>
<object class="NSCustomView" id="810116101">
<reference key="NSNextResponder"/>
<nil key="NSNextResponder"/>
<int key="NSvFlags">256</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
@ -3190,13 +3191,13 @@ AAABAAAAAQ</bytes>
<object class="NSTextField" id="535988411">
<reference key="NSNextResponder" ref="810116101"/>
<int key="NSvFlags">256</int>
<string key="NSFrame">{{99, 351}, {342, 14}}</string>
<string key="NSFrame">{{99, 351}, {285, 14}}</string>
<reference key="NSSuperview" ref="810116101"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="644224844">
<int key="NSCellFlags">67239424</int>
<int key="NSCellFlags2">272760832</int>
<string key="NSContents">This will allow requests from transmission-remote, etc.</string>
<string key="NSContents">This allows requests from transmission-remote, etc.</string>
<reference key="NSSupport" ref="26"/>
<reference key="NSControlView" ref="535988411"/>
<reference key="NSBackgroundColor" ref="977951849"/>
@ -3393,7 +3394,6 @@ AAABAAAAAQ</bytes>
</object>
<string key="NSFrame">{{1, 17}, {332, 95}}</string>
<reference key="NSSuperview" ref="122119447"/>
<reference key="NSNextKeyView" ref="173651346"/>
<reference key="NSDocView" ref="173651346"/>
<reference key="NSBGColor" ref="729660797"/>
<int key="NScvFlags">4</int>
@ -3426,7 +3426,6 @@ AAABAAAAAQ</bytes>
</object>
<string key="NSFrame">{{1, 0}, {332, 17}}</string>
<reference key="NSSuperview" ref="122119447"/>
<reference key="NSNextKeyView" ref="520862816"/>
<reference key="NSDocView" ref="520862816"/>
<reference key="NSBGColor" ref="729660797"/>
<int key="NScvFlags">4</int>
@ -3435,7 +3434,6 @@ AAABAAAAAQ</bytes>
</object>
<string key="NSFrame">{{102, 63}, {349, 113}}</string>
<reference key="NSSuperview" ref="810116101"/>
<reference key="NSNextKeyView" ref="206862330"/>
<int key="NSsFlags">18</int>
<reference key="NSVScroller" ref="220703981"/>
<reference key="NSHScroller" ref="383062716"/>
@ -3537,7 +3535,6 @@ AAABAAAAAQ</bytes>
</object>
</object>
<string key="NSFrameSize">{535, 403}</string>
<reference key="NSSuperview"/>
<string key="NSClassName">NSView</string>
<string key="NSExtension">NSResponder</string>
</object>

View File

@ -582,6 +582,7 @@
[fDefaults setBool: YES forKey: @"WarningResetStats"];
[fDefaults setBool: YES forKey: @"WarningCreatorBlankAddress"];
[fDefaults setBool: YES forKey: @"WarningRemoveBuiltInTracker"];
[fDefaults setBool: YES forKey: @"WarningInvalidOpen"];
}
- (void) setCheckForUpdate: (id) sender

View File

@ -38,6 +38,8 @@
#define GROUP_SPEED_IMAGE_COLUMN_WIDTH 8.0
#define GROUP_RATIO_IMAGE_COLUMN_WIDTH 10.0
#define TOGGLE_PROGRESS_SECONDS 0.175
@interface TorrentTableView (Private)
- (BOOL) pointInControlRect: (NSPoint) point;
@ -850,7 +852,7 @@
for (i = 0.0625; i <= 1.0; i += 0.0625)
[progressMarks addObject: [NSNumber numberWithFloat: i]];
fPiecesBarAnimation = [[NSAnimation alloc] initWithDuration: 0.25 animationCurve: NSAnimationEaseIn];
fPiecesBarAnimation = [[NSAnimation alloc] initWithDuration: TOGGLE_PROGRESS_SECONDS animationCurve: NSAnimationEaseIn];
[fPiecesBarAnimation setAnimationBlockingMode: NSAnimationNonblocking];
[fPiecesBarAnimation setProgressMarks: progressMarks];
[fPiecesBarAnimation setDelegate: self];