Xojo Conferences
XDCMay2019MiamiUSA

Platforms to show: All Mac Windows Linux Cross-Platform

/MacCF/CFBundle example
Function:
Required plugins for this example: MBS MacCF Plugin, MBS Main Plugin, MBS Util Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /MacCF/CFBundle example
This example is the version from Mon, 16th Mar 2014.
Project "CFBundle example.rbp"
FileTypes
Filetype special/folder
Filetype special/application
End FileTypes
Class Window1 Inherits Window
Control ListBox1 Inherits ListBox
ControlInstance ListBox1 Inherits ListBox
End Control
Control PushButton1 Inherits PushButton
ControlInstance PushButton1 Inherits PushButton
EventHandler Sub Action() AllBundlesWindow.Show End EventHandler
End Control
EventHandler Sub DropObject(obj As DragItem, action As Integer) do if obj.FolderItemAvailable then run obj.FolderItem end if loop until not obj.NextItem End EventHandler
EventHandler Sub Open() dim f as FolderItem AcceptFileDrop "special/folder" AcceptFileDrop "special/application" f=ApplicationsFolderMBS(-32766).Child("Image Capture.app") run f End EventHandler
Sub addrow(a as string,b as string) ListBox1.AddRow a ListBox1.cell(ListBox1.LastIndex,1)=b End Sub
Sub run(f as folderItem) dim u as CFURLMBS dim d as CFDictionaryMBS dim c as CFBundleMBS ListBox1.DeleteAllRows if f<>Nil and f.Exists then u=NewCFURLMBSFile(f) if u<>nil then c=CreateBundleMBS(u) if c<>nil then d=c.GetLocalInfoDictionary if d<>Nil then d=c.GetInfoDictionary end if if d<>nil then addrow "Name: ",st(c.GetValueForInfoDictionaryKey(c.kCFBundleNameKey)) addrow "Version: ",st(c.GetValueForInfoDictionaryKey(c.kCFBundleVersionKey)) addrow "Executable: ",st(c.GetValueForInfoDictionaryKey(c.kCFBundleExecutableKey)) addrow "Identifier: ",st(c.GetValueForInfoDictionaryKey(c.kCFBundleIdentifierKey)) addrow "Info Dictionary Version: ",st(c.GetValueForInfoDictionaryKey(c.kCFBundleInfoDictionaryVersionKey)) addrow "Development Region: ",st(c.GetValueForInfoDictionaryKey(c.kCFBundleDevelopmentRegionKey)) addrow "Type: ",c.PackageMacType addrow "Creator: ",c.PackageMacCreator addrow "Resource folder: ",ur(c.ResourceDirectory) addrow "Support folder: ",ur(c.SupportFilesDirectory) addrow "Frameworks folder: ",ur(c.SharedFrameworksDirectory) addrow "Private Frameworks folder: ",ur(c.PrivateFrameworksDirectory) addrow "Plugins folder: ",ur(c.BuiltInPlugInsDirectory) else ListBox1.AddRow "No Info Dictionary" end if else ListBox1.AddRow "CreateBundleMBS failed." end if else ListBox1.AddRow "NewCFURLMBSFile failed." end if else ListBox1.AddRow "File not found!?" end if End Sub
Function st(o as cfobjectMBS) As string dim s as CFStringMBS if o isa CFStringMBS then Return CFStringMBS(o).str end if End Function
Function ur(u as cfurLMBS) As string if u<>nil then Return st(u.PosixFileSystemPath) end if End Function
End Class
MenuBar Menu
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu2 = "File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu0 = "Edit"
MenuItem EditUndo = "Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cut"
MenuItem EditCopy = "Copy"
MenuItem EditPaste = "Paste"
MenuItem EditClear = "Clear"
End MenuBar
Class App Inherits Application
End Class
Class AllBundlesWindow Inherits Window
Control List Inherits ListBox
ControlInstance List Inherits ListBox
End Control
EventHandler Sub Open() dim url as CFURLMBS dim f as FolderItem dim a as CFArrayMBS dim i,co as integer dim c as CFBundleMBS dim o as CFObjectMBS dim d as CFDictionaryMBS dim s as String dim cs as CFStringMBS dim r as IntegerRectMBS f=ApplicationsFolderMBS(-32766) url=NewCFURLMBSFile(f) a=CreateBundlesFromDirectoryMBS(url,NewCFStringMBS(".app")) if a=nil then MsgBox "no bundles found!?" else co=a.Count-1 for i=0 to co o=a.Item(i) if o<>Nil and o.Type=kCFBundleMBSTypeID then // Make a CFBundle object from the CFObject c = CFBundleMBS(o) // display cs=c.Identifier if cs<>nil then s=cs.str else s="" end if List.AddRow c.PackageMacCreator+" "+c.PackageMacType List.Cell(list.LastIndex,1)=s d=c.GetInfoDictionary if d<>Nil then o=d.Value(c.kCFBundleNameKey) if o<>nil then List.cell(List.LastIndex,2)=CFStringMBS(o).str end if o=d.Value(c.kCFBundleVersionKey) if o<>nil then List.cell(List.LastIndex,3)=CFStringMBS(o).str end if end if url=c.URL if url<>nil then List.cell(List.LastIndex,4)=url.Path.str end if end if next end if // Maximum size for this window r=GetAvailableWindowPositioningBoundsMBS if r<>Nil then Left=r.Left+10 top=r.Top+30 Width=r.Width-20 Height=r.Height-40 end if End EventHandler
End Class
End Project

Feedback, Comments & Corrections

The items on this page are in the following plugins: MBS MacCF Plugin.




Links
MBS Xojo PDF Plugins