Line data Source code
1 0 : /* 2 : 3 : OOXMLExtensions.m 4 : 5 : Oolite 6 : Copyright (C) 2004-2013 Giles C Williams and contributors 7 : 8 : This program is free software; you can redistribute it and/or 9 : modify it under the terms of the GNU General Public License 10 : as published by the Free Software Foundation; either version 2 11 : of the License, or (at your option) any later version. 12 : 13 : This program is distributed in the hope that it will be useful, 14 : but WITHOUT ANY WARRANTY; without even the implied warranty of 15 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 : GNU General Public License for more details. 17 : 18 : You should have received a copy of the GNU General Public License 19 : along with this program; if not, write to the Free Software 20 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 21 : MA 02110-1301, USA. 22 : 23 : */ 24 : 25 : #import "OOXMLExtensions.h" 26 : 27 : 28 : @implementation NSDictionary (OOXMLExtensions) 29 : 30 : - (BOOL) writeOOXMLToFile:(NSString *)path atomically:(BOOL)flag errorDescription:(NSString **)outErrorDesc 31 : { 32 : NSData *data = nil; 33 : NSString *errorDesc = nil; 34 : 35 : data = [NSPropertyListSerialization dataFromPropertyList:self format:NSPropertyListXMLFormat_v1_0 errorDescription:outErrorDesc]; 36 : if (data == nil) 37 : { 38 : if (outErrorDesc != NULL) 39 : { 40 : *outErrorDesc = [NSString stringWithFormat:@"could not convert property list to XML: %@", errorDesc]; 41 : } 42 : #if OOLITE_RELEASE_PLIST_ERROR_STRINGS 43 : [errorDesc release]; 44 : #endif 45 : return NO; 46 : } 47 : 48 : if (![data writeToFile:path atomically:YES]) 49 : { 50 : if (outErrorDesc != NULL) 51 : { 52 : *outErrorDesc = [NSString stringWithFormat:@"could not write data to %@.", path]; 53 : } 54 : return NO; 55 : } 56 : 57 : return YES; 58 : } 59 : 60 : @end