aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPExportController.h5
-rw-r--r--Source/SPExportController.m25
-rw-r--r--Source/SPExportInitializer.h2
-rw-r--r--Source/SPExportInitializer.m16
4 files changed, 40 insertions, 8 deletions
diff --git a/Source/SPExportController.h b/Source/SPExportController.h
index 8d0a6969..7788ef0e 100644
--- a/Source/SPExportController.h
+++ b/Source/SPExportController.h
@@ -212,6 +212,11 @@
* Previous connection encoding was via Latin1
*/
BOOL sqlPreviousConnectionEncodingViaLatin1;
+
+ /**
+ * Array of export file paths.
+ */
+ NSMutableArray *exportFiles;
NSInteger heightOffset;
NSUInteger windowMinWidth;
diff --git a/Source/SPExportController.m b/Source/SPExportController.m
index ca4f1ac8..42d8982c 100644
--- a/Source/SPExportController.m
+++ b/Source/SPExportController.m
@@ -75,6 +75,7 @@
tables = [[NSMutableArray alloc] init];
exporters = [[NSMutableArray alloc] init];
+ exportFiles = [[NSMutableArray alloc] init];
operationQueue = [[NSOperationQueue alloc] init];
showAdvancedView = NO;
@@ -124,7 +125,9 @@
- (void)exportTables:(NSArray *)exportTables asFormat:(SPExportType)format
{
[self refreshTableList:self];
-
+
+ if ([exportFiles count] > 0) [exportFiles removeAllObjects];
+
if (exportTables && format) {
// Select the correct tab according to the supplied export type
@@ -358,12 +361,31 @@
{
[self setExportCancelled:YES];
+ [exportProgressTitle setStringValue:NSLocalizedString(@"Cancelling...", @"cancelling export message")];
+ [exportProgressText setStringValue:NSLocalizedString(@"Cleaning up...", @"cancelling export cleaning up message")];
+
+ // Disable the cancel button
+ [sender setEnabled:NO];
+
// Cancel all of the currently running operations
[operationQueue cancelAllOperations];
// Close the progress sheet
[NSApp endSheet:exportProgressWindow returnCode:0];
[exportProgressWindow orderOut:self];
+
+ // Loop the cached export file paths and remove them from disk if they exist
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+
+ for (NSString *filePath in exportFiles)
+ {
+ if ([fileManager fileExistsAtPath:filePath]) {
+ [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
+ }
+ }
+
+ // Re-enable the cancel button for future exports
+ [sender setEnabled:YES];
}
/**
@@ -637,6 +659,7 @@
{
[tables release], tables = nil;
[exporters release], exporters = nil;
+ [exportFiles release], exportFiles = nil;
[operationQueue release], operationQueue = nil;
[exportFilename release], exportFilename = nil;
diff --git a/Source/SPExportInitializer.h b/Source/SPExportInitializer.h
index 4d86f619..189a46d2 100644
--- a/Source/SPExportInitializer.h
+++ b/Source/SPExportInitializer.h
@@ -46,6 +46,6 @@
- (SPXMLExporter *)initializeXMLExporterForTable:(NSString *)table orDataArray:(NSArray *)dataArray;
- (void)writeXMLHeaderToFileHandle:(SPFileHandle *)fileHandle;
-- (SPFileHandle *)getFileHandleForFilePath:(NSString *)filePath;
+- (SPFileHandle *)getFileHandleForFilePath:(NSString *)path;
@end
diff --git a/Source/SPExportInitializer.m b/Source/SPExportInitializer.m
index c5779dc6..4b7dc38c 100644
--- a/Source/SPExportInitializer.m
+++ b/Source/SPExportInitializer.m
@@ -574,13 +574,13 @@
/**
* Returns a file handle for writing at the supplied path.
*/
-- (SPFileHandle *)getFileHandleForFilePath:(NSString *)filePath
+- (SPFileHandle *)getFileHandleForFilePath:(NSString *)path
{
SPFileHandle *fileHandle = nil;
NSFileManager *fileManager = [NSFileManager defaultManager];
- if ([fileManager fileExistsAtPath:filePath]) {
- if ((![fileManager isWritableFileAtPath:filePath]) || (!(fileHandle = [SPFileHandle fileHandleForWritingAtPath:filePath]))) {
+ if ([fileManager fileExistsAtPath:path]) {
+ if ((![fileManager isWritableFileAtPath:path]) || (!(fileHandle = [SPFileHandle fileHandleForWritingAtPath:path]))) {
SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [tableDocumentInstance parentWindow], self, nil, nil,
NSLocalizedString(@"Couldn't replace the file. Be sure that you have the necessary privileges.", @"message of panel when file cannot be replaced"));
return nil;
@@ -588,17 +588,17 @@
}
// Otherwise attempt to create a file
else {
- if (![fileManager createFileAtPath:filePath contents:[NSData data] attributes:nil]) {
+ if (![fileManager createFileAtPath:path contents:[NSData data] attributes:nil]) {
SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [tableDocumentInstance parentWindow], self, nil, nil,
NSLocalizedString(@"Couldn't write to file. Be sure that you have the necessary privileges.", @"message of panel when file cannot be written"));
return nil;
}
// Retrieve a filehandle for the file, attempting to delete it on failure.
- fileHandle = [SPFileHandle fileHandleForWritingAtPath:filePath];
+ fileHandle = [SPFileHandle fileHandleForWritingAtPath:path];
if (!fileHandle) {
- [[NSFileManager defaultManager] removeFileAtPath:filePath handler:nil];
+ [[NSFileManager defaultManager] removeFileAtPath:path handler:nil];
SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [tableDocumentInstance parentWindow], self, nil, nil,
NSLocalizedString(@"Couldn't write to file. Be sure that you have the necessary privileges.", @"message of panel when file cannot be written"));
@@ -606,6 +606,10 @@
}
}
+ // Keep a record of the file handle's path in case the user cancels the export then we need to remove
+ // it from disk.
+ [exportFiles addObject:path];
+
return fileHandle;
}