Include File In App Data Folder

Is there any way to include an existing file (somefile.bin) into an apps data folder so the app could use this file at run time?

Under Build use the CopyFile feature.

David, thanks for the reply. I don’t think this will work as the apps data folder is created at run time.

If you just drag the file into your project, it should be included. You may need to change its extension to .txt to get Xojo to allow you to import it, however. But it could be a binary type. I do this with a VirtualVolume file I embed inside my app (it contains installer items).

The CopyFile feature of Build scripting could also work – you just have to add the script after the build step.

Thanks Marc. Unfortunately, if I drag the file into the project it is crated as a string. It looks like converting this string back into the original binary file would be very difficult. Not familiar with build scripting - is there any source for info on this?

If you drag it into your project it’s basically a constant.
You can then just write it out to a file.

Yes, that’s what I do in my app.

But since build scripting is free with Xojo now, that might be a better approach. As for documentation, I just wrote an article about IDE and Build Scripting (among other topics) in the latest issue of xDev Magazine which might help.

[quote=26572:@Marc Zeedar]Yes, that’s what I do in my app.

But since build scripting is free with Xojo now, that might be a better approach. As for documentation, I just wrote an article about IDE and Build Scripting (among other topics) in the latest issue of xDev Magazine which might help.[/quote]

Right but in the bundle on OS X isn’t the App Data dir.
So it might be something like we do in the IDE where it is in the bundle and on first launch the file gets written to the app data dir.
That way if it ever gets deleted it can be replaced from the item in the bundle.

The Language Reference works that way as it has to be in a location that it’s writeable so on launch we check to see if its installed & if not we copy it there and continue on

[quote=26576:@Norman Palardy]So it might be something like we do in the IDE where it is in the bundle and on first launch the file gets written to the app data dir.
That way if it ever gets deleted it can be replaced from the item in the bundle.[/quote]

That’s exactly the way I do it with my app – it self-heals any installation items (documentation, spelling dictionary, etc.) that the user might have removed that the app needs to run.

Since I started this topic, I would like to let you know how I solved this issue. When dragging the binary file into the project, it appears in the project as a large string with the name for example file1. The original file1 was an array of structures in a binary file. So, I extracted from file1 in a loop each individual structure using its size parameter and then wrote these individual structures to a binary file in the data folder using a binary stream. This worked quite well but seems like a lot of coding for what I thought should be a simple task.

Thanks for all who gave suggestions on this problem. Any critique of what I have described here is welcome.

Jim

open the binary file
write it to the output file
no need to parse it to write it since its just a blob of data

that is assuming the entire thing can just be written to one file ?

Norman, you are very right. My parsing was not necessary. I just wrote the file1 to the data folder as a binary stream and that worked great. thanks for pointing out my error. This is now much simpler.

Jim