Use of Resources folder

[quote=433297:@Dan Paymar]Or can I just write
dim f as FolderItem
f = GetFolderItem(“SpecialFolder.ApplicationData”).child(“OpVPdata”)
and save f for all access to all the data folders?[/quote]

That is the way you should do it.

If you do not mind: and to access items that at build and debugging time will go into the Resources folder of the app boundle :
Dim file As FolderItem = SpecialFolder.GetResource(“MyDb.sqlite”)
(cfr. Language Reference).

unless the item (for instance myPicture that refers to myPicture.png in the Resources folder) is already present in the IDE:
mycanvas.backdrop = myPicture

Save yourself some grief and add another level to the data folder path for the application itself:

Dim f as FolderItem = SpecialFolder.ApplicationData.Child”OptimumVP”) If not f.exists then f.CreateAsFolder f = f.child(“OpVPdata”) If not f.exists then f.CreateAsFolder
By having a folder for the app, if you ever decide to have different data like a prefs file, you have a single place to put it. It also makes it more convenient for the user to reset or uninstall the app if there’s a folder that matches the app name.

Why not just read them from SpecialFolder.Resources whenever they are needed? That seems to be where the IDE puts everyting that is a resource for my app (images, HTML files that the app will be loading into an HTMLViewer). And read/write user-specific data in SpecialFolder.Documents?

[quote=433297:@Dan Paymar]On startup, the app looks for OpVPdata in SpecialFolder.ApplicationData. If it’s not there, it puts a copy there.

Questions:
How do I do that copy?
If it’s a Windows system, what do I do with the Libs folder?[/quote]

i have a components folder next to in my application folder and i put all the html, special images etc in the folder for both mac and windows app… and keep the resource folder just for things that xojo generated.

That sounds like what I need to do, but I don’t understand how to do it.

all i did is when i need to use things in the components folder, i just use folderitem with child(“”).child(“Components”) and then follow what with whatever you need from there.

for me i have the both the windows and mac version of wkhtmltopdf and in the code use the right one when running on mac or on window

If you add all the read-only stuff for your app to a folder IN THE IDE (see below), then for both macOS and Windows all those items will be AUTOMATICALLY added to a Resources folder created by the IDE at build time.

macOS: the Resources folder sits INSIDE your .app. The actual executable for your .app ALSO sits inside the .app (inside the MacOS folder, to be exact). As I said before, to see INSIDE your .app, right-click on your .app and choose “Show package contents”.

Windows: the Resources folder will (at the build step), be created NEXT TO your .exe file. There will also be a Library folder that contains the .dll files your exe needs.

The IDE folder I’m referring to is from the Library pane within the IDE as I previously posted. It’s an organisational convenience item for use within your project and has nothing to do with any folder structure that exists after the build step. You drag it from the Library pane over to the project pane.

But child(“”) is going to let you down over and over again.
It isnt the same place when you compare debug and release builds.
And on a Mac, it isnt the same place if an app becomes translocated.
And finally, if this folder is put in the Applications folder (MAC) or Program files folder (Windows), nothing inside it will be writeable.
(That may not be an issue for you, but …)

Drag the stuff you need into the project… maybe as a zip file.
When your app starts, look for a folder Specialfolder.applicationdata.child(“yourappname”)
if it doesn’t exist, create it, and copy or unzip the files you have in your resources folder to it.

This always works, and the files are writable.

I still don’t know how to copy my OpVPdata folder into the SpecialFolder.ApplicationData folder

The Lang Ref is you friend :slight_smile:

[quote]FolderItem.CopyFileTo

Method
FolderItem.CopyFileTo(Destination as FolderItem)

Supported for all project types and targets.
If Destination is a folder, then the folder and its contents are copied into Destination.
Notes

If Destination is a file and the file already exists, the copy is aborted. You need to delete the existing file first. If there is an error, the LastErrorCode property contains an error code.
On Xojo Cloud, FolderItems that are copied using CopyFileTo cannot have their permissions changed. For now, the workaround is to use a Shell command:
#If TargetXojoCloud Then
Dim sh As New Shell
sh.Execute("chmod 666 " + f.ShellPath)
#EndIf
[/quote]

Thanks, Dave. Somehow I missed that when searching the ref. Can I also use that to copy my app to the Applications folder?

It would be great to have a little app that would copy OptimumVP.app or OptimumVP.exe to the Applications folder and copy the OpVPdata folder and all its contents to SpecialFolder.ApplicationData. Does anyone have an example of such an installer?

just put the required code in the app.open event.
If the files exist in the required location then do nothing, otherwise copy them
and what do you mean “copy the OpVPdata folder”… where does that exist (since I am ASSUMING you are following all the suggestions post previously)

“just put the required code…” doesn’t help me. Can you please offer an example of the required code?

Any why not a separate little installer program? The original data folder may not be available after the CD is ejected, so putting the code in the app would not help.

Sorry Dan… but I get the feeling that you are not really wanting to put much effort of your own into this, and from what I have read you do not seem to want to accept the supplied suggestions and still want to do it “your way” (a way that has been repeatly indicated as causing more issues than solution)… so you figure out “the required code”, and post it back here, and perhaps others will point out issues… but you need to show you are willing to put forth the effort.

If you need an installer, this may help: https://documentation.xojo.com/topics/windows/creating_an_installer_with_the_inno_setup_script_(64-bit_apps).html

Tried that link. Got “There is currently no text in this page.”

The forum messed up the last ) when it automatically created the URL.
I edited the link to fix it. Please try again.

With TPSF, you can very easily put all your documents in a subfolder of the Resources folder, both on Mac and Windows. I have been doing that for for all my programs, even the Windows store version. Note that new API apps are enclosed in the Windows equivalent of the Macintosh bundle. And it is recommended not to try and write next to the executable.

[quote=433340:@Dan Paymar]“just put the required code…” doesn’t help me. Can you please offer an example of the required code?

Any why not a separate little installer program? The original data folder may not be available after the CD is ejected, so putting the code in the app would not help.[/quote]

You have example code in the thread.

The ApplicationData folder is on your computer, in the system files. It is not in the removable media.