Where do I save the database settings

I have a desktop program for one client. He has bought a new mac. When I install the program on the mac (with the use of Anydesk) The program can’t run because the settings of the connection aren’t saved.
If the program starts without the prefs file, it creates one and fills it with standard values.
( in /Users/ClientName/Library/Application Support/ClientName/ProgramName.pref)


Var prefFolder As FolderItem = SpecialFolder.ApplicationData.Child(mAppName)
If Not prefFolder.Exists Then
prefFolder.CreateAsFolder
End If

Var prefName As String = mAppName + “.pref”

mPreferencesFile = prefFolder.Child(prefName)

If mPreferencesFile.Exists = False Then

Var textOutputStream As TextOutputStream
Try
textOutputStream = TextOutputStream.Open(mPreferencesFile)
textOutputStream.Write(GetstandardData())
Catch e As IOException
MessageBox("Could not create, reason: " + e.Message)
Return False
Finally
textOutputStream.Close
End Try

end if

This works on all three of his macs, but not on the new mac.
The file isn’t created in the correct folder.

Is there a solution to this?
I can change the code to the new standard but I need to save the database settings somewhere…..

Thanks for the tips and help in advance.
Brian

Where exactly does the code fail? I had some very memorable fun with my app where it wasn’t possible to write into /Users/ClientName/Library/Application Support/ClientName/ . The users had to delete the ClientName folder and everything was working again.

Shouldn’t the second ClientName be YourAppName?

Also on macOS preferences are saved into a plist into the Preferences folder in the Library. Except if you have lots of complicated configuration data.

1 Like

in my database apps, if the préférence file is reset, I have a dialog that opens to ask for the setup, and saves the values to the pref file

The code doesn’t fail. It gives no error. It just can’t pass the refs code. Every time the programs start it tries to create the file and fails creating the file, without error. Then the standard values aren’t available and there it fails with a nice messagebox. (created by me)
I use the pref module written in 2014. So maybe Apple uses a different way now?

The error with the ClientName is mine, I copied the string from the info box and changed it so it would be a little more generic and not the actual values.

On all the other macs this works fine. Just the new one gives a fault, not even an error.

Thank you for the answers.

I am going to look into this. All I need to save is the database settings.
User, Password, Server, DatabaseName and Port.

I had once a problem with createasfolder, because a file (not a folder) already existed at the same place.
there should be a way to get an error message in your method.

PLists code also creates a file with almost the same code I have now.
It looks easier to use. But I have a class with all the properties so working with the variables is easy.

According to my other friend: (chatgtp)
textOutputStream = TextOutputStream.Open(mPreferencesFile)
should be:
textOutputStream = TextOutputStream.Create(mPreferencesFile)
And that newer macs could fail because of that.
He has been very unreliable in the past.

But I will try this.
And create more checks with the right message.

On macOS you may also look at the UserDefaults.
You can read/write key-value pairs via the defaults shell command.
For example:
Read all application settings:

defaults read com.apple.Finder

Read a single property:

defaults read com.apple.Finder WarnOnEmptyTrash

Write a property:

defaults write com.apple.Finder WarnOnEmptyTrash -bool true

There are several pages on web which show examples of the defaults shell command.

Still is.

In Xojo TextOutputStream.Open() should create or open a file, and TextOutputStream.Create() will create or recreate it, and you will lose all the contents.

Create a sample with tests and logs, collect the logs with paths, error codes, etc and track the issue with details on the target machine.

1 Like

/Users/ClientName/Library/Application Support/ClientName/ProgramName.pref

You used two times: ClientName.

I’m OK with the first, but the second one have to be the Bundle Identifier of your application.

Also, you do not tested the FolderItem(s) against Nil (only if .Exists).

Add a Break before:

mPreferencesFile = prefFolder.Child(prefName)

and run your code in the Debugger / watch the FolderItem values, etc.

HTH

The values were changed by me before putting it here, to save the innocent.

Thanks for the suggestions, but it works on my computer and on 4 of the clients ones. Only on the new mac it doesn’t.

Rename the folder name where the prefs file reside and run your application…

You need to know what OS he is using. Probably the… Ugh… Tahoe. What Xojo version are you using? I hope 2025r3+ because it uses the latest SDK targeting Tahoe support.

Not the issue.

I am using Xojo version 2025 Release 3. And I don’t know which version his new laptop is on.

Then it creates a new folder and a new prefs file with the standard values. Like it should. On my Mac mini that is.

1 Like

I just helped a customer with this because their license data wouldn’t delete.

Migration Assistant set the permissions wrong.

2 Likes

After you’ve figured out your immediate problem, consider whether a plain text file (like a plist) is an appropriately secure way to store this information. MacOS provides pretty good methods of storing and accessing usernames and passwords and your users would benefit from the added security.

1 Like

You are right, but I do save the password hashed. (crypto.Encript and crypto.Decript) And it is software for one company, so it is not in the cruel world out there.
But if you know a better way? I would like to hear from you.
Is it the UserDefaults like TomE mentioned?
I am trying to use them, but the examples aren’t in Xojo or even VB. So I need to translate them.

you could use macos keychain