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?
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.
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