From 4957da593c8a3b0cc81b3f122e4f8b93c8de46b3 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 26 Oct 2018 17:38:18 +0200 Subject: LicenseHandler(addLicense:): Move license file to trash manually Get the trash directory and move the file there manually. Unfortunately, this doesn't do the renaming of the file if there's a name conflict, so we still need to look into how to deal with that. Thanks to Vincent Tourraine (https://stackoverflow.com/users/135712/vincent-tourraine) on Stack Overflow (https://stackoverflow.com/questions/46089964/how-do-i-get-rid-of-ios-version-is-partial-introduced-in-ios-x-warnings-in-xc/46274231#46274231) for explaining how to get rid of the `-Wunguarded-availability` warnings I was getting as a result of using `NSTrashDirectory`. Apparently using the availability macros doesn't silence the error. Since we're already checking for availability without `@available`, forcibly silence the warning here. --- DomeKey/LicenseHandler.m | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/DomeKey/LicenseHandler.m b/DomeKey/LicenseHandler.m index 0421e2e..576e255 100644 --- a/DomeKey/LicenseHandler.m +++ b/DomeKey/LicenseHandler.m @@ -51,11 +51,34 @@ static NSString * const LICENSE_FILE_NAME = @"license.plist"; else { [self printInvalidLicenseMessage]; - BOOL removed = [[NSFileManager defaultManager] - removeItemAtURL:[self licensePath] +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunguarded-availability" +#ifdef AVAILABLE_MAC_OS_X_VERSION_10_8_AND_LATER + // NSTrashDirectory availability starts in 10.8 + NSURL *trash_url = [[NSFileManager defaultManager] + URLForDirectory:NSTrashDirectory + inDomain:NSUserDomainMask + appropriateForURL:nil + create:NO error:&error]; - if (!removed) { + if (error) { + eprintf("%s\n", [[error localizedDescription] UTF8String]); + } +#else + NSURL *trash_url = [NSURL + fileURLWithPath:[NSHomeDirectory() + stringByAppendingPathComponent:@".Trash"] + isDirectory:YES]; +#endif +#pragma clang diagnostic pop + + BOOL moved = [[NSFileManager defaultManager] + moveItemAtURL:[self licensePath] + toURL:trash_url + error:&error]; + + if (!moved) { eprintf("%s\n", [[error localizedDescription] UTF8String]); } } -- cgit v1.2.3