diff --git a/.vs/RGBController2/DesignTimeBuild/.dtbcache.v2 b/.vs/RGBController2/DesignTimeBuild/.dtbcache.v2 index d698935..802a423 100644 Binary files a/.vs/RGBController2/DesignTimeBuild/.dtbcache.v2 and b/.vs/RGBController2/DesignTimeBuild/.dtbcache.v2 differ diff --git a/.vs/RGBController2/v16/.suo b/.vs/RGBController2/v16/.suo index 15e1dcd..98f33d7 100644 Binary files a/.vs/RGBController2/v16/.suo and b/.vs/RGBController2/v16/.suo differ diff --git a/RGBController2/ViewModels/MainViewModel.cs b/RGBController2/ViewModels/MainViewModel.cs index 5ed9be0..f8805bf 100644 --- a/RGBController2/ViewModels/MainViewModel.cs +++ b/RGBController2/ViewModels/MainViewModel.cs @@ -9,6 +9,7 @@ using RGBController2.ViewModels.Dialogs; using System.ComponentModel; using System.Windows; using System.Xml; +using System.IO; namespace RGBController2.ViewModels { @@ -18,6 +19,7 @@ namespace RGBController2.ViewModels public ICommand NewTabCommand { get; } public static ICollection Tabs { get; set; } + private string configLocation = "config.xml"; public MainViewModel() { NewTabCommand = new ActionCommand(p => NewTab()); @@ -28,42 +30,44 @@ namespace RGBController2.ViewModels Tabs = _tabs; // Check here that the config file exists - - // Load the config file - using (XmlReader reader = XmlReader.Create("config.xml")) + if (File.Exists(configLocation)) { - string name = ""; - string type = ""; - while (reader.Read()) + // Load the config file + using (XmlReader reader = XmlReader.Create("config.xml")) { - if (reader.IsStartElement()) + string name = ""; + string type = ""; + while (reader.Read()) { - //return only when you have START tag - switch (reader.Name.ToString()) + if (reader.IsStartElement()) { - case "name": - name = reader.ReadString(); - break; - case "type": - type = reader.ReadString(); - break; + //return only when you have START tag + switch (reader.Name.ToString()) + { + case "name": + name = reader.ReadString(); + break; + case "type": + type = reader.ReadString(); + break; + } } - } - // Create the tab here - if (name != "" && type != "") - { - switch(type) + // Create the tab here + if (name != "" && type != "") { - case "arduino": - _tabs.Add(new ArduinoTab(name)); - break; - case "cue": - _tabs.Add(new CueDeviceTab(name)); - break; - } + switch (type) + { + case "arduino": + _tabs.Add(new ArduinoTab(name)); + break; + case "cue": + _tabs.Add(new CueDeviceTab(name)); + break; + } - name = ""; - type = ""; + name = ""; + type = ""; + } } } } @@ -121,10 +125,16 @@ namespace RGBController2.ViewModels /// public void OnWindowClosing(object sender, CancelEventArgs e) { - // ToDo - Save the config to disk + // Check if the config file currently exists + // if it does then we will need to delete it beofre we can save a new config + if (File.Exists(configLocation)) + { + File.Delete(configLocation); + } + // This may need to be saved somwhere better, for now we will just save it // with the executable - XmlWriter xmlWriter = XmlWriter.Create("config.xml"); + XmlWriter xmlWriter = XmlWriter.Create(configLocation); xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("tabs"); @@ -154,8 +164,6 @@ namespace RGBController2.ViewModels xmlWriter.WriteEndDocument(); xmlWriter.Close(); - - } } diff --git a/RGBController2/Views/LightingModes/StaticView.xaml.cs b/RGBController2/Views/LightingModes/StaticView.xaml.cs index b72b8de..b2e56e1 100644 --- a/RGBController2/Views/LightingModes/StaticView.xaml.cs +++ b/RGBController2/Views/LightingModes/StaticView.xaml.cs @@ -26,11 +26,6 @@ namespace RGBController2.Views.LightingModes public StaticView() { InitializeComponent(); - - // This is a bit hacky but ensure we are only creating one ArduinoTab object and using - // that in both the MainViewModel and here - var test = MainViewModel.Tabs.Last(); // FIX ME - this needs to be something else than .Last to find the correct viewmodel - DataContext = test.SelectedLightingMode; } } } diff --git a/RGBController2/Views/MainWindow.xaml.cs b/RGBController2/Views/MainWindow.xaml.cs index db52316..3aa2eb5 100644 --- a/RGBController2/Views/MainWindow.xaml.cs +++ b/RGBController2/Views/MainWindow.xaml.cs @@ -16,6 +16,8 @@ namespace RGBController2.Views // Why? Something to do with MVVM & good practice? var viewModel = new MainViewModel(); DataContext = viewModel; + + // We are using this to hook on the closing event so that we can save our config when the application is closed Closing += viewModel.OnWindowClosing; } } diff --git a/RGBController2/Views/Tabs/ArduinoTabView.xaml.cs b/RGBController2/Views/Tabs/ArduinoTabView.xaml.cs index 0c474ac..1125d59 100644 --- a/RGBController2/Views/Tabs/ArduinoTabView.xaml.cs +++ b/RGBController2/Views/Tabs/ArduinoTabView.xaml.cs @@ -22,8 +22,6 @@ namespace RGBController2.Views.Tabs public ArduinoTabView() { InitializeComponent(); - - //DataContext = new ArduinoTab(); } } } diff --git a/RGBController2/Views/Tabs/CUEDeviceTabView.xaml.cs b/RGBController2/Views/Tabs/CUEDeviceTabView.xaml.cs index 6646083..83a2a7d 100644 --- a/RGBController2/Views/Tabs/CUEDeviceTabView.xaml.cs +++ b/RGBController2/Views/Tabs/CUEDeviceTabView.xaml.cs @@ -22,8 +22,6 @@ namespace RGBController2.Views.Tabs public CUEDeviceTabView() { InitializeComponent(); - - //DataContext = new ArduinoTab(); } } } diff --git a/RGBController2/obj/Debug/netcoreapp3.1/RGBController2.csprojAssemblyReference.cache b/RGBController2/obj/Debug/netcoreapp3.1/RGBController2.csprojAssemblyReference.cache index 9e1440b..f50b509 100644 Binary files a/RGBController2/obj/Debug/netcoreapp3.1/RGBController2.csprojAssemblyReference.cache and b/RGBController2/obj/Debug/netcoreapp3.1/RGBController2.csprojAssemblyReference.cache differ