Just curious about the current easiest way to access all my files via the Resources folder (text files, graphics, etc) that works on Mac and Windows and in Debug and the compiled app. I’ve looked at a few threads, but no consistent methods really. Version of Xojo is 2019 R1.1.
I currently use:
f = GetFolderItem("").Parent.Child("streets.txt")
f = GetFolderItem("streets.txt")
But this seems to put certain files in a AppData/Temp folder (Windows 10) that breaks if I do other stuff.
- use a copy file step to copy these resources into the Resources dir (which works regardless of debug / build)
- macOS and Windows DO have slightly different locations for the Resources Dir but its the same regardless of debug / built
so you just need one function like (not I wrote this entirely in the forums text editor so it may not be 100% )
Function ResourcesFolder() as Folderitem
// windows exe may use "Appname Resources"
// or a single "Resources"
// so you will want to handle that here
So how would I adapt my code above to use this properly?
f = ResourcesFolder.Child(“streets.txt”)
copy files steps & build automation were specifically designed to make it so you could easily and predicatably put things in to specific places relative to your app regardless of whether it was a debug build or a release build so you didnt have to have special code for “if this is a debug build then look here otherwise look there” as that is harder to test
Yep, not using R2 though, using 2019R1.1. The API 2.0 thing is keeping me away for the moment.
In your case.
f = SpecialFolder.GetResource("streets.txt")
get resource etc will read a single file
but if your copy step copied in a directory full of items (images, text files, etc) then you need a way to get the resources dir and then maybe a child of that
There is no “right way”, this is another consistency problem in the framework. For me, I use a single encrypted resource file (SQLite), With tables for images, strings and others.
Works on debug and compiled with an #If Debug use a fixed path, if not, load the SQLite Db from the app folder.
there is no SINGLE “right way” that does everything that every user wants
if all you want is something dead simple drag your “resources” into the IDE and just use the names everywhere is your code
its simple BUT has some drawbacks - you can never unload resources managed this way
that may or may not be an issue
slightly more complicated is to use a copy file step to copy whatever files to the Resources Dir
Then you can use SpecialFolder.GetResource( filename ) or Resource( filename ) to get the folder item
And even more complex is to use copy file steps to copy a directory of files (or an entire directory hierarchy) into the Resources
At this point SpecialFolder.Resources gets you to the resources folder and you have to navigate the rest on your own
- I’d edit my earlier post if I could to remove that method but I cant