using System; using System.Collections.Generic; using System.Text; using System.IO; using MeGUI.core.util; using System.Xml.Serialization; using MeGUI.core.plugins.interfaces; namespace MeGUI.core.details._0_2_6_x_profileloader { class Loader { private static Profile loadProfile(string name) where T : GenericSettings { GenericProfile prof = Util.XmlDeserialize>(name); if (prof == null) return null; Type t = typeof(GenericProfile<>).MakeGenericType(prof.Settings.GetType()); return (Profile)Activator.CreateInstance(t, prof.Name, prof.Settings); } private static List getProfiles(string folder) where T : GenericSettings { List ps = new List(); if (!Directory.Exists(folder)) return ps; DirectoryInfo di = new DirectoryInfo(folder); foreach (FileInfo fi in di.GetFiles("*.xml")) { Profile p = loadProfile(fi.FullName); if (p != null) ps.Add(p); } return ps; } public static List TryLoadProfiles(string path) { List ps = new List(); ps.AddRange(getProfiles(path + @"\profiles\video")); ps.AddRange(getProfiles(path + @"\profiles\audio")); ps.AddRange(getProfiles(path + @"\profiles\avisynth")); ps.AddRange(getProfiles(path + @"\profiles\oneclick")); return ps; } } }