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…..
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.
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.
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:
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.
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.
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.
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.