GetFolderItem - problems

Platform : MacOS X
I have created an application with Real Basic and compressed the application bundle.
I sent the compressed application bundle through email (gmail to be specific).
The recipient downloaded the compressed file and unzipped it on this computer.
When executing the application, it fails to recognise a key file that is located in the
same folder as the application bundle. The file is referred to in the application
in the following way :

Dim f FolderItem
f = GetFolderItem(“license_key.txt”)

But strangely when I transfer the compressed file through file transfer using TeamViewer,
it works.

Any guidance please ?

P.Chellappan

Search the forum for “Gatekeeper”. This is an issue with Mac security.

[quote=349189:@Chellappan Palaniappan]Dim f FolderItem
f = GetFolderItem(“license_key.txt”)[/quote]

Don’t do that. Place the file in the project, and then access it with TPSF from Tim Parnell http://timi.me/xojo

Or directly, since Xojo will present it as a string.

I tried disabling Gatekeeper, still the problem persists.
I put in a message box to display the absolute path from the following GetFolderItem
f = GetFolderItem(“license_key.txt”)

The absolute path returns : 9850FE57-6CAF-4778-8198-D79075B6C27F:d:license_key.txt

But when I copy the application through File Transfer in TeamViewer, the absolute path is displayed
correctly.

P.Chellappan

If you ship the licence key with the product, why have a licence key at all - doesnt everyone get the same one?

The license key is not shipped with the product.
The software is downloaded and when executed for the first time,
it generates a license request file.
Upon receipt of the license request, a license key is generated
and the client downloads the license key.

P.Chellappan

If so, then [quote]'Place the file in the project, and then access it with TPSF '[/quote] isn’t valid advice, because it assumes the file is in the project bundle, not downloaded.

If it is downloaded, what does the code which SAVES it look like?
If it saves to ‘a place’, and loads from ‘the same place’, it should work no matter where your app is.

Better, if you download a file, is to put the file into ApplicationData, not local to your app.
Then if the app is moved to a new folder, it keeps working

But these are work arounds. I prefer to keep the license key file in the same folder. Any reason why this strange thing happens ? Cannot it be solved ?

P.Chellappan

Most operating systems no longer allow you to modify the application / program folder due to potential security risks… Use the appropriate system approved areas - application data folders for application data and documents for user created documents… less headaches this way…

Actually, the location where the file is saved to and read from is the same location.
I do not think the problem with GetFolderItem is related to the operating system, because when I copy the application through file transfer in Team Viewer, it works fine. Even if I file transfer the compressed application through Team Viewer, unzip it and execute the application it works fine.
The problem crops up only when I send the compressed file through wetransfer or email.

I am sorry, I did not realize you wanted to write to the file.

Jeff is right. If you try to write to the file next to the bundle in /Applications, chances are your app does not have the proper privileges. If you do what I told you and try to write in the bundle in a sandboxed app, that will generate an error.

The fact that Team Viewer works is probably due to it’s higher privileges.

The PROPER way to proceed would be to create a folder in Specialfolder.ApplicationData with the name of the bundle, and then save your license file there, where it is safe. That is how all current Mac applications do, and what is recommended by Apple.

And Windows as well… They started the whole virtual Programs Folder and Registry for programs that still expected this behaviour…

Thanks. I will try it out.

But just for the sake of understanding, if the OS restricts writing into the Application folder, it should do it regardless of wether the compressed application is downloaded from the internet or file transferred trough TeamViewer.
But the reported problem occurs only when it is downloaded from the internet but works fine otherwise.
Is this a bug or is it something I am not understanding ?

Restricted access is the same. Did you check out what Gatekeeper is? It virtualises the path of the app so that the the path isn’t applications/appname anymore but some sort of different path. This is why your app can’t even find the license.

Thanks. But the problem occurs even after I disable Gatekeeper.

That’s not entirely true. Security is categorized in zones. That is, where a file or program comes from is just as important as who downloads it. Downloading from the internet is considered high-risk and the OS will take measures to protect itself.

OK. Thanks.

When your application is downloaded from the internet, it will run in a “translocated” (read only) location on your system.
You can check this by launching Activity Monitor, selecting your application, clicking the i (information) button in the upper left and then selecting the Open Files and Ports tab. You should see that the path to your application includes /AppTranslocation/ as well as a very long random string.

If the user manually moves the application (in the finder) to any location that is different than then download location, then the application should no longer be translocated when it runs. Apple assumes that if the user manually moves the application to a new location in the Finder, then they are aware of its existence and approve of it being executed.

The other option is to manually remove the quarantine flag in terminal.

xattr -d com.apple.quarantine [path to your app]