SpecialFolder.ApplicationData vs path=SpecialFolder.SharedApplicationData

Hi. I’m writing a software that saves some settings in the Application data.

First I create the folder item like this

file= new folderitem(SpecialFolder.ApplicationData.NativePath+“/My Software/”+“My File.txt”)

this file is created with IsWritable = true, so I can write on it and save data into it.

If I use the Shared Application data, so like this

file= new folderitem(SpecialFolder.SharedApplicationData.NativePath+“/My Software/”+“My File.txt”)

the file is created with IsWritable = false, so I´m getting an error 13 when trying to save on it.

The solution seems easy just using the ApplicationData instead of the Shared ApplicationData, but then arrives the problem of making the installer.

I´m using Packages (Stéphane Sudre) for cresting it, and this is always saving the libraries & additional data into the Shared ApplicationData. If I use the “Current user´s home folder” domain, then the installer is not saved into the Applications folder.

So if Is the installer saves the main application into the Applications folder, then the extra packages are saved into the Shared ApplicationData and then I can´t write on them, and if I save the extra packages into the Shared ApplicationData then the main application is not installed into the Applications folder.

Maybe a solution should be using other software for making the installer of the packages, as I believe I´ll not be able to create the files into the ApplicationData with IsWrittable permissions set to true.

Any help or idea with this?.

Best regards.

I have errors in this line (I defined file As FolderItem)…

Do you read .Child in FolderItem (FolderItem.Child) ?

file = SpecialFolder.ApplicationData.Child("My Software")
If file <> Nil Then
file = file.Child("My File.txt")
End if

Yes. I´ve try, and the problem is the same one, the file continue been IsWriteable = False

Sorry, my error !

You cannot create a text file using these commands. Check in the Documentation about TextOutputStream.

Note to self: better not answer question when dinning… :wink:

What settings are you saving? Would they be better placed in the user’s Preferences folder?

The problem is not if it´s a textoutputstream or a binary stream. In both scenarios, it´s failing as I don’t have the rights to write over it…

so this is failing
'________
dim stream as BinaryStream
stream=BinaryStream.Create(file)
stream.Close
'________

and this is also failing

'________
dim contenido_fichero as TextOutputStream
contenido_fichero = TextOutputStream.create(File)
contenido_fichero.Close
'________

Saving in SpecialFolder.Preferences is the same as saving in SpecialFolder. ApplicationData. I can write on it from the software, but the problem comes when building the installer as Packages doesn´t copy the files in the User preferences, it copies it into the Shared preferences

SharedApplicationData underMacOS is in the main Library folder, and under Windows, it’s C:Program Data. Neither is a good place for your app’s settings, which belong in ApplicationData.

I suggest dragging your text file into the IDE and having your app write it back out to ApplicationData instead of trying to do it with the installer.

That´s a good approach. I’m going to try it. Thanks for the idea.

1 Like

The way to handle this is to add a resource and a post-build bash script that figures out the current user’s Library path (the environment is set up to do that) and then use the script to copy it to the correct place.