63000 - Add a FolderItem.IsPackage instruction

Feedback Case Number: 63000

A member of Xojo team gave me the solution with Declare, but I think a FolderItem.IsPackage would be welcome.
There are many package ( . app , .rtfd and so on) which may be considered as file by our program (when we through each item of a folder).

When the Lib will be deprecated, I will have to ask again help to find news Declare instructions.

2 Likes

Not all declares get ever deprecated; there are still declares from earlier version of MacOS X (possibly since the first release) used these days.

Asking for a not cross-platform function may not always succeed in Xojo (look at a lot of OS features not available directly because they target a single platform).

As I understand it, the basic rule of a package is a folder with a file extension that is registered on the system.

Yes, I believe it’s true. LaunchServices knows extensions that make a folder being a bundle and registers them like other documents (e.g. upon app’s first launch/discovery).

I do it this way:

	Function IsThisAPackage(fi As FolderItem) As Boolean
	  Try
	    
	    Dim fiInfoPlist As FolderItem = fi.Child("Contents").Child("Info.plist")
	    Dim t As TextInputStream
	    Dim tAll As String
	    
	    If (fiInfoPlist <> Nil) _
	      And fiInfoPlist.Exists Then
	      Try
	        
	        t = TextInputStream.Open(fiInfoPlist)
	        tAll = t.ReadAll(Encodings.UTF8)
	        
	      Catch e As IOException
	        t.Close
	        Return False
	      End
	      
	      t.Close
	      If InStr(tAll, "CFBundle") > 0 Then Return True
	    End If
	    
	    Return False
	    
	  Catch
	    Return False
	  End
	  
	End Function

What’s the result of a call asking for info for an URL that does not result in a bundle?
Maybe just one call can solve this without false positives.

https://developer.apple.com/documentation/corefoundation/1537156-cfbundlegetpackageinfoindirector

If a folder is a document bundle, it may not contain a “Contents” folder at all.
Only its parent application would define the folder’s extension as a bundle, but your code wouldn’t catch this.

1 Like

Add false negatives to my comment too. :smile:

How about FolderItem.isBundleMBS function in MBS Xojo Plugins?

1 Like

If one has your plugin…

But, using macOSlib one could do it this way:

Dim bundleURL As CoreFoundation.CFURL
bundleURL = CFURL.CreateFromPOSIXPath(fi.NativePath, True)
Return bundleURL.IsPackage

Wouldn’t be something like CFURLCreateWithFileSystemPath() a better current option?

https://developer.apple.com/documentation/corefoundation/1543250-cfurlcreatewithfilesystempath

But they could do better. This would just always return false on other platforms. Simple.

3 Likes

Mac is minority here, if such need were used in more OS’s, like Android, or Windows, or Linux, it would be eligible. In some other frameworks, it would be isolated on some platform specific set of functions, like a Mac.FileUtils.*, and the same would occur for others, like Windows.FileUtils.*. This way the “core” crossplatform classes would not include platform specific things, but could be extended… when such extensions were included.

I see a mixture of different things here, and confusion. What is it exactly that you are trying to accomplish?

A bundle is a package, but a package may not be a bundle.

This made me curious, so I searched for some info and found this great article:

Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.