Guidelines for storing/reading config info? (1 Viewer)

kaburke

Portal Pro
March 4, 2005
64
0
Alberta, Canada
My plugins use the MediaPortal.Profile.Xml object to read/store config info. Currently, I do the following to load the config:
Code:
Xml xmlreader = new Xml("MediaPortal.xml");
I then read/write what I want, and finally call
Code:
xmlreader.Save();
to save any changes.

This strikes my as incorrect. How should I be getting the config, and how (if I should be at all) should I be saving it?

(I have noticed that in the latest CVS version the Xml object no longer has a Save() Method.)
 

waeberd

Portal Pro
August 16, 2004
314
1
Fribourg (CH)
Hi kaburke,

you need two different objects, one for reading (xmlreader) and one for writing (xmlwriter).

One example:

Reading (you did that already, I guess):

Code:
    void LoadSettings()
    {
      using (Xml xmlreader = new Xml("MediaPortal.xml"))
      {
        string curText = (string) xmlreader.GetValue("myprograms", "viewby");
        [... etcetcetc ...]
      }
    }

Writing:
Code:
    void SaveSettings()
    {
      using (Xml xmlwriter = new Xml("MediaPortal.xml"))
      {
        switch ((View) mapSettings.ViewAs)
        {
          case View.VIEW_AS_LIST:
            xmlwriter.SetValue("myprograms", "viewby", "list");
            break;
          case View.VIEW_AS_ICONS:
            xmlwriter.SetValue("myprograms", "viewby", "icons");
            break;
          case View.VIEW_AS_LARGEICONS:
            xmlwriter.SetValue("myprograms", "viewby", "largeicons");
            break;
          case View.VIEW_AS_FILMSTRIP:
            xmlwriter.SetValue("myprograms", "viewby", "filmstrip");
            break;
        }
        [... etcetcetc ...]
      }
    }

Regards,

Daniel
 

Users who are viewing this thread

Top Bottom