CFPreferencesMBS problem

A couple of weeks ago I had a problem with synchronizing CFPreferencesMBS. When solving this I had the great idea to check if the preferences values are saved correctly. This doesn’t work for folderitems.

Getting a folderitem value (code is without error checking):

[code]Public Function getPrefFolderitem(fieldName as string) as Folderitem

Dim theCFObject As CFObjectMBS = theCFPrefs.CopyAppValue(NewCFStringMBS(fieldName), theCFPrefs.kCFPreferencesCurrentApplication)
dim theFolderitem as FolderItem
if theCFObject.TypeDescription = “CFString” then
dim FieldValue as String = CFStringMBS(theCFObject).str

theFolderitem = Volume(0)
dim theSaveInfo as String = DecodeBase64MBS(FieldValue)
theFolderitem = theFolderitem.getRelative(theSaveInfo)
return theFolderitem

end if

End Function[/code]

and setting the value:

[code]Public Sub setPrefFolderitem(fieldName as string, fieldValue as Folderitem)

dim theCFObject As CFObjectMBS
if fieldValue = nil then
theCFObject = NewCFStringMBS("")
theCFObject = NewCFStringMBS(EncodeBase64(fieldValue.GetSaveInfo(volume(0))))
end if

theCFPrefs.SetAppValue(NewCFStringMBS(FieldName), theCFObject, theCFPrefs.kCFPreferencesCurrentApplication)
if not theCFPrefs.AppSynchronize(theCFPrefs.kCFPreferencesCurrentApplication) Then
end if
if getPrefFolderitem(fieldName) <> Nil and getPrefFolderitem(fieldName).NativePath <> fieldValue.NativePath then '<— check fails here
end if

End Sub[/code]

When checking the value of getPrefFolderitem(fieldName).NativePath I can see that it points to volume(0). However, when closing and opening the window where the pref value is used then the value is okay. Bug or feature?

macOS 10.11. Xojo 2017r1, MBS 27.11.17.

put NativePath path values in local variables and take a look on this?

Already done. That’s why I said getPrefFolderitem(fieldName).NativePath points to volume(0) .

When loading you check if string length is > 0?


I forgot to add the error only happens for non-existing folderitems. I usually save my databases on the desktop. Let’s say I have “users/beatrixwillius/desktop/existing database” then the check works fine. If I do “users/beatrixwillius/desktop/non-existing database” then I get the error.

Are you talking about plist files? If yes, take into account those are cached by macOS and the actual file is only updated at intervals (mostly when shutting down your system).
So basically this means you will have a hard time verifying changes in the file itself without rebooting every time.

@Christoph De Vocht : no, after calling AppSynchronize I should be able to see the change. At least in Prefs Editor I can see that something was written.