PrefsObject

3 posts / 0 new
Last post
mritter0
mritter0's picture
Offline
Last seen: 2 years 5 months ago
Joined: 2014-04-21 21:15
PrefsObject

I can load/save my PrefsObject prefs just fine....once. If I try to reload them it does not work.

Set up my application

  1. BOOL
  2. RegisterApp()
  3. {
  4. if (!appShowIcon)
  5. AppIconInfo.iconType=APPICONT_ProgramIcon;
  6. else
  7. AppIconInfo.iconType=APPICONT_None;
  8.  
  9. if ((appID=IApplication->RegisterApplication(PROJECT_NAME2,
  10. REGAPP_URLIdentifier, PROJECT_NAME3,
  11. REGAPP_Description, PROJECT_DESC,
  12. REGAPP_NoIcon, appShowIcon,
  13. REGAPP_AppIconInfo, AppIconInfo,
  14. REGAPP_FileName, ProgramComplete,
  15. REGAPP_HasIconifyFeature, TRUE,
  16. REGAPP_HasPrefsWindow, TRUE,
  17. REGAPP_CanCreateNewDocs, TRUE,
  18. REGAPP_CustomPrefsFileName, PATH_PREFS,
  19. TAG_END)))
  20. {
  21. IApplication->GetApplicationAttrs(appID,
  22. APPATTR_Port, &AppLibPort,
  23. APPATTR_AppIdentifier, &appIDName,
  24. TAG_DONE);
  25.  
  26. AppLibSignal=PORTMASK(AppLibPort);
  27.  
  28. IApplication->SetApplicationAttrs(appID,
  29. APPATTR_MainPrefsDict, myPrefsDict,
  30. TAG_DONE);
  31.  
  32. return(TRUE);
  33. }
  34.  
  35. return(FALSE);
  36. }

Load prefs code

  1. BOOL
  2. LoadPrefs()
  3. {
  4. CONST_STRPTR StringVal;
  5. PrefsObject *PrefsObj;
  6. struct ALPOObjIndex oi, soi;
  7. int32 count, subcount;
  8. uint32 err, value, len;
  9. STRPTR *buffer;
  10.  
  11. myPrefsDict=IPrefsObjects->PrefsDictionary(NULL,NULL,
  12. ALPO_Alloc, 0,
  13. TAG_DONE);
  14. IApplication->GetApplicationAttrs(appID,
  15. APPATTR_MainPrefsDict, &myPrefsDict,
  16. TAG_DONE);
  17.  
  18. if (myPrefsDict)
  19. {
  20. Prefs->NavigationWidth=IPrefsObjects->DictGetIntegerForKey(myPrefsDict,"NavigationWidth",25);
  21. Prefs->ContentHeight=IPrefsObjects->DictGetIntegerForKey(myPrefsDict,"ContentHeight",25);
  22. Prefs->ContentWidth=IPrefsObjects->DictGetIntegerForKey(myPrefsDict,"ContentWidth",25);
  23. Prefs->ThumbnailPreviewWidth=IPrefsObjects->DictGetIntegerForKey(myPrefsDict,"ThumbnailPreviewWidth",13);
  24. Prefs->DetailsHeight=IPrefsObjects->DictGetIntegerForKey(myPrefsDict,"DetailsHeight",15);
  25.  
  26. ...a bunch more lines...
  27.  
  28. myPrefsDict=IPrefsObjects->PrefsDictionary(NULL,NULL,
  29. ALPO_Release, 0,
  30. TAG_DONE);
  31.  
  32. return(TRUE);
  33. }
  34.  
  35. Done:
  36. SAK_IOErr=IDOS->IoErr();
  37. SAK_IOError(Objects[OID_WINDOW],MainWindow,RequesterTitle,REQIMAGE_WARNING,0,SAK_IOErr,SAK_LocaleString(MSG_ERROR_LOADING_PREFS_FILE),SAK_LocaleString(MSG_CONTINUE));
  38.  
  39. return(FALSE);
  40. }

Save prefs code

  1. BOOL
  2. SavePrefs()
  3. {
  4. PrefsObject *PrefsObj, *SubPrefsObj;
  5.  
  6. myPrefsDict=IPrefsObjects->PrefsDictionary(NULL,NULL,
  7. ALPO_Alloc, 0,
  8. TAG_DONE);
  9. IApplication->GetApplicationAttrs(appID,
  10. APPATTR_MainPrefsDict, &myPrefsDict,
  11. TAG_DONE);
  12. if (!myPrefsDict)
  13. {
  14. SAK_IOErr=IDOS->IoErr();
  15. SAK_IOError(Objects[OID_WINDOW],MainWindow,RequesterTitle,REQIMAGE_WARNING,0,SAK_IOErr,SAK_LocaleString(MSG_ERROR_SAVING_PREFS_FILE),SAK_LocaleString(MSG_CONTINUE));
  16.  
  17. return(FALSE);
  18. }
  19.  
  20. IPrefsObjects->PrefsDictionary(myPrefsDict,NULL,
  21. ALPODICT_Clear, 0,
  22. TAG_DONE);
  23.  
  24. IPrefsObjects->DictSetObjectForKey(myPrefsDict,
  25. IPrefsObjects->PrefsNumber(NULL,NULL,
  26. ALPONUM_AllocSetLong, Prefs->NavigationWidth,
  27. TAG_DONE),
  28. "NavigationWidth");
  29. IPrefsObjects->DictSetObjectForKey(myPrefsDict,
  30. IPrefsObjects->PrefsNumber(NULL,NULL,
  31. ALPONUM_AllocSetLong, Prefs->ContentHeight,
  32. TAG_DONE),
  33. "ContentHeight");
  34. IPrefsObjects->DictSetObjectForKey(myPrefsDict,
  35. IPrefsObjects->PrefsNumber(NULL,NULL,
  36. ALPONUM_AllocSetLong, Prefs->ContentWidth,
  37. TAG_DONE),
  38. "ContentWidth");
  39. IPrefsObjects->DictSetObjectForKey(myPrefsDict,
  40. IPrefsObjects->PrefsNumber(NULL,NULL,
  41. ALPONUM_AllocSetLong, Prefs->ThumbnailPreviewWidth,
  42. TAG_DONE),
  43. "ThumbnailPreviewWidth");
  44. IPrefsObjects->DictSetObjectForKey(myPrefsDict,
  45. IPrefsObjects->PrefsNumber(NULL,NULL,
  46. ALPONUM_AllocSetLong, Prefs->DetailsHeight,
  47. TAG_DONE),
  48. "DetailsHeight");
  49.  
  50. ...a bunch more lines...
  51.  
  52. if (IPrefsObjects->WritePrefs(myPrefsDict,
  53. WRITEPREFS_AppID, appID,
  54. WRITEPREFS_WriteENV, TRUE,
  55. // WRITEPREFS_WriteENVARC, TRUE, // already am in path name
  56. TAG_DONE) != 0)
  57. {
  58. SAK_IOErr=IDOS->IoErr();
  59. SAK_IOError(Objects[OID_WINDOW],MainWindow,RequesterTitle,REQIMAGE_WARNING,0,SAK_IOErr,SAK_LocaleString(MSG_ERROR_SAVING_PREFS_FILE),SAK_LocaleString(MSG_CONTINUE));
  60.  
  61. return(FALSE);
  62. }
  63.  
  64. myPrefsDict=IPrefsObjects->PrefsDictionary(NULL,NULL,
  65. ALPO_Release, 0,
  66. TAG_DONE);
  67.  
  68. return(TRUE);
  69. }

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.

jabirulo
jabirulo's picture
Offline
Last seen: 2 weeks 5 days ago
Joined: 2013-05-30 00:53
Re: PrefsObject

What I do (in DateTime.docky) is:

  1. ...
  2. uint32 ReadXMLcfg(char *filename, struct DockyBase *db, struct DockyData *dd)
  3. {
  4. PrefsObject *dict;
  5. uint32 err;
  6. //IDOS->Printf("[XML]Loading '%s':\n",filename);
  7. IExec->NewList(&listbrowser_list);
  8.  
  9. dict = IPrefsObjects->PrefsDictionary(NULL, NULL, ALPO_Alloc,0, TAG_DONE);
  10.  
  11. err = IPrefsObjects->ReadPrefs(dict, READPREFS_FileName,(ULONG)filename, TAG_DONE);
  12. if(err)
  13. {
  14. IUtility->SNPrintf(loc_buffer, 256, GetString(&li,MSG_WARN_READING_XML,db),err);
  15. DoMessage(loc_buffer, REQIMAGE_WARNING, db, dd);
  16. err = 0;
  17. }
  18. else
  19. {
  20. PrefsObject *mydays1 = IPrefsObjects->DictGetObjectForKey(dict, "My Days");
  21. PrefsObject *mydays2 = IPrefsObjects->DictGetObjectForKey(dict, "Month-Day-String-Cmd");
  22.  
  23. ...

Don't you use 'IPrefsObjects->ReadPrefs();' for (re)reading xml file?

AOS4.1/SAM460ex/PPC460EX-1155MHZ/2048MB/RadeonHD6570/SSD120GB/DVDRW :-P

mritter0
mritter0's picture
Offline
Last seen: 2 years 5 months ago
Joined: 2014-04-21 21:15
Re: PrefsObject

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!

Log in or register to post comments