diff --git a/DwmLutGUI/DwmLutGUI/MainViewModel.cs b/DwmLutGUI/DwmLutGUI/MainViewModel.cs index 288d55e..2d9c50f 100644 --- a/DwmLutGUI/DwmLutGUI/MainViewModel.cs +++ b/DwmLutGUI/DwmLutGUI/MainViewModel.cs @@ -19,7 +19,6 @@ internal class MainViewModel : INotifyPropertyChanged private bool _isActive; private readonly string _configPath; - private readonly Dictionary _config; public MainViewModel() { @@ -30,17 +29,6 @@ public MainViewModel() dispatcherTimer.Start(); _configPath = AppDomain.CurrentDomain.BaseDirectory + "config.xml"; - if (File.Exists(_configPath)) - { - var xElem = XElement.Load(_configPath); - _config = xElem.Descendants("monitor") - .ToDictionary(x => (uint)x.Attribute("id"), - x => new[] { (string)x.Attribute("sdr_lut"), (string)x.Attribute("hdr_lut") }); - } - else - { - _config = new Dictionary(); - } Monitors = new ObservableCollection(); UpdateMonitors(); @@ -75,10 +63,10 @@ public MonitorData SelectedMonitor private void SaveConfig() { var xElem = new XElement("monitors", - _config.Select(x => - new XElement("monitor", new XAttribute("id", x.Key), - x.Value[0] != null ? new XAttribute("sdr_lut", x.Value[0]) : null, - x.Value[1] != null ? new XAttribute("hdr_lut", x.Value[1]) : null))); + Monitors.Select(x => + new XElement("monitor", new XAttribute("id", x.DeviceId), + x.SdrLutPath != null ? new XAttribute("sdr_lut", x.SdrLutPath) : null, + x.HdrLutPath != null ? new XAttribute("hdr_lut", x.HdrLutPath) : null))); xElem.Save(_configPath); } @@ -90,25 +78,6 @@ public string SdrLutPath SelectedMonitor.SdrLutPath = value; OnPropertyChanged(); - var key = SelectedMonitor.DeviceId; - if (!string.IsNullOrEmpty(value)) - { - if (!_config.ContainsKey(key)) - { - _config[key] = new string[2]; - } - - _config[key][0] = value; - } - else - { - _config[key][0] = null; - if (_config[key][1] == null) - { - _config.Remove(key); - } - } - SaveConfig(); } get => SelectedMonitor?.SdrLutPath; @@ -122,25 +91,6 @@ public string HdrLutPath SelectedMonitor.HdrLutPath = value; OnPropertyChanged(); - var key = SelectedMonitor.DeviceId; - if (!string.IsNullOrEmpty(value)) - { - if (!_config.ContainsKey(key)) - { - _config[key] = new string[2]; - } - - _config[key][1] = value; - } - else - { - _config[key][1] = null; - if (_config[key][0] == null) - { - _config.Remove(key); - } - } - SaveConfig(); } get => SelectedMonitor?.HdrLutPath; @@ -165,6 +115,12 @@ public void UpdateMonitors() { var selectedId = SelectedMonitor?.DeviceId; Monitors.Clear(); + List config = null; + if (File.Exists(_configPath)) + { + config = XElement.Load(_configPath).Descendants("monitor").ToList(); + } + var paths = WindowsDisplayAPI.DisplayConfig.PathInfo.GetActivePaths(); foreach (var path in paths) { @@ -190,14 +146,11 @@ public void UpdateMonitors() string sdrLutPath = null; string hdrLutPath = null; - if (_config.ContainsKey(deviceId)) - { - sdrLutPath = _config[deviceId][0]; - } - - if (_config.ContainsKey(deviceId)) + var settings = config?.FirstOrDefault(x => (uint)x.Attribute("id") == deviceId); + if (settings != null) { - hdrLutPath = _config[deviceId][1]; + sdrLutPath = (string)settings.Attribute("sdr_lut"); + hdrLutPath = (string)settings.Attribute("hdr_lut"); } Monitors.Add(new MonitorData(deviceId, path.DisplaySource.SourceId + 1, name, resolution, refreshRate,