diff options
-rw-r--r-- | DomeKey/LicenseHandler.h | 2 | ||||
-rw-r--r-- | DomeKey/LicenseHandler.m | 32 | ||||
-rw-r--r-- | DomeKey/main.m | 3 |
3 files changed, 34 insertions, 3 deletions
diff --git a/DomeKey/LicenseHandler.h b/DomeKey/LicenseHandler.h index fb3ab51..4d86923 100644 --- a/DomeKey/LicenseHandler.h +++ b/DomeKey/LicenseHandler.h @@ -15,6 +15,6 @@ @interface LicenseHandler : NSObject + (void)check; -+ (void)addLicense; ++ (void)addLicense:(NSString *)filePath; @end diff --git a/DomeKey/LicenseHandler.m b/DomeKey/LicenseHandler.m index 1bad0b8..021c7d4 100644 --- a/DomeKey/LicenseHandler.m +++ b/DomeKey/LicenseHandler.m @@ -31,8 +31,38 @@ static NSString * const LICENSE_FILE_NAME = @"license.plist"; } } -+ (void)addLicense ++ (void)addLicense:(NSString *)filePath { + // printf("current directory: %s\n", [[[NSFileManager defaultManager] currentDirectoryPath] UTF8String]); + + NSError *error = nil; + + // Copy license file to XDG_DATA_HOME + BOOL copied = [[NSFileManager defaultManager] + copyItemAtPath:[filePath stringByExpandingTildeInPath] + toPath:[[self licensePath] path] + error:&error]; + + if (!copied) { + eprintf("%s\n", [[error localizedDescription] UTF8String]); + } + + BOOL validated = [self validateLicense]; + + if (validated) { + printf("Thank you for registering DomeKey!\n"); + } + else { + BOOL trashed = [[NSFileManager defaultManager] + trashItemAtURL:[self licensePath] + resultingItemURL:nil + error:&error]; + + if (!trashed) { + eprintf("%s\n", [[error localizedDescription] UTF8String]); + } + } + // Copy license file into path // Validate license // If license doesn't validate, remove copied file diff --git a/DomeKey/main.m b/DomeKey/main.m index 2263bac..5daf4b8 100644 --- a/DomeKey/main.m +++ b/DomeKey/main.m @@ -23,7 +23,8 @@ int main(int argc, const char * argv[]) { config = c_parse_args(argv, argc, config); - [LicenseHandler check]; + [LicenseHandler addLicense:@"dome-key-license.plist"]; + // [LicenseHandler check]; if (config->args.reload) { return [Mappings dispatchReload]; |