diff --git a/Artemis/Artemis.sln b/Artemis/Artemis.sln index 48cd72722..216a773bc 100644 --- a/Artemis/Artemis.sln +++ b/Artemis/Artemis.sln @@ -1,20 +1,91 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 -VisualStudioVersion = 14.0.24720.0 +VisualStudioVersion = 14.0.23107.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Artemis", "Artemis\Artemis.csproj", "{ED9997A2-E54C-4E9F-9350-62BE672C3ABE}" EndProject +Project("{6141683F-8A12-4E36-9623-2EB02B2C2303}") = "ArtemisSetup", "ArtemisSetup\ArtemisSetup.isproj", "{9E76B2E0-12AE-431D-8FA5-2233D6853F29}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution + CD_ROM|Any CPU = CD_ROM|Any CPU + CD_ROM|x64 = CD_ROM|x64 + CD_ROM|x86 = CD_ROM|x86 Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + DVD-5|Any CPU = DVD-5|Any CPU + DVD-5|x64 = DVD-5|x64 + DVD-5|x86 = DVD-5|x86 Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 + SingleImage|Any CPU = SingleImage|Any CPU + SingleImage|x64 = SingleImage|x64 + SingleImage|x86 = SingleImage|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.CD_ROM|Any CPU.ActiveCfg = Release|Any CPU + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.CD_ROM|Any CPU.Build.0 = Release|Any CPU + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.CD_ROM|x64.ActiveCfg = Release|x64 + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.CD_ROM|x64.Build.0 = Release|x64 + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.CD_ROM|x86.ActiveCfg = Release|x86 + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.CD_ROM|x86.Build.0 = Release|x86 {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.Debug|x64.ActiveCfg = Debug|x64 + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.Debug|x64.Build.0 = Debug|x64 + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.Debug|x86.ActiveCfg = Debug|x86 + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.Debug|x86.Build.0 = Debug|x86 + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.DVD-5|Any CPU.ActiveCfg = Debug|Any CPU + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.DVD-5|Any CPU.Build.0 = Debug|Any CPU + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.DVD-5|x64.ActiveCfg = Debug|x64 + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.DVD-5|x64.Build.0 = Debug|x64 + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.DVD-5|x86.ActiveCfg = Debug|x86 + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.DVD-5|x86.Build.0 = Debug|x86 {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.Release|Any CPU.ActiveCfg = Release|Any CPU {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.Release|Any CPU.Build.0 = Release|Any CPU + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.Release|x64.ActiveCfg = Release|x64 + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.Release|x64.Build.0 = Release|x64 + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.Release|x86.ActiveCfg = Release|x86 + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.Release|x86.Build.0 = Release|x86 + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.SingleImage|Any CPU.ActiveCfg = Release|Any CPU + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.SingleImage|Any CPU.Build.0 = Release|Any CPU + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.SingleImage|x64.ActiveCfg = Release|x64 + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.SingleImage|x64.Build.0 = Release|x64 + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.SingleImage|x86.ActiveCfg = Release|x86 + {ED9997A2-E54C-4E9F-9350-62BE672C3ABE}.SingleImage|x86.Build.0 = Release|x86 + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.CD_ROM|Any CPU.ActiveCfg = CD_ROM + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.CD_ROM|Any CPU.Build.0 = CD_ROM + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.CD_ROM|x64.ActiveCfg = CD_ROM + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.CD_ROM|x64.Build.0 = CD_ROM + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.CD_ROM|x86.ActiveCfg = CD_ROM + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.CD_ROM|x86.Build.0 = CD_ROM + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.Debug|Any CPU.ActiveCfg = DVD-5 + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.Debug|Any CPU.Build.0 = DVD-5 + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.Debug|x64.ActiveCfg = DVD-5 + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.Debug|x64.Build.0 = DVD-5 + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.Debug|x86.ActiveCfg = DVD-5 + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.Debug|x86.Build.0 = DVD-5 + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.DVD-5|Any CPU.ActiveCfg = DVD-5 + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.DVD-5|Any CPU.Build.0 = DVD-5 + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.DVD-5|x64.ActiveCfg = DVD-5 + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.DVD-5|x64.Build.0 = DVD-5 + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.DVD-5|x86.ActiveCfg = DVD-5 + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.DVD-5|x86.Build.0 = DVD-5 + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.Release|Any CPU.ActiveCfg = SingleImage + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.Release|Any CPU.Build.0 = SingleImage + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.Release|x64.ActiveCfg = SingleImage + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.Release|x64.Build.0 = SingleImage + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.Release|x86.ActiveCfg = SingleImage + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.Release|x86.Build.0 = SingleImage + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.SingleImage|Any CPU.ActiveCfg = SingleImage + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.SingleImage|Any CPU.Build.0 = SingleImage + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.SingleImage|x64.ActiveCfg = SingleImage + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.SingleImage|x64.Build.0 = SingleImage + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.SingleImage|x86.ActiveCfg = SingleImage + {9E76B2E0-12AE-431D-8FA5-2233D6853F29}.SingleImage|x86.Build.0 = SingleImage EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Artemis/Artemis/App.config b/Artemis/Artemis/App.config index 3ae824369..af623241d 100644 --- a/Artemis/Artemis/App.config +++ b/Artemis/Artemis/App.config @@ -2,19 +2,44 @@ - -
-
-
-
-
-
-
-
-
-
-
-
+ +
+
+
+
+
+
+
+
+
+
+
+
@@ -210,12 +235,20 @@ - + + + + + + + + + diff --git a/Artemis/Artemis/App.xaml b/Artemis/Artemis/App.xaml index c80f295e0..0fe50d3fd 100644 --- a/Artemis/Artemis/App.xaml +++ b/Artemis/Artemis/App.xaml @@ -3,12 +3,12 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:Artemis" DispatcherUnhandledException="Application_DispatcherUnhandledException" - Startup="Application_Startup"> + ShutdownMode="OnExplicitShutdown"> - + diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index dfc6cda5d..db806ab53 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -23,6 +23,8 @@ false + + C:\Users\spoin\Desktop\Artemis builds\ true Disk @@ -38,8 +40,6 @@ false true true - - x64 @@ -76,11 +76,57 @@ logo.ico + + true + bin\x86\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + + + bin\x86\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + true + bin\x64\Debug\ + DEBUG;TRACE + full + x64 + prompt + MinimumRecommendedRules.ruleset + + + bin\x64\Release\ + TRACE + true + pdbonly + x64 + prompt + MinimumRecommendedRules.ruleset + true + + + ..\packages\Autofac.3.5.2\lib\net40\Autofac.dll + True + ..\packages\Caliburn.Micro.Core.2.0.2\lib\net45\Caliburn.Micro.dll True + + ..\packages\Caliburn.Micro.AutofacBootstrap.2.0.8\lib\net40\Caliburn.Micro.Autofac.dll + True + ..\packages\Caliburn.Micro.2.0.2\lib\net45\Caliburn.Micro.Platform.dll True @@ -93,6 +139,14 @@ ..\packages\CUE.NET.1.0.0\lib\net45\CUE.NET.dll True + + ..\packages\MouseKeyHook.5.4.0\lib\net40\Gma.System.MouseKeyHook.dll + True + + + ..\packages\Hardcodet.NotifyIcon.Wpf.1.0.5\lib\net451\Hardcodet.Wpf.TaskbarNotification.dll + True + ..\packages\log4net.2.0.5\lib\net45-full\log4net.dll True @@ -101,14 +155,12 @@ ..\packages\MahApps.Metro.1.3.0-ALPHA017\lib\net45\MahApps.Metro.dll True + + E:\Downloads\Chome Downloads\MemorySharp-master\MemorySharp-master\MemorySharp\bin\Release\MemorySharp.dll + False - - False - .\MyMemory-x64.dll - False - ..\packages\NAudio.1.7.3\lib\net35\NAudio.dll True @@ -117,10 +169,6 @@ ..\packages\Newtonsoft.Json.8.0.2\lib\net45\Newtonsoft.Json.dll True - - ..\packages\Open.WinKeyboardHook.1.0.10.0\lib\net45\Open.WinKeyboardHook.dll - True - @@ -222,6 +270,7 @@ True + True True @@ -244,6 +293,11 @@ + + True + True + Resources.resx + True True @@ -260,6 +314,7 @@ + @@ -280,6 +335,7 @@ + EffectsView.xaml @@ -322,16 +378,14 @@ ShellView.xaml + + SystemTrayView.xaml + Code - - True - True - Resources.resx - ResXFileCodeGenerator Resources.Designer.cs @@ -360,9 +414,12 @@ SettingsSingleFileGenerator VolumeDisplay.Designer.cs - + + + + SettingsSingleFileGenerator Offsets.Designer.cs @@ -437,6 +494,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + @@ -446,8 +507,10 @@ PreserveNewest - - + + PreserveNewest + + diff --git a/Artemis/Artemis/ArtemisBootstrapper.cs b/Artemis/Artemis/ArtemisBootstrapper.cs index acea28cf2..36a84f7ce 100644 --- a/Artemis/Artemis/ArtemisBootstrapper.cs +++ b/Artemis/Artemis/ArtemisBootstrapper.cs @@ -1,19 +1,31 @@ using System.Windows; using Artemis.ViewModels; +using Autofac; using Caliburn.Micro; +using Caliburn.Micro.Autofac; namespace Artemis { - public class ArtemisBootstrapper : BootstrapperBase + public class ArtemisBootstrapper : AutofacBootstrapper { public ArtemisBootstrapper() { Initialize(); } + protected override void ConfigureContainer(ContainerBuilder builder) + { + base.ConfigureContainer(builder); + + // create a window manager instance to be used by everyone asking for one (including Caliburn.Micro) + builder.RegisterInstance(new WindowManager()); + builder.RegisterType(); + builder.RegisterType(); + } + protected override void OnStartup(object sender, StartupEventArgs e) { - DisplayRootViewFor(); + DisplayRootViewFor(); } } } \ No newline at end of file diff --git a/Artemis/Artemis/KeyboardProviders/Corsair/K70.cs b/Artemis/Artemis/KeyboardProviders/Corsair/K70.cs index 1146be31e..765381193 100644 --- a/Artemis/Artemis/KeyboardProviders/Corsair/K70.cs +++ b/Artemis/Artemis/KeyboardProviders/Corsair/K70.cs @@ -1,9 +1,11 @@ -using System.Drawing; +using System; +using System.Drawing; +using System.Windows.Forms; +using Artemis.Utilities; using CUE.NET; using CUE.NET.Devices.Generic.Enums; using CUE.NET.Devices.Keyboard; -using CUE.NET.Brushes; -using CUE.NET.Devices.Keyboard.Keys; +using CUE.NET.Exceptions; namespace Artemis.KeyboardProviders.Corsair { @@ -15,8 +17,26 @@ namespace Artemis.KeyboardProviders.Corsair { Name = "Corsair Gaming K70 RGB"; } + + public override bool CanEnable() + { + try + { + CueSDK.Initialize(); + } + catch (CUEException e) + { + if (e.Error == CorsairError.ServerNotFound) + return false; + throw; + } + + return true; + + } + /// - /// Enables the SDK and sets updatemode to manual as well as the color of the background to black. + /// Enables the SDK and sets updatemode to manual as well as the color of the background to black. /// public override void Enable() { @@ -24,13 +44,15 @@ namespace Artemis.KeyboardProviders.Corsair { CueSDK.Initialize(); } - catch (CUE.NET.Exceptions.WrapperException) {/*CUE is already initialized*/} + catch (WrapperException) + { + /*CUE is already initialized*/ + } _keyboard = CueSDK.KeyboardSDK; Height = (int)_keyboard.KeyboardRectangle.Height; Width = (int)_keyboard.KeyboardRectangle.Width; - _keyboard.UpdateMode = UpdateMode.Manual; - _keyboard.Brush = new SolidColorBrush(Color.Black); + // _keyboard.UpdateMode = UpdateMode.Manual; _keyboard.Update(true); } @@ -39,31 +61,28 @@ namespace Artemis.KeyboardProviders.Corsair } /// - /// Properly resizes any size bitmap to the keyboard by creating a rectangle whose size is dependent on the bitmap size. - /// Does not reset the color each time. Uncomment line 48 for collor reset. + /// Properly resizes any size bitmap to the keyboard by creating a rectangle whose size is dependent on the bitmap + /// size. + /// Does not reset the color each time. Uncomment line 48 for collor reset. /// - /// + /// public override void DrawBitmap(Bitmap bitmap) { - RectangleF[,] ledRectangles = new RectangleF[bitmap.Width, bitmap.Height]; - RectangleKeyGroup[,] ledGroups = new RectangleKeyGroup[bitmap.Width, bitmap.Height]; - //_keyboard.Brush = new SolidColorBrush(Color.Black); - for (var x = 0; x < bitmap.Width; x++) + using ( + var resized = ImageUtilities.ResizeImage(bitmap, + (int)_keyboard.KeyboardRectangle.Width, + (int)_keyboard.KeyboardRectangle.Height) + ) { - for (var y = 0; y < bitmap.Height; y++) + foreach (var item in _keyboard.Keys) { - ledRectangles[x, y] = new RectangleF(_keyboard.KeyboardRectangle.X * (x * (_keyboard.KeyboardRectangle.Width / bitmap.Width / _keyboard.KeyboardRectangle.X)), _keyboard.KeyboardRectangle.Y * (y * (_keyboard.KeyboardRectangle.Height / bitmap.Height / _keyboard.KeyboardRectangle.Y)), _keyboard.KeyboardRectangle.Width / bitmap.Width, _keyboard.KeyboardRectangle.Height / bitmap.Height); - ledGroups[x, y] = new RectangleKeyGroup(_keyboard, ledRectangles[x, y], 0.01f) { Brush = new SolidColorBrush(bitmap.GetPixel(x, y)) }; - } - } - _keyboard.Update(); - for (var x = 0; x < bitmap.Width; x++) - { - for (var y = 0; y < bitmap.Height; y++) - { - _keyboard.DetachKeyGroup(ledGroups[x, y]); + var ledColor = resized.GetPixel((int)item.KeyRectangle.X, (int)item.KeyRectangle.Y); + if (ledColor == Color.FromArgb(0, 0, 0, 0)) + ledColor = Color.Black; + item.Led.Color = ledColor; } } + _keyboard.Update(true); } } } \ No newline at end of file diff --git a/Artemis/Artemis/KeyboardProviders/Corsair/K95.cs b/Artemis/Artemis/KeyboardProviders/Corsair/K95.cs index 65856a681..02184d6d9 100644 --- a/Artemis/Artemis/KeyboardProviders/Corsair/K95.cs +++ b/Artemis/Artemis/KeyboardProviders/Corsair/K95.cs @@ -1,9 +1,11 @@ using System; using System.Drawing; -using CUE.NET; -using CUE.NET.Devices.Keyboard; +using System.Windows.Forms; using Artemis.Utilities; -using CUE.NET.Brushes; +using CUE.NET; +using CUE.NET.Devices.Generic.Enums; +using CUE.NET.Devices.Keyboard; +using CUE.NET.Exceptions; namespace Artemis.KeyboardProviders.Corsair { @@ -16,8 +18,25 @@ namespace Artemis.KeyboardProviders.Corsair Name = "Corsair Gaming K95 RGB"; } + public override bool CanEnable() + { + try + { + CueSDK.Initialize(); + } + catch (CUEException e) + { + if (e.Error == CorsairError.ServerNotFound) + return false; + throw; + } + + return true; + + } + /// - /// Enables the SDK and sets updatemode to manual as well as the color of the background to black. + /// Enables the SDK and sets updatemode to manual as well as the color of the background to black. /// public override void Enable() { @@ -25,12 +44,15 @@ namespace Artemis.KeyboardProviders.Corsair { CueSDK.Initialize(); } - catch (CUE.NET.Exceptions.WrapperException){/*CUE is already initialized*/} + catch (WrapperException) + { + /*CUE is already initialized*/ + } _keyboard = CueSDK.KeyboardSDK; - Height = (int)_keyboard.KeyboardRectangle.Height; - Width = (int)_keyboard.KeyboardRectangle.Width; + Height = (int) _keyboard.KeyboardRectangle.Height; + Width = (int) _keyboard.KeyboardRectangle.Width; - // _keyboard.UpdateMode = UpdateMode.Manual; + // _keyboard.UpdateMode = UpdateMode.Manual; _keyboard.Update(true); } @@ -39,50 +61,28 @@ namespace Artemis.KeyboardProviders.Corsair } /// - /// Properly resizes any size bitmap to the keyboard by creating a rectangle whose size is dependent on the bitmap size. - /// Does not reset the color each time. Uncomment line 48 for collor reset. + /// Properly resizes any size bitmap to the keyboard by creating a rectangle whose size is dependent on the bitmap + /// size. + /// Does not reset the color each time. Uncomment line 48 for collor reset. /// /// public override void DrawBitmap(Bitmap bitmap) { using ( var resized = ImageUtilities.ResizeImage(bitmap, - (int)_keyboard.KeyboardRectangle.Width, - (int)_keyboard.KeyboardRectangle.Height) - ) + (int) _keyboard.KeyboardRectangle.Width, + (int) _keyboard.KeyboardRectangle.Height) + ) { foreach (var item in _keyboard.Keys) { - Color ledColor = resized.GetPixel((int)item.KeyRectangle.X, (int)item.KeyRectangle.Y); + var ledColor = resized.GetPixel((int) item.KeyRectangle.X, (int) item.KeyRectangle.Y); if (ledColor == Color.FromArgb(0, 0, 0, 0)) ledColor = Color.Black; item.Led.Color = ledColor; } } _keyboard.Update(true); - } - - /* - RectangleF[,] ledRectangles = new RectangleF[bitmap.Width, bitmap.Height]; - RectangleKeyGroup[,] ledGroups = new RectangleKeyGroup[bitmap.Width, bitmap.Height]; - //_keyboard.Brush = new SolidColorBrush(Color.Black); - for (var x = 0 ; x < bitmap.Width; x++) - { - for (var y = 0; y < bitmap.Height; y++) - { - ledRectangles[x, y] = new RectangleF(_keyboard.KeyboardRectangle.X * (x*(_keyboard.KeyboardRectangle.Width / bitmap.Width / _keyboard.KeyboardRectangle.X)), _keyboard.KeyboardRectangle.Y*(y*(_keyboard.KeyboardRectangle.Height / bitmap.Height / _keyboard.KeyboardRectangle.Y)), _keyboard.KeyboardRectangle.Width / bitmap.Width, _keyboard.KeyboardRectangle.Height / bitmap.Height); - ledGroups[x, y] = new RectangleKeyGroup(_keyboard, ledRectangles[x, y], 0.01f) { Brush = new SolidColorBrush(bitmap.GetPixel(x, y)) }; - } - } - _keyboard.Update(); - for (var x = 0; x < bitmap.Width; x++) - { - for (var y = 0; y < bitmap.Height; y++) - { - _keyboard.DetachKeyGroup(ledGroups[x, y]); - } - } - */ } } \ No newline at end of file diff --git a/Artemis/Artemis/KeyboardProviders/KeyboardProvider.cs b/Artemis/Artemis/KeyboardProviders/KeyboardProvider.cs index b1f3dd154..ecb9a5796 100644 --- a/Artemis/Artemis/KeyboardProviders/KeyboardProvider.cs +++ b/Artemis/Artemis/KeyboardProviders/KeyboardProvider.cs @@ -8,18 +8,19 @@ namespace Artemis.KeyboardProviders public int Height { get; set; } public int Width { get; set; } + public abstract bool CanEnable(); public abstract void Enable(); public abstract void Disable(); public abstract void DrawBitmap(Bitmap bitmap); /// - /// Returns a bitmap matching the keyboard's dimensions + /// Returns a bitmap matching the keyboard's dimensions /// /// public Bitmap KeyboardBitmap() => new Bitmap(Width, Height); /// - /// Returns a bitmap matching the keyboard's dimensions using the provided scale + /// Returns a bitmap matching the keyboard's dimensions using the provided scale /// /// public Bitmap KeyboardBitmap(int scale) => new Bitmap(Width*scale, Height*scale); diff --git a/Artemis/Artemis/KeyboardProviders/Logitech/Orion.cs b/Artemis/Artemis/KeyboardProviders/Logitech/Orion.cs index a8ef91b11..a109c0ad6 100644 --- a/Artemis/Artemis/KeyboardProviders/Logitech/Orion.cs +++ b/Artemis/Artemis/KeyboardProviders/Logitech/Orion.cs @@ -13,6 +13,12 @@ namespace Artemis.KeyboardProviders.Logitech Width = 21; } + public override bool CanEnable() + { + // TODO + return true; + } + public override void Enable() { // Initialize the SDK diff --git a/Artemis/Artemis/KeyboardProviders/Logitech/Utilities/KeyboardNames.cs b/Artemis/Artemis/KeyboardProviders/Logitech/Utilities/KeyboardNames.cs index 57f1ec167..32da4051d 100644 --- a/Artemis/Artemis/KeyboardProviders/Logitech/Utilities/KeyboardNames.cs +++ b/Artemis/Artemis/KeyboardProviders/Logitech/Utilities/KeyboardNames.cs @@ -107,5 +107,5 @@ namespace Artemis.KeyboardProviders.Logitech.Utilities NUM_ZERO = 0x52, NUM_PERIOD = 0x53, TEST = 0x1 - }; + } } \ No newline at end of file diff --git a/Artemis/Artemis/KeyboardProviders/Logitech/Utilities/LogitechGSDK.cs b/Artemis/Artemis/KeyboardProviders/Logitech/Utilities/LogitechGSDK.cs index 71a47313d..87495914c 100644 --- a/Artemis/Artemis/KeyboardProviders/Logitech/Utilities/LogitechGSDK.cs +++ b/Artemis/Artemis/KeyboardProviders/Logitech/Utilities/LogitechGSDK.cs @@ -11,9 +11,9 @@ namespace Artemis.KeyboardProviders.Logitech.Utilities private const int LOGI_DEVICETYPE_RGB_ORD = 1; private const int LOGI_DEVICETYPE_PERKEY_RGB_ORD = 2; - public const int LOGI_DEVICETYPE_MONOCHROME = (1 << LOGI_DEVICETYPE_MONOCHROME_ORD); - public const int LOGI_DEVICETYPE_RGB = (1 << LOGI_DEVICETYPE_RGB_ORD); - public const int LOGI_DEVICETYPE_PERKEY_RGB = (1 << LOGI_DEVICETYPE_PERKEY_RGB_ORD); + public const int LOGI_DEVICETYPE_MONOCHROME = 1 << LOGI_DEVICETYPE_MONOCHROME_ORD; + public const int LOGI_DEVICETYPE_RGB = 1 << LOGI_DEVICETYPE_RGB_ORD; + public const int LOGI_DEVICETYPE_PERKEY_RGB = 1 << LOGI_DEVICETYPE_PERKEY_RGB_ORD; public const int LOGI_LED_BITMAP_WIDTH = 21; public const int LOGI_LED_BITMAP_HEIGHT = 6; public const int LOGI_LED_BITMAP_BYTES_PER_KEY = 4; diff --git a/Artemis/Artemis/KeyboardProviders/Logitech/Utilities/OrionUtilities.cs b/Artemis/Artemis/KeyboardProviders/Logitech/Utilities/OrionUtilities.cs index 41682dd9b..2ab8a1418 100644 --- a/Artemis/Artemis/KeyboardProviders/Logitech/Utilities/OrionUtilities.cs +++ b/Artemis/Artemis/KeyboardProviders/Logitech/Utilities/OrionUtilities.cs @@ -17,7 +17,7 @@ namespace Artemis.KeyboardProviders.Logitech.Utilities var depth = Image.GetPixelFormatSize(b.PixelFormat); var step = depth/8; - var pixels = new byte[(21*6)*step]; + var pixels = new byte[21*6*step]; var iptr = bitmapData.Scan0; // Copy data from pointer to array diff --git a/Artemis/Artemis/KeyboardProviders/Razer/BlackWidow.cs b/Artemis/Artemis/KeyboardProviders/Razer/BlackWidow.cs index 5bc986d26..15cf44672 100644 --- a/Artemis/Artemis/KeyboardProviders/Razer/BlackWidow.cs +++ b/Artemis/Artemis/KeyboardProviders/Razer/BlackWidow.cs @@ -1,7 +1,9 @@ -using System.Drawing; +using System; +using System.Drawing; using Artemis.KeyboardProviders.Razer.Utilities; using Corale.Colore.Core; using Corale.Colore.Razer.Keyboard; +using Color = Corale.Colore.Core.Color; namespace Artemis.KeyboardProviders.Razer { @@ -12,11 +14,32 @@ namespace Artemis.KeyboardProviders.Razer Name = "Razer BlackWidow Chroma"; } + public override bool CanEnable() + { + if (!Chroma.IsSdkAvailable()) + return false; + + // Some people have Synapse installed, but not a Chroma keyboard, deal with this + try + { + // Create a bitmap to send as a test + var b = new Bitmap(22, 6); + var razerArray = RazerUtilities.BitmapColorArray(b, 6, 22); + Chroma.Instance.Keyboard.SetGrid(razerArray); + Chroma.Instance.Keyboard.Clear(); + } + catch (NullReferenceException) + { + return false; + } + return true; + } + public override void Enable() { Chroma.Instance.Initialize(); - Height = (int)Constants.MaxRows; - Width = (int)Constants.MaxColumns; + Height = (int) Constants.MaxRows; + Width = (int) Constants.MaxColumns; } public override void Disable() diff --git a/Artemis/Artemis/Models/EffectModel.cs b/Artemis/Artemis/Models/EffectModel.cs index 27a1fac9b..f2623faa1 100644 --- a/Artemis/Artemis/Models/EffectModel.cs +++ b/Artemis/Artemis/Models/EffectModel.cs @@ -5,6 +5,8 @@ namespace Artemis.Models { public abstract class EffectModel : IDisposable { + public delegate void SettingsUpdateHandler(EffectSettings settings); + public MainModel MainModel; public string Name; @@ -15,6 +17,8 @@ namespace Artemis.Models public abstract void Dispose(); + public event SettingsUpdateHandler SettingsUpdateEvent; + // Called on creation public abstract void Enable(); diff --git a/Artemis/Artemis/Models/GameModel.cs b/Artemis/Artemis/Models/GameModel.cs index 8a30ac30f..b1addf204 100644 --- a/Artemis/Artemis/Models/GameModel.cs +++ b/Artemis/Artemis/Models/GameModel.cs @@ -2,7 +2,7 @@ { public abstract class GameModel : EffectModel { - public abstract bool Enabled(); + public bool Enabled; public string ProcessName; protected GameModel(MainModel mainModel) : base(mainModel) diff --git a/Artemis/Artemis/Models/MainModel.cs b/Artemis/Artemis/Models/MainModel.cs index f1760c8f7..e795e21b7 100644 --- a/Artemis/Artemis/Models/MainModel.cs +++ b/Artemis/Artemis/Models/MainModel.cs @@ -4,10 +4,12 @@ using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Threading; +using System.Windows.Forms; using Artemis.Events; using Artemis.KeyboardProviders; using Artemis.Settings; using Artemis.Utilities.GameState; +using Artemis.Utilities.Keyboard; using Artemis.Utilities.Memory; using Caliburn.Micro; @@ -23,6 +25,7 @@ namespace Artemis.Models EffectModels = new List(); KeyboardProviders = ProviderHelper.GetKeyboardProviders(); GameStateWebServer = new GameStateWebServer(); + KeyboardHook = new KeyboardHook(); Events = events; Fps = 25; @@ -33,6 +36,8 @@ namespace Artemis.Models _processWorker.DoWork += ProcessWorker_DoWork; } + public KeyboardHook KeyboardHook { get; set; } + public EffectModel ActiveEffect { get; set; } public KeyboardProvider ActiveKeyboard { get; set; } public List EffectModels { get; set; } @@ -48,6 +53,9 @@ namespace Artemis.Models public void StartEffects() { LoadLastKeyboard(); + // If no keyboard was loaded, don't enable effects. + if (ActiveKeyboard == null) + return; // Start the webserver GameStateWebServer.Start(); @@ -80,12 +88,28 @@ namespace Artemis.Models ChangeKeyboard(keyboard ?? KeyboardProviders.First(k => k.Name == "Logitech G910 Orion Spark RGB")); } - private void ChangeKeyboard(KeyboardProvider keyboardProvider) + public void ChangeKeyboard(KeyboardProvider keyboardProvider) { if (ActiveKeyboard != null && keyboardProvider.Name == ActiveKeyboard.Name) return; ActiveKeyboard?.Disable(); + + // Disable everything if there's no active keyboard found + if (!keyboardProvider.CanEnable()) + { + ActiveKeyboard = null; + MessageBox.Show( + "Couldn't connect to the " + keyboardProvider.Name + ".\n " + + "Please check your cables and/or drivers (could be outdated).\n\n " + + "If needed, you can select a different keyboard in Artemis under settings", + "Artemis (╯°□°)╯︵ ┻━┻", + MessageBoxButtons.OK, + MessageBoxIcon.Warning); + ShutdownEffects(); + return; + } + ActiveKeyboard = keyboardProvider; ActiveKeyboard.Enable(); @@ -107,7 +131,7 @@ namespace Artemis.Models // Game models are only used if they are enabled var gameModel = effectModel as GameModel; if (gameModel != null) - if (!gameModel.Enabled()) + if (!gameModel.Enabled) return; if (ActiveEffect != null && effectModel.Name == ActiveEffect.Name) @@ -178,7 +202,7 @@ namespace Artemis.Models } // Sleep according to time left this frame - var sleep = (int) ((1000/Fps) - sw.ElapsedMilliseconds); + var sleep = (int) (1000/Fps - sw.ElapsedMilliseconds); if (sleep > 0) Thread.Sleep(sleep); sw.Reset(); @@ -197,9 +221,18 @@ namespace Artemis.Models var process = MemoryHelpers.GetProcessIfRunning(effectModel.ProcessName); if (process == null) continue; + if (process.HasExited) + continue; - ChangeEffect(effectModel); - foundProcess = true; + // If the active effect is a disabled game model, disable it + var model = ActiveEffect as GameModel; + if (model != null && !model.Enabled) + LoadLastEffect(); + else + { + ChangeEffect(effectModel); + foundProcess = true; + } } // If no game process is found, but the active effect still belongs to a game, diff --git a/Artemis/Artemis/Models/OverlayModel.cs b/Artemis/Artemis/Models/OverlayModel.cs index bd0646fa4..11988a1f1 100644 --- a/Artemis/Artemis/Models/OverlayModel.cs +++ b/Artemis/Artemis/Models/OverlayModel.cs @@ -11,6 +11,7 @@ namespace Artemis.Models { } + // Overlay Enabled() and Dispose() is called when changing the Enabled value public bool Enabled { get { return _enabled; } diff --git a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualization.settings b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualization.settings index 4c8f5d200..aef505bd4 100644 --- a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualization.settings +++ b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualization.settings @@ -1,5 +1,7 @@  - + + diff --git a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerModel.cs b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerModel.cs index 516f07555..8cd1329f4 100644 --- a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerModel.cs +++ b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerModel.cs @@ -70,7 +70,6 @@ namespace Artemis.Modules.Effects.AudioVisualizer ColorHelpers.ToDrawingColor(Settings.BottomColor) }, LinearGradientMode.Vertical) {ContainedBrush = false}); - } _sampleAggregator.FftCalculated += FftCalculated; @@ -83,6 +82,9 @@ namespace Artemis.Modules.Effects.AudioVisualizer public override void Update() { + // Start filling the model + _generating = true; + if (SelectedDeviceId == null) return; @@ -92,9 +94,8 @@ namespace Artemis.Modules.Effects.AudioVisualizer if (device == null || SpectrumData == null) return; - - // Start filling the model - _generating = true; + if (!SpectrumData.Any()) + return; // Parse spectrum data for (var i = 0; i < Lines; i++) @@ -107,7 +108,7 @@ namespace Artemis.Modules.Effects.AudioVisualizer // Apply Sensitivity setting height = height*Settings.Sensitivity; - var keyboardHeight = (int) Math.Round(((MainModel.ActiveKeyboard.Height/100.00)*height)*Scale); + var keyboardHeight = (int) Math.Round(MainModel.ActiveKeyboard.Height/100.00*height*Scale); if (keyboardHeight > SoundRectangles[i].Height) SoundRectangles[i].Height = keyboardHeight; else @@ -117,14 +118,14 @@ namespace Artemis.Modules.Effects.AudioVisualizer SoundRectangles[i].Width = Scale; if (Settings.FromBottom) - SoundRectangles[i].Y = (MainModel.ActiveKeyboard.Height*Scale) - SoundRectangles[i].Height; + SoundRectangles[i].Y = MainModel.ActiveKeyboard.Height*Scale - SoundRectangles[i].Height; } _generating = false; } public override Bitmap GenerateBitmap() { - if (SpectrumData == null) + if (SpectrumData == null || SoundRectangles == null) return null; // Lock the _spectrumData array while busy with it diff --git a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerSettings.cs b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerSettings.cs index b0935fc28..22f2b6cfc 100644 --- a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerSettings.cs +++ b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerSettings.cs @@ -18,7 +18,7 @@ namespace Artemis.Modules.Effects.AudioVisualizer public Color MiddleColor { get; set; } public Color BottomColor { get; set; } - public override sealed void Load() + public sealed override void Load() { Sensitivity = AudioVisualization.Default.Sensitivity; Bars = AudioVisualization.Default.Bars; @@ -29,7 +29,7 @@ namespace Artemis.Modules.Effects.AudioVisualizer BottomColor = AudioVisualization.Default.BottomColor; } - public override sealed void Save() + public sealed override void Save() { AudioVisualization.Default.Sensitivity = Sensitivity; AudioVisualization.Default.Bars = Bars; @@ -42,7 +42,7 @@ namespace Artemis.Modules.Effects.AudioVisualizer AudioVisualization.Default.Save(); } - public override sealed void ToDefault() + public sealed override void ToDefault() { Sensitivity = 4; Bars = 21; diff --git a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerView.xaml b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerView.xaml index 85737bc35..539452e50 100644 --- a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerView.xaml +++ b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerView.xaml @@ -90,7 +90,7 @@ HorizontalAlignment="Right" Width="110" TickPlacement="BottomRight" TickFrequency="1" Value="{Binding Path=AudioVisualizerSettings.Bars, Mode=TwoWay}" Minimum="2" Maximum="21" SmallChange="1" IsSnapToTickEnabled="True" /> - + diff --git a/Artemis/Artemis/Modules/Effects/Debug/DebugEffectModel.cs b/Artemis/Artemis/Modules/Effects/Debug/DebugEffectModel.cs index 2ed1a0325..3d65ec62a 100644 --- a/Artemis/Artemis/Modules/Effects/Debug/DebugEffectModel.cs +++ b/Artemis/Artemis/Modules/Effects/Debug/DebugEffectModel.cs @@ -28,15 +28,15 @@ namespace Artemis.Modules.Effects.Debug public override void Enable() { KeyboardRectangle = new KeyboardRectangle(MainModel.ActiveKeyboard, 0, 0, new List - { - Color.Red, - Color.OrangeRed, - Color.Yellow, - Color.Green, - Color.Blue, - Color.Purple, - Color.DeepPink - }, LinearGradientMode.Horizontal); + { + Color.Red, + Color.OrangeRed, + Color.Yellow, + Color.Green, + Color.Blue, + Color.Purple, + Color.DeepPink + }, LinearGradientMode.Horizontal); } public override void Update() diff --git a/Artemis/Artemis/Modules/Effects/Debug/DebugEffectSettings.cs b/Artemis/Artemis/Modules/Effects/Debug/DebugEffectSettings.cs index a891a5115..5075b73cf 100644 --- a/Artemis/Artemis/Modules/Effects/Debug/DebugEffectSettings.cs +++ b/Artemis/Artemis/Modules/Effects/Debug/DebugEffectSettings.cs @@ -16,16 +16,16 @@ namespace Artemis.Modules.Effects.Debug public int Scale { get; set; } public LinearGradientMode Type { get; set; } - public override sealed void Load() + public sealed override void Load() { ToDefault(); } - public override sealed void Save() + public sealed override void Save() { } - public override sealed void ToDefault() + public sealed override void ToDefault() { Width = 84; Height = 24; diff --git a/Artemis/Artemis/Modules/Effects/Debug/DebugEffectView.xaml b/Artemis/Artemis/Modules/Effects/Debug/DebugEffectView.xaml index f3e11d40d..4456af08a 100644 --- a/Artemis/Artemis/Modules/Effects/Debug/DebugEffectView.xaml +++ b/Artemis/Artemis/Modules/Effects/Debug/DebugEffectView.xaml @@ -76,7 +76,7 @@ HorizontalAlignment="Right" Width="110" TickPlacement="BottomRight" TickFrequency="1" Value="{Binding Path=DebugEffectSettings.Scale, Mode=TwoWay}" Minimum="1" Maximum="4" SmallChange="1" IsSnapToTickEnabled="True" /> - + @@ -100,7 +100,7 @@ - +