applications resource folder

What is the best way to access a file in the applications resource folder?
Currently I have something like this:

dim f as FolderItem = GetFolderItem ("C:\\XoJo Projects\\test\\subdirectory\\part.png", FolderItem.PathTypeNative)
If f <> Nil And f.Exists Then
  
End If


If f <> Nil Then
  If f.Exists Then
    // Be aware that TextInputStream.Open coud raise an exception
    Dim t As TextInputStream
    t = TextInputStream.Open(f)
    t.Encoding = Encodings.SystemDefault
    Try
      ImageWell1.Image=Picture.Open(f)
      
    Catch e As IOException
      t.Close
      MsgBox("Error accessing file.")
    End Try
    
  end if
end if

I need this to work on both Windows and Linux.

You need to copy the file itself to the built app. Images can be done by either dragging them into the Navigator or by using a Copy Files build step. Once you set up your Copy Files build step, you can use my TPSF module to access files copied into your app with a Copy Files step.

TPSF makes it easy to get to files copied via Copy Files step on all three desktop platforms.

Git repo:
https://github.com/devtimi/TPSF

Still need help. Not sure which method to use. I have the image files copied into a folder within the project. How do i get it so that
“ImageWell1.Image=Picture.Open(f)” has the correct file name and path.

I think these are the options to work with:

When the image file has been dragged into the project, call it just by its name.

When your compiled application copies the image into its Application Support folder,
call it with SpecialFolder.ApplicationData.child…

During debugging, call the file with your code line seen above:_

dim f as FolderItem = GetFolderItem ("C:\\XoJo Projects\\test\\subdirectory\\part.png",

This is my function for Mac and Windows:

[code]Function GetResourceFolder() As FolderItem
// Return build-resourcefolder

#If TargetMacOS Then

Static fldRscMac As folderitem
If fldRscMac = Nil Or fldRscMac.exists = False Then
  Declare Function NSClassFromString Lib "AppKit" ( className As CFStringRef ) As Ptr
  Declare Function mainBundle Lib "AppKit" selector "mainBundle" ( NSBundleClass As Ptr ) As Ptr
  Declare Function resourcePath Lib "AppKit" selector "resourcePath" ( NSBundleRef As Ptr ) As CfStringRef
  fldRscMac = GetFolderItem( resourcePath( mainBundle( NSClassFromString( "NSBundle" ) ) ), folderItem.pathTypeNative )
End If
Return fldRscMac

#ElseIf TargetWin32 Then

Dim fldRscWin As FolderItem = App.ExecutableFile.Parent.Child("Resources")
If fldRscWin.Exists Then
  Return fldRscWin
Else
  Dim pathStringVar As String = App.ExecutableFile.NativePath
  pathStringVar = pathStringVar.Left(pathStringVar.Len - 4) + " Resources"
  Return GetFolderItem(pathStringVar)
End

#EndIf
End Function[/code]

The Mac part I’ve taken somewhere else from this forum.

The Mac declares style of writing seems familiar…

Over spaced, it kind of looks like your code, Sam. :stuck_out_tongue:

[quote=331949:@James Wolfe]Still need help. Not sure which method to use. I have the image files copied into a folder within the project. How do i get it so that
“ImageWell1.Image=Picture.Open(f)” has the correct file name and path.[/quote]

ImageWell1.Image = Picture.Open(TPSF.Resources.Child("part.png"))