Skip to content

Commit

Permalink
More work on the Daemon project. It's fully funcional now.
Browse files Browse the repository at this point in the history
  • Loading branch information
Spencer Diniz committed Jan 22, 2015
1 parent be901b6 commit 4c9848d
Show file tree
Hide file tree
Showing 42 changed files with 4,151 additions and 1,608 deletions.
1 change: 1 addition & 0 deletions NC DNS Updater Daemon/NC DNS Updater Daemon-Prefix.pch
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@

#ifdef __OBJC__
#import <Cocoa/Cocoa.h>
#import <NWLogging/NWLogging.h>
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
0FCA05881A7015C9000C01D0 /* NC_DNS_Updater.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 0FCA05831A7015C9000C01D0 /* NC_DNS_Updater.xcdatamodeld */; };
0FCA058B1A701750000C01D0 /* NCUDbManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 0FCA058A1A701750000C01D0 /* NCUDbManager.m */; };
0FCA058D1A7017B8000C01D0 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0FCA058C1A7017B8000C01D0 /* Cocoa.framework */; };
0FCA05921A702357000C01D0 /* NCUNamecheapDomain.m in Sources */ = {isa = PBXBuildFile; fileRef = 0FCA05911A702357000C01D0 /* NCUNamecheapDomain.m */; };
0FCA05951A702450000C01D0 /* NCUDomainService.m in Sources */ = {isa = PBXBuildFile; fileRef = 0FCA05941A702450000C01D0 /* NCUDomainService.m */; };
0FCA05981A702486000C01D0 /* NCUIPService.m in Sources */ = {isa = PBXBuildFile; fileRef = 0FCA05961A702486000C01D0 /* NCUIPService.m */; };
7F9C36FCDFFEFE6E7069C9A8 /* libPods-NC DNS Updater Daemon.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5094FF3A4D4E57E55D3DE7DE /* libPods-NC DNS Updater Daemon.a */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand All @@ -36,6 +40,16 @@
0FCA058A1A701750000C01D0 /* NCUDbManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NCUDbManager.m; sourceTree = "<group>"; };
0FCA058C1A7017B8000C01D0 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
0FCA058E1A7018D1000C01D0 /* NC DNS Updater Daemon-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NC DNS Updater Daemon-Prefix.pch"; sourceTree = "<group>"; };
0FCA058F1A70233F000C01D0 /* NC DNS Updater Daemon */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "NC DNS Updater Daemon"; sourceTree = "<group>"; };
0FCA05901A702357000C01D0 /* NCUNamecheapDomain.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NCUNamecheapDomain.h; path = "../NC DNS Updater/NCUNamecheapDomain.h"; sourceTree = "<group>"; };
0FCA05911A702357000C01D0 /* NCUNamecheapDomain.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NCUNamecheapDomain.m; path = "../NC DNS Updater/NCUNamecheapDomain.m"; sourceTree = "<group>"; };
0FCA05931A702450000C01D0 /* NCUDomainService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NCUDomainService.h; sourceTree = "<group>"; };
0FCA05941A702450000C01D0 /* NCUDomainService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NCUDomainService.m; sourceTree = "<group>"; };
0FCA05961A702486000C01D0 /* NCUIPService.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NCUIPService.m; path = "../NC DNS Updater/NCUIPService.m"; sourceTree = "<group>"; };
0FCA05971A702486000C01D0 /* NCUIPService.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NCUIPService.h; path = "../NC DNS Updater/NCUIPService.h"; sourceTree = "<group>"; };
2609946B2D932DE3D58620B7 /* Pods-NC DNS Updater Daemon.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NC DNS Updater Daemon.release.xcconfig"; path = "../Pods/Target Support Files/Pods-NC DNS Updater Daemon/Pods-NC DNS Updater Daemon.release.xcconfig"; sourceTree = "<group>"; };
5094FF3A4D4E57E55D3DE7DE /* libPods-NC DNS Updater Daemon.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-NC DNS Updater Daemon.a"; sourceTree = BUILT_PRODUCTS_DIR; };
95854A915FFBA4FCD47B7B71 /* Pods-NC DNS Updater Daemon.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-NC DNS Updater Daemon.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-NC DNS Updater Daemon/Pods-NC DNS Updater Daemon.debug.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -44,20 +58,37 @@
buildActionMask = 2147483647;
files = (
0FCA058D1A7017B8000C01D0 /* Cocoa.framework in Frameworks */,
7F9C36FCDFFEFE6E7069C9A8 /* libPods-NC DNS Updater Daemon.a in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
0A9EA591E42590D600214923 /* Pods */ = {
isa = PBXGroup;
children = (
95854A915FFBA4FCD47B7B71 /* Pods-NC DNS Updater Daemon.debug.xcconfig */,
2609946B2D932DE3D58620B7 /* Pods-NC DNS Updater Daemon.release.xcconfig */,
);
name = Pods;
sourceTree = "<group>";
};
0FCA05701A701132000C01D0 = {
isa = PBXGroup;
children = (
0FCA05961A702486000C01D0 /* NCUIPService.m */,
0FCA05971A702486000C01D0 /* NCUIPService.h */,
0FCA05901A702357000C01D0 /* NCUNamecheapDomain.h */,
0FCA05911A702357000C01D0 /* NCUNamecheapDomain.m */,
0FCA058F1A70233F000C01D0 /* NC DNS Updater Daemon */,
0FCA058E1A7018D1000C01D0 /* NC DNS Updater Daemon-Prefix.pch */,
0FCA058C1A7017B8000C01D0 /* Cocoa.framework */,
0FCA05831A7015C9000C01D0 /* NC_DNS_Updater.xcdatamodeld */,
0FCA057B1A701132000C01D0 /* NC DNS Updater Daemon */,
0FCA057A1A701132000C01D0 /* Products */,
0A9EA591E42590D600214923 /* Pods */,
1B25C09BB1B2B4397190DCCB /* Frameworks */,
);
sourceTree = "<group>";
};
Expand All @@ -75,20 +106,32 @@
0FCA057C1A701132000C01D0 /* main.m */,
0FCA05891A701750000C01D0 /* NCUDbManager.h */,
0FCA058A1A701750000C01D0 /* NCUDbManager.m */,
0FCA05931A702450000C01D0 /* NCUDomainService.h */,
0FCA05941A702450000C01D0 /* NCUDomainService.m */,
);
path = "NC DNS Updater Daemon";
sourceTree = "<group>";
};
1B25C09BB1B2B4397190DCCB /* Frameworks */ = {
isa = PBXGroup;
children = (
5094FF3A4D4E57E55D3DE7DE /* libPods-NC DNS Updater Daemon.a */,
);
name = Frameworks;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
0FCA05781A701132000C01D0 /* NC DNS Updater Daemon */ = {
isa = PBXNativeTarget;
buildConfigurationList = 0FCA05801A701132000C01D0 /* Build configuration list for PBXNativeTarget "NC DNS Updater Daemon" */;
buildPhases = (
7D22999C3C89032B8BF4DECA /* Check Pods Manifest.lock */,
0FCA05751A701132000C01D0 /* Sources */,
0FCA05761A701132000C01D0 /* Frameworks */,
0FCA05771A701132000C01D0 /* CopyFiles */,
F65781879907635B3427BEDF /* Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -130,14 +173,50 @@
};
/* End PBXProject section */

/* Begin PBXShellScriptBuildPhase section */
7D22999C3C89032B8BF4DECA /* Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Check Pods Manifest.lock";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
F65781879907635B3427BEDF /* Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/../Pods/Target Support Files/Pods-NC DNS Updater Daemon/Pods-NC DNS Updater Daemon-resources.sh\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
0FCA05751A701132000C01D0 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
0FCA058B1A701750000C01D0 /* NCUDbManager.m in Sources */,
0FCA05981A702486000C01D0 /* NCUIPService.m in Sources */,
0FCA05881A7015C9000C01D0 /* NC_DNS_Updater.xcdatamodeld in Sources */,
0FCA057D1A701132000C01D0 /* main.m in Sources */,
0FCA05921A702357000C01D0 /* NCUNamecheapDomain.m in Sources */,
0FCA05951A702450000C01D0 /* NCUDomainService.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -220,6 +299,7 @@
};
0FCA05811A701132000C01D0 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 95854A915FFBA4FCD47B7B71 /* Pods-NC DNS Updater Daemon.debug.xcconfig */;
buildSettings = {
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "NC DNS Updater Daemon-Prefix.pch";
Expand All @@ -229,6 +309,7 @@
};
0FCA05821A701132000C01D0 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 2609946B2D932DE3D58620B7 /* Pods-NC DNS Updater Daemon.release.xcconfig */;
buildSettings = {
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "NC DNS Updater Daemon-Prefix.pch";
Expand All @@ -255,6 +336,7 @@
0FCA05821A701132000C01D0 /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */

Expand Down
4 changes: 4 additions & 0 deletions NC DNS Updater Daemon/NC DNS Updater Daemon/NCUDbManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (strong, nonatomic) NSMutableArray *namecheapDomains;

- (NSURL *)databaseFilesDirectory;
- (void)loadDomains;

@end
114 changes: 112 additions & 2 deletions NC DNS Updater Daemon/NC DNS Updater Daemon/NCUDbManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ @implementation NCUDbManager
- (NSURL *)databaseFilesDirectory
{
NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *appSupportURL = [[fileManager URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask] lastObject];
NSURL *appSupportURL = [[fileManager URLsForDirectory:NSApplicationSupportDirectory inDomains:NSLocalDomainMask] lastObject];
return [appSupportURL URLByAppendingPathComponent:@"com.laratech.NC_DNS_Updater"];
}

Expand All @@ -29,9 +29,119 @@ - (NSManagedObjectModel *)managedObjectModel
return _managedObjectModel;
}

NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"NC_DNS_Updater" withExtension:@"momd"];
NSURL *modelURL = [[self databaseFilesDirectory] URLByAppendingPathComponent:@"NC_DNS_Updater.momd"];

NWLog(@"Model URL: %@", [modelURL absoluteString]);

_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];

return _managedObjectModel;
}

// Returns the persistent store coordinator for the application. This implementation creates and return a coordinator, having added the store for the application to it. (The directory for the store is created, if necessary.)
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
NWLog(@"PERSISTENT STORE COORDINATOR");

if (_persistentStoreCoordinator) {
return _persistentStoreCoordinator;
}

NSManagedObjectModel *mom = [self managedObjectModel];
if (!mom) {
NWLog(@"%@:%@ No model to generate a store from", [self class], NSStringFromSelector(_cmd));
return nil;
}

NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *applicationFilesDirectory = [self databaseFilesDirectory];
NSError *error = nil;

NWLog(@"Database directory path: %@", [applicationFilesDirectory path]);

NSDictionary *properties = [applicationFilesDirectory resourceValuesForKeys:@[NSURLIsDirectoryKey] error:&error];

if (!properties) {
NWLog(@"NO PROPERTIES");
BOOL ok = NO;
if ([error code] == NSFileReadNoSuchFileError) {
ok = [fileManager createDirectoryAtPath:[applicationFilesDirectory path] withIntermediateDirectories:YES attributes:nil error:&error];
}
if (!ok) {
[[NSApplication sharedApplication] presentError:error];
return nil;
}
} else {
NWLog(@"NO PROPERTIES");
if (![properties[NSURLIsDirectoryKey] boolValue]) {
// Customize and localize this error.
NSString *failureDescription = [NSString stringWithFormat:@"Expected a folder to store application data, found a file (%@).", [applicationFilesDirectory path]];

NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setValue:failureDescription forKey:NSLocalizedDescriptionKey];
error = [NSError errorWithDomain:@"YOUR_ERROR_DOMAIN" code:101 userInfo:dict];

[[NSApplication sharedApplication] presentError:error];
return nil;
}
}

NSURL *url = [applicationFilesDirectory URLByAppendingPathComponent:@"NC_DNS_Updater.storedata"];

NWLog(@"Database full path: %@", [url path]);

NSPersistentStoreCoordinator *coordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:mom];

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil];

if (![coordinator addPersistentStoreWithType:NSXMLStoreType configuration:nil URL:url options:options error:&error]) {
[[NSApplication sharedApplication] presentError:error];
return nil;
}
_persistentStoreCoordinator = coordinator;

return _persistentStoreCoordinator;
}

// Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.)
- (NSManagedObjectContext *)managedObjectContext
{
if (_managedObjectContext) {
return _managedObjectContext;
}

NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];
if (!coordinator) {
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setValue:@"Failed to initialize the store" forKey:NSLocalizedDescriptionKey];
[dict setValue:@"There was an error building up the data file." forKey:NSLocalizedFailureReasonErrorKey];
NSError *error = [NSError errorWithDomain:@"YOUR_ERROR_DOMAIN" code:9999 userInfo:dict];
[[NSApplication sharedApplication] presentError:error];
return nil;
}
_managedObjectContext = [[NSManagedObjectContext alloc] init];
[_managedObjectContext setPersistentStoreCoordinator:coordinator];

return _managedObjectContext;
}

- (void)loadDomains {
NWLog(@"Loading domain configuration.");

self.namecheapDomains = [NSMutableArray array];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@"NCUNamecheapDomain"];
NSError *error;

[self.namecheapDomains addObjectsFromArray:[self.managedObjectContext executeFetchRequest:fetchRequest error:&error]];

if (error) {
NWLog(@"ERROR FETCHING DATA: %@", [error localizedDescription]);
} else {
NWLog(@"Domain configuration loaded successfully.");
}
}


@end
15 changes: 15 additions & 0 deletions NC DNS Updater Daemon/NC DNS Updater Daemon/NCUDomainService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// NCUDomainService.h
// NC DNS Updater Daemon
//
// Created by Spencer Müller Diniz on 21/01/15.
// Copyright (c) 2015 LARATECH. All rights reserved.
//

#import <Foundation/Foundation.h>

@interface NCUDomainService : NSObject

- (void)updateDomains:(NSMutableArray *)namecheapDomains;

@end
Loading

0 comments on commit 4c9848d

Please sign in to comment.