| 1 | // |
|---|
| 2 | // MFMainController.m |
|---|
| 3 | // Macfusion2 |
|---|
| 4 | // |
|---|
| 5 | // Licensed under the Apache License, Version 2.0 (the "License"); |
|---|
| 6 | // you may not use this file except in compliance with the License. |
|---|
| 7 | // You may obtain a copy of the License at |
|---|
| 8 | // |
|---|
| 9 | // http://www.apache.org/licenses/LICENSE-2.0 |
|---|
| 10 | // |
|---|
| 11 | // Unless required by applicable law or agreed to in writing, software |
|---|
| 12 | // distributed under the License is distributed on an "AS IS" BASIS, |
|---|
| 13 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|---|
| 14 | // See the License for the specific language governing permissions and |
|---|
| 15 | // limitations under the License. |
|---|
| 16 | |
|---|
| 17 | #import "MFMainController.h" |
|---|
| 18 | #import "MFPlugin.h" |
|---|
| 19 | #import "MFPluginController.h" |
|---|
| 20 | #import "MFFilesystemController.h" |
|---|
| 21 | #import "MFFilesystem.h" |
|---|
| 22 | #import "MFCommunicationServer.h" |
|---|
| 23 | #include <sys/xattr.h> |
|---|
| 24 | #import "MFLogging.h" |
|---|
| 25 | #import "MFConstants.h" |
|---|
| 26 | |
|---|
| 27 | @implementation MFMainController |
|---|
| 28 | static MFMainController* sharedController = nil; |
|---|
| 29 | |
|---|
| 30 | #pragma mark Singleton Methods |
|---|
| 31 | + (MFMainController*)sharedController |
|---|
| 32 | { |
|---|
| 33 | if (sharedController == nil) |
|---|
| 34 | { |
|---|
| 35 | [[self alloc] init]; |
|---|
| 36 | } |
|---|
| 37 | |
|---|
| 38 | return sharedController; |
|---|
| 39 | } |
|---|
| 40 | |
|---|
| 41 | + (id)allocWithZone:(NSZone*) zone |
|---|
| 42 | { |
|---|
| 43 | if (sharedController == nil) |
|---|
| 44 | { |
|---|
| 45 | sharedController = [super allocWithZone:zone]; |
|---|
| 46 | return sharedController; |
|---|
| 47 | } |
|---|
| 48 | |
|---|
| 49 | return nil; |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | - (id)copyWithZone:(NSZone*)zone |
|---|
| 53 | { |
|---|
| 54 | return self; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | #pragma mark Runloop and initialization methods |
|---|
| 58 | |
|---|
| 59 | - (void)initialize |
|---|
| 60 | { |
|---|
| 61 | mfcSetupTrashMonitoring(); |
|---|
| 62 | MFPluginController* pluginController = [MFPluginController sharedController]; |
|---|
| 63 | [pluginController loadPlugins]; |
|---|
| 64 | |
|---|
| 65 | [MFFilesystemController sharedController]; |
|---|
| 66 | [[MFCommunicationServer sharedServer] startServing]; |
|---|
| 67 | } |
|---|
| 68 | |
|---|
| 69 | - (void)applicationDidFinishLaunching:(NSNotification *)aNotification |
|---|
| 70 | { |
|---|
| 71 | [self initialize]; |
|---|
| 72 | } |
|---|
| 73 | |
|---|
| 74 | # pragma mark Opening Files |
|---|
| 75 | - (BOOL)application:(NSApplication *)theApplication |
|---|
| 76 | openFile:(NSString *)filePath |
|---|
| 77 | { |
|---|
| 78 | NSDictionary* fileDict = [NSDictionary dictionaryWithContentsOfFile: filePath]; |
|---|
| 79 | NSString* uuid = [fileDict objectForKey: KMFFSUUIDParameter]; |
|---|
| 80 | if (!uuid) |
|---|
| 81 | { |
|---|
| 82 | MFLogS(self, @"Asked to open bad file at pah %@", filePath); |
|---|
| 83 | return NO; |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | MFServerFS* fs = [[MFFilesystemController sharedController] filesystemWithUUID: uuid]; |
|---|
| 87 | if (!fs) |
|---|
| 88 | { |
|---|
| 89 | MFLogS(self, @"Can not find filesystem references at by file with uuid %@", uuid); |
|---|
| 90 | return NO; |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| 93 | if ([fs isMounted]) |
|---|
| 94 | { |
|---|
| 95 | [[NSWorkspace sharedWorkspace] selectFile:nil |
|---|
| 96 | inFileViewerRootedAtPath:[fs mountPath]]; |
|---|
| 97 | } |
|---|
| 98 | else if ([fs isUnmounted] || [fs isFailedToMount]) |
|---|
| 99 | { |
|---|
| 100 | [fs mount]; |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | return YES; |
|---|
| 104 | } |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | @end |
|---|