Skip to content
Newer
Older
100644 119 lines (98 sloc) 3.45 KB
02855d8 Initial import
Michael Gorbach authored
1 //
2 // MFPluginController.m
3 // MacFusion2
4 //
b798dd6 Advanced options enabled. License headers added. Added item to launch…
Michael Gorbach authored
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.
02855d8 Initial import
Michael Gorbach authored
16
17 #import "MFPluginController.h"
4cd156a Many, many changes. Macfusion2 is now useable.
Michael Gorbach authored
18 #import "MFServerPlugin.h"
19 #import "MFServerFS.h"
bc361ad Add a generic ability for plugins to subclass Server & Client Filesys…
Michael Gorbach authored
20 #import "MFCore.h"
781ab2e Fix warnings, and get rid of the un-needed sshnodelay.so.
Michael Gorbach authored
21 #import "MFLogging.h"
02855d8 Initial import
Michael Gorbach authored
22
23 #define PLUGIN_EXTENSION @"mfplugin"
24
25 @implementation MFPluginController
26 static MFPluginController* sharedController = nil;
27
80b6ffa Parameter generation now works. Mounting to be working soon.
Michael Gorbach authored
28 #pragma mark Singleton Methods
29
435a21b Update code conventions and fixing some stupid bugs.
Michael Gorbach authored
30 + (MFPluginController *)sharedController {
31 if (sharedController == nil) {
32 sharedController = [[self alloc] init];
02855d8 Initial import
Michael Gorbach authored
33 }
34
35 return sharedController;
36 }
37
f40f477 And more cleanup ...
Michael Gorbach authored
38 - (id)copyWithZone:(NSZone *)zone {
02855d8 Initial import
Michael Gorbach authored
39 return self;
40 }
41
435a21b Update code conventions and fixing some stupid bugs.
Michael Gorbach authored
42 - (id)init {
43 if (self = [super init]) {
f40f477 And more cleanup ...
Michael Gorbach authored
44 _pluginsDictionary = [[NSMutableDictionary alloc] init];
435a21b Update code conventions and fixing some stupid bugs.
Michael Gorbach authored
45 }
46
02855d8 Initial import
Michael Gorbach authored
47 return self;
48 }
49
435a21b Update code conventions and fixing some stupid bugs.
Michael Gorbach authored
50 - (NSArray *)pathsToPluginBundles {
02855d8 Initial import
Michael Gorbach authored
51 BOOL isDir = NO;
f40f477 And more cleanup ...
Michael Gorbach authored
52 NSFileManager *fm = [NSFileManager defaultManager];
435a21b Update code conventions and fixing some stupid bugs.
Michael Gorbach authored
53 NSArray *libraryPaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSAllDomainsMask - NSSystemDomainMask, YES);
54 NSMutableArray *pluginSearchPaths = [NSMutableArray array];
55 NSMutableArray *pluginPaths = [NSMutableArray array];
02855d8 Initial import
Michael Gorbach authored
56
435a21b Update code conventions and fixing some stupid bugs.
Michael Gorbach authored
57 for(NSString *path in libraryPaths) {
58 // TODO: Use plugin directory accessor.
59 NSString *specificPath = [path stringByAppendingPathComponent:@"Macfusion/Plugins"];
60 if ([fm fileExistsAtPath:specificPath isDirectory:&isDir] && isDir) {
02855d8 Initial import
Michael Gorbach authored
61 [pluginSearchPaths addObject:specificPath];
62 }
63 }
64
435a21b Update code conventions and fixing some stupid bugs.
Michael Gorbach authored
65 NSString *mainBundlePath = mfcMainBundlePath();
bc361ad Add a generic ability for plugins to subclass Server & Client Filesys…
Michael Gorbach authored
66 MFLogS(self, @"Main bundle path %@", mainBundlePath);
435a21b Update code conventions and fixing some stupid bugs.
Michael Gorbach authored
67 NSBundle *mainBundle = [NSBundle bundleWithPath: mfcMainBundlePath()];
68 NSString *pluginsPath = [mainBundle builtInPlugInsPath];
69 if (pluginsPath) {
1cb84dd Security system, UI refinement and other fixes. Ready for beta 1
Michael Gorbach authored
70 [pluginSearchPaths addObject: pluginsPath];
435a21b Update code conventions and fixing some stupid bugs.
Michael Gorbach authored
71 }
72 for(NSString *path in pluginSearchPaths) {
f40f477 And more cleanup ...
Michael Gorbach authored
73 for(NSString *pluginPath in [fm contentsOfDirectoryAtPath:path error:NULL]) {
435a21b Update code conventions and fixing some stupid bugs.
Michael Gorbach authored
74 if ([[pluginPath pathExtension] isEqualToString:PLUGIN_EXTENSION]) {
02855d8 Initial import
Michael Gorbach authored
75 [pluginPaths addObject: [path stringByAppendingPathComponent: pluginPath]];
76 }
77 }
78 }
79
80 return [pluginPaths copy];
81 }
82
f40f477 And more cleanup ...
Michael Gorbach authored
83 - (BOOL)validatePluginAtPath:(NSString *)path {
02855d8 Initial import
Michael Gorbach authored
84 // TODO: Plugin validation goes here, or maybe this should go into
85 return YES;
86 }
87
435a21b Update code conventions and fixing some stupid bugs.
Michael Gorbach authored
88 - (void)loadPlugins {
89 NSArray *pluginBundlePaths = [self pathsToPluginBundles];
90 for(NSString *path in pluginBundlePaths) {
02855d8 Initial import
Michael Gorbach authored
91 // TODO: What if different version of the same plugin are located in multiple places?
435a21b Update code conventions and fixing some stupid bugs.
Michael Gorbach authored
92 MFServerPlugin *newPlugin = nil;
93 if ([self validatePluginAtPath: path] && (newPlugin = [MFServerPlugin pluginFromBundleAtPath: path])) {
f40f477 And more cleanup ...
Michael Gorbach authored
94 [_pluginsDictionary setObject: newPlugin forKey: newPlugin.ID];
4cd156a Many, many changes. Macfusion2 is now useable.
Michael Gorbach authored
95 MFLogS(self, @"Loaded plugin at path %@ OK: %@", path, newPlugin.ID);
435a21b Update code conventions and fixing some stupid bugs.
Michael Gorbach authored
96 } else {
4cd156a Many, many changes. Macfusion2 is now useable.
Michael Gorbach authored
97 MFLogS(self, @"Failed to load plugin at path %@", path);
02855d8 Initial import
Michael Gorbach authored
98 }
99 }
100 }
101
435a21b Update code conventions and fixing some stupid bugs.
Michael Gorbach authored
102 - (MFServerPlugin *)pluginWithID:(NSString *)ID {
f40f477 And more cleanup ...
Michael Gorbach authored
103 return [_pluginsDictionary objectForKey:ID];
80b6ffa Parameter generation now works. Mounting to be working soon.
Michael Gorbach authored
104 }
105
435a21b Update code conventions and fixing some stupid bugs.
Michael Gorbach authored
106 - (MFServerPlugin *)pluginForFilesystem:(MFServerFS *)fs {
80b6ffa Parameter generation now works. Mounting to be working soon.
Michael Gorbach authored
107 return [fs plugin];
02855d8 Initial import
Michael Gorbach authored
108 }
109
435a21b Update code conventions and fixing some stupid bugs.
Michael Gorbach authored
110 - (NSArray *)plugins {
f40f477 And more cleanup ...
Michael Gorbach authored
111 return [_pluginsDictionary allValues];
4cd156a Many, many changes. Macfusion2 is now useable.
Michael Gorbach authored
112 }
113
435a21b Update code conventions and fixing some stupid bugs.
Michael Gorbach authored
114 - (NSDictionary *)pluginsDictionary {
f40f477 And more cleanup ...
Michael Gorbach authored
115 return [_pluginsDictionary copy];
4cd156a Many, many changes. Macfusion2 is now useable.
Michael Gorbach authored
116 }
117
02855d8 Initial import
Michael Gorbach authored
118 @end
Something went wrong with that request. Please try again.