通常、Cocoa アプリでは、いくつかの場所のいずれかにプラグイン バンドルをインストールできます。たとえば、アプリの名前が「MyApp」の場合、次の場所にプラグインをインストールできます。
- /アプリケーション/MyApp.app/コンテンツ/プラグイン
- ~/Library/Application Support/MyApp/PlugIns
- /ライブラリ/Application Support/MyApp/プラグイン
- /Network/Library/Application Support/MyApp/PlugIns
正しい順序で検索するためのパスを作成してNSArray
いますが、Apple が多くの機能を提供しているように見えるものに対してあまりにも多くの作業を行っているように感じるので、これは間違っていると確信しています。
NSArray *systemSearchPaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSAllDomainsMask, YES);
NSMutableArray *searchPaths = [NSMutableArray array];
NSFileManager *fileManager = [NSFileManager defaultManager];
for (NSString *systemPath in systemSearchPaths) {
NSString *systemPluginsPath = [systemPath stringByAppendingPathComponent:@"PlugIns"];
// FIXME: Remove debug code
NSLog(@"Considering plugin path %@", systemPluginsPath);
if ([fileManager fileExistsAtPath:systemPluginsPath]) {
[searchPaths addObject:systemPluginsPath];
}
}
[searchPaths addObject:[[NSBundle mainBundle] builtInPlugInsPath]];
NSSearchPathForDirectoriesInDomains
これにより、builtInPlugInsPath
末尾に値が追加された Array が返されます。
ただし、実際には「~/Library/Application Support/PlugIns」(「MyApp」がない) フォルダーなどのディレクトリを検索します。コードをハッキングしてアプリケーションの名前を挿入する前に (これはいつでも変更される可能性があります)、これは間違っていますか?
Cocoa に「このアプリケーションの「プラグイン」ディレクトリのすべての検索パスを教えて」と伝える方法はありますか?