exit when configuration file couldn't be opened

* when the configuration file couldn't be opened it failed silently and
used empty configuration. Now it prints an error and quits with
errorcode 1.
* LOGE not used because of circular reference
This commit is contained in:
Remco
2014-12-22 12:31:23 +01:00
parent cbf16d140b
commit 16ca9b85ab

View File

@@ -141,11 +141,27 @@ static NSString * const kMachineIDPlistKeyKey = @"MachineIDKey";
}
- (void)reloadConfigData {
_configData = [[NSDictionary dictionaryWithContentsOfFile:kConfigFilePath] mutableCopy];
NSError* error = nil;
if (!_configData) {
_configData = [NSMutableDictionary dictionary];
NSData *readData = [NSData dataWithContentsOfFile:kConfigFilePath options:0 error:&error];
if (error) {
fprintf(stderr, "%s\n", [[NSString stringWithFormat:@"Could not open configuration file %@: %@", kConfigFilePath, [error localizedDescription]] UTF8String]);
exit(1);
}
CFErrorRef parseError = NULL;
NSDictionary *dictionary = (__bridge_transfer NSDictionary *)CFPropertyListCreateWithData(kCFAllocatorDefault, (__bridge CFDataRef)readData, kCFPropertyListImmutable, NULL, (CFErrorRef *)&parseError);
if (parseError) {
fprintf(stderr, "%s\n", [[NSString stringWithFormat:@"Could not parse configuration file %@: %@", kConfigFilePath, [(__bridge NSError *)parseError localizedDescription]] UTF8String]);
exit(1);
}
_configData = [dictionary mutableCopy];
}
@end