I can load/save my PrefsObject prefs just fine....once. If I try to reload them it does not work.
Set up my application
BOOL RegisterApp() { if (!appShowIcon) AppIconInfo.iconType=APPICONT_ProgramIcon; else AppIconInfo.iconType=APPICONT_None; if ((appID=IApplication->RegisterApplication(PROJECT_NAME2, REGAPP_URLIdentifier, PROJECT_NAME3, REGAPP_Description, PROJECT_DESC, REGAPP_NoIcon, appShowIcon, REGAPP_AppIconInfo, AppIconInfo, REGAPP_FileName, ProgramComplete, REGAPP_HasIconifyFeature, TRUE, REGAPP_HasPrefsWindow, TRUE, REGAPP_CanCreateNewDocs, TRUE, REGAPP_CustomPrefsFileName, PATH_PREFS, TAG_END))) { IApplication->GetApplicationAttrs(appID, APPATTR_Port, &AppLibPort, APPATTR_AppIdentifier, &appIDName, TAG_DONE); AppLibSignal=PORTMASK(AppLibPort); IApplication->SetApplicationAttrs(appID, APPATTR_MainPrefsDict, myPrefsDict, TAG_DONE); return(TRUE); } return(FALSE); }
Load prefs code
BOOL LoadPrefs() { CONST_STRPTR StringVal; PrefsObject *PrefsObj; struct ALPOObjIndex oi, soi; int32 count, subcount; uint32 err, value, len; STRPTR *buffer; myPrefsDict=IPrefsObjects->PrefsDictionary(NULL,NULL, ALPO_Alloc, 0, TAG_DONE); IApplication->GetApplicationAttrs(appID, APPATTR_MainPrefsDict, &myPrefsDict, TAG_DONE); if (myPrefsDict) { Prefs->NavigationWidth=IPrefsObjects->DictGetIntegerForKey(myPrefsDict,"NavigationWidth",25); Prefs->ContentHeight=IPrefsObjects->DictGetIntegerForKey(myPrefsDict,"ContentHeight",25); Prefs->ContentWidth=IPrefsObjects->DictGetIntegerForKey(myPrefsDict,"ContentWidth",25); Prefs->ThumbnailPreviewWidth=IPrefsObjects->DictGetIntegerForKey(myPrefsDict,"ThumbnailPreviewWidth",13); Prefs->DetailsHeight=IPrefsObjects->DictGetIntegerForKey(myPrefsDict,"DetailsHeight",15); ...a bunch more lines... myPrefsDict=IPrefsObjects->PrefsDictionary(NULL,NULL, ALPO_Release, 0, TAG_DONE); return(TRUE); } Done: SAK_IOErr=IDOS->IoErr(); SAK_IOError(Objects[OID_WINDOW],MainWindow,RequesterTitle,REQIMAGE_WARNING,0,SAK_IOErr,SAK_LocaleString(MSG_ERROR_LOADING_PREFS_FILE),SAK_LocaleString(MSG_CONTINUE)); return(FALSE); }
Save prefs code
BOOL SavePrefs() { PrefsObject *PrefsObj, *SubPrefsObj; myPrefsDict=IPrefsObjects->PrefsDictionary(NULL,NULL, ALPO_Alloc, 0, TAG_DONE); IApplication->GetApplicationAttrs(appID, APPATTR_MainPrefsDict, &myPrefsDict, TAG_DONE); if (!myPrefsDict) { SAK_IOErr=IDOS->IoErr(); SAK_IOError(Objects[OID_WINDOW],MainWindow,RequesterTitle,REQIMAGE_WARNING,0,SAK_IOErr,SAK_LocaleString(MSG_ERROR_SAVING_PREFS_FILE),SAK_LocaleString(MSG_CONTINUE)); return(FALSE); } IPrefsObjects->PrefsDictionary(myPrefsDict,NULL, ALPODICT_Clear, 0, TAG_DONE); IPrefsObjects->DictSetObjectForKey(myPrefsDict, IPrefsObjects->PrefsNumber(NULL,NULL, ALPONUM_AllocSetLong, Prefs->NavigationWidth, TAG_DONE), "NavigationWidth"); IPrefsObjects->DictSetObjectForKey(myPrefsDict, IPrefsObjects->PrefsNumber(NULL,NULL, ALPONUM_AllocSetLong, Prefs->ContentHeight, TAG_DONE), "ContentHeight"); IPrefsObjects->DictSetObjectForKey(myPrefsDict, IPrefsObjects->PrefsNumber(NULL,NULL, ALPONUM_AllocSetLong, Prefs->ContentWidth, TAG_DONE), "ContentWidth"); IPrefsObjects->DictSetObjectForKey(myPrefsDict, IPrefsObjects->PrefsNumber(NULL,NULL, ALPONUM_AllocSetLong, Prefs->ThumbnailPreviewWidth, TAG_DONE), "ThumbnailPreviewWidth"); IPrefsObjects->DictSetObjectForKey(myPrefsDict, IPrefsObjects->PrefsNumber(NULL,NULL, ALPONUM_AllocSetLong, Prefs->DetailsHeight, TAG_DONE), "DetailsHeight"); ...a bunch more lines... if (IPrefsObjects->WritePrefs(myPrefsDict, WRITEPREFS_AppID, appID, WRITEPREFS_WriteENV, TRUE, // WRITEPREFS_WriteENVARC, TRUE, // already am in path name TAG_DONE) != 0) { SAK_IOErr=IDOS->IoErr(); SAK_IOError(Objects[OID_WINDOW],MainWindow,RequesterTitle,REQIMAGE_WARNING,0,SAK_IOErr,SAK_LocaleString(MSG_ERROR_SAVING_PREFS_FILE),SAK_LocaleString(MSG_CONTINUE)); return(FALSE); } myPrefsDict=IPrefsObjects->PrefsDictionary(NULL,NULL, ALPO_Release, 0, TAG_DONE); return(TRUE); }
The initial loads works. If I try to reload prefs, it seems to work (put in check lines to see what is happening), but it does not accept the changes I made manually with a text editor to the prefs file.
I have made sure all the ALPO_Alloc's and ALPO_Release's counts match up. Is there something else I need to be doing? It is like the "internal" dictionary is never freed and the newly loaded one does not replace what is already loaded.
I have freed the prefs array and re-allocated it before reloading. Same result.
What I do (in DateTime.docky) is:
Don't you use 'IPrefsObjects->ReadPrefs();' for (re)reading xml file?
AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P
That fixed it. Strange it doesn't require that for the first reading. I built my code from examples on Hyperion forum. I probably had it in there originally, but since it worked the first read without it I took it out. I didn't need to reload the prefs until recently.
Thank you!