What's the correct way to obtain the FolderItem for myApp/Libraries?

Currently, to get the resources folder of an App, one just gets the value of SpecialFolder.Resources
But the docs don’t expose the equivalent for Libraries

What’s the blessed way of doing it?

Do we miss a SpecialFolder.Libraries property needing a Feature Request?

There are TWO Libraries folders in macOS (last time I checked).

I said the app embedded libs, not the OS libs.

In macOS, the libs seems to go in "<path to my app>/Contents/Frameworks", other OSs it varies

There must be a standardized way to get it.

You could use

SpecialFolder.Resources.Parent.Child("Frameworks")

1 Like

That won’t work for Windows, nor Linux.

So I guess we need a SpecialFolder.Libraries or SpecialFolder.Frameworks

Back in the API 1.0 days I wrote a module for this since there wasn’t even SpecialFolder.Resources at the time. Feel free to take a look:

2 Likes

Great resource Tim, so I see we should need another entry in SpecialFolder to accommodate this missing feature, maybe like what I said here What's the correct way to obtain the FolderItem for myApp/Libraries? - #5 by Rick_A

I do think it would be a good idea, perhaps file a ticket.

2 Likes

Tested only under Windows, but my current implementation is:

Protected Function LibrariesFolder() As FolderItem
  
  #If TargetMacOS then
    
    Return SpecialFolder.Resources.Parent.Child("Frameworks")
    
  #ElseIf TargetWin32 Or TargetLinux Then
    
    Var baseName As String = app.ExecutableFile.Name
    If baseName.Right(4)=".exe" Then baseName = baseName.Left(baseName.Length-4)
    
    Var libFolder As FolderItem = App.ExecutableFile.Parent.Child(baseName + " Libs")
    
    If libFolder <> Nil And libFolder.IsFolder Then Return libFolder
    
    Return App.ExecutableFile.Parent.Child("Libs")
    
  #Else
    
    Return Nil // Not supported
    
  #EndIf

End Function

Does your code work for console apps?
I’m not in front of a Windows computer at the moment, but, as I recall, the layout is different between desktop and console apps.

Tested right now, on Windows, debugging a console asdf.exe, and it found and reported correctly those files

image

I tested it on a Mac now. Found it true for Macs (desktop vs console). So I modified it accordingly:

Public Function LibrariesFolder() As FolderItem

  #If TargetDesktop And TargetMacOS then
    
    Return SpecialFolder.Resources.Parent.Child("Frameworks")
    
  #ElseIf TargetWindows Or TargetLinux Or TargetMacOS Then
    
    Var baseName As String = app.ExecutableFile.Name
    
    #If TargetWindows Then
      If baseName.Right(4)=".exe" Then baseName = baseName.Left(baseName.Length-4)
    #EndIf
    
    Var libFolder As FolderItem = App.ExecutableFile.Parent.Child(baseName + " Libs")
    
    If libFolder <> Nil And libFolder.IsFolder Then Return libFolder
    
    Return App.ExecutableFile.Parent.Child("Libs")
    
  #Else
    
    Return Nil // Not supported
    
  #EndIf
  
End Function