Accessing the app's Resource folder

“Games may not be where you think it is.”
After the earlier discussion, this should have been obvious to me. Thanks for the knock on the head.

So what I need is a path to the Games folder, which is in the folder where the installer app was before the OS moved it.

But I don’t understand how your example code would help me do that. How do I get a path back to the Installer folder?

Actually, if I’m now understanding the situation, the Games folder is still in the Installer folder where I thought it was, but a simple GetFolderItem(“Games”) won’t work because the app is not actually running from that folder.

Which leaves me with the problem of an absolute path back to the Installer folder so I can find the actual data folders.

How about if I assume that the Installer folder is on the desktop? What would be the path?

Dan, can you tell us if you are putting “Games” directory inside Resources or next to your app? Jeff code can find the Resources directory used by your app.

“Games” is one of three folders, each containing several data files. All are in the Installer folder, which also contains the installer app.

See my code above, which works fine when the app is actually running from that folder.

Since the newer OS copies the app to somewhere else before it is run, it needs a path back to its folder.

Can you move those folders into the Resources folder?

From what I understand, everything inside Resources is copied too, your directories next to the app will not be copied. Then you can use Jeff’s code to find and work with the Resources folder.

If I understand, you want me to provide written instructions to my customer, who likely knows next to nothing about the system, to manually copy the data folders to somewhere in their system before running the installer.

Wouldn’t it be easier to forego the installer, and tell the customer to manually copy the folders to their SpecialFolder.ApplicationData folder?

Either way, there’s only about a thousand ways that could go badly.

All I need is a path back to the Installer folder.

I guess I don’t fully understand your problem.

I don’t expect your users to change anything, I expect you to release a new version (with code changes and directory structure changes) so your users can just install your app with the new rules that Catalina requires. If you don’t change your code your app will not work.

Oh, now I think I’m finally getting a grasp on this. I thought you were referring to some Resources folder in the OS.

I should put the data folders in the app’s Resources folder so that after the OS copies the app and its resources to who-knows-where, Jeff’s code will return FolderItem f to point to that Resources folder, and my current code can copy from there to the SpecialFolder.ApplicationData folder. Correct?

Will this work for all Macs 10.9 and later, and for all Windows 7 and later? If not, can you tell me exactly which systems it will work on?

Sorry for being so dense. I have 62 years programming experience, but nearly all of that has been in machine code or assembler so I was talking directly to the computer. Putting a very complex, ever changing OS and a compiler between me and the hardware is a whole new world. No sooner do I solve a problem when an OS update creates a new one.

[quote]If I understand, you want me to provide written instructions to my customer, who likely knows next to nothing about the system, to manually copy the data folders to somewhere in their system before running the installer.
[/quote]
No-one said that

You aren’t talking about an installer.

A Mac app, living in ‘Applications’… is actually a folder
Inside that is a folder called Resources
If you place your folders in there before packaging up the app, then the files and folders are in my ‘SpecialFolderResources’

You can do that placement at build time using a CopyFiles step in the build, or manually just before codesigning and packaging.

at run time, you make your source like this

Dim Source as folderitem source = SpecialfolderResources source = source.child("Games") //now copy it

Under Windows, you have choices…
You can make it do what the Mac does, and have your installer copy the Games Folder to the Resources folder where the app lives, and my code will work there too.

OR
You make the Windows Installer package copy Games to the ApplicationData folder as part of the install.

Mac App:

Windows App folder in Program Files:

[code]/Appname
/ Appname.exe
/ Appname Resources
/ Libs

[/code]

I followed this conversation for a while. It is apparent you have a very foggy idea about translocation.

It actually happens in Sierra, High Sierra, as well as Catalina. Any new app is moved to a safe location where it is executed the first time around.

If you have files that can be read only, you can simply copy them with a copy files step so they rest in the Resources folder to be used when the app runs. That is the only acceptable way to do it with recent Mac systems.

Let us say you have a file called “myGamePlan.txt”, inside the “Games” folder, in the Resources folder, all you have to do to access it, is

SpecialFolder.Resources.Child("Games").child("myGamePlan.txt")

Note that since the file is inside the app bundle, it will be found no matter the name of the executable, or if the app is translocated.

Now, if you need to write to the files, the best way would be to copy the files to Application data, within a subfolder by the same name as the application ID.

This is how you do it the first time your app runs:

Dim f as folderitem = Specialfolder.ApplicationData.child("com.mysoftwarecompany.greatgame") If not(f.exists) then f.createasfolder dim source as folderItem = Specialfolder.Resources.child("Games") If sources.Exists then sources.copyfileto(f) end if

You can then access files as for instance

Specialfolder.ApplicationData.child("com.mysoftwarecompany.greatgame").Child("Games".Child("myfile.txt")

These files are not deleted by the system, and will persist between runs.

Note that this scheme works fine under Windows as well, whatever the installer, debug run or not.

Michel, you’re right that my 82-year-old brain is somewhat foggy on the idea of translocation, in fact foggy on all the complications of overblown operating systems. But it’s strange that my program works fine on Sierra, High Sierra and Windows 10 with just keeping the data folders in the same folder as the app. I’m sure some of my customers are running it on Mojave, so it appears to be a problem only on Catalina.

The rest of your post appears to apply only if my data files were to be read only, but as I’ve said that’s not the case, so I think Jeff’s code is more pertinent, to be placed ahead of my current installer code.

I have incorporated Jeff’s code into my installer app, but it seems it can’t work in debug mode since the app doesn’t yet have a Resources folder where I can put the data folders. Is there any way around this?

When you hit run (on Mac) an app is created, you can open its contents (justatest.debug.app):

then navigate to the resources folder:

or you can build the app and then add the folders, and test after that.

Thanks, everybody. I’ve learned a few things today.

My installer appears to be working properly. Now I need to have someone test it on Catalina. My computers are too old to run Catalina.

Oh yes… :frowning:

Read again what my 68 years old brain has offered.

The last part of my post is precisely how to safely place the files where you can read and write.

Xojo will create the Resources folder in Windows, but on Mac, the Resources folder is inside the .app. To see it, right click (Ctrl-Click) on the .app and select “Sow package content”.

Contrary to what you think, there is always a Resources folder, debug or not debug.

Use a copyfiles step to place your folders and files in the Resources folder.

Insert menu/Build Step/Copy Files.

In the right hand side pane, select “both” (by default), and select “Resources folder”.

That way Xojo automatically places all the files you need in the resources folder.

May I suggest you indicate a subdirectory by the name of your app ID, such as “com.matchsoftware.mygreatapp”.

I have just one more thing that the Installer should do – Copy the app to the Applications/Programs folder, and put an alias/shortcut on the desktop. I haven’t been able to get my code to do that.

Is it true that I can install the app essentially the same way as the data folders? That is, put the app in the installer’s Resources folder?

So what is the path to the system’s Applications folder? Would it be simply “Specialfolder.Applications”?

And how about for Windows?