1. We plan to roll out a major software update (XenForo 2.1) to the forum within the next 24h. If you post a thread or answer to an existing thread it may not get ported so please keep that in mind. New member registrations won't be possible until we finally switched.
    Dismiss Notice

Guidelines for storing/reading config info?

Discussion in 'General Development (no feature request here!)' started by kaburke, July 10, 2005.

  1. kaburke

    kaburke Portal Pro

    Joined:
    March 4, 2005
    Messages:
    64
    Likes Received:
    0
    Occupation:
    Programmer/Systems Analyst
    Location:
    Alberta, Canada
    Ratings:
    +0 / 0
    My plugins use the MediaPortal.Profile.Xml object to read/store config info. Currently, I do the following to load the config:
    Code (Text):
    1. Xml xmlreader = new Xml("MediaPortal.xml");
    I then read/write what I want, and finally call
    Code (Text):
    1. 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.)
     
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. waeberd

    waeberd Portal Pro

    Joined:
    August 16, 2004
    Messages:
    314
    Likes Received:
    1
    Location:
    Fribourg (CH)
    Ratings:
    +1 / 0
    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 (Text):
    1.     void LoadSettings()
    2.     {
    3.       using (Xml xmlreader = new Xml("MediaPortal.xml"))
    4.       {
    5.         string curText = (string) xmlreader.GetValue("myprograms", "viewby");
    6.         [... etcetcetc ...]
    7.       }
    8.     }
    9.  
    Writing:
    Code (Text):
    1.  
    2.     void SaveSettings()
    3.     {
    4.       using (Xml xmlwriter = new Xml("MediaPortal.xml"))
    5.       {
    6.         switch ((View) mapSettings.ViewAs)
    7.         {
    8.           case View.VIEW_AS_LIST:
    9.             xmlwriter.SetValue("myprograms", "viewby", "list");
    10.             break;
    11.           case View.VIEW_AS_ICONS:
    12.             xmlwriter.SetValue("myprograms", "viewby", "icons");
    13.             break;
    14.           case View.VIEW_AS_LARGEICONS:
    15.             xmlwriter.SetValue("myprograms", "viewby", "largeicons");
    16.             break;
    17.           case View.VIEW_AS_FILMSTRIP:
    18.             xmlwriter.SetValue("myprograms", "viewby", "filmstrip");
    19.             break;
    20.         }
    21.         [... etcetcetc ...]
    22.       }
    23.     }
    24.  
    Regards,

    Daniel
     
  4. kaburke

    kaburke Portal Pro

    Joined:
    March 4, 2005
    Messages:
    64
    Likes Received:
    0
    Occupation:
    Programmer/Systems Analyst
    Location:
    Alberta, Canada
    Ratings:
    +0 / 0
    Thanks a lot for the reply. That's what I'm doing, so I guess it wasn't incorrect after all.
     
Loading...

Users Viewing Thread (Users: 0, Guests: 0)

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice
  • About The Project

    The vision of the MediaPortal project is to create a free open source media centre application, which supports all advanced media centre functions, and is accessible to all Windows users.

    In reaching this goal we are working every day to make sure our software is one of the best.

             

  • Support MediaPortal!

    The team works very hard to make sure the community is running the best HTPC-software. We give away MediaPortal for free but hosting and software is not for us.

    Care to support our work with a few bucks? We'd really appreciate it!