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("")
else
theCFObject = NewCFStringMBS(EncodeBase64(fieldValue.GetSaveInfo(volume(0))))
end if
theCFPrefs.SetAppValue(NewCFStringMBS(FieldName), theCFObject, theCFPrefs.kCFPreferencesCurrentApplication)
if not theCFPrefs.AppSynchronize(theCFPrefs.kCFPreferencesCurrentApplication) Then
globals.theErrorLog.DialogErrorProceed(kErrorSynchronize)
end if
if getPrefFolderitem(fieldName) <> Nil and getPrefFolderitem(fieldName).NativePath <> fieldValue.NativePath then '<— check fails here
globals.theErrorLog.DialogErrorProceed(kErrorPrefsNotSaved)
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.