Exemple #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);
        }
Exemple #2
0
        public static EffectsPreset NewPreset()
        {
            var i   = 1;
            var dir = GetPresetsFolder();

            // Find unused name;
            while (true)
            {
                var name = string.Format("NewPrest{0}", i);
                var fi   = dir.GetFiles(name + _fileSufix, System.IO.SearchOption.AllDirectories).FirstOrDefault();
                if (fi == null)
                {
                    var preset = new EffectsPreset();
                    preset.Name = name;
                    SavePreset(preset);
                    return(preset);
                }
                i++;
            }
        }
Exemple #3
0
        public static void SavePreset(EffectsPreset preset)
        {
            var fileName   = preset.Name + _fileSufix;
            var dir        = GetPresetsFolder();
            var presetsDir = new System.IO.DirectoryInfo("Presets");

            if (!presetsDir.Exists)
            {
                presetsDir = dir;
            }
            var file = dir.GetFiles(fileName, System.IO.SearchOption.AllDirectories).FirstOrDefault();

            // if file doesn't exist anywhere then...
            if (file == null)
            {
                var path = System.IO.Path.Combine(presetsDir.FullName, fileName);
                file = new System.IO.FileInfo(path);
            }
            var xml = Serializer.SerializeToXmlString(preset);

            System.IO.File.WriteAllText(file.FullName, xml, System.Text.Encoding.UTF8);
        }