added star on windows startup and added device comport to the config file
This commit is contained in:
parent
e47a03695f
commit
ae1c760ffa
Binary file not shown.
Binary file not shown.
|
@ -10,16 +10,38 @@ using System.ComponentModel;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace RGBController2.ViewModels
|
namespace RGBController2.ViewModels
|
||||||
{
|
{
|
||||||
class MainViewModel
|
class MainViewModel
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// This is the directory of the exe
|
||||||
|
/// </summary>
|
||||||
|
public static string BaseDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
|
||||||
|
|
||||||
private readonly ObservableCollection<Tab> _tabs;
|
private readonly ObservableCollection<Tab> _tabs;
|
||||||
public ICommand NewTabCommand { get; }
|
public ICommand NewTabCommand { get; }
|
||||||
public static ICollection<Tab> Tabs { get; set; }
|
public static ICollection<Tab> Tabs { get; set; }
|
||||||
|
|
||||||
private string configLocation = "config.xml";
|
private string configLocation = "config.xml";
|
||||||
|
|
||||||
|
private bool _runOnStartUp;
|
||||||
|
|
||||||
|
public bool RunOnStartUp
|
||||||
|
{
|
||||||
|
get { return _runOnStartUp; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value != _runOnStartUp)
|
||||||
|
{
|
||||||
|
_runOnStartUp = value;
|
||||||
|
RunAppOnStartup(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public MainViewModel()
|
public MainViewModel()
|
||||||
{
|
{
|
||||||
NewTabCommand = new ActionCommand(p => NewTab());
|
NewTabCommand = new ActionCommand(p => NewTab());
|
||||||
|
@ -29,6 +51,8 @@ namespace RGBController2.ViewModels
|
||||||
|
|
||||||
Tabs = _tabs;
|
Tabs = _tabs;
|
||||||
|
|
||||||
|
_runOnStartUp = IsRunAppOnStartup();
|
||||||
|
|
||||||
// Check here that the config file exists
|
// Check here that the config file exists
|
||||||
if (File.Exists(configLocation))
|
if (File.Exists(configLocation))
|
||||||
{
|
{
|
||||||
|
@ -37,6 +61,8 @@ namespace RGBController2.ViewModels
|
||||||
{
|
{
|
||||||
string name = "";
|
string name = "";
|
||||||
string type = "";
|
string type = "";
|
||||||
|
string device = "";
|
||||||
|
|
||||||
while (reader.Read())
|
while (reader.Read())
|
||||||
{
|
{
|
||||||
if (reader.IsStartElement())
|
if (reader.IsStartElement())
|
||||||
|
@ -50,23 +76,53 @@ namespace RGBController2.ViewModels
|
||||||
case "type":
|
case "type":
|
||||||
type = reader.ReadString();
|
type = reader.ReadString();
|
||||||
break;
|
break;
|
||||||
|
case "device":
|
||||||
|
device = reader.ReadString();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Create the tab here
|
// Create the tab here
|
||||||
if (name != "" && type != "")
|
if (name != "" && type != "" && device !="")
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case "arduino":
|
case "arduino":
|
||||||
_tabs.Add(new ArduinoTab(name));
|
{
|
||||||
break;
|
var tab = new ArduinoTab(name);
|
||||||
|
tab.SelectedPort = device;
|
||||||
|
_tabs.Add(tab);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "cue":
|
case "cue":
|
||||||
_tabs.Add(new CueDeviceTab(name));
|
{
|
||||||
break;
|
var tab = new CueDeviceTab(name);
|
||||||
|
switch (device)
|
||||||
|
{
|
||||||
|
case "Headset":
|
||||||
|
tab.SelectedDevice = CUE.NET.Devices.Generic.Enums.CorsairDeviceType.Headset;
|
||||||
|
break;
|
||||||
|
case "HeadsetStand":
|
||||||
|
tab.SelectedDevice = CUE.NET.Devices.Generic.Enums.CorsairDeviceType.HeadsetStand;
|
||||||
|
break;
|
||||||
|
case "Keyboard":
|
||||||
|
tab.SelectedDevice = CUE.NET.Devices.Generic.Enums.CorsairDeviceType.Keyboard;
|
||||||
|
break;
|
||||||
|
case "Mouse":
|
||||||
|
tab.SelectedDevice = CUE.NET.Devices.Generic.Enums.CorsairDeviceType.Mouse;
|
||||||
|
break;
|
||||||
|
case "Mousemat":
|
||||||
|
tab.SelectedDevice = CUE.NET.Devices.Generic.Enums.CorsairDeviceType.Mousemat;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
_tabs.Add(tab);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
name = "";
|
name = "";
|
||||||
type = "";
|
type = "";
|
||||||
|
device = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,11 +208,17 @@ namespace RGBController2.ViewModels
|
||||||
xmlWriter.WriteStartElement("type");
|
xmlWriter.WriteStartElement("type");
|
||||||
xmlWriter.WriteString("arduino");
|
xmlWriter.WriteString("arduino");
|
||||||
xmlWriter.WriteEndElement();
|
xmlWriter.WriteEndElement();
|
||||||
|
xmlWriter.WriteStartElement("device");
|
||||||
|
xmlWriter.WriteString(((ArduinoTab)tab).SelectedPort);
|
||||||
|
xmlWriter.WriteEndElement();
|
||||||
break;
|
break;
|
||||||
case Tab.tabType.CUE:
|
case Tab.tabType.CUE:
|
||||||
xmlWriter.WriteStartElement("type");
|
xmlWriter.WriteStartElement("type");
|
||||||
xmlWriter.WriteString("cue");
|
xmlWriter.WriteString("cue");
|
||||||
xmlWriter.WriteEndElement();
|
xmlWriter.WriteEndElement();
|
||||||
|
xmlWriter.WriteStartElement("device");
|
||||||
|
xmlWriter.WriteString(((CueDeviceTab)tab).SelectedDevice.ToString());
|
||||||
|
xmlWriter.WriteEndElement();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
xmlWriter.WriteEndElement();
|
xmlWriter.WriteEndElement();
|
||||||
|
@ -166,5 +228,33 @@ namespace RGBController2.ViewModels
|
||||||
xmlWriter.Close();
|
xmlWriter.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Checks if run on startup is enabled in the registry for the current user.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>Truw if run on startup is enabled, false if not</returns>
|
||||||
|
private bool IsRunAppOnStartup()
|
||||||
|
{
|
||||||
|
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
|
||||||
|
return key.GetValueNames().Contains("RGB Application");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Helper function for modifying the registry to enable/disable run on startup.
|
||||||
|
/// This only enables run on startup for the current user, not the whole machine.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="enabled">True if should be enabled, false if should be disabled.</param>
|
||||||
|
private void RunAppOnStartup(bool enabled)
|
||||||
|
{
|
||||||
|
if (enabled)
|
||||||
|
{
|
||||||
|
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
|
||||||
|
key.SetValue("RGB Application", Path.Combine(BaseDir, System.AppDomain.CurrentDomain.FriendlyName) + ".exe");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
|
||||||
|
key.DeleteValue("RGB Application", false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ namespace RGBController2.ViewModels.Tabs
|
||||||
{
|
{
|
||||||
if (value != _selectedDevice)
|
if (value != _selectedDevice)
|
||||||
{
|
{
|
||||||
|
_selectedDevice = value;
|
||||||
// Connect to the device
|
// Connect to the device
|
||||||
_cueDeviceBoard.ConnectToDevice(value);
|
_cueDeviceBoard.ConnectToDevice(value);
|
||||||
if (_cueDeviceBoard.Connected)
|
if (_cueDeviceBoard.Connected)
|
||||||
|
|
|
@ -18,7 +18,8 @@
|
||||||
<DockPanel>
|
<DockPanel>
|
||||||
<Menu DockPanel.Dock="Top">
|
<Menu DockPanel.Dock="Top">
|
||||||
<MenuItem Header="_Options">
|
<MenuItem Header="_Options">
|
||||||
<MenuItem Header="_Flux" IsCheckable="True" IsChecked="True" />
|
<MenuItem Header="_Run on Startup" IsCheckable="True" IsChecked="{Binding RunOnStartUp}" />
|
||||||
|
<MenuItem Header="_Flux" IsCheckable="True" IsChecked="False" />
|
||||||
<Separator />
|
<Separator />
|
||||||
<MenuItem Header="_Exit" />
|
<MenuItem Header="_Exit" />
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
using RGBController2.ViewModels;
|
using RGBController2.ViewModels;
|
||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
|
||||||
namespace RGBController2.Views
|
namespace RGBController2.Views
|
||||||
|
|
Binary file not shown.
|
@ -16,5 +16,5 @@ C:\Users\Conor\Desktop\RGB Contorller Tabs Test\RGBController\RGBController2\App
|
||||||
1991249145588
|
1991249145588
|
||||||
Views\Dialogs\NewTabDialogView.xaml;Views\LightingModes\AnimationView.xaml;Views\LightingModes\InformationView.xaml;Views\LightingModes\StaticView.xaml;Views\MainWindow.xaml;Views\Tabs\ArduinoTabView.xaml;Views\Tabs\CUEDeviceTabView.xaml;
|
Views\Dialogs\NewTabDialogView.xaml;Views\LightingModes\AnimationView.xaml;Views\LightingModes\InformationView.xaml;Views\LightingModes\StaticView.xaml;Views\MainWindow.xaml;Views\Tabs\ArduinoTabView.xaml;Views\Tabs\CUEDeviceTabView.xaml;
|
||||||
|
|
||||||
True
|
False
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue