aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-10-26 19:34:58 +0200
committerTeddy Wing2018-10-26 19:34:58 +0200
commit0313bd3aada81beb56e9a6d7dd6e331084940f7f (patch)
treeabf263d8ea4c5f53eabe7adca3c9a03fc83a6a60
parent3ec24a789a299461c53e27492624d10d414f4010 (diff)
downloadDomeKey-0313bd3aada81beb56e9a6d7dd6e331084940f7f.tar.bz2
LicenseHandler: Move trashing code to a new method
Make things a bit more organised by splitting off this functionality and giving it a name.
-rw-r--r--DomeKey/LicenseHandler.m63
1 files changed, 35 insertions, 28 deletions
diff --git a/DomeKey/LicenseHandler.m b/DomeKey/LicenseHandler.m
index 780efef..ff63ed0 100644
--- a/DomeKey/LicenseHandler.m
+++ b/DomeKey/LicenseHandler.m
@@ -51,43 +51,50 @@ static NSString * const LICENSE_FILE_NAME = @"license.plist";
else {
[self printInvalidLicenseMessage];
+ [self trashFileAtURL:[self licensePath]];
+ }
+
+ // Copy license file into path
+ // Validate license
+ // If license doesn't validate, remove copied file
+ // If license does validate, print a success message
+}
+
++ (void)trashFileAtURL:(NSURL *)theURL
+{
+ NSError *error = nil;
+
#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 (error) {
- eprintf("%s\n", [[error localizedDescription] UTF8String]);
- }
+ // NSTrashDirectory availability starts in 10.8
+ NSURL *trash_url = [[NSFileManager defaultManager]
+ URLForDirectory:NSTrashDirectory
+ inDomain:NSUserDomainMask
+ appropriateForURL:nil
+ create:NO
+ error:&error];
+
+ if (error) {
+ eprintf("%s\n", [[error localizedDescription] UTF8String]);
+ }
#else
- NSURL *trash_url = [NSURL
- fileURLWithPath:[NSHomeDirectory()
- stringByAppendingPathComponent:@".Trash"]
- isDirectory:YES];
+ 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
- URLByAppendingPathComponent:[self trashedLicenseFilename]]
- error:&error];
+ BOOL moved = [[NSFileManager defaultManager]
+ moveItemAtURL:theURL
+ toURL:[trash_url
+ URLByAppendingPathComponent:[self trashedLicenseFilename]]
+ error:&error];
- if (!moved) {
- eprintf("%s\n", [[error localizedDescription] UTF8String]);
- }
+ if (!moved) {
+ eprintf("%s\n", [[error localizedDescription] UTF8String]);
}
-
- // Copy license file into path
- // Validate license
- // If license doesn't validate, remove copied file
- // If license does validate, print a success message
}
+ (NSString *)trashedLicenseFilename