Exemple #1
0
        public MediaAccess(string path, string defaultPath)
        {
            try
            {
                XElement file = XElement.Load(path);

                DefaultPlugins = new DefaultPlugins()
                {
                    Filesystem = file.Element("defaultPlugins").Element("filesystem").Value,
                    Movie = file.Element("defaultPlugins").Element("movie").Value,
                    Music = file.Element("defaultPlugins").Element("music").Value,
                    Picture = file.Element("defaultPlugins").Element("picture").Value,
                    TVShow = file.Element("defaultPlugins").Element("tvshow").Value,
                };

                DisabledPlugins = file.Element("disabledPlugins").Elements("disabled").Select(x => x.Value).ToList();

                PluginConfiguration = new Dictionary<string, List<PluginConfigItem>>();

                foreach (XElement plugin in file.Element("pluginConfiguration").Elements("plugin"))
                {
                    PluginConfiguration[plugin.Attribute("name").Value] = new List<PluginConfigItem>();
                    foreach(var x in plugin.Elements())
                    {
                        ConfigType type = (ConfigType)Enum.Parse(typeof(ConfigType), x.Attribute("type").Value, true);
                        string value = type == ConfigType.File || type == ConfigType.Folder ? Configuration.PerformFolderSubstitution(x.Value) : x.Value;
                        PluginConfiguration[plugin.Attribute("name").Value].Add(new PluginConfigItem()
                        {
                            DisplayName = x.Attribute("displayname").Value,
                            Name = x.Name.LocalName,
                            Type = type,
                            Value = value
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("Failed to load MediaAccess configuration", ex);
            }
        }
Exemple #2
0
        public MediaAccess(string path, string defaultPath)
        {
            try
            {
                XElement file = XElement.Load(path);

                DefaultPlugins = new DefaultPlugins()
                {
                    Filesystem = file.Element("defaultPlugins").Element("filesystem").Value,
                    Movie = file.Element("defaultPlugins").Element("movie").Value,
                    Music = file.Element("defaultPlugins").Element("music").Value,
                    Picture = file.Element("defaultPlugins").Element("picture").Value,
                    TVShow = file.Element("defaultPlugins").Element("tvshow").Value,
                };

                DisabledPlugins = file.Element("disabledPlugins").Elements("disabled").Select(x => x.Value).ToList();

                PluginConfiguration = new Dictionary<string, List<PluginConfigItem>>();

                foreach (XElement plugin in file.Element("pluginConfiguration").Elements("plugin"))
                {
                    PluginConfiguration[plugin.Attribute("name").Value] = ReadPluginConfig(plugin);
                }

                // Add configuration for new plugins, if there is one available
                if (File.GetLastWriteTime(defaultPath) > File.GetLastWriteTime(path))
                {
                    var defaultPlugins = XElement.Load(defaultPath)
                        .Element("pluginConfiguration")
                        .Elements("plugin");
                    foreach (var plugin in defaultPlugins)
                    {
                        var name = plugin.Attribute("name").Value;
                        if (!PluginConfiguration.ContainsKey(name))
                        {
                            PluginConfiguration[name] = ReadPluginConfig(plugin);
                        }
                    }

                    Save();
                }
            }
            catch (Exception ex)
            {
                Log.Error("Failed to load MediaAccess configuration", ex);
            }
        }