From: <fr...@us...> - 2008-05-19 17:30:05
|
Revision: 1796 http://mp-plugins.svn.sourceforge.net/mp-plugins/?rev=1796&view=rev Author: framug Date: 2008-05-19 10:30:00 -0700 (Mon, 19 May 2008) Log Message: ----------- - XmlConfig for setup. - Add .png files (taken in MP folders). Modified Paths: -------------- trunk/plugins/MyExplorer/My Explorer.csproj trunk/plugins/MyExplorer/SetupForm.cs Added Paths: ----------- trunk/plugins/MyExplorer/XmlConfig.cs trunk/plugins/MyExplorer/skin/BlueTwo/Media/ trunk/plugins/MyExplorer/skin/BlueTwo/Media/explorer_logo.png trunk/plugins/MyExplorer/skin/BlueTwo/Media/hover_my explorer.png trunk/plugins/MyExplorer/skin/BlueTwo wide/Media/ trunk/plugins/MyExplorer/skin/BlueTwo wide/Media/explorer_logo.png trunk/plugins/MyExplorer/skin/BlueTwo wide/Media/hover_my explorer.png Modified: trunk/plugins/MyExplorer/My Explorer.csproj =================================================================== --- trunk/plugins/MyExplorer/My Explorer.csproj 2008-05-19 17:25:05 UTC (rev 1795) +++ trunk/plugins/MyExplorer/My Explorer.csproj 2008-05-19 17:30:00 UTC (rev 1796) @@ -55,6 +55,7 @@ <Compile Include="SetupForm.cs"> <SubType>Form</SubType> </Compile> + <Compile Include="XmlConfig.cs" /> </ItemGroup> <ItemGroup> <EmbeddedResource Include="SetupForm.resx"> Modified: trunk/plugins/MyExplorer/SetupForm.cs =================================================================== --- trunk/plugins/MyExplorer/SetupForm.cs 2008-05-19 17:25:05 UTC (rev 1795) +++ trunk/plugins/MyExplorer/SetupForm.cs 2008-05-19 17:30:00 UTC (rev 1796) @@ -320,19 +320,26 @@ private void LoadSettings() { - using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MyExplorer.xml"))) +/* using (MediaPortal.Profile.Settings xmlreader = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MyExplorer.xml"))) { textBox1.Text = xmlreader.GetValueAsString("myexplorer", "temp_folder", ""); checkBox1.Checked = xmlreader.GetValueAsBool("myexplorer", "show_only_shares", false); checkBox2.Checked = xmlreader.GetValueAsBool("myexplorer", "enable_delete", false); checkBox3.Checked = xmlreader.GetValueAsBool("myexplorer", "delete_immediately", false); checkBox4.Checked = xmlreader.GetValueAsBool("myexplorer", "delete_temp", false); - } - } + } */ + XmlConfig XmlConfig = new XmlConfig(); + textBox1.Text = XmlConfig.ReadXmlConfig("MyExplorer", "myexplorer", "temp_folder", ""); + checkBox1.Checked = XmlConfig.ReadXmlConfig("MyExplorer", "myexplorer", "show_only_shares", false); + checkBox2.Checked = XmlConfig.ReadXmlConfig("MyExplorer", "myexplorer", "enable_delete", false); + checkBox3.Checked = XmlConfig.ReadXmlConfig("MyExplorer", "myexplorer", "delete_immediately", false); + checkBox4.Checked = XmlConfig.ReadXmlConfig("MyExplorer", "myexplorer", "delete_temp", false); + } + private void SaveSettings() { - using (MediaPortal.Profile.Settings xmlwriter = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MyExplorer.xml"))) +/* using (MediaPortal.Profile.Settings xmlwriter = new MediaPortal.Profile.Settings(Config.GetFile(Config.Dir.Config, "MyExplorer.xml"))) { xmlwriter.SetValue("myexplorer", "temp_folder", textBox1.Text); xmlwriter.SetValueAsBool("myexplorer", "show_only_shares", checkBox1.Checked); @@ -354,7 +361,29 @@ xmlwriter.SetValueAsBool("myexplorer", "delete_immediately", false); xmlwriter.SetValueAsBool("myexplorer", "delete_temp", false); } + } */ + + XmlConfig XmlConfig = new XmlConfig(); + XmlConfig.WriteXmlConfig("MyExplorer", "myexplorer", "temp_folder", textBox1.Text); + XmlConfig.WriteXmlConfig("MyExplorer", "myexplorer", "show_only_shares", checkBox1.Checked); + XmlConfig.WriteXmlConfig("MyExplorer", "myexplorer", "enable_delete", checkBox2.Checked); + if (checkBox2.Checked == true) + { + XmlConfig.WriteXmlConfig("MyExplorer", "myexplorer", "delete_immediately", checkBox3.Checked); + if (checkBox3.Checked == true) + { + XmlConfig.WriteXmlConfig("MyExplorer", "myexplorer", "delete_temp", false); + } + else + { + XmlConfig.WriteXmlConfig("MyExplorer", "myexplorer", "delete_temp", checkBox4.Checked); + } } + else + { + XmlConfig.WriteXmlConfig("MyExplorer", "myexplorer", "delete_immediately", false); + XmlConfig.WriteXmlConfig("MyExplorer", "myexplorer", "delete_temp", false); + } } private void button2_Click(object sender, System.EventArgs e) @@ -363,7 +392,7 @@ { if (textBox1.Text == "") { - MessageBox.Show("Please select a temp path!"); + MessageBox.Show("Please select a temp path !"); } else { @@ -375,7 +404,7 @@ { if (checkBox2.Checked == true && checkBox3.Checked == false && checkBox4.Checked == false) { - MessageBox.Show("Please a Option: \n(Delete Files immediately)\n or \n(Delete moves files to Temp Folder)"); + MessageBox.Show("Please select an option : \n(Delete Files immediately)\n or \n(Delete moves files to Temp Folder)"); } else { Added: trunk/plugins/MyExplorer/XmlConfig.cs =================================================================== --- trunk/plugins/MyExplorer/XmlConfig.cs (rev 0) +++ trunk/plugins/MyExplorer/XmlConfig.cs 2008-05-19 17:30:00 UTC (rev 1796) @@ -0,0 +1,320 @@ +#region Banneer +/* + * Copyright (C) 2008 framug + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Make; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ +#endregion + +#region HowToUse +/* + * Purpose of this class is to manage a xml config file. + * The generated file is MediaPortal xml config file compatible. + * It has been written in case of you have your own plugin save button or, you don't want + * to use MediaPortal.Configuration and MediaPortal.Profile in your plugin classes. + * ie : using (Settings ReadOrWriteXml = new Settings(Config.GetFile(Config.Dir.Config, PluginName()))) + * { ReadOrWriteXml = ... } + * + * How to use : + * - Add this class to your project. + * - Change namespace of this class with your own plugin name. + * + * - Call methods in your own plugin this way for writing : + * XmlConfig XmlConfig = new XmlConfig(); + * XmlConfig.WriteXmlConfig(StringFileName, StringSectionName, StringEntryName, StringValueName); + * XmlConfig.WriteXmlConfig(StringFileName, StringSectionName, StringEntryName, BoolValueName); + * XmlConfig.WriteXmlConfig(StringFileName, StringSectionName, StringEntryName, IntValueName); + * + * - Call methods in your own plugin this way for reading : + * XmlConfig XmlConfig = new XmlConfig(); + * YourString = XmlConfig.ReadXmlConfig(StringFileName, StringSectionName, StringEntryName, StringValueDefaultName); + * YourBool = XmlConfig.ReadXmlConfig(StringFileName, StringSectionName, StringEntryName, BoolValueDefaultName); + * YourInt = XmlConfig.ReadXmlConfig(StringFileName, StringSectionName, StringEntryName, IntValueDefaultName); + * + * - Call methods in your own plugin this way for removing entry : + * XmlConfig XmlConfig = new XmlConfig(); + * XmlConfig.RemoveEntry(StringFileName, StringSectionName, StringEntryName); + * + */ +#endregion + +#region using +using System; +using System.IO; // For I/O file +using System.Collections.Generic; +using System.Text; +using System.Xml; // For XmlDocument +using MediaPortal.Configuration; // For recover install MediaPortal path +#endregion + +namespace GUIExplorer +{ + class XmlConfig + { + +#region <<DECLARATION>> + XmlDocument configxml = new XmlDocument(); +#endregion + +#region <<public>> + + // Recover install MediaPortal path + public string PathInstalMP() + { + string path = Config.GetFolder(Config.Dir.Config); + return path; + } + + // Build entire filename of config file + public string EntireFilenameConfig(string FileName) + { + string entirefilename = PathInstalMP() + @"\" + FileName + ".xml"; + return entirefilename; + } + + // Called with bool type + public void WriteXmlConfig(string FileName, string Section, string Entry, bool Value) + { + string value = ""; + // Change true by "yes" and false by "no" for xml MediaPortal compatibility + if (Value) + { + value = "yes"; + } + else + { + value = "no"; + } + + WriteXmlConfig(FileName, Section, Entry, value); + } + + // Called with decimal type + public void WriteXmlConfig(string FileName, string Section, string Entry, decimal Value) + { + string value = Value.ToString(); + + WriteXmlConfig(FileName, Section, Entry, value); + } + + // Write a config file with XmlDocument + public void WriteXmlConfig(string FileName, string Section, string Entry, string Value) + { + // Create file if doesn't exist + if (!File.Exists(EntireFilenameConfig(FileName))) + { + CreateXmlConfig(FileName); + } + + //Open xml document + configxml.Load(EntireFilenameConfig(FileName)); + //Recover profile node + XmlElement profile = configxml.DocumentElement; + //Create section if doesn't exist + String XPath = @"/profile/section[@name='" + Section + "']"; + XmlNodeList ListSection = configxml.SelectNodes(XPath); + if (ListSection.Count < 1) + { + CreateSection(Section); + } + //Posit on section node + XmlNode section = profile.SelectSingleNode("section[@name='" + Section + "']"); + + //Create Entry if doesn't exist + XPath = @"/profile/section[@name='" + Section + "']/entry[@name='" + Entry + "']"; + XmlNodeList ListEntry = configxml.SelectNodes(XPath); + if (ListEntry.Count < 1) + { + CreateEntry(Section, Entry); + } + //Posit on entry node + XmlNode entry = section.SelectSingleNode("entry[@name='" + Entry + "']"); + + //Store entry value + entry.InnerText = Value; + + //Save xml config file + configxml.Save(EntireFilenameConfig(FileName)); + } + + // Remove an Entry + public void RemoveEntry(string FileName, string Section, string Entry) + { + // Return if xml file doesn't exist + if (!File.Exists(EntireFilenameConfig(FileName))) + { + return; + } + + //Open xml document + configxml.Load(EntireFilenameConfig(FileName)); + //Recover profile node + XmlElement profile = configxml.DocumentElement; + + //Posit on value + String XPath = @"/profile/section[@name='" + Section + "']/entry[@name='" + Entry + "']"; + XmlNodeList ListEntry = configxml.SelectNodes(XPath); + + // If value exist, remove it otherwise, return + if (ListEntry.Count > 0) + { + //Posit on section node + XmlNode section = profile.SelectSingleNode("section[@name='" + Section + "']"); + //Posit on entry node + XmlNode entry = section.SelectSingleNode("entry[@name='" + Entry + "']"); + //Remove the entry node for section + section.RemoveChild(entry); + //Save xml config file + configxml.Save(EntireFilenameConfig(FileName)); + } + return; + } + + // Called with bool type + public bool ReadXmlConfig(string FileName, string Section, string Entry, bool Value) + { + // Change true by "yes" and false by "no" for xml MediaPortal compatibility + string value = Value.ToString(); + if (Value) + { + value = "yes"; + } + else + { + value = "no"; + } + + string result = ReadXmlConfig(FileName, Section, Entry, value); + + // Change "yes" by true and "no" by false for xml MediaPortal compatibility + if (result == "yes") + { + Value = true; + } + else + { + Value = false; + } + + return Value; + } + + // Called with int type + public int ReadXmlConfig(string FileName, string Section, string Entry, int Value) + { + string value = Value.ToString(); + + string result = ReadXmlConfig(FileName, Section, Entry, value); + + Value = Convert.ToInt32(result); + + return Value; + } + + // Read xml config file with XmlDocument + public string ReadXmlConfig(string FileName, string Section, string Entry, string Value) + { + // Default value if xml file doesn't exist + if (!File.Exists(EntireFilenameConfig(FileName))) + { + return Value; + } + + //Open xml document + configxml.Load(EntireFilenameConfig(FileName)); + //Recover profile node + XmlElement profile = configxml.DocumentElement; + + //Posit on value + String XPath = @"/profile/section[@name='" + Section + "']/entry[@name='" + Entry + "']"; + XmlNodeList ListEntry = configxml.SelectNodes(XPath); + + // If value exist, return it otherwise, return default value + if (ListEntry.Count > 0) + { + //Posit on section node + XmlNode section = profile.SelectSingleNode("section[@name='" + Section + "']"); + //Posit on entry node + XmlNode entry = section.SelectSingleNode("entry[@name='" + Entry + "']"); + //Recover value with entry data + Value = entry.InnerText; + } + + return Value; + } + +#endregion + +#region <<private>> + + // Create xml config file with profile node + private void CreateXmlConfig(string FileName) + { + XmlDocument configxml = new XmlDocument(); + //Declaration of XML document type (utf-8, same as MediaPortal) + XmlDeclaration declaration = configxml.CreateXmlDeclaration("1.0", "utf-8", ""); + //Add declaration to document + configxml.AppendChild(declaration); + //Create profile node + XmlNode profile = configxml.CreateNode(System.Xml.XmlNodeType.Element, "profile", ""); + //Add node to document + configxml.AppendChild(profile); + + //Save xml config file + configxml.Save(EntireFilenameConfig(FileName)); + } + + // create section node + private void CreateSection(string Section) + { + //Recover profile node + XmlElement profile = configxml.DocumentElement; + //Create new section node + XmlNode section = configxml.CreateElement("section"); + //Add "name" attribute to section node + XmlAttribute name = configxml.CreateAttribute("name"); + //value is section name + name.Value = Section; + //Add value to section + section.Attributes.Append(name); + //Add section to document + profile.AppendChild(section); + } + + // create entry node + private void CreateEntry(string Section, string Entry) + { + //Recover profile node + XmlElement profile = configxml.DocumentElement; + //Posit on section node + XmlNode section = profile.SelectSingleNode("section[@name='" + Section + "']"); + //Create new node for entry + XmlNode entry = configxml.CreateElement("entry"); + //Add "name" attribute to entry node + XmlAttribute name = configxml.CreateAttribute("name"); + //value is entry name + name.Value = Entry; + //Add value to entry + entry.Attributes.Append(name); + //Add entry to document + section.AppendChild(entry); + } + +#endregion + + } // end of class +} // end of namespace Added: trunk/plugins/MyExplorer/skin/BlueTwo/Media/explorer_logo.png =================================================================== (Binary files differ) Property changes on: trunk/plugins/MyExplorer/skin/BlueTwo/Media/explorer_logo.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/plugins/MyExplorer/skin/BlueTwo/Media/hover_my explorer.png =================================================================== (Binary files differ) Property changes on: trunk/plugins/MyExplorer/skin/BlueTwo/Media/hover_my explorer.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/plugins/MyExplorer/skin/BlueTwo wide/Media/explorer_logo.png =================================================================== (Binary files differ) Property changes on: trunk/plugins/MyExplorer/skin/BlueTwo wide/Media/explorer_logo.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/plugins/MyExplorer/skin/BlueTwo wide/Media/hover_my explorer.png =================================================================== (Binary files differ) Property changes on: trunk/plugins/MyExplorer/skin/BlueTwo wide/Media/hover_my explorer.png ___________________________________________________________________ Name: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |