diff options
| author | Teddy Wing | 2018-10-26 17:38:18 +0200 | 
|---|---|---|
| committer | Teddy Wing | 2018-10-26 17:38:18 +0200 | 
| commit | 4957da593c8a3b0cc81b3f122e4f8b93c8de46b3 (patch) | |
| tree | 0c10eba7ac70527af2ec9598861917e7040dc523 | |
| parent | 388c40cd41e2bbbc3fe3e3336e32a4dc64fa84a4 (diff) | |
| download | DomeKey-4957da593c8a3b0cc81b3f122e4f8b93c8de46b3.tar.bz2 | |
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.
| -rw-r--r-- | DomeKey/LicenseHandler.m | 29 | 
1 files 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]);          }      } | 
