diff options
Diffstat (limited to 'Source/SPDatabaseDocument.m')
-rw-r--r-- | Source/SPDatabaseDocument.m | 175 |
1 files changed, 88 insertions, 87 deletions
diff --git a/Source/SPDatabaseDocument.m b/Source/SPDatabaseDocument.m index dd781992..2340b97e 100644 --- a/Source/SPDatabaseDocument.m +++ b/Source/SPDatabaseDocument.m @@ -439,8 +439,6 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; #ifndef SP_CODA // Set the fileURL and init the preferences (query favs, filters, and history) if available for that URL NSURL *newURL = [[SPQueryController sharedQueryController] registerDocumentWithFileURL:[self fileURL] andContextInfo:spfPreferences]; -#warning debug code for #2266 - if(!newURL) NSLog(@"#2266: Trying to set nil fileURL in %s from queryController=%@ oldFileURL=%@ contextInfo=%@", __func__, [SPQueryController sharedQueryController], [self fileURL], spfPreferences); [self setFileURL:newURL]; // ...but hide the icon while the document is temporary @@ -3323,25 +3321,25 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; } [info setObject:windows forKey:@"windows"]; - NSString *err = nil; - NSData *plist = [NSPropertyListSerialization dataFromPropertyList:info - format:NSPropertyListXMLFormat_v1_0 - errorDescription:&err]; + error = nil; + + NSData *plist = [NSPropertyListSerialization dataWithPropertyList:info + format:NSPropertyListXMLFormat_v1_0 + options:0 + error:&error]; - if(err != nil) { - NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while converting session data", @"error while converting session data")] + if(error) { + NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Error while converting session data", @"error while converting session data") defaultButton:NSLocalizedString(@"OK", @"OK button") alternateButton:nil - otherButton:nil - informativeTextWithFormat:@"%@", err]; + otherButton:nil + informativeTextWithFormat:@"%@", [error localizedDescription]]; [alert setAlertStyle:NSCriticalAlertStyle]; [alert runModal]; return; } - - error = nil; [plist writeToFile:[NSString stringWithFormat:@"%@/info.plist", fileName] options:NSAtomicWrite error:&error]; @@ -3400,36 +3398,42 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; NSBeep(); return NO; } - - NSError *readError = nil; - NSString *convError = nil; - NSPropertyListFormat format; + NSMutableDictionary *spf = [[NSMutableDictionary alloc] init]; - - NSData *pData = [NSData dataWithContentsOfFile:fileName options:NSUncachedRead error:&readError]; - - [spf addEntriesFromDictionary:[NSPropertyListSerialization propertyListFromData:pData - mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError]]; - - if(!spf || ![spf count] || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) { - - [SPAlertSheets beginWaitingAlertSheetWithTitle:[NSString stringWithFormat:NSLocalizedString(@"Error while reading connection data file", @"error while reading connection data file")] - defaultButton:NSLocalizedString(@"OK", @"OK button") - alternateButton:NSLocalizedString(@"Ignore", @"ignore button") - otherButton:nil - alertStyle:NSCriticalAlertStyle - docWindow:parentWindow - modalDelegate:self - didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) - contextInfo:@"saveDocPrefSheetStatus" - infoText:[NSString stringWithFormat:NSLocalizedString(@"Connection data file “%@” couldn't be read. Please try to save the document under a different name.", @"message error while reading connection data file and suggesting to save it under a differnet name"), [fileName lastPathComponent]] - returnCode:&saveDocPrefSheetStatus]; - - if (spf) [spf release]; - if(saveDocPrefSheetStatus == NSAlertAlternateReturn) - return YES; - - return NO; + { + NSError *error = nil; + + NSData *pData = [NSData dataWithContentsOfFile:fileName options:NSUncachedRead error:&error]; + + if(pData && !error) { + NSDictionary *pDict = [NSPropertyListSerialization propertyListWithData:pData + options:NSPropertyListImmutable + format:NULL + error:&error]; + + if(pDict && !error) { + [spf addEntriesFromDictionary:pDict]; + } + } + + if(![spf count] || error) { + [SPAlertSheets beginWaitingAlertSheetWithTitle:NSLocalizedString(@"Error while reading connection data file", @"error while reading connection data file") + defaultButton:NSLocalizedString(@"OK", @"OK button") + alternateButton:NSLocalizedString(@"Ignore", @"ignore button") + otherButton:nil + alertStyle:NSCriticalAlertStyle + docWindow:parentWindow + modalDelegate:self + didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) + contextInfo:@"saveDocPrefSheetStatus" + infoText:[NSString stringWithFormat:NSLocalizedString(@"Connection data file “%@” couldn't be read. Please try to save the document under a different name.\n\nDetails: %@", @"message error while reading connection data file and suggesting to save it under a differnet name"), [fileName lastPathComponent], [error localizedDescription]] + returnCode:&saveDocPrefSheetStatus]; + + if(spf) [spf release]; + if(saveDocPrefSheetStatus == NSAlertAlternateReturn) return YES; + + return NO; + } } // For dispatching later @@ -3445,27 +3449,27 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; [spf setObject:[[SPQueryController sharedQueryController] contentFilterForFileURL:[self fileURL]] forKey:SPContentFilters]; // Save it again - NSString *err = nil; - NSData *plist = [NSPropertyListSerialization dataFromPropertyList:spf - format:NSPropertyListXMLFormat_v1_0 - errorDescription:&err]; + NSError *error = nil; + NSData *plist = [NSPropertyListSerialization dataWithPropertyList:spf + format:NSPropertyListXMLFormat_v1_0 + options:0 + error:&error]; [spf release]; - if(err != nil) { - NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while converting connection data", @"error while converting connection data")] + if(error) { + NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Error while converting connection data", @"error while converting connection data") defaultButton:NSLocalizedString(@"OK", @"OK button") alternateButton:nil - otherButton:nil - informativeTextWithFormat:@"%@", err]; + otherButton:nil + informativeTextWithFormat:@"%@", [error localizedDescription]]; [alert setAlertStyle:NSCriticalAlertStyle]; [alert runModal]; return NO; } - NSError *error = nil; [plist writeToFile:fileName options:NSAtomicWrite error:&error]; - if(error != nil){ + if(error != nil) { NSAlert *errorAlert = [NSAlert alertWithError:error]; [errorAlert runModal]; return NO; @@ -3474,7 +3478,6 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL fileURLWithPath:fileName]]; return YES; - } // Set up the dictionary to save to file, together with a data store @@ -3544,24 +3547,24 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; } // Convert to plist - NSString *err = nil; - NSData *plist = [NSPropertyListSerialization dataFromPropertyList:spfStructure + NSError *error = nil; + NSData *plist = [NSPropertyListSerialization dataWithPropertyList:spfStructure format:NSPropertyListXMLFormat_v1_0 - errorDescription:&err]; + options:0 + error:&error]; - if (err != nil) { - NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while converting connection data", @"error while converting connection data")] + if (error) { + NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Error while converting connection data", @"error while converting connection data") defaultButton:NSLocalizedString(@"OK", @"OK button") alternateButton:nil otherButton:nil - informativeTextWithFormat:@"%@", err]; + informativeTextWithFormat:@"%@", [error localizedDescription]]; [alert setAlertStyle:NSCriticalAlertStyle]; [alert runModal]; return NO; } - NSError *error = nil; [plist writeToFile:fileName options:NSAtomicWrite error:&error]; if (error != nil){ NSAlert *errorAlert = [NSAlert alertWithError:error]; @@ -3578,8 +3581,6 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; [[SPQueryController sharedQueryController] registerDocumentWithFileURL:[NSURL fileURLWithPath:fileName] andContextInfo:preferences]; NSURL *newURL = [NSURL fileURLWithPath:fileName]; -#warning debug code for #2266 - if(!newURL) NSLog(@"#2266: Trying to set nil fileURL in %s from fileName=%@", __func__, fileName); [self setFileURL:newURL]; [[NSDocumentController sharedDocumentController] noteNewRecentDocumentURL:[NSURL fileURLWithPath:fileName]]; @@ -3593,7 +3594,6 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; } return YES; - } /** @@ -4954,33 +4954,36 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; */ - (BOOL)setStateFromConnectionFile:(NSString *)path { - NSError *readError = nil; - NSString *convError = nil; - NSPropertyListFormat format; - NSString *encryptpw = nil; NSMutableDictionary *data = nil; NSDictionary *spf = nil; - - // Read the property list data, and unserialize it. - NSData *pData = [NSData dataWithContentsOfFile:path options:NSUncachedRead error:&readError]; - - spf = [[NSPropertyListSerialization propertyListFromData:pData - mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&convError] retain]; - - if (!spf || readError != nil || [convError length] || !(format == NSPropertyListXMLFormat_v1_0 || format == NSPropertyListBinaryFormat_v1_0)) { - NSAlert *alert = [NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Error while reading connection data file", @"error while reading connection data file")] - defaultButton:NSLocalizedString(@"OK", @"OK button") - alternateButton:nil - otherButton:nil - informativeTextWithFormat:NSLocalizedString(@"Connection data file couldn't be read.", @"error while reading connection data file")]; - - [alert setAlertStyle:NSCriticalAlertStyle]; - [alert runModal]; - if (spf) [spf release]; - [self closeAndDisconnect]; - return NO; + { + NSError *error = nil; + + // Read the property list data, and unserialize it. + NSData *pData = [NSData dataWithContentsOfFile:path options:NSUncachedRead error:&error]; + + if(pData && !error) { + spf = [[NSPropertyListSerialization propertyListWithData:pData + options:NSPropertyListImmutable + format:NULL + error:&error] retain]; + } + + if (!spf || error) { + NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Error while reading connection data file", @"error while reading connection data file") + defaultButton:NSLocalizedString(@"OK", @"OK button") + alternateButton:nil + otherButton:nil + informativeTextWithFormat:NSLocalizedString(@"Connection data file couldn't be read. (%@)", @"error while reading connection data file"), [error localizedDescription]]; + + [alert setAlertStyle:NSCriticalAlertStyle]; + [alert runModal]; + if (spf) [spf release]; + [self closeAndDisconnect]; + return NO; + } } // If the .spf format is unhandled, error. @@ -5139,8 +5142,6 @@ static int64_t SPDatabaseDocumentInstanceCounter = 0; if (![self isSaveInBundle]) { NSURL *newURL = [NSURL fileURLWithPath:path]; -#warning debug code for #2266 - if(!newURL) NSLog(@"#2266: Trying to set nil fileURL in %s from path=%@", __func__, path); [self setFileURL:newURL]; } |