2011-08-16, 07:01 PM
I know that at least a few of us don't have much experience with C#, so I thought it might be nice to have a thread with short tips and tricks, but obviously focused around NPVR and its API.
Here's one to kick things off...
This demonstrates two things: how to let a plugin continue to work if the user's skin doesn't support it, and how to merge the contents of a "global.xml" skin file with another file. I needed the latter to define some extra fonts that aren't in the main set without having to redefine them in every skin file that my plugin uses (popups, different views, and so on).
Feel free to use, abuse and critique, especially if it turns out that there's a better way of doing it
Iain
Here's one to kick things off...
This demonstrates two things: how to let a plugin continue to work if the user's skin doesn't support it, and how to merge the contents of a "global.xml" skin file with another file. I needed the latter to define some extra fonts that aren't in the main set without having to redefine them in every skin file that my plugin uses (popups, different views, and so on).
Code:
internal SkinHelper GetSkinHelper(string name)
{
SkinHelper shMain = null;
SkinHelper shGlbl = null;
// Load the required files, either from the current skin's folder...
if (Directory.Exists(SettingsHelper.GetInstance().GetSkinDirectory() + "VideosPlus"))
{
shMain = new SkinHelper("VideosPlus\\" + name);
shGlbl = new SkinHelper("VideosPlus\\global.xml");
}
// ...or from the Default skin if they couldn't be found
else
{
shMain = new SkinHelper("..\\Default\\VideosPlus\\" + name);
shGlbl = new SkinHelper("..\\Default\\VideosPlus\\global.xml");
}
// Now merge in everything found in global.xml
DataSet dsMain = new DataSet();
DataSet dsGlbl = new DataSet();
dsMain.ReadXml(new XmlNodeReader(shMain.GetBackingDocument()));
dsGlbl.ReadXml(new XmlNodeReader(shGlbl.GetBackingDocument()));
dsMain.Merge(dsGlbl);
shMain.GetBackingDocument().LoadXml(dsMain.GetXml());
return shMain;
}
Feel free to use, abuse and critique, especially if it turns out that there's a better way of doing it

Iain