diff --git a/Artemis/Artemis/App.config b/Artemis/Artemis/App.config index ccd0770ac..4abfc6fbb 100644 --- a/Artemis/Artemis/App.config +++ b/Artemis/Artemis/App.config @@ -2,22 +2,56 @@ - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -25,6 +59,11 @@ + + + Demo (Duplicate to keep changes) + + True diff --git a/Artemis/Artemis/App.xaml.cs b/Artemis/Artemis/App.xaml.cs index 8b35c5e93..5ca4b1c47 100644 --- a/Artemis/Artemis/App.xaml.cs +++ b/Artemis/Artemis/App.xaml.cs @@ -2,7 +2,6 @@ using System.Security.Principal; using System.Windows; using System.Windows.Threading; -using Artemis.Utilities; using NLog; using WpfExceptionViewer; @@ -21,6 +20,8 @@ namespace Artemis InitializeComponent(); } + public bool DoHandle { get; set; } + private static bool IsRunAsAdministrator() { var wi = WindowsIdentity.GetCurrent(); @@ -29,8 +30,6 @@ namespace Artemis return wp.IsInRole(WindowsBuiltInRole.Administrator); } - public bool DoHandle { get; set; } - private void Application_Startup(object sender, StartupEventArgs e) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index 81ee80791..d8c88a20e 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -219,6 +219,8 @@ + + ..\packages\System.Linq.Dynamic.1.0.6\lib\net40\System.Linq.Dynamic.dll True @@ -339,6 +341,12 @@ + + True + True + WindowsProfile.settings + + WindowsProfileView.xaml @@ -583,6 +591,10 @@ SettingsSingleFileGenerator TypeWave.Designer.cs + + SettingsSingleFileGenerator + WindowsProfile.Designer.cs + SettingsSingleFileGenerator CounterStrike.Designer.cs @@ -644,6 +656,7 @@ + diff --git a/Artemis/Artemis/DAL/ProfileProvider.cs b/Artemis/Artemis/DAL/ProfileProvider.cs index 7060f8801..a6ccac598 100644 --- a/Artemis/Artemis/DAL/ProfileProvider.cs +++ b/Artemis/Artemis/DAL/ProfileProvider.cs @@ -1,22 +1,26 @@ using System; using System.Collections.Generic; using System.IO; +using System.IO.Compression; using System.Linq; using System.Reflection; using System.Xml.Serialization; using Artemis.DeviceProviders; using Artemis.Models; using Artemis.Models.Profiles; +using Artemis.Utilities; using NLog; namespace Artemis.DAL { public static class ProfileProvider { - private static readonly Logger _logger = LogManager.GetCurrentClassLogger(); + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - private static readonly string ProfileFolder = - Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Artemis\profiles"; + private static readonly string ProfileFolder = Environment + .GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Artemis\profiles"; + + private static bool _installedDefaults; /// /// Get all profiles @@ -93,7 +97,7 @@ namespace Artemis.DAL } catch (InvalidOperationException e) { - _logger.Error("Failed to load profile: {0} - {1}", path, e.InnerException.Message); + Logger.Error("Failed to load profile: {0} - {1}", path, e.InnerException.Message); } } @@ -105,13 +109,20 @@ namespace Artemis.DAL /// private static void InstallDefaults() { - var test = Assembly.GetExecutingAssembly().GetManifestResourceNames(); - //var stream = - // Assembly.GetExecutingAssembly() - // .GetManifestResourceStream("Artemis.Properties.Resources.logo.jpg"); + // Only install the defaults once per session + if (_installedDefaults) + return; + _installedDefaults = true; - //Resources. - //ZipPackage.Open(Re.defaultProfiles) + // Load the ZIP from resources + var stream = Assembly.GetExecutingAssembly() + .GetManifestResourceStream("Artemis.Resources.Keyboards.default-profiles.zip"); + + // Extract it over the old defaults in case one was updated + if (stream == null) + return; + var archive = new ZipArchive(stream); + archive.ExtractToDirectory(ProfileFolder, true); } /// diff --git a/Artemis/Artemis/DeviceProviders/Corsair/CorsairHeadsets.cs b/Artemis/Artemis/DeviceProviders/Corsair/CorsairHeadsets.cs index 40edac5fc..8090d1dcb 100644 --- a/Artemis/Artemis/DeviceProviders/Corsair/CorsairHeadsets.cs +++ b/Artemis/Artemis/DeviceProviders/Corsair/CorsairHeadsets.cs @@ -41,12 +41,12 @@ namespace Artemis.DeviceProviders.Corsair return; var leds = CueSDK.HeadsetSDK.Leds.Count(); - var rect = new Rect(new Size(leds * 20, leds * 20)); + var rect = new Rect(new Size(leds*20, leds*20)); var visual = new DrawingVisual(); using (var c = visual.RenderOpen()) c.DrawRectangle(brush, null, rect); - var img = ImageUtilities.DrawinVisualToBitmap(visual, rect); + var img = ImageUtilities.DrawinVisualToBitmap(visual, rect); var ledIndex = 0; // Color each LED according to one of the pixels @@ -54,7 +54,7 @@ namespace Artemis.DeviceProviders.Corsair { corsairLed.Color = ledIndex == 0 ? img.GetPixel(0, 0) - : img.GetPixel((ledIndex + 1) * 20 - 1, (ledIndex + 1) * 20 - 1); + : img.GetPixel((ledIndex + 1)*20 - 1, (ledIndex + 1)*20 - 1); ledIndex++; } diff --git a/Artemis/Artemis/DeviceProviders/Corsair/CorsairMice.cs b/Artemis/Artemis/DeviceProviders/Corsair/CorsairMice.cs index 4c72a7204..9d4763851 100644 --- a/Artemis/Artemis/DeviceProviders/Corsair/CorsairMice.cs +++ b/Artemis/Artemis/DeviceProviders/Corsair/CorsairMice.cs @@ -41,12 +41,12 @@ namespace Artemis.DeviceProviders.Corsair return; var leds = CueSDK.MouseSDK.Leds.Count(); - var rect = new Rect(new Size(leds * 20, leds * 20)); + var rect = new Rect(new Size(leds*20, leds*20)); var visual = new DrawingVisual(); using (var c = visual.RenderOpen()) c.DrawRectangle(brush, null, rect); - var img = ImageUtilities.DrawinVisualToBitmap(visual, rect); + var img = ImageUtilities.DrawinVisualToBitmap(visual, rect); var ledIndex = 0; // Color each LED according to one of the pixels @@ -54,7 +54,7 @@ namespace Artemis.DeviceProviders.Corsair { corsairLed.Color = ledIndex == 0 ? img.GetPixel(0, 0) - : img.GetPixel((ledIndex + 1) * 20 - 1, (ledIndex + 1) * 20 - 1); + : img.GetPixel((ledIndex + 1)*20 - 1, (ledIndex + 1)*20 - 1); ledIndex++; } diff --git a/Artemis/Artemis/DeviceProviders/Corsair/CorsairRGB.cs b/Artemis/Artemis/DeviceProviders/Corsair/CorsairRGB.cs index 5e1bd8688..4a8823b27 100644 --- a/Artemis/Artemis/DeviceProviders/Corsair/CorsairRGB.cs +++ b/Artemis/Artemis/DeviceProviders/Corsair/CorsairRGB.cs @@ -72,7 +72,7 @@ namespace Artemis.DeviceProviders.Corsair PreviewSettings = new PreviewSettings(665, 215, new Thickness(0, -5, 0, 0), Resources.strafe); break; } - Slug = "corsair-"+_keyboard.DeviceInfo.Model.Replace(' ', '-').ToLower(); + Slug = "corsair-" + _keyboard.DeviceInfo.Model.Replace(' ', '-').ToLower(); _keyboard.Brush = _keyboardBrush ?? (_keyboardBrush = new ImageBrush()); } diff --git a/Artemis/Artemis/DeviceProviders/Logitech/Orion.cs b/Artemis/Artemis/DeviceProviders/Logitech/Orion.cs index 62321bec3..e4714af6b 100644 --- a/Artemis/Artemis/DeviceProviders/Logitech/Orion.cs +++ b/Artemis/Artemis/DeviceProviders/Logitech/Orion.cs @@ -1,11 +1,11 @@ using System.Drawing; using System.Threading; using System.Windows; -using Microsoft.Win32; using Artemis.DeviceProviders.Logitech.Utilities; using Artemis.Properties; using Artemis.Utilities; using Artemis.Utilities.LogitechDll; +using Microsoft.Win32; namespace Artemis.DeviceProviders.Logitech { @@ -28,12 +28,14 @@ namespace Artemis.DeviceProviders.Logitech { //Check to see if VC++ 2012 x64 is installed. - if (Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Classes\Installer\Dependencies\{ca67548a-5ebe-413a-b50c-4b9ceb6d66c6}") == null) + if ( + Registry.LocalMachine.OpenSubKey( + @"SOFTWARE\Classes\Installer\Dependencies\{ca67548a-5ebe-413a-b50c-4b9ceb6d66c6}") == null) { CantEnableText = "Couldn't connect to your Logitech G910.\n" + - "The Visual C 2012 Redistributable could not be found, which is required.\n" + - "Please download it by going to the following URL:\n\n" + - "https://www.microsoft.com/download/confirmation.aspx?id=30679"; + "The Visual C 2012 Redistributable could not be found, which is required.\n" + + "Please download it by going to the following URL:\n\n" + + "https://www.microsoft.com/download/confirmation.aspx?id=30679"; return false; } diff --git a/Artemis/Artemis/InjectionFactories/ILayerEditorVmFactory.cs b/Artemis/Artemis/InjectionFactories/ILayerEditorVmFactory.cs index 7171fbea1..a33a3416b 100644 --- a/Artemis/Artemis/InjectionFactories/ILayerEditorVmFactory.cs +++ b/Artemis/Artemis/InjectionFactories/ILayerEditorVmFactory.cs @@ -1,6 +1,5 @@ using Artemis.Models.Interfaces; using Artemis.Models.Profiles; -using Artemis.Services; using Artemis.ViewModels.Profiles; namespace Artemis.InjectionFactories diff --git a/Artemis/Artemis/Managers/EffectManager.cs b/Artemis/Artemis/Managers/EffectManager.cs index 3ada533c2..a7143e039 100644 --- a/Artemis/Artemis/Managers/EffectManager.cs +++ b/Artemis/Artemis/Managers/EffectManager.cs @@ -15,8 +15,8 @@ namespace Artemis.Managers /// public class EffectManager { - private readonly IEventAggregator _events; private readonly DeviceManager _deviceManager; + private readonly IEventAggregator _events; private readonly ILogger _logger; private EffectModel _activeEffect; @@ -107,7 +107,7 @@ namespace Artemis.Managers _logger.Debug("Cancelling effect change, provided game not enabled"); return; } - + var wasNull = false; if (ActiveEffect == null) diff --git a/Artemis/Artemis/Managers/LoopManager.cs b/Artemis/Artemis/Managers/LoopManager.cs index 9c05d4cc3..1975b2f6a 100644 --- a/Artemis/Artemis/Managers/LoopManager.cs +++ b/Artemis/Artemis/Managers/LoopManager.cs @@ -1,5 +1,4 @@ using System; -using System.Diagnostics; using System.Drawing; using System.Linq; using System.Timers; @@ -19,7 +18,6 @@ namespace Artemis.Managers private readonly IEventAggregator _events; private readonly ILogger _logger; private readonly Timer _loopTimer; - private int _fpsCount; public LoopManager(ILogger logger, IEventAggregator events, EffectManager effectManager, DeviceManager deviceManager) @@ -33,14 +31,6 @@ namespace Artemis.Managers _loopTimer = new Timer(40); _loopTimer.Elapsed += Render; _loopTimer.Start(); - - var fpsTimer = new Timer(1000); - fpsTimer.Elapsed += delegate - { - Debug.WriteLine(_fpsCount); - _fpsCount = 0; - }; - fpsTimer.Start(); } /// @@ -155,10 +145,7 @@ namespace Artemis.Managers // If no bitmap was generated this frame is done if (bitmap == null) - { - _fpsCount++; return; - } // Fill the bitmap's background with black to avoid trailing colors on some keyboards var fixedBmp = new Bitmap(bitmap.Width, bitmap.Height); @@ -172,8 +159,6 @@ namespace Artemis.Managers // Update the keyboard _deviceManager.ActiveKeyboard?.DrawBitmap(bitmap); - - _fpsCount++; } } } diff --git a/Artemis/Artemis/Managers/MainManager.cs b/Artemis/Artemis/Managers/MainManager.cs index 946116d01..c2c8ca63d 100644 --- a/Artemis/Artemis/Managers/MainManager.cs +++ b/Artemis/Artemis/Managers/MainManager.cs @@ -38,7 +38,7 @@ namespace Artemis.Managers _logger.Info("Intializing MainManager"); _events = events; - + _processTimer = new Timer(1000); _processTimer.Elapsed += ScanProcesses; _processTimer.Start(); diff --git a/Artemis/Artemis/Models/EffectModel.cs b/Artemis/Artemis/Models/EffectModel.cs index 048dc4c37..d0ce7b961 100644 --- a/Artemis/Artemis/Models/EffectModel.cs +++ b/Artemis/Artemis/Models/EffectModel.cs @@ -43,7 +43,7 @@ namespace Artemis.Models mouse = null; headset = null; - if (Profile == null || DataModel == null) + if (Profile == null || DataModel == null || MainManager.DeviceManager.ActiveKeyboard == null) return; // Get all enabled layers who's conditions are met diff --git a/Artemis/Artemis/Models/GameModel.cs b/Artemis/Artemis/Models/GameModel.cs index c11e8747c..a37558bfe 100644 --- a/Artemis/Artemis/Models/GameModel.cs +++ b/Artemis/Artemis/Models/GameModel.cs @@ -1,13 +1,12 @@ -using System.Collections.Generic; -using Artemis.Managers; +using Artemis.Managers; using Artemis.Models.Interfaces; -using Artemis.Models.Profiles; namespace Artemis.Models { public abstract class GameModel : EffectModel { - protected GameModel(MainManager mainManager, GameSettings settings, IDataModel dataModel) : base(mainManager, dataModel) + protected GameModel(MainManager mainManager, GameSettings settings, IDataModel dataModel) + : base(mainManager, dataModel) { Settings = settings; } diff --git a/Artemis/Artemis/Models/Profiles/LayerModel.cs b/Artemis/Artemis/Models/Profiles/LayerModel.cs index f97563dd3..2b8d647ae 100644 --- a/Artemis/Artemis/Models/Profiles/LayerModel.cs +++ b/Artemis/Artemis/Models/Profiles/LayerModel.cs @@ -55,7 +55,7 @@ namespace Artemis.Models.Profiles // Update animations AnimationUpdater.UpdateAnimation((KeyboardPropertiesModel) Properties, updateAnimations); - + if (LayerType == LayerType.Keyboard) Drawer.Draw(c, (KeyboardPropertiesModel) Properties, appliedProperties); else if (LayerType == LayerType.KeyboardGif) @@ -214,22 +214,6 @@ namespace Artemis.Models.Profiles } } - #region IChildItem Members - - LayerModel IChildItem.Parent - { - get { return Parent; } - set { Parent = value; } - } - - ProfileModel IChildItem.Parent - { - get { return Profile; } - set { Profile = value; } - } - - #endregion - /// /// Generates a flat list containing all layers that must be rendered on the keyboard, /// the first mouse layer to be rendered and the first headset layer to be rendered @@ -240,7 +224,8 @@ namespace Artemis.Models.Profiles /// Whether or not to include headsets in the list /// /// A flat list containing all layers that must be rendered - public List GetRenderLayers(IDataModel dataModel, bool includeMice, bool includeHeadsets, bool ignoreConditions = false) + public List GetRenderLayers(IDataModel dataModel, bool includeMice, bool includeHeadsets, + bool ignoreConditions = false) { var layers = new List(); foreach (var layerModel in Children.OrderByDescending(c => c.Order)) @@ -262,6 +247,22 @@ namespace Artemis.Models.Profiles return layers; } + + #region IChildItem Members + + LayerModel IChildItem.Parent + { + get { return Parent; } + set { Parent = value; } + } + + ProfileModel IChildItem.Parent + { + get { return Profile; } + set { Profile = value; } + } + + #endregion } public enum LayerType diff --git a/Artemis/Artemis/Models/Profiles/ProfileModel.cs b/Artemis/Artemis/Models/Profiles/ProfileModel.cs index beb86b4ec..ac12063fc 100644 --- a/Artemis/Artemis/Models/Profiles/ProfileModel.cs +++ b/Artemis/Artemis/Models/Profiles/ProfileModel.cs @@ -126,7 +126,8 @@ namespace Artemis.Models.Profiles /// Whether or not to include headsets in the list /// /// A flat list containing all layers that must be rendered - public List GetRenderLayers(IDataModel dataModel, bool includeMice, bool includeHeadsets, bool ignoreConditions = false) + public List GetRenderLayers(IDataModel dataModel, bool includeMice, bool includeHeadsets, + bool ignoreConditions = false) { var layers = new List(); foreach (var layerModel in Layers.OrderByDescending(l => l.Order)) diff --git a/Artemis/Artemis/Models/Profiles/Properties/DynamicPropertiesModel.cs b/Artemis/Artemis/Models/Profiles/Properties/DynamicPropertiesModel.cs index 7c5930fe5..8c3956744 100644 --- a/Artemis/Artemis/Models/Profiles/Properties/DynamicPropertiesModel.cs +++ b/Artemis/Artemis/Models/Profiles/Properties/DynamicPropertiesModel.cs @@ -63,7 +63,7 @@ namespace Artemis.Models.Profiles.Properties private void ApplyWidth(ref AppliedProperties properties, double percentage) { - var newWidth = percentage * properties.Width; + var newWidth = percentage*properties.Width; var difference = properties.Width - newWidth; properties.Width = newWidth; diff --git a/Artemis/Artemis/Models/Profiles/Properties/FolderPropertiesModel.cs b/Artemis/Artemis/Models/Profiles/Properties/FolderPropertiesModel.cs index 27d35e496..dc36491c4 100644 --- a/Artemis/Artemis/Models/Profiles/Properties/FolderPropertiesModel.cs +++ b/Artemis/Artemis/Models/Profiles/Properties/FolderPropertiesModel.cs @@ -1,5 +1,4 @@ using Artemis.Models.Interfaces; -using Artemis.Utilities; namespace Artemis.Models.Profiles.Properties { diff --git a/Artemis/Artemis/Models/Profiles/Properties/KeyboardPropertiesModel.cs b/Artemis/Artemis/Models/Profiles/Properties/KeyboardPropertiesModel.cs index aa66dfbee..197fdccae 100644 --- a/Artemis/Artemis/Models/Profiles/Properties/KeyboardPropertiesModel.cs +++ b/Artemis/Artemis/Models/Profiles/Properties/KeyboardPropertiesModel.cs @@ -2,10 +2,8 @@ using System.Collections.Generic; using System.ComponentModel; using System.Windows; -using System.Windows.Media; using System.Xml.Serialization; using Artemis.Models.Interfaces; -using Artemis.Utilities; namespace Artemis.Models.Profiles.Properties { diff --git a/Artemis/Artemis/Models/Profiles/Properties/LayerPropertiesModel.cs b/Artemis/Artemis/Models/Profiles/Properties/LayerPropertiesModel.cs index db003d39e..0cd18e38c 100644 --- a/Artemis/Artemis/Models/Profiles/Properties/LayerPropertiesModel.cs +++ b/Artemis/Artemis/Models/Profiles/Properties/LayerPropertiesModel.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Windows.Media; using System.Xml.Serialization; using Artemis.Models.Interfaces; -using Artemis.Utilities; namespace Artemis.Models.Profiles.Properties { diff --git a/Artemis/Artemis/Models/Profiles/Properties/MousePropertiesModel.cs b/Artemis/Artemis/Models/Profiles/Properties/MousePropertiesModel.cs index 92d2eb456..2bebe3c5b 100644 --- a/Artemis/Artemis/Models/Profiles/Properties/MousePropertiesModel.cs +++ b/Artemis/Artemis/Models/Profiles/Properties/MousePropertiesModel.cs @@ -6,7 +6,7 @@ namespace Artemis.Models.Profiles.Properties { public override AppliedProperties GetAppliedProperties(IDataModel dataModel, bool ignoreDynamic = false) { - return new AppliedProperties { Brush = Brush }; + return new AppliedProperties {Brush = Brush}; } } } \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerModel.cs b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerModel.cs index 806f5864a..07accfb46 100644 --- a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerModel.cs +++ b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerModel.cs @@ -140,7 +140,7 @@ namespace Artemis.Modules.Effects.AudioVisualizer } _generating = false; } - + private void OnDataAvailable(object sender, WaveInEventArgs e) { var buffer = e.Buffer; @@ -190,7 +190,8 @@ namespace Artemis.Modules.Effects.AudioVisualizer return null; } - public override void Render(out Bitmap keyboard, out Brush mouse, out Brush headset, bool renderMice, bool renderHeadsets) + public override void Render(out Bitmap keyboard, out Brush mouse, out Brush headset, bool renderMice, + bool renderHeadsets) { keyboard = null; mouse = null; diff --git a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerViewModel.cs b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerViewModel.cs index 11a70a0f0..6183d80a9 100644 --- a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerViewModel.cs +++ b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerViewModel.cs @@ -14,7 +14,7 @@ namespace Artemis.Modules.Effects.AudioVisualizer events.Subscribe(this); MainManager.EffectManager.EffectModels.Add(EffectModel); - EffectSettings = ((AudioVisualizerModel)EffectModel).Settings; + EffectSettings = ((AudioVisualizerModel) EffectModel).Settings; } public void Handle(ActiveEffectChanged message) diff --git a/Artemis/Artemis/Modules/Effects/ProfilePreview/ProfilePreviewModel.cs b/Artemis/Artemis/Modules/Effects/ProfilePreview/ProfilePreviewModel.cs index 7544c8d3c..7030f0c67 100644 --- a/Artemis/Artemis/Modules/Effects/ProfilePreview/ProfilePreviewModel.cs +++ b/Artemis/Artemis/Modules/Effects/ProfilePreview/ProfilePreviewModel.cs @@ -35,7 +35,8 @@ namespace Artemis.Modules.Effects.ProfilePreview return Profile.GetRenderLayers(DataModel, renderMice, renderHeadsets, true); } - public override void Render(out Bitmap keyboard, out Brush mouse, out Brush headset, bool renderMice, bool renderHeadsets) + public override void Render(out Bitmap keyboard, out Brush mouse, out Brush headset, bool renderMice, + bool renderHeadsets) { keyboard = null; mouse = null; @@ -48,11 +49,13 @@ namespace Artemis.Modules.Effects.ProfilePreview var renderLayers = GetRenderLayers(renderMice, renderHeadsets); // Render the keyboard layer-by-layer - keyboard = Profile?.GenerateBitmap(renderLayers, DataModel, MainManager.DeviceManager.ActiveKeyboard.KeyboardRectangle(4), true, true); + keyboard = Profile?.GenerateBitmap(renderLayers, DataModel, + MainManager.DeviceManager.ActiveKeyboard.KeyboardRectangle(4), true, true); // Render the first enabled mouse (will default to null if renderMice was false) mouse = Profile?.GenerateBrush(renderLayers.LastOrDefault(l => l.LayerType == LayerType.Mouse), DataModel); // Render the first enabled headset (will default to null if renderHeadsets was false) - headset = Profile?.GenerateBrush(renderLayers.LastOrDefault(l => l.LayerType == LayerType.Headset), DataModel); + headset = Profile?.GenerateBrush(renderLayers.LastOrDefault(l => l.LayerType == LayerType.Headset), + DataModel); } } diff --git a/Artemis/Artemis/Modules/Effects/TypeWave/TypeWaveModel.cs b/Artemis/Artemis/Modules/Effects/TypeWave/TypeWaveModel.cs index 7f92a2dba..c337ac1e2 100644 --- a/Artemis/Artemis/Modules/Effects/TypeWave/TypeWaveModel.cs +++ b/Artemis/Artemis/Modules/Effects/TypeWave/TypeWaveModel.cs @@ -98,7 +98,8 @@ namespace Artemis.Modules.Effects.TypeWave return null; } - public override void Render(out Bitmap keyboard, out Brush mouse, out Brush headset, bool renderMice, bool renderHeadsets) + public override void Render(out Bitmap keyboard, out Brush mouse, out Brush headset, bool renderMice, + bool renderHeadsets) { keyboard = null; mouse = null; @@ -120,7 +121,7 @@ namespace Artemis.Modules.Effects.TypeWave if (_waves[i].Size == 0) continue; var path = new GraphicsPath(); - path.AddEllipse(_waves[i].Point.X - _waves[i].Size / 2, _waves[i].Point.Y - _waves[i].Size / 2, + path.AddEllipse(_waves[i].Point.X - _waves[i].Size/2, _waves[i].Point.Y - _waves[i].Size/2, _waves[i].Size, _waves[i].Size); Color fillColor; @@ -131,7 +132,7 @@ namespace Artemis.Modules.Effects.TypeWave var pthGrBrush = new PathGradientBrush(path) { - SurroundColors = new[] { _waves[i].Color }, + SurroundColors = new[] {_waves[i].Color}, CenterColor = fillColor }; @@ -139,8 +140,8 @@ namespace Artemis.Modules.Effects.TypeWave pthGrBrush.FocusScales = new PointF(0.3f, 0.8f); g.FillPath(pthGrBrush, path); - g.DrawEllipse(new Pen(pthGrBrush, 1), _waves[i].Point.X - _waves[i].Size / 2, - _waves[i].Point.Y - _waves[i].Size / 2, _waves[i].Size, _waves[i].Size); + g.DrawEllipse(new Pen(pthGrBrush, 1), _waves[i].Point.X - _waves[i].Size/2, + _waves[i].Point.Y - _waves[i].Size/2, _waves[i].Size, _waves[i].Size); } } } diff --git a/Artemis/Artemis/Modules/Effects/TypeWave/TypeWaveViewModel.cs b/Artemis/Artemis/Modules/Effects/TypeWave/TypeWaveViewModel.cs index f422e22b6..8630af3a1 100644 --- a/Artemis/Artemis/Modules/Effects/TypeWave/TypeWaveViewModel.cs +++ b/Artemis/Artemis/Modules/Effects/TypeWave/TypeWaveViewModel.cs @@ -14,7 +14,7 @@ namespace Artemis.Modules.Effects.TypeWave events.Subscribe(this); MainManager.EffectManager.EffectModels.Add(EffectModel); - EffectSettings = ((TypeWaveModel)EffectModel).Settings; + EffectSettings = ((TypeWaveModel) EffectModel).Settings; } public void Handle(ActiveEffectChanged message) diff --git a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfile.Designer.cs b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfile.Designer.cs new file mode 100644 index 000000000..5e8a56c4d --- /dev/null +++ b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfile.Designer.cs @@ -0,0 +1,38 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace Artemis.Modules.Effects.WindowsProfile { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] + internal sealed partial class WindowsProfile : global::System.Configuration.ApplicationSettingsBase { + + private static WindowsProfile defaultInstance = ((WindowsProfile)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new WindowsProfile()))); + + public static WindowsProfile Default { + get { + return defaultInstance; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("Demo (Duplicate to keep changes)")] + public string LastProfile { + get { + return ((string)(this["LastProfile"])); + } + set { + this["LastProfile"] = value; + } + } + } +} diff --git a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfile.settings b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfile.settings new file mode 100644 index 000000000..4a88bb226 --- /dev/null +++ b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfile.settings @@ -0,0 +1,11 @@ + + + + + + + Demo (Duplicate to keep changes) + + + \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileDataModel.cs b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileDataModel.cs index 74c31722f..de9bc9206 100644 --- a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileDataModel.cs +++ b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileDataModel.cs @@ -1,18 +1,17 @@ using Artemis.Models.Interfaces; -using SpotifyAPI.Local.Models; namespace Artemis.Modules.Effects.WindowsProfile { public class WindowsProfileDataModel : IDataModel { - public CpuDataModel Cpu { get; set; } - public Spotify Spotify { get; set; } - public WindowsProfileDataModel() { Spotify = new Spotify(); Cpu = new CpuDataModel(); } + + public CpuDataModel Cpu { get; set; } + public Spotify Spotify { get; set; } } public class CpuDataModel @@ -26,6 +25,7 @@ namespace Artemis.Modules.Effects.WindowsProfile public int Core7Usage { get; set; } public int Core8Usage { get; set; } } + public class Spotify { public bool Running { get; set; } @@ -37,5 +37,6 @@ namespace Artemis.Modules.Effects.WindowsProfile public bool Repeat { get; set; } public bool Shuffle { get; set; } public bool Playing { get; set; } + public int SongLength { get; set; } } } \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileModel.cs b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileModel.cs index 805444d2f..a1537c89b 100644 --- a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileModel.cs +++ b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileModel.cs @@ -1,11 +1,12 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Threading; +using System.Threading.Tasks; using Artemis.Managers; using Artemis.Models; using Artemis.Models.Profiles; using SpotifyAPI.Local; -using SpotifyAPI.Local.Models; namespace Artemis.Modules.Effects.WindowsProfile { @@ -13,14 +14,14 @@ namespace Artemis.Modules.Effects.WindowsProfile { private List _cores; private int _cpuFrames; - private readonly SpotifyLocalAPI _spotify; + private SpotifyLocalAPI _spotify; + private bool _spotifySetupBusy; public WindowsProfileModel(MainManager mainManager, WindowsProfileSettings settings) : base(mainManager, new WindowsProfileDataModel()) { Name = "WindowsProfile"; Settings = settings; - _spotify = new SpotifyLocalAPI(); } public WindowsProfileSettings Settings { get; set; } @@ -32,19 +33,8 @@ namespace Artemis.Modules.Effects.WindowsProfile public override void Enable() { - // Setup CPU cores - _cores = GetPerformanceCounters(); - var coreCount = _cores.Count; - while (coreCount < 8) - { - _cores.Add(null); - coreCount++; - } - - if (SpotifyLocalAPI.IsSpotifyRunning()) - { - _spotify.Connect(); - } + SetupCpu(); + SetupSpotify(); Initialized = true; } @@ -56,6 +46,19 @@ namespace Artemis.Modules.Effects.WindowsProfile UpdateSpotify(dataModel); } + #region CPU + + private void SetupCpu() + { + _cores = GetPerformanceCounters(); + var coreCount = _cores.Count; + while (coreCount < 8) + { + _cores.Add(null); + coreCount++; + } + } + private void UpdateCpu(WindowsProfileDataModel dataModel) { // CPU is only updated every 15 frames, the performance counter gives 0 if updated too often @@ -67,26 +70,26 @@ namespace Artemis.Modules.Effects.WindowsProfile // Update cores, not ideal but data models don't support lists. if (_cores[0] != null) - dataModel.Cpu.Core1Usage = (int)_cores[0].NextValue(); + dataModel.Cpu.Core1Usage = (int) _cores[0].NextValue(); if (_cores[1] != null) - dataModel.Cpu.Core2Usage = (int)_cores[1].NextValue(); + dataModel.Cpu.Core2Usage = (int) _cores[1].NextValue(); if (_cores[2] != null) - dataModel.Cpu.Core3Usage = (int)_cores[2].NextValue(); + dataModel.Cpu.Core3Usage = (int) _cores[2].NextValue(); if (_cores[3] != null) - dataModel.Cpu.Core4Usage = (int)_cores[3].NextValue(); + dataModel.Cpu.Core4Usage = (int) _cores[3].NextValue(); if (_cores[4] != null) - dataModel.Cpu.Core5Usage = (int)_cores[4].NextValue(); + dataModel.Cpu.Core5Usage = (int) _cores[4].NextValue(); if (_cores[5] != null) - dataModel.Cpu.Core6Usage = (int)_cores[5].NextValue(); + dataModel.Cpu.Core6Usage = (int) _cores[5].NextValue(); if (_cores[6] != null) - dataModel.Cpu.Core7Usage = (int)_cores[6].NextValue(); + dataModel.Cpu.Core7Usage = (int) _cores[6].NextValue(); if (_cores[7] != null) - dataModel.Cpu.Core8Usage = (int)_cores[7].NextValue(); + dataModel.Cpu.Core8Usage = (int) _cores[7].NextValue(); } public override List GetRenderLayers(bool renderMice, bool renderHeadsets) { - return Profile.GetRenderLayers(DataModel, renderMice, renderHeadsets, true); + return Profile.GetRenderLayers(DataModel, renderMice, renderHeadsets, false); } public static List GetPerformanceCounters() @@ -101,29 +104,66 @@ namespace Artemis.Modules.Effects.WindowsProfile return performanceCounters; } + #endregion + + #region Spotify + + public void SetupSpotify() + { + if (_spotifySetupBusy) + return; + + _spotifySetupBusy = true; + _spotify = new SpotifyLocalAPI {ListenForEvents = true}; + _spotify.OnPlayStateChange += UpdateSpotifyPlayState; + _spotify.OnTrackChange += UpdateSpotifyTrack; + _spotify.OnTrackTimeChange += UpdateSpotifyTrackTime; + + // Connecting can sometimes use a little bit more conviction + Task.Factory.StartNew(() => + { + var tryCount = 0; + while (tryCount <= 10) + { + tryCount++; + var connected = _spotify.Connect(); + if (connected) + break; + Thread.Sleep(1000); + } + _spotifySetupBusy = false; + }); + } + public void UpdateSpotify(WindowsProfileDataModel dataModel) { - StatusResponse status = _spotify.GetStatus(); - if (status == null) - { - dataModel.Spotify.Running = false; - return; - } + if (!dataModel.Spotify.Running && SpotifyLocalAPI.IsSpotifyRunning()) + SetupSpotify(); - dataModel.Spotify.Running = true; - dataModel.Spotify.SpotifyVolume = (int)(status.Volume * 100); - dataModel.Spotify.Repeat = status.Repeat; - dataModel.Spotify.Shuffle = status.Shuffle; - dataModel.Spotify.Playing = status.Playing; - - // Only update track info if not null - if (status.Track == null) - return; - - dataModel.Spotify.Artist = status.Track.ArtistResource?.Name; - dataModel.Spotify.SongName = status.Track.TrackResource?.Name; - dataModel.Spotify.SongPercentCompleted = (int)(status.PlayingPosition / status.Track.Length * 100.0); - dataModel.Spotify.Album = status.Track.AlbumResource?.Name; + dataModel.Spotify.Running = SpotifyLocalAPI.IsSpotifyRunning(); } + + private void UpdateSpotifyPlayState(object sender, PlayStateEventArgs e) + { + ((WindowsProfileDataModel) DataModel).Spotify.Playing = e.Playing; + } + + private void UpdateSpotifyTrack(object sender, TrackChangeEventArgs e) + { + var dataModel = (WindowsProfileDataModel) DataModel; + dataModel.Spotify.Artist = e.NewTrack.ArtistResource?.Name; + dataModel.Spotify.SongName = e.NewTrack.TrackResource?.Name; + dataModel.Spotify.Album = e.NewTrack.AlbumResource?.Name; + dataModel.Spotify.SongLength = e.NewTrack.Length; + } + + private void UpdateSpotifyTrackTime(object sender, TrackTimeChangeEventArgs e) + { + var dataModel = (WindowsProfileDataModel) DataModel; + if (dataModel.Spotify.SongLength > 0) + dataModel.Spotify.SongPercentCompleted = (int) (e.TrackTime/dataModel.Spotify.SongLength*100.0); + } + + #endregion } } \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileSettings.cs b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileSettings.cs new file mode 100644 index 000000000..a41551fe2 --- /dev/null +++ b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileSettings.cs @@ -0,0 +1,28 @@ +using Artemis.Models; + +namespace Artemis.Modules.Effects.WindowsProfile +{ + public class WindowsProfileSettings : GameSettings + { + public WindowsProfileSettings() + { + Load(); + } + + public sealed override void Load() + { + LastProfile = WindowsProfile.Default.LastProfile; + } + + public sealed override void Save() + { + WindowsProfile.Default.LastProfile = LastProfile; + + WindowsProfile.Default.Save(); + } + + public sealed override void ToDefault() + { + } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileViewModel.cs b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileViewModel.cs index f2bb3cd89..5a66fac7c 100644 --- a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileViewModel.cs +++ b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileViewModel.cs @@ -2,7 +2,6 @@ using Artemis.Events; using Artemis.InjectionFactories; using Artemis.Managers; -using Artemis.Models; using Artemis.Modules.Effects.ProfilePreview; using Artemis.ViewModels.Abstract; using Artemis.ViewModels.Profiles; @@ -20,9 +19,9 @@ namespace Artemis.Modules.Effects.WindowsProfile DisplayName = "Windows Profile"; PFactory = pFactory; ProfilePreviewModel = profilePreviewModel; - EffectSettings = ((WindowsProfileModel)EffectModel).Settings; - ProfileEditor = PFactory.CreateProfileEditorVm(events, main, (WindowsProfileModel)EffectModel, - ((WindowsProfileSettings)EffectSettings).LastProfile); + EffectSettings = ((WindowsProfileModel) EffectModel).Settings; + ProfileEditor = PFactory.CreateProfileEditorVm(events, main, (WindowsProfileModel) EffectModel, + ((WindowsProfileSettings) EffectSettings).LastProfile); ProfilePreviewModel.Profile = ProfileEditor.SelectedProfile; events.Subscribe(this); @@ -35,6 +34,11 @@ namespace Artemis.Modules.Effects.WindowsProfile public IProfileEditorVmFactory PFactory { get; set; } public ProfilePreviewModel ProfilePreviewModel { get; set; } + public void Handle(ActiveEffectChanged message) + { + NotifyOfPropertyChange(() => EffectEnabled); + } + private void ProfileUpdater(object sender, PropertyChangedEventArgs e) { if (e.PropertyName != "SelectedProfile" && IsActive) @@ -45,7 +49,7 @@ namespace Artemis.Modules.Effects.WindowsProfile if (e.PropertyName != "SelectedProfile" || !ProfileEditor.ProfileViewModel.Activated || ProfileEditor.ProfileViewModel.SelectedProfile == null) return; - ((WindowsProfileSettings)EffectSettings).LastProfile = ProfileEditor.ProfileViewModel.SelectedProfile.Name; + ((WindowsProfileSettings) EffectSettings).LastProfile = ProfileEditor.ProfileViewModel.SelectedProfile.Name; EffectSettings.Save(); } @@ -60,25 +64,5 @@ namespace Artemis.Modules.Effects.WindowsProfile base.OnDeactivate(close); ProfileEditor.ProfileViewModel.Deactivate(); } - - public void Handle(ActiveEffectChanged message) - { - NotifyOfPropertyChange(() => EffectEnabled); - } - } - - public class WindowsProfileSettings : GameSettings - { - public override void Load() - { - } - - public override void Save() - { - } - - public override void ToDefault() - { - } } } \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrike.settings b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrike.settings index 5db37a7aa..e5b8b302b 100644 --- a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrike.settings +++ b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrike.settings @@ -1,5 +1,7 @@  - + + @@ -31,6 +33,6 @@ True - + \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeView.xaml b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeView.xaml index 0f4f26545..e591ac8f9 100644 --- a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeView.xaml +++ b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeView.xaml @@ -19,7 +19,7 @@ - + - + \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeague.settings b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeague.settings index 0ade1b612..38d736f51 100644 --- a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeague.settings +++ b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeague.settings @@ -1,5 +1,7 @@  - + + diff --git a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueSettings.cs b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueSettings.cs index 800391d69..f7d2f018e 100644 --- a/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueSettings.cs +++ b/Artemis/Artemis/Modules/Games/RocketLeague/RocketLeagueSettings.cs @@ -1,5 +1,4 @@ -using System.Windows.Media; -using Artemis.Models; +using Artemis.Models; namespace Artemis.Modules.Games.RocketLeague { diff --git a/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionModel.cs b/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionModel.cs index 245ab80d5..8087cb468 100644 --- a/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionModel.cs +++ b/Artemis/Artemis/Modules/Games/TheDivision/TheDivisionModel.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using System.Drawing; using System.Threading; using System.Threading.Tasks; using Artemis.Managers; @@ -7,7 +6,6 @@ using Artemis.Models; using Artemis.Models.Profiles; using Artemis.Utilities; using Artemis.Utilities.LogitechDll; -using Brush = System.Windows.Media.Brush; namespace Artemis.Modules.Games.TheDivision { @@ -94,7 +92,7 @@ namespace Artemis.Modules.Games.TheDivision newState = PlayerState.Offline; if (playerId == 1) - gameDataModel.LowHp = (newState == PlayerState.Hit); + gameDataModel.LowHp = newState == PlayerState.Hit; else if (playerId == 2) gameDataModel.PartyMember1 = newState; else if (playerId == 3) @@ -131,9 +129,9 @@ namespace Artemis.Modules.Games.TheDivision // DataModel updating is done whenever a pipe message is received } - public override List GetRenderLayers(bool renderMice, bool renderHeadsets) - { - return Profile.GetRenderLayers(DataModel, renderMice, renderHeadsets); + public override List GetRenderLayers(bool renderMice, bool renderHeadsets) + { + return Profile.GetRenderLayers(DataModel, renderMice, renderHeadsets); } } } \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/Witcher3/Witcher3View.xaml b/Artemis/Artemis/Modules/Games/Witcher3/Witcher3View.xaml index 276eec0be..66d62178d 100644 --- a/Artemis/Artemis/Modules/Games/Witcher3/Witcher3View.xaml +++ b/Artemis/Artemis/Modules/Games/Witcher3/Witcher3View.xaml @@ -39,8 +39,10 @@ TextAlignment="Justify" Margin="5,0,0,10"> Artemis requires the latest Witcher 3 version and mod to be installed in order to work. If you don't use any (conflicting) Witcher 3 mods, the mod can automatically be installed. - - + - +