forked from mreiferson/encfs-macfusion2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEncfsConfigurationController.m
98 lines (79 loc) · 2.65 KB
/
EncfsConfigurationController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// EncfsConfigurationController.m
// MacFusion2
//
// Created by Tobias Haeberle on 15.02.09.
// Copyright 2009 __MyCompanyName__. All rights reserved.
//
#import "EncfsConfigurationController.h"
#import "EncFSCreationController.h"
#import "ENCFSErrors.h"
#import <MFCore/MFLogging.h>
@implementation EncfsConfigurationController
+ (BOOL) checkRawPath:(NSString *)dirPath withError:(NSError **)error
{
// MFLog(@"checkRawPath: %@, withError: %@", dirPath, *error);
NSArray *contentArray = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:dirPath error:error];
if (nil != *error) {
return NO;
}
NSEnumerator *e = [contentArray objectEnumerator];
BOOL foundKeyFile = NO;
NSString *path;
while (!foundKeyFile && (path = [e nextObject])) {
// MFLog(@"checking: %@ with lastComponent %@", path, [path lastPathComponent]);
if ( [[path lastPathComponent] isEqualToString:@".encfs5"] || [[path lastPathComponent] isEqualToString:@".encfs6.xml"] ) {
foundKeyFile = YES;
}
}
if (foundKeyFile) {
NSLog(@"found path: %@", dirPath);
return YES;
} else {
// NSLog Error
*error = [NSError errorWithDomain:kENCFSErrorDomain code:kENCFSErrorNoKeyFile userInfo:[NSDictionary dictionaryWithObjectsAndKeys:@"No EncFS key file found", NSLocalizedDescriptionKey, nil]];
MFLog(@"error: %@", [*error localizedDescription]);
return NO;
}
}
- (void) showCreationWindow
{
[creationController setRepresentedObject:[self representedObject]];
[NSApp runModalForWindow:[creationController window]];
}
- (void) shouldCreateEncFSAtPath:(NSString *)dirPath
{
NSUInteger clickedButton = NSRunAlertPanel(@"No EncFS key file found", @"This path is not an Encrypted File System. Do you want to create a new filesystem?", @"Yes", @"No", nil);
if ( NSOKButton == clickedButton ) {
[self showCreationWindow];
}
}
- (IBAction) createNewFS: (id)sender
{
[self showCreationWindow];
}
- (IBAction)browse:(id)sender
{
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
[openPanel setCanChooseFiles:NO];
[openPanel setCanChooseDirectories:YES];
[openPanel setCanCreateDirectories:YES];
NSUInteger returnCode = [openPanel runModalForTypes:nil];
if (returnCode == NSOKButton) {
NSLog(@"OK");
NSError *error = nil;
NSString *dirPath = [[openPanel filenames] lastObject];
if ( [EncfsConfigurationController checkRawPath:dirPath withError:&error] ) {
[[self representedObject] setValue:dirPath forKeyPath:@"parameters.rawPath"];
} else {
if ( [[error domain] isEqualToString:kENCFSErrorDomain] && [error code] == kENCFSErrorNoKeyFile) {
[self shouldCreateEncFSAtPath:dirPath];
}
}
return;
} else {
NSLog(@"cancel");
}
return;
}
@end