Beispiel #1
0
        public static BindingList <EffectsPreset> GetPresets()
        {
            var dir         = GetPresetsFolder();
            var presetNames = dir.GetFiles("*" + _fileSufix, System.IO.SearchOption.AllDirectories)
                              .Select(x => x.Name.Replace(_fileSufix, ""))
                              .Distinct()
                              .OrderBy(x => x);
            var list = new BindingList <EffectsPreset>();

            foreach (var name in presetNames)
            {
                var preset = LoadPreset(name);
                list.Add(preset);
            }
            // move default to the top.
            var def = list.FirstOrDefault(x => x.Name == "Default");

            // Create if not exists.
            if (def == null)
            {
                def      = new EffectsPreset();
                def.Name = "Default";
                var assembly = Assembly.GetExecutingAssembly();
                var names    = assembly.GetManifestResourceNames().Where(x => x.EndsWith(_fileSufix)).ToArray();
                foreach (var name in names)
                {
                    var stream = MainHelper.GetResource(name);
                    var sr     = new StreamReader(stream, Encoding.UTF8, true);
                    var xml    = sr.ReadToEnd();
                    sr.Close();
                    var preset = Serializer.DeserializeFromXmlString <EffectsPreset>(xml);
                    SavePreset(preset);
                    if (name.Contains("Default"))
                    {
                        def = preset;
                    }
                    else
                    {
                        list.Add(preset);
                    }
                }
            }
            else
            {
                list.Remove(def);
            }
            list.Insert(0, def);
            return(list);
        }