From abf1349f91bb5921f09f8287bc70225445525d23 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Wed, 18 Jun 2008 16:25:30 +0000 Subject: [PATCH] #562 display an error message when opening broken torrent file --- macosx/Controller.h | 1 + macosx/Controller.m | 45 +++++++++++++++++++++++++--- macosx/CreatorWindowController.m | 3 +- macosx/Defaults.plist | 2 ++ macosx/English.lproj/PrefsWindow.xib | 25 +++++++--------- macosx/PrefsController.m | 1 + macosx/TorrentTableView.m | 4 ++- 7 files changed, 60 insertions(+), 21 deletions(-) diff --git a/macosx/Controller.h b/macosx/Controller.h index 17b625df4..41ecbcd50 100644 --- a/macosx/Controller.h +++ b/macosx/Controller.h @@ -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; diff --git a/macosx/Controller.m b/macosx/Controller.m index 64acc9dfe..f58a4f872 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -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 diff --git a/macosx/CreatorWindowController.m b/macosx/CreatorWindowController.m index e1c496984..44aa7fcd0 100644 --- a/macosx/CreatorWindowController.m +++ b/macosx/CreatorWindowController.m @@ -193,8 +193,7 @@ if (fInfo) tr_metaInfoBuilderFree(fInfo); - if (fTimer) - [fTimer invalidate]; + [fTimer invalidate]; [super dealloc]; } diff --git a/macosx/Defaults.plist b/macosx/Defaults.plist index a5caa5bd5..49a71d8d0 100644 --- a/macosx/Defaults.plist +++ b/macosx/Defaults.plist @@ -172,6 +172,8 @@ WarningFolderDataSameName + WarningInvalidOpen + WarningRemainingSpace WarningRemoveBuiltInTracker diff --git a/macosx/English.lproj/PrefsWindow.xib b/macosx/English.lproj/PrefsWindow.xib index 9ef95a415..e001c5a02 100644 --- a/macosx/English.lproj/PrefsWindow.xib +++ b/macosx/English.lproj/PrefsWindow.xib @@ -8,7 +8,7 @@ 352.00 YES - + YES @@ -359,7 +359,7 @@ NSResponder - + 256 YES @@ -372,7 +372,7 @@ YES - + 256 YES @@ -843,6 +843,7 @@ {{10, 33}, {489, 226}} + Adding @@ -850,7 +851,7 @@ - + 256 YES @@ -1494,25 +1495,25 @@ {{10, 33}, {489, 226}} - Management - + 0 YES YES YES - + {535, 288} + NSView NSResponder @@ -3025,7 +3026,7 @@ AAABAAAAAQ NSResponder - + 256 YES @@ -3190,13 +3191,13 @@ AAABAAAAAQ 256 - {{99, 351}, {342, 14}} + {{99, 351}, {285, 14}} YES 67239424 272760832 - This will allow requests from transmission-remote, etc. + This allows requests from transmission-remote, etc. @@ -3393,7 +3394,6 @@ AAABAAAAAQ {{1, 17}, {332, 95}} - 4 @@ -3426,7 +3426,6 @@ AAABAAAAAQ {{1, 0}, {332, 17}} - 4 @@ -3435,7 +3434,6 @@ AAABAAAAAQ {{102, 63}, {349, 113}} - 18 @@ -3537,7 +3535,6 @@ AAABAAAAAQ {535, 403} - NSView NSResponder diff --git a/macosx/PrefsController.m b/macosx/PrefsController.m index bad52b686..cd3a3a8c2 100644 --- a/macosx/PrefsController.m +++ b/macosx/PrefsController.m @@ -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 diff --git a/macosx/TorrentTableView.m b/macosx/TorrentTableView.m index 026bc9a47..984c620fc 100644 --- a/macosx/TorrentTableView.m +++ b/macosx/TorrentTableView.m @@ -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];