예제 #1
0
        /// <summary>
        /// Reads a FilterPreset that was serialized from the given stream
        /// </summary>
        /// <param name="stream">The stream to load the filter preset from</param>
        /// <returns>A FilterPreset that was read from the stream</returns>
        public static FilterPreset FromStream(Stream stream)
        {
            FilterPreset preset = new FilterPreset();

            preset.LoadFromStream(stream);

            return(preset);
        }
예제 #2
0
        /// <summary>
        /// Returns whether this filter preset matches the given filter preset.
        /// Filter preset comparision is made by filters, the preset name and filter order is ignored
        /// </summary>
        /// <param name="other">Anoher filter preset to compare</param>
        /// <returns>true if all filters match the filters on the given preset; false otherwise</returns>
        public bool Equals(FilterPreset other)
        {
            if (_filters.Length != other._filters.Length)
            {
                return(false);
            }

            return(_filters.Select(f1 => other._filters.Any(f1.Equals)).All(found => found));
        }
예제 #3
0
        /// <summary>
        /// Records a filter preset of the given name with the given filters.
        /// If a filter preset with the given name already exists, it is overriden
        /// </summary>
        /// <param name="name">The name to give to the filter preset</param>
        /// <param name="filters">The filters to save on the filter preset</param>
        public void RecordFilterPreset(string name, IFilter[] filters)
        {
            // Search for a filter preset with the given name
            for (int i = 0; i < _filterPresets.Count; i++)
            {
                if (_filterPresets[i].Name == name)
                {
                    _filterPresets[i] = new FilterPreset(name, filters);
                    return;
                }
            }

            _filterPresets.Add(new FilterPreset(name, filters));

            // Save automatically after each Record call
            SaveFilterPresets();
        }
예제 #4
0
        /// <summary>
        /// Loads the filter presets from disk
        /// </summary>
        private void LoadFilterPresets()
        {
            _filterPresets.Clear();

            string savePath = Path.GetDirectoryName(Application.LocalUserAppDataPath) + "\\filterpresets.bin";

            using (FileStream stream = new FileStream(savePath, FileMode.OpenOrCreate))
            {
                // No filters saved
                if (stream.Length == 0)
                {
                    return;
                }

                BinaryReader reader = new BinaryReader(stream);

                int count = reader.ReadInt32();

                for (int i = 0; i < count; i++)
                {
                    _filterPresets.Add(FilterPreset.FromStream(stream));
                }
            }
        }