Permalink
Browse files

Replace a lot of SPBeginAlertSheet()s with the more concise SPOnewayA…

…lertSheet()

This should also eliminate a few use-after-free crashes
  • Loading branch information...
dmoagx committed Oct 20, 2015
1 parent e12e3e8 commit 5357fd1375d19a6c5de96293b3899f430422a3c0
@@ -58,6 +58,12 @@ void SPBeginAlertSheet(
);
void SPOnewayAlertSheet(
NSString *title,
NSWindow *docWindow,
NSString *msg
);
void SPOnewayAlertSheetWithStyle(
NSString *title,
NSString *defaultButton,
NSWindow *docWindow,
@@ -143,6 +143,17 @@ + (void)beginWaitingAlertSheetWithTitle:(NSString *)title
@end
/**
* Shorthand for SPOnewayAlertSheetWithStyle() with defaultButton=nil and alertStyle=NSWarningAlertStyle
*/
void SPOnewayAlertSheet(
NSString *title,
NSWindow *docWindow,
NSString *msg)
{
SPOnewayAlertSheetWithStyle(title, nil, docWindow, msg, NSWarningAlertStyle);
}
/**
* A Send-and-forget variant for displaying alerts.
* It will queue the alert on the main thread and *always* immediately return.
@@ -151,7 +162,7 @@ + (void)beginWaitingAlertSheetWithTitle:(NSString *)title
* If nil is passed as the button title it will be changed to @"OK".
* If nil is passed as the window NSAlert will be modal
*/
void SPOnewayAlertSheet(
void SPOnewayAlertSheetWithStyle(
NSString *title,
NSString *defaultButton,
NSWindow *docWindow,
@@ -851,8 +851,7 @@ - (void)handleEventWithURL:(NSURL*)url
}
if(![status writeToFile:statusFileName atomically:YES encoding:NSUTF8StringEncoding error:nil]) {
NSBeep();
SPBeginAlertSheet(NSLocalizedString(@"BASH Error", @"bash error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self frontDocumentWindow], self, nil, nil,
NSLocalizedString(@"Status file for sequelpro url scheme command couldn't be written!", @"status file for sequelpro url scheme command couldn't be written error message"));
SPOnewayAlertSheet(NSLocalizedString(@"BASH Error", @"bash error"), [self frontDocumentWindow], NSLocalizedString(@"Status file for sequelpro url scheme command couldn't be written!", @"status file for sequelpro url scheme command couldn't be written error message"));
}
[result writeToFile:resultFileName atomically:YES encoding:NSUTF8StringEncoding error:nil];
return;
@@ -897,8 +896,11 @@ - (void)handleEventWithURL:(NSURL*)url
BOOL succeed = [status writeToFile:statusFileName atomically:YES encoding:NSUTF8StringEncoding error:nil];
if(!succeed) {
NSBeep();
SPBeginAlertSheet(NSLocalizedString(@"BASH Error", @"bash error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self frontDocumentWindow], self, nil, nil,
NSLocalizedString(@"Status file for sequelpro url scheme command couldn't be written!", @"status file for sequelpro url scheme command couldn't be written error message"));
SPOnewayAlertSheet(
NSLocalizedString(@"BASH Error", @"bash error"),
[self frontDocumentWindow],
NSLocalizedString(@"Status file for sequelpro url scheme command couldn't be written!", @"status file for sequelpro url scheme command couldn't be written error message")
);
}
return;
}
@@ -939,8 +941,11 @@ - (void)handleEventWithURL:(NSURL*)url
[cmdDict setObject:(passedProcessID)?:@"" forKey:@"id"];
[processDocument handleSchemeCommand:cmdDict];
} else {
SPBeginAlertSheet(NSLocalizedString(@"sequelpro URL Scheme Error", @"sequelpro url Scheme Error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [NSApp mainWindow], self, nil, nil,
[NSString stringWithFormat:@"%@%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [command description], NSLocalizedString(@"sequelpro URL scheme command not supported.", @"sequelpro URL scheme command not supported.")]);
SPOnewayAlertSheet(
NSLocalizedString(@"sequelpro URL Scheme Error", @"sequelpro url Scheme Error"),
[NSApp mainWindow],
[NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [command description], NSLocalizedString(@"sequelpro URL scheme command not supported.", @"sequelpro URL scheme command not supported.")]
);
// If command failed notify the file handle hand shake mechanism
NSString *out = @"1";
@@ -980,9 +985,11 @@ - (void)handleEventWithURL:(NSURL*)url
encoding:NSUTF8StringEncoding
error:nil];
SPBeginAlertSheet(NSLocalizedString(@"sequelpro URL Scheme Error", @"sequelpro url Scheme Error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [NSApp mainWindow], self, nil, nil,
[NSString stringWithFormat:@"%@%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [command description], NSLocalizedString(@"An error for sequelpro URL scheme command occurred. Probably no corresponding connection window found.", @"An error for sequelpro URL scheme command occurred. Probably no corresponding connection window found.")]);
SPOnewayAlertSheet(
NSLocalizedString(@"sequelpro URL Scheme Error", @"sequelpro url Scheme Error"),
[NSApp mainWindow],
[NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [command description], NSLocalizedString(@"An error for sequelpro URL scheme command occurred. Probably no corresponding connection window found.", @"An error for sequelpro URL scheme command occurred. Probably no corresponding connection window found.")]
);
usleep(5000);
[fm removeItemAtPath:[NSString stringWithFormat:@"%@%@", SPURLSchemeQueryResultStatusPathHeader, passedProcessID] error:nil];
@@ -993,8 +1000,11 @@ - (void)handleEventWithURL:(NSURL*)url
} else {
SPBeginAlertSheet(NSLocalizedString(@"sequelpro URL Scheme Error", @"sequelpro url Scheme Error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [NSApp mainWindow], self, nil, nil,
[NSString stringWithFormat:@"%@%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [command description], NSLocalizedString(@"An error occur while executing a scheme command. If the scheme command was invoked by a Bundle command, it could be that the command still runs. You can try to terminate it by pressing ⌘+. or via the Activities pane.", @"an error occur while executing a scheme command. if the scheme command was invoked by a bundle command, it could be that the command still runs. you can try to terminate it by pressing ⌘+. or via the activities pane.")]);
SPOnewayAlertSheet(
NSLocalizedString(@"sequelpro URL Scheme Error", @"sequelpro url Scheme Error"),
[NSApp mainWindow],
[NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [command description], NSLocalizedString(@"An error occur while executing a scheme command. If the scheme command was invoked by a Bundle command, it could be that the command still runs. You can try to terminate it by pressing ⌘+. or via the Activities pane.", @"an error occur while executing a scheme command. if the scheme command was invoked by a bundle command, it could be that the command still runs. you can try to terminate it by pressing ⌘+. or via the activities pane.")]
);
}
if(processDocument)
@@ -1141,8 +1151,11 @@ - (IBAction)executeBundleItemForApp:(id)sender
if(inputFileError != nil) {
NSString *errorMessage = [inputFileError localizedDescription];
SPBeginAlertSheet(NSLocalizedString(@"Bundle Error", @"bundle error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self frontDocumentWindow], self, nil, nil,
[NSString stringWithFormat:@"%@%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]);
SPOnewayAlertSheet(
NSLocalizedString(@"Bundle Error", @"bundle error"),
[self frontDocumentWindow],
[NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]
);
if (cmdData) [cmdData release];
return;
}
@@ -1235,8 +1248,11 @@ - (IBAction)executeBundleItemForApp:(id)sender
}
} else if([err code] != 9) { // Suppress an error message if command was killed
NSString *errorMessage = [err localizedDescription];
SPBeginAlertSheet(NSLocalizedString(@"BASH Error", @"bash error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [NSApp mainWindow], self, nil, nil,
[NSString stringWithFormat:@"%@%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]);
SPOnewayAlertSheet(
NSLocalizedString(@"BASH Error", @"bash error"),
[NSApp mainWindow],
[NSString stringWithFormat:@"%@ “%@”:\n%@", NSLocalizedString(@"Error for", @"error for message"), [cmdData objectForKey:@"name"], errorMessage]
);
}
}
@@ -191,8 +191,7 @@ - (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSSt
encoding:NSUTF8StringEncoding
error:&err];
if (err != nil) {
SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil,
[NSString stringWithFormat:@"%@", [err localizedDescription]]);
SPOnewayAlertSheet(NSLocalizedString(@"Error", @"error"), [self window], [NSString stringWithFormat:@"%@", [err localizedDescription]]);
}
}
}
@@ -183,21 +183,33 @@ - (IBAction)initiateConnection:(id)sender
// Ensure that host is not empty if this is a TCP/IP or SSH connection
if (([self type] == SPTCPIPConnection || [self type] == SPSSHTunnelConnection) && ![[self host] length]) {
SPBeginAlertSheet(NSLocalizedString(@"Insufficient connection details", @"insufficient details message"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [dbDocument parentWindow], self, nil, nil, NSLocalizedString(@"Insufficient details provided to establish a connection. Please enter at least the hostname.", @"insufficient details informative message"));
SPOnewayAlertSheet(
NSLocalizedString(@"Insufficient connection details", @"insufficient details message"),
[dbDocument parentWindow],
NSLocalizedString(@"Insufficient details provided to establish a connection. Please enter at least the hostname.", @"insufficient details informative message")
);
return;
}
// If SSH is enabled, ensure that the SSH host is not nil
if ([self type] == SPSSHTunnelConnection && ![[self sshHost] length]) {
SPBeginAlertSheet(NSLocalizedString(@"Insufficient connection details", @"insufficient details message"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [dbDocument parentWindow], self, nil, nil, NSLocalizedString(@"Insufficient details provided to establish a connection. Please enter the hostname for the SSH Tunnel, or disable the SSH Tunnel.", @"insufficient SSH tunnel details informative message"));
SPOnewayAlertSheet(
NSLocalizedString(@"Insufficient connection details", @"insufficient details message"),
[dbDocument parentWindow],
NSLocalizedString(@"Insufficient details provided to establish a connection. Please enter the hostname for the SSH Tunnel, or disable the SSH Tunnel.", @"insufficient SSH tunnel details informative message")
);
return;
}
// If an SSH key has been provided, verify it exists
if ([self type] == SPSSHTunnelConnection && sshKeyLocationEnabled && sshKeyLocation) {
if (![[NSFileManager defaultManager] fileExistsAtPath:[sshKeyLocation stringByExpandingTildeInPath]]) {
[self setSshKeyLocationEnabled:NSOffState];
SPBeginAlertSheet(NSLocalizedString(@"SSH Key not found", @"SSH key check error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [dbDocument parentWindow], self, nil, nil, NSLocalizedString(@"A SSH key location was specified, but no file was found in the specified location. Please re-select the key and try again.", @"SSH key not found message"));
SPOnewayAlertSheet(
NSLocalizedString(@"SSH Key not found", @"SSH key check error"),
[dbDocument parentWindow],
NSLocalizedString(@"A SSH key location was specified, but no file was found in the specified location. Please re-select the key and try again.", @"SSH key not found message")
);
return;
}
}
@@ -214,7 +226,11 @@ - (IBAction)initiateConnection:(id)sender
[self setSslKeyFileLocationEnabled:NSOffState];
[self setSslKeyFileLocation:nil];
SPBeginAlertSheet(NSLocalizedString(@"SSL Key File not found", @"SSL key file check error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [dbDocument parentWindow], self, nil, nil, NSLocalizedString(@"A SSL key file location was specified, but no file was found in the specified location. Please re-select the key file and try again.", @"SSL key file not found message"));
SPOnewayAlertSheet(
NSLocalizedString(@"SSL Key File not found", @"SSL key file check error"),
[dbDocument parentWindow],
NSLocalizedString(@"A SSL key file location was specified, but no file was found in the specified location. Please re-select the key file and try again.", @"SSL key file not found message")
);
return;
}
@@ -225,7 +241,11 @@ - (IBAction)initiateConnection:(id)sender
[self setSslCertificateFileLocationEnabled:NSOffState];
[self setSslCertificateFileLocation:nil];
SPBeginAlertSheet(NSLocalizedString(@"SSL Certificate File not found", @"SSL certificate file check error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [dbDocument parentWindow], self, nil, nil, NSLocalizedString(@"A SSL certificate location was specified, but no file was found in the specified location. Please re-select the certificate and try again.", @"SSL certificate file not found message"));
SPOnewayAlertSheet(
NSLocalizedString(@"SSL Certificate File not found", @"SSL certificate file check error"),
[dbDocument parentWindow],
NSLocalizedString(@"A SSL certificate location was specified, but no file was found in the specified location. Please re-select the certificate and try again.", @"SSL certificate file not found message")
);
return;
}
@@ -236,7 +256,11 @@ - (IBAction)initiateConnection:(id)sender
[self setSslCACertFileLocationEnabled:NSOffState];
[self setSslCACertFileLocation:nil];
SPBeginAlertSheet(NSLocalizedString(@"SSL Certificate Authority File not found", @"SSL certificate authority file check error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [dbDocument parentWindow], self, nil, nil, NSLocalizedString(@"A SSL Certificate Authority certificate location was specified, but no file was found in the specified location. Please re-select the Certificate Authority certificate and try again.", @"SSL CA certificate file not found message"));
SPOnewayAlertSheet(
NSLocalizedString(@"SSL Certificate Authority File not found", @"SSL certificate authority file check error"),
[dbDocument parentWindow],
NSLocalizedString(@"A SSL Certificate Authority certificate location was specified, but no file was found in the specified location. Please re-select the Certificate Authority certificate and try again.", @"SSL CA certificate file not found message")
);
return;
}
@@ -1224,17 +1248,21 @@ - (void)_saveCurrentDetailsCreatingNewFavorite:(BOOL)createNewFavorite validateD
// Ensure that host is not empty if this is a TCP/IP or SSH connection
if (validateDetails && ([self type] == SPTCPIPConnection || [self type] == SPSSHTunnelConnection) && ![[self host] length]) {
SPBeginAlertSheet(NSLocalizedString(@"Insufficient connection details", @"insufficient details message"),
NSLocalizedString(@"OK", @"OK button"), nil, nil, [dbDocument parentWindow], nil, nil, nil,
NSLocalizedString(@"Insufficient details provided to establish a connection. Please provide at least a host.", @"insufficient details informative message"));
SPOnewayAlertSheet(
NSLocalizedString(@"Insufficient connection details", @"insufficient details message"),
[dbDocument parentWindow],
NSLocalizedString(@"Insufficient details provided to establish a connection. Please provide at least a host.", @"insufficient details informative message")
);
return;
}
// If SSH is enabled, ensure that the SSH host is not nil
if (validateDetails && [self type] == SPSSHTunnelConnection && ![[self sshHost] length]) {
SPBeginAlertSheet(NSLocalizedString(@"Insufficient connection details", @"insufficient details message"),
NSLocalizedString(@"OK", @"OK button"), nil, nil, [dbDocument parentWindow], nil, nil, nil,
NSLocalizedString(@"Please enter the hostname for the SSH Tunnel, or disable the SSH Tunnel.", @"message of panel when ssh details are incomplete"));
SPOnewayAlertSheet(
NSLocalizedString(@"Insufficient connection details", @"insufficient details message"),
[dbDocument parentWindow],
NSLocalizedString(@"Please enter the hostname for the SSH Tunnel, or disable the SSH Tunnel.", @"message of panel when ssh details are incomplete")
);
return;
}
@@ -1488,7 +1516,7 @@ - (BOOL)_checkHost
[dbDocument parentWindow], // Window to attach to
self, // Modal delegate
@selector(localhostErrorSheetDidEnd:returnCode:contextInfo:), // Did end selector
nil, // Contextual info for selectors
NULL, // Contextual info for selectors
NSLocalizedString(@"To MySQL, 'localhost' is a special host and means that a socket connection should be used.\n\nDid you mean to use a socket connection, or to connect to the local machine via a port? If you meant to connect via a port, '127.0.0.1' should be used instead of 'localhost'.", @"message of error when using 'localhost' for a network connection"));
return NO;
}
@@ -123,15 +123,9 @@ - (NSString *)keychainPasswordForSSHConnection:(SPMySQLConnection *)connection
*/
- (void)noConnectionAvailable:(id)connection
{
SPBeginAlertSheet(
SPOnewayAlertSheet(
NSLocalizedString(@"No connection available", @"no connection available message"),
NSLocalizedString(@"OK", @"OK button"),
nil,
nil,
[self parentWindow],
self,
nil,
nil,
NSLocalizedString(@"An error has occured and there doesn't seem to be a connection available.", @"no connection available informatie message")
);
}
@@ -176,7 +170,7 @@ - (SPMySQLConnectionLostDecision)connectionLost:(id)connection
- (void)showErrorWithTitle:(NSString *)theTitle message:(NSString *)theMessage
{
if ([[self parentWindow] isVisible]) {
SPBeginAlertSheet(theTitle, NSLocalizedString(@"OK", @"OK button"), nil, nil, [self parentWindow], self, nil, nil, theMessage);
SPOnewayAlertSheet(theTitle, [self parentWindow], theMessage);
}
}
@@ -353,7 +353,11 @@ - (void)mySQLConnectionEstablished
// If SSL was enabled, check it was established correctly
if (useSSL && ([self type] == SPTCPIPConnection || [self type] == SPSocketConnection)) {
if (![mySQLConnection isConnectedViaSSL]) {
SPBeginAlertSheet(NSLocalizedString(@"SSL connection not established", @"SSL requested but not used title"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [dbDocument parentWindow], nil, nil, nil, NSLocalizedString(@"You requested that the connection should be established using SSL, but MySQL made the connection without SSL.\n\nThis may be because the server does not support SSL connections, or has SSL disabled; or insufficient details were supplied to establish an SSL connection.\n\nThis connection is not encrypted.", @"SSL connection requested but not established error detail"));
SPOnewayAlertSheet(
NSLocalizedString(@"SSL connection not established", @"SSL requested but not used title"),
[dbDocument parentWindow],
NSLocalizedString(@"You requested that the connection should be established using SSL, but MySQL made the connection without SSL.\n\nThis may be because the server does not support SSL connections, or has SSL disabled; or insufficient details were supplied to establish an SSL connection.\n\nThis connection is not encrypted.", @"SSL connection requested but not established error detail")
);
}
else {
#ifndef SP_CODA
Oops, something went wrong.

0 comments on commit 5357fd1

Please sign in to comment.