From e461a496b2ad1e22be18cf651fcac7a191089059 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 25 Oct 2018 21:07:39 +0200 Subject: LicenseHandler: Move invalid license error message to a new method This enables us to print the error message in both of the following cases: 1. Validating an existing key 2. Adding a new license key --- DomeKey/LicenseHandler.m | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/DomeKey/LicenseHandler.m b/DomeKey/LicenseHandler.m index b18bd77..c6e0e9c 100644 --- a/DomeKey/LicenseHandler.m +++ b/DomeKey/LicenseHandler.m @@ -16,11 +16,7 @@ static NSString * const LICENSE_FILE_NAME = @"license.plist"; { if ([self licenseFileExists]) { if (![self validateLicense]) { - eprintf( - "The license file '%s' is invalid. " - "Try adding your license again using the `--license` flag.\n", - [[[self licensePath] path] UTF8String] - ); + [self printInvalidLicenseMessage]; // TODO: then do trial } @@ -53,6 +49,8 @@ static NSString * const LICENSE_FILE_NAME = @"license.plist"; printf("Thank you for registering DomeKey!\n"); } else { + [self printInvalidLicenseMessage]; + [[NSWorkspace sharedWorkspace] recycleURLs:[NSArray arrayWithObject:[self licensePath]] completionHandler:^(NSDictionary *newURLs, NSError *error) { @@ -129,4 +127,13 @@ static NSString * const LICENSE_FILE_NAME = @"license.plist"; return validated; } ++ (void)printInvalidLicenseMessage +{ + eprintf( + "The license file '%s' is invalid. " + "Try adding your license again using the `--license` flag.\n", + [[[self licensePath] path] UTF8String] + ); +} + @end -- cgit v1.2.3