Skip to content

Commit

Permalink
Warn when signing files > SIZE_WARNING_LEVEL_IN_MB (currently '10')
Browse files Browse the repository at this point in the history
  • Loading branch information
the-kenny committed Apr 22, 2011
1 parent 99202b4 commit c1fe745
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions Source/GPGServices.m
Expand Up @@ -17,6 +17,8 @@
#import "ZipKit/ZKArchive.h"
#import "NSPredicate+negate.h"

#define SIZE_WARNING_LEVEL_IN_MB 10

@implementation GPGServices

-(void)applicationDidFinishLaunching:(NSNotification *)aNotification
Expand Down Expand Up @@ -637,6 +639,20 @@ - (NSString*)detachedSignFile:(NSString*)file withKeys:(NSArray*)keys {
}

- (void)signFiles:(NSArray*)files {
long double megabytes = [[self sizeOfFiles:files] unsignedLongLongValue] / 1048576.0;

if(megabytes > SIZE_WARNING_LEVEL_IN_MB) {
int ret = [[NSAlert alertWithMessageText:@"Large File(s)"
defaultButton:@"Continue"
alternateButton:@"Cancel"
otherButton:nil
informativeTextWithFormat:@"Encryption will take a long time.\nPress 'Cancel' to abort."]
runModal];

if(ret == NSAlertAlternateReturn)
return;
}

GPGKey* chosenKey = [GPGServices myPrivateKey];

NSSet* availableKeys = [[GPGServices myPrivateKeys] filteredSetUsingPredicate:
Expand Down Expand Up @@ -718,7 +734,7 @@ - (void)encryptFiles:(NSArray*)files {
}

//GPGData* gpgData = nil;
double megabytes = 0;
long double megabytes = 0;
NSString* destination = nil;

NSFileManager* fmgr = [[[NSFileManager alloc] init] autorelease];
Expand Down Expand Up @@ -777,7 +793,7 @@ - (void)encryptFiles:(NSArray*)files {
NSLog(@"fileSize: %@Mb", [NSNumberFormatter localizedStringFromNumber:[NSNumber numberWithDouble:megabytes]
numberStyle:NSNumberFormatterDecimalStyle]);

if(megabytes > 10) {
if(megabytes > SIZE_WARNING_LEVEL_IN_MB) {
int ret = [[NSAlert alertWithMessageText:@"Large File(s)"
defaultButton:@"Continue"
alternateButton:@"Cancel"
Expand Down

0 comments on commit c1fe745

Please sign in to comment.