我以前認爲文件夾需要有擴展名,以便它們被Finder識別爲包。該擴展將在所屬應用程序的Info.plist中聲明。如何將一個文件夾標記爲一個包?
顯然還有另一種更優雅的方式,但我無法弄清楚它是如何完成的。
E.g. iPhoto圖庫被Finder視爲一個包。但它沒有延伸。 mdls顯示它確實在內容類型樹中有「com.apple.package」。實際的內容類型是動態分配的。
iPhoto如何創建這樣的目錄?
我以前認爲文件夾需要有擴展名,以便它們被Finder識別爲包。該擴展將在所屬應用程序的Info.plist中聲明。如何將一個文件夾標記爲一個包?
顯然還有另一種更優雅的方式,但我無法弄清楚它是如何完成的。
E.g. iPhoto圖庫被Finder視爲一個包。但它沒有延伸。 mdls顯示它確實在內容類型樹中有「com.apple.package」。實際的內容類型是動態分配的。
iPhoto如何創建這樣的目錄?
雖然你不應該完全依賴它,但有一件事是設置文件的包位。我已經有了NSWorkspace類別來做到這一點:
- (void)setBundleBit:(BOOL)flag forFile:(NSString *)path
{
FSRef fileRef;
OSErr error = FSPathMakeRef((UInt8 *)[path fileSystemRepresentation], &fileRef, NULL);
// Get the file's current info
FSCatalogInfo fileInfo;
if (!error)
{
error = FSGetCatalogInfo(&fileRef, kFSCatInfoFinderInfo, &fileInfo, NULL, NULL, NULL);
}
if (!error)
{
// Adjust the bundle bit
FolderInfo *finderInfo = (FolderInfo *)fileInfo.finderInfo;
if (flag) {
finderInfo->finderFlags |= kHasBundle;
}
else {
finderInfo->finderFlags &= ~kHasBundle;
}
// Set the altered flags of the file
error = FSSetCatalogInfo(&fileRef, kFSCatInfoFinderInfo, &fileInfo);
}
if (error) {
NSLog(@"OSError %i in -[NSWorkspace setBundleBit:forFile:]", error);
}
}
據我所知,文件和協議僅在您的應用程序Info.plist中設置。
掃描應用程序,並將其plist中的信息添加到LaunchServices設置中。
Linkinus有6種不同的文檔類型聲明,TextMate有97和CyberDuck有3個。我會做一些更多的搜索,但我認爲這可能是首選的方法。
有兩個命令可能會感興趣:
GetFileInfo iPhoto\ Library
attributes: avBstclinmedz
在B說,「捆綁」位。 SetFile
命令可讓您設置它們。這些讓你訪問HFS +中的擴展屬性(每個手冊頁)。
下面是可能的屬性:
A Alias file
B Bundle
C Custom icon*
D Desktop*
E Hidden extension*
I Inited*
M Shared (can run multiple times)
N No INIT resources
L Locked
S System (name locked)
T Stationery
V Invisible*
Z Busy*
歷史註釋:最初是用於文件的包位,並意味着文件已經在它「BNDL」資源。 Finder將從遇到的任何文件中讀取捆綁軟件資源,該文件包含已設置的捆綁位並且沒有設置入口位。現在,Info.plist文件實現了'BNDL'資源的功能,捆綁位主要用於目錄,它告訴查找和導航服務將目錄當作文件處理(即它使得目錄一個包)。 – 2009-11-18 17:31:22
爲什麼你把這個放在NSWorkspace上?它不使用NSWorkspace的「自我」指針。 – adib 2010-07-11 17:28:12
我認爲它應該是NSWorkspace或NSFileManager來匹配可可的其餘部分。不記得爲什麼我解決了前者。無可否認,在編寫這段代碼之後,它在NSURL上可能會更好。 – 2010-07-15 18:31:36