diff --git a/Artemis/Artemis/App.config b/Artemis/Artemis/App.config index af9997c3f..5db3e623b 100644 --- a/Artemis/Artemis/App.config +++ b/Artemis/Artemis/App.config @@ -3,6 +3,7 @@ +
@@ -29,6 +30,17 @@ + + + True + + + Default + + + + + True @@ -276,7 +288,7 @@ True - + True diff --git a/Artemis/Artemis/App.xaml.cs b/Artemis/Artemis/App.xaml.cs index 7b5f4dc88..f6b42a8e5 100644 --- a/Artemis/Artemis/App.xaml.cs +++ b/Artemis/Artemis/App.xaml.cs @@ -1,8 +1,6 @@ using System; -using System.Security.Principal; using System.Windows; using System.Windows.Threading; -using Artemis.Utilities; using NLog; using WpfExceptionViewer; @@ -13,28 +11,17 @@ namespace Artemis /// public partial class App : Application { - protected override void OnExit(ExitEventArgs e) - { - base.OnExit(e); - Environment.Exit(0); - } - public App() { - if (!IsRunAsAdministrator()) - GeneralHelpers.RunAsAdministrator(); - InitializeComponent(); } public bool DoHandle { get; set; } - private static bool IsRunAsAdministrator() + protected override void OnExit(ExitEventArgs e) { - var wi = WindowsIdentity.GetCurrent(); - var wp = new WindowsPrincipal(wi); - - return wp.IsInRole(WindowsBuiltInRole.Administrator); + base.OnExit(e); + Environment.Exit(0); } private void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) diff --git a/Artemis/Artemis/Artemis base layout.png b/Artemis/Artemis/Artemis base layout.png deleted file mode 100644 index 62a7a4972..000000000 Binary files a/Artemis/Artemis/Artemis base layout.png and /dev/null differ diff --git a/Artemis/Artemis/Artemis.csproj b/Artemis/Artemis/Artemis.csproj index 707d8f05a..428dacda1 100644 --- a/Artemis/Artemis/Artemis.csproj +++ b/Artemis/Artemis/Artemis.csproj @@ -40,7 +40,7 @@ Artemis Artemis 0 - 1.2.3.0 + 1.3.0.0 false true true @@ -73,7 +73,7 @@ Artemis_TemporaryKey.pfx - true + false false @@ -120,6 +120,12 @@ true + + app.manifest + + + LocalIntranet + ..\packages\Caliburn.Micro.Core.3.0.1\lib\net45\Caliburn.Micro.dll @@ -149,10 +155,26 @@ ..\packages\CUE.NET.1.0.3\lib\net45\CUE.NET.dll True + + ..\packages\DeltaCompressionDotNet.1.0.0\lib\net45\DeltaCompressionDotNet.dll + True + + + ..\packages\DeltaCompressionDotNet.1.0.0\lib\net45\DeltaCompressionDotNet.MsDelta.dll + True + + + ..\packages\DeltaCompressionDotNet.1.0.0\lib\net45\DeltaCompressionDotNet.PatchApi.dll + True + ..\packages\DynamicExpresso.Core.1.3.1.0\lib\net40\DynamicExpresso.Core.dll True + + False + lib\Ets2SdkClient.dll + ..\packages\gong-wpf-dragdrop.0.1.4.3\lib\net40\GongSolutions.Wpf.DragDrop.dll True @@ -161,6 +183,10 @@ ..\packages\Hardcodet.NotifyIcon.Wpf.1.0.8\lib\net451\Hardcodet.Wpf.TaskbarNotification.dll True + + ..\packages\squirrel.windows.1.4.4\lib\Net45\ICSharpCode.SharpZipLib.dll + True + ..\packages\log4net.2.0.5\lib\net45-full\log4net.dll True @@ -172,6 +198,22 @@ False + + ..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.dll + True + + + ..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Mdb.dll + True + + + ..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Pdb.dll + True + + + ..\packages\Mono.Cecil.0.9.6.1\lib\net45\Mono.Cecil.Rocks.dll + True + ..\packages\NAudio.1.7.3\lib\net35\NAudio.dll True @@ -184,6 +226,10 @@ ..\packages\Ninject.3.2.2.0\lib\net45-full\Ninject.dll True + + ..\packages\Ninject.Extensions.Conventions.3.2.0.0\lib\net45-full\Ninject.Extensions.Conventions.dll + True + ..\packages\Ninject.Extensions.Factory.3.2.1.0\lib\net45-full\Ninject.Extensions.Factory.dll True @@ -200,15 +246,24 @@ ..\packages\NLog.4.3.7\lib\net45\NLog.dll True - - False - D:\Downloads\Chome Downloads\Process.NET-master\Process.NET-master\src\Process.NET\bin\Release\Process.NET.dll + + ..\packages\squirrel.windows.1.4.4\lib\Net45\NuGet.Squirrel.dll + True + + + ..\packages\Splat.1.6.2\lib\Net45\Splat.dll + True ..\packages\SpotifyAPI-NET.2.11.0\lib\SpotifyAPI.dll True + + ..\packages\squirrel.windows.1.4.4\lib\Net45\Squirrel.dll + True + + @@ -241,28 +296,28 @@ - - ..\packages\Extended.Wpf.Toolkit.2.7\lib\net40\Xceed.Wpf.AvalonDock.dll + + ..\packages\Extended.Wpf.Toolkit.2.9\lib\net40\Xceed.Wpf.AvalonDock.dll True - - ..\packages\Extended.Wpf.Toolkit.2.7\lib\net40\Xceed.Wpf.AvalonDock.Themes.Aero.dll + + ..\packages\Extended.Wpf.Toolkit.2.9\lib\net40\Xceed.Wpf.AvalonDock.Themes.Aero.dll True - - ..\packages\Extended.Wpf.Toolkit.2.7\lib\net40\Xceed.Wpf.AvalonDock.Themes.Metro.dll + + ..\packages\Extended.Wpf.Toolkit.2.9\lib\net40\Xceed.Wpf.AvalonDock.Themes.Metro.dll True - - ..\packages\Extended.Wpf.Toolkit.2.7\lib\net40\Xceed.Wpf.AvalonDock.Themes.VS2010.dll + + ..\packages\Extended.Wpf.Toolkit.2.9\lib\net40\Xceed.Wpf.AvalonDock.Themes.VS2010.dll True - - ..\packages\Extended.Wpf.Toolkit.2.7\lib\net40\Xceed.Wpf.DataGrid.dll + + ..\packages\Extended.Wpf.Toolkit.2.9\lib\net40\Xceed.Wpf.DataGrid.dll True - - ..\packages\Extended.Wpf.Toolkit.2.7\lib\net40\Xceed.Wpf.Toolkit.dll + + ..\packages\Extended.Wpf.Toolkit.2.9\lib\net40\Xceed.Wpf.Toolkit.dll True @@ -277,6 +332,7 @@ + @@ -284,12 +340,16 @@ - + + + - - + + + + @@ -306,17 +366,17 @@ - - - - + - - True - True - UnrealTournament.settings + + + + + + EurotruckSimulator2View.xaml + @@ -324,11 +384,6 @@ UnrealTournamentView.xaml - - True - True - WoW.settings - @@ -357,31 +412,16 @@ - - AudioVisualization.settings - True - True - - - True - True - Bubbles.settings - BubblesView.xaml - - True - True - WindowsProfile.settings - WindowsProfileView.xaml @@ -391,37 +431,17 @@ - - CounterStrike.settings - True - True - - - True - True - Dota2.settings - OverwatchView.xaml - - RocketLeague.settings - True - True - - - True - True - TheDivision.settings - @@ -430,21 +450,11 @@ - - Overwatch.settings - True - True - - - True - True - Witcher3.settings - @@ -454,10 +464,8 @@ VolumeDisplay.settings - - @@ -488,17 +496,12 @@ - - True - True - General.settings - + + - - True - True - Offsets.settings - + + + @@ -522,7 +525,6 @@ - @@ -630,14 +632,9 @@ Code - - SettingsSingleFileGenerator - UnrealTournament.Designer.cs - - - SettingsSingleFileGenerator - WoW.Designer.cs + + Designer Designer @@ -649,42 +646,6 @@ Designer Resources.Designer.cs - - SettingsSingleFileGenerator - AudioVisualization.Designer.cs - - - SettingsSingleFileGenerator - Bubbles.Designer.cs - - - SettingsSingleFileGenerator - WindowsProfile.Designer.cs - - - SettingsSingleFileGenerator - CounterStrike.Designer.cs - - - SettingsSingleFileGenerator - Dota2.Designer.cs - - - SettingsSingleFileGenerator - RocketLeague.Designer.cs - - - SettingsSingleFileGenerator - TheDivision.Designer.cs - - - SettingsSingleFileGenerator - Overwatch.Designer.cs - - - SettingsSingleFileGenerator - Witcher3.Designer.cs - SettingsSingleFileGenerator VolumeDisplay.Designer.cs @@ -694,6 +655,8 @@ + + PreserveNewest @@ -718,14 +681,6 @@ - - SettingsSingleFileGenerator - Offsets.Designer.cs - - - SettingsSingleFileGenerator - General.Designer.cs - @@ -741,6 +696,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + Designer MSBuild:Compile diff --git a/Artemis/Artemis/ArtemisBootstrapper.cs b/Artemis/Artemis/ArtemisBootstrapper.cs index 2b67e8842..07e5ad234 100644 --- a/Artemis/Artemis/ArtemisBootstrapper.cs +++ b/Artemis/Artemis/ArtemisBootstrapper.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; -using System.Threading; using System.Windows; using System.Windows.Controls; -using System.Windows.Forms; +using System.Windows.Input; +using Artemis.DAL; using Artemis.InjectionModules; using Artemis.Settings; using Artemis.Utilities; @@ -12,9 +12,6 @@ using Artemis.ViewModels; using Caliburn.Micro; using Newtonsoft.Json; using Ninject; -using Application = System.Windows.Application; -using MessageBox = System.Windows.Forms.MessageBox; -using MouseEventArgs = System.Windows.Input.MouseEventArgs; namespace Artemis { @@ -25,15 +22,12 @@ namespace Artemis public ArtemisBootstrapper() { // Start logging before anything else - Logging.SetupLogging(General.Default.LogLevel); + Logging.SetupLogging(SettingsProvider.Load().LogLevel); - CheckDuplicateInstances(); Initialize(); BindSpecialValues(); } - public Mutex Mutex { get; set; } - private void BindSpecialValues() { MessageBinder.SpecialValues.Add("$scaledmousex", ctx => @@ -43,14 +37,14 @@ namespace Artemis var e = ctx.EventArgs as MouseEventArgs; // If there is an image control, get the scaled position - if (img != null && e != null) + if ((img != null) && (e != null)) { var position = e.GetPosition(img); return (int) (img.Source.Width*(position.X/img.ActualWidth)); } // If there is another type of of IInputControl get the non-scaled position - or do some processing to get a scaled position, whatever needs to happen - if (e != null && input != null) + if ((e != null) && (input != null)) return e.GetPosition(input).X; // Return 0 if no processing could be done @@ -63,14 +57,14 @@ namespace Artemis var e = ctx.EventArgs as MouseEventArgs; // If there is an image control, get the scaled position - if (img != null && e != null) + if ((img != null) && (e != null)) { var position = e.GetPosition(img); return (int) (img.Source.Width*(position.Y/img.ActualWidth)); } // If there is another type of of IInputControl get the non-scaled position - or do some processing to get a scaled position, whatever needs to happen - if (e != null && input != null) + if ((e != null) && (input != null)) return e.GetPosition(input).Y; // Return 0 if no processing could be done @@ -80,7 +74,9 @@ namespace Artemis protected override void Configure() { - _kernel = new StandardKernel(new BaseModules(), new ArtemisModules(), new ManagerModules()); + _kernel = new StandardKernel(new BaseModules(), new ManagerModules(), new DeviceModules(), + new EffectModules(), new ProfileModules()); + _kernel.Bind().To().InSingletonScope(); _kernel.Bind().To().InSingletonScope(); @@ -95,7 +91,6 @@ namespace Artemis protected override void OnExit(object sender, EventArgs e) { _kernel.Dispose(); -// Enviroment.Exit(0); base.OnExit(sender, e); } @@ -121,17 +116,5 @@ namespace Artemis { DisplayRootViewFor(); } - - private void CheckDuplicateInstances() - { - bool aIsNewInstance; - Mutex = new Mutex(true, "ArtemisMutex", out aIsNewInstance); - if (aIsNewInstance) - return; - - MessageBox.Show("An instance of Artemis is already running (check your system tray).", - "Artemis (╯°□°)╯︵ ┻━┻", MessageBoxButtons.OK, MessageBoxIcon.Warning); - Application.Current.Shutdown(); - } } } \ No newline at end of file diff --git a/Artemis/Artemis/DAL/SettingsProvider.cs b/Artemis/Artemis/DAL/SettingsProvider.cs new file mode 100644 index 000000000..0e4ecfed6 --- /dev/null +++ b/Artemis/Artemis/DAL/SettingsProvider.cs @@ -0,0 +1,105 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using Artemis.Settings; +using Newtonsoft.Json; +using NLog; + +namespace Artemis.DAL +{ + public static class SettingsProvider + { + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); + + private static readonly string SettingsFolder = + Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + @"\Artemis\settings"; + + private static readonly List Settings = new List(); + + /// + /// Loads settings with the given name from the filesystem + /// + /// + public static T Load() where T : new() + { + if (!AreSettings(typeof(T))) + throw new ArgumentException("Type doesn't implement IArtemisSettings"); + + // Attempt to load from memory first + var inMemory = Settings.FirstOrDefault(s => s.GetType() == typeof(T)); + if (inMemory != null) + return (T) inMemory; + + CheckSettings(); + + try + { + var loadSettings = (IArtemisSettings) JsonConvert + .DeserializeObject(File.ReadAllText(SettingsFolder + $@"\{typeof(T)}.json")); + + if (loadSettings == null) + { + loadSettings = (IArtemisSettings) new T(); + loadSettings.Reset(true); + } + + Settings.Add(loadSettings); + return (T) loadSettings; + } + catch (Exception e) + { + Logger.Error(e, "Couldn't load settings '{0}.json'", typeof(T)); + + // Not sure about this, I've seen prettier code + var loadSettings = (IArtemisSettings) new T(); + loadSettings.Reset(true); + Settings.Add(loadSettings); + return (T) loadSettings; + } + } + + /// + /// Saves the settings object to the filesystem + /// + /// + public static void Save(IArtemisSettings artemisSettings) + { + CheckSettings(); + + string json; + // Should saving fail for whatever reason, catch the exception and log it + // But DON'T touch the settings file. + try + { + json = JsonConvert.SerializeObject(artemisSettings, Formatting.Indented); + } + catch (Exception e) + { + Logger.Error(e, "Couldn't save settings '{0}.json'", artemisSettings.GetType()); + return; + } + + File.WriteAllText(SettingsFolder + $@"\{artemisSettings.GetType()}.json", json); + } + + /// + /// Ensures the settings folder exists + /// + private static void CheckSettings() + { + if (!Directory.Exists(SettingsFolder)) + Directory.CreateDirectory(SettingsFolder); + } + + /// + /// Checks to see if the given type is a setting + /// + /// + /// + private static bool AreSettings(Type t) + { + return typeof(IArtemisSettings).IsAssignableFrom(t); + } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/DeviceProviders/Corsair/CorsairKeyboards.cs b/Artemis/Artemis/DeviceProviders/Corsair/CorsairKeyboards.cs index e25074c60..a77d286b7 100644 --- a/Artemis/Artemis/DeviceProviders/Corsair/CorsairKeyboards.cs +++ b/Artemis/Artemis/DeviceProviders/Corsair/CorsairKeyboards.cs @@ -78,11 +78,6 @@ namespace Artemis.DeviceProviders.Corsair break; } -// Height = 7; -// Width = 18; -// Slug = "corsair-k65-rgb"; -// PreviewSettings = new PreviewSettings(610, 240, new Thickness(0, -30, 0, 0), Resources.k65); - Logger.Debug("Corsair SDK reported device as: {0}", _keyboard.DeviceInfo.Model); _keyboard.Brush = _keyboardBrush ?? (_keyboardBrush = new ImageBrush()); } diff --git a/Artemis/Artemis/DeviceProviders/Logitech/LogitechKeyboard.cs b/Artemis/Artemis/DeviceProviders/Logitech/LogitechKeyboard.cs index 8ad21c937..39f4b0ad8 100644 --- a/Artemis/Artemis/DeviceProviders/Logitech/LogitechKeyboard.cs +++ b/Artemis/Artemis/DeviceProviders/Logitech/LogitechKeyboard.cs @@ -2,7 +2,6 @@ using System.Threading; using System.Windows; using Artemis.DeviceProviders.Logitech.Utilities; -using Artemis.Utilities; using Artemis.Utilities.DataReaders; using Microsoft.Win32; @@ -12,7 +11,7 @@ namespace Artemis.DeviceProviders.Logitech { public override bool CanEnable() { - //Check to see if VC++ 2012 x64 is installed. + // Check to see if VC++ 2012 x64 is installed. if (Registry.LocalMachine.OpenSubKey( @"SOFTWARE\Classes\Installer\Dependencies\{ca67548a-5ebe-413a-b50c-4b9ceb6d66c6}") == null) { @@ -49,10 +48,7 @@ namespace Artemis.DeviceProviders.Logitech "Artemis couldn't enable your Logitech keyboard, because the required files are not in place.\n\n" + "This happens when you run The Division and shut down Artemis before shutting down The Division\n" + "It can be fixed automatically by clicking OK, but to avoid this message in the future please\n" + - "shut down The Division before shutting down Artemis.\n\n" + - "Click OK to fix the issue and restart Artemis"); - - GeneralHelpers.RunAsAdministrator(); + "shut down The Division before shutting down Artemis."); } public override void Enable() diff --git a/Artemis/Artemis/Events/ActiveEffectChanged.cs b/Artemis/Artemis/Events/ActiveEffectChanged.cs deleted file mode 100644 index fc35c1723..000000000 --- a/Artemis/Artemis/Events/ActiveEffectChanged.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Artemis.Events -{ - public class ActiveEffectChanged - { - public ActiveEffectChanged(string activeEffect) - { - ActiveEffect = activeEffect; - } - - public string ActiveEffect { get; set; } - } -} \ No newline at end of file diff --git a/Artemis/Artemis/Events/ActiveKeyboardChanged.cs b/Artemis/Artemis/Events/ActiveKeyboardChanged.cs deleted file mode 100644 index 1557e2a99..000000000 --- a/Artemis/Artemis/Events/ActiveKeyboardChanged.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Artemis.DeviceProviders; - -namespace Artemis.Events -{ - public class ActiveKeyboardChanged - { - public ActiveKeyboardChanged(KeyboardProvider oldKeyboard, KeyboardProvider newKeyboard) - { - OldKeyboard = oldKeyboard; - NewKeyboard = newKeyboard; - } - - public KeyboardProvider OldKeyboard { get; set; } - public KeyboardProvider NewKeyboard { get; set; } - } -} \ No newline at end of file diff --git a/Artemis/Artemis/Events/EffectChangedEventArgs.cs b/Artemis/Artemis/Events/EffectChangedEventArgs.cs new file mode 100644 index 000000000..9e9d4c9a9 --- /dev/null +++ b/Artemis/Artemis/Events/EffectChangedEventArgs.cs @@ -0,0 +1,15 @@ +using System; +using Artemis.Models; + +namespace Artemis.Events +{ + public class EffectChangedEventArgs : EventArgs + { + public EffectChangedEventArgs(EffectModel effect) + { + Effect = effect; + } + + public EffectModel Effect { get; } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Events/EnabledChangedEventArgs.cs b/Artemis/Artemis/Events/EnabledChangedEventArgs.cs new file mode 100644 index 000000000..9782ed634 --- /dev/null +++ b/Artemis/Artemis/Events/EnabledChangedEventArgs.cs @@ -0,0 +1,14 @@ +using System; + +namespace Artemis.Events +{ + public class EnabledChangedEventArgs : EventArgs + { + public EnabledChangedEventArgs(bool enabled) + { + Enabled = enabled; + } + + public bool Enabled { get; } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Events/KeyboardChangedEventArgs.cs b/Artemis/Artemis/Events/KeyboardChangedEventArgs.cs new file mode 100644 index 000000000..74b5b42a3 --- /dev/null +++ b/Artemis/Artemis/Events/KeyboardChangedEventArgs.cs @@ -0,0 +1,17 @@ +using System; +using Artemis.DeviceProviders; + +namespace Artemis.Events +{ + public class KeyboardChangedEventArgs : EventArgs + { + public KeyboardChangedEventArgs(KeyboardProvider oldKeyboard, KeyboardProvider newKeyboard) + { + OldKeyboard = oldKeyboard; + NewKeyboard = newKeyboard; + } + + public KeyboardProvider OldKeyboard { get; } + public KeyboardProvider NewKeyboard { get; } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Events/RazerColorsChangedEventArgs.cs b/Artemis/Artemis/Events/RazerColorsChangedEventArgs.cs new file mode 100644 index 000000000..6005083a8 --- /dev/null +++ b/Artemis/Artemis/Events/RazerColorsChangedEventArgs.cs @@ -0,0 +1,15 @@ +using System; +using System.Windows.Media; + +namespace Artemis.Events +{ + public class RazerColorsChangedEventArgs : EventArgs + { + public RazerColorsChangedEventArgs(Color[,] colors) + { + Colors = colors; + } + + public Color[,] Colors { get; } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Events/ToggleEnabled.cs b/Artemis/Artemis/Events/ToggleEnabled.cs deleted file mode 100644 index 8f30aa40e..000000000 --- a/Artemis/Artemis/Events/ToggleEnabled.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Artemis.Events -{ - public class ToggleEnabled - { - public ToggleEnabled(bool enabled) - { - Enabled = enabled; - } - - public bool Enabled { get; set; } - } -} \ No newline at end of file diff --git a/Artemis/Artemis/InjectionFactories/IProfileEditorVmFactory.cs b/Artemis/Artemis/InjectionFactories/IProfileEditorVmFactory.cs index 85fac1570..ef596f950 100644 --- a/Artemis/Artemis/InjectionFactories/IProfileEditorVmFactory.cs +++ b/Artemis/Artemis/InjectionFactories/IProfileEditorVmFactory.cs @@ -1,13 +1,11 @@ using Artemis.Managers; using Artemis.Models; using Artemis.ViewModels.Profiles; -using Caliburn.Micro; namespace Artemis.InjectionFactories { public interface IProfileEditorVmFactory { - ProfileEditorViewModel CreateProfileEditorVm(IEventAggregator events, MainManager mainManager, - EffectModel gameModel, string lastProfile); + ProfileEditorViewModel CreateProfileEditorVm(MainManager mainManager, EffectModel gameModel, string lastProfile); } } \ No newline at end of file diff --git a/Artemis/Artemis/InjectionModules/ArtemisModules.cs b/Artemis/Artemis/InjectionModules/ArtemisModules.cs deleted file mode 100644 index a8c38414c..000000000 --- a/Artemis/Artemis/InjectionModules/ArtemisModules.cs +++ /dev/null @@ -1,105 +0,0 @@ -using Artemis.DeviceProviders; -using Artemis.DeviceProviders.Corsair; -using Artemis.DeviceProviders.Logitech; -using Artemis.DeviceProviders.Razer; -using Artemis.Modules.Effects.AudioVisualizer; -using Artemis.Modules.Effects.Bubbles; -using Artemis.Modules.Effects.WindowsProfile; -using Artemis.Modules.Games.CounterStrike; -using Artemis.Modules.Games.Dota2; -using Artemis.Modules.Games.Overwatch; -using Artemis.Modules.Games.RocketLeague; -using Artemis.Modules.Games.TheDivision; -using Artemis.Modules.Games.UnrealTournament; -using Artemis.Modules.Games.Witcher3; -using Artemis.Modules.Overlays.VolumeDisplay; -using Artemis.Profiles.Layers.Animations; -using Artemis.Profiles.Layers.Conditions; -using Artemis.Profiles.Layers.Interfaces; -using Artemis.Profiles.Layers.Types.Audio; -using Artemis.Profiles.Layers.Types.Folder; -using Artemis.Profiles.Layers.Types.Generic; -using Artemis.Profiles.Layers.Types.Headset; -using Artemis.Profiles.Layers.Types.Keyboard; -using Artemis.Profiles.Layers.Types.KeyboardGif; -using Artemis.Profiles.Layers.Types.KeyPress; -using Artemis.Profiles.Layers.Types.Mouse; -using Artemis.ViewModels.Abstract; -using Ninject.Modules; - -namespace Artemis.InjectionModules -{ - public class ArtemisModules : NinjectModule - { - public override void Load() - { - #region Modules - - // Effects - Bind().To().InSingletonScope(); - Bind().To().InSingletonScope(); - Bind().To().InSingletonScope(); - - // Games - Bind().To().InSingletonScope(); - Bind().To().InSingletonScope(); - Bind().To().InSingletonScope(); - Bind().To().InSingletonScope(); - Bind().To().InSingletonScope(); - Bind().To().InSingletonScope(); - Bind().To().InSingletonScope(); - - // Overlays - Bind().To().InSingletonScope(); - - #endregion - - #region Devices - - // Keyboards - Bind().To().InSingletonScope(); - Bind().To().InSingletonScope(); - Bind().To().InSingletonScope(); - Bind().To().InSingletonScope(); - // Mice - Bind().To().InSingletonScope(); - // Headsets - Bind().To().InSingletonScope(); - // Other - Bind().To().InSingletonScope(); - - #endregion - - #region Layers - - // Animations - Bind().To(); - Bind().To(); - Bind().To(); - Bind().To(); - Bind().To(); - Bind().To(); - Bind().To(); - - // Conditions - Bind().To(); - Bind().To(); - - // Types - Bind().To(); - Bind().To(); - Bind().To(); - Bind().To(); - Bind().To(); - Bind().To(); - Bind().To(); - Bind().To(); - - // Bind some Layer Types to self as well in order to allow JSON.NET injection - Bind().ToSelf(); - Bind().ToSelf(); - - #endregion - } - } -} \ No newline at end of file diff --git a/Artemis/Artemis/InjectionModules/DeviceModules.cs b/Artemis/Artemis/InjectionModules/DeviceModules.cs new file mode 100644 index 000000000..32e101b64 --- /dev/null +++ b/Artemis/Artemis/InjectionModules/DeviceModules.cs @@ -0,0 +1,29 @@ +using Artemis.DeviceProviders; +using Artemis.DeviceProviders.Corsair; +using Artemis.DeviceProviders.Logitech; +using Artemis.DeviceProviders.Razer; +using Ninject.Modules; + +namespace Artemis.InjectionModules +{ + public class DeviceModules : NinjectModule + { + public override void Load() + { + // Keyboards + Bind().To().InSingletonScope(); + Bind().To().InSingletonScope(); + Bind().To().InSingletonScope(); + Bind().To().InSingletonScope(); + + // Mice + Bind().To().InSingletonScope(); + + // Headsets + Bind().To().InSingletonScope(); + + // Other + Bind().To().InSingletonScope(); + } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/InjectionModules/EffectModules.cs b/Artemis/Artemis/InjectionModules/EffectModules.cs new file mode 100644 index 000000000..91022f09a --- /dev/null +++ b/Artemis/Artemis/InjectionModules/EffectModules.cs @@ -0,0 +1,70 @@ +using Artemis.Models; +using Artemis.ViewModels.Abstract; +using Ninject.Extensions.Conventions; +using Ninject.Modules; + +namespace Artemis.InjectionModules +{ + public class EffectModules : NinjectModule + { + public override void Load() + { + // Effects + Kernel.Bind(x => + { + x.FromThisAssembly() + .SelectAllClasses() + .InheritedFrom() + .BindBase() + .Configure(b => b.InSingletonScope()); + }); + + Kernel.Bind(x => + { + x.FromThisAssembly() + .SelectAllClasses() + .InheritedFrom() + .BindBase() + .Configure(b => b.InSingletonScope()); + }); + + // Games + Kernel.Bind(x => + { + x.FromThisAssembly() + .SelectAllClasses() + .InheritedFrom() + .BindBase() + .Configure(b => b.InSingletonScope()); + }); + + Kernel.Bind(x => + { + x.FromThisAssembly() + .SelectAllClasses() + .InheritedFrom() + .BindBase() + .Configure(b => b.InSingletonScope()); + }); + + // Overlays + Kernel.Bind(x => + { + x.FromThisAssembly() + .SelectAllClasses() + .InheritedFrom() + .BindBase() + .Configure(b => b.InSingletonScope()); + }); + + Kernel.Bind(x => + { + x.FromThisAssembly() + .SelectAllClasses() + .InheritedFrom() + .BindBase() + .Configure(b => b.InSingletonScope()); + }); + } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/InjectionModules/ProfileModules.cs b/Artemis/Artemis/InjectionModules/ProfileModules.cs new file mode 100644 index 000000000..e5e99ee50 --- /dev/null +++ b/Artemis/Artemis/InjectionModules/ProfileModules.cs @@ -0,0 +1,48 @@ +using Artemis.Profiles.Layers.Animations; +using Artemis.Profiles.Layers.Conditions; +using Artemis.Profiles.Layers.Interfaces; +using Artemis.Profiles.Layers.Types.Audio; +using Artemis.Profiles.Layers.Types.Folder; +using Artemis.Profiles.Layers.Types.Generic; +using Artemis.Profiles.Layers.Types.Headset; +using Artemis.Profiles.Layers.Types.Keyboard; +using Artemis.Profiles.Layers.Types.KeyboardGif; +using Artemis.Profiles.Layers.Types.KeyPress; +using Artemis.Profiles.Layers.Types.Mouse; +using Ninject.Modules; + +namespace Artemis.InjectionModules +{ + public class ProfileModules : NinjectModule + { + public override void Load() + { + // Animations + Bind().To(); + Bind().To(); + Bind().To(); + Bind().To(); + Bind().To(); + Bind().To(); + Bind().To(); + + // Conditions + Bind().To(); + Bind().To(); + + // Types + Bind().To(); + Bind().To(); + Bind().To(); + Bind().To(); + Bind().To(); + Bind().To(); + Bind().To(); + Bind().To(); + + // Bind some Layer Types to self as well in order to allow JSON.NET injection + Bind().ToSelf(); + Bind().ToSelf(); + } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/MainWindow.xaml b/Artemis/Artemis/MainWindow.xaml deleted file mode 100644 index 57671ae01..000000000 --- a/Artemis/Artemis/MainWindow.xaml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - diff --git a/Artemis/Artemis/MainWindow.xaml.cs b/Artemis/Artemis/MainWindow.xaml.cs deleted file mode 100644 index 2598c1727..000000000 --- a/Artemis/Artemis/MainWindow.xaml.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Imaging; -using System.Windows.Navigation; -using System.Windows.Shapes; - -namespace Artemis -{ - /// - /// Interaction logic for MainWindow.xaml - /// - public partial class MainWindow : Window - { - public MainWindow() - { - InitializeComponent(); - } - } -} diff --git a/Artemis/Artemis/Managers/DeviceManager.cs b/Artemis/Artemis/Managers/DeviceManager.cs index ad18d36ea..676d3da13 100644 --- a/Artemis/Artemis/Managers/DeviceManager.cs +++ b/Artemis/Artemis/Managers/DeviceManager.cs @@ -2,11 +2,11 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Artemis.DAL; using Artemis.DeviceProviders; using Artemis.Events; using Artemis.Services; using Artemis.Settings; -using Caliburn.Micro; using MahApps.Metro.Controls.Dialogs; using Ninject; using Ninject.Extensions.Logging; @@ -18,13 +18,13 @@ namespace Artemis.Managers /// public class DeviceManager { - private readonly IEventAggregator _events; + private readonly GeneralSettings _generalSettings; private readonly ILogger _logger; - public DeviceManager(IEventAggregator events, ILogger logger, List deviceProviders) + public DeviceManager(ILogger logger, List deviceProviders) { _logger = logger; - _events = events; + _generalSettings = SettingsProvider.Load(); KeyboardProviders = deviceProviders.Where(d => d.Type == DeviceType.Keyboard) .Cast().ToList(); @@ -47,17 +47,18 @@ namespace Artemis.Managers public KeyboardProvider ActiveKeyboard { get; set; } public bool ChangingKeyboard { get; private set; } + public event EventHandler OnKeyboardChangedEvent; /// /// Enables the last keyboard according to the settings file /// public void EnableLastKeyboard() { - _logger.Debug("Getting last keyboard: {0}", General.Default.LastKeyboard); - if (string.IsNullOrEmpty(General.Default.LastKeyboard)) + _logger.Debug("Getting last keyboard: {0}", _generalSettings.LastKeyboard); + if (string.IsNullOrEmpty(_generalSettings.LastKeyboard)) return; - var keyboard = KeyboardProviders.FirstOrDefault(k => k.Name == General.Default.LastKeyboard); + var keyboard = KeyboardProviders.FirstOrDefault(k => k.Name == _generalSettings.LastKeyboard); EnableKeyboard(keyboard); } @@ -70,7 +71,7 @@ namespace Artemis.Managers if (keyboardProvider == null) throw new ArgumentNullException(nameof(keyboardProvider)); - if (ChangingKeyboard || ActiveKeyboard?.Name == keyboardProvider.Name) + if (ChangingKeyboard || (ActiveKeyboard?.Name == keyboardProvider.Name)) return; _logger.Debug("Trying to enable keyboard: {0}", keyboardProvider.Name); @@ -102,8 +103,8 @@ namespace Artemis.Managers DialogService.ShowErrorMessageBox(keyboardProvider.CantEnableText); ActiveKeyboard = null; - General.Default.LastKeyboard = null; - General.Default.Save(); + _generalSettings.LastKeyboard = null; + _generalSettings.Save(); _logger.Warn("Failed enabling keyboard: {0}", keyboardProvider.Name); ChangingKeyboard = false; return; @@ -116,10 +117,10 @@ namespace Artemis.Managers await ActiveKeyboard.EnableAsync(dialog); EnableUsableDevices(); - General.Default.LastKeyboard = ActiveKeyboard.Name; - General.Default.Save(); + _generalSettings.LastKeyboard = ActiveKeyboard.Name; + _generalSettings.Save(); - await _events.PublishOnUIThreadAsync(new ActiveKeyboardChanged(oldKeyboard, ActiveKeyboard)); + RaiseKeyboardChangedEvent(new KeyboardChangedEventArgs(oldKeyboard, ActiveKeyboard)); _logger.Debug("Enabled keyboard: {0}", keyboardProvider.Name); if (dialog != null) @@ -158,13 +159,21 @@ namespace Artemis.Managers if (save) { - General.Default.LastKeyboard = null; - General.Default.Save(); + _generalSettings.LastKeyboard = null; + _generalSettings.Save(); } - _events.PublishOnUIThread(new ActiveKeyboardChanged(oldKeyboard, null)); + RaiseKeyboardChangedEvent(new KeyboardChangedEventArgs(oldKeyboard, null)); _logger.Debug("Released keyboard: {0}", releaseName); } } + + protected virtual void RaiseKeyboardChangedEvent(KeyboardChangedEventArgs e) + { + // I do this in all to avoid a possible race condition + // https://msdn.microsoft.com/en-us/library/w369ty8x.aspx + var handler = OnKeyboardChangedEvent; + handler?.Invoke(this, e); + } } } \ No newline at end of file diff --git a/Artemis/Artemis/Managers/EffectManager.cs b/Artemis/Artemis/Managers/EffectManager.cs index b14b46bab..ab23035e9 100644 --- a/Artemis/Artemis/Managers/EffectManager.cs +++ b/Artemis/Artemis/Managers/EffectManager.cs @@ -5,7 +5,6 @@ using Artemis.Events; using Artemis.Models; using Artemis.Modules.Effects.ProfilePreview; using Artemis.Settings; -using Caliburn.Micro; using Ninject.Extensions.Logging; namespace Artemis.Managers @@ -16,18 +15,20 @@ namespace Artemis.Managers public class EffectManager { private readonly DeviceManager _deviceManager; - private readonly IEventAggregator _events; private readonly ILogger _logger; private EffectModel _activeEffect; + private LoopManager _waitLoopManager; + private EffectModel _waitEffect; + private readonly GeneralSettings _generalSettings; - public EffectManager(ILogger logger, IEventAggregator events, DeviceManager deviceManager) + public EffectManager(ILogger logger, DeviceManager deviceManager) { - _logger = logger; - _events = events; - _deviceManager = deviceManager; - EffectModels = new List(); + _generalSettings = DAL.SettingsProvider.Load(); + _logger = logger; + _deviceManager = deviceManager; + _logger.Info("Intialized EffectManager"); } @@ -44,7 +45,7 @@ namespace Artemis.Managers private set { _activeEffect = value; - _events.PublishOnUIThread(new ActiveEffectChanged(value?.Name)); + RaiseEffectChangedEvent(new EffectChangedEventArgs(value)); } } @@ -64,16 +65,18 @@ namespace Artemis.Managers get { return EffectModels.OfType().Where(g => g.Enabled); } } + public event EventHandler OnEffectChangedEvent; + /// /// Loads the last active effect from settings and enables it. /// /// Whether enabling was successful or not. public EffectModel GetLastEffect() { - _logger.Debug("Getting last effect: {0}", General.Default.LastEffect); - return General.Default.LastEffect == null + _logger.Debug("Getting last effect: {0}", _generalSettings.LastEffect); + return _generalSettings.LastEffect == null ? null - : EffectModels.FirstOrDefault(e => e.Name == General.Default.LastEffect); + : EffectModels.FirstOrDefault(e => e.Name == _generalSettings.LastEffect); } /// @@ -83,17 +86,24 @@ namespace Artemis.Managers /// Optionally pass the LoopManager to automatically start it, if it's not running. public void ChangeEffect(EffectModel effectModel, LoopManager loopManager = null) { + if (_waitEffect != null) + { + _logger.Debug("Stopping effect because a change is already queued"); + return; + } + if (effectModel == null) throw new ArgumentNullException(nameof(effectModel)); if (effectModel is OverlayModel) throw new ArgumentException("Can't set an Overlay effect as the active effect"); - if (_deviceManager.ActiveKeyboard == null) - _deviceManager.EnableLastKeyboard(); - // If still null, no last keyboard, so stop. if (_deviceManager.ActiveKeyboard == null) { - _logger.Debug("Cancelling effect change, no LastKeyboard"); + _logger.Debug("Stopping effect change until keyboard is enabled"); + _waitEffect = effectModel; + _waitLoopManager = loopManager; + _deviceManager.OnKeyboardChangedEvent += DeviceManagerOnOnKeyboardChangedEvent; + _deviceManager.EnableLastKeyboard(); return; } @@ -141,8 +151,21 @@ namespace Artemis.Managers return; // Non-game effects are stored as the new LastEffect. - General.Default.LastEffect = ActiveEffect?.Name; - General.Default.Save(); + _generalSettings.LastEffect = ActiveEffect?.Name; + _generalSettings.Save(); + } + + private void DeviceManagerOnOnKeyboardChangedEvent(object sender, KeyboardChangedEventArgs e) + { + _deviceManager.OnKeyboardChangedEvent -= DeviceManagerOnOnKeyboardChangedEvent; + _logger.Debug("Resuming effect change"); + + var effect = _waitEffect; + _waitEffect = null; + var loopManager = _waitLoopManager; + _waitLoopManager = null; + + ChangeEffect(effect, loopManager); } @@ -159,11 +182,10 @@ namespace Artemis.Managers ActiveEffect.Dispose(); ActiveEffect = null; - General.Default.LastEffect = null; - General.Default.Save(); + _generalSettings.LastEffect = null; + _generalSettings.Save(); } - _logger.Debug("Cleared active effect"); } @@ -192,5 +214,11 @@ namespace Artemis.Managers DisableGame(ActiveEffect); } + + protected virtual void RaiseEffectChangedEvent(EffectChangedEventArgs e) + { + var handler = OnEffectChangedEvent; + handler?.Invoke(this, e); + } } } \ No newline at end of file diff --git a/Artemis/Artemis/Managers/LoopManager.cs b/Artemis/Artemis/Managers/LoopManager.cs index f5ba8c957..b4c3e40a3 100644 --- a/Artemis/Artemis/Managers/LoopManager.cs +++ b/Artemis/Artemis/Managers/LoopManager.cs @@ -21,10 +21,8 @@ namespace Artemis.Managers private readonly ILogger _logger; private readonly Timer _loopTimer; - public LoopManager(IEventAggregator events, ILogger logger, EffectManager effectManager, - DeviceManager deviceManager) + public LoopManager(ILogger logger, EffectManager effectManager, DeviceManager deviceManager) { - events.Subscribe(this); _logger = logger; _effectManager = effectManager; _deviceManager = deviceManager; diff --git a/Artemis/Artemis/Managers/MainManager.cs b/Artemis/Artemis/Managers/MainManager.cs index 09d10be9d..b0d8fe146 100644 --- a/Artemis/Artemis/Managers/MainManager.cs +++ b/Artemis/Artemis/Managers/MainManager.cs @@ -1,12 +1,15 @@ using System; +using System.Diagnostics; using System.Linq; +using System.Reflection; +using System.Threading.Tasks; using System.Timers; using Artemis.Events; using Artemis.Models; +using Artemis.Utilities; using Artemis.Utilities.DataReaders; using Artemis.Utilities.GameState; using Artemis.ViewModels; -using Caliburn.Micro; using Ninject; using Ninject.Extensions.Logging; @@ -17,16 +20,11 @@ namespace Artemis.Managers /// public class MainManager : IDisposable { - public delegate void PauseCallbackHandler(); - - private readonly IEventAggregator _events; private readonly Timer _processTimer; - public MainManager(IEventAggregator events, ILogger logger, LoopManager loopManager, DeviceManager deviceManager, + public MainManager(ILogger logger, LoopManager loopManager, DeviceManager deviceManager, EffectManager effectManager, ProfileManager profileManager, PipeServer pipeServer) { - _events = events; - Logger = logger; LoopManager = loopManager; DeviceManager = deviceManager; @@ -42,13 +40,18 @@ namespace Artemis.Managers Running = false; // Create and start the web server - GameStateWebServer = new GameStateWebServer(); + GameStateWebServer = new GameStateWebServer(logger); GameStateWebServer.Start(); // Start the named pipe PipeServer.Start("artemis"); + // Start the update task + var updateTask = new Task(Updater.UpdateApp); + updateTask.Start(); + Logger.Info("Intialized MainManager"); + Logger.Info($"Artemis version {Assembly.GetExecutingAssembly().GetName().Version} is ready!"); } [Inject] @@ -77,6 +80,8 @@ namespace Artemis.Managers PipeServer?.Stop(); } + public event EventHandler OnEnabledChangedEvent; + /// /// Loads the last active effect and starts the program /// @@ -85,7 +90,7 @@ namespace Artemis.Managers Logger.Debug("Enabling program"); ProgramEnabled = true; LoopManager.StartAsync(); - _events.PublishOnUIThread(new ToggleEnabled(ProgramEnabled)); + RaiseEnabledChangedEvent(new EnabledChangedEventArgs(ProgramEnabled)); } /// @@ -96,7 +101,7 @@ namespace Artemis.Managers Logger.Debug("Disabling program"); LoopManager.Stop(); ProgramEnabled = false; - _events.PublishOnUIThread(new ToggleEnabled(ProgramEnabled)); + RaiseEnabledChangedEvent(new EnabledChangedEventArgs(ProgramEnabled)); } /// @@ -109,7 +114,7 @@ namespace Artemis.Managers if (!ProgramEnabled) return; - var runningProcesses = System.Diagnostics.Process.GetProcesses(); + var runningProcesses = Process.GetProcesses(); // If the currently active effect is a disabled game, get rid of it. if (EffectManager.ActiveEffect != null) @@ -137,5 +142,11 @@ namespace Artemis.Managers Logger.Info("Detected and enabling game: {0}", newGame.Name); EffectManager.ChangeEffect(newGame, LoopManager); } + + protected virtual void RaiseEnabledChangedEvent(EnabledChangedEventArgs e) + { + var handler = OnEnabledChangedEvent; + handler?.Invoke(this, e); + } } } \ No newline at end of file diff --git a/Artemis/Artemis/Managers/ProfileManager.cs b/Artemis/Artemis/Managers/ProfileManager.cs index 50edc8d10..c44cb6f1a 100644 --- a/Artemis/Artemis/Managers/ProfileManager.cs +++ b/Artemis/Artemis/Managers/ProfileManager.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using System.Linq; using System.Timers; +using Artemis.DAL; using Artemis.Models; using Artemis.Modules.Effects.ProfilePreview; using Artemis.Settings; @@ -15,6 +16,7 @@ namespace Artemis.Managers private readonly EffectManager _effectManager; private readonly ILogger _logger; private readonly LoopManager _loopManager; + private GeneralSettings _generalSettings; public ProfileManager(ILogger logger, EffectManager effectManager, DeviceManager deviceManager, LoopManager loopManager) @@ -23,6 +25,7 @@ namespace Artemis.Managers _effectManager = effectManager; _deviceManager = deviceManager; _loopManager = loopManager; + _generalSettings = SettingsProvider.Load(); GameViewModels = new List(); @@ -44,7 +47,7 @@ namespace Artemis.Managers /// private void SetupProfilePreview(object sender, ElapsedEventArgs e) { - if (string.IsNullOrEmpty(General.Default.LastKeyboard) || _deviceManager.ChangingKeyboard || + if (string.IsNullOrEmpty(_generalSettings.LastKeyboard) || _deviceManager.ChangingKeyboard || ProfilePreviewModel == null) return; diff --git a/Artemis/Artemis/Models/EffectModel.cs b/Artemis/Artemis/Models/EffectModel.cs index 3765b85c9..c0ec5cbb6 100644 --- a/Artemis/Artemis/Models/EffectModel.cs +++ b/Artemis/Artemis/Models/EffectModel.cs @@ -8,6 +8,7 @@ using Artemis.Models.Interfaces; using Artemis.Profiles; using Artemis.Profiles.Layers.Interfaces; using Artemis.Profiles.Layers.Models; +using Artemis.Settings; using Newtonsoft.Json; namespace Artemis.Models @@ -18,14 +19,18 @@ namespace Artemis.Models protected DateTime LastTrace; - protected EffectModel(MainManager mainManager, IDataModel dataModel) + protected EffectModel(MainManager mainManager, EffectSettings settings, IDataModel dataModel) { MainManager = mainManager; + Settings = settings; DataModel = dataModel; + + MainManager.EffectManager.EffectModels.Add(this); } public bool Initialized { get; set; } public MainManager MainManager { get; set; } + public EffectSettings Settings { get; set; } public string Name { get; set; } public int KeyboardScale { get; set; } = 4; diff --git a/Artemis/Artemis/Models/EffectSettings.cs b/Artemis/Artemis/Models/EffectSettings.cs deleted file mode 100644 index 98996df54..000000000 --- a/Artemis/Artemis/Models/EffectSettings.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace Artemis.Models -{ - public abstract class EffectSettings - { - /// - /// Loads the settings from the settings file - /// - public abstract void Load(); - - /// - /// Saves the settings to the settings file - /// - public abstract void Save(); - - /// - /// Returns the settings to their default value - /// - public abstract void ToDefault(); - } -} \ No newline at end of file diff --git a/Artemis/Artemis/Models/GameModel.cs b/Artemis/Artemis/Models/GameModel.cs index a37558bfe..fc63cd2ca 100644 --- a/Artemis/Artemis/Models/GameModel.cs +++ b/Artemis/Artemis/Models/GameModel.cs @@ -1,17 +1,18 @@ using Artemis.Managers; using Artemis.Models.Interfaces; +using Artemis.Settings; 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, settings, dataModel) { + // Override settings to the GameSettings type Settings = settings; } - public GameSettings Settings { get; set; } + public new GameSettings Settings { get; set; } public bool Enabled { get; set; } public string ProcessName { get; set; } } diff --git a/Artemis/Artemis/Models/GamePointersCollectionModel.cs b/Artemis/Artemis/Models/GamePointersCollectionModel.cs deleted file mode 100644 index 35279db50..000000000 --- a/Artemis/Artemis/Models/GamePointersCollectionModel.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; - -namespace Artemis.Models -{ - public class GamePointersCollectionModel - { - public string Game { get; set; } - public string GameVersion { get; set; } - public List GameAddresses { get; set; } - } - - public class GamePointer - { - public string Description { get; set; } - public IntPtr BasePointer { get; set; } - public int[] Offsets { get; set; } - - public override string ToString() - { - return Offsets.Aggregate(BasePointer.ToString("X"), - (current, offset) => current + $"+{offset.ToString("X")}"); - } - } -} \ No newline at end of file diff --git a/Artemis/Artemis/Models/GameSettings.cs b/Artemis/Artemis/Models/GameSettings.cs deleted file mode 100644 index fe026cfb4..000000000 --- a/Artemis/Artemis/Models/GameSettings.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Artemis.Models -{ - public abstract class GameSettings : EffectSettings - { - public bool Enabled { get; set; } - public string LastProfile { get; set; } - } -} \ No newline at end of file diff --git a/Artemis/Artemis/Models/Interfaces/GameDataModel.cs b/Artemis/Artemis/Models/Interfaces/IDataModel.cs similarity index 94% rename from Artemis/Artemis/Models/Interfaces/GameDataModel.cs rename to Artemis/Artemis/Models/Interfaces/IDataModel.cs index de39f4457..4e5a0ec07 100644 --- a/Artemis/Artemis/Models/Interfaces/GameDataModel.cs +++ b/Artemis/Artemis/Models/Interfaces/IDataModel.cs @@ -1,6 +1,6 @@ -namespace Artemis.Models.Interfaces -{ - public interface IDataModel - { - } +namespace Artemis.Models.Interfaces +{ + public interface IDataModel + { + } } \ No newline at end of file diff --git a/Artemis/Artemis/Models/OverlayModel.cs b/Artemis/Artemis/Models/OverlayModel.cs index 9657577bb..e5a58c602 100644 --- a/Artemis/Artemis/Models/OverlayModel.cs +++ b/Artemis/Artemis/Models/OverlayModel.cs @@ -1,4 +1,5 @@ using Artemis.Managers; +using Artemis.Settings; namespace Artemis.Models { @@ -7,8 +8,10 @@ namespace Artemis.Models private bool _enabled; public string ProcessName; - protected OverlayModel(MainManager mainManager) : base(mainManager, null) + protected OverlayModel(MainManager mainManager, OverlaySettings settings) : base(mainManager, settings, null) { + Settings = settings; + Enabled = settings.Enabled; } public bool Enabled @@ -27,6 +30,7 @@ namespace Artemis.Models } } + public new OverlaySettings Settings { get; set; } public abstract void RenderOverlay(RenderFrame frame, bool keyboardOnly); } } \ No newline at end of file diff --git a/Artemis/Artemis/Models/OverlaySettings.cs b/Artemis/Artemis/Models/OverlaySettings.cs deleted file mode 100644 index e05df3d2a..000000000 --- a/Artemis/Artemis/Models/OverlaySettings.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Artemis.Models -{ - public abstract class OverlaySettings : EffectSettings - { - public bool Enabled { get; set; } - } -} \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualization.Designer.cs b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualization.Designer.cs deleted file mode 100644 index e5342a3e7..000000000 --- a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualization.Designer.cs +++ /dev/null @@ -1,110 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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.AudioVisualizer { - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] - internal sealed partial class AudioVisualization : global::System.Configuration.ApplicationSettingsBase { - - private static AudioVisualization defaultInstance = ((AudioVisualization)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new AudioVisualization()))); - - public static AudioVisualization Default { - get { - return defaultInstance; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("4")] - public int Sensitivity { - get { - return ((int)(this["Sensitivity"])); - } - set { - this["Sensitivity"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("21")] - public int Bars { - get { - return ((int)(this["Bars"])); - } - set { - this["Bars"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("True")] - public bool FromBottom { - get { - return ((bool)(this["FromBottom"])); - } - set { - this["FromBottom"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("3")] - public int FadeSpeed { - get { - return ((int)(this["FadeSpeed"])); - } - set { - this["FadeSpeed"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("#FFF90000")] - public global::System.Windows.Media.Color TopColor { - get { - return ((global::System.Windows.Media.Color)(this["TopColor"])); - } - set { - this["TopColor"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("#FFFF761E")] - public global::System.Windows.Media.Color MiddleColor { - get { - return ((global::System.Windows.Media.Color)(this["MiddleColor"])); - } - set { - this["MiddleColor"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("#FF00DF00")] - public global::System.Windows.Media.Color BottomColor { - get { - return ((global::System.Windows.Media.Color)(this["BottomColor"])); - } - set { - this["BottomColor"] = value; - } - } - } -} diff --git a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualization.settings b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualization.settings deleted file mode 100644 index aef505bd4..000000000 --- a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualization.settings +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - 4 - - - 21 - - - True - - - 3 - - - #FFF90000 - - - #FFFF761E - - - #FF00DF00 - - - \ 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 9e2dacc18..90ede32ce 100644 --- a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerModel.cs +++ b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerModel.cs @@ -23,9 +23,8 @@ namespace Artemis.Modules.Effects.AudioVisualizer private int _sensitivity; private IWaveIn _waveIn; - public AudioVisualizerModel(MainManager mainManager, AudioVisualizerSettings settings) : base(mainManager, null) + public AudioVisualizerModel(MainManager mainManager) : base(mainManager, null, null) { - Settings = settings; Name = "Audiovisualizer"; DeviceIds = new List(); SpectrumData = new List(); @@ -33,8 +32,7 @@ namespace Artemis.Modules.Effects.AudioVisualizer } public int Lines { get; set; } - - public AudioVisualizerSettings Settings { get; set; } + public List SpectrumData { get; set; } public List SoundRectangles { get; set; } @@ -72,15 +70,15 @@ namespace Artemis.Modules.Effects.AudioVisualizer MainManager.DeviceManager.ActiveKeyboard, 0, 0, new List { - ColorHelpers.ToDrawingColor(Settings.TopColor), - ColorHelpers.ToDrawingColor(Settings.MiddleColor), - ColorHelpers.ToDrawingColor(Settings.BottomColor) + Color.Red, + Color.Yellow, + Color.Lime }, LinearGradientMode.Vertical) {ContainedBrush = false, Height = 0}); } - _sensitivity = Settings.Sensitivity; - _fromBottom = Settings.FromBottom; + _sensitivity = 2; + _fromBottom = true; _sampleAggregator.FftCalculated += FftCalculated; _sampleAggregator.PerformFFT = true; @@ -126,7 +124,8 @@ namespace Artemis.Modules.Effects.AudioVisualizer if (keyboardHeight > SoundRectangles[i].Height) SoundRectangles[i].Height = keyboardHeight; else - SoundRectangles[i].Height = SoundRectangles[i].Height - Settings.FadeSpeed; + SoundRectangles[i].Height = SoundRectangles[i].Height - + 5; // was FadeSpeed setting // Apply Bars setting SoundRectangles[i].X = i*KeyboardScale; SoundRectangles[i].Width = KeyboardScale; diff --git a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerSettings.cs b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerSettings.cs deleted file mode 100644 index 7c965870c..000000000 --- a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerSettings.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Windows.Media; -using Artemis.Models; - -namespace Artemis.Modules.Effects.AudioVisualizer -{ - public class AudioVisualizerSettings : EffectSettings - { - public AudioVisualizerSettings() - { - Load(); - } - - public int Sensitivity { get; set; } - public int Bars { get; set; } - public bool FromBottom { get; set; } - public int FadeSpeed { get; set; } - public Color TopColor { get; set; } - public Color MiddleColor { get; set; } - public Color BottomColor { get; set; } - - public sealed override void Load() - { - Sensitivity = AudioVisualization.Default.Sensitivity; - Bars = AudioVisualization.Default.Bars; - FromBottom = AudioVisualization.Default.FromBottom; - FadeSpeed = AudioVisualization.Default.FadeSpeed; - TopColor = AudioVisualization.Default.TopColor; - MiddleColor = AudioVisualization.Default.MiddleColor; - BottomColor = AudioVisualization.Default.BottomColor; - } - - public sealed override void Save() - { - AudioVisualization.Default.Sensitivity = Sensitivity; - AudioVisualization.Default.Bars = Bars; - AudioVisualization.Default.FromBottom = FromBottom; - AudioVisualization.Default.FadeSpeed = FadeSpeed; - AudioVisualization.Default.TopColor = TopColor; - AudioVisualization.Default.MiddleColor = MiddleColor; - AudioVisualization.Default.BottomColor = BottomColor; - - AudioVisualization.Default.Save(); - } - - public sealed override void ToDefault() - { - Sensitivity = 4; - Bars = 21; - FromBottom = true; - FadeSpeed = 3; - TopColor = Color.FromArgb(255, 249, 0, 0); - MiddleColor = Color.FromArgb(255, 255, 118, 30); - BottomColor = Color.FromArgb(255, 0, 223, 0); - } - } -} \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerViewModel.cs b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerViewModel.cs index 6183d80a9..92614ef8d 100644 --- a/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerViewModel.cs +++ b/Artemis/Artemis/Modules/Effects/AudioVisualizer/AudioVisualizerViewModel.cs @@ -1,25 +1,13 @@ -using Artemis.Events; -using Artemis.Managers; +using Artemis.Managers; using Artemis.ViewModels.Abstract; -using Caliburn.Micro; namespace Artemis.Modules.Effects.AudioVisualizer { - public sealed class AudioVisualizerViewModel : EffectViewModel, IHandle + public sealed class AudioVisualizerViewModel : EffectViewModel { - public AudioVisualizerViewModel(MainManager main, IEventAggregator events) - : base(main, new AudioVisualizerModel(main, new AudioVisualizerSettings())) + public AudioVisualizerViewModel(MainManager main, AudioVisualizerModel model) : base(main, model) { DisplayName = "Audio Visualization"; - events.Subscribe(this); - - MainManager.EffectManager.EffectModels.Add(EffectModel); - EffectSettings = ((AudioVisualizerModel) EffectModel).Settings; - } - - public void Handle(ActiveEffectChanged message) - { - NotifyOfPropertyChange(() => EffectEnabled); } } } \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/Bubbles/Bubbles.Designer.cs b/Artemis/Artemis/Modules/Effects/Bubbles/Bubbles.Designer.cs deleted file mode 100644 index 6815b56a6..000000000 --- a/Artemis/Artemis/Modules/Effects/Bubbles/Bubbles.Designer.cs +++ /dev/null @@ -1,122 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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.Bubbles { - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] - internal sealed partial class Bubbles : global::System.Configuration.ApplicationSettingsBase { - - private static Bubbles defaultInstance = ((Bubbles)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Bubbles()))); - - public static Bubbles Default { - get { - return defaultInstance; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("True")] - public bool IsRandomColors { - get { - return ((bool)(this["IsRandomColors"])); - } - set { - this["IsRandomColors"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("#FFFF0000")] - public global::System.Windows.Media.Color BubbleColor { - get { - return ((global::System.Windows.Media.Color)(this["BubbleColor"])); - } - set { - this["BubbleColor"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("True")] - public bool IsShiftColors { - get { - return ((bool)(this["IsShiftColors"])); - } - set { - this["IsShiftColors"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("25")] - public int BubbleSize { - get { - return ((int)(this["BubbleSize"])); - } - set { - this["BubbleSize"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("4")] - public int MoveSpeed { - get { - return ((int)(this["MoveSpeed"])); - } - set { - this["MoveSpeed"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("12")] - public int ShiftColorSpeed { - get { - return ((int)(this["ShiftColorSpeed"])); - } - set { - this["ShiftColorSpeed"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("14")] - public int BubbleCount { - get { - return ((int)(this["BubbleCount"])); - } - set { - this["BubbleCount"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("25")] - public int Smoothness { - get { - return ((int)(this["Smoothness"])); - } - set { - this["Smoothness"] = value; - } - } - } -} diff --git a/Artemis/Artemis/Modules/Effects/Bubbles/Bubbles.settings b/Artemis/Artemis/Modules/Effects/Bubbles/Bubbles.settings deleted file mode 100644 index 748dada51..000000000 --- a/Artemis/Artemis/Modules/Effects/Bubbles/Bubbles.settings +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - True - - - #FFFF0000 - - - True - - - 25 - - - 4 - - - 12 - - - 14 - - - 25 - - - \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/Bubbles/BubblesModel.cs b/Artemis/Artemis/Modules/Effects/Bubbles/BubblesModel.cs index 45c2fe0b0..56367d9b4 100644 --- a/Artemis/Artemis/Modules/Effects/Bubbles/BubblesModel.cs +++ b/Artemis/Artemis/Modules/Effects/Bubbles/BubblesModel.cs @@ -14,12 +14,11 @@ namespace Artemis.Modules.Effects.Bubbles { #region Constructors - public BubblesModel(MainManager mainManager, BubblesSettings settings) - : base(mainManager, null) + public BubblesModel(MainManager mainManager) : base(mainManager, new BubblesSettings(), null) { Name = "Bubbles"; - Settings = settings; Initialized = false; + Settings = (BubblesSettings) base.Settings; } #endregion @@ -30,7 +29,7 @@ namespace Artemis.Modules.Effects.Bubbles private readonly List _bubbles = new List(); - public BubblesSettings Settings { get; } + public new BubblesSettings Settings { get; } #endregion diff --git a/Artemis/Artemis/Modules/Effects/Bubbles/BubblesSettings.cs b/Artemis/Artemis/Modules/Effects/Bubbles/BubblesSettings.cs index a6f264c67..17b4d9d37 100644 --- a/Artemis/Artemis/Modules/Effects/Bubbles/BubblesSettings.cs +++ b/Artemis/Artemis/Modules/Effects/Bubbles/BubblesSettings.cs @@ -1,60 +1,54 @@ -using System.Windows.Media; -using Artemis.Models; +using System.ComponentModel; +using System.Windows.Media; +using Artemis.DAL; +using Artemis.Settings; +using Newtonsoft.Json; namespace Artemis.Modules.Effects.Bubbles { public class BubblesSettings : EffectSettings { - public BubblesSettings() - { - Load(); - } - + [DefaultValue(true)] + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] public bool IsRandomColors { get; set; } + public Color BubbleColor { get; set; } + + [DefaultValue(true)] + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] public bool IsShiftColors { get; set; } + + [DefaultValue(12)] + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] public int ShiftColorSpeed { get; set; } + + [DefaultValue(25)] + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] public int BubbleSize { get; set; } + + [DefaultValue(4)] + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] public int MoveSpeed { get; set; } + + [DefaultValue(14)] + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] public int BubbleCount { get; set; } + + [DefaultValue(25)] + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)] public int Smoothness { get; set; } - public sealed override void Load() + public new void Reset(bool save = false) { - IsRandomColors = Bubbles.Default.IsRandomColors; - BubbleColor = Bubbles.Default.BubbleColor; - IsShiftColors = Bubbles.Default.IsShiftColors; - ShiftColorSpeed = Bubbles.Default.ShiftColorSpeed; - BubbleSize = Bubbles.Default.BubbleSize; - MoveSpeed = Bubbles.Default.MoveSpeed; - BubbleCount = Bubbles.Default.BubbleCount; - Smoothness = Bubbles.Default.Smoothness; - } + JsonConvert.PopulateObject("{}", this, new JsonSerializerSettings + { + ObjectCreationHandling = ObjectCreationHandling.Reuse + }); - public sealed override void Save() - { - Bubbles.Default.IsRandomColors = IsRandomColors; - Bubbles.Default.BubbleColor = BubbleColor; - Bubbles.Default.IsShiftColors = IsShiftColors; - Bubbles.Default.ShiftColorSpeed = ShiftColorSpeed; - Bubbles.Default.BubbleSize = BubbleSize; - Bubbles.Default.MoveSpeed = MoveSpeed; - Bubbles.Default.BubbleCount = BubbleCount; - Bubbles.Default.Smoothness = Smoothness; + BubbleColor = Colors.Red; - Bubbles.Default.Save(); - } - - public sealed override void ToDefault() - { - IsRandomColors = true; - BubbleColor = Color.FromArgb(255, 255, 0, 0); - IsShiftColors = true; - ShiftColorSpeed = 12; - BubbleSize = 25; - MoveSpeed = 4; - BubbleCount = 14; - Smoothness = 25; + if (save) + SettingsProvider.Save(this); } } } \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/Bubbles/BubblesViewModel.cs b/Artemis/Artemis/Modules/Effects/Bubbles/BubblesViewModel.cs index 9c2803a0e..378b26873 100644 --- a/Artemis/Artemis/Modules/Effects/Bubbles/BubblesViewModel.cs +++ b/Artemis/Artemis/Modules/Effects/Bubbles/BubblesViewModel.cs @@ -1,25 +1,13 @@ -using Artemis.Events; -using Artemis.Managers; +using Artemis.Managers; using Artemis.ViewModels.Abstract; -using Caliburn.Micro; namespace Artemis.Modules.Effects.Bubbles { - public class BubblesViewModel : EffectViewModel, IHandle + public sealed class BubblesViewModel : EffectViewModel { - public BubblesViewModel(MainManager main, IEventAggregator events) - : base(main, new BubblesModel(main, new BubblesSettings())) + public BubblesViewModel(MainManager main, BubblesModel model) : base(main, model) { DisplayName = "Bubbles"; - events.Subscribe(this); - - MainManager.EffectManager.EffectModels.Add(EffectModel); - EffectSettings = ((BubblesModel) EffectModel).Settings; - } - - public void Handle(ActiveEffectChanged message) - { - NotifyOfPropertyChange(() => EffectEnabled); } } } \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/ProfilePreview/ProfilePreviewModel.cs b/Artemis/Artemis/Modules/Effects/ProfilePreview/ProfilePreviewModel.cs index 513a9619d..d2d05ce38 100644 --- a/Artemis/Artemis/Modules/Effects/ProfilePreview/ProfilePreviewModel.cs +++ b/Artemis/Artemis/Modules/Effects/ProfilePreview/ProfilePreviewModel.cs @@ -14,7 +14,7 @@ namespace Artemis.Modules.Effects.ProfilePreview { public class ProfilePreviewModel : EffectModel { - public ProfilePreviewModel(MainManager mainManager) : base(mainManager, new ProfilePreviewDataModel()) + public ProfilePreviewModel(MainManager mainManager) : base(mainManager, null, new ProfilePreviewDataModel()) { Name = "Profile Preview"; } diff --git a/Artemis/Artemis/Modules/Effects/WindowsProfile/PerformanceInfo.cs b/Artemis/Artemis/Modules/Effects/WindowsProfile/PerformanceInfo.cs new file mode 100644 index 000000000..e807c6582 --- /dev/null +++ b/Artemis/Artemis/Modules/Effects/WindowsProfile/PerformanceInfo.cs @@ -0,0 +1,48 @@ +using System; +using System.Runtime.InteropServices; + +namespace Artemis.Modules.Effects.WindowsProfile +{ + internal static class PerformanceInfo + { + [DllImport("psapi.dll", SetLastError = true)] + [return: MarshalAs(UnmanagedType.Bool)] + public static extern bool GetPerformanceInfo([Out] out PerformanceInformation performanceInformation, + [In] int size); + + public static long GetPhysicalAvailableMemoryInMiB() + { + var pi = new PerformanceInformation(); + if (GetPerformanceInfo(out pi, Marshal.SizeOf(pi))) + return Convert.ToInt64(pi.PhysicalAvailable.ToInt64()*pi.PageSize.ToInt64()/1048576); + return -1; + } + + public static long GetTotalMemoryInMiB() + { + var pi = new PerformanceInformation(); + if (GetPerformanceInfo(out pi, Marshal.SizeOf(pi))) + return Convert.ToInt64(pi.PhysicalTotal.ToInt64()*pi.PageSize.ToInt64()/1048576); + return -1; + } + + [StructLayout(LayoutKind.Sequential)] + public struct PerformanceInformation + { + public int Size; + public IntPtr CommitTotal; + public IntPtr CommitLimit; + public IntPtr CommitPeak; + public IntPtr PhysicalTotal; + public IntPtr PhysicalAvailable; + public IntPtr SystemCache; + public IntPtr KernelTotal; + public IntPtr KernelPaged; + public IntPtr KernelNonPaged; + public IntPtr PageSize; + public int HandlesCount; + public int ProcessCount; + public int ThreadCount; + } + } +} \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfile.Designer.cs b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfile.Designer.cs deleted file mode 100644 index 5e8a56c4d..000000000 --- a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfile.Designer.cs +++ /dev/null @@ -1,38 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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 deleted file mode 100644 index 4a88bb226..000000000 --- a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfile.settings +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - Demo (Duplicate to keep changes) - - - \ 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 ce5b05eba..03a355d14 100644 --- a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileModel.cs +++ b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileModel.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Runtime.InteropServices; using System.Threading; using System.Threading.Tasks; +using Artemis.DAL; using Artemis.Managers; using Artemis.Models; using Artemis.Profiles.Layers.Models; @@ -12,54 +12,6 @@ using SpotifyAPI.Local; namespace Artemis.Modules.Effects.WindowsProfile { - internal static class PerformanceInfo - { - [DllImport("psapi.dll", SetLastError = true)] - [return: MarshalAs(UnmanagedType.Bool)] - public static extern bool GetPerformanceInfo([Out] out PerformanceInformation performanceInformation, - [In] int size); - - public static long GetPhysicalAvailableMemoryInMiB() - { - var pi = new PerformanceInformation(); - if (GetPerformanceInfo(out pi, Marshal.SizeOf(pi))) - { - return Convert.ToInt64(pi.PhysicalAvailable.ToInt64()*pi.PageSize.ToInt64()/1048576); - } - return -1; - } - - public static long GetTotalMemoryInMiB() - { - var pi = new PerformanceInformation(); - if (GetPerformanceInfo(out pi, Marshal.SizeOf(pi))) - { - return Convert.ToInt64(pi.PhysicalTotal.ToInt64()*pi.PageSize.ToInt64()/1048576); - } - return -1; - } - - [StructLayout(LayoutKind.Sequential)] - public struct PerformanceInformation - { - public int Size; - public IntPtr CommitTotal; - public IntPtr CommitLimit; - public IntPtr CommitPeak; - public IntPtr PhysicalTotal; - public IntPtr PhysicalAvailable; - public IntPtr SystemCache; - public IntPtr KernelTotal; - public IntPtr KernelPaged; - public IntPtr KernelNonPaged; - public IntPtr PageSize; - public int HandlesCount; - public int ProcessCount; - public int ThreadCount; - } - } - - public class WindowsProfileModel : EffectModel { private readonly ILogger _logger; @@ -69,16 +21,13 @@ namespace Artemis.Modules.Effects.WindowsProfile private SpotifyLocalAPI _spotify; private bool _spotifySetupBusy; - public WindowsProfileModel(ILogger logger, MainManager mainManager, WindowsProfileSettings settings) - : base(mainManager, new WindowsProfileDataModel()) + public WindowsProfileModel(ILogger logger, MainManager mainManager) + : base(mainManager, SettingsProvider.Load(), new WindowsProfileDataModel()) { _logger = logger; Name = "WindowsProfile"; - Settings = settings; } - public WindowsProfileSettings Settings { get; set; } - public override void Dispose() { Initialized = false; @@ -136,7 +85,7 @@ namespace Artemis.Modules.Effects.WindowsProfile private void UpdateCpu(WindowsProfileDataModel dataModel) { - if (_cores == null || _overallCpu == null) + if ((_cores == null) || (_overallCpu == null)) return; // CPU is only updated every 15 frames, the performance counter gives 0 if updated too often diff --git a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileSettings.cs b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileSettings.cs index a41551fe2..adff6e1e7 100644 --- a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileSettings.cs +++ b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileSettings.cs @@ -1,28 +1,8 @@ -using Artemis.Models; +using Artemis.Settings; 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 3bf68a2ce..0299cc0ee 100644 --- a/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileViewModel.cs +++ b/Artemis/Artemis/Modules/Effects/WindowsProfile/WindowsProfileViewModel.cs @@ -1,31 +1,25 @@ using System.ComponentModel; -using Artemis.Events; using Artemis.InjectionFactories; using Artemis.Managers; using Artemis.Modules.Effects.ProfilePreview; using Artemis.ViewModels.Abstract; using Artemis.ViewModels.Profiles; -using Caliburn.Micro; -using Ninject.Extensions.Logging; namespace Artemis.Modules.Effects.WindowsProfile { // TODO: This effect is a hybrid between a regular effect and a game, may want to clean this up - public sealed class WindowsProfileViewModel : EffectViewModel, IHandle + public sealed class WindowsProfileViewModel : EffectViewModel { - public WindowsProfileViewModel(ILogger logger, MainManager main, IEventAggregator events, - IProfileEditorVmFactory pFactory, ProfilePreviewModel profilePreviewModel) - : base(main, new WindowsProfileModel(logger, main, new WindowsProfileSettings())) + public WindowsProfileViewModel(MainManager main, IProfileEditorVmFactory pFactory, + ProfilePreviewModel profilePreviewModel, WindowsProfileModel model) : base(main, model) { DisplayName = "Windows Profile"; PFactory = pFactory; ProfilePreviewModel = profilePreviewModel; EffectSettings = ((WindowsProfileModel) EffectModel).Settings; - ProfileEditor = PFactory.CreateProfileEditorVm(events, main, (WindowsProfileModel) EffectModel, + ProfileEditor = PFactory.CreateProfileEditorVm(main, (WindowsProfileModel) EffectModel, ((WindowsProfileSettings) EffectSettings).LastProfile); ProfilePreviewModel.Profile = ProfileEditor.SelectedProfile; - - events.Subscribe(this); ProfileEditor.PropertyChanged += ProfileUpdater; MainManager.EffectManager.EffectModels.Add(EffectModel); } @@ -35,11 +29,6 @@ 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) diff --git a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrike.Designer.cs b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrike.Designer.cs deleted file mode 100644 index 85a966af8..000000000 --- a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrike.Designer.cs +++ /dev/null @@ -1,62 +0,0 @@ -//------------------------------------------------------------------------------ -// -// 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.Games.CounterStrike { - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] - internal sealed partial class CounterStrike : global::System.Configuration.ApplicationSettingsBase { - - private static CounterStrike defaultInstance = ((CounterStrike)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new CounterStrike()))); - - public static CounterStrike Default { - get { - return defaultInstance; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("True")] - public bool Enabled { - get { - return ((bool)(this["Enabled"])); - } - set { - this["Enabled"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("Default")] - public string LastProfile { - get { - return ((string)(this["LastProfile"])); - } - set { - this["LastProfile"] = value; - } - } - - [global::System.Configuration.UserScopedSettingAttribute()] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Configuration.DefaultSettingValueAttribute("")] - public string GameDirectory { - get { - return ((string)(this["GameDirectory"])); - } - set { - this["GameDirectory"] = value; - } - } - } -} diff --git a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrike.settings b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrike.settings deleted file mode 100644 index 2e32158e5..000000000 --- a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrike.settings +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - True - - - Default - - - - - - \ No newline at end of file diff --git a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs index 8d34cba15..8a7893c5d 100644 --- a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs +++ b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeModel.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Artemis.DAL; using Artemis.Managers; using Artemis.Models; using Artemis.Profiles.Layers.Models; @@ -11,8 +12,8 @@ namespace Artemis.Modules.Games.CounterStrike { public class CounterStrikeModel : GameModel { - public CounterStrikeModel(MainManager mainManager, CounterStrikeSettings settings) - : base(mainManager, settings, new CounterStrikeDataModel()) + public CounterStrikeModel(MainManager mainManager) + : base(mainManager, SettingsProvider.Load(), new CounterStrikeDataModel()) { Name = "CounterStrike"; ProcessName = "csgo"; diff --git a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeSettings.cs b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeSettings.cs index 24b5699f1..cb5d20c9b 100644 --- a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeSettings.cs +++ b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeSettings.cs @@ -1,35 +1,9 @@ -using Artemis.Models; +using Artemis.Settings; namespace Artemis.Modules.Games.CounterStrike { public class CounterStrikeSettings : GameSettings { - public CounterStrikeSettings() - { - Load(); - } - public string GameDirectory { get; set; } - - public sealed override void Load() - { - Enabled = CounterStrike.Default.Enabled; - LastProfile = CounterStrike.Default.LastProfile; - GameDirectory = CounterStrike.Default.GameDirectory; - } - - public sealed override void Save() - { - CounterStrike.Default.Enabled = Enabled; - CounterStrike.Default.GameDirectory = GameDirectory; - - CounterStrike.Default.Save(); - } - - public sealed override void ToDefault() - { - Enabled = true; - GameDirectory = string.Empty; - } } } \ 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 0a8459b29..8cc599305 100644 --- a/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeView.xaml +++ b/Artemis/Artemis/Modules/Games/CounterStrike/CounterStrikeView.xaml @@ -40,7 +40,7 @@ Grid.Column="0" Grid.ColumnSpan="2" Margin="0,0,1,0"> -